diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 14dd25a..7c03f0c 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -27,11 +27,18 @@ - + + + + + + + + - + @@ -45,4 +52,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/composer.json b/composer.json index 8d2235b..11ed6bb 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/constants.php b/constants.php index 01f3e9d..5171bf1 100644 --- a/constants.php +++ b/constants.php @@ -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; diff --git a/inc/admin-pages/class-about-admin-page.php b/inc/admin-pages/class-about-admin-page.php index 0a3d7af..ac0f48d 100644 --- a/inc/admin-pages/class-about-admin-page.php +++ b/inc/admin-pages/class-about-admin-page.php @@ -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') + ) + ); + } +} diff --git a/inc/admin-pages/class-base-admin-page.php b/inc/admin-pages/class-base-admin-page.php index fb3a892..31f5655 100644 --- a/inc/admin-pages/class-base-admin-page.php +++ b/inc/admin-pages/class-base-admin-page.php @@ -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 { '; 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(); +} diff --git a/inc/admin-pages/class-base-customer-facing-admin-page.php b/inc/admin-pages/class-base-customer-facing-admin-page.php index 248669f..c3bd7c0 100644 --- a/inc/admin-pages/class-base-customer-facing-admin-page.php +++ b/inc/admin-pages/class-base-customer-facing-admin-page.php @@ -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 '
'; $form->render(); echo '
'; - - } // 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; + } +} diff --git a/inc/admin-pages/class-broadcast-edit-admin-page.php b/inc/admin-pages/class-broadcast-edit-admin-page.php index ab27ea3..9343509 100644 --- a/inc/admin-pages/class-broadcast-edit-admin-page.php +++ b/inc/admin-pages/class-broadcast-edit-admin-page.php @@ -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 .= ""; - - } // 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('
+ $html .= sprintf( + '', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $targets_count, __('Targets', 'wp-ultimo')); - +
', + 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('
+ $html .= sprintf( + '', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $targets_count, __('Targets', 'wp-ultimo')); - - } // end if; +
', + wu_get_form_url('view_broadcast_targets', $modal_atts), + __('Targets', 'wp-ultimo'), + $targets_count, + __('Targets', 'wp-ultimo') + ); + } break; - - } // end switch; + } $html .= ''; 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; + } +} diff --git a/inc/admin-pages/class-broadcast-list-admin-page.php b/inc/admin-pages/class-broadcast-list-admin-page.php index 5d1697e..54293a6 100644 --- a/inc/admin-pages/class-broadcast-list-admin-page.php +++ b/inc/admin-pages/class-broadcast-list-admin-page.php @@ -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('', esc_attr($avatar)); - } else { - $avatar = ''; - - } // 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; + } +} diff --git a/inc/admin-pages/class-checkout-form-edit-admin-page.php b/inc/admin-pages/class-checkout-form-edit-admin-page.php index 68fefd7..0415859 100644 --- a/inc/admin-pages/class-checkout-form-edit-admin-page.php +++ b/inc/admin-pages/class-checkout-form-edit-admin-page.php @@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages; // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Managers\Signup_Fields_Manager; +use WP_Ultimo\Managers\Signup_Fields_Manager; /** * WP Multisite WaaS Checkout_Form Edit/Add New Admin Page. @@ -96,8 +96,7 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { add_action('wp_ajax_wu_save_editor_session', array($this, 'save_editor_session')); add_action('load-admin_page_wp-ultimo-edit-checkout-form', array($this, 'add_width_control_script')); - - } // end init; + } /** * Adds the script that controls @@ -109,8 +108,7 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { public function add_width_control_script() { wp_enqueue_script('wu-checkout-form-edit-modal', wu_get_asset('checkout-form-editor-modal.js', 'js'), array(), wu_get_version()); - - } // end add_width_control_script; + } /** * Returns the action links for that page. @@ -123,7 +121,6 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $actions = array(); if ($this->get_object()->exists()) { - $url_atts = array( 'id' => $this->get_object()->get_id(), 'slug' => $this->get_object()->get_slug(), @@ -136,12 +133,10 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { 'classes' => 'wubox', 'url' => wu_get_form_url('shortcode_checkout', $url_atts), ); - - } // end if; + } return $actions; - - } // end action_links; + } /** * Renders the preview of a given form being edited. @@ -159,10 +154,8 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { add_filter('wu_is_toolbox_enabled', '__return_false'); add_action('wp', array($this, 'content_checkout_form_by_settings')); - - } // end if; - - } // end generate_checkout_form_preview; + } + } /** * Filter the content to render checkout form by settings. @@ -174,11 +167,9 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $checkout_form = wu_get_checkout_form(wu_request('form_id')); - if (!$checkout_form) { - + if ( ! $checkout_form) { return; - - } // end if; + } $content = ''; @@ -188,53 +179,48 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $settings_session = wu_get_isset($session->get($key), 'wu_checkout_form_editor', array()); - if (!empty($settings_session)) { - + if ( ! empty($settings_session)) { $checkout_form->set_settings($settings_session); - - } // end if; + } $settings = $checkout_form->get_settings(); $preview_type = wu_request('type', 'user'); if ($preview_type === 'visitor') { - global $current_user; $current_user = wp_set_current_user(0); - - } // end if; + } $count = count($settings); foreach ($settings as $index => $step) { - $final_fields = wu_create_checkout_fields($step['fields']); - $content .= wu_get_template_contents('checkout/form', array( - 'step' => $step, - 'step_name' => $step['id'], - 'final_fields' => $final_fields, - 'checkout_form_name' => '', - 'password_strength' => false, - 'apply_styles' => true, - 'display_title' => true, - )); + $content .= wu_get_template_contents( + 'checkout/form', + array( + 'step' => $step, + 'step_name' => $step['id'], + 'final_fields' => $final_fields, + 'checkout_form_name' => '', + 'password_strength' => false, + 'apply_styles' => true, + 'display_title' => true, + ) + ); if ($index < $count - 1) { - $content .= sprintf('
', __('Step Separator', 'wp-ultimo')); - - } // end if; - - } // end foreach; + } + } wp_enqueue_scripts(); wp_print_head_scripts(); - echo sprintf('', 'class="' . esc_attr(implode(' ', get_body_class('wu-styling'))) . '"'); + printf('', 'class="' . esc_attr(implode(' ', get_body_class('wu-styling'))) . '"'); echo '
'; @@ -245,8 +231,7 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { echo '
'; exit; - - } // end content_checkout_form_by_settings; + } /** * Save the editor session. @@ -263,7 +248,6 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $form = wu_get_checkout_form(wu_request('form_id')); if ($form && $settings) { - $session = \WP_Session_Tokens::get_instance(get_current_user_id()); $key = wp_get_session_token(); @@ -275,12 +259,10 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $session->update($key, $session_data); wp_send_json_success(); - - } // end if; + } wp_send_json_error(); - - } // end save_editor_session; + } /** * Adds hooks when the page loads. @@ -294,8 +276,7 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $object = $this->get_object(); - if (!is_wp_error($object->validate())) { - + if ( ! is_wp_error($object->validate())) { $key = wp_get_session_token(); $session = \WP_Session_Tokens::get_instance(get_current_user_id()); @@ -305,16 +286,14 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { unset($session_data['wu_checkout_form_editor']); $session->update($key, $session_data); - - } // end if; + } $screen = get_current_screen(); add_action("wu_edit_{$screen->id}_after_normal", array($this, 'render_steps')); add_action('admin_footer', array($this, 'render_js_templates')); - - } // end page_loaded; + } // Forms @@ -328,22 +307,27 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { /* * Add new Section */ - wu_register_form('add_new_form_step', array( - 'render' => array($this, 'render_add_new_form_step_modal'), - 'handler' => array($this, 'handle_add_new_form_step_modal'), - 'capability' => 'wu_edit_checkout_forms', - )); + wu_register_form( + 'add_new_form_step', + array( + 'render' => array($this, 'render_add_new_form_step_modal'), + 'handler' => array($this, 'handle_add_new_form_step_modal'), + 'capability' => 'wu_edit_checkout_forms', + ) + ); /* * Add new Field */ - wu_register_form('add_new_form_field', array( - 'render' => array($this, 'render_add_new_form_field_modal'), - 'handler' => array($this, 'handle_add_new_form_field_modal'), - 'capability' => 'wu_edit_checkout_forms', - )); - - } // end register_forms; + wu_register_form( + 'add_new_form_field', + array( + 'render' => array($this, 'render_add_new_form_field_modal'), + 'handler' => array($this, 'handle_add_new_form_field_modal'), + 'capability' => 'wu_edit_checkout_forms', + ) + ); + } /** * Returns the list of available field types. @@ -354,26 +338,25 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $field_type_objects = Signup_Fields_Manager::get_instance()->get_field_types(); - $fields = array_map(function($class_name) { + $fields = array_map( + function ($class_name) { - $field = new $class_name(); + $field = new $class_name(); - /* - * Remove the hidden fields. - */ - if ($field->is_hidden()) { + /* + * Remove the hidden fields. + */ + if ($field->is_hidden()) { + return null; + } - return null; - - } // end if; - - return $field->get_field_as_type_option(); - - }, $field_type_objects); + return $field->get_field_as_type_option(); + }, + $field_type_objects + ); return array_filter($fields); - - } // end field_types; + } /** * Returns the list of fields for the add/edit new field screen. @@ -540,66 +523,65 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $additional_fields = array(); foreach ($field_types as $field_type) { - $_fields = call_user_func($field_type['fields'], $attributes); $additional_fields = array_merge($additional_fields, $_fields); - - } // end foreach; + } $default_fields = \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field::fields_list(); $index = 0; foreach ($default_fields as $default_field_slug => &$default_field) { - $default_field['order'] = $index + 10; - $index++; + ++$index; $reqs = $this->get_required_list($default_field_slug, $field_types); $tab = wu_get_isset($default_field, 'tab', 'content'); - $default_field['wrapper_html_attr'] = array_merge(wu_get_isset($default_field, 'wrapper_html_attr', array()), array( - 'v-if' => sprintf('type && require("type", %s) && require("tab", "%s")', json_encode($reqs), $tab), - 'v-cloak' => '1', - )); + $default_field['wrapper_html_attr'] = array_merge( + wu_get_isset($default_field, 'wrapper_html_attr', array()), + array( + 'v-if' => sprintf('type && require("type", %s) && require("tab", "%s")', json_encode($reqs), $tab), + 'v-cloak' => '1', + ) + ); if ($default_field_slug === 'name' || $default_field_slug === 'id' || $default_field_slug === 'default_value') { - unset($default_field['wrapper_html_attr']['v-if']); $default_field['wrapper_html_attr']['v-show'] = sprintf('type && require("type", %s) && require("tab", "%s")', json_encode($reqs), $tab); - - } // end if; + } if ($default_field_slug === 'id') { - $default_field['html_attr']['v-bind:required'] = sprintf('type && require("type", %s) && require("tab", "content")', json_encode($reqs)); + } + } - } // end if; - - } // end foreach; - - $fields = array_merge($fields, $default_fields, $additional_fields, array( - 'submit_button' => array( - 'type' => 'submit', - 'title' => empty($attributes) ? __('Add Field', 'wp-ultimo') : __('Save Field', 'wp-ultimo'), - 'value' => 'save', - 'order' => 100, - 'classes' => 'button button-primary wu-w-full', - 'wrapper_classes' => 'wu-items-end', - 'wrapper_html_attr' => array( - 'v-show' => 'type', - 'v-cloak' => '1', + $fields = array_merge( + $fields, + $default_fields, + $additional_fields, + array( + 'submit_button' => array( + 'type' => 'submit', + 'title' => empty($attributes) ? __('Add Field', 'wp-ultimo') : __('Save Field', 'wp-ultimo'), + 'value' => 'save', + 'order' => 100, + 'classes' => 'button button-primary wu-w-full', + 'wrapper_classes' => 'wu-items-end', + 'wrapper_html_attr' => array( + 'v-show' => 'type', + 'v-cloak' => '1', + ), ), - ), - )); + ) + ); return $fields; - - } // end get_create_field_fields; + } /** * Gets the field from the checkout step OR from the session. @@ -615,17 +597,13 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $field = $checkout_form->get_field($step_name, $field_name); - if (!$field) { - + if ( ! $field) { $field = array( 'saved' => false, ); - } else { - $field['saved'] = true; - - } // end if; + } $key = wp_get_session_token(); @@ -633,23 +611,18 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $settings = wu_get_isset($session->get($key), 'wu_checkout_form_editor', array()); - if (!empty($settings)) { - + if ( ! empty($settings)) { $checkout_form->set_settings($settings); $new_field = $checkout_form->get_field($step_name, $field_name); if (is_array($new_field)) { - $field = array_merge($field, $new_field); - - } // end if; - - } // end if; + } + } return $field; - - } // end get_field; + } /** * Gets the step from the checkout OR from the session. @@ -664,17 +637,13 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $step = $checkout_form->get_step($step_name); - if (!$step) { - + if ( ! $step) { $step = array( 'saved' => false, ); - } else { - $step['saved'] = true; - - } // end if; + } $key = wp_get_session_token(); @@ -683,16 +652,13 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $settings = wu_get_isset($session->get($key), 'wu_checkout_form_editor'); if ($settings) { - $checkout_form->set_settings($settings); $step = $checkout_form->get_step($step_name); - - } // end if; + } return $step; - - } // end get_step; + } /** * Adds the modal for adding new fields. @@ -704,11 +670,9 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $checkout_form = wu_get_checkout_form_by_slug(wu_request('checkout_form')); - if (!$checkout_form) { - + if ( ! $checkout_form) { return; - - } // end if; + } $steps = $checkout_form->get_settings(); @@ -720,42 +684,39 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $edit_fields = $this->get_create_field_fields($_field); - $state = array_map(function($field) { + $state = array_map( + function ($field) { - $value = wu_get_isset($field, 'value', wu_get_isset($field, 'default', '')); + $value = wu_get_isset($field, 'value', wu_get_isset($field, 'default', '')); - return $value; - - }, $edit_fields); + return $value; + }, + $edit_fields + ); if ($_field) { - $state = array_merge($state, $_field); + } - } // end if; + $state = array_map( + function ($value) { - $state = array_map(function($value) { + if ($value === 'false' || $value === 'true') { + $value = (int) wu_string_to_bool($value); + } - if ($value === 'false' || $value === 'true') { - - $value = (int) wu_string_to_bool($value); - - } // end if; - - return $value; - - }, $state); + return $value; + }, + $state + ); $state['tab'] = 'content'; - if (!wu_get_isset($state, 'logged', false)) { - + if ( ! wu_get_isset($state, 'logged', false)) { $state['logged'] = 'always'; + } - } // end if; - - if (!wu_get_isset($state, 'period_options', false)) { - + if ( ! wu_get_isset($state, 'period_options', false)) { $state['period_options'] = array( array( 'duration' => 1, @@ -763,50 +724,44 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { 'label' => __('Monthly'), ), ); + } - } // end if; - - if (!wu_get_isset($state, 'options', false)) { - + if ( ! wu_get_isset($state, 'options', false)) { $state['options'] = array(); + } - } // end if; - - if (!wu_get_isset($state, 'save_as', false)) { - + if ( ! wu_get_isset($state, 'save_as', false)) { $state['save_as'] = 'customer_meta'; + } - } // end if; - - if (!wu_get_isset($state, 'auto_generate', false)) { - + if ( ! wu_get_isset($state, 'auto_generate', false)) { $state['auto_generate'] = 0; + } - } // end if; - - if (!wu_get_isset($state, 'original_id', false)) { - + if ( ! wu_get_isset($state, 'original_id', false)) { $state['original_id'] = wu_get_isset($state, 'id', ''); - - } // end if; + } $state['from_request'] = wu_string_to_bool(wu_get_isset($state, 'from_request', true)); uasort($edit_fields, 'wu_sort_by_order'); - $form = new \WP_Ultimo\UI\Form('add_edit_fields_modal', $edit_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' => wu_convert_to_state($state), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'add_edit_fields_modal', + $edit_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' => wu_convert_to_state($state), + ), + ) + ); $form->render(); - - } // end render_add_new_form_field_modal; + } /** * Handles the submission of a new form field modal submission. @@ -818,14 +773,14 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $checkout_form = wu_get_checkout_form_by_slug(wu_request('checkout_form')); - if (!$checkout_form) { - - wp_send_json_error(new \WP_Error( - 'checkout-form-not-found', - __('The checkout form could not be found.', 'wp-ultimo') - )); - - } // end if; + if ( ! $checkout_form) { + wp_send_json_error( + new \WP_Error( + 'checkout-form-not-found', + __('The checkout form could not be found.', 'wp-ultimo') + ) + ); + } $data = array( 'id' => wu_request('id', ''), @@ -840,11 +795,11 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $field_types = $this->field_types(); - $all_attributes_list = array_combine($field_types[$type]['all_attributes'], $field_types[$type]['all_attributes']); + $all_attributes_list = array_combine($field_types[ $type ]['all_attributes'], $field_types[ $type ]['all_attributes']); $data = array_merge( $data, - $field_types[$type]['force_attributes'], + $field_types[ $type ]['force_attributes'], array_map(fn($item) => wu_request($item, wu_get_isset($data, $item, '')), $all_attributes_list) ); @@ -852,25 +807,24 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { * Auto-assign ID if none is set */ if (wu_get_isset($data, 'id', '') === '') { - $data['id'] = wu_get_isset($data, 'type', 'field') . '-' . uniqid(); - - } // end if; + } /* * Allow developers to change the id of the fields. */ $data['id'] = apply_filters("wu_checkout_form_field_{$type}_id", $data['id'], $data, $checkout_form, $type); - wp_send_json_success(array( - 'send' => array( - 'scope' => 'wu_checkout_forms_editor_app', - 'function_name' => 'add_field', - 'data' => $data, - ), - )); - - } // end handle_add_new_form_field_modal; + wp_send_json_success( + array( + 'send' => array( + 'scope' => 'wu_checkout_forms_editor_app', + 'function_name' => 'add_field', + 'data' => $data, + ), + ) + ); + } /** * Renders the content of the edit-add section modal. @@ -882,11 +836,9 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $checkout_form = wu_get_checkout_form_by_slug(wu_request('checkout_form')); - if (!$checkout_form) { - + if ( ! $checkout_form) { return; - - } // end if; + } $steps = $checkout_form->get_settings(); @@ -1039,34 +991,33 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $state = array_map('__return_empty_string', $fields); if ($_step) { - $state = array_merge($state, $_step); - - } // end if; + } $state['tab'] = 'content'; $state['logged'] = wu_get_isset($state, 'logged', 'always'); - if (!wu_get_isset($state, 'original_id', false)) { - + if ( ! wu_get_isset($state, 'original_id', false)) { $state['original_id'] = wu_get_isset($state, 'id', ''); + } - } // end if; - - $form = new \WP_Ultimo\UI\Form('add_new_form_step', $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' => wu_convert_to_state($state), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'add_new_form_step', + $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' => wu_convert_to_state($state), + ), + ) + ); $form->render(); - - } // end render_add_new_form_step_modal; + } /** * Handles the form used to add a new step to the signup. @@ -1078,14 +1029,14 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $checkout_form = wu_get_checkout_form_by_slug(wu_request('checkout_form')); - if (!$checkout_form) { - - wp_send_json_error(new \WP_Error( - 'checkout-form-not-found', - __('The checkout form could not be found.', 'wp-ultimo') - )); - - } // end if; + if ( ! $checkout_form) { + wp_send_json_error( + new \WP_Error( + 'checkout-form-not-found', + __('The checkout form could not be found.', 'wp-ultimo') + ) + ); + } $data = array( 'id' => wu_request('id', ''), @@ -1098,15 +1049,16 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { 'fields' => array(), ); - wp_send_json_success(array( - 'send' => array( - 'scope' => 'wu_checkout_forms_editor_app', - 'function_name' => 'add_step', - 'data' => $data, - ), - )); - - } // end handle_add_new_form_step_modal; + wp_send_json_success( + array( + 'send' => array( + 'scope' => 'wu_checkout_forms_editor_app', + 'function_name' => 'add_step', + 'data' => $data, + ), + ) + ); + } /** * Get the required fields for a given field-type. @@ -1118,16 +1070,18 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { */ public function get_required_list($field_slug, $field_types): array { - $fields = \Arrch\Arrch::find($field_types, array( - 'sort_key' => 'order', - 'where' => array( - array('default_fields', '~', $field_slug), - ), - )); + $fields = \Arrch\Arrch::find( + $field_types, + array( + 'sort_key' => 'order', + 'where' => array( + array('default_fields', '~', $field_slug), + ), + ) + ); return array_keys($fields); - - } // end get_required_list; + } // Render JS Templates @@ -1139,11 +1093,13 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { */ public function render_steps() { - wu_get_template('base/checkout-forms/steps', array( - 'checkout_form' => $this->get_object()->get_slug(), - )); - - } // end render_steps; + wu_get_template( + 'base/checkout-forms/steps', + array( + 'checkout_form' => $this->get_object()->get_slug(), + ) + ); + } /** * Renders the Vue JS Templates. @@ -1153,11 +1109,13 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { */ public function render_js_templates() { - wu_get_template('base/checkout-forms/js-templates', array( - 'checkout_form' => $this->get_object()->get_slug(), - )); - - } // end render_js_templates; + wu_get_template( + 'base/checkout-forms/js-templates', + array( + 'checkout_form' => $this->get_object()->get_slug(), + ) + ); + } // Boilerplate @@ -1183,19 +1141,23 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $steps = $this->get_object()->get_settings(); - wp_localize_script('wu-checkout-form-editor', 'wu_checkout_form', array( - 'form_id' => $this->get_object()->get_id(), - 'checkout_form' => $this->get_object()->get_slug(), - 'register_page' => wu_get_registration_url(), - 'steps' => $steps, - 'headers' => array( - 'order' => __('Order', 'wp-ultimo'), - 'name' => __('Label', 'wp-ultimo'), - 'type' => __('Type', 'wp-ultimo'), - 'slug' => __('Slug', 'wp-ultimo'), - 'move' => '', - ), - )); + wp_localize_script( + 'wu-checkout-form-editor', + 'wu_checkout_form', + array( + 'form_id' => $this->get_object()->get_id(), + 'checkout_form' => $this->get_object()->get_slug(), + 'register_page' => wu_get_registration_url(), + 'steps' => $steps, + 'headers' => array( + 'order' => __('Order', 'wp-ultimo'), + 'name' => __('Label', 'wp-ultimo'), + 'type' => __('Type', 'wp-ultimo'), + 'slug' => __('Slug', 'wp-ultimo'), + 'move' => '', + ), + ) + ); wp_enqueue_script('wu-checkout-form-editor'); @@ -1203,8 +1165,7 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { 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_style('wu-checkout-form-editor', wu_get_asset('checkout-editor.css', 'css')); - - } // end register_scripts; + } /** * Returns the array of thank you page fields, based on the element. @@ -1221,22 +1182,16 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $new_fields = array(); foreach ($fields as $index => $field) { - if ($field['type'] === 'header') { - continue; - - } // end if; + } if (wu_get_isset($thank_you_settings, $index)) { + $field['value'] = $thank_you_settings[ $index ]; + } - $field['value'] = $thank_you_settings[$index]; - - } // end if; - - $new_fields["meta[wu_thank_you_settings][$index]"] = $field; - - } // end foreach; + $new_fields[ "meta[wu_thank_you_settings][$index]" ] = $field; + } $placeholders = array( 'CUSTOMER_ID', @@ -1262,8 +1217,7 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { ); return $new_fields; - - } // end get_thank_you_page_fields; + } /** * Returns the values of the thank you page settings. @@ -1278,8 +1232,7 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $settings = wp_parse_args($this->get_object()->get_meta('wu_thank_you_settings'), $defaults); return $settings; - - } // end get_thank_you_settings; + } /** * Allow child classes to register widgets, if they need them. @@ -1291,167 +1244,183 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { parent::register_widgets(); - $this->add_tabs_widget('advanced', array( - 'title' => __('Advanced Options', 'wp-ultimo'), - 'position' => 'advanced', - 'html_attr' => array( - 'data-on-load' => 'wu_initialize_code_editors', - ), - 'sections' => array( - 'thank-you' => array( - 'title' => __('Thank You', 'wp-ultimo'), - 'desc' => __('Configure the Thank You page for this Checkout Form.', 'wp-ultimo'), - 'icon' => 'dashicons-wu-emoji-happy', - 'state' => array( - 'enable_thank_you_page' => $this->get_object()->has_thank_you_page(), - 'thank_you_page' => $this->get_object()->get_thank_you_page_id(), - ), - 'fields' => $this->get_thank_you_page_fields(), + $this->add_tabs_widget( + 'advanced', + array( + 'title' => __('Advanced Options', 'wp-ultimo'), + 'position' => 'advanced', + 'html_attr' => array( + 'data-on-load' => 'wu_initialize_code_editors', ), - 'scripts' => array( - 'title' => __('Scripts', 'wp-ultimo'), - 'desc' => __('Configure the Thank You page for this Checkout Form.', 'wp-ultimo'), - 'icon' => 'dashicons-wu-code', - 'state' => array( - 'enable_thank_you_page' => $this->get_object()->has_thank_you_page(), - 'thank_you_page' => $this->get_object()->get_thank_you_page_id(), - ), - 'fields' => array( - 'custom_css' => array( - 'type' => 'code-editor', - 'title' => __('Custom CSS', 'wp-ultimo'), - 'desc' => __('Add custom CSS code to your checkout form. SCSS syntax is supported.', 'wp-ultimo'), - 'value' => $this->get_object()->get_custom_css(), - 'lang' => 'css', + 'sections' => array( + 'thank-you' => array( + 'title' => __('Thank You', 'wp-ultimo'), + 'desc' => __('Configure the Thank You page for this Checkout Form.', 'wp-ultimo'), + 'icon' => 'dashicons-wu-emoji-happy', + 'state' => array( + 'enable_thank_you_page' => $this->get_object()->has_thank_you_page(), + 'thank_you_page' => $this->get_object()->get_thank_you_page_id(), ), + 'fields' => $this->get_thank_you_page_fields(), ), - ), - 'restrictions' => array( - 'title' => __('Restrictions', 'wp-ultimo'), - 'desc' => __('Control the access to this checkout form.', 'wp-ultimo'), - 'icon' => 'dashicons-wu-block', - 'state' => array( - 'restrict_by_country' => $this->get_object()->has_country_lock(), - ), - 'fields' => array( - 'restrict_by_country' => array( - 'type' => 'toggle', - 'title' => __('Restrict by Country', 'wp-ultimo'), - 'desc' => __('Restrict this checkout form to specific countries.', 'wp-ultimo'), - 'html_attr' => array( - 'v-model' => 'restrict_by_country', - ) + 'scripts' => array( + 'title' => __('Scripts', 'wp-ultimo'), + 'desc' => __('Configure the Thank You page for this Checkout Form.', 'wp-ultimo'), + 'icon' => 'dashicons-wu-code', + 'state' => array( + 'enable_thank_you_page' => $this->get_object()->has_thank_you_page(), + 'thank_you_page' => $this->get_object()->get_thank_you_page_id(), ), - 'allowed_countries' => array( - 'type' => 'select', - 'title' => __('Allowed Countries', 'wp-ultimo'), - 'desc' => __('Select the allowed countries.', 'wp-ultimo'), - 'placeholder' => __('Type to search countries...', 'wp-ultimo'), - 'options' => 'wu_get_countries', - 'value' => $this->get_object()->get_allowed_countries(), - 'wrapper_html_attr' => array( - 'v-show' => 'require("restrict_by_country", true)' + 'fields' => array( + 'custom_css' => array( + 'type' => 'code-editor', + 'title' => __('Custom CSS', 'wp-ultimo'), + 'desc' => __('Add custom CSS code to your checkout form. SCSS syntax is supported.', 'wp-ultimo'), + 'value' => $this->get_object()->get_custom_css(), + 'lang' => 'css', + ), + ), + ), + 'restrictions' => array( + 'title' => __('Restrictions', 'wp-ultimo'), + 'desc' => __('Control the access to this checkout form.', 'wp-ultimo'), + 'icon' => 'dashicons-wu-block', + 'state' => array( + 'restrict_by_country' => $this->get_object()->has_country_lock(), + ), + 'fields' => array( + 'restrict_by_country' => array( + 'type' => 'toggle', + 'title' => __('Restrict by Country', 'wp-ultimo'), + 'desc' => __('Restrict this checkout form to specific countries.', 'wp-ultimo'), + 'html_attr' => array( + 'v-model' => 'restrict_by_country', + ), + ), + 'allowed_countries' => array( + 'type' => 'select', + 'title' => __('Allowed Countries', 'wp-ultimo'), + 'desc' => __('Select the allowed countries.', 'wp-ultimo'), + 'placeholder' => __('Type to search countries...', 'wp-ultimo'), + 'options' => 'wu_get_countries', + 'value' => $this->get_object()->get_allowed_countries(), + 'wrapper_html_attr' => array( + 'v-show' => 'require("restrict_by_country", true)', + ), + 'html_attr' => array( + 'v-cloak' => 1, + 'data-selectize' => 1, + 'multiple' => true, + ), ), - 'html_attr' => array( - 'v-cloak' => 1, - 'data-selectize' => 1, - 'multiple' => true, - ) ), ), ), - ), - )); + ) + ); - $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'), - 'position' => 'advanced', - )); + $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'), + 'position' => 'advanced', + ) + ); - $this->add_save_widget('save', array( - 'html_attr' => array( - 'data-wu-app' => 'checkout-form', - 'data-state' => wu_convert_to_state(array( - 'original_slug' => $this->get_object()->get_slug(), - 'slug' => $this->get_object()->get_slug(), - )), - ), - 'fields' => array( - 'slug' => array( - 'type' => 'text', - 'title' => __('Checkout Form Slug', 'wp-ultimo'), - 'desc' => __('This is used to create shortcodes and more.', 'wp-ultimo'), - 'value' => $this->get_object()->get_slug(), - 'wrapper_html_attr' => array( - 'v-cloak' => '1', - ), - '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' => 'checkout-form', + 'data-state' => wu_convert_to_state( + array( + 'original_slug' => $this->get_object()->get_slug(), + 'slug' => $this->get_object()->get_slug(), + ) ), ), - 'slug_change_note' => array( - 'type' => 'note', - 'desc' => __('You are changing the form slug. If you save this change, all the shortcodes and blocks referencing this slug will stop working until you update them with the new slug.', 'wp-ultimo'), - 'classes' => 'wu-p-2 wu-bg-yellow-200 wu-text-yellow-700 wu-rounded wu-w-full', - 'wrapper_html_attr' => array( - 'v-show' => '(original_slug != slug) && slug', - 'v-cloak' => '1', + 'fields' => array( + 'slug' => array( + 'type' => 'text', + 'title' => __('Checkout Form Slug', 'wp-ultimo'), + 'desc' => __('This is used to create shortcodes and more.', 'wp-ultimo'), + 'value' => $this->get_object()->get_slug(), + 'wrapper_html_attr' => array( + 'v-cloak' => '1', + ), + 'html_attr' => array( + 'required' => 'required', + 'v-on:input' => 'slug = $event.target.value.toLowerCase().replace(/[^a-z0-9-_]+/g, "")', + 'v-bind:value' => 'slug', + ), + ), + 'slug_change_note' => array( + 'type' => 'note', + 'desc' => __('You are changing the form slug. If you save this change, all the shortcodes and blocks referencing this slug will stop working until you update them with the new slug.', 'wp-ultimo'), + 'classes' => 'wu-p-2 wu-bg-yellow-200 wu-text-yellow-700 wu-rounded wu-w-full', + 'wrapper_html_attr' => array( + 'v-show' => '(original_slug != slug) && slug', + 'v-cloak' => '1', + ), ), ), - ), - )); + ) + ); - $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 checkout form.', '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 checkout form.', 'wp-ultimo'), + 'value' => $this->get_object()->is_active(), + ), ), - ), - )); + ) + ); - \WP_Ultimo\UI\Tours::get_instance()->create_tour('checkout-form-editor', array( + \WP_Ultimo\UI\Tours::get_instance()->create_tour( + 'checkout-form-editor', array( - 'id' => 'checkout-form-editor', - 'title' => __('Welcome to the Checkout Form builder!', 'wp-ultimo'), - 'text' => array( - __('You should be able to create registration forms in any way, shape, and form you desire. This editor allows you to do just that 😃', 'wp-ultimo'), - __('Want a registration form with multiple steps? Check! A single step? Check! Control the visibility of certain steps and fields based on the context of the customer? Check!', 'wp-ultimo'), + array( + 'id' => 'checkout-form-editor', + 'title' => __('Welcome to the Checkout Form builder!', 'wp-ultimo'), + 'text' => array( + __('You should be able to create registration forms in any way, shape, and form you desire. This editor allows you to do just that 😃', 'wp-ultimo'), + __('Want a registration form with multiple steps? Check! A single step? Check! Control the visibility of certain steps and fields based on the context of the customer? Check!', 'wp-ultimo'), + ), ), - ), - array( - 'id' => 'add-new-step', - 'title' => __('Adding new Steps', 'wp-ultimo'), - 'text' => array( - __('To add a new step to the registration form, use this button here.', 'wp-ultimo'), + array( + 'id' => 'add-new-step', + 'title' => __('Adding new Steps', 'wp-ultimo'), + 'text' => array( + __('To add a new step to the registration form, use this button here.', 'wp-ultimo'), + ), + 'attachTo' => array( + 'element' => '#wp-ultimo-list-table-add-new-1 > div > div.wu-w-1\/2.wu-text-right > ul > li:nth-child(2) > a', + 'on' => 'left', + ), ), - 'attachTo' => array( - 'element' => '#wp-ultimo-list-table-add-new-1 > div > div.wu-w-1\/2.wu-text-right > ul > li:nth-child(2) > a', - 'on' => 'left', + array( + 'id' => 'add-new-field', + 'title' => __('Adding new Fields', 'wp-ultimo'), + 'text' => array( + __('To add a new field to a step, use this button here. You can add fields to capture additional data from your customers and use that data to populate site templates.', 'wp-ultimo'), + sprintf('%s', wu_get_documentation_url('wp-ultimo-populate-site-template'), __('You can learn more about that here →', 'wp-ultimo')), + ), + 'attachTo' => array( + 'element' => '#wp-ultimo-list-table-checkout > div.inside > div.wu-bg-gray-100.wu-px-4.wu-py-3.wu--m-3.wu-mt-3.wu-border-t.wu-border-l-0.wu-border-r-0.wu-border-b-0.wu-border-gray-400.wu-border-solid.wu-text-right > ul > li:nth-child(3) > a', + 'on' => 'left', + ), ), - ), - array( - 'id' => 'add-new-field', - 'title' => __('Adding new Fields', 'wp-ultimo'), - 'text' => array( - __('To add a new field to a step, use this button here. You can add fields to capture additional data from your customers and use that data to populate site templates.', 'wp-ultimo'), - sprintf('%s', wu_get_documentation_url('wp-ultimo-populate-site-template'), __('You can learn more about that here →', 'wp-ultimo')), - ), - 'attachTo' => array( - 'element' => '#wp-ultimo-list-table-checkout > div.inside > div.wu-bg-gray-100.wu-px-4.wu-py-3.wu--m-3.wu-mt-3.wu-border-t.wu-border-l-0.wu-border-r-0.wu-border-b-0.wu-border-gray-400.wu-border-solid.wu-text-right > ul > li:nth-child(3) > a', - 'on' => 'left', - ), - ), - )); - - } // end register_widgets; + ) + ); + } /** * Returns the title of the page. @@ -1462,8 +1431,7 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { public function get_title() { return $this->edit ? __('Edit Checkout Form', 'wp-ultimo') : __('Add new Checkout Form', 'wp-ultimo'); - - } // end get_title; + } /** * Returns the title of menu for this page. @@ -1474,8 +1442,7 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { public function get_menu_title() { return __('Edit Checkout_Form', 'wp-ultimo'); - - } // end get_menu_title; + } /** * Returns the labels to be used on the admin page. @@ -1496,8 +1463,7 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { 'delete_button_label' => __('Delete Checkout Form', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), ); - - } // end get_labels; + } /** * Filters the list table to return only relevant events. @@ -1515,8 +1481,7 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { ); return array_merge($args, $extra_args); - - } // end query_filter; + } /** * Returns the object being edit at the moment. @@ -1527,28 +1492,23 @@ class Checkout_Form_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_checkout_form($item_id); - if (!$item) { - + if ( ! $item) { wp_redirect(wu_network_admin_url('wp-ultimo-checkout-forms')); exit; - - } // end if; + } $this->object = $item; return $this->object; - - } // end get_object; + } /** * Should implement the processes necessary to save the changes made to the object. @@ -1558,11 +1518,9 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { */ public function handle_save() { - if (!wu_request('restrict_by_country') || empty($_POST['allowed_countries'])) { - + if ( ! wu_request('restrict_by_country') || empty($_POST['allowed_countries'])) { $_POST['allowed_countries'] = array(); - - } // end if; + } $_POST['settings'] = json_decode(stripslashes((string) $_POST['_settings']), true); @@ -1577,8 +1535,7 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { $key = wp_get_session_token(); - if (!is_wp_error($object->validate())) { - + if ( ! is_wp_error($object->validate())) { $session = \WP_Session_Tokens::get_instance(get_current_user_id()); $session_data = $session->get($key); @@ -1586,12 +1543,10 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { unset($session_data['wu_checkout_form_editor']); $session->update($key, $session_data); - - } // end if; + } return wp_ob_end_flush_all(); - - } // end handle_save; + } /** * Checkout_Forms have titles. @@ -1601,7 +1556,5 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page { public function has_title(): bool { return true; - - } // end has_title; - -} // end class Checkout_Form_Edit_Admin_Page; + } +} diff --git a/inc/admin-pages/class-checkout-form-list-admin-page.php b/inc/admin-pages/class-checkout-form-list-admin-page.php index 70bd957..14c53ed 100644 --- a/inc/admin-pages/class-checkout-form-list-admin-page.php +++ b/inc/admin-pages/class-checkout-form-list-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-customer-edit-admin-page.php b/inc/admin-pages/class-customer-edit-admin-page.php index 6d16e0b..9e442d5 100644 --- a/inc/admin-pages/class-customer-edit-admin-page.php +++ b/inc/admin-pages/class-customer-edit-admin-page.php @@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages; // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Database\Memberships\Membership_Status; +use WP_Ultimo\Database\Memberships\Membership_Status; /** * WP Multisite WaaS Customer Edit/Add New Admin Page. @@ -94,14 +94,13 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { add_action('wu_page_edit_redirect_handlers', array($this, 'handle_send_verification_notice')); add_filter('removable_query_args', array($this, 'remove_query_args')); - - } // end hooks; + } /** * Allow child classes to register scripts and styles that can be loaded on the output function, for example. * - * @since 1.8.2 * @return void + * @since 1.8.2 */ public function register_scripts() { @@ -112,24 +111,26 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { wp_enqueue_editor(); wp_enqueue_media(); - - } // end register_scripts; + } /** * Register ajax forms that we use for membership. * - * @since 2.0.0 * @return void + * @since 2.0.0 */ public function register_forms() { /* * Transfer customer - Confirmation modal */ - wu_register_form('transfer_customer', array( - 'render' => array($this, 'render_transfer_customer_modal'), - 'handler' => array($this, 'handle_transfer_customer_modal'), - 'capability' => 'wu_transfer_customer', - )); + wu_register_form( + 'transfer_customer', + array( + 'render' => array($this, 'render_transfer_customer_modal'), + 'handler' => array($this, 'handle_transfer_customer_modal'), + 'capability' => 'wu_transfer_customer', + ) + ); /* * Adds the hooks to handle deletion. @@ -139,24 +140,21 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { add_filter('wu_form_attributes_delete_customer_modal', array($this, 'customer_extra_form_attributes')); add_action('wu_after_delete_customer_modal', array($this, 'customer_after_delete_actions')); - - } // end register_forms; + } /** * Renders the transfer confirmation form. * - * @since 2.0.0 * @return void + * @since 2.0.0 */ public function render_transfer_customer_modal() { $user = wu_get_customer(wu_request('id')); - if (!$user) { - + if ( ! $user) { return; - - } // end if; + } $fields = array( 'confirm' => array( @@ -188,27 +186,32 @@ class Customer_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_customer', - '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_customer', + 'data-state' => wp_json_encode( + array( + 'confirmed' => false, + ) + ), + ), + ) + ); $form->render(); - - } // end render_transfer_customer_modal; + } /** * Handles the transfer of customer. * - * @since 2.0.0 * @return void + * @since 2.0.0 */ public function handle_transfer_customer_modal() { @@ -217,43 +220,41 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { $customer = wu_get_customer(wu_request('id')); $target_user = get_user_by('id', wu_request('target_user_id')); - if (!$customer) { - + if ( ! $customer) { wp_send_json_error(new \WP_Error('not-found', __('Customer not found.', 'wp-ultimo'))); + } - } // end if; - - if (!$target_user) { - + if ( ! $target_user) { wp_send_json_error(new \WP_Error('not-found', __('User not found.', 'wp-ultimo'))); - - } // end if; + } $customer->set_user_id($target_user->ID); $saved = $customer->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-customer', array( - 'id' => $customer->get_id(), - )) - )); - - } // end handle_transfer_customer_modal; + wp_send_json_success( + array( + 'redirect_url' => wu_network_admin_url( + 'wp-ultimo-edit-customer', + array( + 'id' => $customer->get_id(), + ) + ), + ) + ); + } /** * Adds the extra fields to the customer delete modal. * - * @since 2.0.0 - * * @param array $fields original array of fields. * @param object $customer The customer object. + * + * @since 2.0.0 */ public function customer_extra_delete_fields($fields, $customer): array { @@ -277,7 +278,7 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { 'data-label-field' => 'display_name', 'data-search-field' => 'display_name', 'data-max-items' => 1, - 'data-exclude' => json_encode(array($customer->get_id())), + 'data-exclude' => wp_json_encode(array($customer->get_id())), ), 'wrapper_html_attr' => array( 'v-show' => '!delete_all_confirmed', @@ -285,29 +286,24 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { ), ); - if (!current_user_can('wu_delete_sites') || !current_user_can('wu_delete_memberships') || !current_user_can('wu_delete_payments')) { - + if ( ! current_user_can('wu_delete_sites') || ! current_user_can('wu_delete_memberships') || ! current_user_can('wu_delete_payments')) { unset($custom_fields['delete_all']); + } - } // end if; - - if (!current_user_can('wu_transfer_sites') || !current_user_can('wu_transfer_memberships') || !current_user_can('wu_edit_payments')) { - + if ( ! current_user_can('wu_transfer_sites') || ! current_user_can('wu_transfer_memberships') || ! current_user_can('wu_edit_payments')) { unset($custom_fields['re_assignment_customer_id']); - - } // end if; + } return array_merge($custom_fields, $fields); - - } // end customer_extra_delete_fields; + } /** * Adds the extra form attributes to the delete modal. * - * @since 2.0.0 - * * @param array $form_attributes Form attributes. + * * @return array + * @since 2.0.0 */ public function customer_extra_form_attributes($form_attributes) { @@ -315,89 +311,93 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { $custom_state['delete_all_confirmed'] = false; - $form_attributes['html_attr']['data-state'] = json_encode($custom_state); + $form_attributes['html_attr']['data-state'] = wp_json_encode($custom_state); return $form_attributes; - - } // end customer_extra_form_attributes; + } /** * Enqueues actions to be run after a customer is deleted. * - * @since 2.0.0 - * * @param object $customer The customer object. + * * @return void + * @since 2.0.0 */ public function customer_after_delete_actions($customer) { $delete_all = wu_request('delete_all'); if ($delete_all) { - foreach ($customer->get_memberships() as $membership) { /** - * Enqueue task - */ - wu_enqueue_async_action('wu_async_delete_membership', array( - 'membership_id' => $membership->get_id(), - ), 'membership'); - - } // end foreach; + * Enqueue task + */ + wu_enqueue_async_action( + 'wu_async_delete_membership', + array( + 'membership_id' => $membership->get_id(), + ), + 'membership' + ); + } foreach ($customer->get_payments() as $payment) { /** - * Enqueue task - */ - wu_enqueue_async_action('wu_async_delete_payment', array( - 'payment_id' => $payment->get_id(), - ), 'payment'); - - } // end foreach; - + * Enqueue task + */ + wu_enqueue_async_action( + 'wu_async_delete_payment', + array( + 'payment_id' => $payment->get_id(), + ), + 'payment' + ); + } } else { - $re_assignment_customer = wu_get_customer(wu_request('re_assignment_customer_id')); if ($re_assignment_customer) { - foreach ($customer->get_memberships() as $membership) { /** * Enqueue task */ - wu_enqueue_async_action('wu_async_transfer_membership', array( - 'membership_id' => $membership->get_id(), - 'target_customer_id' => $re_assignment_customer->get_id(), - ), 'membership'); - - } // end foreach; + wu_enqueue_async_action( + 'wu_async_transfer_membership', + array( + 'membership_id' => $membership->get_id(), + 'target_customer_id' => $re_assignment_customer->get_id(), + ), + 'membership' + ); + } foreach ($customer->get_payments() as $payment) { /** * Enqueue to the future */ - wu_enqueue_async_action('wu_async_transfer_payment', array( - 'payment_id' => $payment->get_id(), - 'target_customer_id' => $re_assignment_customer->get_id(), - ), 'payment'); - - } // end foreach; - - } // end if; - - } // end if; - - } // end customer_after_delete_actions; + wu_enqueue_async_action( + 'wu_async_transfer_payment', + array( + 'payment_id' => $payment->get_id(), + 'target_customer_id' => $re_assignment_customer->get_id(), + ), + 'payment' + ); + } + } + } + } /** * Generates the list of meta fields. * - * @since 2.0.11 * @return array + * @since 2.0.11 */ public function generate_customer_meta_fields() { @@ -408,20 +408,22 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { $meta_fields_unset = array(); foreach ($custom_meta_keys as $key => $value) { - - $field_location_breadcrumbs = array(__('orphan field - the original form no longer exists', 'wp-ultimo')); + $field_location_breadcrumbs = array( + __( + 'orphan field - the original form no longer exists', + 'wp-ultimo' + ), + ); $form = wu_get_isset($value, 'form'); if ($form) { - $field_location_breadcrumbs = array( $form, wu_get_isset($value, 'step'), wu_get_isset($value, 'id'), ); - - } // end if; + } $location = sprintf( '%s %s', @@ -432,13 +434,11 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { $options = wu_get_isset($value, 'options', array()); if ($options) { - $options = array_combine( array_column($options, 'key'), array_column($options, 'label') ); - - } // end if; + } $options = array_merge(array('' => '--'), $options); @@ -452,61 +452,51 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { ); if ($field_data['type'] === 'hidden') { - $field_data['type'] = 'text'; - - } // end if; + } if ($field_data['type'] === 'image') { - $image_attributes = wp_get_attachment_image_src((int) $field_data['value'], 'full'); $field_data['img'] = $image_attributes ? $image_attributes[0] : ''; - - } // end if; + } if (wu_get_isset($value, 'exists')) { - - $meta_fields_set["meta_key_$key"] = $field_data; - + $meta_fields_set[ "meta_key_$key" ] = $field_data; } else { - $field_data['wrapper_html_attr'] = array( 'v-show' => 'display_unset_fields', ); - $meta_fields_unset["meta_key_$key"] = $field_data; - - } // end if; - - } // end foreach; + $meta_fields_unset[ "meta_key_$key" ] = $field_data; + } + } $collapsible_header = array(); if ($meta_fields_unset) { - $collapsible_header['display_unset_fields'] = array( 'title' => __('Display unset fields', 'wp-ultimo'), - 'desc' => __('If fields were added after the customer creation or onto a different form, they will not have a set value for this customer. You can manually set those here.', 'wp-ultimo'), + 'desc' => __( + 'If fields were added after the customer creation or onto a different form, they will not have a set value for this customer. You can manually set those here.', + 'wp-ultimo' + ), 'type' => 'toggle', 'wrapper_classes' => 'wu-bg-gray-100', 'html_attr' => array( 'v-model' => 'display_unset_fields', - ) + ), ); - - } // end if; + } $final_fields = array_merge($meta_fields_set, $collapsible_header, $meta_fields_unset); if (empty($final_fields)) { - $final_fields['empty'] = array( 'type' => 'note', 'desc' => __('No custom meta data collected and no custom fields found.', 'wp-ultimo'), 'classes' => 'wu-text-center', ); - - } // end if; + } $final_fields['display_new_meta_repeater'] = array( 'title' => __('Manually add custom meta fields', 'wp-ultimo'), @@ -515,16 +505,16 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { 'wrapper_classes' => 'wu-bg-gray-100', 'html_attr' => array( 'v-model' => 'new_meta_fields_show', - ) + ), ); - $default_meta_value = fn (string $type, $value = '', bool $is_default = false) => array( + $default_meta_value = fn(string $type, $value = '', bool $is_default = false) => array( 'title' => __('Value', 'wp-ultimo'), 'type' => $type, 'value' => $value, 'wrapper_classes' => 'wu-w-1/4 wu-ml-2', 'wrapper_html_attr' => array( - 'v-show' => ($is_default ? '!new_meta_field.type || ' : '') . "new_meta_field.type === '$type'" + 'v-show' => ($is_default ? '!new_meta_field.type || ' : '') . "new_meta_field.type === '$type'", ), 'html_attr' => array( 'v-model' => 'new_meta_field.value', @@ -542,7 +532,10 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { 'fields' => array( 'new_meta_remove' => array( 'type' => 'note', - 'desc' => sprintf('', __('Remove', 'wp-ultimo')), + 'desc' => sprintf( + '', + __('Remove', 'wp-ultimo') + ), 'wrapper_classes' => 'wu-absolute wu-top-0 wu-right-0', ), 'new_meta_slug' => array( @@ -566,17 +559,17 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { ), ), 'new_meta_type' => array( - 'title' => __('Type', 'wp-ultimo'), - 'type' => 'select', - 'options' => array( + 'title' => __('Type', 'wp-ultimo'), + 'type' => 'select', + 'options' => array( 'text' => __('Text', 'wp-ultimo'), 'textarea' => __('Textarea', 'wp-ultimo'), 'checkbox' => __('Checkbox', 'wp-ultimo'), 'color' => __('Color', 'wp-ultimo'), 'image' => __('Image', 'wp-ultimo'), ), - 'wrapper_classes' => 'wu-w-1/4 wu-ml-2', - 'html_attr' => array( + 'wrapper_classes' => 'wu-w-1/4 wu-ml-2', + 'html_attr' => array( 'v-model' => 'new_meta_field.type', 'v-bind:name' => '"new_meta_fields[" + index + "][type]"', ), @@ -594,18 +587,18 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { ), ), ), - 'repeat_option' => array( - 'type' => 'submit', - 'title' => __('+ Add meta field', 'wp-ultimo'), - 'classes' => 'button wu-self-end', - 'wrapper_classes' => 'wu-bg-whiten wu-items-end', - 'html_attr' => array( + 'repeat_option' => array( + 'type' => 'submit', + 'title' => __('+ Add meta field', 'wp-ultimo'), + 'classes' => 'button wu-self-end', + 'wrapper_classes' => 'wu-bg-whiten wu-items-end', + 'html_attr' => array( 'v-on:click.prevent' => '() => new_meta_fields.push({ type: "text", slug: "", })', ), - ) + ), ); $final_fields['new_meta_fields_wrapper'] = array( @@ -614,18 +607,17 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { 'wrapper_html_attr' => array( 'v-show' => 'new_meta_fields_show', ), - 'fields' => $new_meta_fields + 'fields' => $new_meta_fields, ); return $final_fields; - - } // end generate_customer_meta_fields; + } /** * Allow child classes to register widgets, if they need them. * - * @since 1.8.2 * @return void + * @since 1.8.2 */ public function register_widgets() { @@ -633,80 +625,98 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { $labels = $this->get_labels(); - $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/3 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( - 'id' => array( - 'type' => 'text-display', - 'copy' => true, - 'title' => __('Customer ID', 'wp-ultimo'), - 'display_value' => $this->get_object()->get_id(), - '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/3 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;', ), - 'last_login' => array( - 'edit' => false, - 'title' => __('Last Login', 'wp-ultimo'), - 'type' => 'text-edit', - 'value' => $this->edit ? $this->get_object()->get_last_login(false) : __('No date', 'wp-ultimo'), - 'display_value' => $this->edit ? $this->get_object()->get_last_login(false) : false, - ), - 'total_grossed' => array( - 'type' => 'text-display', - 'title' => __('Total Grossed', 'wp-ultimo'), - 'display_value' => wu_format_currency($this->get_object()->get_total_grossed()), - 'tooltip' => '', - ), - ), - )); - - $this->add_list_table_widget('memberships', array( - 'title' => __('Memberships', 'wp-ultimo'), - 'table' => new \WP_Ultimo\List_Tables\Customers_Membership_List_Table(), - 'query_filter' => array($this, 'memberships_query_filter'), - )); - - $this->add_tabs_widget('options', array( - 'title' => __('Customer Options', 'wp-ultimo'), - 'position' => 'normal', - 'sections' => apply_filters('wu_customer_options_sections', array( - 'general' => array( - 'title' => __('General', 'wp-ultimo'), - 'desc' => __('General options for the customer.', 'wp-ultimo'), - 'icon' => 'dashicons-wu-globe', - 'fields' => array( - 'vip' => array( - 'type' => 'toggle', - 'title' => __('VIP', 'wp-ultimo'), - 'desc' => __('Set this customer as a VIP.', 'wp-ultimo'), - 'tooltip' => '', - 'value' => $this->get_object()->is_vip(), + 'fields' => array( + 'id' => array( + 'type' => 'text-display', + 'copy' => true, + 'title' => __('Customer ID', 'wp-ultimo'), + 'display_value' => $this->get_object()->get_id(), + 'tooltip' => '', + ), + 'last_login' => array( + 'edit' => false, + 'title' => __('Last Login', 'wp-ultimo'), + 'type' => 'text-edit', + 'value' => $this->edit ? $this->get_object()->get_last_login(false) : __( + 'No date', + 'wp-ultimo' ), + 'display_value' => $this->edit ? $this->get_object()->get_last_login(false) : false, + ), + 'total_grossed' => array( + 'type' => 'text-display', + 'title' => __('Total Grossed', 'wp-ultimo'), + 'display_value' => wu_format_currency($this->get_object()->get_total_grossed()), + 'tooltip' => '', ), ), - 'billing_info' => array( - 'title' => __('Billing Info', 'wp-ultimo'), - 'desc' => __('Billing information for this particular customer', 'wp-ultimo'), - 'icon' => 'dashicons-wu-address', - 'fields' => $this->get_object()->get_billing_address()->get_fields(), - ), - 'custom_meta' => array( - 'title' => __('Custom Meta', 'wp-ultimo'), - 'desc' => __('Custom data collected via WP Multisite WaaS forms.', 'wp-ultimo'), - 'icon' => 'dashicons-wu-database wu-pt-px', - 'fields' => $this->generate_customer_meta_fields(), - 'state' => array( - 'display_unset_fields' => false, - 'new_meta_fields_show' => false, - 'new_meta_fields' => array(array('type' => 'text', 'slug' => '')), - ), - ), - // @todo: bring these back + ) + ); + + $this->add_list_table_widget( + 'memberships', + array( + 'title' => __('Memberships', 'wp-ultimo'), + 'table' => new \WP_Ultimo\List_Tables\Customers_Membership_List_Table(), + 'query_filter' => array($this, 'memberships_query_filter'), + ) + ); + + $this->add_tabs_widget( + 'options', + array( + 'title' => __('Customer Options', 'wp-ultimo'), + 'position' => 'normal', + 'sections' => apply_filters( + 'wu_customer_options_sections', + array( + 'general' => array( + 'title' => __('General', 'wp-ultimo'), + 'desc' => __('General options for the customer.', 'wp-ultimo'), + 'icon' => 'dashicons-wu-globe', + 'fields' => array( + 'vip' => array( + 'type' => 'toggle', + 'title' => __('VIP', 'wp-ultimo'), + 'desc' => __('Set this customer as a VIP.', 'wp-ultimo'), + 'tooltip' => '', + 'value' => $this->get_object()->is_vip(), + ), + ), + ), + 'billing_info' => array( + 'title' => __('Billing Info', 'wp-ultimo'), + 'desc' => __('Billing information for this particular customer', 'wp-ultimo'), + 'icon' => 'dashicons-wu-address', + 'fields' => $this->get_object()->get_billing_address()->get_fields(), + ), + 'custom_meta' => array( + 'title' => __('Custom Meta', 'wp-ultimo'), + 'desc' => __('Custom data collected via WP Multisite WaaS forms.', 'wp-ultimo'), + 'icon' => 'dashicons-wu-database wu-pt-px', + 'fields' => $this->generate_customer_meta_fields(), + 'state' => array( + 'display_unset_fields' => false, + 'new_meta_fields_show' => false, + 'new_meta_fields' => array( + array( + 'type' => 'text', + 'slug' => '', + ), + ), + ), + ), + // @todo: bring these back // phpcs:disable // 'payment_methods' => array( // 'title' => __('Payment Methods', 'wp-ultimo'), @@ -715,179 +725,216 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { // 'fields' => apply_filters('wu_customer_payment_methods', array(), $this->get_object(), $this), // ), // phpcs:enable - ), $this->get_object()), - )); + ), + $this->get_object() + ), + ) + ); - $this->add_list_table_widget('payments', array( - 'title' => __('Payments', 'wp-ultimo'), - 'table' => new \WP_Ultimo\List_Tables\Customers_Payment_List_Table(), - 'query_filter' => array($this, 'memberships_query_filter'), - )); + $this->add_list_table_widget( + 'payments', + array( + 'title' => __('Payments', 'wp-ultimo'), + 'table' => new \WP_Ultimo\List_Tables\Customers_Payment_List_Table(), + 'query_filter' => array($this, 'memberships_query_filter'), + ) + ); - $this->add_list_table_widget('sites', array( - 'title' => __('Sites', 'wp-ultimo'), - 'table' => new \WP_Ultimo\List_Tables\Customers_Site_List_Table(), - 'query_filter' => array($this, 'sites_query_filter'), - )); + $this->add_list_table_widget( + 'sites', + array( + 'title' => __('Sites', 'wp-ultimo'), + 'table' => new \WP_Ultimo\List_Tables\Customers_Site_List_Table(), + 'query_filter' => array($this, 'sites_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_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_fields_widget('save', array( - 'html_attr' => array( - 'data-wu-app' => 'customer_save', - 'data-state' => json_encode(array( - 'original_user_id' => $this->get_object()->get_user_id(), - 'user_id' => $this->get_object()->get_user_id(), - 'original_email_verification' => $this->get_object()->get_email_verification(), - 'email_verification' => $this->get_object()->get_email_verification(), - )), - ), - 'before' => wu_get_template_contents('customers/widget-avatar', array( - 'customer' => $this->get_object(), - 'user' => $this->get_object()->get_user(), - )), - 'fields' => array( - 'user_id' => array( - 'type' => 'model', - 'title' => __('User', 'wp-ultimo'), - 'placeholder' => __('Search WordPress user...', 'wp-ultimo'), - 'desc' => __('The WordPress user associated to this customer.', 'wp-ultimo'), - 'value' => $this->get_object()->get_user_id(), - 'tooltip' => '', - 'min' => 1, - 'html_attr' => array( - 'v-model' => 'user_id', - 'data-model' => 'user', - 'data-value-field' => 'ID', - 'data-label-field' => 'display_name', - 'data-search-field' => 'display_name', - 'data-max-items' => 1, - 'data-selected' => json_encode($this->get_object()->get_user()->data), - ), - 'wrapper_html_attr' => array( - 'v-cloak' => '1', + $this->add_fields_widget( + 'save', + array( + 'html_attr' => array( + 'data-wu-app' => 'customer_save', + 'data-state' => json_encode( + array( + 'original_user_id' => $this->get_object()->get_user_id(), + 'user_id' => $this->get_object()->get_user_id(), + 'original_email_verification' => $this->get_object()->get_email_verification(), + 'email_verification' => $this->get_object()->get_email_verification(), + ) ), ), - 'transfer_note' => array( - 'type' => 'note', - 'desc' => __('Changing the user will transfer the customer and all its assets to the new user.', '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_user_id != user_id) && user_id', - 'v-cloak' => '1', + 'before' => wu_get_template_contents( + 'customers/widget-avatar', + array( + 'customer' => $this->get_object(), + 'user' => $this->get_object()->get_user(), + ) + ), + 'fields' => array( + 'user_id' => array( + 'type' => 'model', + 'title' => __('User', 'wp-ultimo'), + 'placeholder' => __('Search WordPress user...', 'wp-ultimo'), + 'desc' => __('The WordPress user associated to this customer.', 'wp-ultimo'), + 'value' => $this->get_object()->get_user_id(), + 'tooltip' => '', + 'min' => 1, + 'html_attr' => array( + 'v-model' => 'user_id', + 'data-model' => 'user', + 'data-value-field' => 'ID', + 'data-label-field' => 'display_name', + 'data-search-field' => 'display_name', + 'data-max-items' => 1, + 'data-selected' => json_encode($this->get_object()->get_user()->data), + ), + 'wrapper_html_attr' => array( + 'v-cloak' => '1', + ), + ), + 'transfer_note' => array( + 'type' => 'note', + 'desc' => __( + 'Changing the user will transfer the customer and all its assets to the new user.', + '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_user_id != user_id) && user_id', + 'v-cloak' => '1', + ), + ), + 'email_verification' => array( + 'type' => 'select', + 'title' => __('Email Verification', 'wp-ultimo'), + 'placeholder' => __('Select Status', 'wp-ultimo'), + 'desc' => __( + 'The email verification status. This gets automatically switched to Verified when the customer verifies their email address.', + 'wp-ultimo' + ), + 'options' => array( + 'none' => __('None', 'wp-ultimo'), + 'pending' => __('Pending', 'wp-ultimo'), + 'verified' => __('Verified', 'wp-ultimo'), + ), + 'value' => $this->get_object()->get_email_verification(), + 'tooltip' => '', + 'wrapper_html_attr' => array( + 'v-cloak' => '1', + ), + 'html_attr' => array( + 'v-model' => 'email_verification', + ), + ), + 'confirm_membership' => array( + 'type' => 'toggle', + 'title' => __('Activate Memberships', 'wp-ultimo'), + 'desc' => __( + 'If you toggle this option, this change in status will also activate the related pending memberships. If any sites are pending, they are also going to be published automatically.', + 'wp-ultimo' + ), + 'value' => 0, + 'wrapper_html_attr' => array( + 'v-if' => 'email_verification !== original_email_verification && email_verification === "verified" && original_email_verification === "pending"', + 'v-cloak' => '1', + ), + ), + 'send_verification' => array( + 'type' => 'submit', + 'title' => __('Re-send Verification Email →', 'wp-ultimo'), + 'value' => 'send_verification', + 'classes' => 'button wu-w-full', + 'wrapper_html_attr' => array( + 'v-if' => 'email_verification === "pending" && original_email_verification == "pending"', + 'v-cloak' => '1', + ), + ), + 'submit_save' => array( + 'type' => 'submit', + 'title' => $labels['save_button_label'], + 'placeholder' => $labels['save_button_label'], + 'value' => 'save', + 'classes' => 'button button-primary wu-w-full', + 'wrapper_html_attr' => array( + 'v-show' => 'original_user_id == user_id || !user_id', + 'v-cloak' => '1', + ), + ), + 'transfer' => array( + 'type' => 'link', + 'display_value' => __('Transfer Customer', 'wp-ultimo'), + 'wrapper_classes' => 'wu-bg-gray-200', + 'classes' => 'button wubox wu-w-full wu-text-center', + 'wrapper_html_attr' => array( + 'v-show' => 'original_user_id != user_id && user_id', + 'v-cloak' => '1', + ), + 'html_attr' => array( + 'v-bind:href' => "'" . wu_get_form_url( + 'transfer_customer', + array( + 'id' => $this->get_object()->get_id(), + 'target_user_id' => '', + ) + ) . "=' + user_id", + 'title' => __('Transfer Customer', 'wp-ultimo'), + ), ), ), - 'email_verification' => array( - 'type' => 'select', - 'title' => __('Email Verification', 'wp-ultimo'), - 'placeholder' => __('Select Status', 'wp-ultimo'), - 'desc' => __('The email verification status. This gets automatically switched to Verified when the customer verifies their email address.', 'wp-ultimo'), - 'options' => array( - 'none' => __('None', 'wp-ultimo'), - 'pending' => __('Pending', 'wp-ultimo'), - 'verified' => __('Verified', 'wp-ultimo'), - ), - 'value' => $this->get_object()->get_email_verification(), - 'tooltip' => '', - 'wrapper_html_attr' => array( - 'v-cloak' => '1', - ), - 'html_attr' => array( - 'v-model' => 'email_verification', - ), - ), - 'confirm_membership' => array( - 'type' => 'toggle', - 'title' => __('Activate Memberships', 'wp-ultimo'), - 'desc' => __('If you toggle this option, this change in status will also activate the related pending memberships. If any sites are pending, they are also going to be published automatically.', 'wp-ultimo'), - 'value' => 0, - 'wrapper_html_attr' => array( - 'v-if' => 'email_verification !== original_email_verification && email_verification === "verified" && original_email_verification === "pending"', - 'v-cloak' => '1', - ), - ), - 'send_verification' => array( - 'type' => 'submit', - 'title' => __('Re-send Verification Email →', 'wp-ultimo'), - 'value' => 'send_verification', - 'classes' => 'button wu-w-full', - 'wrapper_html_attr' => array( - 'v-if' => 'email_verification === "pending" && original_email_verification == "pending"', - 'v-cloak' => '1', - ), - ), - 'submit_save' => array( - 'type' => 'submit', - 'title' => $labels['save_button_label'], - 'placeholder' => $labels['save_button_label'], - 'value' => 'save', - 'classes' => 'button button-primary wu-w-full', - 'wrapper_html_attr' => array( - 'v-show' => 'original_user_id == user_id || !user_id', - 'v-cloak' => '1', - ), - ), - 'transfer' => array( - 'type' => 'link', - 'display_value' => __('Transfer Customer', 'wp-ultimo'), - 'wrapper_classes' => 'wu-bg-gray-200', - 'classes' => 'button wubox wu-w-full wu-text-center', - 'wrapper_html_attr' => array( - 'v-show' => 'original_user_id != user_id && user_id', - 'v-cloak' => '1', - ), - 'html_attr' => array( - 'v-bind:href' => "'" . wu_get_form_url('transfer_customer', array( - 'id' => $this->get_object()->get_id(), - 'target_user_id' => '', - )) . "=' + user_id", - 'title' => __('Transfer Customer', 'wp-ultimo'), - ), - ), - ), - )); + ) + ); - $this->add_fields_widget('last-login', array( - 'title' => __('Last Login & IPs', 'wp-ultimo'), - 'fields' => array( - 'last_login' => array( - 'edit' => true, - 'title' => __('Last Login', 'wp-ultimo'), - 'type' => 'text-edit', - 'date' => true, - 'value' => $this->edit ? $this->get_object()->get_last_login(false) : __('No date', 'wp-ultimo'), - 'display_value' => $this->edit ? $this->get_object()->get_last_login(false) : false, - 'placeholder' => '2020-04-04 12:00:00', - 'html_attr' => array( - 'wu-datepicker' => 'true', - 'data-format' => 'Y-m-d H:i:S', - 'data-allow-time' => 'true', + $this->add_fields_widget( + 'last-login', + array( + 'title' => __('Last Login & IPs', 'wp-ultimo'), + 'fields' => array( + 'last_login' => array( + 'edit' => true, + 'title' => __('Last Login', 'wp-ultimo'), + 'type' => 'text-edit', + 'date' => true, + 'value' => $this->edit ? $this->get_object()->get_last_login(false) : __( + 'No date', + 'wp-ultimo' + ), + 'display_value' => $this->edit ? $this->get_object()->get_last_login(false) : false, + 'placeholder' => '2020-04-04 12:00:00', + 'html_attr' => array( + 'wu-datepicker' => 'true', + 'data-format' => 'Y-m-d H:i:S', + 'data-allow-time' => 'true', + ), + ), + 'ips' => array( + 'title' => __('IP Address', 'wp-ultimo'), + 'type' => 'text-edit', + 'display_value' => $this->get_object()->get_last_ip(), + ), + 'country' => array( + 'title' => __('IP Address Country', 'wp-ultimo'), + 'type' => 'text-edit', + 'display_value' => array($this, 'render_country'), ), ), - 'ips' => array( - 'title' => __('IP Address', 'wp-ultimo'), - 'type' => 'text-edit', - 'display_value' => $this->get_object()->get_last_ip(), - ), - 'country' => array( - 'title' => __('IP Address Country', 'wp-ultimo'), - 'type' => 'text-edit', - 'display_value' => array($this, 'render_country'), - ), - ), - )); - - } // end register_widgets; + ) + ); + } /** * Render the IP info flag. * - * @since 2.0.0 * @return string + * @since 2.0.0 */ public function render_country() { @@ -896,64 +943,57 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { $country_name = wu_get_country_name($country_code); if ($country_code) { - - $html = sprintf('%s', + $html = sprintf( + '%s', $country_name, strtolower((string) $country_code), wu_tooltip_text($country_name) ); - } else { - $html = $country_name; - - } // end if; + } return $html; - - } // end render_country; + } /** * Returns the title of the page. * - * @since 2.0.0 * @return string Title of the page. + * @since 2.0.0 */ public function get_title() { return $this->edit ? __('Edit Customer', 'wp-ultimo') : __('Add new Customer', 'wp-ultimo'); - - } // end get_title; + } /** * Returns the title of menu for this page. * - * @since 2.0.0 * @return string Menu label of the page. + * @since 2.0.0 */ public function get_menu_title() { return __('Edit Customer', 'wp-ultimo'); - - } // end get_menu_title; + } /** * Returns the action links for that page. * - * @since 1.8.2 * @return array + * @since 1.8.2 */ public function action_links() { return array(); - - } // end action_links; + } /** * Returns the labels to be used on the admin page. * - * @since 2.0.0 * @return array + * @since 2.0.0 */ public function get_labels() { @@ -968,32 +1008,30 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { 'delete_button_label' => __('Delete Customer', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), ); - - } // end get_labels; + } /** * Filters the list table to return only relevant events. * - * @since 2.0.0 - * * @param array $args Query args passed to the list table. + * * @return array Modified query args. + * @since 2.0.0 */ public function memberships_query_filter($args) { $args['customer_id'] = $this->get_object()->get_id(); return $args; - - } // end memberships_query_filter; + } /** * Filters the list table to return only relevant sites. * - * @since 2.0.0 - * * @param array $args Query args passed to the list table. + * * @return array Modified query args. + * @since 2.0.0 */ public function sites_query_filter($args) { @@ -1005,16 +1043,15 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { ); return $args; - - } // end sites_query_filter; + } /** * Filters the list table to return only relevant events. * - * @since 2.0.0 - * * @param array $args Query args passed to the list table. + * * @return array Modified query args. + * @since 2.0.0 */ public function events_query_filter($args) { @@ -1024,40 +1061,35 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { ); return array_merge($args, $extra_args); - - } // end events_query_filter; + } /** * Returns the object being edit at the moment. * - * @since 2.0.0 * @return \WP_Ultimo\Models\Customer + * @since 2.0.0 */ public function get_object() { if ($this->object !== null) { - return $this->object; - - } // end if; + } $item_id = wu_request('id', 0); $item = wu_get_customer($item_id); - if (!$item || $item->get_type() !== 'customer') { - + if ( ! $item || $item->get_type() !== 'customer') { wp_redirect(wu_network_admin_url('wp-ultimo-customers')); exit; - - } // end if; + } $this->object = $item; return $this->object; + } - } // end get_object; /** * Customers have titles. * @@ -1066,33 +1098,33 @@ class Customer_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. * - * @since 2.0.0 * @return void + * @since 2.0.0 */ public function handle_save() { if ($_POST['submit_button'] === 'send_verification') { - $customer = $this->get_object(); $customer->send_verification_email(); - $redirect_url = wu_network_admin_url('wp-ultimo-edit-customer', array( - 'id' => $customer->get_id(), - 'notice_verification_sent' => 1 - )); + $redirect_url = wu_network_admin_url( + 'wp-ultimo-edit-customer', + array( + 'id' => $customer->get_id(), + 'notice_verification_sent' => 1, + ) + ); wp_redirect($redirect_url); - exit; - - } // end if; + exit; + } $object = $this->get_object(); @@ -1105,14 +1137,12 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { $valid_address = $billing_address->validate(); if (is_wp_error($valid_address)) { - $errors = implode('
', $valid_address->get_error_messages()); WP_Ultimo()->notices->add($errors, 'error', 'network-admin'); return; - - } // end if; + } $object->set_billing_address($billing_address); @@ -1122,10 +1152,8 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { $should_confirm_membership = wu_request('confirm_membership', false); if ($should_confirm_membership) { - $this->confirm_memberships(); - - } // end if; + } /** * Deal with custom metadata @@ -1133,42 +1161,41 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { $custom_meta_keys = wu_get_all_customer_meta($this->get_object()->get_id(), true); foreach ($custom_meta_keys as $key => $value) { - - wu_update_customer_meta($object->get_id(), $key, wu_request("meta_key_$key"), $value['type'], $value['title']); - - } // end foreach; + wu_update_customer_meta( + $object->get_id(), + $key, + wu_request("meta_key_$key"), + $value['type'], + $value['title'] + ); + } foreach (wu_get_isset($_POST, 'new_meta_fields', array()) as $meta_field) { - $slug = sanitize_key(wu_get_isset($meta_field, 'slug', '')); if (empty($slug) || $this->restricted_customer_meta_keys($slug)) { - continue; + } - } // end if; - - $title = !empty($meta_field['title']) ? $meta_field['title'] : wu_slug_to_name($slug); - $type = !empty($meta_field['type']) ? $meta_field['type'] : 'text'; + $title = ! empty($meta_field['title']) ? $meta_field['title'] : wu_slug_to_name($slug); + $type = ! empty($meta_field['type']) ? $meta_field['type'] : 'text'; $value = wu_get_isset($meta_field, 'value', ''); wu_update_customer_meta($object->get_id(), $slug, $value, $type, $title); - - } // end foreach; + } unset($_POST['new_meta_fields']); parent::handle_save(); - - } // end handle_save; + } /** * Checks whether a meta slug is restricted or not. * - * @since 2.3.0 - * * @param string $meta_slug The meta slug to be verified. + * * @return bool + * @since 2.3.0 */ public function restricted_customer_meta_keys(string $meta_slug): bool { @@ -1182,71 +1209,60 @@ class Customer_Edit_Admin_Page extends Edit_Admin_Page { ); return in_array($meta_slug, $restricted_meta, true); - - } // end restricted_customer_meta_keys; + } /** * Handles the email verification sent notice * - * @since 2.0.0 * @return void + * @since 2.0.0 */ public function handle_send_verification_notice() { if (isset($_GET['notice_verification_sent'])) : ?>
-

+

get_object()->get_memberships(); foreach ($memberships as $membership) { - if ($membership->get_status() === Membership_Status::PENDING) { - $membership->set_status(Membership_Status::ACTIVE); $membership->save(); - - } // end if; - - } // end foreach; - - } // end confirm_memberships; - -} // end class Customer_Edit_Admin_Page; + } + } + } +} diff --git a/inc/admin-pages/class-customer-list-admin-page.php b/inc/admin-pages/class-customer-list-admin-page.php index dcd2cf1..b83212c 100644 --- a/inc/admin-pages/class-customer-list-admin-page.php +++ b/inc/admin-pages/class-customer-list-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-customizer-admin-page.php b/inc/admin-pages/class-customizer-admin-page.php index ef9c28a..2702e54 100644 --- a/inc/admin-pages/class-customizer-admin-page.php +++ b/inc/admin-pages/class-customizer-admin-page.php @@ -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() {} +} diff --git a/inc/admin-pages/class-dashboard-admin-page.php b/inc/admin-pages/class-dashboard-admin-page.php index d49fd01..bcff1e5 100644 --- a/inc/admin-pages/class-dashboard-admin-page.php +++ b/inc/admin-pages/class-dashboard-admin-page.php @@ -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 WP Multisite WaaS Dashboard, 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 WP Multisite WaaS Dashboard, 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'))); + } +} diff --git a/inc/admin-pages/class-discount-code-edit-admin-page.php b/inc/admin-pages/class-discount-code-edit-admin-page.php index f74c9b4..cc1c2c3 100644 --- a/inc/admin-pages/class-discount-code-edit-admin-page.php +++ b/inc/admin-pages/class-discount-code-edit-admin-page.php @@ -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 %s. The current time is %s', 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; + } +} diff --git a/inc/admin-pages/class-discount-code-list-admin-page.php b/inc/admin-pages/class-discount-code-list-admin-page.php index 60ef3a0..042a8f9 100644 --- a/inc/admin-pages/class-discount-code-list-admin-page.php +++ b/inc/admin-pages/class-discount-code-list-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-domain-edit-admin-page.php b/inc/admin-pages/class-domain-edit-admin-page.php index 8cf0939..fa364e7 100644 --- a/inc/admin-pages/class-domain-edit-admin-page.php +++ b/inc/admin-pages/class-domain-edit-admin-page.php @@ -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' => '' . $this->get_object()->get_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(), + $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' => '' . $this->get_object()->get_domain() . ' ', ), - '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; + } +} diff --git a/inc/admin-pages/class-domain-list-admin-page.php b/inc/admin-pages/class-domain-list-admin-page.php index 4e9d098..811d219 100644 --- a/inc/admin-pages/class-domain-list-admin-page.php +++ b/inc/admin-pages/class-domain-list-admin-page.php @@ -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 WP Multisite WaaS: Domain Seller 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; + } +} diff --git a/inc/admin-pages/class-edit-admin-page.php b/inc/admin-pages/class-edit-admin-page.php index bf63e45..fee0764 100644 --- a/inc/admin-pages/class-edit-admin-page.php +++ b/inc/admin-pages/class-edit-admin-page.php @@ -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('
%s
', __('Loading...', 'wp-ultimo')), + 'wrapper_html_attr' => array( + 'v-if' => 0, + ), + ); + } - $atts['fields']['loading'] = array( - 'type' => 'note', - 'desc' => sprintf('
%s
', __('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('
', $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('
', $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; + } +} diff --git a/inc/admin-pages/class-email-edit-admin-page.php b/inc/admin-pages/class-email-edit-admin-page.php index a75fb52..3c96967 100644 --- a/inc/admin-pages/class-email-edit-admin-page.php +++ b/inc/admin-pages/class-email-edit-admin-page.php @@ -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(' - %s - %s - ', $days_text, $hour_text); + $desc = sprintf( + '%s + %s', + $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 { 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; + } +} diff --git a/inc/admin-pages/class-email-list-admin-page.php b/inc/admin-pages/class-email-list-admin-page.php index 31bbdbb..84b75a0 100644 --- a/inc/admin-pages/class-email-list-admin-page.php +++ b/inc/admin-pages/class-email-list-admin-page.php @@ -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 = '
' . $system_email_value->get_title() . '
'; - $fields[$field_name] = array( + $fields[ $field_name ] = array( 'type' => 'toggle', 'title' => $field_title, 'desc' => $system_email_value->get_event() . ' ' . $system_email_target . '', @@ -366,14 +372,10 @@ class Email_List_Admin_Page extends List_Admin_Page { ); if (isset($fields['reset_note'])) { - unset($fields['reset_note']); - - } // end if; - - } // end if; - - } // end foreach; + } + } + } $fields['import_emails'] = array( 'type' => 'toggle', @@ -399,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 = '
' . $default_email_value['title'] . '
'; - $fields[$field_name] = array( + $fields[ $field_name ] = array( 'type' => 'toggle', 'title' => $field_title, 'desc' => $default_email_value['event'] . ' ' . $default_email_value['target'] . '', @@ -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 { 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; + } +} diff --git a/inc/admin-pages/class-email-template-customize-admin-page.php b/inc/admin-pages/class-email-template-customize-admin-page.php index 8d1f05a..8445a49 100644 --- a/inc/admin-pages/class-email-template-customize-admin-page.php +++ b/inc/admin-pages/class-email-template-customize-admin-page.php @@ -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 .= ' @@ -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; + } +} diff --git a/inc/admin-pages/class-event-list-admin-page.php b/inc/admin-pages/class-event-list-admin-page.php index 0e14338..57adf47 100644 --- a/inc/admin-pages/class-event-list-admin-page.php +++ b/inc/admin-pages/class-event-list-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-event-view-admin-page.php b/inc/admin-pages/class-event-view-admin-page.php index 8613db9..d431e9c 100644 --- a/inc/admin-pages/class-event-view-admin-page.php +++ b/inc/admin-pages/class-event-view-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-hosting-integration-wizard-admin-page.php b/inc/admin-pages/class-hosting-integration-wizard-admin-page.php index 332cda1..d39534c 100644 --- a/inc/admin-pages/class-hosting-integration-wizard-admin-page.php +++ b/inc/admin-pages/class-hosting-integration-wizard-admin-page.php @@ -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, + ) + ); + } +} diff --git a/inc/admin-pages/class-invoice-template-customize-admin-page.php b/inc/admin-pages/class-invoice-template-customize-admin-page.php index bca0405..c5b1d53 100644 --- a/inc/admin-pages/class-invoice-template-customize-admin-page.php +++ b/inc/admin-pages/class-invoice-template-customize-admin-page.php @@ -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.

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.

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; + } +} diff --git a/inc/admin-pages/class-jobs-list-admin-page.php b/inc/admin-pages/class-jobs-list-admin-page.php index 13d37c3..5f25672 100644 --- a/inc/admin-pages/class-jobs-list-admin-page.php +++ b/inc/admin-pages/class-jobs-list-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-list-admin-page.php b/inc/admin-pages/class-list-admin-page.php index 2b15820..837e08e 100644 --- a/inc/admin-pages/class-list-admin-page.php +++ b/inc/admin-pages/class-list-admin-page.php @@ -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; +} diff --git a/inc/admin-pages/class-membership-edit-admin-page.php b/inc/admin-pages/class-membership-edit-admin-page.php index 801ca87..b868fd1 100644 --- a/inc/admin-pages/class-membership-edit-admin-page.php +++ b/inc/admin-pages/class-membership-edit-admin-page.php @@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages; // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Database\Memberships\Membership_Status; +use WP_Ultimo\Database\Memberships\Membership_Status; /** * WP Multisite WaaS Membership Edit/Add New Admin Page. @@ -102,8 +102,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { * Adds the swap notices, if needed. */ $this->add_swap_notices(); - - } // end page_loaded; + } /** * Displays swap notices, if necessary. @@ -115,11 +114,9 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $swap_order = $this->get_object()->get_scheduled_swap(); - if (!$swap_order || wu_request('preview-swap')) { - + if ( ! $swap_order || wu_request('preview-swap')) { return; - - } // end if; + } $actions = array( 'preview' => array( @@ -134,8 +131,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $message = sprintf(__('There is a change scheduled to take place on this membership in %s. You can preview the changes here. Scheduled changes are usually created by downgrades.', 'wp-ultimo'), $date->format(get_option('date_format'))); WP_Ultimo()->notices->add($message, 'warning', 'network-admin', false, $actions); - - } // end add_swap_notices; + } /** * Registers the necessary scripts and styles for this admin page. @@ -148,8 +144,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { parent::register_scripts(); wp_enqueue_editor(); - - } // end register_scripts; + } /** * Register ajax forms that we use for membership. @@ -161,41 +156,55 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { /* * Transfer membership - Confirmation modal */ - wu_register_form('transfer_membership', array( - 'render' => array($this, 'render_transfer_membership_modal'), - 'handler' => array($this, 'handle_transfer_membership_modal'), - 'capability' => 'wu_transfer_memberships', - )); + wu_register_form( + 'transfer_membership', + array( + 'render' => array($this, 'render_transfer_membership_modal'), + 'handler' => array($this, 'handle_transfer_membership_modal'), + 'capability' => 'wu_transfer_memberships', + ) + ); /* * Edit/Add product */ - wu_register_form('edit_membership_product', array( - 'render' => array($this, 'render_edit_membership_product_modal'), - 'handler' => array($this, 'handle_edit_membership_product_modal'), - )); + wu_register_form( + 'edit_membership_product', + array( + 'render' => array($this, 'render_edit_membership_product_modal'), + 'handler' => array($this, 'handle_edit_membership_product_modal'), + ) + ); /* * Change Plan */ - wu_register_form('change_membership_plan', array( - 'render' => array($this, 'render_change_membership_plan_modal'), - 'handler' => array($this, 'handle_change_membership_plan_modal'), - )); + wu_register_form( + 'change_membership_plan', + array( + 'render' => array($this, 'render_change_membership_plan_modal'), + 'handler' => array($this, 'handle_change_membership_plan_modal'), + ) + ); /* * Delete Product */ - wu_register_form('remove_membership_product', array( - 'render' => array($this, 'render_remove_membership_product'), - 'handler' => array($this, 'handle_remove_membership_product'), - )); + wu_register_form( + 'remove_membership_product', + array( + 'render' => array($this, 'render_remove_membership_product'), + 'handler' => array($this, 'handle_remove_membership_product'), + ) + ); - add_filter('wu_data_json_success_delete_membership_modal', fn($data_json) => array( - 'redirect_url' => wu_network_admin_url('wp-ultimo-memberships', array('deleted' => 1)) - )); - - } // end register_forms; + add_filter( + 'wu_data_json_success_delete_membership_modal', + fn($data_json) => array( + 'redirect_url' => wu_network_admin_url('wp-ultimo-memberships', array('deleted' => 1)), + ) + ); + } /** * Renders the deletion confirmation form. @@ -207,11 +216,9 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $membership = wu_get_membership(wu_request('id')); - if (!$membership) { - + if ( ! $membership) { return; - - } // end if; + } $fields = array( 'confirm' => array( @@ -243,21 +250,26 @@ class Membership_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' => '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_transfer_membership_modal; + } /** * Handles the deletion of line items. @@ -269,25 +281,19 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $membership = wu_get_membership(wu_request('id')); - if (!$membership) { - + if ( ! $membership) { wp_send_json_error(new \WP_Error('not-found', __('Membership not found.', 'wp-ultimo'))); - - } // end if; + } $target_customer = wu_get_customer(wu_request('target_customer_id')); - if (!$target_customer) { - + if ( ! $target_customer) { wp_send_json_error(new \WP_Error('not-found', __('Target customer not found.', 'wp-ultimo'))); - - } // end if; + } if ($target_customer->get_id() === $membership->get_customer_id()) { - wp_send_json_error(new \WP_Error('not-found', __('Cannot transfer to the same customer.', 'wp-ultimo'))); - - } // end if; + } /* * Lock the membership to prevent memberships. @@ -297,19 +303,27 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { /* * Enqueue task */ - wu_enqueue_async_action('wu_async_transfer_membership', array( - 'membership_id' => $membership->get_id(), - 'target_customer_id' => $target_customer->get_id(), - ), 'membership'); + wu_enqueue_async_action( + 'wu_async_transfer_membership', + array( + 'membership_id' => $membership->get_id(), + 'target_customer_id' => $target_customer->get_id(), + ), + 'membership' + ); - wp_send_json_success(array( - 'redirect_url' => wu_network_admin_url('wp-ultimo-edit-membership', array( - 'id' => $membership->get_id(), - 'transfer-started' => 1, - )) - )); - - } // end handle_transfer_membership_modal; + wp_send_json_success( + array( + 'redirect_url' => wu_network_admin_url( + 'wp-ultimo-edit-membership', + array( + 'id' => $membership->get_id(), + 'transfer-started' => 1, + ) + ), + ) + ); + } /** * Allow child classes to register widgets, if they need them. @@ -331,104 +345,125 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $gateway_message = false; - if (!empty($this->get_object()->get_gateway())) { - + if ( ! empty($this->get_object()->get_gateway())) { $gateway = wu_get_gateway($this->get_object()->get_gateway()); $gateway_message = $gateway ? $gateway->get_amount_update_message() : ''; + } - } // end if; - - $this->add_fields_widget('at_a_glance', array( - 'title' => __('At a Glance', 'wp-ultimo'), - 'position' => 'normal', - 'classes' => 'wu-overflow-hidden wu-widget-inset', - 'field_wrapper_classes' => 'wu-w-1/3 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', - 'fields' => array( - 'status' => array( - 'type' => 'text-display', - 'title' => __('Membership Status', 'wp-ultimo'), - 'display_value' => $tag, - 'tooltip' => '', - ), - 'hash' => array( - 'copy' => true, - 'type' => 'text-display', - 'title' => __('Reference ID', 'wp-ultimo'), - 'display_value' => $this->get_object()->get_hash(), - ), - 'total_grossed' => array( - 'type' => 'text-display', - 'title' => __('Total Grossed', 'wp-ultimo'), - 'display_value' => wu_format_currency($this->get_object()->get_total_grossed(), $this->get_object()->get_currency()), - 'wrapper_classes' => 'sm:wu-border-r-0', - ), - ), - )); - - $this->add_list_table_widget('membership-products', array( - 'position' => 'normal', - 'title' => __('Products', 'wp-ultimo'), - 'table' => new \WP_Ultimo\List_Tables\Membership_Line_Item_List_Table(), - 'after' => $this->output_widget_products(), - )); - - $this->add_list_table_widget('payments', array( - 'title' => __('Payments', 'wp-ultimo'), - 'table' => new \WP_Ultimo\List_Tables\Customers_Payment_List_Table(), - 'query_filter' => array($this, 'payments_query_filter'), - )); - - $this->add_list_table_widget('sites', array( - 'title' => __('Sites', 'wp-ultimo'), - 'table' => new \WP_Ultimo\List_Tables\Memberships_Site_List_Table(), - 'query_filter' => array($this, 'sites_query_filter'), - )); - - $this->add_list_table_widget('customer', array( - 'title' => __('Linked Customer', 'wp-ultimo'), - 'table' => new \WP_Ultimo\List_Tables\Site_Customer_List_Table(), - 'query_filter' => array($this, 'customer_query_filter'), - )); - - $this->add_tabs_widget('options', array( - 'title' => __('Membership Options', 'wp-ultimo'), - 'position' => 'normal', - 'sections' => apply_filters('wu_membership_options_sections', array( - 'general' => array( - 'title' => __('General', 'wp-ultimo'), - 'desc' => __('General membership options', 'wp-ultimo'), - 'icon' => 'dashicons-wu-globe', - 'fields' => array( - 'blocking' => array( - 'type' => 'toggle', - 'title' => __('Is Blocking?', 'wp-ultimo'), - 'desc' => __('Should we block access to the site, plugins, themes, and services after the expiration date is reached?', 'wp-ultimo'), - 'value' => true, - ), + $this->add_fields_widget( + 'at_a_glance', + array( + 'title' => __('At a Glance', 'wp-ultimo'), + 'position' => 'normal', + 'classes' => 'wu-overflow-hidden wu-widget-inset', + 'field_wrapper_classes' => 'wu-w-1/3 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', + 'fields' => array( + 'status' => array( + 'type' => 'text-display', + 'title' => __('Membership Status', 'wp-ultimo'), + 'display_value' => $tag, + 'tooltip' => '', + ), + 'hash' => array( + 'copy' => true, + 'type' => 'text-display', + 'title' => __('Reference ID', 'wp-ultimo'), + 'display_value' => $this->get_object()->get_hash(), + ), + 'total_grossed' => array( + 'type' => 'text-display', + 'title' => __('Total Grossed', 'wp-ultimo'), + 'display_value' => wu_format_currency($this->get_object()->get_total_grossed(), $this->get_object()->get_currency()), + 'wrapper_classes' => 'sm:wu-border-r-0', ), ), - 'billing_info' => array( - 'title' => __('Billing Info', 'wp-ultimo'), - 'desc' => __('Billing information for this particular membership.', 'wp-ultimo'), - 'icon' => 'dashicons-wu-address', - 'fields' => $this->get_object()->get_billing_address()->get_fields(), + ) + ); + + $this->add_list_table_widget( + 'membership-products', + array( + 'position' => 'normal', + 'title' => __('Products', 'wp-ultimo'), + 'table' => new \WP_Ultimo\List_Tables\Membership_Line_Item_List_Table(), + 'after' => $this->output_widget_products(), + ) + ); + + $this->add_list_table_widget( + 'payments', + array( + 'title' => __('Payments', 'wp-ultimo'), + 'table' => new \WP_Ultimo\List_Tables\Customers_Payment_List_Table(), + 'query_filter' => array($this, 'payments_query_filter'), + ) + ); + + $this->add_list_table_widget( + 'sites', + array( + 'title' => __('Sites', 'wp-ultimo'), + 'table' => new \WP_Ultimo\List_Tables\Memberships_Site_List_Table(), + 'query_filter' => array($this, 'sites_query_filter'), + ) + ); + + $this->add_list_table_widget( + 'customer', + array( + 'title' => __('Linked Customer', 'wp-ultimo'), + 'table' => new \WP_Ultimo\List_Tables\Site_Customer_List_Table(), + 'query_filter' => array($this, 'customer_query_filter'), + ) + ); + + $this->add_tabs_widget( + 'options', + array( + 'title' => __('Membership Options', 'wp-ultimo'), + 'position' => 'normal', + 'sections' => apply_filters( + 'wu_membership_options_sections', + array( + 'general' => array( + 'title' => __('General', 'wp-ultimo'), + 'desc' => __('General membership options', 'wp-ultimo'), + 'icon' => 'dashicons-wu-globe', + 'fields' => array( + 'blocking' => array( + 'type' => 'toggle', + 'title' => __('Is Blocking?', 'wp-ultimo'), + 'desc' => __('Should we block access to the site, plugins, themes, and services after the expiration date is reached?', 'wp-ultimo'), + 'value' => true, + ), + ), + ), + 'billing_info' => array( + 'title' => __('Billing Info', 'wp-ultimo'), + 'desc' => __('Billing information for this particular membership.', 'wp-ultimo'), + 'icon' => 'dashicons-wu-address', + 'fields' => $this->get_object()->get_billing_address()->get_fields(), + ), + ), + $this->get_object() ), - ), $this->get_object()), - )); + ) + ); /* * Hide sensitive things when in swap preview. */ - if (!$this->is_swap_preview) { - - $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'), - )); - - } // end if; + if ( ! $this->is_swap_preview) { + $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'), + ) + ); + } $regular_fields = array( 'status' => array( @@ -461,7 +496,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { 'desc' => __('If enable we will cancel the subscription on payment method', 'wp-ultimo'), 'value' => false, 'wrapper_html_attr' => array( - 'v-show' => !empty($this->get_object()->get_gateway_customer_id()) ? 'status == \'cancelled\'' : 'false', + 'v-show' => ! empty($this->get_object()->get_gateway_customer_id()) ? 'status == \'cancelled\'' : 'false', 'v-cloak' => '1', ), ), @@ -521,17 +556,19 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { 'v-cloak' => '1', ), 'html_attr' => array( - 'v-bind:href' => "'" . wu_get_form_url('transfer_membership', array( - 'id' => $this->get_object()->get_id(), - 'target_customer_id' => '', - )) . "=' + customer_id", + 'v-bind:href' => "'" . wu_get_form_url( + 'transfer_membership', + array( + 'id' => $this->get_object()->get_id(), + 'target_customer_id' => '', + ) + ) . "=' + customer_id", 'title' => __('Transfer Membership', 'wp-ultimo'), ), ), ); if ($this->get_object()->is_locked()) { - unset($regular_fields['transfer_note']); unset($regular_fields['transfer']); @@ -539,301 +576,309 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $regular_fields['submit_save']['title'] = __('Locked', 'wp-ultimo'); $regular_fields['submit_save']['value'] = 'none'; $regular_fields['submit_save']['html_attr']['disabled'] = 'disabled'; + } - } // end if; + $this->add_fields_widget( + 'save', + array( + 'html_attr' => array( + 'data-wu-app' => 'membership_save', + 'data-state' => json_encode( + array( + 'status' => $this->get_object()->get_status(), + 'original_customer_id' => $this->get_object()->get_customer_id(), + 'customer_id' => $this->get_object()->get_customer_id(), + 'plan_id' => $this->get_object()->get_plan_id(), + ) + ), + ), + 'fields' => $regular_fields, + ) + ); - $this->add_fields_widget('save', array( - 'html_attr' => array( - 'data-wu-app' => 'membership_save', - 'data-state' => json_encode(array( - 'status' => $this->get_object()->get_status(), - 'original_customer_id' => $this->get_object()->get_customer_id(), - 'customer_id' => $this->get_object()->get_customer_id(), - 'plan_id' => $this->get_object()->get_plan_id(), - )), - ), - 'fields' => $regular_fields, - )); - - $this->add_fields_widget('pricing', array( - 'title' => __('Billing Amount', 'wp-ultimo'), - 'html_attr' => array( - 'data-wu-app' => 'true', - 'data-state' => json_encode(array( - 'is_recurring' => $this->get_object()->is_recurring(), - 'is_auto_renew' => $this->get_object()->should_auto_renew(), - 'amount' => $this->get_object()->get_amount(), - 'initial_amount' => $this->get_object()->get_initial_amount(), - 'duration' => $this->get_object()->get_duration(), - 'duration_unit' => $this->get_object()->get_duration_unit(), - 'gateway' => $this->get_object()->get_gateway(), - 'gateway_subscription_id' => $this->get_object()->get_gateway_subscription_id(), - 'gateway_customer_id' => $this->get_object()->get_gateway_customer_id(), - )), - ), - 'fields' => array( - // Fields for price - '_initial_amount' => array( - 'type' => 'text', - 'title' => __('Initial Amount', 'wp-ultimo'), - // translators: %s is a price placeholder value. - 'placeholder' => sprintf(__('E.g. %s', 'wp-ultimo'), wu_format_currency(199)), - 'desc' => __('The initial amount collected on the first payment.', 'wp-ultimo'), - 'value' => $this->get_object()->get_initial_amount(), - 'money' => true, - 'html_attr' => array( - 'v-model' => 'initial_amount', - ), - 'wrapper_html_attr' => array( - 'v-cloak' => '1', + $this->add_fields_widget( + 'pricing', + array( + 'title' => __('Billing Amount', 'wp-ultimo'), + 'html_attr' => array( + 'data-wu-app' => 'true', + 'data-state' => json_encode( + array( + 'is_recurring' => $this->get_object()->is_recurring(), + 'is_auto_renew' => $this->get_object()->should_auto_renew(), + 'amount' => $this->get_object()->get_amount(), + 'initial_amount' => $this->get_object()->get_initial_amount(), + 'duration' => $this->get_object()->get_duration(), + 'duration_unit' => $this->get_object()->get_duration_unit(), + 'gateway' => $this->get_object()->get_gateway(), + 'gateway_subscription_id' => $this->get_object()->get_gateway_subscription_id(), + 'gateway_customer_id' => $this->get_object()->get_gateway_customer_id(), + ) ), ), - 'initial_amount' => array( - 'type' => 'hidden', - 'html_attr' => array( - 'v-model' => 'initial_amount', - ), - ), - 'recurring' => array( - 'type' => 'toggle', - 'title' => __('Is Recurring', 'wp-ultimo'), - 'desc' => __('Use this option to manually enable or disable this membership.', 'wp-ultimo'), - 'value' => $this->get_object()->is_recurring(), - 'html_attr' => array( - 'v-model' => 'is_recurring', - ), - 'wrapper_html_attr' => array( - 'v-cloak' => '1', - ), - ), - 'amount' => array( - 'type' => 'hidden', - 'html_attr' => array( - 'v-model' => 'amount', - ), - ), - 'recurring_amount_group' => array( - 'type' => 'group', - 'title' => __('Recurring Amount', 'wp-ultimo'), - // translators: placeholder %1$s is the amount, %2$s is the duration (such as 1, 2, 3), and %3$s is the unit (such as month, year, week) - 'desc' => sprintf(__('The customer will be charged %1$s every %2$s %3$s(s).', 'wp-ultimo'), '{{ wu_format_money(amount) }}', '{{ duration }}', '{{ duration_unit }}'), - 'wrapper_html_attr' => array( - 'v-show' => 'is_recurring', - 'v-cloak' => '1', - ), - 'fields' => array( - '_amount' => array( - 'type' => 'text', - 'value' => $this->get_object()->get_amount(), - 'placeholder' => wu_format_currency('99'), - 'wrapper_classes' => '', - 'money' => true, - 'html_attr' => array( - 'v-model' => 'amount', - ), + 'fields' => array( + // Fields for price + '_initial_amount' => array( + 'type' => 'text', + 'title' => __('Initial Amount', 'wp-ultimo'), + // translators: %s is a price placeholder value. + 'placeholder' => sprintf(__('E.g. %s', 'wp-ultimo'), wu_format_currency(199)), + 'desc' => __('The initial amount collected on the first payment.', 'wp-ultimo'), + 'value' => $this->get_object()->get_initial_amount(), + 'money' => true, + 'html_attr' => array( + 'v-model' => 'initial_amount', ), - 'duration' => array( - 'type' => 'number', - 'value' => $this->get_object()->get_duration(), - 'placeholder' => '', - 'wrapper_classes' => 'wu-mx-2 wu-w-1/3', - 'min' => 0, - 'html_attr' => array( - 'v-model' => 'duration', - 'steps' => 1, - ), + 'wrapper_html_attr' => array( + 'v-cloak' => '1', ), - 'duration_unit' => array( - 'type' => 'select', - 'value' => $this->get_object()->get_duration_unit(), - 'placeholder' => '', - 'wrapper_classes' => 'wu-w-2/3', - 'html_attr' => array( - 'v-model' => 'duration_unit', + ), + 'initial_amount' => array( + 'type' => 'hidden', + 'html_attr' => array( + 'v-model' => 'initial_amount', + ), + ), + 'recurring' => array( + 'type' => 'toggle', + 'title' => __('Is Recurring', 'wp-ultimo'), + 'desc' => __('Use this option to manually enable or disable this membership.', 'wp-ultimo'), + 'value' => $this->get_object()->is_recurring(), + 'html_attr' => array( + 'v-model' => 'is_recurring', + ), + 'wrapper_html_attr' => array( + 'v-cloak' => '1', + ), + ), + 'amount' => array( + 'type' => 'hidden', + 'html_attr' => array( + 'v-model' => 'amount', + ), + ), + 'recurring_amount_group' => array( + 'type' => 'group', + 'title' => __('Recurring Amount', 'wp-ultimo'), + // translators: placeholder %1$s is the amount, %2$s is the duration (such as 1, 2, 3), and %3$s is the unit (such as month, year, week) + 'desc' => sprintf(__('The customer will be charged %1$s every %2$s %3$s(s).', 'wp-ultimo'), '{{ wu_format_money(amount) }}', '{{ duration }}', '{{ duration_unit }}'), + 'wrapper_html_attr' => array( + 'v-show' => 'is_recurring', + 'v-cloak' => '1', + ), + 'fields' => array( + '_amount' => array( + 'type' => 'text', + 'value' => $this->get_object()->get_amount(), + 'placeholder' => wu_format_currency('99'), + 'wrapper_classes' => '', + 'money' => true, + 'html_attr' => array( + 'v-model' => 'amount', + ), ), - 'options' => array( - 'day' => __('Days', 'wp-ultimo'), - 'week' => __('Weeks', 'wp-ultimo'), - 'month' => __('Months', 'wp-ultimo'), - 'year' => __('Years', 'wp-ultimo'), + 'duration' => array( + 'type' => 'number', + 'value' => $this->get_object()->get_duration(), + 'placeholder' => '', + 'wrapper_classes' => 'wu-mx-2 wu-w-1/3', + 'min' => 0, + 'html_attr' => array( + 'v-model' => 'duration', + 'steps' => 1, + ), + ), + 'duration_unit' => array( + 'type' => 'select', + 'value' => $this->get_object()->get_duration_unit(), + 'placeholder' => '', + 'wrapper_classes' => 'wu-w-2/3', + 'html_attr' => array( + 'v-model' => 'duration_unit', + ), + 'options' => array( + 'day' => __('Days', 'wp-ultimo'), + 'week' => __('Weeks', 'wp-ultimo'), + 'month' => __('Months', 'wp-ultimo'), + 'year' => __('Years', 'wp-ultimo'), + ), ), ), ), - ), - 'recurring_note' => array( - 'type' => 'note', - 'desc' => $gateway_message, - 'classes' => 'wu-p-2 wu-bg-red-100 wu-text-red-600 wu-rounded wu-w-full', - 'wrapper_html_attr' => array( - 'v-show' => implode(' && ', array( - 'is_recurring', - 'gateway', - 'gateway === "' . $this->get_object()->get_gateway() . '"', - 'gateway_subscription_id === "' . $this->get_object()->get_gateway_subscription_id() . '"', - 'gateway_customer_id === "' . $this->get_object()->get_gateway_customer_id() . '"', - '(' . implode(' || ', array( - $this->get_object()->get_amount() . ' !== amount', - $this->get_object()->get_duration() . ' != duration', - '"' . $this->get_object()->get_duration_unit() . '" !== duration_unit', - )) . ')', - )), - 'v-cloak' => '1', + 'recurring_note' => array( + 'type' => 'note', + 'desc' => $gateway_message, + 'classes' => 'wu-p-2 wu-bg-red-100 wu-text-red-600 wu-rounded wu-w-full', + 'wrapper_html_attr' => array( + 'v-show' => implode( + ' && ', + array( + 'is_recurring', + 'gateway', + 'gateway === "' . $this->get_object()->get_gateway() . '"', + 'gateway_subscription_id === "' . $this->get_object()->get_gateway_subscription_id() . '"', + 'gateway_customer_id === "' . $this->get_object()->get_gateway_customer_id() . '"', + '(' . implode( + ' || ', + array( + $this->get_object()->get_amount() . ' !== amount', + $this->get_object()->get_duration() . ' != duration', + '"' . $this->get_object()->get_duration_unit() . '" !== duration_unit', + ) + ) . ')', + ) + ), + 'v-cloak' => '1', + ), ), - ), - 'billing_cycles' => array( - 'type' => 'number', - 'title' => __('Billing Cycles', 'wp-ultimo'), - 'placeholder' => __('E.g. 0', 'wp-ultimo'), - 'desc' => __('How many times should we bill this customer. Leave 0 to charge until cancelled.', 'wp-ultimo'), - 'value' => $this->get_object()->get_billing_cycles(), - 'min' => 0, - 'wrapper_html_attr' => array( - 'v-show' => 'is_recurring', - 'v-cloak' => '1', + 'billing_cycles' => array( + 'type' => 'number', + 'title' => __('Billing Cycles', 'wp-ultimo'), + 'placeholder' => __('E.g. 0', 'wp-ultimo'), + 'desc' => __('How many times should we bill this customer. Leave 0 to charge until cancelled.', 'wp-ultimo'), + 'value' => $this->get_object()->get_billing_cycles(), + 'min' => 0, + 'wrapper_html_attr' => array( + 'v-show' => 'is_recurring', + 'v-cloak' => '1', + ), ), - ), - 'times_billed' => array( - 'type' => 'number', - 'title' => __('Times Billed', 'wp-ultimo'), - 'desc' => __('The number of times this membership was billed so far.', 'wp-ultimo'), - 'value' => $this->get_object()->get_times_billed(), - 'min' => 0, - 'wrapper_html_attr' => array( - 'v-show' => 'is_recurring', - 'v-cloak' => '1', + 'times_billed' => array( + 'type' => 'number', + 'title' => __('Times Billed', 'wp-ultimo'), + 'desc' => __('The number of times this membership was billed so far.', 'wp-ultimo'), + 'value' => $this->get_object()->get_times_billed(), + 'min' => 0, + 'wrapper_html_attr' => array( + 'v-show' => 'is_recurring', + 'v-cloak' => '1', + ), ), - ), - 'auto_renew' => array( - 'type' => 'toggle', - 'title' => __('Auto-Renew?', 'wp-ultimo'), - 'desc' => __('Activating this will tell the gateway to try to automatically charge for this membership.', 'wp-ultimo'), - 'value' => $this->get_object()->should_auto_renew(), - 'wrapper_html_attr' => array( - 'v-show' => 'is_recurring', - 'v-cloak' => '1', + 'auto_renew' => array( + 'type' => 'toggle', + 'title' => __('Auto-Renew?', 'wp-ultimo'), + 'desc' => __('Activating this will tell the gateway to try to automatically charge for this membership.', 'wp-ultimo'), + 'value' => $this->get_object()->should_auto_renew(), + 'wrapper_html_attr' => array( + 'v-show' => 'is_recurring', + 'v-cloak' => '1', + ), + 'html_attr' => array( + 'v-model' => 'is_auto_renew', + ), ), - 'html_attr' => array( - 'v-model' => 'is_auto_renew', + 'gateway' => array( + 'type' => 'text', + 'title' => __('Gateway', 'wp-ultimo'), + 'placeholder' => __('e.g. stripe', 'wp-ultimo'), + 'description' => __('e.g. stripe', 'wp-ultimo'), + 'desc' => __('Payment gateway used to process the payment.', 'wp-ultimo'), + 'value' => $this->get_object()->get_gateway(), + 'wrapper_classes' => 'wu-w-full', + 'html_attr' => array( + 'v-on:input' => 'gateway = $event.target.value.toLowerCase().replace(/[^a-z0-9-_]+/g, "")', + 'v-bind:value' => 'gateway', + ), + 'wrapper_html_attr' => array( + 'v-cloak' => '1', + ), ), - ), - 'gateway' => array( - 'type' => 'text', - 'title' => __('Gateway', 'wp-ultimo'), - 'placeholder' => __('e.g. stripe', 'wp-ultimo'), - 'description' => __('e.g. stripe', 'wp-ultimo'), - 'desc' => __('Payment gateway used to process the payment.', 'wp-ultimo'), - 'value' => $this->get_object()->get_gateway(), - 'wrapper_classes' => 'wu-w-full', - 'html_attr' => array( - 'v-on:input' => 'gateway = $event.target.value.toLowerCase().replace(/[^a-z0-9-_]+/g, "")', - 'v-bind:value' => 'gateway', - ), - 'wrapper_html_attr' => array( - 'v-cloak' => '1', - ), - ), - 'gateway_customer_id_group' => array( - 'type' => 'group', - 'desc' => function(): string { + 'gateway_customer_id_group' => array( + 'type' => 'group', + 'desc' => function (): string { - $gateway_id = $this->get_object()->get_gateway(); + $gateway_id = $this->get_object()->get_gateway(); - if (empty($this->get_object()->get_gateway_customer_id())) { + if (empty($this->get_object()->get_gateway_customer_id())) { + return ''; + } + + $url = apply_filters("wu_{$gateway_id}_remote_customer_url", $this->get_object()->get_gateway_customer_id()); + + if ($url) { + return sprintf('%s', esc_attr($url), __('View on Gateway →', 'wp-ultimo')); + } return ''; - - } // end if; - - $url = apply_filters("wu_{$gateway_id}_remote_customer_url", $this->get_object()->get_gateway_customer_id()); - - if ($url) { - - return sprintf('%s', esc_attr($url), __('View on Gateway →', 'wp-ultimo')); - - } // end if; - - return ''; - - }, - 'wrapper_html_attr' => array( - 'v-show' => 'is_recurring && is_auto_renew', - 'v-cloak' => '1', - ), - 'fields' => array( - 'gateway_customer_id' => array( - 'type' => 'text', - 'title' => __('Gateway Customer ID', 'wp-ultimo'), - 'placeholder' => __('Gateway Customer ID', 'wp-ultimo'), - 'value' => $this->get_object()->get_gateway_customer_id(), - 'tooltip' => '', - 'wrapper_classes' => 'wu-w-full', - 'wrapper_html_attr' => array(), - 'html_attr' => array( - 'v-model' => 'gateway_customer_id', + }, + 'wrapper_html_attr' => array( + 'v-show' => 'is_recurring && is_auto_renew', + 'v-cloak' => '1', + ), + 'fields' => array( + 'gateway_customer_id' => array( + 'type' => 'text', + 'title' => __('Gateway Customer ID', 'wp-ultimo'), + 'placeholder' => __('Gateway Customer ID', 'wp-ultimo'), + 'value' => $this->get_object()->get_gateway_customer_id(), + 'tooltip' => '', + 'wrapper_classes' => 'wu-w-full', + 'wrapper_html_attr' => array(), + 'html_attr' => array( + 'v-model' => 'gateway_customer_id', + ), ), ), ), - ), - 'gateway_subscription_id_group' => array( - 'type' => 'group', - 'desc' => function(): string { + 'gateway_subscription_id_group' => array( + 'type' => 'group', + 'desc' => function (): string { - $gateway_id = $this->get_object()->get_gateway(); + $gateway_id = $this->get_object()->get_gateway(); - if (empty($this->get_object()->get_gateway_subscription_id())) { + if (empty($this->get_object()->get_gateway_subscription_id())) { + return ''; + } + + $url = apply_filters("wu_{$gateway_id}_remote_subscription_url", $this->get_object()->get_gateway_subscription_id()); + + if ($url) { + return sprintf('%s', esc_attr($url), __('View on Gateway →', 'wp-ultimo')); + } return ''; - - } // end if; - - $url = apply_filters("wu_{$gateway_id}_remote_subscription_url", $this->get_object()->get_gateway_subscription_id()); - - if ($url) { - - return sprintf('%s', esc_attr($url), __('View on Gateway →', 'wp-ultimo')); - - } // end if; - - return ''; - - }, - 'wrapper_html_attr' => array( - 'v-show' => 'is_recurring && is_auto_renew', - 'v-cloak' => '1', - ), - 'fields' => array( - 'gateway_subscription_id' => array( - 'type' => 'text', - 'title' => __('Gateway Subscription ID', 'wp-ultimo'), - 'placeholder' => __('Gateway Subscription ID', 'wp-ultimo'), - 'value' => $this->get_object()->get_gateway_subscription_id(), - 'tooltip' => '', - 'wrapper_classes' => 'wu-w-full', - 'wrapper_html_attr' => array(), - 'html_attr' => array( - 'v-model' => 'gateway_subscription_id', + }, + 'wrapper_html_attr' => array( + 'v-show' => 'is_recurring && is_auto_renew', + 'v-cloak' => '1', + ), + 'fields' => array( + 'gateway_subscription_id' => array( + 'type' => 'text', + 'title' => __('Gateway Subscription ID', 'wp-ultimo'), + 'placeholder' => __('Gateway Subscription ID', 'wp-ultimo'), + 'value' => $this->get_object()->get_gateway_subscription_id(), + 'tooltip' => '', + 'wrapper_classes' => 'wu-w-full', + 'wrapper_html_attr' => array(), + 'html_attr' => array( + 'v-model' => 'gateway_subscription_id', + ), ), ), ), - ), - 'gateway_note' => array( - 'type' => 'note', - 'desc' => __('We will try to cancel the old subscription on the gateway.', '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' => 'is_recurring && (' . implode(' || ', array( - '"' . $this->get_object()->get_gateway() . '" !== "" && gateway !== "' . $this->get_object()->get_gateway() . '"', - '"' . $this->get_object()->get_gateway_subscription_id() . '" !== "" && gateway_subscription_id !== "' . $this->get_object()->get_gateway_subscription_id() . '"', - '"' . $this->get_object()->get_gateway_customer_id() . '" !== "" && gateway_customer_id !== "' . $this->get_object()->get_gateway_customer_id() . '"', - )) . ')', - 'v-cloak' => '1', + 'gateway_note' => array( + 'type' => 'note', + 'desc' => __('We will try to cancel the old subscription on the gateway.', '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' => 'is_recurring && (' . implode( + ' || ', + array( + '"' . $this->get_object()->get_gateway() . '" !== "" && gateway !== "' . $this->get_object()->get_gateway() . '"', + '"' . $this->get_object()->get_gateway_subscription_id() . '" !== "" && gateway_subscription_id !== "' . $this->get_object()->get_gateway_subscription_id() . '"', + '"' . $this->get_object()->get_gateway_customer_id() . '" !== "" && gateway_customer_id !== "' . $this->get_object()->get_gateway_customer_id() . '"', + ) + ) . ')', + 'v-cloak' => '1', + ), ), ), - ), - )); + ) + ); $timestamp_fields = array(); @@ -845,10 +890,9 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { ); foreach ($timestamps as $timestamp_name => $timestamp_label) { - $value = $this->get_object()->{"get_$timestamp_name"}(); - $timestamp_fields[$timestamp_name] = array( + $timestamp_fields[ $timestamp_name ] = array( 'title' => $timestamp_label, 'type' => 'text-edit', 'date' => true, @@ -862,11 +906,9 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { 'data-allow-time' => 'true', ), ); + } - } // end foreach; - - if (!$this->get_object()->is_lifetime()) { - + if ( ! $this->get_object()->is_lifetime()) { $timestamp_fields['convert_to_lifetime'] = array( 'type' => 'submit', 'title' => __('Convert to Lifetime', 'wp-ultimo'), @@ -874,15 +916,16 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { 'classes' => 'button wu-w-full', 'wrapper_html_attr' => array(), ); + } - } // end if; - - $this->add_fields_widget('membership-timestamps', array( - 'title' => __('Important Timestamps', 'wp-ultimo'), - 'fields' => $timestamp_fields, - )); - - } // end register_widgets; + $this->add_fields_widget( + 'membership-timestamps', + array( + 'title' => __('Important Timestamps', 'wp-ultimo'), + 'fields' => $timestamp_fields, + ) + ); + } /** * Renders the widget used to display the product list. @@ -892,11 +935,13 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { */ public function output_widget_products() { - return wu_get_template_contents('memberships/product-list', array( - 'membership' => $this->get_object(), - )); - - } // end output_widget_products; + return wu_get_template_contents( + 'memberships/product-list', + array( + 'membership' => $this->get_object(), + ) + ); + } /** * Returns the title of the page. @@ -907,8 +952,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { public function get_title() { return $this->edit ? __('Edit Membership', 'wp-ultimo') : __('Add new Membership', 'wp-ultimo'); - - } // end get_title; + } /** * Returns the title of menu for this page. @@ -919,8 +963,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { public function get_menu_title() { return __('Edit Membership', 'wp-ultimo'); - - } // end get_menu_title; + } /** * Returns the action links for that page. @@ -931,8 +974,7 @@ class Membership_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. @@ -953,8 +995,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { 'delete_button_label' => __('Delete Membership', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), ); - - } // end get_labels; + } /** * Filters the list table to return only relevant payments. @@ -969,8 +1010,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $args['membership_id'] = $this->get_object()->get_id(); return $args; - - } // end payments_query_filter; + } /** * Filters the list table to return only relevant sites. @@ -990,8 +1030,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { ); return $args; - - } // end sites_query_filter; + } /** * Filters the list table to return only relevant customer. @@ -1006,8 +1045,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $args['id'] = $this->get_object()->get_customer_id(); return $args; - - } // end customer_query_filter; + } /** * Filters the list table to return only relevant events. @@ -1025,8 +1063,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { ); return array_merge($args, $extra_args); - - } // end events_query_filter; + } /** * Returns the object being edit at the moment. @@ -1037,22 +1074,18 @@ class Membership_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_membership($item_id); - if (!$item) { - + if ( ! $item) { wp_redirect(wu_network_admin_url('wp-ultimo-memberships')); exit; - - } // end if; + } $this->object = $item; @@ -1060,14 +1093,11 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { * Deal with scheduled swaps. */ if (wu_request('preview-swap')) { - $swap_order = $this->get_object()->get_scheduled_swap(); - if (!$swap_order) { - + if ( ! $swap_order) { return $this->object; - - } // end if; + } $this->is_swap_preview = true; @@ -1086,12 +1116,10 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { WP_Ultimo()->notices->add($message, 'info', 'network-admin', false, $actions); $this->object->swap($swap_order->order); - - } // end if; + } return $this->object; - - } // end get_object; + } /** * Memberships have titles. * @@ -1100,8 +1128,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { public function has_title(): bool { return false; - - } // end has_title; + } /** * Handle convert to lifetime. * @@ -1116,32 +1143,27 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $save = $object->save(); if (is_wp_error($save)) { - $errors = implode('
', $save->get_error_messages()); WP_Ultimo()->notices->add($errors, 'error', 'network-admin'); return false; - - } // end if; + } $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); return true; - - } // end handle_convert_to_lifetime; + } /** * Should implement the processes necessary to save the changes made to the object. @@ -1154,25 +1176,19 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $object = $this->get_object(); // Cancel membership on gateway - if ((bool) wu_request('cancel_gateway', false) && wu_request('status', Membership_Status::CANCELLED)) { - + if ( (bool) wu_request('cancel_gateway', false) && wu_request('status', Membership_Status::CANCELLED)) { $gateway = wu_get_gateway(wu_request('gateway')); if ($gateway) { - $gateway->process_cancellation($object, $object->get_customer()); $_POST['gateway'] = ''; - - } // end if; - - } // end if; + } + } if (wu_request('submit_button') === 'convert_to_lifetime') { - return $this->handle_convert_to_lifetime(); - - } // end if; + } $_POST['auto_renew'] = (bool) wu_request('auto_renew', false); @@ -1183,14 +1199,12 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $valid_address = $billing_address->validate(); if (is_wp_error($valid_address)) { - $errors = implode('
', $valid_address->get_error_messages()); WP_Ultimo()->notices->add($errors, 'error', 'network-admin'); return false; - - } // end if; + } $object->set_billing_address($billing_address); @@ -1199,7 +1213,6 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $status = parent::handle_save(); if ($this->is_swap_preview) { - ob_clean(); $object->delete_scheduled_swap(); @@ -1215,12 +1228,10 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { wp_redirect($url); return true; - - } // end if; + } return $status; - - } // end handle_save; + } /** * Renders the add/edit line items form. @@ -1232,21 +1243,17 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $membership = wu_get_membership(wu_request('id')); - if (!$membership) { - + if ( ! $membership) { return; - - } // end if; + } $gateway_message = false; - if (!empty($membership->get_gateway())) { - + if ( ! empty($membership->get_gateway())) { $gateway = wu_get_gateway($membership->get_gateway()); $gateway_message = $gateway ? $gateway->get_amount_update_message() : ''; - - } // end if; + } $fields = array( 'product_id' => array( @@ -1306,27 +1313,30 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { ), ); - if (!$gateway_message) { - + if ( ! $gateway_message) { unset($fields['transfer_note']); + } - } // end if; - - $form = new \WP_Ultimo\UI\Form('edit_membership_product', $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - 'html_attr' => array( - 'data-wu-app' => 'edit_membership_product', - 'data-state' => wu_convert_to_state(array( - 'update_pricing' => 0, - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'edit_membership_product', + $fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + 'html_attr' => array( + 'data-wu-app' => 'edit_membership_product', + 'data-state' => wu_convert_to_state( + array( + 'update_pricing' => 0, + ) + ), + ), + ) + ); $form->render(); - - } // end render_edit_membership_product_modal; + } /** * Handles the add/edit of line items. @@ -1338,54 +1348,45 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $membership = wu_get_membership(wu_request('id')); - if (!$membership) { - + if ( ! $membership) { $error = new \WP_Error('membership-not-found', __('Membership not found.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } $product = wu_get_product(wu_request('product_id')); - if (!$product) { - + if ( ! $product) { $error = new \WP_Error('product-not-found', __('Product not found.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } $membership->add_product($product->get_id(), (int) wu_request('quantity', 1)); // if we are updating the pricing, we need to update the membership price. if (wu_request('update_price')) { - $value_to_add = wu_get_membership_product_price($membership, $product->get_id(), (int) wu_request('quantity', 1)); if (is_wp_error($value_to_add)) { - wp_send_json_error($value_to_add); - - } // end if; + } $membership->set_amount($membership->get_amount() + $value_to_add); - - } // end if; + } $saved = $membership->save(); if (is_wp_error($saved)) { - wp_send_json_error($saved); + } - } // end if; - - wp_send_json_success(array( - 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), - )); - - } // end handle_edit_membership_product_modal; + wp_send_json_success( + array( + 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), + ) + ); + } /** * Renders the deletion confirmation form. @@ -1397,21 +1398,17 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $membership = wu_get_membership(wu_request('id')); - if (!$membership) { - + if ( ! $membership) { return; - - } // end if; + } $gateway_message = false; if ($membership->get_gateway()) { - $gateway = wu_get_gateway($membership->get_gateway()); $gateway_message = $gateway ? $gateway->get_amount_update_message() : ''; - - } // end if; + } $fields = array( 'quantity' => array( @@ -1460,27 +1457,30 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { ), ); - if (!$gateway_message) { - + if ( ! $gateway_message) { unset($fields['transfer_note']); + } - } // end if; - - $form = new \WP_Ultimo\UI\Form('edit_membership_product', $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - 'html_attr' => array( - 'data-wu-app' => 'edit_membership_product', - 'data-state' => wu_convert_to_state(array( - 'update_pricing' => 0, - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'edit_membership_product', + $fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + 'html_attr' => array( + 'data-wu-app' => 'edit_membership_product', + 'data-state' => wu_convert_to_state( + array( + 'update_pricing' => 0, + ) + ), + ), + ) + ); $form->render(); - - } // end render_remove_membership_product; + } /** * Handles the deletion of line items. @@ -1492,23 +1492,19 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $membership = wu_get_membership(wu_request('id')); - if (!$membership) { - + if ( ! $membership) { $error = new \WP_Error('membership-not-found', __('Membership not found.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } $product = wu_get_product(wu_request('product_id')); - if (!$product) { - + if ( ! $product) { $error = new \WP_Error('product-not-found', __('Product not found.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } // Get the existing quantity by filtering the products array. $existing_quantity = array_filter($membership->get_addon_products(), fn($item) => $item['product']->get_id() === $product->get_id())[0]['quantity']; @@ -1520,32 +1516,27 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { // if we are updating the pricing, we need to update the membership price. if (wu_request('update_price')) { - $value_to_remove = wu_get_membership_product_price($membership, $product->get_id(), $quantity); if (is_wp_error($value_to_remove)) { - wp_send_json_error($value_to_remove); - - } // end if; + } $membership->set_amount($membership->get_amount() - $value_to_remove); - - } // end if; + } $saved = $membership->save(); if (is_wp_error($saved)) { - wp_send_json_error($saved); + } - } // end if; - - wp_send_json_success(array( - 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), - )); - - } // end handle_remove_membership_product; + wp_send_json_success( + array( + 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), + ) + ); + } /** * Renders the add/edit line items form. @@ -1557,29 +1548,23 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $membership = wu_get_membership(wu_request('id')); - if (!$membership) { - + if ( ! $membership) { return; - - } // end if; + } $product = wu_get_product(wu_request('product_id')); - if (!$product) { - + if ( ! $product) { return; - - } // end if; + } $gateway_message = false; if ($membership->get_gateway()) { - $gateway = wu_get_gateway($membership->get_gateway()); $gateway_message = $gateway ? $gateway->get_amount_update_message() : ''; - - } // end if; + } $fields = array( 'plan_id' => array( @@ -1634,29 +1619,32 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { ), ); - if (!$gateway_message) { - + if ( ! $gateway_message) { unset($fields['transfer_note']); + } - } // end if; - - $form = new \WP_Ultimo\UI\Form('change_membership_plan', $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' => 'change_membership_plan', - 'data-state' => wu_convert_to_state(array( - 'update_pricing' => 0, - 'original_plan_id' => $product->get_id(), - 'plan_id' => $product->get_id(), - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'change_membership_plan', + $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' => 'change_membership_plan', + 'data-state' => wu_convert_to_state( + array( + 'update_pricing' => 0, + 'original_plan_id' => $product->get_id(), + 'plan_id' => $product->get_id(), + ) + ), + ), + ) + ); $form->render(); - - } // end render_change_membership_plan_modal; + } /** * Handles the add/edit of line items. @@ -1668,71 +1656,57 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page { $membership = wu_get_membership(wu_request('id')); - if (!$membership) { - + if ( ! $membership) { $error = new \WP_Error('membership-not-found', __('Membership not found.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } $plan = wu_get_product(wu_request('plan_id')); - if (!$plan) { - + if ( ! $plan) { $error = new \WP_Error('plan-not-found', __('Plan not found.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } $original_plan_id = $membership->get_plan_id(); if (absint($original_plan_id) === absint($plan->get_id())) { - $error = new \WP_Error('same-plan', __('No change performed. The same plan selected.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } $membership->set_plan_id($plan->get_id()); // if we are updating the pricing, we need to update the membership price. if (wu_request('update_price')) { - $value_to_add = wu_get_membership_product_price($membership, $plan->get_id(), 1); if (is_wp_error($value_to_add)) { - wp_send_json_error($value_to_add); - - } // end if; + } $value_to_remove = wu_get_membership_product_price($membership, $original_plan_id, 1); if (is_wp_error($value_to_remove)) { - wp_send_json_error($value_to_remove); - - } // end if; + } $membership->set_amount($membership->get_amount() + $value_to_add - $value_to_remove); - - } // end if; + } $saved = $membership->save(); if (is_wp_error($saved)) { - wp_send_json_error($saved); + } - } // end if; - - wp_send_json_success(array( - 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), - )); - - } // end handle_change_membership_plan_modal; - -} // end class Membership_Edit_Admin_Page; + wp_send_json_success( + array( + 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), + ) + ); + } +} diff --git a/inc/admin-pages/class-membership-list-admin-page.php b/inc/admin-pages/class-membership-list-admin-page.php index bf6e491..94b0870 100644 --- a/inc/admin-pages/class-membership-list-admin-page.php +++ b/inc/admin-pages/class-membership-list-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-migration-alert-admin-page.php b/inc/admin-pages/class-migration-alert-admin-page.php index a9a993b..65e28c0 100644 --- a/inc/admin-pages/class-migration-alert-admin-page.php +++ b/inc/admin-pages/class-migration-alert-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-payment-edit-admin-page.php b/inc/admin-pages/class-payment-edit-admin-page.php index fb21edc..0fb0698 100644 --- a/inc/admin-pages/class-payment-edit-admin-page.php +++ b/inc/admin-pages/class-payment-edit-admin-page.php @@ -12,8 +12,8 @@ namespace WP_Ultimo\Admin_Pages; // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Models\Payment; -use \WP_Ultimo\Database\Payments\Payment_Status; +use WP_Ultimo\Models\Payment; +use WP_Ultimo\Database\Payments\Payment_Status; /** * WP Multisite WaaS Payment Edit/Add New Admin Page. @@ -92,8 +92,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { parent::register_scripts(); wp_enqueue_editor(); - - } // end register_scripts; + } /** * Register ajax forms that we use for payments. @@ -105,38 +104,49 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { /* * Edit/Add Line Item */ - wu_register_form('edit_line_item', array( - 'render' => array($this, 'render_edit_line_item_modal'), - 'handler' => array($this, 'handle_edit_line_item_modal'), - 'capability' => 'wu_edit_payments', - )); + wu_register_form( + 'edit_line_item', + array( + 'render' => array($this, 'render_edit_line_item_modal'), + 'handler' => array($this, 'handle_edit_line_item_modal'), + 'capability' => 'wu_edit_payments', + ) + ); /* * Delete Line Item - Confirmation modal */ - wu_register_form('delete_line_item', array( - 'render' => array($this, 'render_delete_line_item_modal'), - 'handler' => array($this, 'handle_delete_line_item_modal'), - 'capability' => 'wu_delete_payments', - )); + wu_register_form( + 'delete_line_item', + array( + 'render' => array($this, 'render_delete_line_item_modal'), + 'handler' => array($this, 'handle_delete_line_item_modal'), + 'capability' => 'wu_delete_payments', + ) + ); /* * Refund Line Item */ - wu_register_form('refund_payment', array( - 'render' => array($this, 'render_refund_payment_modal'), - 'handler' => array($this, 'handle_refund_payment_modal'), - 'capability' => 'wu_refund_payments', - )); + wu_register_form( + 'refund_payment', + array( + 'render' => array($this, 'render_refund_payment_modal'), + 'handler' => array($this, 'handle_refund_payment_modal'), + 'capability' => 'wu_refund_payments', + ) + ); /* * Delete - Confirmation modal */ - add_filter('wu_data_json_success_delete_payment_modal', fn($data_json) => array( - 'redirect_url' => wu_network_admin_url('wp-ultimo-payments', array('deleted' => 1)) - )); - - } // end register_forms; + add_filter( + 'wu_data_json_success_delete_payment_modal', + fn($data_json) => array( + 'redirect_url' => wu_network_admin_url('wp-ultimo-payments', array('deleted' => 1)), + ) + ); + } /** * Renders the deletion confirmation form. @@ -150,11 +160,9 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { $line_item = wu_get_line_item(wu_request('line_item_id'), $payment->get_id()); - if (!$line_item || !$payment) { - + if ( ! $line_item || ! $payment) { return; - - } // end if; + } $fields = array( 'confirm' => array( @@ -185,21 +193,26 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { ), ); - $form = new \WP_Ultimo\UI\Form('total-actions', $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - 'html_attr' => array( - 'data-wu-app' => 'true', - 'data-state' => wu_convert_to_state(array( - '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' => wu_convert_to_state( + array( + 'confirmed' => false, + ) + ), + ), + ) + ); $form->render(); - - } // end render_delete_line_item_modal; + } /** * Handles the deletion of line items. @@ -213,31 +226,28 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { $line_item = wu_get_line_item(wu_request('line_item_id'), $payment->get_id()); - if (!$payment || !$line_item) { - + if ( ! $payment || ! $line_item) { wp_send_json_error(new \WP_Error('not-found', __('Payment not found.', 'wp-ultimo'))); - - } // end if; + } $line_items = $payment->get_line_items(); - unset($line_items[$line_item->get_id()]); + unset($line_items[ $line_item->get_id() ]); $payment->set_line_items($line_items); $saved = $payment->recalculate_totals()->save(); if (is_wp_error($saved)) { - wp_send_json_error($saved); + } - } // end if; - - wp_send_json_success(array( - 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), - )); - - } // end handle_delete_line_item_modal; + wp_send_json_success( + array( + 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), + ) + ); + } /** * Renders the refund line item modal. @@ -249,11 +259,9 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { $payment = wu_get_payment(wu_request('id')); - if (!$payment) { - + if ( ! $payment) { return; - - } // end if; + } $fields = array( '_amount' => array( @@ -265,7 +273,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { 'html_attr' => array( 'v-model' => 'amount', 'step' => '0.01', - 'v-bind:max' => 'total' + 'v-bind:max' => 'total', ), 'wrapper_html_attr' => array( 'v-show' => 'step === 1', @@ -317,7 +325,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { ), 'html_attr' => array( 'v-bind:disabled' => 'amount <= 0 || amount > total', - 'v-on:click.prevent' => 'step = 2' + 'v-on:click.prevent' => 'step = 2', ), ), 'submit_button_2' => array( @@ -340,24 +348,29 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { ), ); - $form = new \WP_Ultimo\UI\Form('total-actions', $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - 'html_attr' => array( - 'data-wu-app' => 'refund', - 'data-state' => wu_convert_to_state(array( - 'step' => 1, - 'confirmed' => false, - 'total' => round($payment->get_total(), 2), - 'amount' => round($payment->get_total(), 2), - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'total-actions', + $fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + 'html_attr' => array( + 'data-wu-app' => 'refund', + 'data-state' => wu_convert_to_state( + array( + 'step' => 1, + 'confirmed' => false, + 'total' => round($payment->get_total(), 2), + 'amount' => round($payment->get_total(), 2), + ) + ), + ), + ) + ); $form->render(); - - } // end render_refund_payment_modal; + } /** * Handles the deletion of line items. @@ -371,20 +384,16 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { $payment = wu_get_payment(wu_request('id')); - if (!$payment) { - + if ( ! $payment) { wp_send_json_error(new \WP_Error('not-found', __('Payment not found.', 'wp-ultimo'))); - - } // end if; + } /* * Checks for a valid amount. */ if (empty($amount) || $amount > $payment->get_total()) { - wp_send_json_error(new \WP_Error('invalid-amount', __('The refund amount is out of bounds.', 'wp-ultimo'))); - - } // end if; + } /* * Check if the payment is in a @@ -392,11 +401,9 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { */ $is_refundable = in_array($payment->get_status(), wu_get_refundable_payment_types(), true); - if (!$is_refundable) { - + if ( ! $is_refundable) { wp_send_json_error(new \WP_Error('payment-not-refunded', __('This payment is not in a refundable state.', 'wp-ultimo'))); - - } // end if; + } /* * First we set the flag to cancel membership @@ -415,7 +422,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { */ $gateway_id = $payment->get_gateway(); - if (!$gateway_id) { + if ( ! $gateway_id) { /* * The payment does not have a * gateway attached to it. @@ -424,30 +431,30 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { $status = $payment->refund($amount, $should_cancel_membership_on_refund); if (is_wp_error($status)) { - wp_send_json_error($status); - - } // end if; + } /* * Done! Redirect back. */ - wp_send_json_success(array( - 'redirect_url' => wu_network_admin_url('wp-ultimo-edit-payment', array( - 'id' => $payment->get_id(), - 'updated' => 1, - )), - )); - - } // end if; + wp_send_json_success( + array( + 'redirect_url' => wu_network_admin_url( + 'wp-ultimo-edit-payment', + array( + 'id' => $payment->get_id(), + 'updated' => 1, + ) + ), + ) + ); + } $gateway = wu_get_gateway($gateway_id); - if (!$gateway) { - + if ( ! $gateway) { wp_send_json_error(new \WP_Error('gateway-not-found', __('Payment gateway not found.', 'wp-ultimo'))); - - } // end if; + } /* * Process the refund on the gateway. @@ -478,29 +485,30 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { $error = new \WP_Error('refund-error', sprintf(__('An error occurred: %s', 'wp-ultimo'), $status->get_error_message())); wp_send_json_error($error); - - } // end if; - + } } catch (\Throwable $e) { // translators: %s is the exception error message. $error = new \WP_Error('refund-error', sprintf(__('An error occurred: %s', 'wp-ultimo'), $e->getMessage())); wp_send_json_error($error); - - } // end try; + } /* * Done! Redirect back. */ - wp_send_json_success(array( - 'redirect_url' => wu_network_admin_url('wp-ultimo-edit-payment', array( - 'id' => $payment->get_id(), - 'updated' => 1, - )), - )); - - } // end handle_refund_payment_modal; + wp_send_json_success( + array( + 'redirect_url' => wu_network_admin_url( + 'wp-ultimo-edit-payment', + array( + 'id' => $payment->get_id(), + 'updated' => 1, + ) + ), + ) + ); + } /** * Handles the add/edit of line items. @@ -514,11 +522,9 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { $line_item = wu_get_line_item(wu_request('line_item_id'), $payment->get_id()); - if (!$line_item) { - + if ( ! $line_item) { $line_item = new \WP_Ultimo\Checkout\Line_Item(array()); - - } // end if; + } /* * First, we get the type. @@ -532,16 +538,13 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { $type = wu_request('type', 'product'); if ($type === 'product') { - $product = wu_get_product(wu_request('product_id')); if (empty($product)) { - $error = new \WP_Error('missing-product', __('The product was not found.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } /* * Constructs the arguments @@ -557,7 +560,6 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { 'tax_type' => wu_request('tax_type', 'percentage'), 'tax_label' => wu_request('tax_label', ''), ); - } else { /** @@ -566,19 +568,20 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { * * First, check the valid types. */ - $allowed_types = apply_filters('wu_allowed_line_item_types', array( - 'fee', - 'refund', - 'credit', - )); - - if (!in_array($type, $allowed_types, true)) { + $allowed_types = apply_filters( + 'wu_allowed_line_item_types', + array( + 'fee', + 'refund', + 'credit', + ) + ); + if ( ! in_array($type, $allowed_types, true)) { $error = new \WP_Error('invalid-type', __('The line item type is invalid.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } /* * Set the new attributes @@ -592,8 +595,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { 'tax_type' => 'percentage', 'tax_label' => '', ); - - } // end if; + } $line_item->attributes($atts); @@ -601,29 +603,26 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { $line_items = $payment->get_line_items(); - $line_items[$line_item->get_id()] = $line_item; + $line_items[ $line_item->get_id() ] = $line_item; $payment->set_line_items($line_items); $saved = $payment->recalculate_totals()->save(); - if (!$saved) { - + if ( ! $saved) { wp_send_json_error(new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo'))); - - } // end if; + } if (is_wp_error($saved)) { - wp_send_json_error($saved); + } - } // end if; - - wp_send_json_success(array( - 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), - )); - - } // end handle_edit_line_item_modal; + wp_send_json_success( + array( + 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), + ) + ); + } /** * Renders the add/edit line items form. @@ -637,14 +636,13 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { */ $line_item = wu_get_line_item(wu_request('line_item_id'), wu_request('id')); - if (!$line_item) { + if ( ! $line_item) { /* * If that doesn't work, * we start a new line. */ $line_item = new \WP_Ultimo\Checkout\Line_Item(array()); - - } // end if; + } $fields = array( 'tab' => array( @@ -845,24 +843,29 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { ), ); - $form = new \WP_Ultimo\UI\Form('edit_line_item', $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - 'html_attr' => array( - 'data-wu-app' => 'edit_line_item', - 'data-state' => wu_convert_to_state(array( - 'tab' => 'type', - 'type' => $line_item->get_type(), - 'taxable' => $line_item->get_tax_rate() > 0, - 'unit_price' => $line_item->get_unit_price(), - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'edit_line_item', + $fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + 'html_attr' => array( + 'data-wu-app' => 'edit_line_item', + 'data-state' => wu_convert_to_state( + array( + 'tab' => 'type', + 'type' => $line_item->get_type(), + 'taxable' => $line_item->get_tax_rate() > 0, + 'unit_price' => $line_item->get_unit_price(), + ) + ), + ), + ) + ); $form->render(); - - } // end render_edit_line_item_modal; + } /** * Display the payment actions. @@ -877,33 +880,39 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { $is_refundable = in_array($this->get_object()->get_status(), wu_get_refundable_payment_types(), true); if ($is_refundable) { - $actions['refund_payment'] = array( 'label' => __('Refund Payment', 'wp-ultimo'), 'icon_classes' => 'dashicons-wu-ccw wu-align-text-bottom', 'classes' => 'button wubox', - 'href' => wu_get_form_url('refund_payment', array( - 'id' => $this->get_object()->get_id(), - )), + 'href' => wu_get_form_url( + 'refund_payment', + array( + 'id' => $this->get_object()->get_id(), + ) + ), ); - - } // end if; + } $actions['add_line_item'] = array( 'label' => __('Add Line Item', 'wp-ultimo'), 'icon_classes' => 'dashicons-wu-circle-with-plus wu-align-text-bottom', 'classes' => 'button wubox', - 'href' => wu_get_form_url('edit_line_item', array( - 'id' => $this->get_object()->get_id(), - )), + 'href' => wu_get_form_url( + 'edit_line_item', + array( + 'id' => $this->get_object()->get_id(), + ) + ), ); - return wu_get_template_contents('payments/line-item-actions', array( - 'payment' => $this->get_object(), - 'actions' => $actions, - )); - - } // end display_payment_actions; + return wu_get_template_contents( + 'payments/line-item-actions', + array( + 'payment' => $this->get_object(), + 'actions' => $actions, + ) + ); + } /** * Displays the tax tax breakthrough. @@ -915,12 +924,14 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { $tax_breakthrough = $this->get_object()->get_tax_breakthrough(); - wu_get_template('payments/tax-details', array( - 'tax_breakthrough' => $tax_breakthrough, - 'payment' => $this->get_object(), - )); - - } // end display_tax_breakthrough; + wu_get_template( + 'payments/tax-details', + array( + 'tax_breakthrough' => $tax_breakthrough, + 'payment' => $this->get_object(), + ) + ); + } /** * Allow child classes to register widgets, if they need them. @@ -938,192 +949,206 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { $tag = "{$label}"; - $this->add_fields_widget('at_a_glance', array( - 'title' => __('At a Glance', 'wp-ultimo'), - 'position' => 'normal', - 'classes' => 'wu-overflow-hidden wu-widget-inset', - 'field_wrapper_classes' => 'wu-w-1/3 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', - 'fields' => array( - 'status' => array( - 'type' => 'text-display', - 'title' => __('Payment Status', '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-widget-inset', + 'field_wrapper_classes' => 'wu-w-1/3 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', + 'fields' => array( + 'status' => array( + 'type' => 'text-display', + 'title' => __('Payment Status', 'wp-ultimo'), + 'display_value' => $tag, + 'tooltip' => '', + ), + 'hash' => array( + 'copy' => true, + 'type' => 'text-display', + 'title' => __('Reference ID', 'wp-ultimo'), + 'display_value' => $this->get_object()->get_hash(), + ), + 'total' => array( + 'type' => 'text-display', + 'title' => __('Total', 'wp-ultimo'), + 'display_value' => wu_format_currency($this->get_object()->get_total(), $this->get_object()->get_currency()), + 'wrapper_classes' => 'sm:wu-border-r-0', + ), ), - 'hash' => array( - 'copy' => true, - 'type' => 'text-display', - 'title' => __('Reference ID', 'wp-ultimo'), - 'display_value' => $this->get_object()->get_hash(), - ), - 'total' => array( - 'type' => 'text-display', - 'title' => __('Total', 'wp-ultimo'), - 'display_value' => wu_format_currency($this->get_object()->get_total(), $this->get_object()->get_currency()), - 'wrapper_classes' => 'sm:wu-border-r-0', - ), - ), - )); + ) + ); - $this->add_list_table_widget('line-items', array( - 'title' => __('Line Items', 'wp-ultimo'), - 'table' => new \WP_Ultimo\List_Tables\Payment_Line_Item_List_Table(), - 'position' => 'normal', - 'query_filter' => array($this, 'payments_query_filter'), - 'after' => $this->display_payment_actions(), - )); + $this->add_list_table_widget( + 'line-items', + array( + 'title' => __('Line Items', 'wp-ultimo'), + 'table' => new \WP_Ultimo\List_Tables\Payment_Line_Item_List_Table(), + 'position' => 'normal', + 'query_filter' => array($this, 'payments_query_filter'), + 'after' => $this->display_payment_actions(), + ) + ); - $this->add_widget('tax-rates', array( - 'title' => __('Tax Rate Breakthrough', 'wp-ultimo'), - 'position' => 'normal', - 'display' => array($this, 'display_tax_breakthrough'), - )); + $this->add_widget( + 'tax-rates', + array( + 'title' => __('Tax Rate Breakthrough', 'wp-ultimo'), + 'position' => 'normal', + 'display' => array($this, 'display_tax_breakthrough'), + ) + ); - $this->add_tabs_widget('options', array( - 'title' => __('Payment Options', 'wp-ultimo'), - 'position' => 'normal', - 'sections' => apply_filters('wu_payments_options_sections', array(), $this->get_object()), - )); + $this->add_tabs_widget( + 'options', + array( + 'title' => __('Payment Options', 'wp-ultimo'), + 'position' => 'normal', + 'sections' => apply_filters('wu_payments_options_sections', array(), $this->get_object()), + ) + ); - $this->add_list_table_widget('events', array( - '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'), + ) + ); $membership = $this->get_object()->get_membership(); - $this->add_save_widget('save', array( - 'html_attr' => array( - 'data-wu-app' => 'payment_save', - 'data-state' => wu_convert_to_state(array( - 'status' => $this->get_object()->get_status(), - 'original_status' => $this->get_object()->get_status(), - 'membership_id' => $membership ? $this->get_object()->get_membership_id() : '', - 'membership_status' => $membership ? $membership->get_status() : 'active', - 'gateway' => $this->get_object()->get_gateway(), - )), - ), - 'fields' => array( - 'status' => array( - 'type' => 'select', - 'title' => __('Status', 'wp-ultimo'), - 'placeholder' => __('Status', 'wp-ultimo'), - 'desc' => __('The payment current status.', 'wp-ultimo'), - 'value' => $this->get_object()->get_status(), - 'options' => Payment_Status::to_array(), - 'tooltip' => '', - 'wrapper_html_attr' => array( - 'v-cloak' => '1', - ), - 'html_attr' => array( - 'v-model' => 'status', + $this->add_save_widget( + 'save', + array( + 'html_attr' => array( + 'data-wu-app' => 'payment_save', + 'data-state' => wu_convert_to_state( + array( + 'status' => $this->get_object()->get_status(), + 'original_status' => $this->get_object()->get_status(), + 'membership_id' => $membership ? $this->get_object()->get_membership_id() : '', + 'membership_status' => $membership ? $membership->get_status() : 'active', + 'gateway' => $this->get_object()->get_gateway(), + ) ), ), - 'confirm_membership' => array( - 'type' => 'toggle', - 'title' => __('Activate Membership?', 'wp-ultimo'), - 'desc' => __('This payment belongs to a pending membership. If you toggle this option, this change in status will also apply to the membership. If any sites are pending, they are also going to be published automatically.', 'wp-ultimo'), - 'value' => 0, - 'wrapper_html_attr' => array( - 'v-if' => 'status !== original_status && status === "completed" && membership_status === "pending"', - 'v-cloak' => '1', + 'fields' => array( + 'status' => array( + 'type' => 'select', + 'title' => __('Status', 'wp-ultimo'), + 'placeholder' => __('Status', 'wp-ultimo'), + 'desc' => __('The payment current status.', 'wp-ultimo'), + 'value' => $this->get_object()->get_status(), + 'options' => Payment_Status::to_array(), + 'tooltip' => '', + 'wrapper_html_attr' => array( + 'v-cloak' => '1', + ), + 'html_attr' => array( + 'v-model' => 'status', + ), ), - ), - 'membership_id' => array( - 'type' => 'model', - 'title' => __('Membership', 'wp-ultimo'), - 'desc' => __('The membership associated with this payment.', 'wp-ultimo'), - 'value' => $this->get_object()->get_membership_id(), - 'tooltip' => '', - 'html_attr' => array( - 'v-model' => 'membership_id', - 'data-base-link' => wu_network_admin_url('wp-ultimo-edit-membership', array('id' => '')), - 'data-model' => 'membership', - 'data-value-field' => 'id', - 'data-label-field' => 'reference_code', - 'data-max-items' => 1, - 'data-selected' => $this->get_object()->get_membership() ? json_encode($this->get_object()->get_membership()->to_search_results()) : '', + 'confirm_membership' => array( + 'type' => 'toggle', + 'title' => __('Activate Membership?', 'wp-ultimo'), + 'desc' => __('This payment belongs to a pending membership. If you toggle this option, this change in status will also apply to the membership. If any sites are pending, they are also going to be published automatically.', 'wp-ultimo'), + 'value' => 0, + 'wrapper_html_attr' => array( + 'v-if' => 'status !== original_status && status === "completed" && membership_status === "pending"', + 'v-cloak' => '1', + ), ), - 'wrapper_html_attr' => array( - 'v-cloak' => '1', + 'membership_id' => array( + 'type' => 'model', + 'title' => __('Membership', 'wp-ultimo'), + 'desc' => __('The membership associated with this payment.', 'wp-ultimo'), + 'value' => $this->get_object()->get_membership_id(), + 'tooltip' => '', + 'html_attr' => array( + 'v-model' => 'membership_id', + 'data-base-link' => wu_network_admin_url('wp-ultimo-edit-membership', array('id' => '')), + 'data-model' => 'membership', + 'data-value-field' => 'id', + 'data-label-field' => 'reference_code', + 'data-max-items' => 1, + 'data-selected' => $this->get_object()->get_membership() ? json_encode($this->get_object()->get_membership()->to_search_results()) : '', + ), + 'wrapper_html_attr' => array( + 'v-cloak' => '1', + ), ), - ), - 'gateway' => array( - 'type' => 'text', - 'title' => __('Gateway', 'wp-ultimo'), - 'placeholder' => __('e.g. stripe', 'wp-ultimo'), - 'description' => __('e.g. stripe', 'wp-ultimo'), - 'desc' => __('Payment gateway used to process the payment.', 'wp-ultimo'), - 'value' => $this->get_object()->get_gateway(), - 'wrapper_classes' => 'wu-w-full', - 'html_attr' => array( - 'v-on:input' => 'gateway = $event.target.value.toLowerCase().replace(/[^a-z0-9-_]+/g, "")', - 'v-bind:value' => 'gateway', + 'gateway' => array( + 'type' => 'text', + 'title' => __('Gateway', 'wp-ultimo'), + 'placeholder' => __('e.g. stripe', 'wp-ultimo'), + 'description' => __('e.g. stripe', 'wp-ultimo'), + 'desc' => __('Payment gateway used to process the payment.', 'wp-ultimo'), + 'value' => $this->get_object()->get_gateway(), + 'wrapper_classes' => 'wu-w-full', + 'html_attr' => array( + 'v-on:input' => 'gateway = $event.target.value.toLowerCase().replace(/[^a-z0-9-_]+/g, "")', + 'v-bind:value' => 'gateway', + ), + 'wrapper_html_attr' => array( + 'v-cloak' => '1', + ), ), - 'wrapper_html_attr' => array( - 'v-cloak' => '1', - ), - ), - 'gateway_payment_id_group' => array( - 'type' => 'group', - 'desc' => function(): string { + 'gateway_payment_id_group' => array( + 'type' => 'group', + 'desc' => function (): string { - $gateway_id = $this->get_object()->get_gateway(); + $gateway_id = $this->get_object()->get_gateway(); - if (empty($this->get_object()->get_gateway_payment_id())) { + if (empty($this->get_object()->get_gateway_payment_id())) { + return ''; + } + + $url = apply_filters("wu_{$gateway_id}_remote_payment_url", $this->get_object()->get_gateway_payment_id()); + + if ($url) { + return sprintf('%s', esc_attr($url), __('View on Gateway →', 'wp-ultimo')); + } return ''; - - } // end if; - - $url = apply_filters("wu_{$gateway_id}_remote_payment_url", $this->get_object()->get_gateway_payment_id()); - - if ($url) { - - return sprintf('%s', esc_attr($url), __('View on Gateway →', 'wp-ultimo')); - - } // end if; - - return ''; - - }, - 'wrapper_html_attr' => array( - 'v-cloak' => '1', - 'v-show' => 'gateway', + }, + 'wrapper_html_attr' => array( + 'v-cloak' => '1', + 'v-show' => 'gateway', + ), + 'fields' => array( + 'gateway_payment_id' => array( + 'type' => 'text', + 'title' => __('Gateway Payment ID', 'wp-ultimo'), + 'placeholder' => __('e.g. EX897540987913', 'wp-ultimo'), + 'description' => __('e.g. EX897540987913', 'wp-ultimo'), + 'tooltip' => __('This will usually be set automatically by the payment gateway.', 'wp-ultimo'), + 'value' => $this->get_object()->get_gateway_payment_id(), + 'wrapper_classes' => 'wu-w-full', + 'html_attr' => array(), + 'wrapper_html_attr' => array(), + ), + ), ), - 'fields' => array( - 'gateway_payment_id' => array( - 'type' => 'text', - 'title' => __('Gateway Payment ID', 'wp-ultimo'), - 'placeholder' => __('e.g. EX897540987913', 'wp-ultimo'), - 'description' => __('e.g. EX897540987913', 'wp-ultimo'), - 'tooltip' => __('This will usually be set automatically by the payment gateway.', 'wp-ultimo'), - 'value' => $this->get_object()->get_gateway_payment_id(), - 'wrapper_classes' => 'wu-w-full', - 'html_attr' => array(), - 'wrapper_html_attr' => array(), + 'invoice_number' => array( + 'type' => 'number', + 'min' => 0, + 'title' => __('Invoice Number', 'wp-ultimo'), + 'placeholder' => __('e.g. 20', 'wp-ultimo'), + 'tooltip' => __('This number gets saved automatically when a payment transitions to a complete state. You can change it to generate invoices with a particular number. The number chosen here has no effect on other invoices in the platform.', 'wp-ultimo'), + 'desc' => __('The invoice number for this particular payment.', 'wp-ultimo'), + 'value' => $this->get_object()->get_saved_invoice_number(), + 'wrapper_classes' => 'wu-w-full', + 'wrapper_html_attr' => array( + 'v-show' => json_encode(wu_get_setting('invoice_numbering_scheme', 'reference_code') === 'sequential_number'), + 'v-cloak' => '1', ), ), ), - 'invoice_number' => array( - 'type' => 'number', - 'min' => 0, - 'title' => __('Invoice Number', 'wp-ultimo'), - 'placeholder' => __('e.g. 20', 'wp-ultimo'), - 'tooltip' => __('This number gets saved automatically when a payment transitions to a complete state. You can change it to generate invoices with a particular number. The number chosen here has no effect on other invoices in the platform.', 'wp-ultimo'), - 'desc' => __('The invoice number for this particular payment.', 'wp-ultimo'), - 'value' => $this->get_object()->get_saved_invoice_number(), - 'wrapper_classes' => 'wu-w-full', - 'wrapper_html_attr' => array( - 'v-show' => json_encode(wu_get_setting('invoice_numbering_scheme', 'reference_code') === 'sequential_number'), - 'v-cloak' => '1', - ), - ), - ), - )); - - } // end register_widgets; + ) + ); + } /** * Returns the title of the page. @@ -1134,8 +1159,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { public function get_title() { return $this->edit ? __('Edit Payment', 'wp-ultimo') : __('Add new Payment', 'wp-ultimo'); - - } // end get_title; + } /** * Returns the title of menu for this page. @@ -1146,8 +1170,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { public function get_menu_title() { return __('Edit Payment', 'wp-ultimo'); - - } // end get_menu_title; + } /** * Returns the action links for that page. @@ -1162,7 +1185,6 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { $payment = $this->get_object(); if ($payment) { - $actions[] = array( 'url' => $payment->get_invoice_url(), 'label' => __('Generate Invoice', 'wp-ultimo'), @@ -1170,20 +1192,16 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { ); if ($payment->is_payable()) { - $actions[] = array( 'url' => $payment->get_payment_url(), 'label' => __('Payment URL', 'wp-ultimo'), 'icon' => 'wu-credit-card', ); - - } // end if; - - } // end if; + } + } return $actions; - - } // end action_links; + } /** * Returns the labels to be used on the admin page. @@ -1204,8 +1222,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { 'delete_button_label' => __('Delete Payment', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), ); - - } // end get_labels; + } /** * Filters the list table to return only relevant events. @@ -1223,8 +1240,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { ); return array_merge($args, $extra_args); - - } // end events_query_filter; + } /** * Filters the list table to return only relevant events. @@ -1242,8 +1258,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { ); return array_merge($args, $extra_args); - - } // end payments_query_filter; + } /** * Returns the object being edit at the moment. @@ -1256,34 +1271,27 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { static $payment; if ($payment !== null) { - return $payment; - - } // end if; + } if (isset($_GET['id'])) { - - $query = new \WP_Ultimo\Database\Payments\Payment_Query; + $query = new \WP_Ultimo\Database\Payments\Payment_Query(); $item = $query->get_item_by('id', $_GET['id']); - if (!$item || $item->get_parent_id()) { - + if ( ! $item || $item->get_parent_id()) { wp_redirect(wu_network_admin_url('wp-ultimo-payments')); exit; - - } // end if; + } $payment = $item; return $item; + } - } // end if; - - return new Payment; - - } // end get_object; + return new Payment(); + } /** * Payments have titles. * @@ -1292,8 +1300,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { public function has_title(): bool { return false; - - } // end has_title; + } /** * WIP: Handles saving by recalculating totals for a payment. @@ -1309,21 +1316,15 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page { $should_confirm_membership = wu_request('confirm_membership'); if ($should_confirm_membership) { - $membership = $this->get_object()->get_membership(); if ($membership) { - $membership->add_to_times_billed(1); $membership->renew(false, 'active'); - - } // end if; - - } // end if; + } + } parent::handle_save(); - - } // end handle_save; - -} // end class Payment_Edit_Admin_Page; + } +} diff --git a/inc/admin-pages/class-payment-list-admin-page.php b/inc/admin-pages/class-payment-list-admin-page.php index 99400e0..b879956 100644 --- a/inc/admin-pages/class-payment-list-admin-page.php +++ b/inc/admin-pages/class-payment-list-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-placeholders-admin-page.php b/inc/admin-pages/class-placeholders-admin-page.php index 1cfbbf1..68c78ef 100644 --- a/inc/admin-pages/class-placeholders-admin-page.php +++ b/inc/admin-pages/class-placeholders-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-product-edit-admin-page.php b/inc/admin-pages/class-product-edit-admin-page.php index fb2d52a..2d81934 100644 --- a/inc/admin-pages/class-product-edit-admin-page.php +++ b/inc/admin-pages/class-product-edit-admin-page.php @@ -12,8 +12,8 @@ namespace WP_Ultimo\Admin_Pages; // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Models\Product; -use \WP_Ultimo\Database\Products\Product_Type; +use WP_Ultimo\Models\Product; +use WP_Ultimo\Database\Products\Product_Type; /** * WP Multisite WaaS Product Edit/Add New Admin Page. @@ -96,8 +96,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { add_action('wu_after_delete_product_modal', array($this, 'product_after_delete_actions')); add_filter("wu_page_{$this->id}_load", array($this, 'add_new_product_warning_message')); - - } // end register_forms; + } /** * Adds the new product warning. @@ -108,39 +107,37 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { public function add_new_product_warning_message() { if (wu_request('wu-new-model')) { - - if (!$this->get_object() || $this->get_object()->get_type() !== Product_Type::PLAN) { - + if ( ! $this->get_object() || $this->get_object()->get_type() !== Product_Type::PLAN) { return; + } - } // end if; - - \WP_Ultimo\UI\Tours::get_instance()->create_tour('new_product_warning', array( + \WP_Ultimo\UI\Tours::get_instance()->create_tour( + 'new_product_warning', array( - 'id' => 'new-product-warning', - 'title' => __('On adding a new product...', 'wp-ultimo'), - 'text' => array( - __("You just successfully added a new product to your WP Multisite WaaS network and that's awesome!", 'wp-ultimo'), - __('Keep in mind that newly created products do not appear automatically in your checkout forms.', 'wp-ultimo'), - __('To make a product available on registration, you will need to manually add it to the pricing table field of your checkout forms.', 'wp-ultimo'), + array( + 'id' => 'new-product-warning', + 'title' => __('On adding a new product...', 'wp-ultimo'), + 'text' => array( + __("You just successfully added a new product to your WP Multisite WaaS network and that's awesome!", 'wp-ultimo'), + __('Keep in mind that newly created products do not appear automatically in your checkout forms.', 'wp-ultimo'), + __('To make a product available on registration, you will need to manually add it to the pricing table 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_product_warning_message; + ) + ); + } + } /** * Adds the extra delete fields to the delete form. @@ -165,14 +162,13 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { 'data-label-field' => 'name', 'data-search-field' => 'name', 'data-max-items' => 1, - 'data-exclude' => json_encode(array($product->get_id())) + 'data-exclude' => json_encode(array($product->get_id())), ), ), ); return array_merge($custom_fields, $fields); - - } // end product_extra_delete_fields; + } /** * Adds the primary domain handling to the product deletion. @@ -191,7 +187,6 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { $re_assignment_product = wu_get_product($new_product_id); if ($re_assignment_product) { - $query = $wpdb->prepare( "UPDATE {$wpdb->base_prefix}wu_memberships SET product_id = %d @@ -201,10 +196,8 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { ); $wpdb->query($query); // phpcs:ignore - - } // end if; - - } // end product_after_delete_actions; + } + } /** * Registers the necessary scripts and styles for this admin page. @@ -217,8 +210,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { parent::register_scripts(); wp_enqueue_media(); - - } // end register_scripts; + } /** * Allow child classes to register widgets, if they need them. @@ -230,303 +222,323 @@ class Product_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' => __('Product Description', 'wp-ultimo'), - 'placeholder' => __('Tell your customers what this product is about.', 'wp-ultimo'), - 'tooltip' => __('This description is made available for layouts and can be shown to end customers.', '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' => __('Product Description', 'wp-ultimo'), + 'placeholder' => __('Tell your customers what this product is about.', 'wp-ultimo'), + 'tooltip' => __('This description is made available for layouts and can be shown to end customers.', 'wp-ultimo'), + 'value' => $this->get_object()->get_description(), + 'html_attr' => array( + 'rows' => 3, + ), ), ), - ), - )); + ) + ); - $this->add_tabs_widget('product_options', array( - 'title' => __('Product Options', 'wp-ultimo'), - 'position' => 'normal', - 'sections' => $this->get_product_option_sections(), - )); + $this->add_tabs_widget( + 'product_options', + array( + 'title' => __('Product Options', 'wp-ultimo'), + 'position' => 'normal', + 'sections' => $this->get_product_option_sections(), + ) + ); /* * Handle legacy options for back-compat. */ $this->handle_legacy_options(); - $this->add_list_table_widget('events', array( - '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'), + ) + ); - $save_widget_args = apply_filters('wu_product_edit_save_widget', array( - 'html_attr' => array( - 'data-wu-app' => 'product_pricing', - 'data-state' => json_encode(array( - 'is_recurring' => $this->get_object()->is_recurring(), - 'pricing_type' => $this->get_object()->get_pricing_type(), - 'has_trial' => $this->get_object()->get_trial_duration() > 0, - 'has_setup_fee' => $this->get_object()->has_setup_fee(), - 'setup_fee' => $this->get_object()->get_setup_fee(), - 'amount' => $this->get_object()->get_formatted_amount(), - 'duration' => $this->get_object()->get_duration(), - 'duration_unit' => $this->get_object()->get_duration_unit(), - )), - ), - 'fields' => array( - // Fields for price - 'pricing_type' => array( - 'type' => 'select', - 'title' => __('Pricing Type', 'wp-ultimo'), - 'placeholder' => __('Select Pricing Type', 'wp-ultimo'), - 'desc' => __('Products can be free, paid, or require further contact for pricing.', 'wp-ultimo'), - 'value' => $this->get_object()->get_pricing_type(), - 'tooltip' => '', - 'options' => array( - 'paid' => __('Paid', 'wp-ultimo'), - 'free' => __('Free', 'wp-ultimo'), - 'contact_us' => __('Contact Us', 'wp-ultimo'), - ), - 'wrapper_html_attr' => array( - 'v-cloak' => '1', - ), - 'html_attr' => array( - 'v-model' => 'pricing_type', + $save_widget_args = apply_filters( + 'wu_product_edit_save_widget', + array( + 'html_attr' => array( + 'data-wu-app' => 'product_pricing', + 'data-state' => json_encode( + array( + 'is_recurring' => $this->get_object()->is_recurring(), + 'pricing_type' => $this->get_object()->get_pricing_type(), + 'has_trial' => $this->get_object()->get_trial_duration() > 0, + 'has_setup_fee' => $this->get_object()->has_setup_fee(), + 'setup_fee' => $this->get_object()->get_setup_fee(), + 'amount' => $this->get_object()->get_formatted_amount(), + 'duration' => $this->get_object()->get_duration(), + 'duration_unit' => $this->get_object()->get_duration_unit(), + ) ), ), - 'contact_us_label' => array( - 'type' => 'text', - 'title' => __('Button Label', 'wp-ultimo'), - 'placeholder' => __('E.g. Contact us', 'wp-ultimo'), - 'desc' => __('This will be used on the pricing table CTA button, as the label.', 'wp-ultimo'), - 'value' => $this->get_object()->get_contact_us_label(), - 'wrapper_html_attr' => array( - 'v-show' => "pricing_type == 'contact_us'", - 'v-cloak' => '1', - ), - ), - 'contact_us_link' => array( - 'type' => 'url', - 'title' => __('Button Link', 'wp-ultimo'), - 'placeholder' => __('E.g. https://contactus.page.com', 'wp-ultimo'), - 'desc' => __('This will be used on the pricing table CTA button.', 'wp-ultimo'), - 'value' => $this->get_object()->get_contact_us_link(), - 'wrapper_html_attr' => array( - 'v-show' => "pricing_type == 'contact_us'", - 'v-cloak' => '1', - ), - ), - 'recurring' => array( - 'type' => 'toggle', - 'title' => __('Is Recurring?', 'wp-ultimo'), - 'desc' => __('Check this if this product has a recurring charge.', 'wp-ultimo'), - 'value' => $this->get_object()->is_recurring(), - 'wrapper_html_attr' => array( - 'v-show' => "pricing_type == 'paid'", - 'v-cloak' => '1', - ), - 'html_attr' => array( - 'v-model' => 'is_recurring', - ), - ), - 'amount' => array( - 'type' => 'hidden', - 'html_attr' => array( - 'v-model' => 'amount', - ), - ), - '_amount' => array( - 'type' => 'text', - 'title' => __('Price', 'wp-ultimo'), - 'placeholder' => __('Price', 'wp-ultimo'), - 'value' => $this->get_object()->get_formatted_amount(), - 'tooltip' => '', - 'money' => true, - 'wrapper_html_attr' => array( - 'v-show' => "pricing_type == 'paid' && !is_recurring ", - 'v-cloak' => '1', - ), - 'html_attr' => array( - 'v-bind:name' => '""', - 'v-model' => 'amount', - ), - ), - 'amount_group' => array( - 'type' => 'group', - 'title' => __('Price', 'wp-ultimo'), - // translators: placeholder %1$s is the amount, %2$s is the duration (such as 1, 2, 3), and %3$s is the unit (such as month, year, week) - 'desc' => sprintf(__('The customer will be charged %1$s every %2$s %3$s(s).', 'wp-ultimo'), '{{ wu_format_money(amount) }}', '{{ duration }}', '{{ duration_unit }}'), - 'tooltip' => '', - 'wrapper_html_attr' => array( - 'v-show' => "is_recurring && pricing_type == 'paid'", - 'v-cloak' => '1', - ), - 'fields' => array( - '_amount' => array( - 'type' => 'text', - 'value' => $this->get_object()->get_formatted_amount(), - 'placeholder' => wu_format_currency('99'), - 'wrapper_classes' => '', - 'money' => true, - 'html_attr' => array( - 'v-bind:name' => '""', - 'v-model' => 'amount', - ), + 'fields' => array( + // Fields for price + 'pricing_type' => array( + 'type' => 'select', + 'title' => __('Pricing Type', 'wp-ultimo'), + 'placeholder' => __('Select Pricing Type', 'wp-ultimo'), + 'desc' => __('Products can be free, paid, or require further contact for pricing.', 'wp-ultimo'), + 'value' => $this->get_object()->get_pricing_type(), + 'tooltip' => '', + 'options' => array( + 'paid' => __('Paid', 'wp-ultimo'), + 'free' => __('Free', 'wp-ultimo'), + 'contact_us' => __('Contact Us', 'wp-ultimo'), ), - 'duration' => array( - 'type' => 'number', - 'value' => $this->get_object()->get_duration(), - 'placeholder' => '', - 'wrapper_classes' => 'wu-mx-2 wu-w-1/3', - 'min' => 0, - 'html_attr' => array( - 'v-model' => 'duration', - 'steps' => 1, - ), + 'wrapper_html_attr' => array( + 'v-cloak' => '1', ), - 'duration_unit' => array( - 'type' => 'select', - 'value' => $this->get_object()->get_duration_unit(), - 'placeholder' => '', - 'wrapper_classes' => 'wu-w-2/3', - 'html_attr' => array( - 'v-model' => 'duration_unit', + 'html_attr' => array( + 'v-model' => 'pricing_type', + ), + ), + 'contact_us_label' => array( + 'type' => 'text', + 'title' => __('Button Label', 'wp-ultimo'), + 'placeholder' => __('E.g. Contact us', 'wp-ultimo'), + 'desc' => __('This will be used on the pricing table CTA button, as the label.', 'wp-ultimo'), + 'value' => $this->get_object()->get_contact_us_label(), + 'wrapper_html_attr' => array( + 'v-show' => "pricing_type == 'contact_us'", + 'v-cloak' => '1', + ), + ), + 'contact_us_link' => array( + 'type' => 'url', + 'title' => __('Button Link', 'wp-ultimo'), + 'placeholder' => __('E.g. https://contactus.page.com', 'wp-ultimo'), + 'desc' => __('This will be used on the pricing table CTA button.', 'wp-ultimo'), + 'value' => $this->get_object()->get_contact_us_link(), + 'wrapper_html_attr' => array( + 'v-show' => "pricing_type == 'contact_us'", + 'v-cloak' => '1', + ), + ), + 'recurring' => array( + 'type' => 'toggle', + 'title' => __('Is Recurring?', 'wp-ultimo'), + 'desc' => __('Check this if this product has a recurring charge.', 'wp-ultimo'), + 'value' => $this->get_object()->is_recurring(), + 'wrapper_html_attr' => array( + 'v-show' => "pricing_type == 'paid'", + 'v-cloak' => '1', + ), + 'html_attr' => array( + 'v-model' => 'is_recurring', + ), + ), + 'amount' => array( + 'type' => 'hidden', + 'html_attr' => array( + 'v-model' => 'amount', + ), + ), + '_amount' => array( + 'type' => 'text', + 'title' => __('Price', 'wp-ultimo'), + 'placeholder' => __('Price', 'wp-ultimo'), + 'value' => $this->get_object()->get_formatted_amount(), + 'tooltip' => '', + 'money' => true, + 'wrapper_html_attr' => array( + 'v-show' => "pricing_type == 'paid' && !is_recurring ", + 'v-cloak' => '1', + ), + 'html_attr' => array( + 'v-bind:name' => '""', + 'v-model' => 'amount', + ), + ), + 'amount_group' => array( + 'type' => 'group', + 'title' => __('Price', 'wp-ultimo'), + // translators: placeholder %1$s is the amount, %2$s is the duration (such as 1, 2, 3), and %3$s is the unit (such as month, year, week) + 'desc' => sprintf(__('The customer will be charged %1$s every %2$s %3$s(s).', 'wp-ultimo'), '{{ wu_format_money(amount) }}', '{{ duration }}', '{{ duration_unit }}'), + 'tooltip' => '', + 'wrapper_html_attr' => array( + 'v-show' => "is_recurring && pricing_type == 'paid'", + 'v-cloak' => '1', + ), + 'fields' => array( + '_amount' => array( + 'type' => 'text', + 'value' => $this->get_object()->get_formatted_amount(), + 'placeholder' => wu_format_currency('99'), + 'wrapper_classes' => '', + 'money' => true, + 'html_attr' => array( + 'v-bind:name' => '""', + 'v-model' => 'amount', + ), ), - 'options' => array( - 'day' => __('Days', 'wp-ultimo'), - 'week' => __('Weeks', 'wp-ultimo'), - 'month' => __('Months', 'wp-ultimo'), - 'year' => __('Years', 'wp-ultimo'), + 'duration' => array( + 'type' => 'number', + 'value' => $this->get_object()->get_duration(), + 'placeholder' => '', + 'wrapper_classes' => 'wu-mx-2 wu-w-1/3', + 'min' => 0, + 'html_attr' => array( + 'v-model' => 'duration', + 'steps' => 1, + ), + ), + 'duration_unit' => array( + 'type' => 'select', + 'value' => $this->get_object()->get_duration_unit(), + 'placeholder' => '', + 'wrapper_classes' => 'wu-w-2/3', + 'html_attr' => array( + 'v-model' => 'duration_unit', + ), + 'options' => array( + 'day' => __('Days', 'wp-ultimo'), + 'week' => __('Weeks', 'wp-ultimo'), + 'month' => __('Months', 'wp-ultimo'), + 'year' => __('Years', 'wp-ultimo'), + ), ), ), ), - ), - 'billing_cycles' => array( - 'type' => 'number', - 'title' => __('Billing Cycles', 'wp-ultimo'), - 'placeholder' => __('E.g. 1', 'wp-ultimo'), - 'desc' => __('How many times should we bill this customer. Leave 0 to charge until cancelled.', 'wp-ultimo'), - 'value' => $this->get_object()->get_billing_cycles(), - 'tooltip' => '', - 'wrapper_html_attr' => array( - 'v-show' => "is_recurring && pricing_type == 'paid'", - 'v-cloak' => '1', - ), - ), - 'has_trial' => array( - 'type' => 'toggle', - 'title' => __('Offer Trial', 'wp-ultimo'), - 'desc' => __('Check if you want to add a trial period to this product.', 'wp-ultimo'), - 'value' => $this->get_object()->has_trial(), - 'wrapper_html_attr' => array( - 'v-show' => "pricing_type == 'paid'", - 'v-cloak' => '1', - ), - 'html_attr' => array( - 'v-model' => 'has_trial', - ), - ), - 'trial_group' => array( - 'type' => 'group', - 'title' => __('Trial', 'wp-ultimo'), - 'tooltip' => '', - 'wrapper_html_attr' => array( - 'v-show' => "has_trial && pricing_type == 'paid'", - 'v-cloak' => '1', - ), - 'fields' => array( - 'trial_duration' => array( - 'type' => 'number', - 'value' => $this->get_object()->get_trial_duration(), - 'placeholder' => '', - 'wrapper_classes' => 'wu-mr-2 wu-w-1/3', + 'billing_cycles' => array( + 'type' => 'number', + 'title' => __('Billing Cycles', 'wp-ultimo'), + 'placeholder' => __('E.g. 1', 'wp-ultimo'), + 'desc' => __('How many times should we bill this customer. Leave 0 to charge until cancelled.', 'wp-ultimo'), + 'value' => $this->get_object()->get_billing_cycles(), + 'tooltip' => '', + 'wrapper_html_attr' => array( + 'v-show' => "is_recurring && pricing_type == 'paid'", + 'v-cloak' => '1', ), - 'trial_duration_unit' => array( - 'type' => 'select', - 'value' => $this->get_object()->get_trial_duration_unit(), - 'placeholder' => '', - 'wrapper_classes' => 'wu-w-2/3', - 'options' => array( - 'day' => __('Days', 'wp-ultimo'), - 'week' => __('Weeks', 'wp-ultimo'), - 'month' => __('Months', 'wp-ultimo'), - 'year' => __('Years', 'wp-ultimo'), + ), + 'has_trial' => array( + 'type' => 'toggle', + 'title' => __('Offer Trial', 'wp-ultimo'), + 'desc' => __('Check if you want to add a trial period to this product.', 'wp-ultimo'), + 'value' => $this->get_object()->has_trial(), + 'wrapper_html_attr' => array( + 'v-show' => "pricing_type == 'paid'", + 'v-cloak' => '1', + ), + 'html_attr' => array( + 'v-model' => 'has_trial', + ), + ), + 'trial_group' => array( + 'type' => 'group', + 'title' => __('Trial', 'wp-ultimo'), + 'tooltip' => '', + 'wrapper_html_attr' => array( + 'v-show' => "has_trial && pricing_type == 'paid'", + 'v-cloak' => '1', + ), + 'fields' => array( + 'trial_duration' => array( + 'type' => 'number', + 'value' => $this->get_object()->get_trial_duration(), + 'placeholder' => '', + 'wrapper_classes' => 'wu-mr-2 wu-w-1/3', + ), + 'trial_duration_unit' => array( + 'type' => 'select', + 'value' => $this->get_object()->get_trial_duration_unit(), + 'placeholder' => '', + 'wrapper_classes' => 'wu-w-2/3', + 'options' => array( + 'day' => __('Days', 'wp-ultimo'), + 'week' => __('Weeks', 'wp-ultimo'), + 'month' => __('Months', 'wp-ultimo'), + 'year' => __('Years', 'wp-ultimo'), + ), ), ), ), - ), - 'has_setup_fee' => array( - 'type' => 'toggle', - 'title' => __('Add Setup Fee?', 'wp-ultimo'), - 'desc' => __('Check if you want to add a setup fee.', 'wp-ultimo'), - 'value' => $this->get_object()->has_setup_fee(), - 'wrapper_html_attr' => array( - 'v-show' => "pricing_type == 'paid'", - 'v-cloak' => '1', + 'has_setup_fee' => array( + 'type' => 'toggle', + 'title' => __('Add Setup Fee?', 'wp-ultimo'), + 'desc' => __('Check if you want to add a setup fee.', 'wp-ultimo'), + 'value' => $this->get_object()->has_setup_fee(), + 'wrapper_html_attr' => array( + 'v-show' => "pricing_type == 'paid'", + 'v-cloak' => '1', + ), + 'html_attr' => array( + 'v-model' => 'has_setup_fee', + ), ), - 'html_attr' => array( - 'v-model' => 'has_setup_fee', + 'setup_fee' => array( + 'type' => 'hidden', + 'html_attr' => array( + 'v-model' => 'setup_fee', + ), ), - ), - 'setup_fee' => array( - 'type' => 'hidden', - 'html_attr' => array( - 'v-model' => 'setup_fee', - ), - ), - '_setup_fee' => array( - 'type' => 'text', - 'money' => true, - 'title' => __('Setup Fee', 'wp-ultimo'), - 'desc' => __('The setup fee will be added to the first charge, in addition to the regular price of the product.', 'wp-ultimo'), - // translators: %s is a price placeholder value. - 'placeholder' => sprintf(__('E.g. %s', 'wp-ultimo'), wu_format_currency(199)), - 'value' => $this->get_object()->get_formatted_amount('setup_fee'), - 'wrapper_html_attr' => array( - 'v-show' => "has_setup_fee && pricing_type == 'paid'", - 'v-cloak' => '1', - ), - 'html_attr' => array( - 'v-model' => 'setup_fee', + '_setup_fee' => array( + 'type' => 'text', + 'money' => true, + 'title' => __('Setup Fee', 'wp-ultimo'), + 'desc' => __('The setup fee will be added to the first charge, in addition to the regular price of the product.', 'wp-ultimo'), + // translators: %s is a price placeholder value. + 'placeholder' => sprintf(__('E.g. %s', 'wp-ultimo'), wu_format_currency(199)), + 'value' => $this->get_object()->get_formatted_amount('setup_fee'), + 'wrapper_html_attr' => array( + 'v-show' => "has_setup_fee && pricing_type == 'paid'", + 'v-cloak' => '1', + ), + 'html_attr' => array( + 'v-model' => 'setup_fee', + ), ), ), ), - ), $this->get_object()); + $this->get_object() + ); $this->add_save_widget('save', $save_widget_args); - $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 product 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 product for new sign-ups.', 'wp-ultimo'), + 'value' => $this->get_object()->is_active(), + ), ), - ), - )); + ) + ); - $this->add_fields_widget('image', array( - 'title' => __('Product Image', 'wp-ultimo'), - 'fields' => array( - 'featured_image_id' => array( - 'type' => 'image', - 'stacked' => true, - 'title' => __('Product Image', 'wp-ultimo'), - 'desc' => __('This image is used on product list tables and other places.', 'wp-ultimo'), - 'value' => $this->get_object()->get_featured_image_id(), - 'img' => $this->get_object()->get_featured_image(), + $this->add_fields_widget( + 'image', + array( + 'title' => __('Product Image', 'wp-ultimo'), + 'fields' => array( + 'featured_image_id' => array( + 'type' => 'image', + 'stacked' => true, + 'title' => __('Product Image', 'wp-ultimo'), + 'desc' => __('This image is used on product list tables and other places.', 'wp-ultimo'), + 'value' => $this->get_object()->get_featured_image_id(), + 'img' => $this->get_object()->get_featured_image(), + ), ), - ), - )); - - } // end register_widgets; + ) + ); + } /** * Handles legacy advanced options for plans. @@ -538,15 +550,18 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { global $wp_filter; - $tabs = apply_filters_deprecated('wu_plans_advanced_options_tabs', array( - array(), - ), '2.0.0', 'wu_product_options_sections'); - - if (!isset($wp_filter['wu_plans_advanced_options_after_panels'])) { + $tabs = apply_filters_deprecated( + 'wu_plans_advanced_options_tabs', + array( + array(), + ), + '2.0.0', + 'wu_product_options_sections' + ); + if ( ! isset($wp_filter['wu_plans_advanced_options_after_panels'])) { return; - - } // end if; + } wp_enqueue_style('wu-legacy-admin-tabs', wu_get_asset('legacy-admin-tabs.css', 'css'), false, wu_get_version()); @@ -562,35 +577,32 @@ class Product_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'], new \WU_Plan($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;', + ), + ) + ); + } /** * Returns the list of sections and its fields for the product page. @@ -693,10 +705,14 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { 'data-label-field' => 'name', 'data-search-field' => 'name', 'data-max-items' => 99, - 'data-selected' => json_encode(wu_get_products(array( - 'id__in' => $this->get_object()->get_available_addons(), - 'id__not_in' => array_keys(wu_get_plans_as_options()), - ))), + 'data-selected' => json_encode( + wu_get_products( + array( + 'id__in' => $this->get_object()->get_available_addons(), + 'id__not_in' => array_keys(wu_get_plans_as_options()), + ) + ) + ), ), ), ), @@ -707,7 +723,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { 'desc' => __('Discounts for longer membership commitments.', 'wp-ultimo'), 'icon' => 'dashicons-wu-price-tag', 'state' => array( - 'enable_price_variations' => !empty($this->get_object()->get_price_variations()), + 'enable_price_variations' => ! empty($this->get_object()->get_price_variations()), 'price_variations' => $this->get_object()->get_price_variations(), ), 'fields' => array( @@ -770,7 +786,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { 'type' => 'hidden', 'html_attr' => array( 'v-bind:value' => 'price_variation.amount', - 'v-bind:name' => '"price_variations[" + index + "][amount]"' + 'v-bind:name' => '"price_variations[" + index + "][amount]"', ), ), '_price_variations_amount' => array( @@ -869,7 +885,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { 'options' => array( 'default' => __('Default', 'wp-ultimo'), 'assign_template' => __('Assign Site Template', 'wp-ultimo'), - 'choose_available_templates' => __('Choose Available Site Templates', 'wp-ultimo') + 'choose_available_templates' => __('Choose Available Site Templates', 'wp-ultimo'), ), 'html_attr' => array( 'v-model' => 'site_template_selection_mode', @@ -893,8 +909,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { ); return apply_filters('wu_product_options_sections', $sections, $this->get_object()); - - } // end get_product_option_sections; + } /** * Returns the HTML markup for the plugin selector list. @@ -908,12 +923,14 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { $all_templates = wu_get_site_templates(); - return wu_get_template_contents('limitations/site-template-selector', array( - 'templates' => $all_templates, - 'product' => $product, - )); - - } // end get_site_template_selection_list; + return wu_get_template_contents( + 'limitations/site-template-selector', + array( + 'templates' => $all_templates, + 'product' => $product, + ) + ); + } /** * Returns the title of the page. @@ -924,8 +941,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { public function get_title() { return $this->edit ? __('Edit Product', 'wp-ultimo') : __('Add new Product', 'wp-ultimo'); - - } // end get_title; + } /** * Returns the title of menu for this page. @@ -936,8 +952,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { public function get_menu_title() { return __('Edit Product', 'wp-ultimo'); - - } // end get_menu_title; + } /** * Returns the action links for that page. @@ -950,7 +965,6 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { $actions = array(); if ($this->get_object()->get_type() === 'plan' && $this->edit) { - $shareable_link = $this->get_object()->get_shareable_link(); $actions[] = array( @@ -960,12 +974,10 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { 'classes' => 'wu-copy', 'attrs' => 'data-clipboard-text="' . esc_attr($shareable_link) . '"', ); - - } // end if; + } return $actions; - - } // end action_links; + } /** * Returns the labels to be used on the admin page. @@ -986,8 +998,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { 'delete_button_label' => __('Delete Product', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), ); - - } // end get_labels; + } /** * Filters the list table to return only relevant events. @@ -1005,8 +1016,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { ); return array_merge($args, $extra_args); - - } // end query_filter; + } /** * Returns the object being edit at the moment. @@ -1017,36 +1027,29 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { public function get_object() { if ($this->object !== null) { - return $this->object; - - } // end if; + } if (isset($_GET['id'])) { - - $query = new \WP_Ultimo\Database\Products\Product_Query; + $query = new \WP_Ultimo\Database\Products\Product_Query(); $item = $query->get_item_by('id', $_GET['id']); - if (!$item) { - + if ( ! $item) { wp_redirect(wu_network_admin_url('wp-ultimo-products')); exit; - - } // end if; + } $this->object = $item; return $this->object; + } - } // end if; - - $this->object = new Product; + $this->object = new Product(); return $this->object; - - } // end get_object; + } /** * Products have titles. * @@ -1055,8 +1058,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { public function has_title(): bool { return true; - - } // end has_title; + } /** * Should implement the processes necessary to save the changes made to the object. @@ -1068,62 +1070,46 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page { /* * Set the recurring value to zero if the toggle is disabled. */ - if (!wu_request('recurring')) { - + if ( ! wu_request('recurring')) { $_POST['recurring'] = false; + } - } // end if; - - if (!wu_request('legacy_options')) { - + if ( ! wu_request('legacy_options')) { $_POST['legacy_options'] = false; + } - } // end if; - - if (!wu_request('featured_plan')) { - + if ( ! wu_request('featured_plan')) { $_POST['featured_plan'] = false; - - } // end if; + } /* * Set the setup fee value to zero if the toggle is disabled. */ - if (!wu_request('has_setup_fee')) { - + if ( ! wu_request('has_setup_fee')) { $_POST['setup_fee'] = 0; - - } // end if; + } /* * Disabled Trial */ - if (!wu_request('has_trial')) { - + if ( ! wu_request('has_trial')) { $_POST['trial_duration'] = 0; - - } // end if; + } /* * Set the setup fee value to zero if the toggle is disabled. */ - if (!wu_request('price_variations')) { - + if ( ! wu_request('price_variations')) { $_POST['price_variations'] = array(); - - } // end if; + } /* * Set the taxable value to zero if the toggle is disabled. */ - if (!wu_request('taxable')) { - + if ( ! wu_request('taxable')) { $_POST['taxable'] = 0; - - } // end if; + } parent::handle_save(); - - } // end handle_save; - -} // end class Product_Edit_Admin_Page; + } +} diff --git a/inc/admin-pages/class-product-list-admin-page.php b/inc/admin-pages/class-product-list-admin-page.php index fff2ea7..9683304 100644 --- a/inc/admin-pages/class-product-list-admin-page.php +++ b/inc/admin-pages/class-product-list-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-settings-admin-page.php b/inc/admin-pages/class-settings-admin-page.php index 3f9b6ba..fb98554 100644 --- a/inc/admin-pages/class-settings-admin-page.php +++ b/inc/admin-pages/class-settings-admin-page.php @@ -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() { + ?>
@@ -206,8 +223,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
+ public function render_site_template_side_panel() { + + ?>
@@ -248,8 +266,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
+ public function render_site_placeholders_side_panel() { + + ?>
@@ -290,8 +309,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
+ public function render_invoice_side_panel() { + + ?>
@@ -332,8 +352,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
+ public function render_system_emails_side_panel() { + + ?>
@@ -374,8 +395,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
+ public function render_email_template_side_panel() { + + ?>
@@ -416,8 +438,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
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; + } +} diff --git a/inc/admin-pages/class-setup-wizard-admin-page.php b/inc/admin-pages/class-setup-wizard-admin-page.php index e0751e7..f3007af 100644 --- a/inc/admin-pages/class-setup-wizard-admin-page.php +++ b/inc/admin-pages/class-setup-wizard-admin-page.php @@ -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('

', 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( + '

', + 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 →', '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!

We strongly recommend creating a backup of your database before moving forward with the migration.', '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') . '

' . __('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 = '' . __('List of errors detected:', 'wp-ultimo') . '

'; - $errors[] = sprintf('
%1$s', __('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( + '
%1$s', + __('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('
%1$s', __('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( + '
%1$s', + __('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('
', $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('
%s
', $error_list); - - }, + return sprintf('
%s
', $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 >'), - 'prev' => __('< 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 >'), + 'prev' => __('< 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') + ) + ); + } +} diff --git a/inc/admin-pages/class-shortcodes-admin-page.php b/inc/admin-pages/class-shortcodes-admin-page.php index ea90eef..36d82c7 100644 --- a/inc/admin-pages/class-shortcodes-admin-page.php +++ b/inc/admin-pages/class-shortcodes-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-site-edit-admin-page.php b/inc/admin-pages/class-site-edit-admin-page.php index dd57de8..3aa34b3 100644 --- a/inc/admin-pages/class-site-edit-admin-page.php +++ b/inc/admin-pages/class-site-edit-admin-page.php @@ -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 = "{$label}"; - $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' => '', + 'wrapper_classes' => 'wu-hidden wu-scraper-error', + ), + 'scraper_message' => array( + 'type' => 'note', + 'desc' => sprintf('%s', __('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' => '', - 'wrapper_classes' => 'wu-hidden wu-scraper-error', - ), - 'scraper_message' => array( - 'type' => 'note', - 'desc' => sprintf('%s', __('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; + } +} diff --git a/inc/admin-pages/class-site-list-admin-page.php b/inc/admin-pages/class-site-list-admin-page.php index 36a41ad..6b331f1 100644 --- a/inc/admin-pages/class-site-list-admin-page.php +++ b/inc/admin-pages/class-site-list-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-system-info-admin-page.php b/inc/admin-pages/class-system-info-admin-page.php index 098bf01..39a7ca0 100644 --- a/inc/admin-pages/class-system-info-admin-page.php +++ b/inc/admin-pages/class-system-info-admin-page.php @@ -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 = '#(?' . join('|', $known) . ')[/ ]+(?[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; + } +} diff --git a/inc/admin-pages/class-tax-rates-admin-page.php b/inc/admin-pages/class-tax-rates-admin-page.php index f8cb085..3a651f7 100644 --- a/inc/admin-pages/class-tax-rates-admin-page.php +++ b/inc/admin-pages/class-tax-rates-admin-page.php @@ -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('
%s
', __('Loading...', 'wp-ultimo')), + 'wrapper_html_attr' => array( + 'v-if' => 0, + ), + ); + } - $atts['fields']['loading'] = array( - 'type' => 'note', - 'desc' => sprintf('
%s
', __('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 + ); + } +} diff --git a/inc/admin-pages/class-template-previewer-customize-admin-page.php b/inc/admin-pages/class-template-previewer-customize-admin-page.php index 17dfea7..294a545 100644 --- a/inc/admin-pages/class-template-previewer-customize-admin-page.php +++ b/inc/admin-pages/class-template-previewer-customize-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-top-admin-nav-menu.php b/inc/admin-pages/class-top-admin-nav-menu.php index a77d8a6..7dfb5c4 100644 --- a/inc/admin-pages/class-top-admin-nav-menu.php +++ b/inc/admin-pages/class-top-admin-nav-menu.php @@ -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; + } + } +} diff --git a/inc/admin-pages/class-view-logs-admin-page.php b/inc/admin-pages/class-view-logs-admin-page.php index 406d1cf..9b796f3 100644 --- a/inc/admin-pages/class-view-logs-admin-page.php +++ b/inc/admin-pages/class-view-logs-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-webhook-edit-admin-page.php b/inc/admin-pages/class-webhook-edit-admin-page.php index bd08517..25833cb 100644 --- a/inc/admin-pages/class-webhook-edit-admin-page.php +++ b/inc/admin-pages/class-webhook-edit-admin-page.php @@ -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('
', $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; + } + } +} diff --git a/inc/admin-pages/class-webhook-list-admin-page.php b/inc/admin-pages/class-webhook-list-admin-page.php index 31e056f..3f2463e 100644 --- a/inc/admin-pages/class-webhook-list-admin-page.php +++ b/inc/admin-pages/class-webhook-list-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/class-wizard-admin-page.php b/inc/admin-pages/class-wizard-admin-page.php index 1fd5021..ec468ef 100644 --- a/inc/admin-pages/class-wizard-admin-page.php +++ b/inc/admin-pages/class-wizard-admin-page.php @@ -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 ''; - - } // 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 →', 'wp-ultimo'), - 'back_label' => __('← 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 →', 'wp-ultimo'), + 'back_label' => __('← 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(); +} diff --git a/inc/admin-pages/customer-panel/class-account-admin-page.php b/inc/admin-pages/customer-panel/class-account-admin-page.php index 35680e4..d2bb1f2 100644 --- a/inc/admin-pages/customer-panel/class-account-admin-page.php +++ b/inc/admin-pages/customer-panel/class-account-admin-page.php @@ -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, + ) + ); + } +} diff --git a/inc/admin-pages/customer-panel/class-add-new-site-admin-page.php b/inc/admin-pages/customer-panel/class-add-new-site-admin-page.php index dc630f4..171d9c7 100644 --- a/inc/admin-pages/customer-panel/class-add-new-site-admin-page.php +++ b/inc/admin-pages/customer-panel/class-add-new-site-admin-page.php @@ -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, + ) + ); + } +} diff --git a/inc/admin-pages/customer-panel/class-checkout-admin-page.php b/inc/admin-pages/customer-panel/class-checkout-admin-page.php index 18d60f4..a34f5ec 100644 --- a/inc/admin-pages/customer-panel/class-checkout-admin-page.php +++ b/inc/admin-pages/customer-panel/class-checkout-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/customer-panel/class-my-sites-admin-page.php b/inc/admin-pages/customer-panel/class-my-sites-admin-page.php index 3e4d801..ff4c9c4 100644 --- a/inc/admin-pages/customer-panel/class-my-sites-admin-page.php +++ b/inc/admin-pages/customer-panel/class-my-sites-admin-page.php @@ -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, + ) + ); + } +} diff --git a/inc/admin-pages/customer-panel/class-template-switching-admin-page.php b/inc/admin-pages/customer-panel/class-template-switching-admin-page.php index e816a68..be5935c 100644 --- a/inc/admin-pages/customer-panel/class-template-switching-admin-page.php +++ b/inc/admin-pages/customer-panel/class-template-switching-admin-page.php @@ -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; + } +} diff --git a/inc/admin-pages/debug/class-debug-admin-page.php b/inc/admin-pages/debug/class-debug-admin-page.php index 539300c..1a08492 100644 --- a/inc/admin-pages/debug/class-debug-admin-page.php +++ b/inc/admin-pages/debug/class-debug-admin-page.php @@ -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 '
    '; foreach ($pages as $page_id => $url) { - - echo sprintf(' + printf( + '
  • %s
  • - ', $url, $page_id); - - } // end foreach; + ', + $url, + $page_id + ); + } echo '
'; - - } // 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, + ) + ); + } +} diff --git a/inc/api/class-register-endpoint.php b/inc/api/class-register-endpoint.php index 4056511..d7e7626 100644 --- a/inc/api/class-register-endpoint.php +++ b/inc/api/class-register-endpoint.php @@ -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; + } +} diff --git a/inc/api/trait-rest-api.php b/inc/api/trait-rest-api.php index 1851471..f024b7c 100644 --- a/inc/api/trait-rest-api.php +++ b/inc/api/trait-rest-api.php @@ -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[\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; + } +} diff --git a/inc/api/trait-wp-cli.php b/inc/api/trait-wp-cli.php index 994989c..ef59231 100644 --- a/inc/api/trait-wp-cli.php +++ b/inc/api/trait-wp-cli.php @@ -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; + } + } +} diff --git a/inc/builders/block-editor/assets/js/blocks.js b/inc/builders/block-editor/assets/js/blocks.js index fecbd3a..39e39bc 100644 --- a/inc/builders/block-editor/assets/js/blocks.js +++ b/inc/builders/block-editor/assets/js/blocks.js @@ -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; diff --git a/inc/builders/block-editor/class-block-editor-widget-manager.php b/inc/builders/block-editor/class-block-editor-widget-manager.php index dfc0a1d..656f59b 100644 --- a/inc/builders/block-editor/class-block-editor-widget-manager.php +++ b/inc/builders/block-editor/class-block-editor-widget-manager.php @@ -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; + } +} diff --git a/inc/checkout/class-cart.php b/inc/checkout/class-cart.php index 9d05a8a..3ffd4c4 100644 --- a/inc/checkout/class-cart.php +++ b/inc/checkout/class-cart.php @@ -9,9 +9,9 @@ namespace WP_Ultimo\Checkout; -use \WP_Ultimo\Checkout\Line_Item; -use \WP_Ultimo\Database\Memberships\Membership_Status; -use \Arrch\Arrch as Array_Search; +use WP_Ultimo\Checkout\Line_Item; +use WP_Ultimo\Database\Memberships\Membership_Status; +use Arrch\Arrch as Array_Search; // Exit if accessed directly defined('ABSPATH') || exit; @@ -39,16 +39,16 @@ class Cart implements \JsonSerializable { public $errors; /** - * Cart Attributes. - * - * List of attributes passed to the - * constructor. - * - * @since 2.0.0 - * @var object - * @readonly - */ - private \stdClass $attributes; + * Cart Attributes. + * + * List of attributes passed to the + * constructor. + * + * @since 2.0.0 + * @var object + * @readonly + */ + private \stdClass $attributes; /** * Type of registration: new, renewal, upgrade, downgrade, retry, and display. @@ -254,66 +254,69 @@ class Cart implements \JsonSerializable { * Since we're passing over the entire $_POST array * this helps us to keep things cleaner and secure. */ - $args = shortcode_atts(array( + $args = shortcode_atts( + array( - /* - * Cart Type. - */ - 'cart_type' => 'new', + /* + * Cart Type. + */ + 'cart_type' => 'new', - /* - * The list of products being bought. - */ - 'products' => array(), + /* + * The list of products being bought. + */ + 'products' => array(), - /* - * The duration parameters - * This will dictate which price variations we are going to use. - */ - 'duration' => false, - 'duration_unit' => false, + /* + * The duration parameters + * This will dictate which price variations we are going to use. + */ + 'duration' => false, + 'duration_unit' => false, - /* - * The membership ID. - * This is passed when we want to handle a upgrade/downgrade/addon. - */ - 'membership_id' => false, + /* + * The membership ID. + * This is passed when we want to handle a upgrade/downgrade/addon. + */ + 'membership_id' => false, - /* - * Payment ID. - * This is passed when we are trying to recovered a abandoned/pending payment. - */ - 'payment_id' => false, + /* + * Payment ID. + * This is passed when we are trying to recovered a abandoned/pending payment. + */ + 'payment_id' => false, - /* - * The discount code to be used. - */ - 'discount_code' => false, + /* + * The discount code to be used. + */ + 'discount_code' => false, - /* - * If we should auto-renew or not. - */ - 'auto_renew' => true, + /* + * If we should auto-renew or not. + */ + 'auto_renew' => true, - /* - * The country, state, and city of the customer. - * Used for taxation purposes. - */ - 'country' => '', - 'state' => '', - 'city' => '', + /* + * The country, state, and city of the customer. + * Used for taxation purposes. + */ + 'country' => '', + 'state' => '', + 'city' => '', - /* - * Currency - */ - 'currency' => '', + /* + * Currency + */ + 'currency' => '', - ), $args); + ), + $args + ); /* * Checks for errors */ - $this->errors = new \WP_Error; + $this->errors = new \WP_Error(); /* * Save arguments in memory @@ -363,11 +366,9 @@ class Cart implements \JsonSerializable { * This setting can be forced if the settings say so, * so we only set it if that is not enabled. */ - if (!wu_get_setting('force_auto_renew', true)) { - + if ( ! wu_get_setting('force_auto_renew', true)) { $this->auto_renew = wu_string_to_bool($this->attributes->auto_renew); - - } // end if; + } /* * Calculate-totals. @@ -385,23 +386,21 @@ class Cart implements \JsonSerializable { * @param $this \WP_Ultimo\Checkout\Cart The cart object. */ do_action('wu_cart_after_setup', $this); // @phpstan-ignore-line - - } // end __construct; + } /** * Get additional parameters set by integrations and add-ons. * - * @since 2.0.0 - * * @param string $key The parameter key. - * @param boolean $default The default value. + * @param boolean $default_value The default value. + * * @return mixed + * @since 2.0.0 */ - public function get_param($key, $default = false) { + public function get_param($key, $default_value = false) { - return wu_get_isset($this->attributes, $key, $default); - - } // end get_param; + return wu_get_isset($this->attributes, $key, $default_value); + } /** * Set additional parameters set by integrations and add-ons. @@ -417,8 +416,7 @@ class Cart implements \JsonSerializable { $this->extra[] = $key; $this->attributes->{$key} = $value; - - } // end set_param; + } /** * Gets the tax exempt status of the current cart. @@ -429,8 +427,7 @@ class Cart implements \JsonSerializable { public function is_tax_exempt() { return apply_filters('wu_cart_is_tax_exempt', false, $this); - - } // end is_tax_exempt; + } /** * Builds the cart. @@ -454,10 +451,8 @@ class Cart implements \JsonSerializable { * in order to build the proper cart. */ if ($is_recovery_cart) { - return; - - } // end if; + } /* * The next step is to deal with membership changes. @@ -470,10 +465,8 @@ class Cart implements \JsonSerializable { * we can return as our work is done. */ if ($is_membership_change) { - return; - - } // end if; + } /* * Otherwise, we add the the products normally, @@ -482,18 +475,14 @@ class Cart implements \JsonSerializable { $this->cart_type = 'new'; if (is_array($this->attributes->products)) { - /* + /* * Otherwise, we add the products to build the cart. */ foreach ($this->attributes->products as $product_id) { - $this->add_product($product_id); - - } // end foreach; - - } // end if; - - } // end build_cart; + } + } + } /** * Creates a string that describes the cart. @@ -509,35 +498,28 @@ class Cart implements \JsonSerializable { */ public function get_cart_descriptor() { - if (!empty($this->cart_descriptor)) { - + if ( ! empty($this->cart_descriptor)) { return $this->cart_descriptor; - - } // end if; + } $desc = wu_get_setting('company_name', __('Subscription', 'wp-ultimo')); $products = array(); foreach ($this->get_line_items() as $line_item) { - $product = $line_item->get_product(); - if (!$product) { - + if ( ! $product) { continue; - - } // end if; + } $products[] = $line_item->get_title(); - - } // end foreach; + } $descriptor = $desc . ' - ' . implode(', ', $products); return trim($descriptor); - - } // end get_cart_descriptor; + } /** * Set a custom cart descriptor. @@ -550,8 +532,7 @@ class Cart implements \JsonSerializable { public function set_cart_descriptor($descriptor) { $this->cart_descriptor = $descriptor; - - } // end set_cart_descriptor; + } /** * Decides if we are trying to recover a payment. * @@ -565,23 +546,19 @@ class Cart implements \JsonSerializable { * are not trying to recover a payment. */ if (empty($payment_id)) { - return false; - - } // end if; + } /* * Now, let's try to fetch the payment in question. */ $payment = wu_get_payment($payment_id); - if (!$payment) { - + if ( ! $payment) { $this->errors->add('payment_not_found', __('The payment in question was not found.', 'wp-ultimo')); return true; - - } // end if; + } /* * The payment exists, set it globally. @@ -605,25 +582,21 @@ class Cart implements \JsonSerializable { * a payment can pay it. Let's check for that. */ if (empty($this->customer) || $this->customer->get_id() !== $payment->get_customer_id()) { - $this->errors->add('lacks_permission', __('You are not allowed to modify this payment.', 'wp-ultimo')); return true; - - } // end if; + } /* * Sets the membership as well, to prevent issues */ $membership = $payment->get_membership(); - if (!$membership) { - + if ( ! $membership) { $this->errors->add('membership_not_found', __('The membership in question was not found.', 'wp-ultimo')); return true; - - } // end if; + } if ($payment->get_discount_code()) { /** @@ -632,16 +605,11 @@ class Cart implements \JsonSerializable { $discount_code = $membership->get_discount_code(); if ($discount_code && $discount_code->get_code() === $payment->get_discount_code()) { - $this->add_discount_code($discount_code); - } else { - $this->add_discount_code($payment->get_discount_code()); - - } // end if; - - } // end if; + } + } /* * Sets membership globally. @@ -654,25 +622,19 @@ class Cart implements \JsonSerializable { * Finally, copy the line items from the payment. */ foreach ($payment->get_line_items() as $line_item) { - $product = $line_item->get_product(); if ($product) { - 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; + } + } $this->products[] = $product; @@ -682,22 +644,17 @@ class Cart implements \JsonSerializable { * another one. */ if (empty($this->plan_id)) { - $this->plan_id = $product->get_id(); $this->billing_cycles = $product->get_billing_cycles(); $this->duration = $line_item->get_duration(); $this->duration_unit = $line_item->get_duration_unit(); - - } // end if; - - } // end if; - - } // end if; + } + } + } $this->add_line_item($line_item); - - } // end foreach; + } /* * If the payment is completed @@ -709,8 +666,7 @@ class Cart implements \JsonSerializable { * We should return false to continue in case of membership updates. */ return false; - - } // end if; + } /* * Check for payment status. @@ -718,28 +674,27 @@ class Cart implements \JsonSerializable { * We want to make sure we only allow for repayment of pending, * cancelled, or abandoned payments */ - $allowed_status = apply_filters('wu_cart_set_payment_allowed_status', array( - 'pending', - )); - - if (!in_array($payment->get_status(), $allowed_status, true)) { + $allowed_status = apply_filters( + 'wu_cart_set_payment_allowed_status', + array( + 'pending', + ) + ); + if ( ! in_array($payment->get_status(), $allowed_status, true)) { $this->errors->add('invalid_status', __('The payment in question has an invalid status.', 'wp-ultimo')); return true; - - } // end if; + } /* * If the membership is active or is * already in trial this can't be a * retry, so we skip the rest. */ - if ($membership->is_active() || ($membership->get_status() === Membership_Status::TRIALING && !$this->has_trial())) { - + if ($membership->is_active() || ($membership->get_status() === Membership_Status::TRIALING && ! $this->has_trial())) { return false; - - } // end if; + } /* * We got here, that means @@ -751,8 +706,7 @@ class Cart implements \JsonSerializable { $this->cart_type = 'retry'; return true; - - } // end build_from_payment; + } /** * Uses the membership to decide if this is a upgrade/downgrade/addon cart. * @@ -766,10 +720,8 @@ class Cart implements \JsonSerializable { * are not trying to change a membership. */ if (empty($membership_id)) { - return false; - - } // end if; + } /* * We got here, that means @@ -787,13 +739,11 @@ class Cart implements \JsonSerializable { */ $membership = wu_get_membership($membership_id); - if (!$membership) { - + if ( ! $membership) { $this->errors->add('membership_not_found', __('The membership in question was not found.', 'wp-ultimo')); return true; - - } // end if; + } /* * The membership exists, set it globally. @@ -810,12 +760,10 @@ class Cart implements \JsonSerializable { * Only the customer that owns a membership can change it. */ if (empty($this->customer) || $this->customer->get_id() !== $membership->get_customer_id()) { - $this->errors->add('lacks_permission', __('You are not allowed to modify this membership.', 'wp-ultimo')); return true; - - } // end if; + } /* * Adds the country to calculate taxes. @@ -835,7 +783,6 @@ class Cart implements \JsonSerializable { * being added, and process those. */ if (empty($this->attributes->products)) { - if ($this->payment) { /** * If we do not have any change but we have a already @@ -843,23 +790,19 @@ class Cart implements \JsonSerializable { * for this. */ return false; - - } // end if; + } $this->errors->add('no_changes', __('This cart proposes no changes to the current membership.', 'wp-ultimo')); return true; - - } // end if; + } /* * Otherwise, we add the products to build the cart. */ foreach ($this->attributes->products as $product_id) { - $this->add_product($product_id); - - } // end foreach; + } /* * With products added, let's check if this is an addon. @@ -870,14 +813,11 @@ class Cart implements \JsonSerializable { * must be added to the membership. */ if (empty($this->plan_id)) { - if (count($this->products) === 0) { - $this->errors->add('no_changes', __('This cart proposes no changes to the current membership.', 'wp-ultimo')); return true; - - } // end if; + } /* * Set the type to addon. @@ -890,12 +830,10 @@ class Cart implements \JsonSerializable { */ $plan_product = $membership->get_plan(); - if ($plan_product && !$membership->is_free()) { - + if ($plan_product && ! $membership->is_free()) { $this->duration = $plan_product->get_duration(); $this->duration_unit = $plan_product->get_duration_unit(); - - } // end if; + } /* * Checks the membership to see if we need to add back the @@ -920,8 +858,7 @@ class Cart implements \JsonSerializable { $this->calculate_prorate_credits(); return true; - - } // end if; + } /* * With products added, let's check if the plan is changing. @@ -938,10 +875,8 @@ class Cart implements \JsonSerializable { $is_plan_change = false; if ($membership->get_plan_id() !== $this->plan_id || $this->duration_unit !== $membership->get_duration_unit() || $this->duration !== $membership->get_duration()) { - $is_plan_change = true; - - } // end if; + } /* * Checks for periodicity changes. @@ -950,17 +885,15 @@ class Cart implements \JsonSerializable { $new_periodicity = sprintf('%s-%s', $this->duration, $this->duration_unit); if ($old_periodicity !== $new_periodicity) { - $is_plan_change = true; - - } // end if; + } /* * If there is no plan change, but the product count is > 1 * We know that there is another product in this cart other than the * plan, so this is again an addon cart. */ - if (count($this->products) > 1 && $is_plan_change === false) { + if (count($this->products) > 1 && false === $is_plan_change) { /* * Set the type to addon. */ @@ -972,12 +905,10 @@ class Cart implements \JsonSerializable { */ $plan_product = $membership->get_plan(); - if ($plan_product && !$membership->is_free()) { - + if ($plan_product && ! $membership->is_free()) { $this->duration = $plan_product->get_duration(); $this->duration_unit = $plan_product->get_duration_unit(); - - } // end if; + } /* * Checks the membership to see if we need to add back the @@ -995,28 +926,25 @@ class Cart implements \JsonSerializable { $this->calculate_prorate_credits(); return true; - - } // end if; + } /* * We'll probably never enter in this if, but we * hev it here to prevent bugs. */ - if (!$is_plan_change || ($this->get_plan_id() === $membership->get_plan_id() && $this->duration_unit === $membership->get_duration_unit() && $this->duration === $membership->get_duration())) { - + if ( ! $is_plan_change || ($this->get_plan_id() === $membership->get_plan_id() && $this->duration_unit === $membership->get_duration_unit() && $this->duration === $membership->get_duration())) { $this->products = array(); $this->line_items = array(); $this->errors->add('no_changes', __('This cart proposes no changes to the current membership.', 'wp-ultimo')); return true; - - } // end if; + } /* * Upgrade to Lifetime. */ - if (!$this->has_recurring() && !$this->is_free()) { + if ( ! $this->has_recurring() && ! $this->is_free()) { /* * Adds the credit line, after * calculating pro-rate. @@ -1024,8 +952,7 @@ class Cart implements \JsonSerializable { $this->calculate_prorate_credits(); return true; - - } // end if; + } /* * If we get to this point, we know that this is either @@ -1048,14 +975,12 @@ class Cart implements \JsonSerializable { * when setting a downgrade cart. */ if ($days_in_old_cycle !== $days_in_new_cycle) { - $old_plan = $membership->get_plan(); $new_plan = $this->get_plan(); $variations = $this->search_for_same_period_plans($old_plan, $new_plan); if ($variations) { - $old_plan = $variations[0]; $new_plan = $variations[1]; @@ -1064,13 +989,10 @@ class Cart implements \JsonSerializable { $old_price_per_day = $days_in_old_cycle_plan > 0 ? $old_plan->get_amount() / $days_in_old_cycle_plan : $old_plan->get_amount(); $new_price_per_day = $days_in_new_cycle_plan > 0 ? $new_plan->get_amount() / $days_in_new_cycle_plan : $new_plan->get_amount(); + } + } - } // end if; - - } // end if; - - if (!$membership->is_free() && $old_price_per_day < $new_price_per_day && $days_in_old_cycle > $days_in_new_cycle && $membership->get_status() === Membership_Status::ACTIVE) { - + if ( ! $membership->is_free() && $old_price_per_day < $new_price_per_day && $days_in_old_cycle > $days_in_new_cycle && $membership->get_status() === Membership_Status::ACTIVE) { $this->products = array(); $this->line_items = array(); @@ -1087,128 +1009,108 @@ class Cart implements \JsonSerializable { $this->errors->add('no_changes', $message); return true; - - } // end if; + } /* * If is the same product and the customer will start to pay less * or if is not the same product and the price per day is smaller * this is a downgrade */ - if (($is_same_product && $membership->get_amount() > $this->get_recurring_total()) || (!$is_same_product && $old_price_per_day > $new_price_per_day)) { - + if (($is_same_product && $membership->get_amount() > $this->get_recurring_total()) || (! $is_same_product && $old_price_per_day > $new_price_per_day)) { $this->cart_type = 'downgrade'; // If membership is active or trialing we will schendule the swap if ($membership->is_active() || $membership->get_status() === Membership_Status::TRIALING) { - - $line_item_params = apply_filters('wu_checkout_credit_line_item_params', array( - 'type' => 'credit', - 'title' => __('Scheduled Swap Credit', 'wp-ultimo'), - 'description' => __('Swap scheduled to next billing cycle.', 'wp-ultimo'), - 'discountable' => false, - 'taxable' => false, - 'quantity' => 1, - 'unit_price' => - $this->get_total(), - )); + $line_item_params = apply_filters( + 'wu_checkout_credit_line_item_params', + array( + 'type' => 'credit', + 'title' => __('Scheduled Swap Credit', 'wp-ultimo'), + 'description' => __('Swap scheduled to next billing cycle.', 'wp-ultimo'), + 'discountable' => false, + 'taxable' => false, + 'quantity' => 1, + 'unit_price' => - $this->get_total(), + ) + ); $credit_line_item = new Line_Item($line_item_params); $this->add_line_item($credit_line_item); + } + } - } // end if; - - } // end if; - - // If this is a upgrade, we need to prorate the current amount - if ($this->cart_type === 'upgrade') { - + // If this is an upgrade, we need to prorate the current amount + if ('upgrade' === $this->cart_type) { $this->calculate_prorate_credits(); - - } // end if; + } /* * All set! */ return true; - - } // end build_from_membership; - /** - * Search for variations of the plans with same duration. - * - * @since 2.0.20 - * @param \WP_Ultimo\Models\Product $plan_a The first plan without variations. - * @param \WP_Ultimo\Models\Product $plan_b The second plan without variations. - * @return mixed[]|false - */ - protected function search_for_same_period_plans($plan_a, $plan_b) { + } + /** + * Search for variations of the plans with same duration. + * + * @since 2.0.20 + * @param \WP_Ultimo\Models\Product $plan_a The first plan without variations. + * @param \WP_Ultimo\Models\Product $plan_b The second plan without variations. + * @return mixed[]|false + */ + protected function search_for_same_period_plans($plan_a, $plan_b) { if ($plan_a->get_duration_unit() === $plan_b->get_duration_unit() && $plan_a->get_duration() === $plan_b->get_duration()) { - return array( $plan_a, $plan_b, ); - - } // end if; + } $plan_a_variation = $plan_a->get_as_variation($plan_b->get_duration(), $plan_b->get_duration_unit()); if ($plan_a_variation) { - return array( $plan_a_variation, $plan_b, ); - - } // end if; + } $plan_b_variation = $plan_b->get_as_variation($plan_a->get_duration(), $plan_a->get_duration_unit()); if ($plan_b_variation) { - return array( $plan_a, $plan_b_variation, ); - - } // end if; + } if ($this->duration_unit && $this->duration && ($this->duration_unit !== $plan_b->get_duration_unit() || $this->duration !== $plan_b->get_duration())) { - $plan_a_variation = $plan_a->get_as_variation($this->duration, $this->duration_unit); - if (!$plan_a_variation) { - + if ( ! $plan_a_variation) { return false; - - } // end if; + } if ($plan_b->get_duration_unit() === $plan_a_variation->get_duration_unit() && $plan_b->get_duration() === $plan_a_variation->get_duration()) { - return array( $plan_a_variation, $plan_b, ); - - } // end if; + } $plan_b_variation = $plan_b->get_as_variation($this->duration, $this->duration_unit); if ($plan_b_variation) { - return array( $plan_a_variation, $plan_b_variation, ); - - } // end if; - - } // end if; + } + } return false; - - } // end search_for_same_period_plans; + } /** * Calculate pro-rate credits. @@ -1228,17 +1130,12 @@ class Cart implements \JsonSerializable { * If the membership is in trial period theres nothing to prorate. */ if ($this->membership->get_status() === Membership_Status::TRIALING) { - return; + } - } // end if; - - if ($this->membership->is_lifetime() || !$this->membership->is_recurring()) { - + if ($this->membership->is_lifetime() || ! $this->membership->is_recurring()) { $credit = $this->membership->get_initial_amount(); - } else { - $days_unused = $this->membership->get_remaining_days_in_cycle(); $days_in_old_cycle = wu_get_days_in_cycle($this->membership->get_duration_unit(), $this->membership->get_duration()); @@ -1248,21 +1145,16 @@ class Cart implements \JsonSerializable { $credit = $days_unused * $old_price_per_day; if ($credit > $this->membership->get_amount()) { - $credit = $this->membership->get_amount(); - - } // end if; - - } // end if; + } + } /* * No credits */ if (empty($credit)) { - return; - - } // end if; + } /* * Checks if we need to add back the value of the @@ -1270,43 +1162,39 @@ class Cart implements \JsonSerializable { */ $has_setup_fee = $this->get_line_items_by_type('fee'); - if (!empty($has_setup_fee) || $this->get_cart_type() === 'upgrade') { - + if ( ! empty($has_setup_fee) || $this->get_cart_type() === 'upgrade') { $old_plan = $this->membership->get_plan(); $new_plan = $this->get_plan(); if ($old_plan && $new_plan) { - $old_setup_fee = $old_plan->get_setup_fee(); $new_setup_fee = $new_plan->get_setup_fee(); $fee_credit = $old_setup_fee < $new_setup_fee ? $old_setup_fee : $new_setup_fee; if ($fee_credit > 0) { - - $new_line_item = new Line_Item(array( - 'product' => $old_plan, - 'type' => 'fee', - 'description' => '--', - 'title' => '', - 'taxable' => $old_plan->is_taxable(), - 'recurring' => false, - 'unit_price' => $fee_credit, - 'quantity' => 1, - )); + $new_line_item = new Line_Item( + array( + 'product' => $old_plan, + 'type' => 'fee', + 'description' => '--', + 'title' => '', + 'taxable' => $old_plan->is_taxable(), + 'recurring' => false, + 'unit_price' => $fee_credit, + 'quantity' => 1, + ) + ); $new_line_item = $this->apply_taxes_to_item($new_line_item); $new_line_item->recalculate_totals(); $credit += $new_line_item->get_total(); - - } // end if; - - } // end if; - - } // end if; + } + } + } /** * Allow plugin developers to meddle with the credit value. @@ -1324,20 +1212,21 @@ class Cart implements \JsonSerializable { * No credits */ if (empty($credit)) { - return; + } - } // end if; - - $line_item_params = apply_filters('wu_checkout_credit_line_item_params', array( - 'type' => 'credit', - 'title' => __('Credit', 'wp-ultimo'), - 'description' => __('Prorated amount based on the previous membership.', 'wp-ultimo'), - 'discountable' => false, - 'taxable' => false, - 'quantity' => 1, - 'unit_price' => - $credit, - )); + $line_item_params = apply_filters( + 'wu_checkout_credit_line_item_params', + array( + 'type' => 'credit', + 'title' => __('Credit', 'wp-ultimo'), + 'description' => __('Prorated amount based on the previous membership.', 'wp-ultimo'), + 'discountable' => false, + 'taxable' => false, + 'quantity' => 1, + 'unit_price' => - $credit, + ) + ); /* * Finally, we add the credit to the purchase. @@ -1345,8 +1234,7 @@ class Cart implements \JsonSerializable { $credit_line_item = new Line_Item($line_item_params); $this->add_line_item($credit_line_item); - - } // end calculate_prorate_credits; + } /** * Adds a discount code to the cart. * @@ -1357,10 +1245,8 @@ class Cart implements \JsonSerializable { protected function set_discount_code($code): bool { if (empty($code)) { - return false; - - } // end if; + } $code = strtoupper($code); @@ -1372,18 +1258,15 @@ class Cart implements \JsonSerializable { $this->errors->add('discount_code', sprintf(__('The code %s do not exist or is no longer valid.', 'wp-ultimo'), $code)); return false; - - } // end if; + } $is_valid = $discount_code->is_valid(); if (is_wp_error($is_valid)) { - $this->errors->merge_from($is_valid); return false; - - } // end if; + } /* * Set the coupon @@ -1391,8 +1274,7 @@ class Cart implements \JsonSerializable { $this->discount_code = $discount_code; return true; - - } // end set_discount_code; + } /** * Returns the current errors. @@ -1403,8 +1285,7 @@ class Cart implements \JsonSerializable { public function get_errors() { return $this->errors; - - } // end get_errors; + } /** * For an order to be valid, all the recurring products must have the same @@ -1422,24 +1303,19 @@ class Cart implements \JsonSerializable { * the setup, bail. */ if ($this->errors->has_errors()) { - return false; - - } // end if; + } $interval = null; foreach ($this->line_items as $line_item) { - $duration = $line_item->get_duration(); $duration_unit = $line_item->get_duration_unit(); $cycles = $line_item->get_billing_cycles(); - if (!$line_item->is_recurring()) { - + if ( ! $line_item->is_recurring()) { continue; - - } // end if; + } /* * Create a key that will tell us if something changes. @@ -1454,25 +1330,20 @@ class Cart implements \JsonSerializable { */ $line_item_interval = "{$duration}-{$duration_unit}-{$cycles}"; - if (!$interval) { - + if ( ! $interval) { $interval = $line_item_interval; - - } // end if; + } if ($line_item_interval !== $interval) { - + // translators: two intervals $this->errors->add('wrong', sprintf(__('Interval %1$s and %2$s do not match.', 'wp-ultimo'), $line_item_interval, $interval)); return false; - - } // end if; - - } // end foreach; + } + } return $is_valid; - - } // end is_valid; + } /** * Checks if this order is free. @@ -1487,8 +1358,7 @@ class Cart implements \JsonSerializable { public function is_free() { return empty($this->get_total()); - - } // end is_free; + } /** * Checks if we need to collect a payment method. @@ -1504,18 +1374,13 @@ class Cart implements \JsonSerializable { $should_collect_payment = true; if ($this->is_free() && $this->get_recurring_total() === 0.0) { - $should_collect_payment = false; - } elseif ($this->has_trial()) { - - $should_collect_payment = !wu_get_setting('allow_trial_without_payment_method', false); - - } // end if; + $should_collect_payment = ! wu_get_setting('allow_trial_without_payment_method', false); + } return (bool) apply_filters('wu_cart_should_collect_payment', $should_collect_payment, $this); - - } // end should_collect_payment; + } /** * Checks if the cart has a plan. @@ -1526,8 +1391,7 @@ class Cart implements \JsonSerializable { public function has_plan() { return (bool) $this->get_plan(); - - } // end has_plan; + } /** * Returns the cart plan. @@ -1538,8 +1402,7 @@ class Cart implements \JsonSerializable { public function get_plan() { return wu_get_product((int) $this->plan_id); - - } // end get_plan; + } /** * Returns the recurring products added to the cart. @@ -1550,8 +1413,7 @@ class Cart implements \JsonSerializable { public function get_recurring_products() { return $this->recurring_products; - - } // end get_recurring_products; + } /** * Returns the non-recurring products added to the cart. @@ -1562,8 +1424,7 @@ class Cart implements \JsonSerializable { public function get_non_recurring_products() { return $this->additional_products; - - } // end get_non_recurring_products; + } /** * Returns an array containing all products added to the cart, recurring or not. @@ -1574,8 +1435,7 @@ class Cart implements \JsonSerializable { public function get_all_products() { return $this->products; - - } // end get_all_products; + } /** * Returns the duration value for this cart. @@ -1586,8 +1446,7 @@ class Cart implements \JsonSerializable { public function get_duration() { return $this->duration; - - } // end get_duration; + } /** * Returns the duration unit for this cart. @@ -1598,8 +1457,7 @@ class Cart implements \JsonSerializable { public function get_duration_unit() { return $this->duration_unit; - - } // end get_duration_unit; + } /** * Add a new line item. @@ -1611,29 +1469,22 @@ class Cart implements \JsonSerializable { */ public function add_line_item($line_item) { - if (!is_a($line_item, '\WP_Ultimo\Checkout\Line_Item')) { - + if ( ! is_a($line_item, '\WP_Ultimo\Checkout\Line_Item')) { return; - - } // end if; + } if ($line_item->is_discountable()) { - $line_item = $this->apply_discounts_to_item($line_item); - - } // end if; + } if ($line_item->is_taxable()) { - $line_item = $this->apply_taxes_to_item($line_item); + } - } // end if; - - $this->line_items[$line_item->get_id()] = $line_item; + $this->line_items[ $line_item->get_id() ] = $line_item; krsort($this->line_items); - - } // end add_line_item; + } /** * Adds a new product to the cart. * @@ -1646,52 +1497,43 @@ class Cart implements \JsonSerializable { $product = is_numeric($product_id_or_slug) ? wu_get_product($product_id_or_slug) : wu_get_product_by_slug($product_id_or_slug); - if (!$product) { - + if ( ! $product) { $message = __('The product you are trying to add does not exist.', 'wp-ultimo'); $this->errors->add('missing-product', $message); return false; - - } // end if; + } // Here we check if the product is recurring and if so, get the correct variation - if ($product->is_recurring() && !empty($this->duration) && ($this->duration !== $product->get_duration() || $this->duration_unit !== $product->get_duration_unit())) { - + if ($product->is_recurring() && ! empty($this->duration) && ($this->duration !== $product->get_duration() || $this->duration_unit !== $product->get_duration_unit())) { $product = $product->get_as_variation($this->duration, $this->duration_unit); - if (!$product) { - + if ( ! $product) { $message = __('The product you are trying to add does not exist for the selected duration.', 'wp-ultimo'); $this->errors->add('missing-price-variations', $message); return false; - - } // end if; - - } // end if; + } + } if ($product->get_type() === 'plan') { /* * If we already have a plan, we can't add * another one. Bail. */ - if (!empty($this->plan_id)) { - + if ( ! empty($this->plan_id)) { $message = __('Theres already a plan in this membership.', 'wp-ultimo'); $this->errors->add('plan-already-added', $message); return false; - - } // end if; + } $this->plan_id = $product->get_id(); $this->billing_cycles = $product->get_billing_cycles(); - - } // end if; + } /* * We only try to reset the duration and such if @@ -1701,17 +1543,13 @@ class Cart implements \JsonSerializable { * want access this to fetch price variations. */ if (empty($this->duration) || $product->is_recurring() === false) { - $this->duration = $product->get_duration(); $this->duration_unit = $product->get_duration_unit(); - - } // end if; + } if (empty($this->currency)) { - $this->currency = $product->get_currency(); - - } // end if; + } /* * Set product amount in here, because @@ -1733,19 +1571,15 @@ class Cart implements \JsonSerializable { * the cart. */ if ($product->is_free() === false) { - if (absint($this->duration) !== $product->get_duration() || $this->duration_unit !== $product->get_duration_unit()) { - $price_variation = $product->get_price_variation($this->duration, $this->duration_unit); if ($price_variation) { - $price_variation = (object) $price_variation; $amount = $price_variation->amount; $duration = $price_variation->duration; $duration_unit = $price_variation->duration_unit; - } else { /* * This product does not have a valid @@ -1757,28 +1591,30 @@ class Cart implements \JsonSerializable { $this->errors->add('missing-price-variations', $message); return false; + } + } + } - } // end if; - - } // end if; - - } // end if; - - $line_item_data = apply_filters('wu_add_product_line_item', array( - 'product' => $product, - 'quantity' => $quantity, - 'unit_price' => $amount, - 'duration' => $duration, - 'duration_unit' => $duration_unit, - ), $product, $duration, $duration_unit, $this); + $line_item_data = apply_filters( + 'wu_add_product_line_item', + array( + 'product' => $product, + 'quantity' => $quantity, + 'unit_price' => $amount, + 'duration' => $duration, + 'duration_unit' => $duration_unit, + ), + $product, + $duration, + $duration_unit, + $this + ); $this->products[] = $product; if (empty($line_item_data)) { - return false; - - } // end if; + } $line_item = new Line_Item($line_item_data); @@ -1793,10 +1629,8 @@ class Cart implements \JsonSerializable { * Signup Fees */ if (empty($product->get_setup_fee())) { - return true; - - } // end if; + } $add_signup_fee = 'renewal' !== $this->get_cart_type(); @@ -1811,11 +1645,9 @@ class Cart implements \JsonSerializable { */ $add_signup_fee = apply_filters('wu_apply_signup_fee', $add_signup_fee, $product, $this); // @phpstan-ignore-line - if (!$add_signup_fee) { - + if ( ! $add_signup_fee) { return true; - - } // end if; + } // translators: placeholder is the product name. $description = ($product->get_setup_fee() > 0) ? __('Signup Fee for %s', 'wp-ultimo') : __('Signup Credit for %s', 'wp-ultimo'); @@ -1832,24 +1664,28 @@ class Cart implements \JsonSerializable { * @param \WP_Ultimo\Checkout\Cart $cart The cart object. * @return array */ - $setup_fee_line_item = apply_filters('wu_add_product_setup_fee_line_item', array( - 'product' => $product, - 'type' => 'fee', - 'description' => '--', - 'title' => $description, - 'taxable' => $product->is_taxable(), - 'recurring' => false, - 'unit_price' => $product->get_setup_fee(), - 'quantity' => $quantity, - ), $product, $this); + $setup_fee_line_item = apply_filters( + 'wu_add_product_setup_fee_line_item', + array( + 'product' => $product, + 'type' => 'fee', + 'description' => '--', + 'title' => $description, + 'taxable' => $product->is_taxable(), + 'recurring' => false, + 'unit_price' => $product->get_setup_fee(), + 'quantity' => $quantity, + ), + $product, + $this + ); $setup_fee_line_item = new Line_Item($setup_fee_line_item); $this->add_line_item($setup_fee_line_item); return true; - - } // end add_product; + } /** * Returns an array containing the subtotal per tax rate. @@ -1864,24 +1700,19 @@ class Cart implements \JsonSerializable { $tax_brackets = array(); foreach ($line_items as $line_item) { - $tax_bracket = $line_item->get_tax_rate(); - if (isset($tax_brackets[$tax_bracket])) { - - $tax_brackets[$tax_bracket] += $line_item->get_tax_total(); + if (isset($tax_brackets[ $tax_bracket ])) { + $tax_brackets[ $tax_bracket ] += $line_item->get_tax_total(); continue; + } - } // end if; - - $tax_brackets[$tax_bracket] = $line_item->get_tax_total(); - - } // end foreach; + $tax_brackets[ $tax_bracket ] = $line_item->get_tax_total(); + } return $tax_brackets; - - } // end get_tax_breakthrough; + } /** * Determine whether or not the level being registered for has a trial that the current user is eligible @@ -1896,39 +1727,30 @@ class Cart implements \JsonSerializable { $products = $this->get_all_products(); if (empty($products)) { - return false; - - } // end if; + } $is_trial = $this->get_billing_start_date(); - if (!$is_trial) { - + if ( ! $is_trial) { return false; - - } // end if; + } // There is a trial, but let's check eligibility. $customer = wu_get_current_customer(); // No customer, which means they're brand new, which means they're eligible. if (empty($customer)) { - return true; - - } // end if; + } // Check if this is the initial membership payment with trial if ($this->membership && $this->payment && $this->membership->is_trialing()) { - return empty($this->payment->get_total()); + } - } // end if; - - return !$customer->has_trialed(); - - } // end has_trial; + return ! $customer->has_trialed(); + } /** * Get the recovered payment object. @@ -1939,8 +1761,7 @@ class Cart implements \JsonSerializable { public function get_recovered_payment() { return $this->recovered_payment; - - } // end get_recovered_payment; + } /** * Add discount to the order. * @@ -1951,37 +1772,31 @@ class Cart implements \JsonSerializable { public function add_discount_code($code): bool { if (is_a($code, \WP_Ultimo\Models\Discount_Code::class)) { - $this->discount_code = $code; return true; - - } // end if; + } $discount_code = wu_get_discount_code_by_code($code); - if (!$discount_code) { - + if ( ! $discount_code) { return false; - - } // end if; + } $this->discount_code = $discount_code; return true; - - } // end add_discount_code; - /** - * Get registration discounts. - * - * @since 2.5 - * @return mixed[]|bool - */ - public function get_discounts() { + } + /** + * Get registration discounts. + * + * @since 2.5 + * @return mixed[]|bool + */ + public function get_discounts() { return $this->get_line_items_by_type('discount'); - - } // end get_discounts; + } /** * Checks if the cart has any discounts applied. @@ -1992,8 +1807,7 @@ class Cart implements \JsonSerializable { public function has_discount() { return $this->get_total_discounts() > 0; - - } // end has_discount; + } /** * Returns a list of line items based on the line item type. @@ -2011,26 +1825,27 @@ class Cart implements \JsonSerializable { // Cast to array recursively $line_items = json_decode(json_encode($this->line_items), true); - $line_items = Array_Search::find($line_items, array( - 'where' => $where_clauses, - )); + $line_items = Array_Search::find( + $line_items, + array( + 'where' => $where_clauses, + ) + ); $ids = array_keys($line_items); return array_filter($this->line_items, fn($id) => in_array($id, $ids, true), ARRAY_FILTER_USE_KEY); - - } // end get_line_items_by_type; - /** - * Get registration fees. - * - * @since 2.0.0 - * @return mixed[]|bool - */ - public function get_fees() { + } + /** + * Get registration fees. + * + * @since 2.0.0 + * @return mixed[]|bool + */ + public function get_fees() { return $this->get_line_items_by_type('fees'); - - } // end get_fees; + } /** * Calculates the total tax amount. @@ -2044,14 +1859,11 @@ class Cart implements \JsonSerializable { $total_taxes = 0; foreach ($this->line_items as $line_item) { - $total_taxes += $line_item->get_tax_total(); - - } // end foreach; + } return $total_taxes; - - } // end get_total_taxes; + } /** * Get the total number of fees. @@ -2067,37 +1879,28 @@ class Cart implements \JsonSerializable { $line_items = $this->get_fees(); - if (!$line_items) { - + if ( ! $line_items) { return 0; - - } // end if; + } $fees = 0; foreach ($line_items as $fee) { - - if ($only_recurring && !$fee->is_recurring()) { - + if ($only_recurring && ! $fee->is_recurring()) { continue; - - } // end if; + } $fees += $fee->get_total(); - - } // end foreach; + } // if total is present, make sure that any negative fees are not // greater than the total. if ($total && ($fees + $total) < 0) { - $fees = -1 * $total; - - } // end if; + } return apply_filters('wu_cart_get_total_fees', (float) $fees, $total, $only_recurring, $this); - - } // end get_total_fees; + } /** * Get the total proration amount. @@ -2109,29 +1912,22 @@ class Cart implements \JsonSerializable { */ public function get_proration_credits() { - if (!$this->get_fees()) { - + if ( ! $this->get_fees()) { return 0; - - } // end if; + } $proration = 0; foreach ($this->get_fees() as $fee) { - - if (!$fee['proration']) { - + if ( ! $fee['proration']) { continue; - - } // end if; + } $proration += $fee['amount']; - - } // end foreach; + } return apply_filters('wu_cart_get_proration_fees', (float) $proration, $this); - - } // end get_proration_credits; + } /** * Get the total discounts. @@ -2144,16 +1940,13 @@ class Cart implements \JsonSerializable { $total_discount = 0; foreach ($this->line_items as $line_item) { - $total_discount -= $line_item->get_discount_total(); - - } // end foreach; + } $total_discount = round($total_discount, wu_currency_decimal_filter()); return apply_filters('wu_cart_get_total_discounts', $total_discount, $this); - - } // end get_total_discounts; + } /** * Gets the subtotal value of the cart. @@ -2171,22 +1964,16 @@ class Cart implements \JsonSerializable { ); foreach ($this->line_items as $line_item) { - if (in_array($line_item->get_type(), $exclude_types, true)) { - continue; - - } // end if; + } $subtotal += $line_item->get_subtotal(); - - } // end foreach; + } if (0 > $subtotal) { - $subtotal = 0; - - } // end if; + } $subtotal = round($subtotal, wu_currency_decimal_filter()); @@ -2197,8 +1984,7 @@ class Cart implements \JsonSerializable { * @param \WP_Ultimo\Checkout\Cart $this Cart object. */ return apply_filters('wu_cart_get_subtotal', floatval($subtotal), $this); // @phpstan-ignore-line - - } // end get_subtotal; + } /** * Get the registration total due today. @@ -2211,16 +1997,12 @@ class Cart implements \JsonSerializable { $total = 0; foreach ($this->line_items as $line_item) { - $total += $line_item->get_total(); - - } // end foreach; + } if (0 > $total) { - $total = 0; - - } // end if; + } $total = round($total, wu_currency_decimal_filter()); @@ -2231,8 +2013,7 @@ class Cart implements \JsonSerializable { * @param \WP_Ultimo\Checkout\Cart $this Cart object. */ return apply_filters('wu_cart_get_total', floatval($total), $this); // @phpstan-ignore-line - - } // end get_total; + } /** * Get the registration recurring total. @@ -2245,43 +2026,35 @@ class Cart implements \JsonSerializable { $total = 0; foreach ($this->line_items as $line_item) { - - if (!$line_item->is_recurring()) { - + if ( ! $line_item->is_recurring()) { continue; - - } // end if; + } /* * Check for coupon codes */ - if ($line_item->get_discount_total() > 0 && !$line_item->should_apply_discount_to_renewals()) { - + if ($line_item->get_discount_total() > 0 && ! $line_item->should_apply_discount_to_renewals()) { $new_line_item = clone $line_item; - $new_line_item->attributes(array( - 'discount_rate' => 0, - )); + $new_line_item->attributes( + array( + 'discount_rate' => 0, + ) + ); $new_line_item->recalculate_totals(); $amount = $new_line_item->get_total(); - } else { - $amount = $line_item->get_total(); - - } // end if; + } $total += $amount; - - } // end foreach; + } if (0 > $total) { - $total = 0; - - } // end if; + } $total = round($total, wu_currency_decimal_filter()); @@ -2292,8 +2065,7 @@ class Cart implements \JsonSerializable { * @param \WP_Ultimo\Checkout\Cart $this Cart object. */ return apply_filters('wu_cart_get_recurring_total', floatval($total), $this); // @phpstan-ignore-line - - } // end get_recurring_total; + } /** * Gets the recurring subtotal, before taxes. @@ -2306,22 +2078,16 @@ class Cart implements \JsonSerializable { $subtotal = 0; foreach ($this->line_items as $line_item) { - - if (!$line_item->is_recurring()) { - + if ( ! $line_item->is_recurring()) { continue; - - } // end if; + } $subtotal += $line_item->get_subtotal(); - - } // end foreach; + } if (0 > $subtotal) { - $subtotal = 0; - - } // end if; + } $subtotal = round($subtotal, wu_currency_decimal_filter()); @@ -2332,8 +2098,7 @@ class Cart implements \JsonSerializable { * @param \WP_Ultimo\Checkout\Cart $this Cart object. */ return apply_filters('wu_cart_get_recurring_total', floatval($subtotal), $this); // @phpstan-ignore-line - - } // end get_recurring_subtotal; + } /** * Returns the timestamp of the end of the trial period. @@ -2343,11 +2108,9 @@ class Cart implements \JsonSerializable { */ public function get_billing_start_date() { - if ($this->is_free() && !$this->has_recurring()) { - + if ($this->is_free() && ! $this->has_recurring()) { return null; - - } // end if; + } /* * Set extremely high value at first to prevent any change of errors. @@ -2355,67 +2118,51 @@ class Cart implements \JsonSerializable { $smallest_trial = 300 * YEAR_IN_SECONDS; foreach ($this->get_all_products() as $product) { - - if (!$product->has_trial()) { - + if ( ! $product->has_trial()) { $smallest_trial = 0; - - } // end if; + } $duration = $product->get_trial_duration(); $duration_unit = $product->get_trial_duration_unit(); if ($duration && $duration_unit) { - $trial_period = strtotime("+$duration $duration_unit"); if ($trial_period < $smallest_trial) { - $smallest_trial = $trial_period; - - } // end if; - - } // end if; - - } // end foreach; + } + } + } return $smallest_trial; - - } // end get_billing_start_date; - /** - * Returns the timestamp of the next charge, if recurring. - * - * @since 2.0.0 - * @return string|false - */ - public function get_billing_next_charge_date() { + } + /** + * Returns the timestamp of the next charge, if recurring. + * + * @since 2.0.0 + * @return string|false + */ + public function get_billing_next_charge_date() { /* * Set extremely high value at first to prevent any chance of errors. */ $smallest_next_charge = 300 * YEAR_IN_SECONDS; if ($this->get_cart_type() === 'downgrade') { - $membership = $this->membership; if ($membership->is_active() || $membership->get_status() === Membership_Status::TRIALING) { - $next_charge = strtotime($membership->get_date_expiration()); return $next_charge; - - } // end if; - - } // end if; + } + } foreach ($this->get_all_products() as $product) { - - if (!$product->is_recurring() || ($product->has_trial() && $this->has_trial())) { - + if ( ! $product->is_recurring() || ($product->has_trial() && $this->has_trial())) { continue; - - } // end if; + } $duration = $product->get_duration(); @@ -2424,16 +2171,12 @@ class Cart implements \JsonSerializable { $next_charge = strtotime("+$duration $duration_unit"); if ($next_charge < $smallest_next_charge) { - $smallest_next_charge = $next_charge; - - } // end if; - - } // end foreach; + } + } return $smallest_next_charge; - - } // end get_billing_next_charge_date; + } /** * Checks if the order is recurring or not. @@ -2444,8 +2187,7 @@ class Cart implements \JsonSerializable { public function has_recurring() { return $this->get_recurring_total() > 0; - - } // end has_recurring; + } /** * Returns an array with all types of line-items of the cart. @@ -2456,8 +2198,7 @@ class Cart implements \JsonSerializable { public function get_line_items() { return $this->line_items; - - } // end get_line_items; + } /** * Apply discounts to a line item. @@ -2472,52 +2213,45 @@ class Cart implements \JsonSerializable { /** * Product is not taxable, bail. */ - if (!$line_item->is_discountable() || !$this->discount_code) { - + if ( ! $line_item->is_discountable() || ! $this->discount_code) { return $line_item; - - } // end if; + } if (is_wp_error($this->discount_code->is_valid($line_item->get_product_id()))) { - return $line_item; - - } // end if; + } /** * Should apply to fees? */ if ($line_item->get_type() === 'fee') { - if ($this->discount_code->get_setup_fee_value() <= 0) { - return $line_item; + } - } // end if; - - $line_item->attributes(array( - 'discount_rate' => $this->discount_code->get_setup_fee_value(), - 'discount_type' => $this->discount_code->get_setup_fee_type(), - 'apply_discount_to_renewals' => false, - 'discount_label' => strtoupper($this->discount_code->get_code()), - )); - + $line_item->attributes( + array( + 'discount_rate' => $this->discount_code->get_setup_fee_value(), + 'discount_type' => $this->discount_code->get_setup_fee_type(), + 'apply_discount_to_renewals' => false, + 'discount_label' => strtoupper($this->discount_code->get_code()), + ) + ); } else { - - $line_item->attributes(array( - 'discount_rate' => $this->discount_code->get_value(), - 'discount_type' => $this->discount_code->get_type(), - 'apply_discount_to_renewals' => $this->discount_code->should_apply_to_renewals(), - 'discount_label' => strtoupper($this->discount_code->get_code()), - )); - - } // end if; + $line_item->attributes( + array( + 'discount_rate' => $this->discount_code->get_value(), + 'discount_type' => $this->discount_code->get_type(), + 'apply_discount_to_renewals' => $this->discount_code->should_apply_to_renewals(), + 'discount_label' => strtoupper($this->discount_code->get_code()), + ) + ); + } $line_item->recalculate_totals(); return $line_item; - - } // end apply_discounts_to_item; + } /** * Apply taxes to a line item. @@ -2532,63 +2266,54 @@ class Cart implements \JsonSerializable { /** * Tax collection is not enabled */ - if (!wu_should_collect_taxes()) { - + if ( ! wu_should_collect_taxes()) { return $line_item; - - } // end if; + } /** * Product is not taxable, bail. */ - if (!$line_item->is_taxable()) { - + if ( ! $line_item->is_taxable()) { return $line_item; - - } // end if; + } $tax_category = $line_item->get_tax_category(); /** * No tax category, bail. */ - if (!$tax_category) { - + if ( ! $tax_category) { return $line_item; - - } // end if; + } $tax_rates = apply_filters('wu_cart_applicable_tax_rates', wu_get_applicable_tax_rates($this->country, $tax_category, $this->state, $this->city), $this->country, $tax_category, $this); if (empty($tax_rates)) { - return $line_item; - - } // end if; + } foreach ($tax_rates as $applicable_tax_rate) { - $tax_type = 'percentage'; $tax_rate = $applicable_tax_rate['tax_rate']; $tax_label = $applicable_tax_rate['title']; continue; + } - } // end foreach; - - $line_item->attributes(array( - 'tax_rate' => $tax_rate ?? 0, - 'tax_type' => $tax_type ?? 'percentage', - 'tax_label' => $tax_label ?? '', - 'tax_inclusive' => wu_get_setting('inclusive_tax', false), - 'tax_exempt' => $this->is_tax_exempt(), - )); + $line_item->attributes( + array( + 'tax_rate' => $tax_rate ?? 0, + 'tax_type' => $tax_type ?? 'percentage', + 'tax_label' => $tax_label ?? '', + 'tax_inclusive' => wu_get_setting('inclusive_tax', false), + 'tax_exempt' => $this->is_tax_exempt(), + ) + ); $line_item->recalculate_totals(); return $line_item; - - } // end apply_taxes_to_item; + } /** * Calculates the totals of the cart and return them. @@ -2609,8 +2334,7 @@ class Cart implements \JsonSerializable { 'total_discounts' => $this->get_total_discounts(), 'total' => $this->get_total(), ); - - } // end calculate_totals; + } /** * Used for serialization purposes. @@ -2621,8 +2345,7 @@ class Cart implements \JsonSerializable { public function jsonSerialize(): string { return json_encode($this->done()); - - } // end jsonSerialize; + } /** * Get the list of extra parameters. @@ -2635,14 +2358,11 @@ class Cart implements \JsonSerializable { $extra_params = array(); foreach ($this->extra as $key) { - - $extra_params[$key] = $this->get_param($key); - - } // end foreach; + $extra_params[ $key ] = $this->get_param($key); + } return apply_filters('wu_cart_get_extra_params', $extra_params, $this); - - } // end get_extra_params; + } /** * Implements our on json_decode version of this object. Useful for use in vue.js. @@ -2657,21 +2377,15 @@ class Cart implements \JsonSerializable { $errors = array(); if ($this->errors->has_errors()) { - foreach ($this->errors as $code => $messages) { - foreach ($messages as $message) { - $errors[] = array( 'code' => $code, 'message' => $message, ); - - } // end foreach; - - } // end foreach; - - } // end if; + } + } + } return (object) array( @@ -2699,8 +2413,7 @@ class Cart implements \JsonSerializable { ), ); - - } // end done; + } /** * Converts the current cart to an array of membership elements. @@ -2712,36 +2425,38 @@ class Cart implements \JsonSerializable { $membership_data = array(); - $all_additional_products = $this->get_line_items_by_type('product', array( - array('product_id', '!=', $this->get_plan_id()), - )); + $all_additional_products = $this->get_line_items_by_type( + 'product', + array( + array('product_id', '!=', $this->get_plan_id()), + ) + ); $addon_list = array(); foreach ($all_additional_products as $line_item) { + $addon_list[ $line_item->get_product_id() ] = $line_item->get_quantity(); + } - $addon_list[$line_item->get_product_id()] = $line_item->get_quantity(); - - } // end foreach; - - $membership_data = array_merge(array( - 'recurring' => $this->has_recurring(), - 'plan_id' => $this->get_plan() ? $this->get_plan()->get_id() : 0, - 'initial_amount' => $this->get_total(), - 'addon_products' => $addon_list, - 'currency' => $this->get_currency(), - 'duration' => $this->get_duration(), - 'duration_unit' => $this->get_duration_unit(), - 'amount' => $this->get_recurring_total(), - 'times_billed' => 0, - 'billing_cycles' => $this->get_plan() ? $this->get_plan()->get_billing_cycles() : 0, - 'auto_renew' => false, // @todo: revisit - 'upgraded_from' => false, // @todo: revisit - )); + $membership_data = array_merge( + array( + 'recurring' => $this->has_recurring(), + 'plan_id' => $this->get_plan() ? $this->get_plan()->get_id() : 0, + 'initial_amount' => $this->get_total(), + 'addon_products' => $addon_list, + 'currency' => $this->get_currency(), + 'duration' => $this->get_duration(), + 'duration_unit' => $this->get_duration_unit(), + 'amount' => $this->get_recurring_total(), + 'times_billed' => 0, + 'billing_cycles' => $this->get_plan() ? $this->get_plan()->get_billing_cycles() : 0, + 'auto_renew' => false, // @todo: revisit + 'upgraded_from' => false, // @todo: revisit + ) + ); return $membership_data; - - } // end to_membership_data; + } /** * Converts the current cart to a payment data array. @@ -2766,8 +2481,7 @@ class Cart implements \JsonSerializable { ); return $payment_data; - - } // end to_payment_data; + } /** * Get the value of discount_code @@ -2778,8 +2492,7 @@ class Cart implements \JsonSerializable { public function get_discount_code() { return $this->discount_code; - - } // end get_discount_code; + } /** * Get the value of plan_id @@ -2790,8 +2503,7 @@ class Cart implements \JsonSerializable { public function get_plan_id() { return $this->plan_id; - - } // end get_plan_id; + } /** * Get the currency code. @@ -2802,8 +2514,7 @@ class Cart implements \JsonSerializable { public function get_currency() { return $this->currency; - - } // end get_currency; + } /** * Set the currency. @@ -2815,8 +2526,7 @@ class Cart implements \JsonSerializable { public function set_currency($currency) { $this->currency = $currency; - - } // end set_currency; + } /** * Get the cart membership. @@ -2827,8 +2537,7 @@ class Cart implements \JsonSerializable { public function get_membership() { return $this->membership; - - } // end get_membership; + } /** * Get the cart payment. @@ -2839,8 +2548,7 @@ class Cart implements \JsonSerializable { public function get_payment() { return $this->payment; - - } // end get_payment; + } /** * Get the cart customer. @@ -2851,8 +2559,7 @@ class Cart implements \JsonSerializable { public function get_customer() { return $this->customer; - - } // end get_customer; + } /** * Set the cart membership. @@ -2864,8 +2571,7 @@ class Cart implements \JsonSerializable { public function set_membership($membership) { $this->membership = $membership; - - } // end set_membership; + } /** * Set the cart customer. @@ -2877,8 +2583,7 @@ class Cart implements \JsonSerializable { public function set_customer($customer) { $this->customer = $customer; - - } // end set_customer; + } /** * Set the cart payment. @@ -2890,8 +2595,7 @@ class Cart implements \JsonSerializable { public function set_payment($payment) { $this->payment = $payment; - - } // end set_payment; + } /** * Get the value of auto_renew. @@ -2902,8 +2606,7 @@ class Cart implements \JsonSerializable { public function should_auto_renew() { return $this->auto_renew === 'yes' || $this->auto_renew === true; - - } // end should_auto_renew; + } /** * Get the cart type. @@ -2914,8 +2617,7 @@ class Cart implements \JsonSerializable { public function get_cart_type() { return $this->cart_type; - - } // end get_cart_type; + } /** * Get the country of the customer. @@ -2926,8 +2628,7 @@ class Cart implements \JsonSerializable { public function get_country() { return $this->country; - - } // end get_country; + } /** * Set the country of the customer. @@ -2939,8 +2640,7 @@ class Cart implements \JsonSerializable { public function set_country($country) { $this->country = $country; - - } // end set_country; + } /** * Builds a cart URL that we can use with the browser history APIs. @@ -2955,41 +2655,32 @@ class Cart implements \JsonSerializable { $plan = wu_get_product($this->plan_id); if ($plan) { - $base_url .= $plan->get_slug(); - - } // end if; + } if ($this->duration && absint($this->duration) !== 1) { - $base_url .= "/{$this->duration}"; + } - } // end if; - - if ($this->duration_unit && $this->duration_unit !== 'month') { - + if ($this->duration_unit && 'month' !== $this->duration_unit) { $base_url .= "/{$this->duration_unit}"; - - } // end if; + } $all_products = $this->products; $products_list = array(); foreach ($all_products as $product) { - if ($product->get_id() !== $this->plan_id) { - $products_list[] = $product->get_slug(); + } + } - } // end if; - - } // end foreach; - - return add_query_arg(array( - 'products' => $products_list, - ), $base_url); - - } // end get_cart_url; - -} // end class Cart; + return add_query_arg( + array( + 'products' => $products_list, + ), + $base_url + ); + } +} diff --git a/inc/checkout/class-checkout-pages.php b/inc/checkout/class-checkout-pages.php index 18d31e7..ea25e95 100644 --- a/inc/checkout/class-checkout-pages.php +++ b/inc/checkout/class-checkout-pages.php @@ -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 { 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(__( 'Error: The password you entered is incorrect.', 'wp-ultimo')), + 'incorrect_password' => sprintf(__('Error: 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 login page.'), wp_login_url()), - 'registered' => sprintf(__( 'Registration complete. Please check your email, then visit the login page.' ), wp_login_url()), + 'registered' => sprintf(__('Registration complete. Please check your email, then visit the login page.'), wp_login_url()), 'loggedout' => __('You are now logged out.'), 'registerdisabled' => __('Error: User registration is currently not allowed.'), 'empty_username' => __('Error: 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 = '
%s
'; $message = __('Your email address is not yet verified. Your site will only be activated 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('
%s', __('Resend verification email →', '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')), + ) + ); + } +} diff --git a/inc/checkout/class-checkout.php b/inc/checkout/class-checkout.php index 2b74f4c..98c439b 100644 --- a/inc/checkout/class-checkout.php +++ b/inc/checkout/class-checkout.php @@ -12,13 +12,13 @@ namespace WP_Ultimo\Checkout; // Exit if accessed directly defined('ABSPATH') || exit; -use \Psr\Log\LogLevel; -use \WP_Ultimo\Database\Sites\Site_Type; -use \WP_Ultimo\Database\Payments\Payment_Status; -use \WP_Ultimo\Database\Memberships\Membership_Status; -use \WP_Ultimo\Checkout\Checkout_Pages; -use \WP_Ultimo\Objects\Billing_Address; -use \WP_Ultimo\Models\Site; +use Psr\Log\LogLevel; +use WP_Ultimo\Database\Sites\Site_Type; +use WP_Ultimo\Database\Payments\Payment_Status; +use WP_Ultimo\Database\Memberships\Membership_Status; +use WP_Ultimo\Checkout\Checkout_Pages; +use WP_Ultimo\Objects\Billing_Address; +use WP_Ultimo\Models\Site; /** * Handles the processing of new membership purchases. @@ -197,8 +197,7 @@ class Checkout { * Errors */ add_action('wu_checkout_errors', array($this, 'maybe_display_checkout_errors')); - - } // end init; + } /** * Add checkout rewrite rules. @@ -218,11 +217,9 @@ class Checkout { $register = Checkout_Pages::get_instance()->get_signup_page('register'); - if (!is_a($register, '\WP_Post')) { - + if ( ! is_a($register, '\WP_Post')) { return; - - } // end if; + } $register_slug = $register->post_name; @@ -279,8 +276,7 @@ class Checkout { 'index.php?pagename=' . $register_slug . '&template_name=$matches[1]&wu_preselected=template_id', 'top' ); - - } // end add_rewrite_rules; + } /** * Filters the wu_request with the query vars. @@ -293,21 +289,22 @@ class Checkout { */ public function get_checkout_from_query_vars($value, $key) { - if (!did_action('wp')) { - + if ( ! did_action('wp')) { return $value; - - } // end if; + } $from_query = get_query_var($key); - $cart_arguments = apply_filters('wu_get_checkout_from_query_vars', array( - 'products', - 'duration', - 'duration_unit', - 'template_id', - 'wu_preselected', - )); + $cart_arguments = apply_filters( + 'wu_get_checkout_from_query_vars', + array( + 'products', + 'duration', + 'duration_unit', + 'template_id', + 'wu_preselected', + ) + ); /** * Deal with site templates in a specific manner. @@ -315,11 +312,9 @@ class Checkout { * @since 2.0.8 */ if ($key === 'template_id') { - $template_name = get_query_var('template_name', null); if ($template_name !== null) { - $d = wu_get_site_domain_and_path($template_name); $wp_site = get_site_by_path($d->domain, $d->path); @@ -327,28 +322,21 @@ class Checkout { $site = $wp_site ? wu_get_site($wp_site->blog_id) : false; if ($site && $site->get_type() === Site_Type::SITE_TEMPLATE) { - return $site->get_id(); - - } // end if; - - } // end if; - - } // end if; + } + } + } /* * Otherwise, simply check for its existence * on the query object. */ if (in_array($key, $cart_arguments, true) && $from_query) { - return $from_query; - - } // end if; + } return $value; - - } // end get_checkout_from_query_vars; + } /** * Setups the necessary boilerplate code to have checkouts work. @@ -360,39 +348,30 @@ class Checkout { public function setup_checkout($element = null) { if ($this->already_setup) { - return; - - } // end if; + } $checkout_form_slug = wu_request('checkout_form'); if (wu_request('pre-flight')) { - $checkout_form_slug = false; $_REQUEST['pre_selected'] = $_REQUEST; + } - } // end if; - - if (!$checkout_form_slug && is_a($element, \WP_Ultimo\UI\Checkout_Element::class)) { - + if ( ! $checkout_form_slug && is_a($element, \WP_Ultimo\UI\Checkout_Element::class)) { $pre_loaded_checkout_form_slug = $element->get_pre_loaded_attribute('slug', $checkout_form_slug); $checkout_form_slug = $pre_loaded_checkout_form_slug ? $pre_loaded_checkout_form_slug : $checkout_form_slug; - - } // end if; + } $this->checkout_form = wu_get_checkout_form_by_slug($checkout_form_slug); if ($this->session === null) { - $this->session = wu_get_session('signup'); - - } // end if; + } if ($this->checkout_form) { - $this->steps = $this->checkout_form->get_steps_to_show(); $first_step = current($this->steps); @@ -408,20 +387,16 @@ class Checkout { $this->auto_submittable_field = $this->contains_auto_submittable_field($this->step['fields']); $this->step['fields'] = wu_create_checkout_fields($this->step['fields']); - - } // end if; + } if (is_user_logged_in()) { - $_REQUEST['user_id'] = get_current_user_id(); - - } // end if; + } $this->already_setup = true; wu_no_cache(); // Prevent the registration page from being cached. - - } // end setup_checkout; + } /** * Checks if a list of fields has an auto-submittable field. @@ -440,45 +415,34 @@ class Checkout { 'products', 'submit_button', 'period_selection', - 'steps' + 'steps', ); // Extra check to prevent error messages from being displayed. - if (!is_array($fields)) { - + if ( ! is_array($fields)) { $fields = array(); - - } // end if; + } foreach ($fields as $field) { - if (in_array($field['type'], $field_types_to_ignore, true)) { - continue; - - } // end if; + } $relevant_fields[] = $field; if (count($relevant_fields) > 1) { - return false; + } + } - } // end if; - - } // end foreach; - - if (!$relevant_fields) { - + if ( ! $relevant_fields) { return false; - - } // end if; + } $auto_submittable_field = $relevant_fields[0]['type']; return wu_get_isset($this->get_auto_submittable_fields(), $auto_submittable_field, false); - - } // end contains_auto_submittable_field; + } /** * Returns a list of auto-submittable fields. @@ -499,8 +463,7 @@ class Checkout { ); return apply_filters('wu_checkout_get_auto_submittable_fields', $auto_submittable_fields, $this); - - } // end get_auto_submittable_fields; + } /** * Decides if we want to handle a step submission or a full checkout submission. @@ -513,24 +476,17 @@ class Checkout { $this->setup_checkout(); if ($this->is_last_step()) { - $this->handle_order_submission(); - } else { - $validation = $this->validate(); if (is_wp_error($validation)) { - wp_send_json_error($validation); - - } // end if; + } wp_send_json_success(array()); - - } // end if; - - } // end maybe_handle_order_submission; + } + } /** * Validates the order submission, and then delegates the processing to the gateway. @@ -571,28 +527,21 @@ class Checkout { do_action('wu_after_handle_order_submission', $results, $this); if (is_wp_error($results)) { - $this->errors = $results; - - } // end if; - + } } catch (\Throwable $e) { - wu_maybe_log_error($e); $wpdb->query('ROLLBACK'); $this->errors = new \WP_Error('exception-order-submission', $e->getMessage(), $e->getTrace()); - - } // end try; + } if (is_wp_error($this->errors)) { - $wpdb->query('ROLLBACK'); wp_send_json_error($this->errors); - - } // end if; + } $wpdb->query('COMMIT'); @@ -600,36 +549,35 @@ class Checkout { $this->session->commit(); wp_send_json_success($results); - - } // end handle_order_submission; - /** - * Process an order. - * - * This method is responsible for - * creating all the data elements we - * need in order to actually process a - * checkout. - * - * Those include: - * - A customer; - * - A pending payment; - * - A membership. - * - * With those elements, we can then - * delegate to the gateway to run their - * own preparations (@see run_preflight). - * - * We then return everything to be added - * to the front-end form. That data then - * gets submitted with the rest of the form, - * and eventually handled by process_checkout. - * - * @see process_checkout - * - * @since 2.0.0 - * @return mixed[]|\WP_Error - */ - public function process_order() { + } + /** + * Process an order. + * + * This method is responsible for + * creating all the data elements we + * need in order to actually process a + * checkout. + * + * Those include: + * - A customer; + * - A pending payment; + * - A membership. + * + * With those elements, we can then + * delegate to the gateway to run their + * own preparations (@see run_preflight). + * + * We then return everything to be added + * to the front-end form. That data then + * gets submitted with the rest of the form, + * and eventually handled by process_checkout. + * + * @see process_checkout + * + * @since 2.0.0 + * @return mixed[]|\WP_Error + */ + public function process_order() { global $current_site, $wpdb; @@ -638,19 +586,25 @@ class Checkout { * We need to take into consideration the date we receive from * the form submission. */ - $cart = new Cart(apply_filters('wu_cart_parameters', array( - 'products' => $this->request_or_session('products', array()), - 'discount_code' => $this->request_or_session('discount_code'), - 'country' => $this->request_or_session('billing_country'), - 'state' => $this->request_or_session('billing_state'), - 'city' => $this->request_or_session('billing_city'), - 'membership_id' => $this->request_or_session('membership_id'), - 'payment_id' => $this->request_or_session('payment_id'), - 'auto_renew' => $this->request_or_session('auto_renew', false), - 'duration' => $this->request_or_session('duration'), - 'duration_unit' => $this->request_or_session('duration_unit'), - 'cart_type' => $this->request_or_session('cart_type', 'new'), - ), $this)); + $cart = new Cart( + apply_filters( + 'wu_cart_parameters', + array( + 'products' => $this->request_or_session('products', array()), + 'discount_code' => $this->request_or_session('discount_code'), + 'country' => $this->request_or_session('billing_country'), + 'state' => $this->request_or_session('billing_state'), + 'city' => $this->request_or_session('billing_city'), + 'membership_id' => $this->request_or_session('membership_id'), + 'payment_id' => $this->request_or_session('payment_id'), + 'auto_renew' => $this->request_or_session('auto_renew', false), + 'duration' => $this->request_or_session('duration'), + 'duration_unit' => $this->request_or_session('duration_unit'), + 'cart_type' => $this->request_or_session('cart_type', 'new'), + ), + $this + ) + ); /* * Check if our order is valid. @@ -659,10 +613,8 @@ class Checkout { * cart setup issues, as well as */ if ($cart->is_valid() === false) { - return $cart->get_errors(); - - } // end if; + } /* * Update the checkout type @@ -690,30 +642,20 @@ class Checkout { * That's what's we checking on the else case. */ if ($cart->should_collect_payment() === false) { - $gateway = wu_get_gateway('free'); + } elseif ( ! $gateway || $gateway->get_id() === 'free') { + $this->errors = new \WP_Error('no-gateway', __('Payment gateway not registered.', 'wp-ultimo')); - } else { - - if (!$gateway || $gateway->get_id() === 'free') { - - $this->errors = new \WP_Error('no-gateway', __('Payment gateway not registered.', 'wp-ultimo')); - - return false; - - } // end if; - - } // end if; + return false; + } /* * If we do not have a gateway object, * we need to bail. */ - if (!$gateway) { - + if ( ! $gateway) { return new \WP_Error('no-gateway', __('Payment gateway not registered.', 'wp-ultimo')); - - } // end if; + } $this->gateway_id = $gateway->get_id(); @@ -729,10 +671,8 @@ class Checkout { * Bail on error. */ if (is_wp_error($validation)) { - return $validation; - - } // end if; + } /* * From now on, logic can be delegated to @@ -760,10 +700,8 @@ class Checkout { * a new customer or retrieve an existing one. */ if (is_wp_error($this->customer)) { - return $this->customer; - - } // end if; + } /* * Next, we need to create a membership. @@ -780,10 +718,8 @@ class Checkout { * a new membership or retrieve an existing one. */ if (is_wp_error($this->membership)) { - return $this->membership; - - } // end if; + } /* * Next step: maybe create a site. @@ -799,10 +735,8 @@ class Checkout { * in here for now but completeness dictates I add this. */ if (is_wp_error($this->pending_site)) { - return $this->pending_site; - - } // end if; + } /* * Next, we need to create a payment. @@ -819,10 +753,8 @@ class Checkout { * a new payment or retrieve an existing one. */ if (is_wp_error($this->payment)) { - return $this->payment; - - } // end if; + } /** * Keep the cart used in checkout for later reference. @@ -847,15 +779,13 @@ class Checkout { * let's check if the user is logged in, * and if not, let's do that. */ - if (!is_user_logged_in()) { - + if ( ! is_user_logged_in()) { wp_clear_auth_cookie(); wp_set_current_user($this->customer->get_user_id()); wp_set_auth_cookie($this->customer->get_user_id()); - - } // end if; + } /* * Action time. @@ -868,15 +798,12 @@ class Checkout { /* * Checks for free memberships. */ - if ($this->order->is_free() && $this->order->get_recurring_total() === 0.0 && (!wu_get_setting('enable_email_verification', true) || $this->customer->get_email_verification() !== 'pending')) { - + if ($this->order->is_free() && $this->order->get_recurring_total() === 0.0 && (! wu_get_setting('enable_email_verification', true) || $this->customer->get_email_verification() !== 'pending')) { if ($this->order->get_plan_id() === $this->membership->get_plan_id()) { - $this->membership->set_status(Membership_Status::ACTIVE); $this->membership->save(); - - } // end if; + } /** * Trigger payment received manually. @@ -884,21 +811,18 @@ class Checkout { * @since 2.0.10 */ $gateway->trigger_payment_processed($this->payment, $this->membership); - } elseif ($this->order->has_trial()) { - $this->membership->set_date_trial_end(gmdate('Y-m-d 23:59:59', $this->order->get_billing_start_date())); $this->membership->set_date_expiration(gmdate('Y-m-d 23:59:59', $this->order->get_billing_start_date())); - if (wu_get_setting('allow_trial_without_payment_method') && (!wu_get_setting('enable_email_verification', true) || $this->customer->get_email_verification() !== 'pending')) { + if (wu_get_setting('allow_trial_without_payment_method') && (! wu_get_setting('enable_email_verification', true) || $this->customer->get_email_verification() !== 'pending')) { /* * In this particular case, we need to set the status to trialing here as we will not update the membership after and then, publish the site. */ $this->membership->set_status(Membership_Status::TRIALING); $this->membership->publish_pending_site_async(); - - } // end if; + } $this->membership->save(); @@ -908,8 +832,7 @@ class Checkout { * @since 2.0.10 */ $gateway->trigger_payment_processed($this->payment, $this->membership); - - } // end if; + } $success_data = array( 'nonce' => wp_create_nonce('wp-ultimo-register-nonce'), @@ -945,18 +868,13 @@ class Checkout { * On error, bail. */ if (is_wp_error($result)) { - return $result; - - } // end if; - + } } catch (\Throwable $e) { + wu_maybe_log_error($e); - wu_maybe_log_error($e); - - return new \WP_Error('exception', $e->getMessage(), $e->getTrace()); - - } // end try; + return new \WP_Error('exception', $e->getMessage(), $e->getTrace()); + } /** * Allow developers to triggers additional hooks. @@ -973,15 +891,14 @@ class Checkout { * All set! */ return $success_data; - - } // end process_order; - /** - * Checks if a customer exists, otherwise, creates a new one. - * - * @since 2.0.0 - * @return \WP_Ultimo\Models\Customer|\WP_Error - */ - protected function maybe_create_customer() { + } + /** + * Checks if a customer exists, otherwise, creates a new one. + * + * @since 2.0.0 + * @return \WP_Ultimo\Models\Customer|\WP_Error + */ + protected function maybe_create_customer() { /* * Check if we have * a customer for the current user. @@ -1002,26 +919,21 @@ class Checkout { * and that happens at the end of this method. */ if (empty($customer)) { - $username = $this->request_or_session('username'); /* * Handles auto-generation based on the email address. */ if ($this->request_or_session('auto_generate_username') === 'email') { - $username = wu_username_from_email($this->request_or_session('email_address')); /* * Case where the site title is also auto-generated, based on the username. */ if ($this->request_or_session('auto_generate_site_title') && $this->request_or_session('site_title', '') === '') { - $_REQUEST['site_title'] = $username; - - } // end if; - - } // end if; + } + } /* * If we get to this point, @@ -1043,17 +955,13 @@ class Checkout { * we use the existing email address to create the customer. */ if ($this->is_existing_user()) { - $customer_data = array( 'email' => wp_get_current_user()->user_email, 'email_verification' => 'verified', ); - } elseif (isset($customer_data['email']) && get_user_by('email', $customer_data['email'])) { - return new \WP_Error('email_exists', __('The email address you entered is already in use.', 'wp-ultimo')); - - } // end if; + } /* * Tries to create it. @@ -1064,12 +972,9 @@ class Checkout { * Something failed, bail. */ if (is_wp_error($customer)) { - return $customer; - - } // end if; - - } // end if; + } + } /* * Updates IP, and country @@ -1101,10 +1006,8 @@ class Checkout { * bail with the errors. */ if (is_wp_error($valid_address)) { - return $valid_address; - - } // end if; + } $customer->set_billing_address($billing_address); @@ -1114,11 +1017,9 @@ class Checkout { * This should rarely happen, but if something goes * wrong with the customer update, we return a general error. */ - if (!$address_saved) { - + if ( ! $address_saved) { return new \WP_Error('address_failure', __('Something wrong happened while attempting to save the customer billing address', 'wp-ultimo')); - - } // end if; + } /* * Handle meta fields. @@ -1145,8 +1046,7 @@ class Checkout { * Otherwise, get the customer back. */ return $customer; - - } // end maybe_create_customer; + } /** * Save meta data related to customers. @@ -1160,15 +1060,12 @@ class Checkout { protected function handle_customer_meta_fields($customer, $form_slug) { if (empty($form_slug) || $form_slug === 'none') { - return; - - } // end if; + } $checkout_form = wu_get_checkout_form_by_slug($form_slug); if ($checkout_form) { - $customer_meta_fields = $checkout_form->get_all_meta_fields('customer_meta'); $meta_repository = array(); @@ -1178,7 +1075,7 @@ class Checkout { * Adds to the repository so we can save it again. * in filters, if we need be. */ - $meta_repository[$customer_meta_field['id']] = $this->request_or_session($customer_meta_field['id']); + $meta_repository[ $customer_meta_field['id'] ] = $this->request_or_session($customer_meta_field['id']); wu_update_customer_meta( $customer->get_id(), @@ -1187,8 +1084,7 @@ class Checkout { $customer_meta_field['type'], $customer_meta_field['name'] ); - - } // end foreach; + } /** * Allow plugin developers to save meta @@ -1217,11 +1113,10 @@ class Checkout { * Adds to the repository so we can save it again. * in filters, if we need be. */ - $user_meta_repository[$user_meta_field['id']] = $this->request_or_session($user_meta_field['id']); + $user_meta_repository[ $user_meta_field['id'] ] = $this->request_or_session($user_meta_field['id']); update_user_meta($customer->get_user_id(), $user_meta_field['id'], $this->request_or_session($user_meta_field['id'])); - - } // end foreach; + } /** * Allow plugin developers to save user meta @@ -1234,26 +1129,22 @@ class Checkout { * @param Checkout $this The checkout class. */ do_action('wu_handle_user_meta_fields', $user_meta_repository, $user, $customer, $this); - - } // end if; - - } // end handle_customer_meta_fields; - /** - * Checks if a membership exists, otherwise, creates a new one. - * - * @since 2.0.0 - * @return \WP_Ultimo\Models\Membership|\WP_Error - */ - protected function maybe_create_membership() { + } + } + /** + * Checks if a membership exists, otherwise, creates a new one. + * + * @since 2.0.0 + * @return \WP_Ultimo\Models\Membership|\WP_Error + */ + protected function maybe_create_membership() { /* * The first thing we'll do is check the cart * to see if a membership was passed. */ if ($this->order->get_membership()) { - return $this->order->get_membership(); - - } // end if; + } /* * If that's not the case, @@ -1284,22 +1175,19 @@ class Checkout { $discount_code = $this->order->get_discount_code(); if ($discount_code) { - $membership->set_discount_code($discount_code); $membership->save(); - - } // end if; + } return $membership; - - } // end maybe_create_membership; - /** - * Checks if a pending site exists, otherwise, creates a new one. - * - * @since 2.0.0 - * @return bool|\WP_Ultimo\Models\Site|\WP_Error - */ - protected function maybe_create_site() { + } + /** + * Checks if a pending site exists, otherwise, creates a new one. + * + * @since 2.0.0 + * @return bool|\WP_Ultimo\Models\Site|\WP_Error + */ + protected function maybe_create_site() { /* * Let's get a list of membership sites. * This list includes pending sites as well. @@ -1317,28 +1205,25 @@ class Checkout { * 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 = $this->request_or_session('site_url'); $site_title = $this->request_or_session('site_title'); - if (!$site_url && !$site_title) { - + if ( ! $site_url && ! $site_title) { return false; - - } // end if; + } $auto_generate_url = $this->request_or_session('auto_generate_site_url'); - $site_title = !$site_title && !$auto_generate_url ? $site_url : $site_title; + $site_title = ! $site_title && ! $auto_generate_url ? $site_url : $site_title; /* * Let's handle auto-generation of site URLs. @@ -1351,34 +1236,26 @@ class Checkout { * check if it is already taken. */ if (empty($site_url) || $auto_generate_url === 'username') { - if ($auto_generate_url === 'username') { - $site_url = $this->customer->get_username(); $site_title = $site_title ? $site_title : $site_url; - } else { - $site_url = strtolower(str_replace(' ', '', preg_replace('/&([a-z])[a-z]+;/i', '$1', htmlentities(trim((string) $site_title))))); - - } // end if; + } $d = wu_get_site_domain_and_path($site_url, $this->request_or_session('site_domain')); $n = 0; while (domain_exists($d->domain, $d->path)) { - - $n++; + ++$n; $site_url = $this->customer->get_username() . $n; $d = wu_get_site_domain_and_path($site_url, $this->request_or_session('site_domain')); - - } // end while; - - } // end if; + } + } $d = wu_get_site_domain_and_path($site_url, $this->request_or_session('site_domain')); @@ -1388,10 +1265,8 @@ class Checkout { $results = wpmu_validate_blog_signup($site_url, $site_title, $this->customer->get_user()); if ($results['errors']->has_errors()) { - return $results['errors']; - - } // end if; + } /* * Get the form slug to save with the customer. @@ -1406,7 +1281,6 @@ class Checkout { $transient = array(); if ($this->checkout_form) { - $site_meta_fields = $this->checkout_form->get_all_fields(); foreach ($site_meta_fields as $site_meta_field) { @@ -1416,16 +1290,12 @@ class Checkout { * on the database. */ if (strpos((string) $site_meta_field['id'], 'password') !== false ) { - continue; + } - } // end if; - - $transient[$site_meta_field['id']] = $this->request_or_session($site_meta_field['id']); - - } // end foreach; - - } // end if; + $transient[ $site_meta_field['id'] ] = $this->request_or_session($site_meta_field['id']); + } + } /* * Gets the template id from the request. @@ -1456,8 +1326,7 @@ class Checkout { $pending_site = $this->membership->create_pending_site($site_data); return $pending_site; - - } // end maybe_create_site; + } /** * Gets list of site meta data. @@ -1471,37 +1340,30 @@ class Checkout { protected function get_site_meta_fields($form_slug, $meta_type = 'site_meta') { if (empty($form_slug) || $form_slug === 'none') { - return array(); - - } // end if; + } $checkout_form = wu_get_checkout_form_by_slug($form_slug); $list = array(); if ($checkout_form) { - $site_meta_fields = $checkout_form->get_all_meta_fields($meta_type); foreach ($site_meta_fields as $site_meta_field) { - - $list[$site_meta_field['id']] = $this->request_or_session($site_meta_field['id']); - - } // end foreach; - - } // end if; + $list[ $site_meta_field['id'] ] = $this->request_or_session($site_meta_field['id']); + } + } return $list; - - } // end get_site_meta_fields; - /** - * Checks if a pending payment exists, otherwise, creates a new one. - * - * @since 2.0.0 - * @return \WP_Ultimo\Models\Payment|\WP_Error - */ - protected function maybe_create_payment() { + } + /** + * Checks if a pending payment exists, otherwise, creates a new one. + * + * @since 2.0.0 + * @return \WP_Ultimo\Models\Payment|\WP_Error + */ + protected function maybe_create_payment() { /* * The first thing we'll do is check the cart * to see if a payment was passed. @@ -1513,15 +1375,12 @@ class Checkout { * Set the gateway in existing payment */ if ($payment->get_gateway() !== $this->gateway_id) { - $payment->set_gateway($this->gateway_id); $payment->save(); - - } // end if; + } return $this->order->get_payment(); - - } // end if; + } /* * The membership might have a previous payment. @@ -1537,7 +1396,6 @@ class Checkout { ); if ($previous_payment && in_array($this->type, $cancel_types, true)) { - $previous_payment->set_status(Payment_Status::CANCELLED); /* @@ -1546,8 +1404,7 @@ class Checkout { * were able to cancel the previous payment or not. */ $previous_payment->save(); - - } // end if; + } /* * If that's not the case, @@ -1572,11 +1429,9 @@ class Checkout { * to handle the status here as the payment is not * passed to process_checkout method in this case. */ - if (!$this->order->should_collect_payment() && $this->type === 'downgrade') { - + if ( ! $this->order->should_collect_payment() && $this->type === 'downgrade') { $payment_data['status'] = Payment_Status::COMPLETED; - - } // end if; + } /* * Create new payment. @@ -1588,21 +1443,20 @@ class Checkout { * we need to set the payment value to zero. */ if ($this->order->has_trial()) { - - $payment->attributes(array( - 'tax_total' => 0, - 'subtotal' => 0, - 'refund_total' => 0, - 'total' => 0, - )); + $payment->attributes( + array( + 'tax_total' => 0, + 'subtotal' => 0, + 'refund_total' => 0, + 'total' => 0, + ) + ); $payment->save(); - - } // end if; + } return $payment; - - } // end maybe_create_payment; + } /** * Validates the checkout form to see if it's valid por not. @@ -1615,14 +1469,11 @@ class Checkout { $validation = $this->validate(); if (is_wp_error($validation)) { - wp_send_json_error($validation); - - } // end if; + } wp_send_json_success(); - - } // end validate_form; + } /** * Creates an order object to display the order summary tables. @@ -1635,23 +1486,29 @@ class Checkout { $this->setup_checkout(); // Set billing address to be used on the order - $country = !empty($this->request_or_session('country')) ? $this->request_or_session('country') : $this->request_or_session('billing_country', ''); - $state = !empty($this->request_or_session('state')) ? $this->request_or_session('state') : $this->request_or_session('billing_state', ''); - $city = !empty($this->request_or_session('city')) ? $this->request_or_session('city') : $this->request_or_session('billing_city', ''); + $country = ! empty($this->request_or_session('country')) ? $this->request_or_session('country') : $this->request_or_session('billing_country', ''); + $state = ! empty($this->request_or_session('state')) ? $this->request_or_session('state') : $this->request_or_session('billing_state', ''); + $city = ! empty($this->request_or_session('city')) ? $this->request_or_session('city') : $this->request_or_session('billing_city', ''); - $cart = new Cart(apply_filters('wu_cart_parameters', array( - 'products' => $this->request_or_session('products', array()), - 'discount_code' => $this->request_or_session('discount_code'), - 'country' => $country, - 'state' => $state, - 'city' => $city, - 'membership_id' => $this->request_or_session('membership_id'), - 'payment_id' => $this->request_or_session('payment_id'), - 'auto_renew' => $this->request_or_session('auto_renew', false), - 'duration' => $this->request_or_session('duration'), - 'duration_unit' => $this->request_or_session('duration_unit'), - 'cart_type' => $this->request_or_session('cart_type', 'new'), - ), $this)); + $cart = new Cart( + apply_filters( + 'wu_cart_parameters', + array( + 'products' => $this->request_or_session('products', array()), + 'discount_code' => $this->request_or_session('discount_code'), + 'country' => $country, + 'state' => $state, + 'city' => $city, + 'membership_id' => $this->request_or_session('membership_id'), + 'payment_id' => $this->request_or_session('payment_id'), + 'auto_renew' => $this->request_or_session('auto_renew', false), + 'duration' => $this->request_or_session('duration'), + 'duration_unit' => $this->request_or_session('duration_unit'), + 'cart_type' => $this->request_or_session('cart_type', 'new'), + ), + $this + ) + ); /** * Calculate state and city options, if necessary. @@ -1660,17 +1517,18 @@ class Checkout { */ $country_data = wu_get_country($cart->get_country()); - wp_send_json_success(array( - 'order' => $cart->done(), - 'states' => wu_key_map_to_array($country_data->get_states_as_options(), 'code', 'name'), - 'cities' => wu_key_map_to_array($country_data->get_cities_as_options($state), 'code', 'name'), - 'labels' => array( - 'state_field' => $country_data->get_administrative_division_name(null, true), - 'city_field' => $country_data->get_municipality_name(null, true), - ), - )); - - } // end create_order; + wp_send_json_success( + array( + 'order' => $cart->done(), + 'states' => wu_key_map_to_array($country_data->get_states_as_options(), 'code', 'name'), + 'cities' => wu_key_map_to_array($country_data->get_cities_as_options($state), 'code', 'name'), + 'labels' => array( + 'state_field' => $country_data->get_administrative_division_name(null, true), + 'city_field' => $country_data->get_municipality_name(null, true), + ), + ) + ); + } /** * Returns the checkout variables. @@ -1705,31 +1563,21 @@ class Checkout { // If duration is not set we check for a previous period_selection field in form to use; if (empty($duration) && $this->steps) { - foreach ($this->steps as $step) { - foreach ($step['fields'] as $field) { - if ($field['type'] === 'period_selection') { - $duration = $field['period_options'][0]['duration']; $duration_unit = $field['period_options'][0]['duration_unit']; break; - - } // end if; - - } // end foreach; + } + } if ($duration) { - break; - - } // end if; - - } // end foreach; - - } // end if; + } + } + } $products = array_merge($this->request_or_session('products', array()), wu_request('products', array())); @@ -1776,10 +1624,8 @@ class Checkout { * a retry. */ if ($payment_id) { - $variables['payment_id'] = $payment_id; - - } // end if; + } /* * The next case we need to take care of @@ -1802,10 +1648,8 @@ class Checkout { * a retry. */ if ($membership_id) { - $variables['membership_id'] = $membership_id; - - } // end if; + } list($plan, $other_products) = wu_segregate_products($variables['products']); @@ -1835,8 +1679,7 @@ class Checkout { * @return array The new variables array. */ return apply_filters('wu_get_checkout_variables', $variables, $this); - - } // end get_checkout_variables; + } /** * Returns the validation rules for the fields. @@ -1880,12 +1723,10 @@ class Checkout { // char limit according https://datatracker.ietf.org/doc/html/rfc1034#section-3.1 $rules['site_title'] = 'min:4'; $rules['site_url'] = 'min:3|max:63|lowercase|unique_site'; - - } // end if; + } return apply_filters('wu_checkout_validation_rules', $rules, $this); - - } // end validation_rules; + } /** * Returns the list of validation rules. @@ -1904,29 +1745,23 @@ class Checkout { $validation_rules = $this->validation_rules(); if (wu_request('pre-flight') || wu_request('checkout_form') === 'wu-finish-checkout') { - $validation_rules = array(); return $validation_rules; - - } // end if; + } if ($this->step_name && $this->is_last_step() === false) { - $fields_available = array_column($this->step['fields'], 'id'); /* * Re-adds the template id check */ if (wu_request('template_id', null) !== null) { - $fields_available[] = 'template_id'; - - } // end if; + } $validation_rules = array_filter($validation_rules, fn($rule) => in_array($rule, $fields_available, true), ARRAY_FILTER_USE_KEY); - - } // end if; + } // We'll use this to validate product fields $product_fields = array( @@ -1942,29 +1777,20 @@ class Checkout { * General required fields */ if (wu_get_isset($field, 'required') && wu_get_isset($field, 'id')) { - - if (isset($validation_rules[$field['id']])) { - - $validation_rules[$field['id']] .= '|required'; - + if (isset($validation_rules[ $field['id'] ])) { + $validation_rules[ $field['id'] ] .= '|required'; } else { - - $validation_rules[$field['id']] = 'required'; - - } // end if; - - } // end if; + $validation_rules[ $field['id'] ] = 'required'; + } + } /* * Product fields */ if (wu_get_isset($field, 'id') && in_array($field['id'], $product_fields, true)) { - $validation_rules['products'] = 'products|required'; - - } // end if; - - } // end foreach; + } + } /** * Allow plugin developers to filter the validation rules. @@ -1974,8 +1800,7 @@ class Checkout { * @param Checkout $this The checkout class. */ return apply_filters('wu_checkout_validation_rules', $validation_rules, $this); - - } // end get_validation_rules; + } /** * Validates the rules and make sure we only save models when necessary. @@ -1986,23 +1811,19 @@ class Checkout { */ public function validate($rules = null) { - $validator = new \WP_Ultimo\Helpers\Validator; + $validator = new \WP_Ultimo\Helpers\Validator(); $session = $this->session->get('signup'); $stack = $_REQUEST; if (is_array($session)) { - $stack = array_merge($session, $_REQUEST); - - } // end if; + } if ($rules === null) { - $rules = $this->get_validation_rules(); - - } // end if; + } $base_aliases = array(); @@ -2010,26 +1831,25 @@ class Checkout { // Add current form fields foreach ($checkout_form_fields as $field) { - - $base_aliases[$field['id']] = wu_get_isset($field, 'name', ''); - - } // end foreach; + $base_aliases[ $field['id'] ] = wu_get_isset($field, 'name', ''); + } // Add Billing Address fields foreach (Billing_Address::fields() as $field_key => $field) { - - $base_aliases[$field_key] = wu_get_isset($field, 'title', ''); - - } // end foreach; + $base_aliases[ $field_key ] = wu_get_isset($field, 'title', ''); + } // Add some hidden or compound fields ids - $validation_aliases = array_merge(array( - 'password_conf' => __('Password confirmation', 'wp-ultimo'), - 'template_id' => __('Template ID', 'wp-ultimo'), - 'valid_password' => __('Valid password', 'wp-ultimo'), - 'products' => __('Products', 'wp-ultimo'), - 'gateway' => __('Payment Gateway', 'wp-ultimo'), - ), $base_aliases); + $validation_aliases = array_merge( + array( + 'password_conf' => __('Password confirmation', 'wp-ultimo'), + 'template_id' => __('Template ID', 'wp-ultimo'), + 'valid_password' => __('Valid password', 'wp-ultimo'), + 'products' => __('Products', 'wp-ultimo'), + 'gateway' => __('Payment Gateway', 'wp-ultimo'), + ), + $base_aliases + ); /** * Allow plugin developers to add custom aliases in form validator. @@ -2043,18 +1863,15 @@ class Checkout { $validator->validate($stack, $rules, $validation_aliases); if ($validator->fails()) { - $errors = $validator->get_errors(); $errors->remove('valid_password'); return $errors; - - } // end if; + } return true; - - } // end validate; + } /** * Decides if we are to process a checkout. @@ -2080,11 +1897,9 @@ class Checkout { * We can only process a checkout * if certain conditions are met. */ - if (!$this->should_process_checkout()) { - + if ( ! $this->should_process_checkout()) { return; - - } // end if; + } /* * Checks if we are in the last step. @@ -2112,7 +1927,6 @@ class Checkout { * arg so the customer can try again. */ if (is_wp_error($results)) { - $redirect_url = wu_get_current_url(); $this->session->set('errors', $results); @@ -2129,13 +1943,14 @@ class Checkout { * to a try again page. */ if ($payment) { - - $redirect_url = add_query_arg(array( - 'payment' => $payment->get_hash(), - 'status' => 'error', - ), $redirect_url); - - } // end if; + $redirect_url = add_query_arg( + array( + 'payment' => $payment->get_hash(), + 'status' => 'error', + ), + $redirect_url + ); + } /* * Redirect go burrr! @@ -2143,14 +1958,13 @@ class Checkout { wp_redirect($redirect_url); exit; + } - } // end if; - - /* - * This is not the final step, - * so we just clean the data and save it - * for later. - */ + /* + * This is not the final step, + * so we just clean the data and save it + * for later. + */ } else { /* * Cleans data and add it to the session. @@ -2162,11 +1976,9 @@ class Checkout { $to_save = array_filter($_POST, fn($item) => strncmp((string) $item, 'checkout_', strlen('checkout_')) !== 0 && strncmp((string) $item, '_', strlen('_')) !== 0, ARRAY_FILTER_USE_KEY); if (isset($to_save['pre-flight'])) { - unset($to_save['pre-flight']); $this->session->add_values('signup', array('pre_selected' => $to_save)); - - } // end if; + } /* * Append the cleaned date to the @@ -2179,7 +1991,7 @@ class Checkout { * Whether we should advance to the next step. * This prevents breaking the checkout flow when triggered from a shortcode page. */ - if (!wu_request('pre-flight')) { + if ( ! wu_request('pre-flight')) { /* * Go to the next step. */ @@ -2188,12 +2000,9 @@ class Checkout { wp_redirect(add_query_arg('step', $next_step)); exit; - - } // end if; - - } // end if; - - } // end maybe_process_checkout; + } + } + } /** * Runs pre-checks to see if we should process the checkout. @@ -2203,9 +2012,8 @@ class Checkout { */ public function should_process_checkout() { - return wu_request('checkout_action') === 'wu_checkout' && !wp_doing_ajax(); - - } // end should_process_checkout; + return wu_request('checkout_action') === 'wu_checkout' && ! wp_doing_ajax(); + } /** * Handles the checkout submission. @@ -2251,32 +2059,20 @@ class Checkout { * That's what's we checking on the else case. */ if ($payment->get_status() === Payment_Status::COMPLETED) { - $gateway = wu_get_gateway($payment->get_gateway()); - } elseif ($this->order->should_collect_payment() === false) { - $gateway = wu_get_gateway('free'); - - } else { - - if ($gateway->get_id() === 'free') { - + } elseif ($gateway->get_id() === 'free') { $this->errors = new \WP_Error('no-gateway', __('Payment gateway not registered.', 'wp-ultimo')); return false; + } - } // end if; - - } // end if; - - if (!$gateway) { - + if ( ! $gateway) { $this->errors = new \WP_Error('no-gateway', __('Payment gateway not registered.', 'wp-ultimo')); return false; - - } // end if; + } /* * Set the gateway data. @@ -2307,10 +2103,8 @@ class Checkout { * In that case, we simply return. */ if ($status === false) { - return; - - } // end if; + } /* * Run after every checkout processing. @@ -2323,7 +2117,6 @@ class Checkout { * Deprecated hook for registration. */ if (has_action('wp_ultimo_registration')) { - $_payment = wu_get_payment($payment->get_id()); $args = array( @@ -2338,8 +2131,7 @@ class Checkout { do_action_deprecated('wp_ultimo_registration', $args, '2.0.0'); ob_flush(); - - } // end if; + } /* * Otherwise, we redirect @@ -2348,7 +2140,7 @@ class Checkout { */ $redirect_url = $gateway->get_return_url(); - if (!is_admin()) { + if ( ! is_admin()) { /** * Set the redirect URL. * @@ -2359,19 +2151,19 @@ class Checkout { */ $redirect_url = apply_filters('wp_ultimo_redirect_url_after_signup', $redirect_url, 0, get_current_user_id(), $_POST); - $redirect_url = add_query_arg(array( - 'payment' => $payment ? $payment->get_hash() : 'none', - 'status' => 'done', - ), $redirect_url); - - } // end if; + $redirect_url = add_query_arg( + array( + 'payment' => $payment ? $payment->get_hash() : 'none', + 'status' => 'done', + ), + $redirect_url + ); + } wp_redirect($redirect_url); exit; - } catch (\Throwable $e) { - $membership_id = $this->order->get_membership() ? $this->order->get_membership()->get_id() : 'unknown'; $log_message = sprintf(__('Checkout failed for customer %s: ', 'wp-ultimo'), $membership_id); @@ -2379,14 +2171,16 @@ class Checkout { wu_log_add('checkout', $log_message, LogLevel::ERROR); - return new \WP_Error('error', $e->getMessage(), array( - 'trace' => $e->getTrace(), - 'payment' => $payment, - )); - - } // end try; - - } // end process_checkout; + return new \WP_Error( + 'error', + $e->getMessage(), + array( + 'trace' => $e->getTrace(), + 'payment' => $payment, + ) + ); + } + } /** * Handle user display names, if first and last names are available. @@ -2403,14 +2197,11 @@ class Checkout { $last_name = $this->request_or_session('last_name', ''); if ($first_name || $last_name) { - $display_name = trim("$first_name $last_name"); - - } // end if; + } return $display_name; - - } // end handle_display_name; + } /* * Helper methods @@ -2429,8 +2220,7 @@ class Checkout { public function get_thank_you_page() { return wu_get_current_url(); - - } // end get_thank_you_page; + } /** * Checks if the user already exists. @@ -2441,8 +2231,7 @@ class Checkout { public function is_existing_user() { return is_user_logged_in(); - - } // end is_existing_user; + } /** * Returns the customer email verification status we want to use depending on the type of checkout. @@ -2455,8 +2244,7 @@ class Checkout { $should_confirm_email = wu_get_setting('enable_email_verification', true); return $this->order->should_collect_payment() === false && $should_confirm_email ? 'pending' : 'none'; - - } // end get_customer_email_verification_status; + } /** * Adds the checkout scripts. @@ -2481,8 +2269,7 @@ class Checkout { wp_localize_script('wu-checkout', 'wu_checkout', $this->get_checkout_variables()); wp_enqueue_script('wu-checkout'); - - } // end register_scripts; + } /** * Gets the info either from the request or session. @@ -2502,22 +2289,17 @@ class Checkout { $value = $default; if ($this->session !== null) { - $session = $this->session->get('signup'); - if (isset($session[$key])) { - - $value = $session[$key]; - - } // end if; - - } // end if; + if (isset($session[ $key ])) { + $value = $session[ $key ]; + } + } $value = wu_request($key, $value); return $value; - - } // end request_or_session; + } /** * Returns the name of the next step on the flow. @@ -2539,16 +2321,13 @@ class Checkout { * so we need to set it to the first. */ if ($current_step_index === false) { - $current_step_index = 0; - - } // end if; + } $index = $current_step_index + 1; - return isset($keys[$index]) ? $keys[$index] : $keys[$current_step_index]; - - } // end get_next_step_name; + return isset($keys[ $index ]) ? $keys[ $index ] : $keys[ $current_step_index ]; + } /** * Checks if we are in the first step of the signup. @@ -2561,14 +2340,11 @@ class Checkout { $step_names = array_column($this->steps, 'id'); if (empty($step_names)) { - return true; - - } // end if; + } return $this->step_name === array_shift($step_names); - - } // end is_first_step; + } /** * Checks if we are in the last step of the signup. @@ -2596,22 +2372,17 @@ class Checkout { * you need to add the ?pre-flight to the action URL. */ if (wu_request('pre-flight')) { - return false; - - } // end if; + } $step_names = array_column($this->steps, 'id'); if (empty($step_names)) { - return true; - - } // end if; + } return $this->step_name === array_pop($step_names); - - } // end is_last_step; + } /** * Decides if we should display errors on the checkout screen. @@ -2622,11 +2393,7 @@ class Checkout { public function maybe_display_checkout_errors() { if (wu_request('status') !== 'error') { - return; - - } // end if; - - } // end maybe_display_checkout_errors; - -} // end class Checkout; + } + } +} diff --git a/inc/checkout/class-legacy-checkout.php b/inc/checkout/class-legacy-checkout.php index 2f01fc3..20f48c8 100644 --- a/inc/checkout/class-legacy-checkout.php +++ b/inc/checkout/class-legacy-checkout.php @@ -111,7 +111,7 @@ class Legacy_Checkout { // template assigned and return it's path add_filter('template_include', array($this, 'view_legacy_template')); - } // end init; + } /** * Adds our page templates to the page template dropdown. @@ -127,11 +127,11 @@ class Legacy_Checkout { $posts_templates = array_merge($posts_templates, $this->templates); - } // end if; + } return $posts_templates; - } // end add_new_template; + } /** * Adds our template to the pages cache in order to trick WordPress @@ -155,7 +155,7 @@ class Legacy_Checkout { $templates = array(); - } // end if; + } // New cache, therefore remove the old one wp_cache_delete($cache_key, 'themes'); @@ -170,7 +170,7 @@ class Legacy_Checkout { return $atts; - } // end register_legacy_templates; + } /** * Checks if our custom template is assigned to the page and display it. @@ -187,7 +187,7 @@ class Legacy_Checkout { return $template; - } // end if; + } // Get global post global $post, $signup; @@ -197,7 +197,7 @@ class Legacy_Checkout { return $template; - } // end if; + } $template_slug = get_post_meta($post->ID, '_wp_page_template', true); @@ -206,7 +206,7 @@ class Legacy_Checkout { return $template; - } // end if; + } $file = wu_path("views/legacy/signup/$template_slug"); @@ -215,12 +215,12 @@ class Legacy_Checkout { return $file; - } // end if; + } // Return template return $template; - } // end view_legacy_template; + } /** * Loads the necessary scripts. @@ -251,11 +251,11 @@ class Legacy_Checkout { wp_enqueue_style('login'); - } // end if; + } wp_enqueue_style('common'); - } // end register_scripts; + } /** * Adds the additional dynamic styles. @@ -298,8 +298,7 @@ class Legacy_Checkout { // phpcs:enable return ob_get_clean(); - - } // end get_legacy_dynamic_styles; + } /** * Checks if we should pre-fill checkout fields based on the request. @@ -319,7 +318,6 @@ class Legacy_Checkout { $page_name = isset($request['pagename']) ? $request['pagename'] : ''; if (strncmp((string) $page_name, $checkout_page_slug, strlen($checkout_page_slug)) === 0) { - $page = explode('/', (string) $page_name); /** @@ -328,24 +326,20 @@ class Legacy_Checkout { * @todo needs to check for frequency and unit. */ if (isset($page[1])) { - $product_slug = $page[1]; $product = wu_get_product_by_slug($product_slug); $this->product = $product; - - } // end if; + } $request['pagename'] = $checkout_page_slug; return $this->legacy_signup(); - - } // end if; + } return $request; - - } // end maybe_render_legacy_signup; + } /** * Renders the legacy checkout. @@ -369,13 +363,15 @@ class Legacy_Checkout { $this->handle_post(); - wu_get_template('legacy/signup/signup-main', array( - 'signup' => $this, - )); + wu_get_template( + 'legacy/signup/signup-main', + array( + 'signup' => $this, + ) + ); exit; - - } // end legacy_signup; + } /** * Check Geolocation @@ -391,16 +387,11 @@ class Legacy_Checkout { $allowed_countries = wu_get_setting('allowed_countries'); if (isset($location['country']) && $location['country'] && $allowed_countries) { - - if (!in_array($location['country'], $allowed_countries, true)) { - + if ( ! in_array($location['country'], $allowed_countries, true)) { wp_die(apply_filters('wu_geolocation_error_message', __('Sorry. Our service is not allowed in your country.', 'wp-ultimo'))); - - } // end if; - - } // end if; - - } // end check_geolocation; + } + } + } /** * Gets the info for the current step. @@ -410,9 +401,8 @@ class Legacy_Checkout { */ protected function get_current_step_info() { - return $this->steps[$this->step]; - - } // end get_current_step_info; + return $this->steps[ $this->step ]; + } /** * Handles a post submission. @@ -433,23 +423,17 @@ class Legacy_Checkout { /** Checks if the view has a handler of its own */ if (isset($current_step['handler']) && $current_step['handler']) { - $handler_function = $current_step['handler']; - } else { - $handler_function = array($this, 'default_save'); - - } // end if; + } /** Allows for handler rewrite */ $handler_function = apply_filters("wu_signup_step_handler_$this->step", $handler_function); call_user_func($handler_function); - - } // end if; - - } // end handle_post; + } + } /** * The first invisible step, handles the creation of the transient saver @@ -479,19 +463,16 @@ class Legacy_Checkout { // Adds to the payload $content['coupon'] = $_REQUEST['coupon']; - - } // end if; + } /** * Check if user came from a pricing select table */ if (isset($_REQUEST['plan_id']) && isset($_REQUEST['plan_freq']) && WU_Gateway::check_frequency($_REQUEST['plan_freq'])) { - $content['plan_id'] = $_REQUEST['plan_id']; $content['plan_freq'] = $_REQUEST['plan_freq']; $content['skip_plan'] = true; - - } // end if; + } /** * Check if we only have one plan and the skip_plan enabled @@ -500,7 +481,6 @@ class Legacy_Checkout { $plans = wu_get_plans(); if (wu_get_setting('skip_plan', false) && count($plans) === 1) { - $billing_frequency = wu_get_setting('default_pricing_option', 1); $plan = reset($plans); @@ -511,34 +491,29 @@ class Legacy_Checkout { $content['skip_plan'] = true; $_REQUEST['skip_plan'] = 1; - - } // end if; + } /** * Check if we are settings the template via the URL - * + * * @since 1.7.3 */ if (isset($_REQUEST['template_id']) && wu_get_setting('allow_template')) { // Check if the template is valid - $site = new WU_Site_Template( $_REQUEST['template_id'] ); + $site = new WU_Site_Template($_REQUEST['template_id']); if ($site->is_template) { - $content['template'] = $_REQUEST['template_id']; $content['skip_template_selection'] = true; - - } // end if; - - } // end if; + } + } $this->session->set('form', $content); /** Go to the next step */ $this->next_step(); - - } // end begin_signup; + } /** * Check if the current page is a customizer page. */ @@ -547,18 +522,13 @@ class Legacy_Checkout { $exclude_list = apply_filters('wu_replace_signup_urls_exclude', array('wu-signup-customizer-preview')); foreach ($exclude_list as $replace_word) { - - if (isset($_GET[$replace_word])) { - + if (isset($_GET[ $replace_word ])) { return true; - - } // end if; - - } // end foreach; + } + } return false; - - } // end is_customizer; + } /** * Returns the first step of the signup process @@ -570,16 +540,11 @@ class Legacy_Checkout { $keys = array_keys($this->get_steps()); if (isset($keys[1])) { - return $keys[1]; - } else { - return false; - - } // end if; - - } // end get_first_step; + } + } /** * Get the current step @@ -592,14 +557,11 @@ class Legacy_Checkout { // Always get the first step for the customizer // if ($this->is_customizer()) { - $current_step = $this->get_first_step(); - - } // end if; + } return apply_filters('wu_current_step', $current_step); - - } // end get_current_step; + } /** * Includes the template for that particular step; If none is set (false), includes the default template @@ -616,16 +578,12 @@ class Legacy_Checkout { * Set the errors */ if ($this->results === null) { - - $this->results = array('errors' => new \WP_Error); - - } // end if; + $this->results = array('errors' => new \WP_Error()); + } if (empty($_POST)) { - $this->results = array_merge($this->results, $transient); - - } // end if; + } /** * Builds the array containing the available elements inside the template @@ -633,37 +591,28 @@ class Legacy_Checkout { $args = array( 'signup' => $this, 'transient' => $transient, - 'fields' => isset($this->steps[$step]['fields']) ? $this->steps[$step]['fields'] : array(), + 'fields' => isset($this->steps[ $step ]['fields']) ? $this->steps[ $step ]['fields'] : array(), 'results' => $this->results, ); /** * Checks if anything is passed to the view element */ - if (isset($this->steps[$step]['view']) && $this->steps[$step]['view']) { - - wu_get_template('legacy/signup/steps/' . $this->steps[$step]['view'], $args); - + if (isset($this->steps[ $step ]['view']) && $this->steps[ $step ]['view']) { + wu_get_template('legacy/signup/steps/' . $this->steps[ $step ]['view'], $args); } else { - $found = locate_template("wp-ultimo/signup/steps/step-$step.php"); /** * Let's try to locate a custom template on the user's theme. If it's there, we use it instead */ if ($found) { - wu_get_template("legacy/signup/steps/step-$step", $args); - } else { - wu_get_template('legacy/signup/steps/step-default', $args); - - } // end if; - - } // end if; - - } // end get_step_view; + } + } + } /** * Set and return the steps and fields of each step. @@ -696,7 +645,6 @@ class Legacy_Checkout { // We add template selection if this has template if ($site_templates) { - $steps['template'] = array( 'name' => __('Template Selection', 'wp-ultimo'), 'desc' => __('Select the base template of your new site.', 'wp-ultimo'), @@ -705,8 +653,7 @@ class Legacy_Checkout { 'handler' => false, 'core' => true, ); - - } // end if; + } // Domain registering $steps['domain'] = array( @@ -716,40 +663,43 @@ class Legacy_Checkout { 'view' => false, 'order' => 30, 'core' => true, - 'fields' => apply_filters('wu_signup_fields_domain', array( - 'blog_title' => array( - 'order' => 10, - 'name' => apply_filters('wu_signup_site_title_label', __('Site Title', 'wp-ultimo')), - 'type' => 'text', - 'default' => '', - 'placeholder' => '', - 'tooltip' => apply_filters('wu_signup_site_title_tooltip', __('Select the title your site is going to have.', 'wp-ultimo')), - 'required' => true, - 'core' => true, - ), - 'blogname' => array( - 'order' => 20, - 'name' => apply_filters('wu_signup_site_url_label', __('URL', 'wp-ultimo')), - 'type' => 'text', - 'default' => '', - 'placeholder' => '', - 'tooltip' => apply_filters('wu_signup_site_url_tooltip', __('Site urls can only contain lowercase letters (a-z) and numbers and must be at least 4 characters. .', 'wp-ultimo')), - 'required' => true, - 'core' => true, - ), - 'url_preview' => array( - 'order' => 30, - 'name' => __('Site URL Preview', 'wp-ultimo'), - 'type' => 'html', - 'content' => wu_get_template_contents('legacy/signup/steps/step-domain-url-preview'), - ), - 'submit' => array( - 'order' => 100, - 'type' => 'submit', - 'name' => __('Continue to the next step', 'wp-ultimo'), - 'core' => true, - ), - )), + 'fields' => apply_filters( + 'wu_signup_fields_domain', + array( + 'blog_title' => array( + 'order' => 10, + 'name' => apply_filters('wu_signup_site_title_label', __('Site Title', 'wp-ultimo')), + 'type' => 'text', + 'default' => '', + 'placeholder' => '', + 'tooltip' => apply_filters('wu_signup_site_title_tooltip', __('Select the title your site is going to have.', 'wp-ultimo')), + 'required' => true, + 'core' => true, + ), + 'blogname' => array( + 'order' => 20, + 'name' => apply_filters('wu_signup_site_url_label', __('URL', 'wp-ultimo')), + 'type' => 'text', + 'default' => '', + 'placeholder' => '', + 'tooltip' => apply_filters('wu_signup_site_url_tooltip', __('Site urls can only contain lowercase letters (a-z) and numbers and must be at least 4 characters. .', 'wp-ultimo')), + 'required' => true, + 'core' => true, + ), + 'url_preview' => array( + 'order' => 30, + 'name' => __('Site URL Preview', 'wp-ultimo'), + 'type' => 'html', + 'content' => wu_get_template_contents('legacy/signup/steps/step-domain-url-preview'), + ), + 'submit' => array( + 'order' => 100, + 'type' => 'submit', + 'name' => __('Continue to the next step', 'wp-ultimo'), + 'core' => true, + ), + ) + ), ); /** @@ -818,14 +768,14 @@ class Legacy_Checkout { ), 'attributes' => array( 'autocomplete' => 'nope', - ) + ), ), - ); // end first account fields; + ); /** * Check and Add Coupon Code Fields - * + * * @since 1.4.0 */ // if (wu_get_setting('enable_coupon_codes', 'url_and_field') == 'url_and_field') { @@ -851,7 +801,7 @@ class Legacy_Checkout { // 'requires' => array('has_coupon' => true), // 'core' => true, // ); - // } // end if; + // } // /** // * Check and Add the Terms field // * @since 1.0.4 @@ -864,7 +814,7 @@ class Legacy_Checkout { // 'name' => sprintf(__('I agree with the Terms of Service', 'wp-ultimo'), $this->get_terms_url()), // 'core' => true, // ); - // } // end if; + // } /** * Submit Field @@ -896,23 +846,23 @@ class Legacy_Checkout { // Sorts each of the fields block foreach ($steps as &$step) { - - $step = wp_parse_args($step, array( - 'hidden' => false, - )); + $step = wp_parse_args( + $step, + array( + 'hidden' => false, + ) + ); if (isset($step['fields']) && is_array($step['fields'])) { // Sort elements based on their order uasort($step['fields'], array($this, 'sort_steps_and_fields')); - - } // end if; - - } // end foreach; + } + } /** * Adds the hidden step now responsible for validating data entry and the actual account creation - * + * * @since 1.4.0 */ $begin_signup = array( @@ -928,7 +878,7 @@ class Legacy_Checkout { /** * Adds the hidden step now responsible for validating data entry and the actual account creation - * + * * @since 1.4.0 */ $create_account = array( @@ -949,25 +899,20 @@ class Legacy_Checkout { /** * Filter the hidden ones, if we need to... - * + * * @var array */ - if (!$include_hidden) { - - $steps = array_filter($steps, fn($step) => !(isset($step['hidden']) && $step['hidden'])); - - } // end if; + if ( ! $include_hidden) { + $steps = array_filter($steps, fn($step) => ! (isset($step['hidden']) && $step['hidden'])); + } // If we need to add that - if (!$this->has_plan_step()) { - + if ( ! $this->has_plan_step()) { unset($steps['plan']); - - } // end if; + } return $steps; - - } // end get_steps; + } /** * Check the transient, and if it does not exists, throw fatal @@ -978,32 +923,24 @@ class Legacy_Checkout { public static function get_transient($die = true) { if (self::is_customizer()) { - $transient = array( 'not-empty' => '', ); - } else { - $transient = wu_get_session('signup')->get('form'); - - } // end if; + } if ($die && empty($transient)) { // wp_die(__('Try again', 'wp-ultimo')); - - } // end if; + } if (is_null($transient)) { - return array(); - - } // end if; + } return $transient; - - } // end get_transient; + } /** * Update the transient data in out database @@ -1015,8 +952,7 @@ class Legacy_Checkout { $this->session->set('form', $transient); $this->session->commit(); - - } // end update_transient; + } /** * Checks transient data to see if the plan step is necessary */ @@ -1025,14 +961,11 @@ class Legacy_Checkout { $transient = $this->get_transient(); if (isset($transient['skip_plan']) && isset($transient['plan_id']) && isset($transient['plan_freq'])) { - return false; - - } // end if; + } return true; - - } // end has_plan_step; + } /** * Get the link for the next step @@ -1044,57 +977,42 @@ class Legacy_Checkout { // Add CS if (isset($_GET['cs'])) { - $params['cs'] = $_GET['cs']; - - } // end if; + } if (isset($_REQUEST['customized'])) { - $params['customized'] = $_REQUEST['customized']; - - } // end if; + } if (isset($_REQUEST['skip_plan']) && $_REQUEST['skip_plan'] == 1) { - unset($this->steps['plan']); unset($params['skip_plan']); - - } // end if; + } if (isset($_REQUEST['template_id'])) { - $plan = false; if (isset($_REQUEST['plan_id'])) { - $plan = wu_get_plan($_REQUEST['plan_id']); - - } // end if; + } $templates = array_keys((array) wu_get_setting('templates')); if ( ($plan && $plan->is_template_available($_REQUEST['template_id'])) || in_array($_REQUEST['template_id'], $templates)) { - unset($this->steps['template']); unset($params['skip_template_selection']); - - } // end if; - - } // end if; + } + } $keys = array_keys($this->steps); $url = add_query_arg('step', $keys[ array_search($this->step, array_keys($this->steps)) + 1 ]); foreach ($params as $param => $value) { - $url = add_query_arg($param, $value, $url); - - } // end foreach; + } return $url; - - } // end get_next_step_link; + } /** * Redirects the user to the next step on the signup flow @@ -1105,12 +1023,11 @@ class Legacy_Checkout { public function next_step($args = array()) { /** Redirect the user to the next step */ - wp_redirect(esc_url_raw($this->get_next_step_link( $args ))); + wp_redirect(esc_url_raw($this->get_next_step_link($args))); /** Kill the execution after the redirect */ exit; - - } // end next_step; + } /** * Get the link for the previous step @@ -1122,38 +1039,29 @@ class Legacy_Checkout { // Add CS if (isset($_GET['cs'])) { - $params['cs'] = $_GET['cs']; - - } // end if; + } if (isset($_REQUEST['customized'])) { - $params['customized'] = $_REQUEST['customized']; - - } // end if; + } $keys = array_keys($this->steps); $search_key = array_search($this->step, array_keys($this->steps)) - 1 >= 0 ? array_search($this->step, array_keys($this->steps)) - 1 : false; - $key = $search_key === false ? '' : $keys[$search_key]; - - if (!$key || $key == 'begin-signup') { + $key = $search_key === false ? '' : $keys[ $search_key ]; + if ( ! $key || $key == 'begin-signup') { return false; - - } // end if; + } $url = add_query_arg('step', $key); foreach ($params as $param => $value) { - $url = add_query_arg($param, $value, $url); - - } // end foreach; + } return $url; - - } // end get_prev_step_link; + } /** * Sorts the steps. @@ -1169,8 +1077,7 @@ class Legacy_Checkout { $b['order'] = isset($b['order']) ? (int) $b['order'] : 50; return $a['order'] - $b['order']; - - } // end sort_steps_and_fields; + } /** * Display the necessary fields for the plan template @@ -1191,11 +1098,11 @@ class Legacy_Checkout { - - + + @@ -1205,13 +1112,12 @@ class Legacy_Checkout { - + -domain; if (wu_get_setting('enable_multiple_domains', false) && $domain_options) { - $domain = array_shift($domain_options); - - } // end if; + } $domain = rtrim($domain . $site->path, '/'); @@ -1244,8 +1148,7 @@ class Legacy_Checkout { * @return string New domain to be used */ return apply_filters('get_site_url_for_previewer', $domain, $domain_options); // phpcs:ignore - - } // end get_site_url_for_previewer; + } /** * We pass the following info @@ -1259,19 +1162,19 @@ class Legacy_Checkout { check_admin_referer('signup_form_1', '_signup_form'); // Errors - $this->results['errors'] = new \WP_Error; + $this->results['errors'] = new \WP_Error(); // We need now to check for plan - if (!isset($_POST['plan_id'])) { + if ( ! isset($_POST['plan_id'])) { $this->results['errors']->add('plan_id', __('You don\'t have any plan selected.', 'wp-ultimo')); } else { // We need now to check if the plan exists $plan = wu_get_product($_POST['plan_id']); - if (!$plan->exists()) { + if ( ! $plan->exists()) { $this->results['errors']->add('plan_id', __('The plan you\'ve selected doesn\'t exist.', 'wp-ultimo')); - } // end if; - } // end if; + } + } $transient = apply_filters('wp_ultimo_registration_step_plans_save_transient', $transient); @@ -1281,7 +1184,7 @@ class Legacy_Checkout { // Stay on the form if we get any errors if ($this->results['errors']->get_error_code()) { return; - } // end if; + } /** Update Transient Content */ $transient['plan_freq'] = $_POST['plan_freq']; @@ -1292,8 +1195,7 @@ class Legacy_Checkout { /** Go to the next step */ $this->next_step(); - - } // end plans_save; + } /** * Personal Info Settings. @@ -1324,20 +1226,17 @@ class Legacy_Checkout { // Stay on the form if we get any errors if ($this->results['errors']->get_error_code()) { - $this->results = array_merge($this->results, $_POST); return; - - } // end if; + } // Re-saves the transient $this->update_transient($transient); /** Go to the next step */ $this->next_step(); - - } // end domain_save; + } /** * Filters the input variables and sanitizes its contents @@ -1351,14 +1250,13 @@ class Legacy_Checkout { $exclude_list = $exclude_list ? $exclude_list : array('_signup_form', '_wp_http_referer'); /** Filter Array */ - $post = $this->array_filter_key($post, fn($element_key) => !in_array($element_key, $exclude_list, true)); + $post = $this->array_filter_key($post, fn($element_key) => ! in_array($element_key, $exclude_list, true)); /** Sanitizes the input */ $post = array_map(fn($element) => sanitize_text_field($element), $post); return $post; - - } // end filter_post_array; + } /** * Helper function to filter based on key. * @@ -1369,11 +1267,10 @@ class Legacy_Checkout { */ public function array_filter_key(array $array, $callback): array { - $matched_keys = array_filter(array_keys($array), $callback === null ? fn($v, $k): bool => !empty($v) : $callback, $callback === null ? ARRAY_FILTER_USE_BOTH : 0); + $matched_keys = array_filter(array_keys($array), $callback === null ? fn($v, $k): bool => ! empty($v) : $callback, $callback === null ? ARRAY_FILTER_USE_BOTH : 0); return array_intersect_key($array, array_flip($matched_keys)); - - } // end array_filter_key; + } /** * Get the active until + trial days, to allow for putting subscription on hold * @@ -1388,8 +1285,7 @@ class Legacy_Checkout { $active_until->add(new \DateInterval('P' . $trial_days . 'D')); return $active_until->format('Y-m-d H:i:s'); - - } // end get_active_until_with_trial; + } /** * Adds a new Step to the sign-up flow @@ -1402,21 +1298,22 @@ class Legacy_Checkout { */ public function add_signup_step($id, $order, $step) { - add_filter('wp_ultimo_registration_steps', function($steps) use ($id, $order, $step) { + add_filter( + 'wp_ultimo_registration_steps', + function ($steps) use ($id, $order, $step) { - // Save new order - $step['order'] = $order; + // Save new order + $step['order'] = $order; - // mark as not core - $step['core'] = false; + // mark as not core + $step['core'] = false; - $steps[$id] = $step; + $steps[ $id ] = $step; - return $steps; - - }); - - } // end add_signup_step; + return $steps; + } + ); + } /** * Adds a new field to a step the sign-up flow @@ -1430,27 +1327,25 @@ class Legacy_Checkout { */ public function add_signup_field($step, $id, $order, $field) { - add_filter('wp_ultimo_registration_steps', function($steps) use ($step, $id, $order, $field) { + add_filter( + 'wp_ultimo_registration_steps', + function ($steps) use ($step, $id, $order, $field) { - // Checks for honey-trap id - if ($id === 'site_url') { + // Checks for honey-trap id + if ($id === 'site_url') { + wp_die(__('Please, do not use the "site_url" as one of your custom fields\' ids. We use it as a honeytrap field to prevent spam registration. Consider alternatives such as "url" or "website".', 'wp-ultimo')); + } - wp_die(__('Please, do not use the "site_url" as one of your custom fields\' ids. We use it as a honeytrap field to prevent spam registration. Consider alternatives such as "url" or "website".', 'wp-ultimo')); + // Saves the order + $field['order'] = $order; - } // end if; + // mark as not core + $field['core'] = false; - // Saves the order - $field['order'] = $order; + $steps[ $step ]['fields'][ $id ] = $field; - // mark as not core - $field['core'] = false; - - $steps[$step]['fields'][$id] = $field; - - return $steps; - - }); - - } // end add_signup_field; - -} // end class Legacy_Checkout; + return $steps; + } + ); + } +} diff --git a/inc/checkout/class-line-item.php b/inc/checkout/class-line-item.php index 46163db..e7487f4 100644 --- a/inc/checkout/class-line-item.php +++ b/inc/checkout/class-line-item.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-base-signup-field.php b/inc/checkout/signup-fields/class-base-signup-field.php index 1eca1ad..738d2f5 100644 --- a/inc/checkout/signup-fields/class-base-signup-field.php +++ b/inc/checkout/signup-fields/class-base-signup-field.php @@ -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('
%s
', __('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('
%s
', __('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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-billing-address.php b/inc/checkout/signup-fields/class-signup-field-billing-address.php index cfc8b03..c80c161 100644 --- a/inc/checkout/signup-fields/class-signup-field-billing-address.php +++ b/inc/checkout/signup-fields/class-signup-field-billing-address.php @@ -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('', $data_key_name); + ', + $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('%s', "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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-checkbox.php b/inc/checkout/signup-fields/class-signup-field-checkbox.php index 5477929..ef12f82 100644 --- a/inc/checkout/signup-fields/class-signup-field-checkbox.php +++ b/inc/checkout/signup-fields/class-signup-field-checkbox.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-color.php b/inc/checkout/signup-fields/class-signup-field-color.php index 5283942..d2e4ffb 100644 --- a/inc/checkout/signup-fields/class-signup-field-color.php +++ b/inc/checkout/signup-fields/class-signup-field-color.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-discount-code.php b/inc/checkout/signup-fields/class-signup-field-discount-code.php index db400d7..1e7a623 100644 --- a/inc/checkout/signup-fields/class-signup-field-discount-code.php +++ b/inc/checkout/signup-fields/class-signup-field-discount-code.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-email.php b/inc/checkout/signup-fields/class-signup-field-email.php index c0b6922..59d01b1 100644 --- a/inc/checkout/signup-fields/class-signup-field-email.php +++ b/inc/checkout/signup-fields/class-signup-field-email.php @@ -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 { 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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-order-bump.php b/inc/checkout/signup-fields/class-signup-field-order-bump.php index dabe24a..44ef87a 100644 --- a/inc/checkout/signup-fields/class-signup-field-order-bump.php +++ b/inc/checkout/signup-fields/class-signup-field-order-bump.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-order-summary.php b/inc/checkout/signup-fields/class-signup-field-order-summary.php index 0f18672..dc16bc8 100644 --- a/inc/checkout/signup-fields/class-signup-field-order-summary.php +++ b/inc/checkout/signup-fields/class-signup-field-order-summary.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-password.php b/inc/checkout/signup-fields/class-signup-field-password.php index 7a35bf2..f3d0c87 100644 --- a/inc/checkout/signup-fields/class-signup-field-password.php +++ b/inc/checkout/signup-fields/class-signup-field-password.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-payment.php b/inc/checkout/signup-fields/class-signup-field-payment.php index 855dcd3..9f6fb48 100644 --- a/inc/checkout/signup-fields/class-signup-field-payment.php +++ b/inc/checkout/signup-fields/class-signup-field-payment.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-period-selection.php b/inc/checkout/signup-fields/class-signup-field-period-selection.php index ba49ba1..7ea5cca 100644 --- a/inc/checkout/signup-fields/class-signup-field-period-selection.php +++ b/inc/checkout/signup-fields/class-signup-field-period-selection.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-pricing-table.php b/inc/checkout/signup-fields/class-signup-field-pricing-table.php index e9ed328..e4c6817 100644 --- a/inc/checkout/signup-fields/class-signup-field-pricing-table.php +++ b/inc/checkout/signup-fields/class-signup-field-pricing-table.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-products.php b/inc/checkout/signup-fields/class-signup-field-products.php index f5a8cc5..d4177ac 100644 --- a/inc/checkout/signup-fields/class-signup-field-products.php +++ b/inc/checkout/signup-fields/class-signup-field-products.php @@ -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 + ); + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-select.php b/inc/checkout/signup-fields/class-signup-field-select.php index c8985cf..29fd1de 100644 --- a/inc/checkout/signup-fields/class-signup-field-select.php +++ b/inc/checkout/signup-fields/class-signup-field-select.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-shortcode.php b/inc/checkout/signup-fields/class-signup-field-shortcode.php index 1ac5906..49e497d 100644 --- a/inc/checkout/signup-fields/class-signup-field-shortcode.php +++ b/inc/checkout/signup-fields/class-signup-field-shortcode.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-site-title.php b/inc/checkout/signup-fields/class-signup-field-site-title.php index 089a927..528f655 100644 --- a/inc/checkout/signup-fields/class-signup-field-site-title.php +++ b/inc/checkout/signup-fields/class-signup-field-site-title.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-site-url.php b/inc/checkout/signup-fields/class-signup-field-site-url.php index a642571..a059668 100644 --- a/inc/checkout/signup-fields/class-signup-field-site-url.php +++ b/inc/checkout/signup-fields/class-signup-field-site-url.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-steps.php b/inc/checkout/signup-fields/class-signup-field-steps.php index dfb14c3..374ce08 100644 --- a/inc/checkout/signup-fields/class-signup-field-steps.php +++ b/inc/checkout/signup-fields/class-signup-field-steps.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-submit-button.php b/inc/checkout/signup-fields/class-signup-field-submit-button.php index 96573c6..f4214c6 100644 --- a/inc/checkout/signup-fields/class-signup-field-submit-button.php +++ b/inc/checkout/signup-fields/class-signup-field-submit-button.php @@ -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' => __('← 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' => '', @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-template-selection.php b/inc/checkout/signup-fields/class-signup-field-template-selection.php index c6dacd7..0b2b054 100644 --- a/inc/checkout/signup-fields/class-signup-field-template-selection.php +++ b/inc/checkout/signup-fields/class-signup-field-template-selection.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-terms-of-use.php b/inc/checkout/signup-fields/class-signup-field-terms-of-use.php index d6ca43e..c0204e5 100644 --- a/inc/checkout/signup-fields/class-signup-field-terms-of-use.php +++ b/inc/checkout/signup-fields/class-signup-field-terms-of-use.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-text.php b/inc/checkout/signup-fields/class-signup-field-text.php index 5e91b06..1ce3760 100644 --- a/inc/checkout/signup-fields/class-signup-field-text.php +++ b/inc/checkout/signup-fields/class-signup-field-text.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/class-signup-field-username.php b/inc/checkout/signup-fields/class-signup-field-username.php index 70703fe..ac0e4cc 100644 --- a/inc/checkout/signup-fields/class-signup-field-username.php +++ b/inc/checkout/signup-fields/class-signup-field-username.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/field-templates/class-base-field-template.php b/inc/checkout/signup-fields/field-templates/class-base-field-template.php index f498630..eb8207b 100644 --- a/inc/checkout/signup-fields/field-templates/class-base-field-template.php +++ b/inc/checkout/signup-fields/field-templates/class-base-field-template.php @@ -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('', 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; + } +} diff --git a/inc/checkout/signup-fields/field-templates/order-bump/class-simple-order-bump-field-template.php b/inc/checkout/signup-fields/field-templates/order-bump/class-simple-order-bump-field-template.php index 6882ba4..80d8590 100644 --- a/inc/checkout/signup-fields/field-templates/order-bump/class-simple-order-bump-field-template.php +++ b/inc/checkout/signup-fields/field-templates/order-bump/class-simple-order-bump-field-template.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/field-templates/order-summary/class-clean-order-summary-field-template.php b/inc/checkout/signup-fields/field-templates/order-summary/class-clean-order-summary-field-template.php index bfd85d2..34e411d 100644 --- a/inc/checkout/signup-fields/field-templates/order-summary/class-clean-order-summary-field-template.php +++ b/inc/checkout/signup-fields/field-templates/order-summary/class-clean-order-summary-field-template.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/field-templates/period-selection/class-clean-period-selection-field-template.php b/inc/checkout/signup-fields/field-templates/period-selection/class-clean-period-selection-field-template.php index 4bdf6a9..b2ec553 100644 --- a/inc/checkout/signup-fields/field-templates/period-selection/class-clean-period-selection-field-template.php +++ b/inc/checkout/signup-fields/field-templates/period-selection/class-clean-period-selection-field-template.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/field-templates/period-selection/class-legacy-period-selection-field-template.php b/inc/checkout/signup-fields/field-templates/period-selection/class-legacy-period-selection-field-template.php index 946fbc9..77441b9 100644 --- a/inc/checkout/signup-fields/field-templates/period-selection/class-legacy-period-selection-field-template.php +++ b/inc/checkout/signup-fields/field-templates/period-selection/class-legacy-period-selection-field-template.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/field-templates/pricing-table/class-legacy-pricing-table-field-template.php b/inc/checkout/signup-fields/field-templates/pricing-table/class-legacy-pricing-table-field-template.php index 682f202..3fddec6 100644 --- a/inc/checkout/signup-fields/field-templates/pricing-table/class-legacy-pricing-table-field-template.php +++ b/inc/checkout/signup-fields/field-templates/pricing-table/class-legacy-pricing-table-field-template.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/field-templates/pricing-table/class-list-pricing-table-field-template.php b/inc/checkout/signup-fields/field-templates/pricing-table/class-list-pricing-table-field-template.php index c50b360..af5a121 100644 --- a/inc/checkout/signup-fields/field-templates/pricing-table/class-list-pricing-table-field-template.php +++ b/inc/checkout/signup-fields/field-templates/pricing-table/class-list-pricing-table-field-template.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/field-templates/steps/class-clean-steps-field-template.php b/inc/checkout/signup-fields/field-templates/steps/class-clean-steps-field-template.php index 741580e..5eb2beb 100644 --- a/inc/checkout/signup-fields/field-templates/steps/class-clean-steps-field-template.php +++ b/inc/checkout/signup-fields/field-templates/steps/class-clean-steps-field-template.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/field-templates/steps/class-legacy-steps-field-template.php b/inc/checkout/signup-fields/field-templates/steps/class-legacy-steps-field-template.php index edd605b..fddfaf5 100644 --- a/inc/checkout/signup-fields/field-templates/steps/class-legacy-steps-field-template.php +++ b/inc/checkout/signup-fields/field-templates/steps/class-legacy-steps-field-template.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/field-templates/steps/class-minimal-steps-field-template.php b/inc/checkout/signup-fields/field-templates/steps/class-minimal-steps-field-template.php index 5755a28..939b7cd 100644 --- a/inc/checkout/signup-fields/field-templates/steps/class-minimal-steps-field-template.php +++ b/inc/checkout/signup-fields/field-templates/steps/class-minimal-steps-field-template.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/field-templates/template-selection/class-clean-template-selection-field-template.php b/inc/checkout/signup-fields/field-templates/template-selection/class-clean-template-selection-field-template.php index 10eb475..d882a61 100644 --- a/inc/checkout/signup-fields/field-templates/template-selection/class-clean-template-selection-field-template.php +++ b/inc/checkout/signup-fields/field-templates/template-selection/class-clean-template-selection-field-template.php @@ -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; + } +} diff --git a/inc/checkout/signup-fields/field-templates/template-selection/class-legacy-template-selection-field-template.php b/inc/checkout/signup-fields/field-templates/template-selection/class-legacy-template-selection-field-template.php index 9e21eeb..3623c2f 100644 --- a/inc/checkout/signup-fields/field-templates/template-selection/class-legacy-template-selection-field-template.php +++ b/inc/checkout/signup-fields/field-templates/template-selection/class-legacy-template-selection-field-template.php @@ -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; /** * Legacy Field Template Selector @@ -41,8 +41,7 @@ class Legacy_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. @@ -55,8 +54,7 @@ class Legacy_Template_Selection_Field_Template extends Base_Field_Template { public function get_title() { return __('Legacy', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the field template. @@ -69,8 +67,7 @@ class Legacy_Template_Selection_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. @@ -83,8 +80,7 @@ class Legacy_Template_Selection_Field_Template extends Base_Field_Template { public function get_preview(): string { return wu_get_asset('checkout-forms/legacy-template-selection.png'); - - } // end get_preview; + } /** * The content of the template. @@ -97,7 +93,5 @@ class Legacy_Template_Selection_Field_Template extends Base_Field_Template { public function output($attributes) { wu_get_template('checkout/templates/template-selection/legacy', $attributes); - - } // end output; - -} // end class Legacy_Template_Selection_Field_Template; + } +} diff --git a/inc/checkout/signup-fields/field-templates/template-selection/class-minimal-template-selection-field-template.php b/inc/checkout/signup-fields/field-templates/template-selection/class-minimal-template-selection-field-template.php index fdf044b..bf47de5 100644 --- a/inc/checkout/signup-fields/field-templates/template-selection/class-minimal-template-selection-field-template.php +++ b/inc/checkout/signup-fields/field-templates/template-selection/class-minimal-template-selection-field-template.php @@ -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 Minimal @@ -41,8 +41,7 @@ class Minimal_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. @@ -55,8 +54,7 @@ class Minimal_Template_Selection_Field_Template extends Base_Field_Template { public function get_title() { return __('Minimal', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the field template. @@ -69,8 +67,7 @@ class Minimal_Template_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 of the field template. @@ -81,8 +78,7 @@ class Minimal_Template_Selection_Field_Template extends Base_Field_Template { public function get_preview(): string { return wu_get_asset('checkout-forms/minimal-template-selection.png'); - - } // end get_preview; + } /** * The content of the template. @@ -95,7 +91,5 @@ class Minimal_Template_Selection_Field_Template extends Base_Field_Template { public function output($attributes) { wu_get_template('checkout/templates/template-selection/minimal', $attributes); - - } // end output; - -} // end class Minimal_Template_Selection_Field_Template; + } +} diff --git a/inc/class-admin-notices.php b/inc/class-admin-notices.php index 9086e07..bbdccae 100644 --- a/inc/class-admin-notices.php +++ b/inc/class-admin-notices.php @@ -45,8 +45,7 @@ class Admin_Notices { add_action('in_admin_header', array($this, 'display_notices')); add_action('wp_ajax_wu_dismiss_admin_notice', array($this, 'ajax_dismiss_admin_notices')); - - } // end init; + } /** * Get the notices the current user has dismissed @@ -61,8 +60,7 @@ class Admin_Notices { $dismissed = $dismissed ? $dismissed : array(); return $dismissed; - - } // end get_dismissed_notices; + } /** * Adds a new admin notice @@ -83,14 +81,13 @@ class Admin_Notices { $id = $dismissible_key ? $dismissible_key : md5($notice); - $this->notices[$panel][$id] = array( + $this->notices[ $panel ][ $id ] = array( 'type' => $type, 'message' => $notice, 'dismissible_key' => is_string($dismissible_key) ? $dismissible_key : false, 'actions' => $actions, ); - - } // end add; + } /** * Returns the list of notices added for a particular panel. @@ -103,15 +100,13 @@ class Admin_Notices { */ public function get_notices($panel = 'admin', $filter = true) { - $notices = isset($this->notices[$panel]) ? $this->notices[$panel] : array(); + $notices = isset($this->notices[ $panel ]) ? $this->notices[ $panel ] : array(); $dismissed_messages = $this->get_dismissed_notices(); if ($filter && $notices) { - - $notices = array_filter($notices, fn($notice) => !$notice['dismissible_key'] || !in_array($notice['dismissible_key'], $dismissed_messages, true)); - - } // end if; + $notices = array_filter($notices, fn($notice) => ! $notice['dismissible_key'] || ! in_array($notice['dismissible_key'], $dismissed_messages, true)); + } /** * Allow developers to filter admin notices added by WP Multisite WaaS. @@ -123,11 +118,10 @@ class Admin_Notices { * @param string $panel Panel to retrieve the notices. * @param string $filter If the dismissable notices have been filtered out. * @param array $dismissed_messages List of dismissed notice keys. - * @return array + * @return array */ return apply_filters('wu_admin_notices', $notices, $this->notices, $panel, $filter, $dismissed_messages); - - } // end get_notices; + } /** * Enqueues the JavaScript code that sends the dismiss call to the ajax endpoint. @@ -138,8 +132,7 @@ class Admin_Notices { public function enqueue_scripts() { wp_enqueue_script('wu-admin-notices', wu_get_asset('admin-notices.js', 'js'), array('jquery'), wu_get_version()); - - } // end enqueue_scripts; + } /** * Gets the current panel the user is viewing @@ -152,20 +145,15 @@ class Admin_Notices { $panel = 'admin'; if (is_user_admin()) { - $panel = 'user'; - - } // end if; + } if (is_network_admin()) { - $panel = 'network-admin'; - - } // end if; + } return $panel; - - } // end get_current_panel; + } /** * Retrieves the admin notices for the current panel and displays them. @@ -179,12 +167,14 @@ class Admin_Notices { $notices = $this->get_notices($panel); - wu_get_template('admin-notices', array( - 'notices' => $notices, - 'nonce' => wp_create_nonce('wu-dismiss-admin-notice'), - )); - - } // end display_notices; + wu_get_template( + 'admin-notices', + array( + 'notices' => $notices, + 'nonce' => wp_create_nonce('wu-dismiss-admin-notice'), + ) + ); + } /** * Adds an ajax endpoint to dismiss admin notices @@ -194,26 +184,20 @@ class Admin_Notices { */ public function ajax_dismiss_admin_notices() { - if (!wp_verify_nonce($_POST['nonce'], 'wu-dismiss-admin-notice')) { - + if ( ! wp_verify_nonce($_POST['nonce'], 'wu-dismiss-admin-notice')) { die('-1'); - - } // end if; + } $dismissed = $this->get_dismissed_notices(); - if (!in_array($_POST['notice_id'], $dismissed, true)) { - + if ( ! in_array($_POST['notice_id'], $dismissed, true)) { $dismissed[] = $_POST['notice_id']; update_user_meta(get_current_user_id(), 'wu_dismissed_admin_notices', $dismissed); die('1'); - - } // end if; + } die('0'); - - } // end ajax_dismiss_admin_notices; - -} // end class Admin_Notices; + } +} diff --git a/inc/class-admin-themes-compatibility.php b/inc/class-admin-themes-compatibility.php index 7c62330..c683bdb 100644 --- a/inc/class-admin-themes-compatibility.php +++ b/inc/class-admin-themes-compatibility.php @@ -29,8 +29,7 @@ class Admin_Themes_Compatibility { public function __construct() { add_filter('admin_body_class', array($this, 'add_body_classes')); - - } // end __construct; + } /** * Body tag classes. Fired by `body_class` filter. @@ -45,18 +44,13 @@ class Admin_Themes_Compatibility { $prefix = 'wu-compat-admin-theme-'; foreach (self::get_admin_themes() as $key => $value) { - if ($value['activated']) { - $classes .= ' ' . $prefix . $key . ' '; - - } // end if; - - } // end foreach; + } + } return $classes; - - } // end add_body_classes; + } /** * Get list of Admin Themes @@ -66,27 +60,28 @@ class Admin_Themes_Compatibility { */ public static function get_admin_themes() { - return apply_filters('wu_admin_themes_compatibility', array( - 'material-wp' => array( - 'activated' => class_exists('MaterialWP'), - ), - 'pro-theme' => array( - 'activated' => class_exists('PROTheme'), - ), - 'admin-2020' => array( - 'activated' => function_exists('run_admin_2020'), - ), - 'clientside' => array( - 'activated' => class_exists('Clientside'), - ), - 'wphave' => array( - 'activated' => class_exists('wphave_admin'), - ), - 'waaspro' => array( - 'activated' => class_exists('AdminUIPRO') || class_exists('AdminUIPROflat'), - ), - )); - - } // end get_admin_themes; - -} // end class Admin_Themes_Compatibility; + return apply_filters( + 'wu_admin_themes_compatibility', + array( + 'material-wp' => array( + 'activated' => class_exists('MaterialWP'), + ), + 'pro-theme' => array( + 'activated' => class_exists('PROTheme'), + ), + 'admin-2020' => array( + 'activated' => function_exists('run_admin_2020'), + ), + 'clientside' => array( + 'activated' => class_exists('Clientside'), + ), + 'wphave' => array( + 'activated' => class_exists('wphave_admin'), + ), + 'waaspro' => array( + 'activated' => class_exists('AdminUIPRO') || class_exists('AdminUIPROflat'), + ), + ) + ); + } +} diff --git a/inc/class-ajax.php b/inc/class-ajax.php index 4b81971..4b58f6e 100644 --- a/inc/class-ajax.php +++ b/inc/class-ajax.php @@ -41,8 +41,7 @@ class Ajax { * Load search endpoints. */ add_action('wp_ajax_wu_list_table_fetch_ajax_results', array($this, 'refresh_list_table')); - - } // end __construct; + } /** * Reverts the name of the table being processed. * @@ -53,8 +52,7 @@ class Ajax { private function get_table_class_name($table_id): string { return str_replace(' ', '_', (ucwords(str_replace('_', ' ', $table_id)))); - - } // end get_table_class_name; + } /** * Serves the pagination and search results of a list table ajax query. @@ -71,16 +69,13 @@ class Ajax { $full_class_name = "\\WP_Ultimo\\List_Tables\\{$class_name}"; if (class_exists($full_class_name)) { - $table = new $full_class_name(); $table->ajax_response(); - - } // end if; + } do_action('wu_list_table_fetch_ajax_results', $table_id); - - } // end refresh_list_table; + } /** * Search models using our ajax endpoint. @@ -98,125 +93,102 @@ class Ajax { do_action('wu_before_search_models'); if (wu_request('model') === 'all') { - $this->search_all_models(); return; + } - } // end if; + $args = wp_parse_args( + $_REQUEST, + array( + 'model' => 'membership', + 'query' => array(), + 'exclude' => array(), + ) + ); - $args = wp_parse_args($_REQUEST, array( - 'model' => 'membership', - 'query' => array(), - 'exclude' => array() - )); - - $query = array_merge($args['query'], array( - 'number' => -1, - )); + $query = array_merge( + $args['query'], + array( + 'number' => -1, + ) + ); if ($args['exclude']) { - if (is_string($args['exclude'])) { - $args['exclude'] = explode(',', $args['exclude']); $args['exclude'] = array_map('trim', $args['exclude']); - - } // end if; + } $query['id__not_in'] = $args['exclude']; - - } // end if; + } if (wu_get_isset($args, 'include')) { - if (is_string($args['include'])) { - $args['include'] = explode(',', $args['include']); $args['include'] = array_map('trim', $args['include']); - - } // end if; + } $query['id__in'] = $args['include']; - - } // end if; + } /* * Deal with site */ if ($args['model'] === 'site') { - if (wu_get_isset($query, 'id__in')) { - $query['blog_id__in'] = $query['id__in']; unset($query['id__in']); - - } // end if; + } if (wu_get_isset($query, 'id__not_in')) { - $query['blog_id__not_in'] = $query['id__not_in']; unset($query['id__not_in']); - - } // end if; - - } // end if; + } + } $results = array(); if ($args['model'] === 'user') { - $results = $this->search_wordpress_users($query); - } elseif ($args['model'] === 'page') { - - $results = get_posts(array( - 'post_type' => 'page', - 'post_status' => 'publish', - 'numberposts' => -1, - 'exclude' => isset($query['id__not_in']) ? $query['id__not_in'] : '' - )); - + $results = get_posts( + array( + 'post_type' => 'page', + 'post_status' => 'publish', + 'numberposts' => -1, + 'exclude' => isset($query['id__not_in']) ? $query['id__not_in'] : '', + ) + ); } elseif ($args['model'] === 'setting') { - $results = $this->search_wp_ultimo_setting($query); - } else { - $model_func = 'wu_get_' . strtolower((string) $args['model']) . 's'; if (function_exists($model_func)) { - $results = $model_func($query); - - } // end if; - - } // end if; + } + } // Try search by hash if do not have any result if (empty($results)) { - $model_func = 'wu_get_' . strtolower((string) $args['model']) . '_by_hash'; if (function_exists($model_func)) { - $result = $model_func(trim((string) $query['search'], '*')); $results = $result ? array($result) : array(); - - } // end if; - - } // end if; + } + } wp_send_json($results); exit; - - } // end search_models; + } /** * Search all models for Jumper. @@ -226,33 +198,40 @@ class Ajax { */ public function search_all_models() { - $query = array_merge(wu_request('query', array()), array( - 'number' => 10000, - )); + $query = array_merge( + wu_request('query', array()), + array( + 'number' => 10000, + ) + ); - $results_user = array_map(function($item) { + $results_user = array_map( + function ($item) { - $item->model = 'user'; + $item->model = 'user'; - $item->group = 'Users'; + $item->group = 'Users'; - $item->value = network_admin_url("user-edit.php?user_id={$item->ID}"); + $item->value = network_admin_url("user-edit.php?user_id={$item->ID}"); - return $item; + return $item; + }, + $this->search_wordpress_users($query) + ); - }, $this->search_wordpress_users($query)); + $results_settings = array_map( + function ($item) { - $results_settings = array_map(function($item) { + $item['model'] = 'setting'; - $item['model'] = 'setting'; + $item['group'] = 'Settings'; - $item['group'] = 'Settings'; + $item['value'] = $item['url']; - $item['value'] = $item['url']; - - return $item; - - }, $this->search_wp_ultimo_setting($query)); + return $item; + }, + $this->search_wp_ultimo_setting($query) + ); $data = array_merge($results_user, $results_settings); @@ -261,57 +240,67 @@ class Ajax { * * @since 2.0.0 */ - $data_sources = apply_filters('wu_search_models_functions', array( - 'wu_get_customers', - 'wu_get_products', - 'wu_get_plans', - 'wu_get_domains', - 'wu_get_sites', - 'wu_get_memberships', - 'wu_get_payments', - 'wu_get_broadcasts', - 'wu_get_checkout_forms', - )); + $data_sources = apply_filters( + 'wu_search_models_functions', + array( + 'wu_get_customers', + 'wu_get_products', + 'wu_get_plans', + 'wu_get_domains', + 'wu_get_sites', + 'wu_get_memberships', + 'wu_get_payments', + 'wu_get_broadcasts', + 'wu_get_checkout_forms', + ) + ); foreach ($data_sources as $function) { - $results = call_user_func($function, $query); - array_map(function($item) { + array_map( + function ($item) { - $url = str_replace('_', '-', (string) $item->model); + $url = str_replace('_', '-', (string) $item->model); - $item->value = wu_network_admin_url("wp-ultimo-edit-{$url}", array( - 'id' => $item->get_id(), - )); + $item->value = wu_network_admin_url( + "wp-ultimo-edit-{$url}", + array( + 'id' => $item->get_id(), + ) + ); - $item->group = ucwords((string) $item->model) . 's'; + $item->group = ucwords((string) $item->model) . 's'; - return $item; + return $item; + }, + $results + ); - }, $results); + $discount_codes = array_map( + function ($item) { - $discount_codes = array_map(function($item) { + $discount = $item->to_array(); - $discount = $item->to_array(); + $discount['value'] = wu_network_admin_url( + 'wp-ultimo-edit-discount-code', + array( + 'id' => $discount['id'], + ) + ); - $discount['value'] = wu_network_admin_url('wp-ultimo-edit-discount-code', array( - 'id' => $discount['id'], - )); + $discount['group'] = 'Discount Codes'; - $discount['group'] = 'Discount Codes'; - - return $discount; - - }, wu_get_discount_codes($query)); + return $discount; + }, + wu_get_discount_codes($query) + ); $data = array_merge($data, $results, $discount_codes); - - } // end foreach; + } wp_send_json($data); - - } // end search_all_models; + } /** * Search for WP Multisite WaaS settings to help customers find them. * @@ -326,36 +315,41 @@ class Ajax { $all_fields = array(); foreach ($sections as $section_slug => $section) { + $section['fields'] = array_map( + function ($item) use ($section, $section_slug) { - $section['fields'] = array_map(function($item) use ($section, $section_slug) { + $item['section'] = $section_slug; - $item['section'] = $section_slug; + $item['section_title'] = wu_get_isset($section, 'title', ''); - $item['section_title'] = wu_get_isset($section, 'title', ''); + $item['url'] = wu_network_admin_url( + 'wp-ultimo-settings', + array( + 'tab' => $section_slug, + ) + ) . '#' . $item['setting_id']; - $item['url'] = wu_network_admin_url('wp-ultimo-settings', array( - 'tab' => $section_slug, - )) . '#' . $item['setting_id']; - - return $item; - - }, $section['fields']); + return $item; + }, + $section['fields'] + ); $all_fields = array_merge($all_fields, $section['fields']); + } - } // end foreach; - - $_settings = \Arrch\Arrch::find($all_fields, array( - 'sort_key' => 'title', - 'where' => array( - array('setting_id', '~', trim((string) $query['search'], '*')), - array('type', '!=', 'header'), - ), - )); + $_settings = \Arrch\Arrch::find( + $all_fields, + array( + 'sort_key' => 'title', + 'where' => array( + array('setting_id', '~', trim((string) $query['search'], '*')), + array('type', '!=', 'header'), + ), + ) + ); return array_values($_settings); - - } // end search_wp_ultimo_setting; + } /** * Handles the special case of searching native WP users. @@ -367,30 +361,44 @@ class Ajax { */ public function search_wordpress_users($query) { - $results = get_users(array( - 'blog_id' => 0, - 'search' => '*' . $query['search'] . '*', - 'search_columns' => array( - 'ID', 'user_login', 'user_email', 'user_url', 'user_nicename', 'display_name', - ), - )); + $results = get_users( + array( + 'blog_id' => 0, + 'search' => '*' . $query['search'] . '*', + 'search_columns' => array( + 'ID', + 'user_login', + 'user_email', + 'user_url', + 'user_nicename', + 'display_name', + ), + ) + ); - $results = array_map(function($item) { + $results = array_map( + function ($item) { - $item->data->user_pass = ''; + $item->data->user_pass = ''; - $item->data->avatar = get_avatar($item->data->user_email, 40, 'identicon', '', array( - 'force_display' => true, - 'class' => 'wu-rounded-full wu-mr-3', - )); + $item->data->avatar = get_avatar( + $item->data->user_email, + 40, + 'identicon', + '', + array( + 'force_display' => true, + 'class' => 'wu-rounded-full wu-mr-3', + ) + ); - return $item->data; - - }, $results); + return $item->data; + }, + $results + ); return $results; - - } // end search_wordpress_users; + } /** * Adds the selectize templates to the admin footer. @@ -401,11 +409,7 @@ class Ajax { public function render_selectize_templates() { if (current_user_can('manage_network')) { - wu_get_template('ui/selectize-templates'); - - } // end if; - - } // end render_selectize_templates; - -} // end class Ajax; + } + } +} diff --git a/inc/class-api.php b/inc/class-api.php index ad04e27..9a16487 100644 --- a/inc/class-api.php +++ b/inc/class-api.php @@ -22,19 +22,19 @@ class API { use \WP_Ultimo\Traits\Singleton; /** - * Namespace of our API endpoints - * - * @since 1.7.4 - * @var string - */ + * Namespace of our API endpoints + * + * @since 1.7.4 + * @var string + */ private string $namespace = 'wu'; /** - * Version fo the API, this is used to build the API URL - * - * @since 1.7.4 - * @var string - */ + * Version fo the API, this is used to build the API URL + * + * @since 1.7.4 + * @var string + */ private string $api_version = 'v2'; /** @@ -61,7 +61,7 @@ class API { /** * Register the routes - * + * * @since 1.7.4 */ add_action('rest_api_init', array($this, 'register_routes')); @@ -79,8 +79,7 @@ class API { * @since 2.1.2 */ add_filter('rest_authentication_errors', array($this, 'maybe_bypass_wp_auth'), 1); - - } // end __construct; + } /** * Maybe bypass the WP Core auth errors in our routes so we can use our api keys. @@ -94,10 +93,8 @@ class API { // Another plugin already bypass this request if ($result === true) { - return $result; - - } // end if; + } $current_route = $_SERVER['REQUEST_URI']; @@ -105,14 +102,11 @@ class API { $rest_path = rtrim(parse_url($rest_url, PHP_URL_PATH), '/'); if (strncmp((string) $current_route, $rest_path . '/' . $this->get_namespace(), strlen($rest_path . '/' . $this->get_namespace())) !== 0) { - return $result; - - } // end if; + } return true; - - } // end maybe_bypass_wp_auth; + } /** * Allow admins to refresh their API credentials. @@ -123,7 +117,6 @@ class API { public function refresh_API_credentials() { // phpcs:ignore if (wu_request('submit_button') === 'refresh_api_credentials') { - wu_save_setting('api_url', network_site_url()); wu_save_setting('api_key', wp_generate_password(24, false)); @@ -133,10 +126,8 @@ class API { wp_safe_redirect(network_admin_url('admin.php?page=wp-ultimo-settings&tab=api&api=refreshed&updated=1')); exit; - - } // end if; - - } // end refresh_API_credentials; + } + } /** * Add the admin interface to create new webhooks @@ -144,119 +135,159 @@ class API { * @since 1.7.4 */ public function add_settings() { - /* + /* * API & Webhooks * This section holds the API settings of the WP Multisite WaaS Plugin. */ - wu_register_settings_section('api', array( - 'title' => __('API & Webhooks', 'wp-ultimo'), - 'desc' => __('API & Webhooks', 'wp-ultimo'), - 'icon' => 'dashicons-wu-paper-plane', - 'order' => 95, - )); + wu_register_settings_section( + 'api', + array( + 'title' => __('API & Webhooks', 'wp-ultimo'), + 'desc' => __('API & Webhooks', 'wp-ultimo'), + 'icon' => 'dashicons-wu-paper-plane', + 'order' => 95, + ) + ); - wu_register_settings_field('api', 'api_header', array( - 'title' => __('API Settings', 'wp-ultimo'), - 'desc' => __('Options related to WP Multisite WaaS API endpoints.', 'wp-ultimo'), - 'type' => 'header', - )); + wu_register_settings_field( + 'api', + 'api_header', + array( + 'title' => __('API Settings', 'wp-ultimo'), + 'desc' => __('Options related to WP Multisite WaaS API endpoints.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - wu_register_settings_field('api', 'enable_api', array( - 'title' => __('Enable API', 'wp-ultimo'), - 'desc' => __('Tick this box if you want WP Multisite WaaS to add its own endpoints to the WordPress REST API. This is required for some integrations to work, most notabily, Zapier.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + wu_register_settings_field( + 'api', + 'enable_api', + array( + 'title' => __('Enable API', 'wp-ultimo'), + 'desc' => __('Tick this box if you want WP Multisite WaaS to add its own endpoints to the WordPress REST API. This is required for some integrations to work, most notabily, Zapier.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); $refreshed_tag = ''; if (wu_request('updated') && wu_request('api') === 'refreshed') { - $refreshed_tag = sprintf('%s', __('Credentials Refreshed', 'wp-ultimo')); + } - } // end if; + wu_register_settings_field( + 'api', + 'api_url', + array( + 'title' => __('API URL', 'wp-ultimo'), + 'desc' => '', + 'tooltip' => '', + 'copy' => true, + 'type' => 'text-display', + 'default' => network_site_url(), + 'require' => array( + 'enable_api' => true, + ), + ) + ); - wu_register_settings_field('api', 'api_url', array( - 'title' => __('API URL', 'wp-ultimo'), - 'desc' => '', - 'tooltip' => '', - 'copy' => true, - 'type' => 'text-display', - 'default' => network_site_url(), - 'require' => array( - 'enable_api' => true, - ), - )); + wu_register_settings_field( + 'api', + 'api_key', + array( + 'title' => __('API Key', 'wp-ultimo') . $refreshed_tag, + 'desc' => '', + 'tooltip' => '', + 'type' => 'text-display', + 'copy' => true, + 'default' => wp_generate_password(24, false), + 'wrapper_classes' => 'sm:wu-w-1/2 wu-float-left', + 'require' => array( + 'enable_api' => true, + ), + ) + ); - wu_register_settings_field('api', 'api_key', array( - 'title' => __('API Key', 'wp-ultimo') . $refreshed_tag, - 'desc' => '', - 'tooltip' => '', - 'type' => 'text-display', - 'copy' => true, - 'default' => wp_generate_password(24, false), - 'wrapper_classes' => 'sm:wu-w-1/2 wu-float-left', - 'require' => array( - 'enable_api' => true, - ), - )); + wu_register_settings_field( + 'api', + 'api_secret', + array( + 'title' => __('API Secret', 'wp-ultimo') . $refreshed_tag, + 'tooltip' => '', + 'type' => 'text-display', + 'copy' => true, + 'default' => wp_generate_password(24, false), + 'wrapper_classes' => 'sm:wu-border-l-0 sm:wu-w-1/2 wu-float-left', + 'require' => array( + 'enable_api' => 1, + ), + ) + ); - wu_register_settings_field('api', 'api_secret', array( - 'title' => __('API Secret', 'wp-ultimo') . $refreshed_tag, - 'tooltip' => '', - 'type' => 'text-display', - 'copy' => true, - 'default' => wp_generate_password(24, false), - 'wrapper_classes' => 'sm:wu-border-l-0 sm:wu-w-1/2 wu-float-left', - 'require' => array( - 'enable_api' => 1, - ), - )); + wu_register_settings_field( + 'api', + 'api_note', + array( + 'desc' => __('This is your API Key. You cannot change it directly. To reset the API key and secret, use the button "Refresh API credentials" below.', 'wp-ultimo'), + 'type' => 'note', + 'classes' => 'wu-text-gray-700 wu-text-xs', + 'wrapper_classes' => 'wu-bg-white sm:wu-border-t-0 sm:wu-mt-0 sm:wu-pt-0', + 'require' => array( + 'enable_api' => 1, + ), + ) + ); - wu_register_settings_field('api', 'api_note', array( - 'desc' => __('This is your API Key. You cannot change it directly. To reset the API key and secret, use the button "Refresh API credentials" below.', 'wp-ultimo'), - 'type' => 'note', - 'classes' => 'wu-text-gray-700 wu-text-xs', - 'wrapper_classes' => 'wu-bg-white sm:wu-border-t-0 sm:wu-mt-0 sm:wu-pt-0', - 'require' => array( - 'enable_api' => 1, - ), - )); + wu_register_settings_field( + 'api', + 'refresh_api_credentials', + array( + 'title' => __('Refresh API Credentials', 'wp-ultimo'), + 'type' => 'submit', + 'classes' => 'button wu-ml-auto', + 'wrapper_classes' => 'wu-bg-white sm:wu-border-t-0 sm:wu-mt-0 sm:wu-pt-0', + 'require' => array( + 'enable_api' => 1, + ), + ) + ); - wu_register_settings_field('api', 'refresh_api_credentials', array( - 'title' => __('Refresh API Credentials', 'wp-ultimo'), - 'type' => 'submit', - 'classes' => 'button wu-ml-auto', - 'wrapper_classes' => 'wu-bg-white sm:wu-border-t-0 sm:wu-mt-0 sm:wu-pt-0', - 'require' => array( - 'enable_api' => 1, - ), - )); + wu_register_settings_field( + 'api', + 'api_log_calls', + array( + 'title' => __('Log API calls (Advanced)', 'wp-ultimo'), + 'desc' => __('Tick this box if you want to log all calls received via WP Multisite WaaS API endpoints. You can access the logs on WP Multisite WaaS → System Info → Logs.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + 'require' => array( + 'enable_api' => 1, + ), + ) + ); - wu_register_settings_field('api', 'api_log_calls', array( - 'title' => __('Log API calls (Advanced)', 'wp-ultimo'), - 'desc' => __('Tick this box if you want to log all calls received via WP Multisite WaaS API endpoints. You can access the logs on WP Multisite WaaS → System Info → Logs.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - 'require' => array( - 'enable_api' => 1, - ), - )); + wu_register_settings_field( + 'api', + 'webhook_header', + array( + 'title' => __('Webhook Settings', 'wp-ultimo'), + 'desc' => __('Options related to WP Multisite WaaS API webhooks.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - wu_register_settings_field('api', 'webhook_header', array( - 'title' => __('Webhook Settings', 'wp-ultimo'), - 'desc' => __('Options related to WP Multisite WaaS API webhooks.', 'wp-ultimo'), - 'type' => 'header', - )); - - wu_register_settings_field('api', 'webhook_calls_blocking', array( - 'title' => __('Wait for Response (Advanced)', 'wp-ultimo'), - 'desc' => __('Tick this box if you want the WP Multisite WaaS\'s webhook calls to wait for the remote server to respond. Keeping this option enabled can have huge effects on your network\'s performance, only enable it if you know what you are doing and need to debug webhook calls.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - )); - - } // end add_settings; + wu_register_settings_field( + 'api', + 'webhook_calls_blocking', + array( + 'title' => __('Wait for Response (Advanced)', 'wp-ultimo'), + 'desc' => __('Tick this box if you want the WP Multisite WaaS\'s webhook calls to wait for the remote server to respond. Keeping this option enabled can have huge effects on your network\'s performance, only enable it if you know what you are doing and need to debug webhook calls.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + ) + ); + } /** * Returns the namespace of our API endpoints. @@ -267,8 +298,7 @@ class API { public function get_namespace() { return "$this->namespace/$this->api_version"; - - } // end get_namespace; + } /** * Returns the credentials. @@ -282,8 +312,7 @@ class API { 'api_key' => wu_get_setting('api_key', 'prevent'), 'api_secret' => wu_get_setting('api_secret', 'prevent'), ); - - } // end get_auth; + } /** * Validate a pair of API credentials @@ -296,8 +325,7 @@ class API { public function validate_credentials($api_key, $api_secret) { return compact('api_key', 'api_secret') === $this->get_auth(); // phpcs:ignore - - } // end validate_credentials; + } /** * Check if we can log api calls. @@ -308,8 +336,7 @@ class API { public function should_log_api_calls() { return apply_filters('wu_should_log_api_calls', wu_get_setting('api_log_calls', false)); - - } // end should_log_api_calls; + } /** * Checks if we should log api calls or not, and if we should, log them. @@ -321,19 +348,16 @@ class API { public function maybe_log_api_call($request) { if ($this->should_log_api_calls()) { - $payload = array( 'route' => $request->get_route(), 'method' => $request->get_method(), 'url_params' => $request->get_url_params(), - 'body_params' => $request->get_body() + 'body_params' => $request->get_body(), ); wu_log_add('api-calls', json_encode($payload, JSON_PRETTY_PRINT)); - - } // end if; - - } // end maybe_log_api_call; + } + } /** * Log api errors. @@ -351,26 +375,22 @@ class API { /* * Log API call here if we didn't log it before. */ - if (!$this->should_log_api_calls()) { - + if ( ! $this->should_log_api_calls()) { $payload = array( 'route' => $request->get_route(), 'method' => $request->get_method(), 'url_params' => $request->get_url_params(), - 'body_params' => $request->get_body() + 'body_params' => $request->get_body(), ); wu_log_add('api-errors', json_encode($payload, JSON_PRETTY_PRINT)); - - } // end if; + } wu_log_add('api-errors', $result); - - } // end if; + } return $result; - - } // end log_api_errors; + } /** * Tries to validate the API key and secret from the request @@ -382,28 +402,21 @@ class API { public function check_authorization($request) { if (isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER']) { - $api_key = $_SERVER['PHP_AUTH_USER']; $api_secret = $_SERVER['PHP_AUTH_PW']; - } else { - $params = $request->get_params(); $api_key = wu_get_isset($params, 'api_key', wu_get_isset($params, 'api-key')); $api_secret = wu_get_isset($params, 'api_secret', wu_get_isset($params, 'api-secret')); - - } // end if; + } if ($api_key === false) { - return false; - - } // end if; + } return $this->validate_credentials($api_key, $api_secret); - - } // end check_authorization; + } /** * Checks if the API routes are available or not, via the settings. @@ -420,8 +433,7 @@ class API { * @return boolean */ return apply_filters('wu_is_api_enabled', wu_get_setting('enable_api', true)); - - } // end is_api_enabled; + } /** * Register the API routes. @@ -431,19 +443,21 @@ class API { */ public function register_routes() { - if (!$this->is_api_enabled()) { - + if ( ! $this->is_api_enabled()) { return; - - } // end if; + } $namespace = $this->get_namespace(); - register_rest_route($namespace, '/auth', array( - 'methods' => 'GET', - 'callback' => array($this, 'auth'), - 'permission_callback' => array($this, 'check_authorization'), - )); + register_rest_route( + $namespace, + '/auth', + array( + 'methods' => 'GET', + 'callback' => array($this, 'auth'), + 'permission_callback' => array($this, 'check_authorization'), + ) + ); /** * Allow additional routes to be registered. @@ -454,8 +468,7 @@ class API { * @param self $this The current API instance. */ do_action('wu_register_rest_routes', $this); - - } // end register_routes; + } /** * Dummy endpoint to low services to test the authentication method being used. @@ -469,12 +482,12 @@ class API { $current_site = get_current_site(); - wp_send_json(array( - 'success' => true, - 'label' => $current_site->site_name, - 'message' => __('Welcome to our API', 'wp-ultimo'), - )); - - } // end auth; - -} // end class API; + wp_send_json( + array( + 'success' => true, + 'label' => $current_site->site_name, + 'message' => __('Welcome to our API', 'wp-ultimo'), + ) + ); + } +} diff --git a/inc/class-async-calls.php b/inc/class-async-calls.php index 7e0f094..1bc3e28 100644 --- a/inc/class-async-calls.php +++ b/inc/class-async-calls.php @@ -9,14 +9,14 @@ namespace WP_Ultimo; -use \Amp\Iterator; -use \Amp\Sync\LocalSemaphore; -use \Amp\Sync\ConcurrentIterator; -use \Amp\Http\Client\Request; -use \Amp\Http\Client\Connection\DefaultConnectionPool; -use \Amp\Socket\ClientTlsContext; -use \Amp\Socket\ConnectContext; -use \Amp\Http\Client\HttpClientBuilder; +use Amp\Iterator; +use Amp\Sync\LocalSemaphore; +use Amp\Sync\ConcurrentIterator; +use Amp\Http\Client\Request; +use Amp\Http\Client\Connection\DefaultConnectionPool; +use Amp\Socket\ClientTlsContext; +use Amp\Socket\ConnectContext; +use Amp\Http\Client\HttpClientBuilder; // Exit if accessed directly defined('ABSPATH') || exit; @@ -47,12 +47,11 @@ class Async_Calls { */ public static function register_listener($id, $callable, ...$args) { - self::$registry[$id] = array( + self::$registry[ $id ] = array( 'callable' => $callable, 'args' => $args, ); - - } // end register_listener; + } /** * Install the registered listeners. @@ -63,28 +62,23 @@ class Async_Calls { public static function install_listeners() { foreach (self::$registry as $id => $listener) { + add_action( + "wp_ajax_wu_async_call_listener_{$id}", + function () use ($listener) { - add_action("wp_ajax_wu_async_call_listener_{$id}", function() use ($listener) { + try { + $results = call_user_func_array($listener['callable'], $listener['args']); + } catch (\Throwable $th) { + wp_send_json_error($th); + } - try { + wp_send_json_success($results); - $results = call_user_func_array($listener['callable'], $listener['args']); - - } catch (\Throwable $th) { - - wp_send_json_error($th); - - } // end try; - - wp_send_json_success($results); - - exit; - - }); - - } // end foreach; - - } // end install_listeners; + exit; + } + ); + } + } /** * Build the base URL for the listener calls. @@ -98,8 +92,7 @@ class Async_Calls { public static function build_base_url($id, $args) { return add_query_arg($args, admin_url('admin-ajax.php')); - - } // end build_base_url; + } /** * Build the final URL to be called. @@ -119,19 +112,22 @@ class Async_Calls { $urls = array(); for ($i = 1; $i <= $pages; $i++) { - - $urls[] = self::build_base_url($id, array_merge($args, array( - 'action' => "wu_async_call_listener_$id", - 'parallel' => 1, - 'page' => $i, - 'per_page' => $chunk_size, - ))); - - } // end for; + $urls[] = self::build_base_url( + $id, + array_merge( + $args, + array( + 'action' => "wu_async_call_listener_$id", + 'parallel' => 1, + 'page' => $i, + 'per_page' => $chunk_size, + ) + ) + ); + } return $urls; - - } // end build_url_list; + } /** * Builds and returns the client that will handle the calls. @@ -143,17 +139,16 @@ class Async_Calls { $client_tls_context = new ClientTlsContext(''); - $connect_base_context = new ConnectContext; + $connect_base_context = new ConnectContext(); $tls_context = $client_tls_context->withoutPeerVerification(); $connect_context = $connect_base_context->withTlsContext($tls_context); - $builder = new HttpClientBuilder; + $builder = new HttpClientBuilder(); return $builder->usingPool(new DefaultConnectionPool(null, $connect_context))->build(); - - } // end get_client; + } /** * Run the parallel queue after everything is correctly enqueued. @@ -173,49 +168,48 @@ class Async_Calls { $urls = self::build_url_list($id, $total, $chunk_size, $args); - $coroutine = \Amp\call(static function() use ($id, $total, $chunk_size, $parallel_threads, $client, $urls) { + $coroutine = \Amp\call( + static function () use ($id, $total, $chunk_size, $parallel_threads, $client, $urls) { - $results = array(); + $results = array(); - $chunker = new LocalSemaphore($parallel_threads); + $chunker = new LocalSemaphore($parallel_threads); - yield ConcurrentIterator\each(Iterator\fromIterable($urls), $chunker, function($url) use (&$results, $client) { + yield ConcurrentIterator\each( + Iterator\fromIterable($urls), + $chunker, + function ($url) use (&$results, $client) { - try { + try { + $request = new Request($url); - $request = new Request($url); + $request->setTcpConnectTimeout(1000 * 1000); - $request->setTcpConnectTimeout(1000 * 1000); + $request->setTlsHandshakeTimeout(1000 * 1000); - $request->setTlsHandshakeTimeout(1000 * 1000); + $request->setTransferTimeout(1000 * 1000); - $request->setTransferTimeout(1000 * 1000); + $request->setHeader('cookie', wu_get_isset($_SERVER, 'HTTP_COOKIE', '')); - $request->setHeader('cookie', wu_get_isset($_SERVER, 'HTTP_COOKIE', '')); + $response = yield $client->request($request); - $response = yield $client->request($request); + $body = yield $response->getBody()->buffer(); - $body = yield $response->getBody()->buffer(); - - $results[$url] = json_decode($body); - - } catch (\Throwable $e) { - - throw $e; - - } // end try; - - }); + $results[ $url ] = json_decode($body); + } catch (\Throwable $e) { + throw $e; + } + } + ); return self::condense_results($results); // phpcs:ignore - - }); + } + ); $responses = \Amp\Promise\wait($coroutine); return $responses; - - } // end run; + } /** * Condense multiple results into one single result. @@ -228,19 +222,13 @@ class Async_Calls { public static function condense_results($results) { foreach ($results as $result) { - $status = wu_get_isset($result, 'success', false); if ($status === false) { - return $result; - - } // end if; - - } // end foreach; + } + } return true; - - } // end condense_results; - -} // end class Async_Calls; + } +} diff --git a/inc/class-autoloader.php b/inc/class-autoloader.php index 8a118f6..8210b75 100644 --- a/inc/class-autoloader.php +++ b/inc/class-autoloader.php @@ -31,7 +31,7 @@ class Autoloader { /** * Static-only class. */ - private function __construct() {} // end __construct; + private function __construct() {} /** * Initializes our custom autoloader @@ -42,7 +42,7 @@ class Autoloader { */ public static function init() { // do nothing now. Composer autoloader does the work. - } // end init; + } /** * Checks for unit tests and WP_ULTIMO_DEBUG. @@ -53,7 +53,5 @@ class Autoloader { public static function is_debug() { return false; // return wu_is_debug(); - - } // end is_debug; - -} // end class Autoloader; + } +} diff --git a/inc/class-cron.php b/inc/class-cron.php index ec93328..436b75d 100644 --- a/inc/class-cron.php +++ b/inc/class-cron.php @@ -13,8 +13,8 @@ namespace WP_Ultimo; -use \WP_Ultimo\Database\Memberships\Membership_Status; -use \WP_Ultimo\Database\Payments\Payment_Status; +use WP_Ultimo\Database\Memberships\Membership_Status; +use WP_Ultimo\Database\Payments\Payment_Status; // Exit if accessed directly defined('ABSPATH') || exit; @@ -66,8 +66,7 @@ class Cron { add_action('wu_membership_check', array($this, 'membership_expired_check'), 20); add_action('wu_async_mark_membership_as_expired', array($this, 'async_mark_membership_as_expired'), 10); - - } // end init; + } /** * Creates the recurring schedules for WP Multisite WaaS. @@ -82,34 +81,27 @@ class Cron { * Hourly check */ if (wu_next_scheduled_action('wu_hourly') === false) { - $next_hour = strtotime(gmdate('Y-m-d H:00:00', strtotime('+1 hour'))); wu_schedule_recurring_action($next_hour, HOUR_IN_SECONDS, 'wu_hourly', array(), 'wu_cron'); - - } // end if; + } /* * Daily check */ if (wu_next_scheduled_action('wu_daily') === false) { - wu_schedule_recurring_action(strtotime('tomorrow'), DAY_IN_SECONDS, 'wu_daily', array(), 'wu_cron'); - - } // end if; + } /* * Monthly check */ if (wu_next_scheduled_action('wu_monthly') === false) { - $next_month = strtotime(gmdate('Y-m-01 00:00:00', strtotime('+1 month'))); wu_schedule_recurring_action($next_month, MONTH_IN_SECONDS, 'wu_monthly', array(), 'wu_cron'); - - } // end if; - - } // end create_schedules; + } + } /** * Creates the default membership checking schedule. @@ -126,12 +118,9 @@ class Cron { $interval = apply_filters('wu_schedule_membership_check_interval', 1 * HOUR_IN_SECONDS); if (wu_next_scheduled_action('wu_membership_check') === false) { - wu_schedule_recurring_action(time(), $interval, 'wu_membership_check', array(), 'wu_cron'); - - } // end if; - - } // end schedule_membership_check; + } + } /** * Checks if non-auto-renewable memberships need work. @@ -144,23 +133,27 @@ class Cron { */ public function membership_renewal_check() { /* - * Define how many days before we need to + * Define how many days before we need to * create pending payments. */ $days_before_expiring = apply_filters('wu_membership_renewal_days_before_expiring', 3); - $query_params = apply_filters('wu_membership_renewal_check_query_params', array( - 'auto_renew' => false, - 'status__in' => array( - Membership_Status::ACTIVE, + $query_params = apply_filters( + 'wu_membership_renewal_check_query_params', + array( + 'auto_renew' => false, + 'status__in' => array( + Membership_Status::ACTIVE, + ), + 'date_query' => array( + 'column' => 'date_expiration', + 'before' => "+{$days_before_expiring} days", + 'after' => 'yesterday', + 'inclusive' => true, + ), ), - 'date_query' => array( - 'column' => 'date_expiration', - 'before' => "+{$days_before_expiring} days", - 'after' => 'yesterday', - 'inclusive' => true, - ), - ), $days_before_expiring); + $days_before_expiring + ); $memberships = wu_get_memberships($query_params); @@ -169,14 +162,15 @@ class Cron { * a new async call for each one. */ foreach ($memberships as $membership) { - - wu_enqueue_async_action('wu_async_create_renewal_payment', array( - 'membership_id' => $membership->get_id(), - ), 'wu_cron_check'); - - } // end foreach; - - } // end membership_renewal_check; + wu_enqueue_async_action( + 'wu_async_create_renewal_payment', + array( + 'membership_id' => $membership->get_id(), + ), + 'wu_cron_check' + ); + } + } /** * Checks if trialing memberships need work. @@ -189,17 +183,20 @@ class Cron { */ public function membership_trial_check() { - $query_params = apply_filters('wu_membership_trial_check_query_params', array( - 'auto_renew' => false, - 'status__in' => array( - Membership_Status::TRIALING, - ), - 'date_query' => array( - 'column' => 'date_trial_end', - 'before' => '-3 hours', - 'inclusive' => true, - ), - )); + $query_params = apply_filters( + 'wu_membership_trial_check_query_params', + array( + 'auto_renew' => false, + 'status__in' => array( + Membership_Status::TRIALING, + ), + 'date_query' => array( + 'column' => 'date_trial_end', + 'before' => '-3 hours', + 'inclusive' => true, + ), + ) + ); $memberships = wu_get_memberships($query_params); @@ -208,15 +205,16 @@ class Cron { * a new async call for each one. */ foreach ($memberships as $membership) { - - wu_enqueue_async_action('wu_async_create_renewal_payment', array( - 'membership_id' => $membership->get_id(), - 'trial' => true, - ), 'wu_cron_check'); - - } // end foreach; - - } // end membership_trial_check; + wu_enqueue_async_action( + 'wu_async_create_renewal_payment', + array( + 'membership_id' => $membership->get_id(), + 'trial' => true, + ), + 'wu_cron_check' + ); + } + } /** * Creates the pending payment for a renewing membership. @@ -232,10 +230,8 @@ class Cron { $membership = wu_get_membership($membership_id); if (empty($membership)) { - return false; - - } // end if; + } /* * List of things to do: @@ -249,8 +245,7 @@ class Cron { $pending_payment = $membership->get_last_pending_payment(); if (empty($pending_payment)) { - - $new_payment = wu_membership_create_new_payment($membership, false, !$trial); + $new_payment = wu_membership_create_new_payment($membership, false, ! $trial); /* * Update the membership status. @@ -259,9 +254,12 @@ class Cron { $saved = $membership->save(); - $payment_url = add_query_arg(array( - 'payment' => $new_payment->get_hash(), - ), wu_get_registration_url()); + $payment_url = add_query_arg( + array( + 'payment' => $new_payment->get_hash(), + ), + wu_get_registration_url() + ); $payload = array_merge( array( @@ -275,12 +273,10 @@ class Cron { wu_do_event('renewal_payment_created', $payload); return $saved; - - } // end if; + } return true; - - } // end async_create_renewal_payment; + } /** * Checks if any memberships need to be marked as expired. @@ -295,19 +291,23 @@ class Cron { */ $grace_period_days = apply_filters('wu_membership_grace_period_days', 3); - $query_params = apply_filters('wu_membership_expired_check_query_params', array( - 'auto_renew' => false, - 'status__in' => array( - Membership_Status::ACTIVE, - Membership_Status::ON_HOLD, + $query_params = apply_filters( + 'wu_membership_expired_check_query_params', + array( + 'auto_renew' => false, + 'status__in' => array( + Membership_Status::ACTIVE, + Membership_Status::ON_HOLD, + ), + 'date_expiration__not_in' => array(null, '0000-00-00 00:00:00'), + 'date_query' => array( + 'column' => 'date_expiration', + 'before' => "-{$grace_period_days} days", + 'inclusive' => true, + ), ), - 'date_expiration__not_in' => array(null, '0000-00-00 00:00:00'), - 'date_query' => array( - 'column' => 'date_expiration', - 'before' => "-{$grace_period_days} days", - 'inclusive' => true, - ), - ), $grace_period_days); + $grace_period_days + ); $memberships = wu_get_memberships($query_params); @@ -316,14 +316,15 @@ class Cron { * a new async call for each one. */ foreach ($memberships as $membership) { - - wu_enqueue_async_action('wu_async_mark_membership_as_expired', array( - 'membership_id' => $membership->get_id(), - ), 'wu_cron_check'); - - } // end foreach; - - } // end membership_expired_check; + wu_enqueue_async_action( + 'wu_async_mark_membership_as_expired', + array( + 'membership_id' => $membership->get_id(), + ), + 'wu_cron_check' + ); + } + } /** * Marks expired memberships as such. @@ -338,10 +339,8 @@ class Cron { $membership = wu_get_membership($membership_id); if (empty($membership)) { - return false; - - } // end if; + } /* * Update the membership status. @@ -356,7 +355,5 @@ class Cron { $membership->set_skip_validation(true); return $membership->save(); - - } // end async_mark_membership_as_expired; - -} // end class Cron; + } +} diff --git a/inc/class-current.php b/inc/class-current.php index d59de97..b9cc46d 100644 --- a/inc/class-current.php +++ b/inc/class-current.php @@ -90,8 +90,7 @@ class Current { */ add_action('init', array($this, 'load_currents')); add_action('wp', array($this, 'load_currents')); - - } // end init; + } /** * Flush rewrite rules to make sure any newly added ones get installed on update. @@ -102,8 +101,7 @@ class Current { public function flush_rewrite_rules_on_update() { flush_rewrite_rules(); - - } // end flush_rewrite_rules_on_update; + } /** * Adds a new rewrite rule to allow for pretty links. @@ -124,16 +122,13 @@ class Current { ); if (is_subdomain_install() === false) { - add_rewrite_rule( "blog/(.?.+?)/{$site_url_param}/([0-9a-zA-Z]+)/?$", 'index.php?name=$matches[1]&site_hash=$matches[2]', 'top' ); - - } // end if; - - } // end add_rewrite_rules; + } + } /** * Adds the necessary query vars to support pretty links. @@ -153,8 +148,7 @@ class Current { $query_vars[] = 'wu_preselected'; return $query_vars; - - } // end add_query_vars; + } /** * List of URL keys to set the current objects. @@ -172,8 +166,7 @@ class Current { ); return wu_get_isset($params, $type, $type); - - } // end param_key; + } /** * Returns the URL to manage a site/customer on the front-end or back end. @@ -189,8 +182,7 @@ class Current { // Uses hash instead of the ID. $site_hash = \WP_Ultimo\Helpers\Hash::encode($id, $type); - if (!is_admin()) { - + if ( ! is_admin()) { $current_url = rtrim((string) wu_get_current_url(), '/'); $url_param = self::param_key($type); @@ -199,20 +191,15 @@ class Current { * Check if the current URL already has a site parameter and remove it. */ if (strpos($current_url, '/' . $url_param . '/') !== false) { - $current_url = preg_replace('/\/' . $url_param . '\/(.+)/', '/', $current_url); - - } // end if; + } $pretty_url = $current_url . '/' . $url_param . '/' . $site_hash; $manage_site_url = get_option('permalink_structure') ? $pretty_url : add_query_arg($url_param, $site_hash); - } else { - $manage_site_url = get_admin_url($id); - - } // end if; + } /** * Allow developers to modify the manage site URL parameters. @@ -225,8 +212,7 @@ class Current { * @return string The modified manage URL. */ return apply_filters("wu_current_{$type}_get_manage_url", $manage_site_url, $id, $site_hash); - - } // end get_manage_url; + } /** * Loads the current site and makes it available. @@ -241,7 +227,7 @@ class Current { /** * On the front-end, we need to check for url overrides. */ - if (!is_admin()) { + if ( ! is_admin()) { /* * By default, we'll use the `site` parameter. */ @@ -252,31 +238,24 @@ class Current { $site_from_url = wu_get_site_by_hash($site_hash); if ($site_from_url) { - $this->site_set_via_request = true; $site = $site_from_url; - - } // end if; - + } } else { - $site = wu_get_current_site(); - - } // end if; + } if ($site) { - $this->set_site($site); - - } // end if; + } $customer = wu_get_current_customer(); /** * On the front-end, we need to check for url overrides. */ - if (!is_admin()) { + if ( ! is_admin()) { /* * By default, we'll use the `site` parameter. */ @@ -285,14 +264,11 @@ class Current { $customer_from_url = wu_get_customer(wu_request($customer_url_param, 0)); if ($customer_from_url) { - $this->customer_set_via_request = true; $customer = $customer_from_url; - - } // end if; - - } // end if; + } + } $this->set_customer($customer); @@ -306,28 +282,21 @@ class Current { $membership_hash = wu_request($membership_url_param, get_query_var('membership_hash')); if ($membership_hash) { - $this->membership_set_via_request = true; $membership = wu_get_membership_by_hash($membership_hash); - } elseif ($site) { - $membership = $site->get_membership(); + } - } // end if; - - if ($customer && !$membership) { - + if ($customer && ! $membership) { $memberships = (array) $customer->get_memberships(); $membership = wu_get_isset($memberships, 0, false); - - } // end if; + } $this->set_membership($membership); - - } // end load_currents; + } /** * Get the current site instance. @@ -338,8 +307,7 @@ class Current { public function get_site() { return $this->site; - - } // end get_site; + } /** * Set the current site instance. @@ -363,8 +331,7 @@ class Current { $site = apply_filters('wu_current_set_site', $site, $this); $this->site = $site; - - } // end set_site; + } /** * Get wether or not the site was set via request. @@ -375,8 +342,7 @@ class Current { public function is_site_set_via_request() { return $this->site_set_via_request; - - } // end is_site_set_via_request; + } /** * Get the current customer instance. @@ -387,8 +353,7 @@ class Current { public function get_customer() { return $this->customer; - - } // end get_customer; + } /** * Set the current customer instance. @@ -412,8 +377,7 @@ class Current { $customer = apply_filters('wu_current_set_customer', $customer, $this); $this->customer = $customer; - - } // end set_customer; + } /** * Get the current membership instance. @@ -424,8 +388,7 @@ class Current { public function get_membership() { return $this->membership; - - } // end get_membership; + } /** * Set the current membership instance. @@ -449,8 +412,7 @@ class Current { $membership = apply_filters('wu_current_set_membership', $membership, $this); $this->membership = $membership; - - } // end set_membership; + } /** * Get wether or not the membership was set via request. @@ -461,7 +423,5 @@ class Current { public function is_membership_set_via_request() { return $this->membership_set_via_request; - - } // end is_membership_set_via_request; - -} // end class Current; + } +} diff --git a/inc/class-dashboard-statistics.php b/inc/class-dashboard-statistics.php index 4165377..289bc5b 100644 --- a/inc/class-dashboard-statistics.php +++ b/inc/class-dashboard-statistics.php @@ -11,9 +11,9 @@ namespace WP_Ultimo; -use \WP_Ultimo\Models\Membership; -use \WP_Ultimo\Models\Payment; -use \WP_Ultimo\Database\Payments\Payment_Status; +use WP_Ultimo\Models\Membership; +use WP_Ultimo\Models\Payment; +use WP_Ultimo\Database\Payments\Payment_Status; // Exit if accessed directly defined('ABSPATH') || exit; @@ -59,16 +59,13 @@ class Dashboard_Statistics { public function __construct($args = array()) { if ($args) { - $this->start_date = $args['start_date']; $this->end_date = $args['end_date']; $this->types = $args['types']; - - } // end if; - - } // end __construct; + } + } /** * Runs on singleton instantiation. @@ -76,7 +73,7 @@ class Dashboard_Statistics { * @since 2.0.0 * @return void. */ - public function init() {} // end init; + public function init() {} /** * Main function to call the get data functions based on the array of types. @@ -89,16 +86,13 @@ class Dashboard_Statistics { $data = array(); foreach ($this->types as $key => $type) { - $data_function = 'get_data_' . $type; - $data[$key] = $this->$data_function(); - - } // end foreach; + $data[ $key ] = $this->$data_function(); + } return $data; - - } // end statistics_data; + } /** * Get data of all completed and refunded payments to show in the main graph. @@ -159,16 +153,18 @@ class Dashboard_Statistics { ), ); - $memberships = wu_get_memberships(array( - 'date_query' => array( - 'column' => 'date_created', - 'compare' => 'BETWEEN', - 'relation' => '', - array( - 'year' => current_time('Y', true), + $memberships = wu_get_memberships( + array( + 'date_query' => array( + 'column' => 'date_created', + 'compare' => 'BETWEEN', + 'relation' => '', + array( + 'year' => current_time('Y', true), + ), ), ) - )); + ); $mrr_status = array( 'active', @@ -182,39 +178,29 @@ class Dashboard_Statistics { ); foreach ($memberships as $membership) { - - if (!$membership->is_recurring()) { - + if ( ! $membership->is_recurring()) { continue; - - } // end if; + } $status = $membership->get_status(); if (in_array($status, $mrr_status, true)) { - $data = getdate(strtotime($membership->get_date_created())); $month = strtolower($data['month']); - $payments_per_month[$month]['total'] += floatval($membership->get_normalized_amount()); - - } // end if; + $payments_per_month[ $month ]['total'] += floatval($membership->get_normalized_amount()); + } if (in_array($status, $churn_status, true)) { - $data = getdate(strtotime((string) $membership->get_date_cancellation())); $month = strtolower($data['month']); - $payments_per_month[$month]['cancelled'] += floatval($membership->get_normalized_amount()); - - } // end if; - - } // end foreach; + $payments_per_month[ $month ]['cancelled'] += floatval($membership->get_normalized_amount()); + } + } return $payments_per_month; - - } // end get_data_mrr_growth; - -} // end class Dashboard_Statistics; + } +} diff --git a/inc/class-dashboard-widgets.php b/inc/class-dashboard-widgets.php index 14fe4cd..096d159 100644 --- a/inc/class-dashboard-widgets.php +++ b/inc/class-dashboard-widgets.php @@ -58,8 +58,7 @@ class Dashboard_Widgets { add_action('wp_ajax_wu_fetch_activity', array($this, 'process_ajax_fetch_events')); add_action('wp_ajax_wu_generate_csv', array($this, 'handle_table_csv')); - - } // end init; + } /** * Enqueues the JavaScript code that sends the dismiss call to the ajax endpoint. @@ -71,17 +70,14 @@ class Dashboard_Widgets { global $pagenow; - if (!$pagenow || $pagenow !== 'index.php') { - + if ( ! $pagenow || $pagenow !== 'index.php') { return; - - } // end if; + } wp_enqueue_script('wu-vue'); wp_enqueue_script('moment'); - - } // end enqueue_scripts; + } /** * Register the widgets @@ -97,40 +93,42 @@ class Dashboard_Widgets { add_meta_box('wp-ultimo-activity-stream', __('WP Multisite WaaS - Activity Stream', 'wp-ultimo'), array($this, 'output_widget_activity_stream'), $this->screen_id, 'normal', 'high'); - \WP_Ultimo\UI\Tours::get_instance()->create_tour('dashboard', array( + \WP_Ultimo\UI\Tours::get_instance()->create_tour( + 'dashboard', array( - 'id' => 'welcome', - 'title' => __('Welcome!', 'wp-ultimo'), - 'text' => array( - __('Welcome to your new network dashboard!', 'wp-ultimo'), - __('You will notice that WP Multisite WaaS adds a couple of useful widgets here so you can keep an eye on how your network is doing.', 'wp-ultimo'), + array( + 'id' => 'welcome', + 'title' => __('Welcome!', 'wp-ultimo'), + 'text' => array( + __('Welcome to your new network dashboard!', 'wp-ultimo'), + __('You will notice that WP Multisite WaaS adds a couple of useful widgets here so you can keep an eye on how your network is doing.', 'wp-ultimo'), + ), ), - ), - array( - 'id' => 'finish-your-setup', - 'title' => __('Finish your setup', 'wp-ultimo'), - 'text' => array( - __('You still have a couple of things to do configuration-wise. Check the steps on this list and make sure you complete them all.', 'wp-ultimo'), + array( + 'id' => 'finish-your-setup', + 'title' => __('Finish your setup', 'wp-ultimo'), + 'text' => array( + __('You still have a couple of things to do configuration-wise. Check the steps on this list and make sure you complete them all.', 'wp-ultimo'), + ), + 'attachTo' => array( + 'element' => '#wp-ultimo-setup', + 'on' => 'left', + ), ), - 'attachTo' => array( - 'element' => '#wp-ultimo-setup', - 'on' => 'left', + array( + 'id' => 'wp-ultimo-menu', + 'title' => __('Our home', 'wp-ultimo'), + 'text' => array( + __('You can always find WP Multisite WaaS settings and other pages under our menu item, here on the Network-level dashboard. 😃', 'wp-ultimo'), + ), + 'attachTo' => array( + 'element' => '.toplevel_page_wp-ultimo', + 'on' => 'left', + ), ), - ), - array( - 'id' => 'wp-ultimo-menu', - 'title' => __('Our home', 'wp-ultimo'), - 'text' => array( - __('You can always find WP Multisite WaaS settings and other pages under our menu item, here on the Network-level dashboard. 😃', 'wp-ultimo'), - ), - 'attachTo' => array( - 'element' => '.toplevel_page_wp-ultimo', - 'on' => 'left', - ), - ), - )); - - } // end register_network_widgets; + ) + ); + } /** * Adds the customer's site's dashboard widgets. @@ -143,10 +141,8 @@ class Dashboard_Widgets { $screen = get_current_screen(); if (wu_get_current_site()->get_type() !== 'customer_owned') { - return; - - } // end if; + } /* * Account Summary @@ -162,21 +158,16 @@ class Dashboard_Widgets { * Maintenance Mode Widget */ if (wu_get_setting('maintenance_mode')) { - \WP_Ultimo\UI\Site_Maintenance_Element::get_instance()->as_metabox($screen->id, 'side'); - - } // end if; + } /* * Domain Mapping Widget */ if (wu_get_setting('enable_domain_mapping') && wu_get_setting('custom_domains')) { - \WP_Ultimo\UI\Domain_Mapping_Element::get_instance()->as_metabox($screen->id, 'side'); - - } // end if; - - } // end register_widgets; + } + } /** * Widget First Steps Output. @@ -201,13 +192,16 @@ class Dashboard_Widgets { 'title' => __('Payment Method', 'wp-ultimo'), 'desc' => __('You will need to configure at least one payment gateway to be able to receive money from your customers.', 'wp-ultimo'), 'action_label' => __('Add a Payment Method', 'wp-ultimo'), - 'action_link' => wu_network_admin_url('wp-ultimo-settings', array( - 'tab' => 'payment-gateways', - )), - 'done' => !empty(wu_get_active_gateways()), + 'action_link' => wu_network_admin_url( + 'wp-ultimo-settings', + array( + 'tab' => 'payment-gateways', + ) + ), + 'done' => ! empty(wu_get_active_gateways()), ), 'your-first-customer' => array( - 'done' => !empty(wu_get_customers()), + 'done' => ! empty(wu_get_customers()), 'title' => __('Your First Customer', 'wp-ultimo'), 'desc' => __('Open the link below in an incognito tab and go through your newly created signup form.', 'wp-ultimo'), 'action_link' => wp_registration_url(), @@ -215,19 +209,24 @@ class Dashboard_Widgets { ), ); - $done = \Arrch\Arrch::find($steps, array( - 'where' => array( - array('done', true), - ), - )); + $done = \Arrch\Arrch::find( + $steps, + array( + 'where' => array( + array('done', true), + ), + ) + ); - wu_get_template('dashboard-widgets/first-steps', array( - 'steps' => $steps, - 'percentage' => round(count($done) / count($steps) * 100), - 'all_done' => count($done) === count($steps), - )); - - } // end output_widget_first_steps; + wu_get_template( + 'dashboard-widgets/first-steps', + array( + 'steps' => $steps, + 'percentage' => round(count($done) / count($steps) * 100), + 'all_done' => count($done) === count($steps), + ) + ); + } /** * Widget Activity Stream Output. @@ -239,8 +238,7 @@ class Dashboard_Widgets { public function output_widget_activity_stream() { wu_get_template('dashboard-widgets/activity-stream'); - - } // end output_widget_activity_stream; + } /** * Widget Summary Output @@ -253,22 +251,26 @@ class Dashboard_Widgets { /* * Get today's signups. */ - $signups = wu_get_customers(array( - 'count' => true, - 'date_query' => array( - 'column' => 'date_registered', - 'after' => 'today', - 'inclusive' => true, - ), - )); + $signups = wu_get_customers( + array( + 'count' => true, + 'date_query' => array( + 'column' => 'date_registered', + 'after' => 'today', + 'inclusive' => true, + ), + ) + ); - wu_get_template('dashboard-widgets/summary', array( - 'signups' => $signups, - 'mrr' => wu_calculate_mrr(), - 'gross_revenue' => wu_calculate_revenue('today'), - )); - - } // end output_widget_summary; + wu_get_template( + 'dashboard-widgets/summary', + array( + 'signups' => $signups, + 'mrr' => wu_calculate_mrr(), + 'gross_revenue' => wu_calculate_revenue('today'), + ) + ); + } /** * Process Ajax Filters for rss. @@ -278,20 +280,22 @@ class Dashboard_Widgets { */ public function process_ajax_fetch_rss() { - $atts = wp_parse_args($_GET, array( - 'url' => 'https://community.wpultimo.com/topics/feed', - 'title' => __('Forum Discussions', 'wp-ultimo'), - 'items' => 3, - 'show_summary' => 1, - 'show_author' => 0, - 'show_date' => 1, - )); + $atts = wp_parse_args( + $_GET, + array( + 'url' => 'https://community.wpultimo.com/topics/feed', + 'title' => __('Forum Discussions', 'wp-ultimo'), + 'items' => 3, + 'show_summary' => 1, + 'show_author' => 0, + 'show_date' => 1, + ) + ); wp_widget_rss_output($atts); exit; - - } // end process_ajax_fetch_rss; + } /** * Process Ajax Filters for rss. @@ -303,22 +307,27 @@ class Dashboard_Widgets { check_ajax_referer('wu_activity_stream'); - $count = wu_get_events(array( - 'count' => true, - 'number' => -1, - )); + $count = wu_get_events( + array( + 'count' => true, + 'number' => -1, + ) + ); - $data = wu_get_events(array( - 'offset' => (wu_request('page', 1) - 1) * 5, - 'number' => 5, - )); + $data = wu_get_events( + array( + 'offset' => (wu_request('page', 1) - 1) * 5, + 'number' => 5, + ) + ); - wp_send_json_success(array( - 'events' => $data, - 'count' => $count, - )); - - } // end process_ajax_fetch_events; + wp_send_json_success( + array( + 'events' => $data, + 'count' => $count, + ) + ); + } /** * Handle ajax endpoint to generate table CSV. @@ -339,8 +348,7 @@ class Dashboard_Widgets { wu_generate_csv($file_name, $data); die; - - } // end handle_table_csv; + } /** * Get the registered widgets. @@ -354,11 +362,9 @@ class Dashboard_Widgets { ob_start(); - if (!function_exists('wp_add_dashboard_widget')) { - + if ( ! function_exists('wp_add_dashboard_widget')) { require_once ABSPATH . '/wp-admin/includes/dashboard.php'; - - } // end if; + } do_action('wp_network_dashboard_setup'); // phpcs:ignore @@ -374,22 +380,20 @@ class Dashboard_Widgets { ); foreach ($dashboard_widgets as $position => $priorities) { - foreach ($priorities as $priority => $widgets) { - foreach ($widgets as $widget_key => $widget) { - if (empty($widget) || wu_get_isset($widget, 'title') === false) { - continue; + } - } // end if; - - $key = implode(':', array( - $position, - $priority, - $widget_key, - )); + $key = implode( + ':', + array( + $position, + $priority, + $widget_key, + ) + ); /** * For some odd reason, in some cases, $options @@ -397,22 +401,15 @@ class Dashboard_Widgets { * This checks prevents that error from happening. * I don't know why $options would ever be a boolean here, though. */ - if (!is_array($options)) { - + if ( ! is_array($options)) { $options = array(); + } - } // end if; - - $options[$key] = $widget['title']; - - } // end foreach; - - } // end foreach; - - } // end foreach; + $options[ $key ] = $widget['title']; + } + } + } return $options; - - } // end get_registered_dashboard_widgets; - -} // end class Dashboard_Widgets; + } +} diff --git a/inc/class-documentation.php b/inc/class-documentation.php index dafe27c..c4a5ac0 100644 --- a/inc/class-documentation.php +++ b/inc/class-documentation.php @@ -84,8 +84,7 @@ class Documentation { $links['multiple-accounts'] = 'https://help.wpultimo.com/article/303-accounts-taken-care-of-with-wp-ultimo-multiple-accounts'; $this->links = apply_filters('wu_documentation_links_list', $links); - - } // end init; + } /** * Checks if a link exists. @@ -98,8 +97,7 @@ class Documentation { public function has_link($slug) { return (bool) $this->get_link($slug, false); - - } // end has_link; + } /** * Retrieves a link registered @@ -125,8 +123,7 @@ class Documentation { * @param string $default_link The default link registered */ return apply_filters('wu_documentation_get_link', $link, $slug, $this->default_link); - - } // end get_link; + } /** * Add a new link to the list of links available for reference @@ -138,8 +135,6 @@ class Documentation { */ public function register_link($slug, $link) { - $this->links[$slug] = $link; - - } // end register_link; - -} // end class Documentation; + $this->links[ $slug ] = $link; + } +} diff --git a/inc/class-domain-mapping.php b/inc/class-domain-mapping.php index 850e5c6..e580c73 100644 --- a/inc/class-domain-mapping.php +++ b/inc/class-domain-mapping.php @@ -48,16 +48,11 @@ class Domain_Mapping { public function init() { if ($this->should_skip_checks()) { - $this->startup(); - } else { - $this->maybe_startup(); - - } // end if; - - } // end init; + } + } /** * Check if we should skip checks before running mapping functions. @@ -68,8 +63,7 @@ class Domain_Mapping { public static function should_skip_checks() { return defined('WP_ULTIMO_DOMAIN_MAPPING_SKIP_CHECKS') && WP_ULTIMO_DOMAIN_MAPPING_SKIP_CHECKS; - - } // end should_skip_checks; + } /** * Run the checks to make sure the requirements for Domain mapping are in place and execute it. @@ -82,34 +76,27 @@ class Domain_Mapping { * Don't run during installation... */ if (defined('WP_INSTALLING') && $_SERVER['SCRIPT_NAME'] !== '/wp-activate.php') { - return; - - } // end if; + } /* * Make sure we got loaded in the sunrise stage. */ if (did_action('muplugins_loaded')) { - return; - - } // end if; + } $is_enabled = (bool) wu_get_setting_early('enable_domain_mapping'); if ($is_enabled === false) { - return; - - } // end if; + } /* * Start the engines! */ $this->startup(); - - } // end maybe_startup; + } /** * Actual handles domain mapping functionality. @@ -122,12 +109,10 @@ class Domain_Mapping { * Adds the necessary tables to the $wpdb global. */ if (empty($GLOBALS['wpdb']->wu_dmtable)) { - $GLOBALS['wpdb']->wu_dmtable = $GLOBALS['wpdb']->base_prefix . 'wu_domain_mappings'; $GLOBALS['wpdb']->ms_global_tables[] = 'wu_domain_mappings'; - - } // end if; + } // Ensure cache is shared wp_cache_add_global_groups(array('domain_mappings', 'network_mappings')); @@ -153,23 +138,27 @@ class Domain_Mapping { * On WP Multisite WaaS 1.X builds we used Mercator. The Mercator actions and filters are now deprecated. */ if (has_action('mercator_load')) { - do_action_deprecated('mercator_load', array(), '2.0.0', 'wu_domain_mapping_load'); + } - } // end if; + add_action( + 'wu_sso_site_allowed_domains', + function ($list, $site_id): array { - add_action('wu_sso_site_allowed_domains', function($list, $site_id): array { + $domains = wu_get_domains( + array( + 'active' => true, + 'blog_id' => $site_id, + 'stage__not_in' => \WP_Ultimo\Models\Domain::INACTIVE_STAGES, + 'fields' => 'domain', + ) + ); - $domains = wu_get_domains(array( - 'active' => true, - 'blog_id' => $site_id, - 'stage__not_in' => \WP_Ultimo\Models\Domain::INACTIVE_STAGES, - 'fields' => 'domain', - )); - - return array_merge($list, $domains); - - }, 10, 2); + return array_merge($list, $domains); + }, + 10, + 2 + ); /** * Fired after our core Domain Mapping has been loaded @@ -177,8 +166,7 @@ class Domain_Mapping { * Hook into this to handle any add-on functionality. */ do_action('wu_domain_mapping_load'); - - } // end startup; + } /** * Checks if an origin is a mapped domain. @@ -192,31 +180,24 @@ class Domain_Mapping { */ public function add_mapped_domains_as_allowed_origins($origin) { - if (!function_exists('wu_get_domain_by_domain')) { - + if ( ! function_exists('wu_get_domain_by_domain')) { return; - - } // end if; + } if (empty($origin) && wp_doing_ajax()) { - $origin = wu_get_current_url(); - - } // end if; + } $the_domain = wp_parse_url($origin, PHP_URL_HOST); $domain = wu_get_domain_by_domain($the_domain); if ($domain) { - return $domain->get_domain(); - - } // end if; + } return $origin; - - } // end add_mapped_domains_as_allowed_origins; + } /** * Fixes the SSO target site in cases of domain mapping. @@ -229,21 +210,16 @@ class Domain_Mapping { */ public function fix_sso_target_site($target_site, $domain) { - if (!$target_site || !$target_site->blog_id) { - + if ( ! $target_site || ! $target_site->blog_id) { $mapping = \WP_Ultimo\Models\Domain::get_by_domain($domain); if ($mapping) { - $target_site = get_site($mapping->get_site_id()); - - } // end if; - - } // end if; + } + } return $target_site; - - } // end fix_sso_target_site; + } /** * Returns both the naked and www. version of the given domain @@ -256,62 +232,51 @@ class Domain_Mapping { public function get_www_and_nowww_versions($domain) { if (strncmp($domain, 'www.', strlen('www.')) === 0) { - $www = $domain; $nowww = substr($domain, 4); - } else { - $nowww = $domain; $www = 'www.' . $domain; - - } // end if; + } return array($nowww, $www); - - } // end get_www_and_nowww_versions; - /** - * Checks if we have a site associated with the domain being accessed - * - * This method tries to find a site on the network that has a mapping related to the current - * domain being accessed. This uses the default WordPress mapping functionality, added on 4.5. - * - * @since 2.0.0 - * - * @param null|false|\WP_Site $site Site object being searched by path. - * @param string $domain Domain to search for. - * @return null|false|\WP_Site - */ - public function check_domain_mapping($site, $domain) { + } + /** + * Checks if we have a site associated with the domain being accessed + * + * This method tries to find a site on the network that has a mapping related to the current + * domain being accessed. This uses the default WordPress mapping functionality, added on 4.5. + * + * @since 2.0.0 + * + * @param null|false|\WP_Site $site Site object being searched by path. + * @param string $domain Domain to search for. + * @return null|false|\WP_Site + */ + public function check_domain_mapping($site, $domain) { // Have we already matched? (Allows other plugins to match first) - if (!empty($site)) { - + if ( ! empty($site)) { return $site; - - } // end if; + } $domains = $this->get_www_and_nowww_versions($domain); $mapping = Domain::get_by_domain($domains); if (empty($mapping) || is_wp_error($mapping)) { - return $site; - - } // end if; + } if (has_filter('mercator.use_mapping')) { - $deprecated_args = array( $mapping->is_active(), $mapping, - $domain + $domain, ); $is_active = apply_filters_deprecated('mercator.use_mapping', $deprecated_args, '2.0.0', 'wu_use_domain_mapping'); - - } // end if; + } /** * Determine whether a mapping should be used @@ -327,20 +292,16 @@ class Domain_Mapping { $is_active = apply_filters('wu_use_domain_mapping', $mapping->is_active(), $mapping, $domain); // Ignore non-active mappings - if (!$is_active) { - + if ( ! $is_active) { return $site; - - } // end if; + } // Fetch the actual data for the site $mapped_site = $mapping->get_site(); if (empty($mapped_site)) { - return $site; - - } // end if; + } /* * Note: This is only for backwards compatibility with WPMU Domain Mapping, @@ -352,33 +313,26 @@ class Domain_Mapping { * Decide if we use SSL */ if ($mapping->is_secure()) { - force_ssl_admin(true); - - } // end if; + } $_site = $site; if (is_a($mapped_site, '\WP_Site')) { - $this->original_url = $mapped_site->domain . $mapped_site->path; $_site = $mapped_site; - } elseif (is_a($mapped_site, '\WP_Ultimo\Models\Site')) { - $this->original_url = $mapped_site->get_domain() . $mapped_site->get_path(); $_site = $mapped_site->to_wp_site(); - - } // end if; + } /* * We found a site based on the mapped domain =) */ return $_site; - - } // end check_domain_mapping; + } /** * Clear mappings for a site when it's deleted @@ -390,13 +344,10 @@ class Domain_Mapping { $mappings = Domain::get_by_site($site->blog_id); if (empty($mappings)) { - return; - - } // end if; + } foreach ($mappings as $mapping) { - $error = $mapping->delete(); if (is_wp_error($error)) { @@ -405,12 +356,9 @@ class Domain_Mapping { $message = sprintf(__('Unable to delete mapping %1$d for site %2$d', 'wp-ultimo'), $mapping->get_id(), $site->blog_id); trigger_error($message, E_USER_WARNING); - - } // end if; - - } // end foreach; - - } // end clear_mappings_on_delete; + } + } + } /** * Register filters for URLs, if we've mapped @@ -422,11 +370,9 @@ class Domain_Mapping { $current_site = $GLOBALS['current_blog']; - if (!$current_site) { - + if ( ! $current_site) { return; - - } // end if; + } $real_domain = $current_site->domain; $domain = $_SERVER['HTTP_HOST']; @@ -435,18 +381,15 @@ class Domain_Mapping { // Domain hasn't been mapped return; - - } // end if; + } $domains = $this->get_www_and_nowww_versions($domain); $mapping = Domain::get_by_domain($domains); if (empty($mapping) || is_wp_error($mapping)) { - return; - - } // end if; + } $this->current_mapping = $mapping; @@ -465,11 +408,9 @@ class Domain_Mapping { // If on network site, also filter network urls if (is_main_site()) { - add_filter('network_site_url', array($this, 'mangle_url'), -10, 3); add_filter('network_home_url', array($this, 'mangle_url'), -10, 3); - - } // end if; + } add_filter('jetpack_sync_home_url', array($this, 'mangle_url')); add_filter('jetpack_sync_site_url', array($this, 'mangle_url')); @@ -491,8 +432,7 @@ class Domain_Mapping { * @return void */ do_action('wu_domain_mapping_register_filters', array($this, 'mangle_url'), $this); - - } // end register_mapped_filters; + } /** * Apply the replace URL to URL filters provided by other plugins. @@ -504,19 +444,18 @@ class Domain_Mapping { */ public static function apply_mapping_to_url($hooks) { - add_action('wu_domain_mapping_register_filters', function($callback) use ($hooks) { + add_action( + 'wu_domain_mapping_register_filters', + function ($callback) use ($hooks) { - $hooks = (array) $hooks; + $hooks = (array) $hooks; - foreach ($hooks as $hook) { - - add_filter($hook, $callback); - - } // end foreach; - - }); - - } // end apply_mapping_to_url; + foreach ($hooks as $hook) { + add_filter($hook, $callback); + } + } + ); + } /** * Replaces the URL. @@ -530,10 +469,8 @@ class Domain_Mapping { public function replace_url($url, $current_mapping = null) { if ($current_mapping === null) { - $current_mapping = $this->current_mapping; - - } // end if; + } // Replace the domain $domain_base = parse_url($url, PHP_URL_HOST); @@ -545,18 +482,15 @@ class Domain_Mapping { * Another try if we don't need to deal with subdirectory. */ if ($mangled === $url && $this->current_mapping !== $current_mapping) { - $domain = rtrim($domain_base, '/'); $regex = '#^(\w+://)' . preg_quote($domain, '#') . '#i'; $mangled = preg_replace($regex, '${1}' . $current_mapping->get_domain(), $url); - - } // end if; + } $mangled = wu_replace_scheme($mangled, $current_mapping->is_secure() ? 'https://' : 'http://'); return $mangled; - - } // end replace_url; + } /** * Mangle the home URL to give our primary domain @@ -570,22 +504,17 @@ class Domain_Mapping { public function mangle_url($url, $path = '/', $orig_scheme = '', $site_id = 0) { if (empty($site_id)) { - $site_id = get_current_blog_id(); - - } // end if; + } $current_mapping = $this->current_mapping; if (empty($current_mapping) || $site_id !== $current_mapping->get_site_id()) { - return $url; - - } // end if; + } return $this->replace_url($url); - - } // end mangle_url; + } /** * Adds a fix to the srcset URLs when we need that domain mapped @@ -597,13 +526,9 @@ class Domain_Mapping { public function fix_srcset($sources) { foreach ($sources as &$source) { - - $sources[$source['value']]['url'] = $this->replace_url($sources[$source['value']]['url']); - - } // end foreach; + $sources[ $source['value'] ]['url'] = $this->replace_url($sources[ $source['value'] ]['url']); + } return $sources; - - } // end fix_srcset; - -} // end class Domain_Mapping; + } +} diff --git a/inc/class-faker.php b/inc/class-faker.php index 551f81d..e897d67 100644 --- a/inc/class-faker.php +++ b/inc/class-faker.php @@ -45,8 +45,7 @@ class Faker { public function __construct() { $this->faker = Lib_Faker\Factory::create(); - - } // end __construct; + } /** * Get the faker generator. @@ -57,8 +56,7 @@ class Faker { private function get_faker() { return $this->faker; - - } // end get_faker; + } /** * Get the faker generator. @@ -69,8 +67,7 @@ class Faker { public function generate() { return $this->get_faker(); - - } // end generate; + } /** * Get the fake data generated. @@ -82,7 +79,6 @@ class Faker { public function get_fake_data_generated($model = '') { if (empty($this->fake_data_generated)) { - $this->fake_data_generated = array( 'customers' => array(), 'products' => array(), @@ -97,25 +93,18 @@ class Faker { 'payments' => array(), 'sites' => array(), ); - - } // end if; + } if (empty($model)) { - return $this->fake_data_generated; + } - } // end if; - - if (isset($this->fake_data_generated[$model])) { - - return $this->fake_data_generated[$model]; - + if (isset($this->fake_data_generated[ $model ])) { + return $this->fake_data_generated[ $model ]; } else { - return array(); - - } // end if; - } // end get_fake_data_generated; + } + } /** * Set the fake data generated. @@ -128,9 +117,8 @@ class Faker { $this->get_fake_data_generated(); - $this->fake_data_generated[$model][] = $value; - - } // end set_fake_data_generated; + $this->fake_data_generated[ $model ][] = $value; + } /** * Get the option "debug_faker" with the data generated by faker. @@ -140,22 +128,24 @@ class Faker { */ public function get_option_debug_faker() { - return wu_get_option('debug_faker', array( - 'customers' => array(), - 'products' => array(), - 'memberships' => array(), - 'domains' => array(), - 'events' => array(), - 'discount_codes' => array(), - 'checkout_forms' => array(), - 'emails' => array(), - 'broadcasts' => array(), - 'webhooks' => array(), - 'payments' => array(), - 'sites' => array(), - )); - - } // end get_option_debug_faker; + return wu_get_option( + 'debug_faker', + array( + 'customers' => array(), + 'products' => array(), + 'memberships' => array(), + 'domains' => array(), + 'events' => array(), + 'discount_codes' => array(), + 'checkout_forms' => array(), + 'emails' => array(), + 'broadcasts' => array(), + 'webhooks' => array(), + 'payments' => array(), + 'sites' => array(), + ) + ); + } /** * Get random data. @@ -167,42 +157,31 @@ class Faker { private function get_random_data($model) { if ($model) { - $faker = $this->get_faker(); $data_saved = wu_get_isset($this->get_option_debug_faker(), $model, array()); $data_in_memory = $this->get_fake_data_generated($model); - if (!empty($data_saved) && !empty($data_in_memory)) { - + if ( ! empty($data_saved) && ! empty($data_in_memory)) { $data_saved_or_in_memory = $faker->randomElement(array('data_saved', 'data_in_memory')); $data_index = $faker->numberBetween(0, count(${$data_saved_or_in_memory}) - 1); - return ${$data_saved_or_in_memory}[$data_index]; - - } elseif (!empty($data_saved)) { - + return ${$data_saved_or_in_memory}[ $data_index ]; + } elseif ( ! empty($data_saved)) { $data_index = $faker->numberBetween(0, count($data_saved) - 1); - return $data_saved[$data_index]; - - } elseif (!empty($data_in_memory)) { - + return $data_saved[ $data_index ]; + } elseif ( ! empty($data_in_memory)) { $data_index = $faker->numberBetween(0, count($data_in_memory) - 1); - return $data_in_memory[$data_index]; - + return $data_in_memory[ $data_index ]; } else { - return false; - - } // end if; - - } // end if; - - } // end get_random_data; + } + } + } /** * Get random customer. @@ -217,32 +196,22 @@ class Faker { $customer = $this->get_random_data('customers'); - if (!$customer) { - + if ( ! $customer) { if ($create_if_not_exist) { - $this->generate_fake_customers(); $customer = $this->get_random_data('customers'); - } else { - return false; - - } // end if; - - } // end if; + } + } if (is_object($customer)) { - return $customer; - } else { - return wu_get_customer($customer); - - } // end if; - } // end get_random_customer; + } + } /** * Get random product. @@ -257,33 +226,22 @@ class Faker { $product = $this->get_random_data('products'); - if (!$product) { - + if ( ! $product) { if ($create_if_not_exist) { - $this->generate_fake_products(); $product = $this->get_random_data('products'); - } else { - return false; - - } // end if; - - } // end if; + } + } if (is_object($product)) { - return $product; - } else { - return wu_get_product($product); - - } // end if; - - } // end get_random_product; + } + } /** * Get random membership. @@ -297,23 +255,16 @@ class Faker { $membership = $this->get_random_data('memberships'); - if (!$membership) { - + if ( ! $membership) { return false; - - } // end if; + } if (is_object($membership)) { - return $membership; - } else { - return wu_get_membership($membership); - - } // end if; - - } // end get_random_membership; + } + } /** * Get random site. @@ -327,23 +278,16 @@ class Faker { $site = $this->get_random_data('sites'); - if (!$site) { - + if ( ! $site) { return false; - - } // end if; + } if (is_object($site)) { - return $site; - } else { - return wu_get_site($site); - - } // end if; - - } // end get_random_site; + } + } /** * Get random payment. @@ -357,23 +301,16 @@ class Faker { $payment = $this->get_random_data('payments'); - if (!$payment) { - + if ( ! $payment) { return false; - - } // end if; + } if (is_object($payment)) { - return $payment; - } else { - return wu_get_payment($payment); - - } // end if; - - } // end get_random_payment; + } + } /** * Generate a faker customer. @@ -385,47 +322,42 @@ class Faker { public function generate_fake_customers($number = 1) { for ($i = 0; $i < $number; $i++) { - $user_name = $this->get_faker()->userName; $user_email = $this->get_faker()->safeEmail; - if (!username_exists($user_name) && !email_exists($user_email)) { - - $password = wp_generate_password( 12, false ); + if ( ! username_exists($user_name) && ! email_exists($user_email)) { + $password = wp_generate_password(12, false); $user_id = wp_create_user($user_name, $password, $user_email); remove_user_from_blog($user_id); - $customer = wu_create_customer(array( - 'user_id' => $user_id, - 'vip' => $this->get_faker()->boolean, - 'date_registered' => $this->get_faker()->dateTimeThisYear()->format('Y-m-d H:i:s'), - 'email_verification' => $this->get_faker()->randomElement(array( - 'none', - 'pending', - 'verified' - )), - 'meta' => array( - 'ip_country' => $this->get_faker()->countryCode, - ), - )); + $customer = wu_create_customer( + array( + 'user_id' => $user_id, + 'vip' => $this->get_faker()->boolean, + 'date_registered' => $this->get_faker()->dateTimeThisYear()->format('Y-m-d H:i:s'), + 'email_verification' => $this->get_faker()->randomElement( + array( + 'none', + 'pending', + 'verified', + ) + ), + 'meta' => array( + 'ip_country' => $this->get_faker()->countryCode, + ), + ) + ); if (is_wp_error($customer)) { - throw new \Exception($customer->get_error_message()); - } else { - $this->set_fake_data_generated('customers', $customer); - - } // end if; - - } // end if; - - } // end for; - - } // end generate_fake_customers; + } + } + } + } /** * Generate a faker product. @@ -440,22 +372,21 @@ class Faker { $product_type_options = array( 'plan', 'package', - 'service' + 'service', ); $pricing_type_options = array( 'paid', 'free', - 'contact_us' + 'contact_us', ); $duration_unit_options = array( 'day', 'week', 'month', - 'year' + 'year', ); for ($i = 0; $i < $number; $i++) { - $product_data = array(); $type = $faker->optional(0.5, $product_type_options[0])->randomElement($product_type_options); @@ -480,18 +411,12 @@ class Faker { $product = wu_create_product($product_data); if (is_wp_error($product)) { - throw new \Exception($product->get_error_message()); - } else { - $this->set_fake_data_generated('products', $product); - - } // end if; - - } // end for; - - } // end generate_fake_products; + } + } + } /** * Generate a faker membership. @@ -505,7 +430,6 @@ class Faker { $faker = $this->get_faker(); for ($i = 0; $i < $number; $i++) { - $customer = $this->get_random_customer(true); $product = $this->get_random_product(true); @@ -514,7 +438,7 @@ class Faker { 'active', 'on-hold', 'expired', - 'cancelled' + 'cancelled', ); $membership_data = array(); @@ -536,18 +460,12 @@ class Faker { $membership = wu_create_membership($membership_data); if (is_wp_error($membership)) { - throw new \Exception($membership->get_error_message()); - } else { - $this->set_fake_data_generated('memberships', $membership); - - } // end if; - - } // end for; - - } // end generate_fake_memberships; + } + } + } /** * Generate a fake domain. @@ -562,7 +480,7 @@ class Faker { $stage_options = array( 'checking-dns', 'checking-ssl-cert', - 'done' + 'done', ); $stage_checking_dns = $stage_options[0]; @@ -570,31 +488,26 @@ class Faker { $stage = $faker->optional(0.35, $stage_checking_dns)->randomElement($stage_options); for ($i = 0; $i < $number; $i++) { - $site = $this->get_random_site(); - $domain = wu_create_domain(array( - 'domain' => $faker->domainName, // phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase + $domain = wu_create_domain( + array( + 'domain' => $faker->domainName, // phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 'stage' => $stage, 'blog_id' => $site ? $site->get_blog_id() : 0, 'primary_domain' => $faker->boolean(25), 'active' => $faker->boolean(75), - 'secure' => $faker->boolean(25) - )); + 'secure' => $faker->boolean(25), + ) + ); if (is_wp_error($domain)) { - throw new \Exception($domain->get_error_message()); - } else { - $this->set_fake_data_generated('domains', $domain); - - } // end if; - - } // end for; - - } // end generate_fake_domain; + } + } + } /** * Generate a fake event. @@ -619,7 +532,6 @@ class Faker { ); for ($i = 0; $i < $number; $i++) { - $membership = $this->get_random_membership(true); $author_id = $membership->get_id(); @@ -638,18 +550,12 @@ class Faker { $event_data = wu_create_event($event_data); if (is_wp_error($event_data)) { - throw new \Exception($event_data->get_error_message()); - } else { - $this->set_fake_data_generated('events', $event_data); - - } // end if; - - } // end for; - - } // end generate_fake_events; + } + } + } /** * Generate a fake discount code. @@ -668,7 +574,6 @@ class Faker { $type_options_percentage = $type_options[0]; for ($i = 0; $i < $number; $i++) { - $name = rtrim((string) $faker->sentence(2), '.'); $value = $faker->numberBetween(1, 25); $code = strtoupper(substr(implode('', explode(' ', $name)), 0, 15)) . $value . 'OFF'; @@ -677,33 +582,29 @@ class Faker { $start_date = $faker->dateTimeBetween('-1 weeks', 'now', 'UTC'); $expiration_date = $faker->dateTimeBetween('now', '+4 weeks', 'UTC'); - $discount_code = wu_create_discount_code(array( - 'name' => $name, - 'description' => $faker->sentence(), - 'code' => $code, - 'max_uses' => $faker->numberBetween(1, 50), - 'type' => $type, - 'value' => $value, - 'setup_fee_type' => $setup_fee_type, - 'setup_fee_value' => $faker->numberBetween(1, 20), - 'date_start' => $start_date->format('Y-m-d H:i:s'), - 'date_expiration' => $expiration_date->format('Y-m-d H:i:s'), - 'active' => true - )); + $discount_code = wu_create_discount_code( + array( + 'name' => $name, + 'description' => $faker->sentence(), + 'code' => $code, + 'max_uses' => $faker->numberBetween(1, 50), + 'type' => $type, + 'value' => $value, + 'setup_fee_type' => $setup_fee_type, + 'setup_fee_value' => $faker->numberBetween(1, 20), + 'date_start' => $start_date->format('Y-m-d H:i:s'), + 'date_expiration' => $expiration_date->format('Y-m-d H:i:s'), + 'active' => true, + ) + ); if (is_wp_error($discount_code)) { - throw new \Exception($discount_code->get_error_message()); - } else { - $this->set_fake_data_generated('discount_codes', $discount_code); - - } // end if; - - } // end for; - - } // end generate_fake_discount_code; + } + } + } /** * Generate a fake checkout form. @@ -720,7 +621,6 @@ class Faker { $checkout_form_slug = str_replace(' ', '-', $checkout_form_name); for ($i = 0; $i < $number; $i++) { - $checkout_form_data = array( 'name' => $checkout_form_name, 'slug' => strtolower($checkout_form_slug), @@ -735,18 +635,12 @@ class Faker { $checkout_form = wu_create_checkout_form($checkout_form_data); if (is_wp_error($checkout_form)) { - throw new \Exception($checkout_form->get_error_message()); - } else { - $this->set_fake_data_generated('checkout_forms', $checkout_form); - - } // end if; - - } // end for; - - } // end generate_fake_checkout_form; + } + } + } /** * Generate a fake email. @@ -770,7 +664,6 @@ class Faker { ); for ($i = 0; $i < $number; $i++) { - $email_title = rtrim((string) $faker->sentence(2), '.'); $email_slug = strtolower(str_replace(' ', '-', $email_title)); $user_name = $this->get_faker()->userName; @@ -798,18 +691,12 @@ class Faker { $email = wu_create_email($email_data); if (is_wp_error($email)) { - throw new \Exception($email->get_error_message()); - } else { - $this->set_fake_data_generated('emails', $email); - - } // end if; - - } // end for; - - } // end generate_fake_email; + } + } + } /** * Generate a fake broadcast. @@ -835,7 +722,6 @@ class Faker { ); for ($i = 0; $i < $number; $i++) { - $broadcast_data = array( 'notice_type' => $faker->randomElement($notice_type_optinos), 'status' => 'publish', @@ -848,18 +734,12 @@ class Faker { $broadcast = wu_create_broadcast($broadcast_data); if (is_wp_error($broadcast)) { - throw new \Exception($broadcast->get_error_message()); - } else { - $this->set_fake_data_generated('broadcasts', $broadcast); - - } // end if; - - } // end for; - - } // end generate_fake_broadcast; + } + } + } /** * Generate a fake webhook. @@ -883,7 +763,6 @@ class Faker { ); for ($i = 0; $i < $number; $i++) { - $webhook_data = array( 'name' => rtrim((string) $faker->sentence(2), '.'), 'webhook_url' => 'https://' . $faker->domainName, @@ -892,24 +771,18 @@ class Faker { 'active' => $faker->boolean(75), 'hidden' => 0, 'integration' => rtrim((string) $faker->sentence(3), '.'), - 'date_last_failed' => '' + 'date_last_failed' => '', ); $webhook = wu_create_webhook($webhook_data); if (is_wp_error($webhook)) { - throw new \Exception($webhook->get_error_message()); - } else { - $this->set_fake_data_generated('webhooks', $webhook); - - } // end if; - - } // end for; - - } // end generate_fake_webhook; + } + } + } /** * Generate a fake payment. @@ -940,7 +813,6 @@ class Faker { $memberships = $this->get_fake_data_generated('memberships'); for ($i = 0; $i < $number; $i++) { - $membership = $this->get_random_membership(); $payment_data = array( @@ -967,20 +839,14 @@ class Faker { $payment = wu_create_payment($payment_data); if (is_wp_error($payment)) { - throw new \Exception($payment->get_error_message()); - } else { - $payment->recalculate_totals()->save(); $this->set_fake_data_generated('payments', $payment); - - } // end if; - - } // end for; - - } // end generate_fake_payment; + } + } + } /** * Generate a faker site. @@ -1015,31 +881,21 @@ class Faker { $site_data['public'] = $faker->boolean(75); if ($type_customer_owned === $type) { - $membership = $this->get_random_membership(); if ($membership) { - $site_data['customer_id'] = $membership->get_customer_id(); $site_data['membership_id'] = $membership->get_id(); - - } // end if; - } // end if; + } + } $site = wu_create_site($site_data); if (is_wp_error($site)) { - throw new \Exception($site->get_error_message()); - } else { - $this->set_fake_data_generated('sites', $site); - - } // end if; - - } // end for; - - } // end generate_fake_site; - -} // end class Faker; + } + } + } +} diff --git a/inc/class-geolocation.php b/inc/class-geolocation.php index 90aa597..a08df71 100644 --- a/inc/class-geolocation.php +++ b/inc/class-geolocation.php @@ -68,7 +68,7 @@ class Geolocation { */ private static function supports_geolite2(): bool { return false; // version_compare( PHP_VERSION, '5.4.0', '>=' ); - } // end supports_geolite2; + } /** * Check if geolocation is enabled. * @@ -77,7 +77,7 @@ class Geolocation { */ private static function is_geolocation_enabled($current_settings ): bool { return in_array( $current_settings, array( 'geolocation', 'geolocation_ajax' ), true ); - } // end is_geolocation_enabled; + } /** @@ -90,10 +90,10 @@ class Geolocation { public static function disable_geolocation_on_legacy_php($default_customer_address ) { if ( self::is_geolocation_enabled( $default_customer_address ) ) { $default_customer_address = 'base'; - } // end if; + } return $default_customer_address; - } // end disable_geolocation_on_legacy_php; + } /** @@ -104,14 +104,14 @@ class Geolocation { // Only download the database from MaxMind if the geolocation function is enabled, or a plugin specifically requests it. if ( self::is_geolocation_enabled( get_option( 'wu_default_customer_address' ) ) || apply_filters( 'wu_geolocation_update_database_periodically', false ) ) { add_action( 'wu_geoip_updater', array( __CLASS__, 'update_database' ) ); - } // end if; + } // Trigger database update when settings are changed to enable geolocation. add_filter( 'pre_update_option_wu_default_customer_address', array( __CLASS__, 'maybe_update_database' ), 10, 2 ); } else { add_filter( 'pre_option_wu_default_customer_address', array( __CLASS__, 'disable_geolocation_on_legacy_php' ) ); - } // end if; - } // end init; + } + } /** @@ -124,10 +124,10 @@ class Geolocation { public static function maybe_update_database($new_value, $old_value ) { if ( $new_value !== $old_value && self::is_geolocation_enabled( $new_value ) ) { self::update_database(); - } // end if; + } return $new_value; - } // end maybe_update_database; + } /** * Get current user IP Address. @@ -143,9 +143,9 @@ class Geolocation { return (string) rest_is_ip_address( trim( (string) current( preg_split( '/,/', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) ) ); // WPCS: input var ok, CSRF ok. } elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) { // @codingStandardsIgnoreLine return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); // @codingStandardsIgnoreLine - } // end if; + } return ''; - } // end get_ip_address; + } /** @@ -161,7 +161,7 @@ class Geolocation { if ( '' !== self::get_ip_address() ) { $transient_name = 'external_ip_address_' . self::get_ip_address(); $external_ip_address = get_transient( $transient_name ); - } // end if; + } if ( false === $external_ip_address ) { $external_ip_address = '0.0.0.0'; @@ -176,14 +176,14 @@ class Geolocation { if ( !is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { $external_ip_address = apply_filters( 'wu_geolocation_ip_lookup_api_response', ( $response['body'] ), $service_name ); break; - } // end if; - } // end foreach; + } + } set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); - } // end if; + } return $external_ip_address; - } // end get_external_ip_address; + } /** @@ -218,21 +218,21 @@ class Geolocation { $country_code = self::geolocate_via_api( $ip_address ); } else { $country_code = ''; - } // end if; + } if ( !$country_code && $fallback ) { // May be a local environment - find external IP. return self::geolocate_ip( self::get_external_ip_address(), false, $api_fallback ); - } // end if; - } // end if; - } // end if; + } + } + } return array( 'ip' => $ip_address, 'country' => $country_code, 'state' => '', ); - } // end geolocate_ip; + } /** @@ -243,7 +243,7 @@ class Geolocation { */ public static function get_local_database_path($deprecated = '2' ) { return apply_filters( 'wu_geolocation_local_database_path', WP_CONTENT_DIR . '/uploads/GeoLite2-Country.mmdb', $deprecated ); - } // end get_local_database_path; + } /** @@ -257,7 +257,7 @@ class Geolocation { if ( !self::supports_geolite2() ) { $logger->notice( 'Requires PHP 5.4 to be able to download MaxMind GeoLite2 database', array( 'source' => 'geolocation' ) ); return; - } // end if; + } require_once ABSPATH . 'wp-admin/includes/file.php'; @@ -288,7 +288,7 @@ class Geolocation { // Reschedule download of DB. wp_clear_scheduled_hook( 'wu_geoip_updater' ); wp_schedule_event( strtotime( 'first tuesday of next month' ), 'monthly', 'wu_geoip_updater' ); - } // end try; + } // Delete temp file regardless of success. $wp_filesystem->delete( $tmp_database_path ); } else { @@ -296,8 +296,8 @@ class Geolocation { 'Unable to download GeoIP Database: ' . $tmp_database_path->get_error_message(), array( 'source' => 'geolocation' ) ); - } // end if; - } // end update_database; + } + } /** @@ -310,12 +310,12 @@ class Geolocation { private static function geolocate_via_db($ip_address, $database ) { if ( !class_exists( 'WC_Geolite_Integration', false ) ) { require_once WC_ABSPATH . 'includes/class-wc-geolite-integration.php'; - } // end if; + } $geolite = new WC_Geolite_Integration( $database ); return $geolite->get_country_iso( $ip_address ); - } // end geolocate_via_db; + } /** @@ -338,7 +338,7 @@ class Geolocation { if ( empty( $geoip_services ) ) { return ''; - } // end if; + } $geoip_services_keys = array_keys( $geoip_services ); @@ -361,21 +361,21 @@ class Geolocation { default: $country_code = apply_filters( 'wu_geolocation_geoip_response_' . $service_name, '', $response['body'] ); break; - } // end switch; + } $country_code = sanitize_text_field( strtoupper( (string) $country_code ) ); if ( $country_code ) { break; - } // end if; - } // end if; - } // end foreach; + } + } + } set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); - } // end if; + } return $country_code; - } // end geolocate_via_api; + } -} // end class Geolocation; +} diff --git a/inc/class-helper.php b/inc/class-helper.php index a9995b7..de86a16 100644 --- a/inc/class-helper.php +++ b/inc/class-helper.php @@ -33,8 +33,7 @@ class Helper { _deprecated_function(__METHOD__, '2.0.11', 'wu_path'); return wu_path($dir); - - } // end path; + } /** * Returns the URL to the plugin folder. @@ -48,8 +47,7 @@ class Helper { _deprecated_function(__METHOD__, '2.0.11', 'wu_url'); return wu_url($dir); - - } // end url; + } /** * Shorthand for url('assets/img'). Returns the URL for assets inside the assets folder. @@ -65,8 +63,7 @@ class Helper { _deprecated_function(__METHOD__, '2.0.11', 'wu_get_asset'); return wu_get_asset($asset, $assets_dir, $base_dir); - - } // end get_asset; + } /** * Renders a view file from the view folder. @@ -82,8 +79,7 @@ class Helper { _deprecated_function(__METHOD__, '2.0.11', 'wu_get_template'); wu_get_template($view, $vars, $default_view); - - } // end render; + } /** * This function return 'slugfied' options terms to be used as options ids. @@ -99,8 +95,7 @@ class Helper { _deprecated_function(__METHOD__, '2.0.11', 'wu_slugify'); return wu_slugify($term); - - } // end slugfy; + } /** * Get the value of a slugified network option @@ -115,8 +110,7 @@ class Helper { _deprecated_function(__METHOD__, '2.0.11', 'wu_get_option'); return wu_get_option($option_name, $default); - - } // end get_option; + } /** * Save slugified network option. @@ -131,8 +125,7 @@ class Helper { _deprecated_function(__METHOD__, '2.0.11', 'wu_save_option'); return wu_save_option($option_name, $value); - - } // end save_option; + } /** * Delete slugified network option @@ -146,8 +139,7 @@ class Helper { _deprecated_function(__METHOD__, '2.0.11', 'wu_delete_option'); return wu_delete_option($option_name); - - } // end delete_option; + } /** * Gets the URL for the folders created with maybe_create_folder(). @@ -163,8 +155,7 @@ class Helper { _deprecated_function(__METHOD__, '2.0.11', 'wu_get_folder_url'); return wu_get_folder_url($folder); - - } // end get_folder_url; + } /** * Creates a WP Multisite WaaS folder inside the uploads folder. Returns the path to the folder. @@ -180,8 +171,7 @@ class Helper { _deprecated_function(__METHOD__, '2.0.11', 'wu_maybe_create_folder'); return wu_maybe_create_folder($folder); - - } // end maybe_create_folder; + } /** * Drop our custom tables. @@ -196,7 +186,5 @@ class Helper { _deprecated_function(__METHOD__, '2.0.11', 'wu_drop_tables'); wu_drop_tables(); - - } // end drop_tables; - -} // end class Helper; + } +} diff --git a/inc/class-hooks.php b/inc/class-hooks.php index d6f67b5..5f56eb5 100644 --- a/inc/class-hooks.php +++ b/inc/class-hooks.php @@ -22,7 +22,7 @@ class Hooks { /** * Static-only class. */ - private function __construct() {} // end __construct; + private function __construct() {} /** * Register the activation and deactivation hooks @@ -46,8 +46,7 @@ class Hooks { * Runs the activation hook. */ add_action('plugins_loaded', array('WP_Ultimo\Hooks', 'on_activation_do'), 1); - - } // end init; + } /** * Runs when WP Multisite WaaS is activated @@ -63,8 +62,7 @@ class Hooks { * Set the activation flag */ update_network_option(null, 'wu_activation', 'yes'); - - } // end on_activation; + } /** * Runs whenever the activation flag is set. @@ -91,10 +89,8 @@ class Hooks { * @return void */ do_action('wu_activation'); - - } // end if; - - } // end on_activation_do; + } + } /** * Runs when WP Multisite WaaS is deactivated @@ -118,7 +114,5 @@ class Hooks { * @return void */ do_action('wu_deactivation'); - - } // end on_deactivation; - -} // end class Hooks; + } +} diff --git a/inc/class-license.php b/inc/class-license.php index 6af00da..45d5c01 100644 --- a/inc/class-license.php +++ b/inc/class-license.php @@ -10,8 +10,7 @@ class License { * * @return null */ - public function get_license_key() - { + public function get_license_key() { return null; } -} \ No newline at end of file +} diff --git a/inc/class-light-ajax.php b/inc/class-light-ajax.php index 9be94fc..025afe5 100644 --- a/inc/class-light-ajax.php +++ b/inc/class-light-ajax.php @@ -32,16 +32,13 @@ class Light_Ajax { public function __construct() { if (isset($_REQUEST['wu-ajax'])) { - $action = $this->get_when_to_run(); wu_x_header("X-Ultimo-Ajax-When: $action"); add_action($action, array($this, 'process_light_ajax'), 20); - - } // end if; - - } // end __construct; + } + } /** * Actions that can ignore the referer check. @@ -51,25 +48,27 @@ class Light_Ajax { */ protected function should_skip_referer_check(): bool { - $allowed_actions = apply_filters('wu_light_ajax_should_skip_referer_check', array( + $allowed_actions = apply_filters( + 'wu_light_ajax_should_skip_referer_check', + array( - /** - * Checkout Form Actions - * - * They're here because in some cases, - * the caching settings might prevent nonces from - * being properly refreshed, which could cause 403 - * errors with the actions below. - */ - 'wu_render_field_template', - 'wu_create_order', - 'wu_validate_form', + /** + * Checkout Form Actions + * + * They're here because in some cases, + * the caching settings might prevent nonces from + * being properly refreshed, which could cause 403 + * errors with the actions below. + */ + 'wu_render_field_template', + 'wu_create_order', + 'wu_validate_form', - )); + ) + ); return in_array(wu_request('action', 'no-action'), $allowed_actions, true); - - } // end should_skip_referer_check; + } /** * Gets the hook we should use to attach the light ajax runner to. @@ -92,18 +91,20 @@ class Light_Ajax { * @since 2.0.0 * @return array The hook list. */ - $allowed_list = apply_filters('wu_light_ajax_allowed_hooks', array( - 'plugins_loaded', - 'setup_theme', - 'after_setup_theme', - 'init', - )); + $allowed_list = apply_filters( + 'wu_light_ajax_allowed_hooks', + array( + 'plugins_loaded', + 'setup_theme', + 'after_setup_theme', + 'init', + ) + ); $action = isset($_REQUEST['wu-when']) ? base64_decode((string) $_REQUEST['wu-when']) : 'plugins_loaded'; return in_array($action, $allowed_list, true) ? $action : 'plugins_loaded'; - - } // end get_when_to_run; + } /** * Adds an wu_ajax handler. @@ -138,12 +139,10 @@ class Light_Ajax { header('X-Robots-Tag: noindex'); if (empty($_REQUEST['action'])) { - status_header(400); die('0'); - - } // end if; + } send_nosniff_header(); @@ -155,17 +154,11 @@ class Light_Ajax { $action = esc_attr(trim((string) $_REQUEST['action'])); if (is_user_logged_in()) { - do_action('wu_ajax_' . $action); // phpcs:ignore - } else { - do_action('wu_ajax_nopriv_' . $action); // phpcs:ignore - - } // end if; + } die('1'); - - } // end process_light_ajax; - -} // end class Light_Ajax; + } +} diff --git a/inc/class-logger.php b/inc/class-logger.php index 04180c6..8cf07d0 100644 --- a/inc/class-logger.php +++ b/inc/class-logger.php @@ -42,8 +42,7 @@ class Logger extends AbstractLogger { public static function get_logs_folder() { return wu_maybe_create_folder('wu-logs'); - - } // end get_logs_folder; + } /** * Add a log entry to chosen file. @@ -57,10 +56,8 @@ class Logger extends AbstractLogger { $allowed_log_level = wu_get_setting('error_logging_level', 'default'); if ($allowed_log_level === 'disabled') { - return; - - } // end if; + } if ($allowed_log_level === 'default') { /** @@ -91,42 +88,30 @@ class Logger extends AbstractLogger { $current_log_levels = array(); foreach ($psr_log_levels as $php_level => $psr_level) { - if ($reporting_level & $php_level) { - $current_log_levels[] = $psr_level; + } + } - } // end if; - - } // end foreach; - - if (!in_array($log_level, $current_log_levels, true) && ($reporting_level & ~E_ALL)) { - + if ( ! in_array($log_level, $current_log_levels, true) && ($reporting_level & ~E_ALL)) { return; - - } // end if; - + } } elseif ($allowed_log_level === 'errors' && $log_level !== LogLevel::ERROR && $log_level !== LogLevel::CRITICAL) { - return; - - } // end if; + } $instance = self::get_instance(); $instance->set_log_file(self::get_logs_folder() . "/$handle.log"); if (is_wp_error($message)) { - $message = $message->get_error_message(); - - } // end if; + } $instance->log($log_level, $message); do_action('wu_log_add', $handle, $message); - - } // end add; + } /** * Get the log contents @@ -141,11 +126,9 @@ class Logger extends AbstractLogger { $file = self::get_logs_folder() . "/$handle.log"; - if (!file_exists($file)) { - + if ( ! file_exists($file)) { return array(); - - } // end if; + } // read file $content = file_get_contents($file); @@ -155,15 +138,12 @@ class Logger extends AbstractLogger { // remove last line if empty if (empty(end($arr_content))) { - array_pop($arr_content); - - } // end if; + } // return last lines return array_slice($arr_content, -$lines); - - } // end read_lines; + } /** * Clear entries from chosen file. @@ -176,14 +156,11 @@ class Logger extends AbstractLogger { // Delete the file if it exists. if (file_exists($file)) { - @unlink($file); // phpcs:ignore - - } // end if; + } do_action('wu_log_clear', $handle); - - } // end clear; + } /** * Takes a callable as a parameter and logs how much time it took to execute it. @@ -209,8 +186,7 @@ class Logger extends AbstractLogger { self::add($handle, $message); return $return; - - } // end track_time; + } /** * Set the log file path. @@ -222,8 +198,7 @@ class Logger extends AbstractLogger { public function set_log_file($log_file) { $this->log_file = $log_file; - - } // end set_log_file; + } /** * Logs with an arbitrary level. @@ -238,17 +213,14 @@ class Logger extends AbstractLogger { */ public function log($level, $message, array $context = array()) { - if (!$this->is_valid_log_level($level) ) { - + if ( ! $this->is_valid_log_level($level) ) { return; - - } // end if; + } $formatted_message = $this->format_message($level, $message, $context); $this->write_to_file($formatted_message); - - } // end log; + } /** * Check if the log level is valid. @@ -271,8 +243,7 @@ class Logger extends AbstractLogger { ); return in_array($level, $valid_log_levels, true); - - } // end is_valid_log_level; + } /** * Format the message to be logged. @@ -296,8 +267,7 @@ class Logger extends AbstractLogger { ); return $formatted_message; - - } // end format_message; + } /** * Write the message to the log file. @@ -309,20 +279,14 @@ class Logger extends AbstractLogger { */ protected function write_to_file($message) { - if (!file_exists($this->log_file)) { - + if ( ! file_exists($this->log_file)) { touch($this->log_file); + } - } // end if; - - if (!is_writable($this->log_file)) { - + if ( ! is_writable($this->log_file)) { return; - - } // end if; + } file_put_contents($this->log_file, $message, FILE_APPEND | LOCK_EX); - - } // end write_to_file; - -} // end class Logger; + } +} diff --git a/inc/class-maintenance-mode.php b/inc/class-maintenance-mode.php index 2632d87..9c464a6 100644 --- a/inc/class-maintenance-mode.php +++ b/inc/class-maintenance-mode.php @@ -33,12 +33,9 @@ class Maintenance_Mode { add_action('wp_ultimo_load', array($this, 'add_settings')); if (wu_get_setting('maintenance_mode')) { - $this->hooks(); - - } // end if; - - } // end init; + } + } /** * Adds the additional hooks, when necessary. @@ -50,35 +47,25 @@ class Maintenance_Mode { add_action('wu_ajax_toggle_maintenance_mode', array($this, 'toggle_maintenance_mode')); - if (!is_main_site()) { - + if ( ! is_main_site()) { add_action('admin_bar_menu', array($this, 'add_notice_to_admin_bar'), 15); - - } // end if; + } if (self::check_maintenance_mode()) { - add_filter('pre_option_blog_public', '__return_true'); - if (!is_admin()) { - + if ( ! is_admin()) { add_action('wp', array($this, 'render_page')); if (function_exists('wp_robots_no_robots')) { - add_filter('wp_robots', 'wp_robots_no_robots'); // WordPress 5.7+ } else { - add_action('wp_head', 'wp_no_robots', 20); - - } // end if; - - } // end if; - - } // end if; - - } // end hooks; + } + } + } + } /** * Add maintenance mode Notice to Admin Bar @@ -89,14 +76,11 @@ class Maintenance_Mode { */ public function add_notice_to_admin_bar($wp_admin_bar) { - if (!current_user_can('manage_options')) { - + if ( ! current_user_can('manage_options')) { return; - - } // end if; + } if (is_admin() || self::check_maintenance_mode()) { - $args = array( 'id' => 'wu-maintenance-mode', 'parent' => 'top-secondary', @@ -109,10 +93,8 @@ class Maintenance_Mode { ); $wp_admin_bar->add_node($args); - - } // end if; - - } // end add_notice_to_admin_bar; + } + } /** * Render page - html filtrable @@ -123,10 +105,8 @@ class Maintenance_Mode { public function render_page() { if (is_main_site() || current_user_can('read')) { - return; - - } // end if; + } $text = apply_filters( 'wu_maintenance_mode_text', @@ -139,8 +119,7 @@ class Maintenance_Mode { ); wp_die($text, $title, 503); - - } // end render_page; + } /** * Check should display maintenance mode @@ -151,8 +130,7 @@ class Maintenance_Mode { public static function check_maintenance_mode() { return get_site_meta(get_current_blog_id(), 'wu_maintenance_mode', true); - - } // end check_maintenance_mode; + } /** * Callback button admin toggle maintenance mode. @@ -166,14 +144,14 @@ class Maintenance_Mode { $site_id = \WP_Ultimo\Helpers\Hash::decode(wu_request('site_hash'), 'site'); - if (!current_user_can_for_blog($site_id, 'manage_options')) { - - return wp_send_json_error(array( - 'message' => __('You do not have the necessary permissions to perform this option.', 'wp-ultimo'), - 'value' => false, - )); - - } // end if; + if ( ! current_user_can_for_blog($site_id, 'manage_options')) { + return wp_send_json_error( + array( + 'message' => __('You do not have the necessary permissions to perform this option.', 'wp-ultimo'), + 'value' => false, + ) + ); + } $value = wu_request('maintenance_status', false); @@ -190,8 +168,7 @@ class Maintenance_Mode { Cache_Manager::get_instance()->flush_known_caches(); wp_send_json_success($return); - - } // end toggle_maintenance_mode; + } /** * Filter the WP Multisite WaaS settings to add Jumper options @@ -201,14 +178,16 @@ class Maintenance_Mode { */ public function add_settings() { - wu_register_settings_field('sites', 'maintenance_mode', array( - 'title' => __('Site Maintenance Mode', 'wp-ultimo'), - 'desc' => __('Allow your customers and super admins to quickly take sites offline via a toggle on the site dashboard.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - 'order' => 23, - )); - - } // end add_settings; - -} // end class Maintenance_Mode; + wu_register_settings_field( + 'sites', + 'maintenance_mode', + array( + 'title' => __('Site Maintenance Mode', 'wp-ultimo'), + 'desc' => __('Allow your customers and super admins to quickly take sites offline via a toggle on the site dashboard.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + 'order' => 23, + ) + ); + } +} diff --git a/inc/class-newsletter.php b/inc/class-newsletter.php index b96c72c..a5ad983 100644 --- a/inc/class-newsletter.php +++ b/inc/class-newsletter.php @@ -10,17 +10,19 @@ class Newsletter { public function init() { add_action('wu_settings_login', array($this, 'add_settings'), 20); add_filter('wu_pre_save_settings', array($this, 'maybe_update_newsletter_subscription'), 10, 3); - - } // end init; + } public function add_settings() { - wu_register_settings_field('general', self::SETTING_FIELD_SLUG, array( - 'title' => __('Signup for WP Multisite WaaS Newsletter', 'wp-ultimo'), - 'desc' => __('Be informed of new releases and all things related to running a WaaS Network.', 'wp-ultimo'), - 'type' => 'toggle', - 'value' => '1', - ), - 45 + wu_register_settings_field( + 'general', + self::SETTING_FIELD_SLUG, + array( + 'title' => __('Signup for WP Multisite WaaS Newsletter', 'wp-ultimo'), + 'desc' => __('Be informed of new releases and all things related to running a WaaS Network.', 'wp-ultimo'), + 'type' => 'toggle', + 'value' => '1', + ), + 45 ); } @@ -37,38 +39,46 @@ class Newsletter { */ public function maybe_update_newsletter_subscription($settings, $settings_to_save, $saved_settings) { - if ( isset($settings_to_save[ self::SETTING_FIELD_SLUG ]) && $settings_to_save[ self::SETTING_FIELD_SLUG ] && $settings_to_save[ self::SETTING_FIELD_SLUG ] != $saved_settings[ self::SETTING_FIELD_SLUG ] ) { - - $response = wp_remote_post( 'https://wpmultisitewaas.org/wp-json/newsletter/v2/subscribers', [ - 'method' => 'PUT', - 'body' => wp_json_encode( [ - 'email' => $settings['company_email'], - 'status' => 'confirmed', - 'first_name' => $settings['company_name'], - 'country' => $settings['company_country'], - ] ), - 'headers' => [ - 'Accept' => 'application/json', - 'Content-Type' => 'application/json', - 'Authorization' => 'Basic ' . base64_encode( '30220d7fb4ec49a7410b3a309b9346c18410bd56:0407cd731d6f074cd0b96f2643b7619e89af1ed2' ), - ], - ] ); - } elseif( empty($settings_to_save[ self::SETTING_FIELD_SLUG ]) && ! empty( $saved_settings[ self::SETTING_FIELD_SLUG ] ) ) { - $response = wp_remote_post( 'https://wpmultisitewaas.org/wp-json/newsletter/v2/subscribers', [ - 'method' => 'PUT', - 'body' => wp_json_encode( [ - 'email' => $settings['company_email'], - 'status' => 'unsubscribed', - ] ), - 'headers' => [ - 'Accept' => 'application/json', - 'Content-Type' => 'application/json', - 'Authorization' => 'Basic ' . base64_encode( '30220d7fb4ec49a7410b3a309b9346c18410bd56:0407cd731d6f074cd0b96f2643b7619e89af1ed2' ), - ], - ] ); + if ( isset($settings_to_save[ self::SETTING_FIELD_SLUG ]) && $settings_to_save[ self::SETTING_FIELD_SLUG ] && $settings_to_save[ self::SETTING_FIELD_SLUG ] != $saved_settings[ self::SETTING_FIELD_SLUG ] ) { + $response = wp_remote_post( + 'https://wpmultisitewaas.org/wp-json/newsletter/v2/subscribers', + array( + 'method' => 'PUT', + 'body' => wp_json_encode( + array( + 'email' => $settings['company_email'], + 'status' => 'confirmed', + 'first_name' => $settings['company_name'], + 'country' => $settings['company_country'], + ) + ), + 'headers' => array( + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + 'Authorization' => 'Basic ' . base64_encode('30220d7fb4ec49a7410b3a309b9346c18410bd56:0407cd731d6f074cd0b96f2643b7619e89af1ed2'), + ), + ) + ); + } elseif ( empty($settings_to_save[ self::SETTING_FIELD_SLUG ]) && ! empty($saved_settings[ self::SETTING_FIELD_SLUG ]) ) { + $response = wp_remote_post( + 'https://wpmultisitewaas.org/wp-json/newsletter/v2/subscribers', + array( + 'method' => 'PUT', + 'body' => wp_json_encode( + array( + 'email' => $settings['company_email'], + 'status' => 'unsubscribed', + ) + ), + 'headers' => array( + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + 'Authorization' => 'Basic ' . base64_encode('30220d7fb4ec49a7410b3a309b9346c18410bd56:0407cd731d6f074cd0b96f2643b7619e89af1ed2'), + ), + ) + ); } return $settings; - - } // end fix_saving_settings; + } } diff --git a/inc/class-requirements.php b/inc/class-requirements.php index c0879f7..97a8ee8 100644 --- a/inc/class-requirements.php +++ b/inc/class-requirements.php @@ -65,7 +65,7 @@ class Requirements { /** * Static-only class. */ - private function __construct() {} // end __construct; + private function __construct() {} /** * Check if the minimum pre-requisites to run WP Multisite WaaS are present. @@ -80,20 +80,17 @@ class Requirements { */ public static function met() { - if (self::$met === null) { - + if (null === self::$met) { self::$met = ( self::check_php_version() && self::check_wp_version() && self::is_multisite() && self::is_network_active() ); - - } // end if; + } return self::$met; - - } // end met; + } /** * Checks if we have ran through the setup already. @@ -106,26 +103,21 @@ class Requirements { global $wpdb; if (self::is_unit_test()) { - // phpcs:disable $tables = wu_array_flatten($wpdb->get_results(sprintf('SHOW TABLES FROM %s;', DB_NAME), ARRAY_N)); // phpcs:enable - if (!in_array("{$wpdb->prefix}wu_domain_mappings", $tables, true)) { - + if (! in_array("{$wpdb->prefix}wu_domain_mappings", $tables, true)) { Core_Installer::get_instance()->_install_database_tables(); - - } // end if; + } return true; - - } // end if; + } return get_network_option(null, 'wu_setup_finished', false); - - } // end run_setup; + } /** * Checks for a test environment. @@ -134,10 +126,8 @@ class Requirements { * @return boolean */ public static function is_unit_test() { - return defined('WP_TESTS_MULTISITE') && WP_TESTS_MULTISITE; - - } // end is_unit_test; + } /** * Check if the PHP version requirements are met * @@ -146,16 +136,13 @@ class Requirements { public static function check_php_version(): bool { if (version_compare(phpversion(), self::$php_version, '<')) { - add_action('network_admin_notices', array('WP_Ultimo\Requirements', 'notice_unsupported_php_version')); return false; - - } // end if; + } return true; - - } // end check_php_version; + } /** * Check if the WordPress version requirements are met * @@ -166,16 +153,13 @@ class Requirements { global $wp_version; if (version_compare($wp_version, self::$wp_version, '<')) { - add_action('network_admin_notices', array('WP_Ultimo\Requirements', 'notice_unsupported_wp_version')); return false; - - } // end if; + } return true; - - } // end check_wp_version; + } /** * Check Cron Status @@ -195,50 +179,44 @@ class Requirements { global $wp_version; if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) { - return false; - - } // end if; + } if (defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) { - return false; - - } // end if; + } $cached_status = get_site_transient('wp-ultimo-cron-test-ok'); if ($cached_status) { - return true; - - } // end if; + } $sslverify = version_compare($wp_version, 4.0, '<'); $doing_wp_cron = sprintf('%.22F', microtime(true)); - $cron_request = apply_filters('cron_request', array( // phpcs:ignore - 'url' => site_url('wp-cron.php?doing_wp_cron=' . $doing_wp_cron), - 'args' => array( - 'timeout' => 3, - 'blocking' => true, - 'sslverify' => apply_filters('https_local_ssl_verify', $sslverify), // phpcs:ignore - ), - )); + $cron_request = apply_filters( + 'cron_request', // phpcs:ignore + array( + 'url' => site_url('wp-cron.php?doing_wp_cron=' . $doing_wp_cron), + 'args' => array( + 'timeout' => 3, + 'blocking' => true, + 'sslverify' => apply_filters('https_local_ssl_verify', $sslverify), // phpcs:ignore + ), + ) + ); $result = wp_remote_post($cron_request['url'], $cron_request['args']); if (wp_remote_retrieve_response_code($result) >= 300) { - return false; - - } // end if; + } set_transient('wp-ultimo-cron-test-ok', 1, HOUR_IN_SECONDS); return true; - - } // end check_wp_cron; + } /** * Check if the install is a Multisite install * @@ -246,17 +224,14 @@ class Requirements { */ public static function is_multisite(): bool { - if (!is_multisite()) { - + if (! is_multisite()) { add_action('admin_notices', array('WP_Ultimo\Requirements', 'notice_not_multisite')); return false; - - } // end if; + } return true; - - } // end is_multisite; + } /** * Check if WP Multisite WaaS is network active. * @@ -277,28 +252,21 @@ class Requirements { $skip_network_activation_check = apply_filters('wp_ultimo_skip_network_active_check', wu_is_must_use()); if ($skip_network_activation_check) { - return true; + } - } // end if; - - if (!function_exists('is_plugin_active_for_network')) { - + if (! function_exists('is_plugin_active_for_network')) { require_once ABSPATH . '/wp-admin/includes/plugin.php'; + } - } // end if; - - if (!is_plugin_active_for_network(WP_ULTIMO_PLUGIN_BASENAME) && !self::is_unit_test()) { - + if (! is_plugin_active_for_network(WP_ULTIMO_PLUGIN_BASENAME) && ! self::is_unit_test()) { add_action('admin_notices', array('WP_Ultimo\Requirements', 'notice_not_network_active')); return false; - - } // end if; + } return true; - - } // end is_network_active; + } /** * Adds a network admin notice about the PHP requirements not being met @@ -312,8 +280,7 @@ class Requirements { $message = sprintf(__('WP Multisite WaaS requires at least PHP version %1$s to run. Your current PHP version is %2$s. Please, contact your hosting company support to upgrade your PHP version. If you want maximum performance consider upgrading your PHP to version 7.0 or later.', 'wp-ultimo'), self::$php_version, phpversion()); printf('

%s

', $message); - - } // end notice_unsupported_php_version; + } /** * Adds a network admin notice about the WordPress requirements not being met @@ -329,8 +296,7 @@ class Requirements { $message = sprintf(__('WP Multisite WaaS requires at least WordPress version %1$s to run. Your current WordPress version is %2$s.', 'wp-ultimo'), self::$wp_version, $wp_version); printf('

%s

', $message); - - } // end notice_unsupported_wp_version; + } /** * Adds a network admin notice about the install not being a multisite install @@ -343,8 +309,7 @@ class Requirements { $message = __('WP Multisite WaaS requires a multisite install to run properly. To know more about WordPress Networks, visit this link: Create a Network →', 'wp-ultimo'); printf('

%s

', $message); - - } // end notice_not_multisite; + } /** * Adds a network admin notice about the WP Multisite WaaS not being network-active @@ -358,7 +323,5 @@ class Requirements { $message = sprintf(__('WP Multisite WaaS needs to be network active to run properly. You can "Network Activate" it here', 'wp-ultimo'), network_admin_url('plugins.php')); printf('

%s

', $message); - - } // end notice_not_network_active; - -} // end class Requirements; + } +} diff --git a/inc/class-scripts.php b/inc/class-scripts.php index ab89881..e6386c7 100644 --- a/inc/class-scripts.php +++ b/inc/class-scripts.php @@ -40,8 +40,7 @@ class Scripts { add_action('wp_ajax_wu_toggle_container', array($this, 'update_use_container')); add_filter('admin_body_class', array($this, 'add_body_class_container_boxed')); - - } // end init; + } /** * Wrapper for the register scripts function. @@ -56,8 +55,7 @@ class Scripts { public function register_script($handle, $src, $deps = array()) { wp_register_script($handle, $src, $deps, wu_get_version()); - - } // end register_script; + } /** * Wrapper for the register styles function. @@ -72,8 +70,7 @@ class Scripts { public function register_style($handle, $src, $deps = array()) { wp_register_style($handle, $src, $deps, wu_get_version()); - - } // end register_style; + } /** * Registers the default WP Multisite WaaS scripts. @@ -138,16 +135,20 @@ class Scripts { */ $this->register_script('wu-functions', wu_get_asset('functions.js', 'js'), array('jquery-core', 'wu-tiptip', 'wu-flatpicker', 'wu-block-ui', 'wu-accounting', 'clipboard', 'wp-hooks')); - wp_localize_script('wu-functions', 'wu_settings', array( - 'currency' => wu_get_setting('currency_symbol', 'USD'), - 'currency_symbol' => wu_get_currency_symbol(), - 'currency_position' => wu_get_setting('currency_position'), - 'decimal_separator' => wu_get_setting('decimal_separator'), - 'thousand_separator' => wu_get_setting('thousand_separator'), - 'precision' => wu_get_setting('precision', 2), - 'use_container' => get_user_setting('wu_use_container', false), - 'disable_image_zoom' => wu_get_setting('disable_image_zoom', false), - )); + wp_localize_script( + 'wu-functions', + 'wu_settings', + array( + 'currency' => wu_get_setting('currency_symbol', 'USD'), + 'currency_symbol' => wu_get_currency_symbol(), + 'currency_position' => wu_get_setting('currency_position'), + 'decimal_separator' => wu_get_setting('decimal_separator'), + 'thousand_separator' => wu_get_setting('thousand_separator'), + 'precision' => wu_get_setting('precision', 2), + 'use_container' => get_user_setting('wu_use_container', false), + 'disable_image_zoom' => wu_get_setting('disable_image_zoom', false), + ) + ); /* * Adds Fields & Components @@ -157,12 +158,16 @@ class Scripts { /* * 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'), + ), + ) + ); /* * Adds Admin Script @@ -183,33 +188,45 @@ class Scripts { /* * Localize selectizer */ - wp_localize_script('wu-functions', 'wu_selectizer', array( - 'ajaxurl' => wu_ajax_url(), - )); + wp_localize_script( + 'wu-functions', + 'wu_selectizer', + array( + 'ajaxurl' => wu_ajax_url(), + ) + ); /* * Load variables to localized it */ - wp_localize_script('wu-functions', 'wu_ticker', array( + wp_localize_script( + 'wu-functions', + 'wu_ticker', + array( 'server_clock_offset' => (wu_get_current_time('timestamp') - time()) / 60 / 60, // phpcs:ignore 'moment_clock_timezone_name' => wp_date('e'), 'moment_clock_timezone_offset' => wp_date('Z'), - )); + ) + ); /* * Adds our thickbox fork. */ $this->register_script('wubox', wu_get_asset('wubox.js', 'js'), array('wu-vue-apps')); - wp_localize_script('wubox', 'wuboxL10n', array( - 'next' => __('Next >'), - 'prev' => __('< 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 >'), + 'prev' => __('< 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'), + ) + ); /* * WordPress localizes month names and all, but @@ -217,8 +234,7 @@ class Scripts { * times to be translated, so we need to do it ourselves. */ $this->localize_moment(); - - } // end register_default_scripts; + } /** * Localize moment.js relative times. @@ -231,15 +247,18 @@ class Scripts { $time_format = get_option('time_format', __('g:i a')); $date_format = get_option('date_format', __('F j, Y')); - $long_date_formats = array_map('wu_convert_php_date_format_to_moment_js_format', array( - 'LT' => $time_format, - 'LTS' => str_replace(':i', ':i:s', (string) $time_format), - /* translators: the day/month/year date format used by WP Multisite WaaS. You can changed it to localize this date format to your language. the default value is d/m/Y, which is the format 31/12/2021. */ - 'L' => __('d/m/Y', 'wp-ultimo'), - 'LL' => $date_format, - 'LLL' => sprintf('%s %s', $date_format, $time_format), - 'LLLL' => sprintf('%s %s', $date_format, $time_format), - )); + $long_date_formats = array_map( + 'wu_convert_php_date_format_to_moment_js_format', + array( + 'LT' => $time_format, + 'LTS' => str_replace(':i', ':i:s', (string) $time_format), + /* translators: the day/month/year date format used by WP Multisite WaaS. You can changed it to localize this date format to your language. the default value is d/m/Y, which is the format 31/12/2021. */ + 'L' => __('d/m/Y', 'wp-ultimo'), + 'LL' => $date_format, + 'LLL' => sprintf('%s %s', $date_format, $time_format), + 'LLLL' => sprintf('%s %s', $date_format, $time_format), + ) + ); // phpcs:disable $strings = array( @@ -268,8 +287,7 @@ class Scripts { $inline_script = sprintf("moment.updateLocale( '%s', %s );", get_user_locale(), wp_json_encode($strings)); return did_action('init') && wp_add_inline_script('moment', $inline_script, 'after'); - - } // end localize_moment; + } /** * Registers the default WP Multisite WaaS styles. @@ -286,8 +304,7 @@ class Scripts { $this->register_style('wu-checkout', wu_get_asset('checkout.css', 'css'), array(), wu_get_version()); $this->register_style('wu-flags', wu_get_asset('flags.css', 'css'), array(), wu_get_version()); - - } // end register_default_styles; + } /** * Loads the default admin styles. @@ -298,8 +315,7 @@ class Scripts { public function enqueue_default_admin_styles() { wp_enqueue_style('wu-admin'); - - } // end enqueue_default_admin_styles; + } /** * Loads the default admin scripts. @@ -310,8 +326,7 @@ class Scripts { public function enqueue_default_admin_scripts() { wp_enqueue_script('wu-admin'); - - } // end enqueue_default_admin_scripts; + } /** * Update the use container setting. @@ -323,13 +338,12 @@ class Scripts { check_ajax_referer('wu_toggle_container', 'nonce'); - $new_value = (bool) !(get_user_setting('wu_use_container', false)); + $new_value = (bool) ! (get_user_setting('wu_use_container', false)); set_user_setting('wu_use_container', $new_value); wp_die(); - - } // end update_use_container; + } /** * Add body classes of container boxed if user has setting. @@ -342,13 +356,9 @@ class Scripts { public function add_body_class_container_boxed($classes) { if (get_user_setting('wu_use_container', false)) { - $classes .= ' has-wu-container '; - - } // end if; + } return $classes; - - } // end add_body_class_container_boxed; - -} // end class Scripts; + } +} diff --git a/inc/class-session-cookie.php b/inc/class-session-cookie.php index 2bfd66d..a3bd4e3 100644 --- a/inc/class-session-cookie.php +++ b/inc/class-session-cookie.php @@ -11,8 +11,8 @@ namespace WP_Ultimo; -use \WP_Ultimo\Contracts\Session; -use \Delight\Cookie\Cookie; +use WP_Ultimo\Contracts\Session; +use Delight\Cookie\Cookie; // Exit if accessed directly defined('ABSPATH') || exit; @@ -27,18 +27,18 @@ class Session_Cookie implements Session { * * @var array */ - protected $data = array(); + protected $data = array(); /** * If the session has already loaded * * @var boolean */ - protected $loaded = false; - /** - * @var string - */ - protected $realm_name; + protected $loaded = false; + /** + * @var string + */ + protected $realm_name; /** * Constructs the manager. @@ -49,24 +49,21 @@ class Session_Cookie implements Session { */ public function __construct($realm_name) { - $this->realm_name = $realm_name; - if ($this->loaded === true) { - - return; - + $this->realm_name = $realm_name; + if ($this->loaded === true) { + return; } - $cookie_name = $this->get_cookie_name(); + $cookie_name = $this->get_cookie_name(); - $data_raw = Cookie::get($cookie_name, '{"new": true}'); - $data_raw = urldecode((string) $data_raw); - $data_raw = stripslashes($data_raw); + $data_raw = Cookie::get($cookie_name, '{"new": true}'); + $data_raw = urldecode((string) $data_raw); + $data_raw = stripslashes($data_raw); - $this->data = json_decode($data_raw, true); + $this->data = json_decode($data_raw, true); - $this->loaded = true; - - } // end __construct; + $this->loaded = true; + } /** * Get the name of current cookie. @@ -76,8 +73,7 @@ class Session_Cookie implements Session { protected function get_cookie_name() { return "wu_session_{$this->realm_name}"; - - } // end get_cookie_name; + } /** * Gets the value of a session key. @@ -89,15 +85,12 @@ class Session_Cookie implements Session { */ public function get($key = null) { - if (!$key) { - + if ( ! $key) { return $this->data; + } - } // end if; - - return is_array($this->data) && isset($this->data[$key]) ? $this->data[$key] : null; - - } // end get; + return is_array($this->data) && isset($this->data[ $key ]) ? $this->data[ $key ] : null; + } /** * Set the value of a session key. * @@ -108,11 +101,10 @@ class Session_Cookie implements Session { */ public function set($key, $value): bool { - $this->data[$key] = $value; + $this->data[ $key ] = $value; - return true; - - } // end set; + return true; + } /** * Appends values to a given key, instead of replacing it. * @@ -123,13 +115,12 @@ class Session_Cookie implements Session { */ public function add_values($key, $values): bool { - $old_values = isset($this->data[$key]) ? $this->data[$key] : array(); + $old_values = isset($this->data[ $key ]) ? $this->data[ $key ] : array(); - $this->data[$key] = array_merge($old_values, $values); + $this->data[ $key ] = array_merge($old_values, $values); return true; - - } // end add_values; + } /** * Writes to the session and closes the connection. * @@ -138,11 +129,9 @@ class Session_Cookie implements Session { */ public function commit($expire = null): bool { - if ($expire === null) { - + if ($expire === null) { $expire = HOUR_IN_SECONDS; - - } // end if; + } $value = json_encode($this->data, JSON_UNESCAPED_UNICODE); @@ -158,11 +147,10 @@ class Session_Cookie implements Session { $cookie->save(); // Set for current call - $_COOKIE[$this->get_cookie_name()] = $value; + $_COOKIE[ $this->get_cookie_name() ] = $value; return true; - - } // end commit; + } /** * Clears the current session. @@ -171,9 +159,8 @@ class Session_Cookie implements Session { */ public function clear() { - $this->data = array(); - - } // end clear; + $this->data = array(); + } /** * Destroys the session. Equivalent to session_destroy(); @@ -186,10 +173,8 @@ class Session_Cookie implements Session { $name = $this->get_cookie_name(); // unset from current call - unset($_COOKIE[$this->get_cookie_name()]); + unset($_COOKIE[ $this->get_cookie_name() ]); return (new Cookie($name))->delete(); - - } // end destroy; - -} // end class Session_Cookie; + } +} diff --git a/inc/class-settings.php b/inc/class-settings.php index f29cdf1..0f42040 100644 --- a/inc/class-settings.php +++ b/inc/class-settings.php @@ -22,7 +22,8 @@ defined('ABSPATH') || exit; */ class Settings { - use \WP_Ultimo\Traits\Singleton, \WP_Ultimo\Traits\WP_Ultimo_Settings_Deprecated; + use \WP_Ultimo\Traits\Singleton; + use \WP_Ultimo\Traits\WP_Ultimo_Settings_Deprecated; /** * Keeps the key used to access settings. @@ -70,8 +71,7 @@ class Settings { add_filter('pre_site_option_add_new_users', array($this, 'force_add_new_users'), 10, 3); add_filter('pre_site_option_menu_items', array($this, 'force_plugins_menu'), 10, 3); - - } // end init; + } /** * Change the current status of the registration on WordPress MS. @@ -88,16 +88,13 @@ class Settings { global $current_site; if ($network_id !== $current_site->id) { - return $status; - - } // end if; + } $status = wu_get_setting('enable_registration') ? 'all' : $status; return $status; - - } // end force_registration_status; + } /** * Change the current status of the add_new network option. @@ -114,14 +111,11 @@ class Settings { global $current_site; if ($network_id !== $current_site->id) { - return $status; - - } // end if; + } return wu_get_setting('add_new_users', true); - - } // end force_add_new_users; + } /** * Change the current status of the add_new network option. @@ -138,16 +132,13 @@ class Settings { global $current_site; if ($network_id !== $current_site->id || is_bool($status)) { - return $status; - - } // end if; + } $status['plugins'] = wu_get_setting('menu_items_plugin', true); return $status; - - } // end force_plugins_menu; + } /** * Get all the settings from WP Multisite WaaS @@ -159,26 +150,22 @@ class Settings { // Get all the settings if (null === $this->settings) { - - $this->settings = wu_get_option(Settings::KEY); - - } // end if; + $this->settings = wu_get_option(self::KEY); + } if ($this->settings === false || empty($this->settings)) { - if (! $this->saving) { + if ( ! $this->saving) { $this->saving = true; - $this->settings = $this->save_settings( array(), true ); + $this->settings = $this->save_settings(array(), true); } else { return array(); } - - } // end if; + } if ($check_caps) {} // phpcs:ignore; return $this->settings; - - } // end get_all; + } /** * Get a specific settings from the plugin @@ -195,16 +182,13 @@ class Settings { $settings = $this->get_all(); if (strpos($setting, '-') !== false) { - _doing_it_wrong($setting, __('Dashes are no longer supported when registering a setting. You should change it to underscores in later versions.', 'wp-ultimo'), '2.0.0'); + } - } // end if; - - $setting_value = isset($settings[$setting]) ? $settings[$setting] : $default; + $setting_value = isset($settings[ $setting ]) ? $settings[ $setting ] : $default; return apply_filters('wu_get_setting', $setting_value, $setting, $default, $settings); - - } // end get_setting; + } /** * Saves a specific setting into the database @@ -220,20 +204,17 @@ class Settings { $value = apply_filters('wu_save_setting', $value, $setting, $settings); if (is_callable($value)) { - $value = call_user_func($value); + } - } // end if; + $settings[ $setting ] = $value; - $settings[$setting] = $value; - - $status = wu_save_option(Settings::KEY, $settings); + $status = wu_save_option(self::KEY, $settings); $this->settings = $settings; return $status; - - } // end save_setting; + } /** * Save WP Multisite WaaS Settings @@ -253,44 +234,36 @@ class Settings { $sections = $this->get_sections(); - $saved_settings = !$reset ? $this->get_all() : array(); + $saved_settings = ! $reset ? $this->get_all() : array(); do_action('wu_before_save_settings', $settings_to_save); foreach ($sections as $section_slug => $section) { - foreach ($section['fields'] as $field_slug => $field_atts) { - - $existing_value = isset($saved_settings[$field_slug]) ? $saved_settings[$field_slug] : false; + $existing_value = isset($saved_settings[ $field_slug ]) ? $saved_settings[ $field_slug ] : false; $field = new Field($field_slug, $field_atts); - $new_value = isset($settings_to_save[$field_slug]) ? $settings_to_save[$field_slug] : $existing_value; + $new_value = isset($settings_to_save[ $field_slug ]) ? $settings_to_save[ $field_slug ] : $existing_value; /** * For the current tab, we need to assume toggle fields. */ - if ($section_slug === wu_request('tab', 'general') && $field->type === 'toggle' && !isset($settings_to_save[$field_slug])) { - + if ($section_slug === wu_request('tab', 'general') && $field->type === 'toggle' && ! isset($settings_to_save[ $field_slug ])) { $new_value = false; - - } // end if; + } $value = $reset ? $field->default : $new_value; $field->set_value($value); if ($field->get_value() !== null) { - - $settings[$field_slug] = $field->get_value(); - - } // end if; + $settings[ $field_slug ] = $field->get_value(); + } do_action('wu_saving_setting', $field_slug, $field, $settings_to_save); - - } // end foreach; - - } // end foreach; + } + } /** * Allow developers to filter settings before save by WP Multisite WaaS. @@ -303,15 +276,14 @@ class Settings { */ $settings = apply_filters('wu_pre_save_settings', $settings, $settings_to_save, $saved_settings); - wu_save_option(Settings::KEY, $settings); + wu_save_option(self::KEY, $settings); $this->settings = $settings; do_action('wu_after_save_settings', $settings, $settings_to_save, $saved_settings); return $settings; - - } // end save_settings; + } /** * Returns the list of sections and their respective fields. @@ -327,24 +299,26 @@ class Settings { return $this->sections; } $this->default_sections(); - $this->sections = apply_filters('wu_settings_get_sections', array( + $this->sections = apply_filters( + 'wu_settings_get_sections', + array( - /* - * Add a default invisible section that we can use - * to register settings that will not have a control. - */ - 'core' => array( - 'invisible' => true, - 'order' => 1_000_000, - 'fields' => apply_filters('wu_settings_section_core_fields', array()), - ), - )); + /* + * Add a default invisible section that we can use + * to register settings that will not have a control. + */ + 'core' => array( + 'invisible' => true, + 'order' => 1_000_000, + 'fields' => apply_filters('wu_settings_section_core_fields', array()), + ), + ) + ); uasort($this->sections, 'wu_sort_by_order'); return $this->sections; - - } // end get_sections; + } /** * Returns a particular settings section. @@ -358,11 +332,14 @@ class Settings { $sections = $this->get_sections(); - return wu_get_isset($sections, $section_name, array( - 'fields' => array(), - )); - - } // end get_section; + return wu_get_isset( + $sections, + $section_name, + array( + 'fields' => array(), + ) + ); + } /** * Adds a new settings section. @@ -379,25 +356,29 @@ class Settings { */ public function add_section($section_slug, $atts) { - add_filter('wu_settings_get_sections', function($sections) use ($section_slug, $atts) { + add_filter( + 'wu_settings_get_sections', + function ($sections) use ($section_slug, $atts) { - $default_order = (count($sections) + 1) * 10; + $default_order = (count($sections) + 1) * 10; - $atts = wp_parse_args($atts, array( - 'icon' => 'dashicons-wu-cog', - 'order' => $default_order, - 'capability' => 'manage_network', - )); + $atts = wp_parse_args( + $atts, + array( + 'icon' => 'dashicons-wu-cog', + 'order' => $default_order, + 'capability' => 'manage_network', + ) + ); - $atts['fields'] = apply_filters("wu_settings_section_{$section_slug}_fields", array()); + $atts['fields'] = apply_filters("wu_settings_section_{$section_slug}_fields", array()); - $sections[$section_slug] = $atts; + $sections[ $section_slug ] = $atts; - return $sections; - - }); - - } // end add_section; + return $sections; + } + ); + } /** * Adds a new field to a settings section. @@ -416,132 +397,115 @@ class Settings { /* * Adds the field to the desired fields array. */ - add_filter("wu_settings_section_{$section_slug}_fields", function($fields) use ($field_slug, $atts) { - /* - * We no longer support settings with hyphens. - */ - if (strpos($field_slug, '-') !== false) { + add_filter( + "wu_settings_section_{$section_slug}_fields", + function ($fields) use ($field_slug, $atts) { + /* + * We no longer support settings with hyphens. + */ + if (strpos($field_slug, '-') !== false) { + _doing_it_wrong($field_slug, __('Dashes are no longer supported when registering a setting. You should change it to underscores in later versions.', 'wp-ultimo'), '2.0.0'); + } - _doing_it_wrong($field_slug, __('Dashes are no longer supported when registering a setting. You should change it to underscores in later versions.', 'wp-ultimo'), '2.0.0'); + $default_order = (count($fields) + 1) * 10; - } // end if; + $atts = wp_parse_args( + $atts, + array( + 'setting_id' => $field_slug, + 'title' => '', + 'desc' => '', + 'order' => $default_order, + 'default' => null, + 'capability' => 'manage_network', + 'wrapper_html_attr' => array(), + 'require' => array(), + 'html_attr' => array(), + 'value' => fn() => wu_get_setting($field_slug), + 'display_value' => fn() => wu_get_setting($field_slug), + 'img' => function () use ($field_slug) { - $default_order = (count($fields) + 1) * 10; + $img_id = wu_get_setting($field_slug); - $atts = wp_parse_args($atts, array( - 'setting_id' => $field_slug, - 'title' => '', - 'desc' => '', - 'order' => $default_order, - 'default' => null, - 'capability' => 'manage_network', - 'wrapper_html_attr' => array(), - 'require' => array(), - 'html_attr' => array(), - 'value' => fn() => wu_get_setting($field_slug), - 'display_value' => fn() => wu_get_setting($field_slug), - 'img' => function() use ($field_slug) { + if ( ! $img_id) { + return ''; + } - $img_id = wu_get_setting($field_slug); + $custom_logo_args = wp_get_attachment_image_src($img_id, 'full'); - if (!$img_id) { + return $custom_logo_args ? $custom_logo_args[0] : ''; + }, + ) + ); - return ''; + /** + * Adds v-model + */ + if (wu_get_isset($atts, 'type') !== 'submit') { + $atts['html_attr']['v-model'] = wu_replace_dashes($field_slug); + $atts['html_attr']['true-value'] = '1'; + $atts['html_attr']['false-value'] = '0'; + } - } // end if; + $atts['html_attr']['id'] = $field_slug; - $custom_logo_args = wp_get_attachment_image_src($img_id, 'full'); + /** + * Handle selectize. + */ + $model_name = wu_get_isset($atts['html_attr'], 'data-model'); - return $custom_logo_args ? $custom_logo_args[0] : ''; + if ($model_name) { + if (function_exists("wu_get_{$model_name}") || $model_name === 'page') { + $original_html_attr = $atts['html_attr']; - }, - )); + $atts['html_attr'] = function () use ($field_slug, $model_name, $atts, $original_html_attr) { - /** - * Adds v-model - */ - if (wu_get_isset($atts, 'type') !== 'submit') { + $value = wu_get_setting($field_slug); - $atts['html_attr']['v-model'] = wu_replace_dashes($field_slug); - $atts['html_attr']['true-value'] = '1'; - $atts['html_attr']['false-value'] = '0'; + if ($model_name === 'page') { + $new_attrs['data-selected'] = get_post($value); + } else { + $data_selected = call_user_func("wu_get_{$model_name}", $value); + $new_attrs['data-selected'] = $data_selected->to_search_results(); + } - } // end if; + $new_attrs['data-selected'] = json_encode($new_attrs['data-selected']); - $atts['html_attr']['id'] = $field_slug; + return array_merge($original_html_attr, $new_attrs); + }; + } + } - /** - * Handle selectize. - */ - $model_name = wu_get_isset($atts['html_attr'], 'data-model'); + if ( ! empty($atts['require'])) { + $require_rules = array(); - if ($model_name) { + foreach ($atts['require'] as $attr => $value) { + $attr = str_replace('-', '_', $attr); - if (function_exists("wu_get_{$model_name}") || $model_name === 'page') { + $value = json_encode($value); - $original_html_attr = $atts['html_attr']; + $require_rules[] = "require('{$attr}', {$value})"; + } - $atts['html_attr'] = function() use ($field_slug, $model_name, $atts, $original_html_attr) { + $atts['wrapper_html_attr']['v-show'] = implode(' && ', $require_rules); + $atts['wrapper_html_attr']['v-cloak'] = 'v-cloak'; + } - $value = wu_get_setting($field_slug); + $fields[ $field_slug ] = $atts; - if ($model_name === 'page') { - - $new_attrs['data-selected'] = get_post($value); - - } else { - - $data_selected = call_user_func("wu_get_{$model_name}", $value); - $new_attrs['data-selected'] = $data_selected->to_search_results(); - - } // end if; - - $new_attrs['data-selected'] = json_encode($new_attrs['data-selected']); - - return array_merge($original_html_attr, $new_attrs); - - }; - - } // end if; - - } // end if; - - if (!empty($atts['require'])) { - - $require_rules = array(); - - foreach ($atts['require'] as $attr => $value) { - - $attr = str_replace('-', '_', $attr); - - $value = json_encode($value); - - $require_rules[] = "require('{$attr}', {$value})"; - - } // end foreach; - - $atts['wrapper_html_attr']['v-show'] = implode(' && ', $require_rules); - $atts['wrapper_html_attr']['v-cloak'] = 'v-cloak'; - - } // end if; - - $fields[$field_slug] = $atts; - - return $fields; - - }, $priority ); + return $fields; + }, + $priority + ); $settings = $this->get_all(); /* * Makes sure we install the default value if it is not set yet. */ - if (isset($atts['default']) && $atts['default'] !== null && !isset($settings[$field_slug])) { - + if (isset($atts['default']) && $atts['default'] !== null && ! isset($settings[ $field_slug ])) { $this->save_setting($field_slug, $atts['default']); - - } // end if; - - } // end add_field; + } + } /** * Register the WP Multisite WaaS default sections and fields. @@ -558,252 +522,358 @@ class Settings { // Comma separated string of page ids that are already being used as default option $filter_default_signup_pages = implode(',', array_filter(Checkout_Pages::get_instance()->get_signup_pages())); - $this->add_section('general', array( - 'title' => __('General', 'wp-ultimo'), - 'desc' => __('General', 'wp-ultimo'), - )); - - $this->add_field('general', 'company_header', array( - 'title' => __('Your Business', 'wp-ultimo'), - 'desc' => __('General information about your business..', 'wp-ultimo'), - 'type' => 'header', - ), - 10 + $this->add_section( + 'general', + array( + 'title' => __('General', 'wp-ultimo'), + 'desc' => __('General', 'wp-ultimo'), + ) ); - $this->add_field('general', 'company_name', array( - 'title' => __('Company Name', 'wp-ultimo'), - 'desc' => __('This name is used when generating invoices, for example.', 'wp-ultimo'), - 'type' => 'text', - 'default' => get_network_option(null, 'site_name'), - ), - 20 + $this->add_field( + 'general', + 'company_header', + array( + 'title' => __('Your Business', 'wp-ultimo'), + 'desc' => __('General information about your business..', 'wp-ultimo'), + 'type' => 'header', + ), + 10 ); - $this->add_field('general', 'company_logo', array( - 'title' => __('Upload Company Logo', 'wp-ultimo'), - 'desc' => __('Add your company logo to be used on the login page and other places.', 'wp-ultimo'), - 'type' => 'image', - 'default' => '', - ), - 30 + $this->add_field( + 'general', + 'company_name', + array( + 'title' => __('Company Name', 'wp-ultimo'), + 'desc' => __('This name is used when generating invoices, for example.', 'wp-ultimo'), + 'type' => 'text', + 'default' => get_network_option(null, 'site_name'), + ), + 20 ); - $this->add_field('general', 'company_email', array( - 'title' => __('Company Email Address', 'wp-ultimo'), - 'desc' => __('This email is used when generating invoices, for example.', 'wp-ultimo'), - 'type' => 'text', - 'default' => get_network_option(null, 'admin_email'), - ), + $this->add_field( + 'general', + 'company_logo', + array( + 'title' => __('Upload Company Logo', 'wp-ultimo'), + 'desc' => __('Add your company logo to be used on the login page and other places.', 'wp-ultimo'), + 'type' => 'image', + 'default' => '', + ), + 30 + ); + + $this->add_field( + 'general', + 'company_email', + array( + 'title' => __('Company Email Address', 'wp-ultimo'), + 'desc' => __('This email is used when generating invoices, for example.', 'wp-ultimo'), + 'type' => 'text', + 'default' => get_network_option(null, 'admin_email'), + ), 40 ); - $this->add_field('general', 'company_address', array( - 'title' => __('Company Address', 'wp-ultimo'), - 'desc' => __('This address is used when generating invoices.', 'wp-ultimo'), - 'type' => 'textarea', - 'placeholder' => "350 Fifth Avenue\nManhattan, \nNew York City, NY \n10118", - 'default' => '', - 'html_attr' => array( - 'rows' => 5, + $this->add_field( + 'general', + 'company_address', + array( + 'title' => __('Company Address', 'wp-ultimo'), + 'desc' => __('This address is used when generating invoices.', 'wp-ultimo'), + 'type' => 'textarea', + 'placeholder' => "350 Fifth Avenue\nManhattan, \nNew York City, NY \n10118", + 'default' => '', + 'html_attr' => array( + 'rows' => 5, + ), ), - ), - 50); - - $this->add_field('general', 'company_country', array( - 'title' => __('Company Country', 'wp-ultimo'), - 'desc' => __('This info is used when generating invoices, as well as for calculating when taxes apply in some contexts.', 'wp-ultimo'), - 'type' => 'select', - 'options' => 'wu_get_countries', - 'default' => array($this, 'get_default_company_country'), - ), 60); - - $this->add_field('general', 'currency_header', array( - 'title' => __('Currency Options', 'wp-ultimo'), - 'desc' => __('The following options affect how prices are displayed on the frontend, the backend and in reports.', 'wp-ultimo'), - 'type' => 'header', - ), 70 + 50 ); - $this->add_field('general', 'currency_symbol', array( - 'title' => __('Currency', 'wp-ultimo'), - 'desc' => __('Select the currency to be used in WP Multisite WaaS.', 'wp-ultimo'), - 'type' => 'select', - 'default' => 'USD', - 'options' => 'wu_get_currencies', - ), 80 + $this->add_field( + 'general', + 'company_country', + array( + 'title' => __('Company Country', 'wp-ultimo'), + 'desc' => __('This info is used when generating invoices, as well as for calculating when taxes apply in some contexts.', 'wp-ultimo'), + 'type' => 'select', + 'options' => 'wu_get_countries', + 'default' => array($this, 'get_default_company_country'), + ), + 60 ); - $this->add_field('general', 'currency_position', array( - 'title' => __('Currency Position', 'wp-ultimo'), - 'desc' => __('This setting affects all prices displayed across the plugin elements.', 'wp-ultimo'), - 'desc' => '', - 'type' => 'select', - 'default' => '%s %v', - 'options' => array( - '%s%v' => __('Left ($99.99)', 'wp-ultimo'), - '%v%s' => __('Right (99.99$)', 'wp-ultimo'), - '%s %v' => __('Left with space ($ 99.99)', 'wp-ultimo'), - '%v %s' => __('Right with space (99.99 $)', 'wp-ultimo'), - ) - ), 90 + $this->add_field( + 'general', + 'currency_header', + array( + 'title' => __('Currency Options', 'wp-ultimo'), + 'desc' => __('The following options affect how prices are displayed on the frontend, the backend and in reports.', 'wp-ultimo'), + 'type' => 'header', + ), + 70 ); - $this->add_field('general', 'decimal_separator', array( - 'title' => __('Decimal Separator', 'wp-ultimo'), - 'desc' => __('This setting affects all prices displayed across the plugin elements.', 'wp-ultimo'), - 'type' => 'text', - 'default' => '.', - ), 100); + $this->add_field( + 'general', + 'currency_symbol', + array( + 'title' => __('Currency', 'wp-ultimo'), + 'desc' => __('Select the currency to be used in WP Multisite WaaS.', 'wp-ultimo'), + 'type' => 'select', + 'default' => 'USD', + 'options' => 'wu_get_currencies', + ), + 80 + ); - $this->add_field('general', 'thousand_separator', array( - 'title' => __('Thousand Separator', 'wp-ultimo'), - 'desc' => __('This setting affects all prices displayed across the plugin elements.', 'wp-ultimo'), - 'type' => 'text', - 'default' => ',', - 'raw' => true - ),110); + $this->add_field( + 'general', + 'currency_position', + array( + 'title' => __('Currency Position', 'wp-ultimo'), + 'desc' => __('This setting affects all prices displayed across the plugin elements.', 'wp-ultimo'), + 'desc' => '', + 'type' => 'select', + 'default' => '%s %v', + 'options' => array( + '%s%v' => __('Left ($99.99)', 'wp-ultimo'), + '%v%s' => __('Right (99.99$)', 'wp-ultimo'), + '%s %v' => __('Left with space ($ 99.99)', 'wp-ultimo'), + '%v %s' => __('Right with space (99.99 $)', 'wp-ultimo'), + ), + ), + 90 + ); - $this->add_field('general', 'precision', array( - 'title' => __('Number of Decimals', 'wp-ultimo'), - 'desc' => __('This setting affects all prices displayed across the plugin elements.', 'wp-ultimo'), - 'type' => 'number', - 'default' => '2', - 'min' => 0, - ), 120); + $this->add_field( + 'general', + 'decimal_separator', + array( + 'title' => __('Decimal Separator', 'wp-ultimo'), + 'desc' => __('This setting affects all prices displayed across the plugin elements.', 'wp-ultimo'), + 'type' => 'text', + 'default' => '.', + ), + 100 + ); + + $this->add_field( + 'general', + 'thousand_separator', + array( + 'title' => __('Thousand Separator', 'wp-ultimo'), + 'desc' => __('This setting affects all prices displayed across the plugin elements.', 'wp-ultimo'), + 'type' => 'text', + 'default' => ',', + 'raw' => true, + ), + 110 + ); + + $this->add_field( + 'general', + 'precision', + array( + 'title' => __('Number of Decimals', 'wp-ultimo'), + 'desc' => __('This setting affects all prices displayed across the plugin elements.', 'wp-ultimo'), + 'type' => 'number', + 'default' => '2', + 'min' => 0, + ), + 120 + ); /* * Login & Registration * This section holds the Login & Registration settings of the WP Multisite WaaS Plugin. */ - $this->add_section('login-and-registration', array( - 'title' => __('Login & Registration', 'wp-ultimo'), - 'desc' => __('Login & Registration', 'wp-ultimo'), - 'icon' => 'dashicons-wu-key', - )); + $this->add_section( + 'login-and-registration', + array( + 'title' => __('Login & Registration', 'wp-ultimo'), + 'desc' => __('Login & Registration', 'wp-ultimo'), + 'icon' => 'dashicons-wu-key', + ) + ); - $this->add_field('login-and-registration', 'registration_header', array( - 'title' => __('Login and Registration Options', 'wp-ultimo'), - 'desc' => __('Options related to registration and login behavior.', 'wp-ultimo'), - 'type' => 'header', - )); + $this->add_field( + 'login-and-registration', + 'registration_header', + array( + 'title' => __('Login and Registration Options', 'wp-ultimo'), + 'desc' => __('Options related to registration and login behavior.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - $this->add_field('login-and-registration', 'enable_registration', array( - 'title' => __('Enable Registration', 'wp-ultimo'), - 'desc' => __('Turning this toggle off will disable registration in all checkout forms across the network.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + $this->add_field( + 'login-and-registration', + 'enable_registration', + array( + 'title' => __('Enable Registration', 'wp-ultimo'), + 'desc' => __('Turning this toggle off will disable registration in all checkout forms across the network.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); - $this->add_field('login-and-registration', 'enable_email_verification', array( - 'title' => __('Enable email verification', 'wp-ultimo'), - 'desc' => __('Enabling this option will require the customer to verify their email address when subscribing to a free plan or a plan with a trial period. Sites will not be created until the customer email verification status is changed to verified.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + $this->add_field( + 'login-and-registration', + 'enable_email_verification', + array( + 'title' => __('Enable email verification', 'wp-ultimo'), + 'desc' => __('Enabling this option will require the customer to verify their email address when subscribing to a free plan or a plan with a trial period. Sites will not be created until the customer email verification status is changed to verified.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); - $this->add_field('login-and-registration', 'default_registration_page', array( - 'type' => 'model', - 'title' => __('Default Registration Page', 'wp-ultimo'), - 'placeholder' => __('Search pages on the main site...', 'wp-ultimo'), - 'desc' => __('Only published pages on the main site are available for selection, and you need to make sure they contain a [wu_checkout] shortcode.', 'wp-ultimo'), - 'tooltip' => '', - 'html_attr' => array( - 'data-base-link' => get_admin_url(wu_get_main_site_id(), 'post.php?action=edit&post'), - 'data-model' => 'page', - 'data-value-field' => 'ID', - 'data-label-field' => 'post_title', - 'data-search-field' => 'post_title', - 'data-max-items' => 1, - 'data-exclude' => $filter_default_signup_pages - ), - )); + $this->add_field( + 'login-and-registration', + 'default_registration_page', + array( + 'type' => 'model', + 'title' => __('Default Registration Page', 'wp-ultimo'), + 'placeholder' => __('Search pages on the main site...', 'wp-ultimo'), + 'desc' => __('Only published pages on the main site are available for selection, and you need to make sure they contain a [wu_checkout] shortcode.', 'wp-ultimo'), + 'tooltip' => '', + 'html_attr' => array( + 'data-base-link' => get_admin_url(wu_get_main_site_id(), 'post.php?action=edit&post'), + 'data-model' => 'page', + 'data-value-field' => 'ID', + 'data-label-field' => 'post_title', + 'data-search-field' => 'post_title', + 'data-max-items' => 1, + 'data-exclude' => $filter_default_signup_pages, + ), + ) + ); - $this->add_field('login-and-registration', 'enable_custom_login_page', array( - 'title' => __('Use Custom Login Page', 'wp-ultimo'), - 'desc' => __('Turn this toggle on to select a custom page to be used as the login page.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - )); + $this->add_field( + 'login-and-registration', + 'enable_custom_login_page', + array( + 'title' => __('Use Custom Login Page', 'wp-ultimo'), + 'desc' => __('Turn this toggle on to select a custom page to be used as the login page.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + ) + ); - $this->add_field('login-and-registration', 'default_login_page', array( - 'type' => 'model', - 'title' => __('Default Login Page', 'wp-ultimo'), - 'placeholder' => __('Search pages on the main site...', 'wp-ultimo'), - 'desc' => __('Only published pages on the main site are available for selection, and you need to make sure they contain a [wu_login_form] shortcode.', 'wp-ultimo'), - 'tooltip' => '', - 'html_attr' => array( - 'data-base-link' => get_admin_url(wu_get_main_site_id(), 'post.php?action=edit&post'), - 'data-model' => 'page', - 'data-value-field' => 'ID', - 'data-label-field' => 'post_title', - 'data-search-field' => 'post_title', - 'data-max-items' => 1, - ), - 'require' => array( - 'enable_custom_login_page' => true, - ), - )); + $this->add_field( + 'login-and-registration', + 'default_login_page', + array( + 'type' => 'model', + 'title' => __('Default Login Page', 'wp-ultimo'), + 'placeholder' => __('Search pages on the main site...', 'wp-ultimo'), + 'desc' => __('Only published pages on the main site are available for selection, and you need to make sure they contain a [wu_login_form] shortcode.', 'wp-ultimo'), + 'tooltip' => '', + 'html_attr' => array( + 'data-base-link' => get_admin_url(wu_get_main_site_id(), 'post.php?action=edit&post'), + 'data-model' => 'page', + 'data-value-field' => 'ID', + 'data-label-field' => 'post_title', + 'data-search-field' => 'post_title', + 'data-max-items' => 1, + ), + 'require' => array( + 'enable_custom_login_page' => true, + ), + ) + ); - $this->add_field('login-and-registration', 'obfuscate_original_login_url', array( - 'title' => __('Obfuscate the Original Login URL (wp-login.php)', 'wp-ultimo'), - 'desc' => __('If this option is enabled, we will display a 404 error when a user tries to access the original wp-login.php link. This is useful to prevent brute-force attacks.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - 'require' => array( - 'enable_custom_login_page' => 1, - ), - )); + $this->add_field( + 'login-and-registration', + 'obfuscate_original_login_url', + array( + 'title' => __('Obfuscate the Original Login URL (wp-login.php)', 'wp-ultimo'), + 'desc' => __('If this option is enabled, we will display a 404 error when a user tries to access the original wp-login.php link. This is useful to prevent brute-force attacks.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + 'require' => array( + 'enable_custom_login_page' => 1, + ), + ) + ); - $this->add_field('login-and-registration', 'subsite_custom_login_logo', array( - 'title' => __('Use Sub-site logo on Login Page', 'wp-ultimo'), - 'desc' => __('Toggle this option to replace the WordPress logo on the sub-site login page with the logo set for that sub-site. If unchecked, the network logo will be used instead.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - 'require' => array( - 'enable_custom_login_page' => 0, - ), - )); + $this->add_field( + 'login-and-registration', + 'subsite_custom_login_logo', + array( + 'title' => __('Use Sub-site logo on Login Page', 'wp-ultimo'), + 'desc' => __('Toggle this option to replace the WordPress logo on the sub-site login page with the logo set for that sub-site. If unchecked, the network logo will be used instead.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + 'require' => array( + 'enable_custom_login_page' => 0, + ), + ) + ); - $this->add_field('login-and-registration', 'force_publish_sites_sync', array( - 'title' => __('Force Synchronous Site Publication ', 'wp-ultimo'), - 'desc' => __('By default, when a new pending site needs to be converted into a real network site, the publishing process happens via Job Queue, asynchronously. Enable this option to force the publication to happen in the same request as the signup. Be careful, as this can cause timeouts depending on the size of the site templates being copied.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - )); + $this->add_field( + 'login-and-registration', + 'force_publish_sites_sync', + array( + 'title' => __('Force Synchronous Site Publication ', 'wp-ultimo'), + 'desc' => __('By default, when a new pending site needs to be converted into a real network site, the publishing process happens via Job Queue, asynchronously. Enable this option to force the publication to happen in the same request as the signup. Be careful, as this can cause timeouts depending on the size of the site templates being copied.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + ) + ); - $this->add_field('login-and-registration', 'other_header', array( - 'title' => __('Other Options', 'wp-ultimo'), - 'desc' => __('Other registration-related options.', 'wp-ultimo'), - 'type' => 'header', - )); + $this->add_field( + 'login-and-registration', + 'other_header', + array( + 'title' => __('Other Options', 'wp-ultimo'), + 'desc' => __('Other registration-related options.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - $this->add_field('login-and-registration', 'default_role', array( - 'title' => __('Default Role', 'wp-ultimo'), - 'desc' => __('Set the role to be applied to the user during the signup process.', 'wp-ultimo'), - 'type' => 'select', - 'default' => 'administrator', - 'options' => 'wu_get_roles_as_options', - )); + $this->add_field( + 'login-and-registration', + 'default_role', + array( + 'title' => __('Default Role', 'wp-ultimo'), + 'desc' => __('Set the role to be applied to the user during the signup process.', 'wp-ultimo'), + 'type' => 'select', + 'default' => 'administrator', + 'options' => 'wu_get_roles_as_options', + ) + ); - $this->add_field('login-and-registration', 'add_users_to_main_site', array( - 'title' => __('Add Users to the Main Site as well?', 'wp-ultimo'), - 'desc' => __('Enabling this option will also add the user to the main site of your network.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - )); + $this->add_field( + 'login-and-registration', + 'add_users_to_main_site', + array( + 'title' => __('Add Users to the Main Site as well?', 'wp-ultimo'), + 'desc' => __('Enabling this option will also add the user to the main site of your network.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + ) + ); - $this->add_field('login-and-registration', 'main_site_default_role', array( - 'title' => __('Add to Main Site with Role...', 'wp-ultimo'), - 'desc' => __('Select the role WP Multisite WaaS should use when adding the user to the main site of your network. Be careful.', 'wp-ultimo'), - 'type' => 'select', - 'default' => 'subscriber', - 'options' => 'wu_get_roles_as_options', - 'require' => array( - 'add_users_to_main_site' => 1, - ), - )); + $this->add_field( + 'login-and-registration', + 'main_site_default_role', + array( + 'title' => __('Add to Main Site with Role...', 'wp-ultimo'), + 'desc' => __('Select the role WP Multisite WaaS should use when adding the user to the main site of your network. Be careful.', 'wp-ultimo'), + 'type' => 'select', + 'default' => 'subscriber', + 'options' => 'wu_get_roles_as_options', + 'require' => array( + 'add_users_to_main_site' => 1, + ), + ) + ); do_action('wu_settings_login'); @@ -812,188 +882,243 @@ class Settings { * This section holds the Membership settings of the WP Multisite WaaS Plugin. */ - $this->add_section('memberships', array( - 'title' => __('Memberships', 'wp-ultimo'), - 'desc' => __('Memberships', 'wp-ultimo'), - 'icon' => 'dashicons-wu-infinity', - )); + $this->add_section( + 'memberships', + array( + 'title' => __('Memberships', 'wp-ultimo'), + 'desc' => __('Memberships', 'wp-ultimo'), + 'icon' => 'dashicons-wu-infinity', + ) + ); - $this->add_field('memberships', 'default_update_page', array( - 'type' => 'model', - 'title' => __('Default Membership Update Page', 'wp-ultimo'), - 'placeholder' => __('Search pages on the main site...', 'wp-ultimo'), - 'desc' => __('Only published pages on the main site are available for selection, and you need to make sure they contain a [wu_checkout] shortcode.', 'wp-ultimo'), - 'tooltip' => '', - 'html_attr' => array( - 'data-base-link' => get_admin_url(wu_get_main_site_id(), 'post.php?action=edit&post'), - 'data-model' => 'page', - 'data-value-field' => 'ID', - 'data-label-field' => 'post_title', - 'data-search-field' => 'post_title', - 'data-max-items' => 1, - 'data-exclude' => $filter_default_signup_pages - ), - )); - - $this->add_field('memberships', 'block_frontend', array( - 'title' => __('Block Frontend Access', 'wp-ultimo'), - 'desc' => __('Block the frontend access of network sites after a membership is no longer active.', 'wp-ultimo'), - 'tooltip' => __('By default, if a user does not pay and the account goes inactive, only the admin panel will be blocked, but the user\'s site will still be accessible on the frontend. If enabled, this option will also block frontend access in those cases.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - )); - - $this->add_field('memberships', 'block_frontend_grace_period', array( - 'title' => __('Frontend Block Grace Period', 'wp-ultimo'), - 'desc' => __('Select the number of days WP Multisite WaaS should wait after the membership goes inactive before blocking the frontend access. Leave 0 to block immediately after the membership becomes inactive.', 'wp-ultimo'), - 'type' => 'number', - 'default' => 0, - 'min' => 0, - 'require' => array( - 'block_frontend' => 1, - ), - )); - - $this->add_field('memberships', 'default_block_frontend_page', array( - 'title' => __('Frontend Block Page', 'wp-ultimo'), - 'desc' => __('Select a page on the main site to redirect user if access is blocked', 'wp-ultimo'), - 'tooltip' => '', - 'html_attr' => array( - 'data-base-link' => get_admin_url(wu_get_main_site_id(), 'post.php?action=edit&post'), - 'data-model' => 'page', - 'data-value-field' => 'ID', - 'data-label-field' => 'post_title', - 'data-search-field' => 'post_title', - 'data-max-items' => 1, - ), - 'require' => array( - 'block_frontend' => 1, - ), - )); - - $this->add_field('memberships', 'enable_multiple_memberships', array( - 'title' => __('Enable Multiple Memberships per Customer', 'wp-ultimo'), - 'desc' => __('Enabling this option will allow your users to create more than one membership.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - )); - - $this->add_field('memberships', 'enable_multiple_sites', array( - 'title' => __('Enable Multiple Sites per Membership', 'wp-ultimo'), - 'desc' => __('Enabling this option will allow your customers to create more than one site. You can limit how many sites your users can create in a per plan basis.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - )); - - $this->add_field('memberships', 'block_sites_on_downgrade', array( - 'title' => __('Block Sites on Downgrade', 'wp-ultimo'), - 'desc' => __('Choose how WP Multisite WaaS should handle client sites above their plan quota on downgrade.', 'wp-ultimo'), - 'type' => 'select', - 'default' => 'none', - 'options' => array( - 'none' => __('Keep sites as is (do nothing)', 'wp-ultimo'), - 'block-frontend' => __('Block only frontend access', 'wp-ultimo'), - 'block-backend' => __('Block only backend access', 'wp-ultimo'), - 'block-both' => __('Block both frontend and backend access', 'wp-ultimo'), - ), - 'require' => array( - 'enable_multiple_sites' => true, - ), - )); - - $this->add_field('memberships', 'move_posts_on_downgrade', array( - 'title' => __('Move Posts on Downgrade', 'wp-ultimo'), - 'desc' => __('Select how you want to handle the posts above the quota on downgrade. This will apply to all post types with quotas set.', 'wp-ultimo'), - 'type' => 'select', - 'default' => 'none', - 'options' => array( - 'none' => __('Keep posts as is (do nothing)', 'wp-ultimo'), - 'trash' => __('Move posts above the new quota to the Trash', 'wp-ultimo'), - 'draft' => __('Mark posts above the new quota as Drafts', 'wp-ultimo'), - ), - )); - - $this->add_field('memberships', 'emulated_post_types_header', array( - 'type' => 'header', - 'title' => __('Emulated Post Types', 'wp-ultimo'), - 'desc' => __('Emulates the registering of a custom post type to be able to create limits for it without having to activate plugins on the main site.', 'wp-ultimo'), - )); - - $this->add_field('memberships', 'emulated_post_types_explanation', array( - 'type' => 'note', - 'desc' => __('By default, WP Multisite WaaS only allows super admins to limit post types that are registered on the main site. This makes sense from a technical stand-point but it also forces you to have plugins network-activated in order to be able to set limitations for their custom post types. Using this option, you can emulate the registering of a post type. This will register them on the main site and allow you to create limits for them on your products.', 'wp-ultimo'), - 'classes' => '', - 'wrapper_classes' => '', - )); - - $this->add_field('memberships', 'emulated_post_types_empty', array( - 'type' => 'note', - 'desc' => __('Add the first post type using the button below.', 'wp-ultimo'), - 'classes' => 'wu-text-gray-600 wu-text-xs wu-text-center wu-w-full', - 'wrapper_classes' => 'wu-bg-gray-100 wu-items-end', - 'wrapper_html_attr' => array( - 'v-if' => 'emulated_post_types.length === 0', - 'v-cloak' => '1', - ), - )); - - $this->add_field('memberships', 'emulated_post_types', array( - 'type' => 'group', - 'tooltip' => '', - 'raw' => true, - 'default' => array(), - 'wrapper_classes' => 'wu-relative wu-bg-gray-100 wu-pb-2', - 'wrapper_html_attr' => array( - 'v-if' => 'emulated_post_types.length', - 'v-for' => '(emulated_post_type, index) in emulated_post_types', - 'v-cloak' => '1', - ), - 'fields' => array( - 'emulated_post_types_remove' => array( - 'type' => 'note', - 'desc' => sprintf('', __('Remove', 'wp-ultimo')), - 'wrapper_classes' => 'wu-absolute wu-top-0 wu-right-0', + $this->add_field( + 'memberships', + 'default_update_page', + array( + 'type' => 'model', + 'title' => __('Default Membership Update Page', 'wp-ultimo'), + 'placeholder' => __('Search pages on the main site...', 'wp-ultimo'), + 'desc' => __('Only published pages on the main site are available for selection, and you need to make sure they contain a [wu_checkout] shortcode.', 'wp-ultimo'), + 'tooltip' => '', + 'html_attr' => array( + 'data-base-link' => get_admin_url(wu_get_main_site_id(), 'post.php?action=edit&post'), + 'data-model' => 'page', + 'data-value-field' => 'ID', + 'data-label-field' => 'post_title', + 'data-search-field' => 'post_title', + 'data-max-items' => 1, + 'data-exclude' => $filter_default_signup_pages, ), - 'emulated_post_types_slug' => array( - 'type' => 'text', - 'title' => __('Post Type Slug', 'wp-ultimo'), - 'placeholder' => __('e.g. product', 'wp-ultimo'), - 'wrapper_classes' => 'wu-w-5/12', - 'html_attr' => array( - 'v-model' => 'emulated_post_type.post_type', - 'v-bind:name' => '"emulated_post_types[" + index + "][post_type]"', + ) + ); + + $this->add_field( + 'memberships', + 'block_frontend', + array( + 'title' => __('Block Frontend Access', 'wp-ultimo'), + 'desc' => __('Block the frontend access of network sites after a membership is no longer active.', 'wp-ultimo'), + 'tooltip' => __('By default, if a user does not pay and the account goes inactive, only the admin panel will be blocked, but the user\'s site will still be accessible on the frontend. If enabled, this option will also block frontend access in those cases.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + ) + ); + + $this->add_field( + 'memberships', + 'block_frontend_grace_period', + array( + 'title' => __('Frontend Block Grace Period', 'wp-ultimo'), + 'desc' => __('Select the number of days WP Multisite WaaS should wait after the membership goes inactive before blocking the frontend access. Leave 0 to block immediately after the membership becomes inactive.', 'wp-ultimo'), + 'type' => 'number', + 'default' => 0, + 'min' => 0, + 'require' => array( + 'block_frontend' => 1, + ), + ) + ); + + $this->add_field( + 'memberships', + 'default_block_frontend_page', + array( + 'title' => __('Frontend Block Page', 'wp-ultimo'), + 'desc' => __('Select a page on the main site to redirect user if access is blocked', 'wp-ultimo'), + 'tooltip' => '', + 'html_attr' => array( + 'data-base-link' => get_admin_url(wu_get_main_site_id(), 'post.php?action=edit&post'), + 'data-model' => 'page', + 'data-value-field' => 'ID', + 'data-label-field' => 'post_title', + 'data-search-field' => 'post_title', + 'data-max-items' => 1, + ), + 'require' => array( + 'block_frontend' => 1, + ), + ) + ); + + $this->add_field( + 'memberships', + 'enable_multiple_memberships', + array( + 'title' => __('Enable Multiple Memberships per Customer', 'wp-ultimo'), + 'desc' => __('Enabling this option will allow your users to create more than one membership.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + ) + ); + + $this->add_field( + 'memberships', + 'enable_multiple_sites', + array( + 'title' => __('Enable Multiple Sites per Membership', 'wp-ultimo'), + 'desc' => __('Enabling this option will allow your customers to create more than one site. You can limit how many sites your users can create in a per plan basis.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + ) + ); + + $this->add_field( + 'memberships', + 'block_sites_on_downgrade', + array( + 'title' => __('Block Sites on Downgrade', 'wp-ultimo'), + 'desc' => __('Choose how WP Multisite WaaS should handle client sites above their plan quota on downgrade.', 'wp-ultimo'), + 'type' => 'select', + 'default' => 'none', + 'options' => array( + 'none' => __('Keep sites as is (do nothing)', 'wp-ultimo'), + 'block-frontend' => __('Block only frontend access', 'wp-ultimo'), + 'block-backend' => __('Block only backend access', 'wp-ultimo'), + 'block-both' => __('Block both frontend and backend access', 'wp-ultimo'), + ), + 'require' => array( + 'enable_multiple_sites' => true, + ), + ) + ); + + $this->add_field( + 'memberships', + 'move_posts_on_downgrade', + array( + 'title' => __('Move Posts on Downgrade', 'wp-ultimo'), + 'desc' => __('Select how you want to handle the posts above the quota on downgrade. This will apply to all post types with quotas set.', 'wp-ultimo'), + 'type' => 'select', + 'default' => 'none', + 'options' => array( + 'none' => __('Keep posts as is (do nothing)', 'wp-ultimo'), + 'trash' => __('Move posts above the new quota to the Trash', 'wp-ultimo'), + 'draft' => __('Mark posts above the new quota as Drafts', 'wp-ultimo'), + ), + ) + ); + + $this->add_field( + 'memberships', + 'emulated_post_types_header', + array( + 'type' => 'header', + 'title' => __('Emulated Post Types', 'wp-ultimo'), + 'desc' => __('Emulates the registering of a custom post type to be able to create limits for it without having to activate plugins on the main site.', 'wp-ultimo'), + ) + ); + + $this->add_field( + 'memberships', + 'emulated_post_types_explanation', + array( + 'type' => 'note', + 'desc' => __('By default, WP Multisite WaaS only allows super admins to limit post types that are registered on the main site. This makes sense from a technical stand-point but it also forces you to have plugins network-activated in order to be able to set limitations for their custom post types. Using this option, you can emulate the registering of a post type. This will register them on the main site and allow you to create limits for them on your products.', 'wp-ultimo'), + 'classes' => '', + 'wrapper_classes' => '', + ) + ); + + $this->add_field( + 'memberships', + 'emulated_post_types_empty', + array( + 'type' => 'note', + 'desc' => __('Add the first post type using the button below.', 'wp-ultimo'), + 'classes' => 'wu-text-gray-600 wu-text-xs wu-text-center wu-w-full', + 'wrapper_classes' => 'wu-bg-gray-100 wu-items-end', + 'wrapper_html_attr' => array( + 'v-if' => 'emulated_post_types.length === 0', + 'v-cloak' => '1', + ), + ) + ); + + $this->add_field( + 'memberships', + 'emulated_post_types', + array( + 'type' => 'group', + 'tooltip' => '', + 'raw' => true, + 'default' => array(), + 'wrapper_classes' => 'wu-relative wu-bg-gray-100 wu-pb-2', + 'wrapper_html_attr' => array( + 'v-if' => 'emulated_post_types.length', + 'v-for' => '(emulated_post_type, index) in emulated_post_types', + 'v-cloak' => '1', + ), + 'fields' => array( + 'emulated_post_types_remove' => array( + 'type' => 'note', + 'desc' => sprintf('', __('Remove', 'wp-ultimo')), + 'wrapper_classes' => 'wu-absolute wu-top-0 wu-right-0', + ), + 'emulated_post_types_slug' => array( + 'type' => 'text', + 'title' => __('Post Type Slug', 'wp-ultimo'), + 'placeholder' => __('e.g. product', 'wp-ultimo'), + 'wrapper_classes' => 'wu-w-5/12', + 'html_attr' => array( + 'v-model' => 'emulated_post_type.post_type', + 'v-bind:name' => '"emulated_post_types[" + index + "][post_type]"', + ), + ), + 'emulated_post_types_label' => array( + 'type' => 'text', + 'title' => __('Post Type Label', 'wp-ultimo'), + 'placeholder' => __('e.g. Products', 'wp-ultimo'), + 'wrapper_classes' => 'wu-w-7/12 wu-ml-2', + 'html_attr' => array( + 'v-model' => 'emulated_post_type.label', + 'v-bind:name' => '"emulated_post_types[" + index + "][label]"', + ), ), ), - 'emulated_post_types_label' => array( - 'type' => 'text', - 'title' => __('Post Type Label', 'wp-ultimo'), - 'placeholder' => __('e.g. Products', 'wp-ultimo'), - 'wrapper_classes' => 'wu-w-7/12 wu-ml-2', - 'html_attr' => array( - 'v-model' => 'emulated_post_type.label', - 'v-bind:name' => '"emulated_post_types[" + index + "][label]"', - ), - ), - ), - )); + ) + ); - $this->add_field('memberships', 'emulated_post_types_repeat', array( - 'type' => 'submit', - 'title' => __('+ Add Post Type', 'wp-ultimo'), - 'classes' => 'wu-uppercase wu-text-2xs wu-text-blue-700 wu-border-none wu-bg-transparent wu-font-bold wu-text-right wu-w-full wu-cursor-pointer', - 'wrapper_classes' => 'wu-bg-gray-100 wu-items-end', - 'wrapper_html_attr' => array( - 'v-cloak' => '1', - ), - 'html_attr' => array( - 'v-on:click.prevent' => '() => { + $this->add_field( + 'memberships', + 'emulated_post_types_repeat', + array( + 'type' => 'submit', + 'title' => __('+ Add Post Type', 'wp-ultimo'), + 'classes' => 'wu-uppercase wu-text-2xs wu-text-blue-700 wu-border-none wu-bg-transparent wu-font-bold wu-text-right wu-w-full wu-cursor-pointer', + 'wrapper_classes' => 'wu-bg-gray-100 wu-items-end', + 'wrapper_html_attr' => array( + 'v-cloak' => '1', + ), + 'html_attr' => array( + 'v-on:click.prevent' => '() => { emulated_post_types = Array.isArray(emulated_post_types) ? emulated_post_types : []; emulated_post_types.push({ post_type: "", label: "", }) }', - ), - )); + ), + ) + ); do_action('wu_settings_memberships'); @@ -1002,107 +1127,158 @@ class Settings { * This section holds the Site Templates settings of the WP Multisite WaaS Plugin. */ - $this->add_section('sites', array( - 'title' => __('Sites', 'wp-ultimo'), - 'desc' => __('Sites', 'wp-ultimo'), - 'icon' => 'dashicons-wu-browser', - )); + $this->add_section( + 'sites', + array( + 'title' => __('Sites', 'wp-ultimo'), + 'desc' => __('Sites', 'wp-ultimo'), + 'icon' => 'dashicons-wu-browser', + ) + ); - $this->add_field('sites', 'sites_features_heading', array( - 'title' => __('Site Options', 'wp-ultimo'), - 'desc' => __('Configure certain aspects of how network Sites behave.', 'wp-ultimo'), - 'type' => 'header', - )); + $this->add_field( + 'sites', + 'sites_features_heading', + array( + 'title' => __('Site Options', 'wp-ultimo'), + 'desc' => __('Configure certain aspects of how network Sites behave.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - $this->add_field('sites', 'default_new_site_page', array( - 'type' => 'model', - 'title' => __('Default New Site Page', 'wp-ultimo'), - 'placeholder' => __('Search pages on the main site...', 'wp-ultimo'), - 'desc' => __('Only published pages on the main site are available for selection, and you need to make sure they contain a [wu_checkout] shortcode.', 'wp-ultimo'), - 'tooltip' => '', - 'html_attr' => array( - 'data-base-link' => get_admin_url(wu_get_main_site_id(), 'post.php?action=edit&post'), - 'data-model' => 'page', - 'data-value-field' => 'ID', - 'data-label-field' => 'post_title', - 'data-search-field' => 'post_title', - 'data-max-items' => 1, - 'data-exclude' => $filter_default_signup_pages - ), - )); + $this->add_field( + 'sites', + 'default_new_site_page', + array( + 'type' => 'model', + 'title' => __('Default New Site Page', 'wp-ultimo'), + 'placeholder' => __('Search pages on the main site...', 'wp-ultimo'), + 'desc' => __('Only published pages on the main site are available for selection, and you need to make sure they contain a [wu_checkout] shortcode.', 'wp-ultimo'), + 'tooltip' => '', + 'html_attr' => array( + 'data-base-link' => get_admin_url(wu_get_main_site_id(), 'post.php?action=edit&post'), + 'data-model' => 'page', + 'data-value-field' => 'ID', + 'data-label-field' => 'post_title', + 'data-search-field' => 'post_title', + 'data-max-items' => 1, + 'data-exclude' => $filter_default_signup_pages, + ), + ) + ); - $this->add_field('sites', 'enable_visits_limiting', array( - 'title' => __('Enable Visits Limitation & Counting', 'wp-ultimo'), - 'desc' => __('Enabling this option will add visits limitation settings to the plans and add the functionality necessary to count site visits on the front-end.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + $this->add_field( + 'sites', + 'enable_visits_limiting', + array( + 'title' => __('Enable Visits Limitation & Counting', 'wp-ultimo'), + 'desc' => __('Enabling this option will add visits limitation settings to the plans and add the functionality necessary to count site visits on the front-end.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); - $this->add_field('sites', 'enable_screenshot_generator', array( - 'title' => __('Enable Screenshot Generator', 'wp-ultimo'), - 'desc' => __('With this option is enabled, WP Multisite WaaS will take a screenshot for every newly created site on your network and set the resulting image as that site\'s featured image. This features requires a valid license key to work and it is not supported for local sites.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + $this->add_field( + 'sites', + 'enable_screenshot_generator', + array( + 'title' => __('Enable Screenshot Generator', 'wp-ultimo'), + 'desc' => __('With this option is enabled, WP Multisite WaaS will take a screenshot for every newly created site on your network and set the resulting image as that site\'s featured image. This features requires a valid license key to work and it is not supported for local sites.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); - $this->add_field('sites', 'wordpress_features_heading', array( - 'title' => __('WordPress Features', 'wp-ultimo'), - 'desc' => __('Override default WordPress settings for network Sites.', 'wp-ultimo'), - 'type' => 'header', - )); + $this->add_field( + 'sites', + 'wordpress_features_heading', + array( + 'title' => __('WordPress Features', 'wp-ultimo'), + 'desc' => __('Override default WordPress settings for network Sites.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - $this->add_field('sites', 'menu_items_plugin', array( - 'title' => __('Enable Plugins Menu', 'wp-ultimo'), - 'desc' => __('Do you want to let users on the network to have access to the Plugins page, activating plugins for their sites? If this option is disabled, the customer will not be able to manage the site plugins.', 'wp-ultimo'), - 'tooltip' => __('You can select which plugins the user will be able to use for each plan.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + $this->add_field( + 'sites', + 'menu_items_plugin', + array( + 'title' => __('Enable Plugins Menu', 'wp-ultimo'), + 'desc' => __('Do you want to let users on the network to have access to the Plugins page, activating plugins for their sites? If this option is disabled, the customer will not be able to manage the site plugins.', 'wp-ultimo'), + 'tooltip' => __('You can select which plugins the user will be able to use for each plan.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); - $this->add_field('sites', 'add_new_users', array( - 'title' => __('Add New Users', 'wp-ultimo'), - 'desc' => __('Allow site administrators to add new users to their site via the "Users → Add New" page.', 'wp-ultimo'), - 'tooltip' => __('You can limit the number of users allowed for each plan.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + $this->add_field( + 'sites', + 'add_new_users', + array( + 'title' => __('Add New Users', 'wp-ultimo'), + 'desc' => __('Allow site administrators to add new users to their site via the "Users → Add New" page.', 'wp-ultimo'), + 'tooltip' => __('You can limit the number of users allowed for each plan.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); - $this->add_field('sites', 'site_template_features_heading', array( - 'title' => __('Site Template Options', 'wp-ultimo'), - 'desc' => __('Configure certain aspects of how Site Templates behave.', 'wp-ultimo'), - 'type' => 'header', - )); + $this->add_field( + 'sites', + 'site_template_features_heading', + array( + 'title' => __('Site Template Options', 'wp-ultimo'), + 'desc' => __('Configure certain aspects of how Site Templates behave.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - $this->add_field('sites', 'allow_template_switching', array( - 'title' => __('Allow Template Switching', 'wp-ultimo'), - 'desc' => __("Enabling this option will add an option on your client's dashboard to switch their site template to another one available on the catalog of available templates. The data is lost after a switch as the data from the new template is copied over.", 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + $this->add_field( + 'sites', + 'allow_template_switching', + array( + 'title' => __('Allow Template Switching', 'wp-ultimo'), + 'desc' => __("Enabling this option will add an option on your client's dashboard to switch their site template to another one available on the catalog of available templates. The data is lost after a switch as the data from the new template is copied over.", 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); - $this->add_field('sites', 'allow_own_site_as_template', array( - 'title' => __('Allow Users to use their own Sites as Templates', 'wp-ultimo'), - 'desc' => __('Enabling this option will add the user own sites to the template screen, allowing them to create a new site based on the content and customizations they made previously.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - 'require' => array( - 'allow_template_switching' => true, - ), - )); + $this->add_field( + 'sites', + 'allow_own_site_as_template', + array( + 'title' => __('Allow Users to use their own Sites as Templates', 'wp-ultimo'), + 'desc' => __('Enabling this option will add the user own sites to the template screen, allowing them to create a new site based on the content and customizations they made previously.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + 'require' => array( + 'allow_template_switching' => true, + ), + ) + ); - $this->add_field('sites', 'copy_media', array( - 'title' => __('Copy Media on Template Duplication?', 'wp-ultimo'), - 'desc' => __('Checking this option will copy the media uploaded on the template site to the newly created site. This can be overridden on each of the plans.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + $this->add_field( + 'sites', + 'copy_media', + array( + 'title' => __('Copy Media on Template Duplication?', 'wp-ultimo'), + 'desc' => __('Checking this option will copy the media uploaded on the template site to the newly created site. This can be overridden on each of the plans.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); - $this->add_field('sites', 'stop_template_indexing', array( - 'title' => __('Prevent Search Engines from indexing Site Templates', 'wp-ultimo'), - 'desc' => __('Checking this option will discourage search engines from indexing all the Site Templates on your network.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - )); + $this->add_field( + 'sites', + 'stop_template_indexing', + array( + 'title' => __('Prevent Search Engines from indexing Site Templates', 'wp-ultimo'), + 'desc' => __('Checking this option will discourage search engines from indexing all the Site Templates on your network.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + ) + ); do_action('wu_settings_site_templates'); @@ -1111,84 +1287,119 @@ class Settings { * This section holds the Payment Gateways settings of the WP Multisite WaaS Plugin. */ - $this->add_section('payment-gateways', array( - 'title' => __('Payments', 'wp-ultimo'), - 'desc' => __('Payments', 'wp-ultimo'), - 'icon' => 'dashicons-wu-credit-card', - )); + $this->add_section( + 'payment-gateways', + array( + 'title' => __('Payments', 'wp-ultimo'), + 'desc' => __('Payments', 'wp-ultimo'), + 'icon' => 'dashicons-wu-credit-card', + ) + ); - $this->add_field('payment-gateways', 'main_header', array( - 'title' => __('Payment Settings', 'wp-ultimo'), - 'desc' => __('The following options affect how prices are displayed on the frontend, the backend and in reports.', 'wp-ultimo'), - 'type' => 'header', - 'show_as_submenu' => true, - )); + $this->add_field( + 'payment-gateways', + 'main_header', + array( + 'title' => __('Payment Settings', 'wp-ultimo'), + 'desc' => __('The following options affect how prices are displayed on the frontend, the backend and in reports.', 'wp-ultimo'), + 'type' => 'header', + 'show_as_submenu' => true, + ) + ); - $this->add_field('payment-gateways', 'force_auto_renew', array( - 'title' => __('Force Auto-Renew', 'wp-ultimo'), - 'desc' => __('Enable this option if you want to make sure memberships are created with auto-renew activated whenever the selected gateway supports it. Disabling this option will show an auto-renew option during checkout.', 'wp-ultimo'), - 'tooltip' => '', - 'type' => 'toggle', - 'default' => 1, - )); + $this->add_field( + 'payment-gateways', + 'force_auto_renew', + array( + 'title' => __('Force Auto-Renew', 'wp-ultimo'), + 'desc' => __('Enable this option if you want to make sure memberships are created with auto-renew activated whenever the selected gateway supports it. Disabling this option will show an auto-renew option during checkout.', 'wp-ultimo'), + 'tooltip' => '', + 'type' => 'toggle', + 'default' => 1, + ) + ); - $this->add_field('payment-gateways', 'allow_trial_without_payment_method', array( - 'title' => __('Allow Trials without Payment Method', 'wp-ultimo'), - 'desc' => __('By default, WP Multisite WaaS asks customers to add a payment method on sign-up even if a trial period is present. Enable this option to only ask for a payment method when the trial period is over.', 'wp-ultimo'), - 'tooltip' => '', - 'type' => 'toggle', - 'default' => 0, - )); + $this->add_field( + 'payment-gateways', + 'allow_trial_without_payment_method', + array( + 'title' => __('Allow Trials without Payment Method', 'wp-ultimo'), + 'desc' => __('By default, WP Multisite WaaS asks customers to add a payment method on sign-up even if a trial period is present. Enable this option to only ask for a payment method when the trial period is over.', 'wp-ultimo'), + 'tooltip' => '', + 'type' => 'toggle', + 'default' => 0, + ) + ); - $this->add_field('payment-gateways', 'attach_invoice_pdf', array( - 'title' => __('Send Invoice on Payment Confirmation', 'wp-ultimo'), - 'desc' => __('Enabling this option will attach a PDF invoice (marked paid) with the payment confirmation email. This option does not apply to the Manual Gateway, which sends invoices regardless of this option.', 'wp-ultimo'), - 'tooltip' => __('The invoice files will be saved on the wp-content/uploads/wu-invoices folder.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + $this->add_field( + 'payment-gateways', + 'attach_invoice_pdf', + array( + 'title' => __('Send Invoice on Payment Confirmation', 'wp-ultimo'), + 'desc' => __('Enabling this option will attach a PDF invoice (marked paid) with the payment confirmation email. This option does not apply to the Manual Gateway, which sends invoices regardless of this option.', 'wp-ultimo'), + 'tooltip' => __('The invoice files will be saved on the wp-content/uploads/wu-invoices folder.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); - $this->add_field('payment-gateways', 'invoice_numbering_scheme', array( - 'title' => __('Invoice Numbering Scheme', 'wp-ultimo'), - 'desc' => __('What should WP Multisite WaaS use as the invoice number?', 'wp-ultimo'), - 'type' => 'select', - 'default' => 'reference_code', - 'tooltip' => '', - 'options' => array( - 'reference_code' => __('Payment Reference Code', 'wp-ultimo'), - 'sequential_number' => __('Sequential Number', 'wp-ultimo'), - ), - )); + $this->add_field( + 'payment-gateways', + 'invoice_numbering_scheme', + array( + 'title' => __('Invoice Numbering Scheme', 'wp-ultimo'), + 'desc' => __('What should WP Multisite WaaS use as the invoice number?', 'wp-ultimo'), + 'type' => 'select', + 'default' => 'reference_code', + 'tooltip' => '', + 'options' => array( + 'reference_code' => __('Payment Reference Code', 'wp-ultimo'), + 'sequential_number' => __('Sequential Number', 'wp-ultimo'), + ), + ) + ); - $this->add_field('payment-gateways', 'next_invoice_number', array( - 'title' => __('Next Invoice Number', 'wp-ultimo'), - 'desc' => __('This number will be used as the invoice number for the next invoice generated on the system. It is incremented by one every time a new invoice is created. You can change it and save it to reset the invoice sequential number to a specific value.', 'wp-ultimo'), - 'type' => 'number', - 'default' => '1', - 'min' => 0, - 'require' => array( - 'invoice_numbering_scheme' => 'sequential_number', - ), - )); + $this->add_field( + 'payment-gateways', + 'next_invoice_number', + array( + 'title' => __('Next Invoice Number', 'wp-ultimo'), + 'desc' => __('This number will be used as the invoice number for the next invoice generated on the system. It is incremented by one every time a new invoice is created. You can change it and save it to reset the invoice sequential number to a specific value.', 'wp-ultimo'), + 'type' => 'number', + 'default' => '1', + 'min' => 0, + 'require' => array( + 'invoice_numbering_scheme' => 'sequential_number', + ), + ) + ); - $this->add_field('payment-gateways', 'invoice_prefix', array( - 'title' => __('Invoice Number Prefix', 'wp-ultimo'), - 'placeholder' => __('INV00', 'wp-ultimo'), + $this->add_field( + 'payment-gateways', + 'invoice_prefix', + array( + 'title' => __('Invoice Number Prefix', 'wp-ultimo'), + 'placeholder' => __('INV00', 'wp-ultimo'), 'desc' => sprintf(__('Use %%YEAR%%, %%MONTH%%, and %%DAY%% to create a dynamic placeholder. E.g. %%YEAR%%-%%MONTH%%-INV will become %s.', 'wp-ultimo'), date('Y') . '-' . date('m') . '-INV'), // phpcs:ignore - 'default' => '', - 'type' => 'text', - 'raw' => true, // Necessary to prevent the removal of the %% tags. - 'require' => array( + 'default' => '', + 'type' => 'text', + 'raw' => true, // Necessary to prevent the removal of the %% tags. + 'require' => array( 'invoice_numbering_scheme' => 'sequential_number', ), - )); + ) + ); - $this->add_field('payment-gateways', 'gateways_header', array( - 'title' => __('Payment Gateways', 'wp-ultimo'), - 'desc' => __('Activate and configure the installed payment gateways in this section.', 'wp-ultimo'), - 'type' => 'header', - 'show_as_submenu' => true, - )); + $this->add_field( + 'payment-gateways', + 'gateways_header', + array( + 'title' => __('Payment Gateways', 'wp-ultimo'), + 'desc' => __('Activate and configure the installed payment gateways in this section.', 'wp-ultimo'), + 'type' => 'header', + 'show_as_submenu' => true, + ) + ); do_action('wu_settings_payment_gateways'); @@ -1196,24 +1407,30 @@ class Settings { * Emails * This section holds the Email settings of the WP Multisite WaaS Plugin. */ - $this->add_section('emails', array( - 'title' => __('Emails', 'wp-ultimo'), - 'desc' => __('Emails', 'wp-ultimo'), - 'icon' => 'dashicons-wu-email', - )); + $this->add_section( + 'emails', + array( + 'title' => __('Emails', 'wp-ultimo'), + 'desc' => __('Emails', 'wp-ultimo'), + 'icon' => 'dashicons-wu-email', + ) + ); do_action('wu_settings_emails'); - /* + /* * Domain Mapping * This section holds the Domain Mapping settings of the WP Multisite WaaS Plugin. */ - $this->add_section('domain-mapping', array( - 'title' => __('Domain Mapping', 'wp-ultimo'), - 'desc' => __('Domain Mapping', 'wp-ultimo'), - 'icon' => 'dashicons-wu-link', - )); + $this->add_section( + 'domain-mapping', + array( + 'title' => __('Domain Mapping', 'wp-ultimo'), + 'desc' => __('Domain Mapping', 'wp-ultimo'), + 'icon' => 'dashicons-wu-link', + ) + ); do_action('wu_settings_domain_mapping'); @@ -1222,11 +1439,14 @@ class Settings { * This section includes settings related to the single sign-on functionality */ - $this->add_section('sso', array( - 'title' => __('Single Sign-On', 'wp-ultimo'), - 'desc' => __('Single Sign-On', 'wp-ultimo'), - 'icon' => 'dashicons-wu-add-user', - )); + $this->add_section( + 'sso', + array( + 'title' => __('Single Sign-On', 'wp-ultimo'), + 'desc' => __('Single Sign-On', 'wp-ultimo'), + 'icon' => 'dashicons-wu-add-user', + ) + ); do_action('wu_settings_sso'); @@ -1235,18 +1455,25 @@ class Settings { * This section holds the Integrations settings of the WP Multisite WaaS Plugin. */ - $this->add_section('integrations', array( - 'title' => __('Integrations', 'wp-ultimo'), - 'desc' => __('Integrations', 'wp-ultimo'), - 'icon' => 'dashicons-wu-power-plug', - )); + $this->add_section( + 'integrations', + array( + 'title' => __('Integrations', 'wp-ultimo'), + 'desc' => __('Integrations', 'wp-ultimo'), + 'icon' => 'dashicons-wu-power-plug', + ) + ); - $this->add_field('integrations', 'hosting_providers_header', array( - 'title' => __('Hosting or Panel Providers', 'wp-ultimo'), - 'desc' => __('Configure and manage the integration with your Hosting or Panel Provider.', 'wp-ultimo'), - 'type' => 'header', - 'show_as_submenu' => true, - )); + $this->add_field( + 'integrations', + 'hosting_providers_header', + array( + 'title' => __('Hosting or Panel Providers', 'wp-ultimo'), + 'desc' => __('Configure and manage the integration with your Hosting or Panel Provider.', 'wp-ultimo'), + 'type' => 'header', + 'show_as_submenu' => true, + ) + ); do_action('wu_settings_integrations'); @@ -1255,76 +1482,108 @@ class Settings { * This section holds the Other Options settings of the WP Multisite WaaS Plugin. */ - $this->add_section('other', array( - 'title' => __('Other Options', 'wp-ultimo'), - 'desc' => __('Other Options', 'wp-ultimo'), - 'icon' => 'dashicons-wu-switch', - 'order' => 1000, - )); + $this->add_section( + 'other', + array( + 'title' => __('Other Options', 'wp-ultimo'), + 'desc' => __('Other Options', 'wp-ultimo'), + 'icon' => 'dashicons-wu-switch', + 'order' => 1000, + ) + ); - $this->add_field('other', 'Other_header', array( - 'title' => __('Miscellaneous', 'wp-ultimo'), - 'desc' => __('Other options that do not fit anywhere else.', 'wp-ultimo'), - 'type' => 'header', - )); + $this->add_field( + 'other', + 'Other_header', + array( + 'title' => __('Miscellaneous', 'wp-ultimo'), + 'desc' => __('Other options that do not fit anywhere else.', 'wp-ultimo'), + 'type' => 'header', + ) + ); $preview_image = wu_preview_image(wu_get_asset('settings/settings-hide-ui-tours.png')); - $this->add_field('other', 'hide_tours', array( - 'title' => __('Hide UI Tours', 'wp-ultimo') . $preview_image, - 'desc' => __('The UI tours showed by WP Multisite WaaS should permanently hide themselves after being seen but if they persist for whatever reason, toggle this option to force them into their viewed state - which will prevent them from showing up again.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - )); + $this->add_field( + 'other', + 'hide_tours', + array( + 'title' => __('Hide UI Tours', 'wp-ultimo') . $preview_image, + 'desc' => __('The UI tours showed by WP Multisite WaaS should permanently hide themselves after being seen but if they persist for whatever reason, toggle this option to force them into their viewed state - which will prevent them from showing up again.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + ) + ); $preview_image_2 = wu_preview_image(wu_get_asset('settings/settings-disable-hover-to-zoom.png')); - $this->add_field('other', 'disable_image_zoom', array( - 'title' => __('Disable "Hover to Zoom"', 'wp-ultimo') . $preview_image_2, - 'desc' => __('By default, WP Multisite WaaS adds a "hover to zoom" feature, allowing network admins to see larger version of site screenshots and other images across the UI in full-size when hovering over them. You can disable that feature here. Preview tags like the above are not affected.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - )); + $this->add_field( + 'other', + 'disable_image_zoom', + array( + 'title' => __('Disable "Hover to Zoom"', 'wp-ultimo') . $preview_image_2, + 'desc' => __('By default, WP Multisite WaaS adds a "hover to zoom" feature, allowing network admins to see larger version of site screenshots and other images across the UI in full-size when hovering over them. You can disable that feature here. Preview tags like the above are not affected.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + ) + ); - $this->add_field('other', 'error_reporting_header', array( - 'title' => __('Logging', 'wp-ultimo'), - 'desc' => __('Log WP Multisite WaaS data. This is useful for debugging purposes.', 'wp-ultimo'), - 'type' => 'header', - )); + $this->add_field( + 'other', + 'error_reporting_header', + array( + 'title' => __('Logging', 'wp-ultimo'), + 'desc' => __('Log WP Multisite WaaS data. This is useful for debugging purposes.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - $this->add_field('other', 'error_logging_level', array( - 'title' => __('Logging Level', 'wp-ultimo'), - 'desc' => __('Select the level of logging you want to use.', 'wp-ultimo'), - 'type' => 'select', - 'default' => 'default', - 'options' => array( - 'default' => __('PHP Default', 'wp-ultimo'), - 'disabled' => __('Disabled', 'wp-ultimo'), - 'errors' => __('Errors Only', 'wp-ultimo'), - 'all' => __('Everything', 'wp-ultimo'), - ), - )); + $this->add_field( + 'other', + 'error_logging_level', + array( + 'title' => __('Logging Level', 'wp-ultimo'), + 'desc' => __('Select the level of logging you want to use.', 'wp-ultimo'), + 'type' => 'select', + 'default' => 'default', + 'options' => array( + 'default' => __('PHP Default', 'wp-ultimo'), + 'disabled' => __('Disabled', 'wp-ultimo'), + 'errors' => __('Errors Only', 'wp-ultimo'), + 'all' => __('Everything', 'wp-ultimo'), + ), + ) + ); - $this->add_field('other', 'enable_error_reporting', array( - 'title' => __('Send Error Data to WP Multisite WaaS Developers', 'wp-ultimo'), - 'desc' => __('With this option enabled, every time your installation runs into an error related to WP Multisite WaaS, that error data will be sent to us. No sensitive data gets collected, only environmental stuff (e.g. if this is this is a subdomain network, etc).', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + $this->add_field( + 'other', + 'enable_error_reporting', + array( + 'title' => __('Send Error Data to WP Multisite WaaS Developers', 'wp-ultimo'), + 'desc' => __('With this option enabled, every time your installation runs into an error related to WP Multisite WaaS, that error data will be sent to us. No sensitive data gets collected, only environmental stuff (e.g. if this is this is a subdomain network, etc).', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); - $this->add_field('other', 'advanced_header', array( - 'title' => __('Advanced Options', 'wp-ultimo'), - 'desc' => __('Change the plugin and wordpress behavior.', 'wp-ultimo'), - 'type' => 'header', - )); + $this->add_field( + 'other', + 'advanced_header', + array( + 'title' => __('Advanced Options', 'wp-ultimo'), + 'desc' => __('Change the plugin and wordpress behavior.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - $plans = get_posts(array( - 'post_type' => 'wpultimo_plan', - 'numberposts' => 1, - )); - - if (!empty($plans)) { + $plans = get_posts( + array( + 'post_type' => 'wpultimo_plan', + 'numberposts' => 1, + ) + ); + if ( ! empty($plans)) { $url = wu_network_admin_url('wp-ultimo-migration-alert'); $title = __('Run Migration Again', 'wp-ultimo') . sprintf( @@ -1337,13 +1596,16 @@ class Settings { $html = sprintf('%s', $url, __('Migrate', 'wp-ultimo')); - $this->add_field('other', 'run_migration', array( - 'title' => $title, - 'type' => 'note', - 'desc' => $html, - )); - - } // end if; + $this->add_field( + 'other', + 'run_migration', + array( + 'title' => $title, + 'type' => 'note', + 'desc' => $html, + ) + ); + } if (function_exists('wu_get_security_mode_key')) { /** @@ -1351,24 +1613,30 @@ class Settings { */ $security_mode_key = '?wu_secure=' . wu_get_security_mode_key(); - $this->add_field('other', 'security_mode', array( - 'title' => __('Security Mode', 'wp-ultimo'), - // Translators: Placeholder adds the security mode key and current site url with query string - 'desc' => sprintf(__('Only WP Multisite WaaS and other must-use plugins will run on your WordPress install while this option is enabled.
Important: Copy the following URL to disable security mode if something goes wrong and this page becomes unavailable:%2$s
', 'wp-ultimo'), $security_mode_key, get_site_url() . $security_mode_key), + $this->add_field( + 'other', + 'security_mode', + array( + 'title' => __('Security Mode', 'wp-ultimo'), + // Translators: Placeholder adds the security mode key and current site url with query string + 'desc' => sprintf(__('Only WP Multisite WaaS and other must-use plugins will run on your WordPress install while this option is enabled.
Important: Copy the following URL to disable security mode if something goes wrong and this page becomes unavailable:%2$s
', 'wp-ultimo'), $security_mode_key, get_site_url() . $security_mode_key), + 'type' => 'toggle', + 'default' => 0, + ) + ); + } + + $this->add_field( + 'other', + 'uninstall_wipe_tables', + array( + 'title' => __('Remove Data on Uninstall', 'wp-ultimo'), + 'desc' => __('Remove all saved data for WP Multisite WaaS when the plugin is uninstalled.', 'wp-ultimo'), 'type' => 'toggle', 'default' => 0, - )); - - } // end if; - - $this->add_field('other', 'uninstall_wipe_tables', array( - 'title' => __('Remove Data on Uninstall', 'wp-ultimo'), - 'desc' => __('Remove all saved data for WP Multisite WaaS when the plugin is uninstalled.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - )); - - } // end default_sections; + ) + ); + } /** * Tries to determine the location of the company based on the admin IP. @@ -1381,7 +1649,5 @@ class Settings { $geolocation = \WP_Ultimo\Geolocation::geolocate_ip('', true); return $geolocation['country']; - - } // end get_default_company_country; - -} // end class Settings; + } +} diff --git a/inc/class-sunrise.php b/inc/class-sunrise.php index 6e51048..d85087b 100644 --- a/inc/class-sunrise.php +++ b/inc/class-sunrise.php @@ -60,7 +60,7 @@ class Sunrise { * Domain mapping needs to be loaded * before anything else. */ - \WP_Ultimo\Sunrise::load_domain_mapping(); + self::load_domain_mapping(); /** * Enqueue the main hooks that deal with Sunrise @@ -73,8 +73,7 @@ class Sunrise { add_action('init', array('\WP_Ultimo\Sunrise', 'maybe_tap_on_init')); add_filter('wu_system_info_data', array('\WP_Ultimo\Sunrise', 'system_info')); - - } // end init; + } /** * Checks if all the requirements for sunrise loading are in place. @@ -95,8 +94,7 @@ class Sunrise { $should_load_sunrise = wu_should_load_sunrise(); return $setup_finished && $should_load_sunrise; - - } // end should_startup; + } /** * Load dependencies, if we need them somewhere. @@ -139,9 +137,7 @@ class Sunrise { require_once __DIR__ . '/class-settings.php'; require_once __DIR__ . '/limits/class-plugin-limits.php'; require_once __DIR__ . '/limits/class-theme-limits.php'; - - - } // end load_dependencies; + } /** * Loads domain mapping before anything else. @@ -151,11 +147,10 @@ class Sunrise { */ public static function load_domain_mapping() { - $should_startup = \WP_Ultimo\Sunrise::should_startup(); + $should_startup = self::should_startup(); if ($should_startup) { - - \WP_Ultimo\Sunrise::load_dependencies(); + self::load_dependencies(); /* * Primary Domain capabilities @@ -163,10 +158,8 @@ class Sunrise { \WP_Ultimo\Domain_Mapping\Primary_Domain::get_instance(); \WP_Ultimo\Domain_Mapping::get_instance(); - - } // end if; - - } // end load_domain_mapping; + } + } /** * Loads the Sunrise components, if needed. @@ -176,7 +169,7 @@ class Sunrise { */ public static function load() { - $should_startup = \WP_Ultimo\Sunrise::should_startup(); + $should_startup = self::should_startup(); if ($should_startup) { /** @@ -202,7 +195,7 @@ class Sunrise { /** * Define the WP Multisite WaaS main debug constant. */ - !defined('WP_ULTIMO_DEBUG') && define('WP_ULTIMO_DEBUG', false); + ! defined('WP_ULTIMO_DEBUG') && define('WP_ULTIMO_DEBUG', false); /** * Check if we are using security mode. @@ -210,11 +203,8 @@ class Sunrise { $security_mode = (bool) (int) wu_get_setting_early('security_mode'); if ($security_mode) { - if (wu_get_isset($_GET, 'wu_secure') === wu_get_security_mode_key()) { - wu_save_setting_early('security_mode', false); - } else { /** * Disable all plugins except WP Multisite WaaS @@ -222,14 +212,10 @@ class Sunrise { add_filter('option_active_plugins', fn() => array()); add_filter('site_option_active_sitewide_plugins', fn($plugins) => array(basename(dirname(__DIR__)) . '/wp-ultimo.php' => 1)); - - } // end if; - - } // end if; - - } // end if; - - } // end load; + } + } + } + } /** * Adds an additional hook that runs after ms_loaded. @@ -246,8 +232,7 @@ class Sunrise { public static function loaded() { do_action('wu_sunrise_loaded'); - - } // end loaded; + } /** * Checks if we need to upgrade the sunrise version on wp-content @@ -262,12 +247,9 @@ class Sunrise { $old_version = defined('WP_ULTIMO_SUNRISE_VERSION') ? WP_ULTIMO_SUNRISE_VERSION : '0.0.1'; if (version_compare($old_version, self::$version, '<')) { - - \WP_Ultimo\Sunrise::try_upgrade(); - - } // end if; - - } // end manage_sunrise_updates; + self::try_upgrade(); + } + } /** * Upgrades the sunrise file, if necessary. @@ -290,49 +272,38 @@ class Sunrise { $location = WP_CONTENT_DIR . '/sunrise.php'; foreach ($possible_sunrises as $new_file) { - - if (!file_exists($new_file)) { - + if ( ! file_exists($new_file)) { continue; - - } // end if; + } $sunrise_found = true; $copy_results = @copy($new_file, $location); // phpcs:ignore - if (!$copy_results) { - + if ( ! $copy_results) { $error = error_get_last(); continue; - - } // end if; + } wu_log_add('sunrise', __('Sunrise upgrade attempt succeeded.', 'wp-ultimo')); return true; - - } // end foreach; + } if ($sunrise_found === false) { - $error = array( 'message' => __('File not found.', 'wp-ultimo'), ); + } - } // end if; - - if (!empty($error)) { - + if ( ! empty($error)) { wu_log_add('sunrise', $error['message'], LogLevel::ERROR); /* translators: the placeholder is an error message */ return new \WP_Error('error', sprintf(__('Sunrise copy failed: %s', 'wp-ultimo'), $error['message'])); - - } // end if; - - } // end try_upgrade; + } + } /** * Reads the sunrise meta file and loads it to the static cache. @@ -345,27 +316,22 @@ class Sunrise { */ protected static function read_sunrise_meta() { - if (is_array(\WP_Ultimo\Sunrise::$sunrise_meta)) { - - return \WP_Ultimo\Sunrise::$sunrise_meta; - - } // end if; + if (is_array(self::$sunrise_meta)) { + return self::$sunrise_meta; + } $sunrise_meta = get_network_option(null, 'wu_sunrise_meta', null); $existing = array(); if ($sunrise_meta) { - $existing = $sunrise_meta; self::$sunrise_meta = $existing; - - } // end if; + } return $existing; - - } // end read_sunrise_meta; + } /** * Method for imputing Sunrise data at wp-ultimo-system-info table. @@ -376,9 +342,10 @@ class Sunrise { */ public static function system_info($sys_info) { - $data = Sunrise::read_sunrise_meta(); + $data = self::read_sunrise_meta(); - $sys_info = array_merge($sys_info, + $sys_info = array_merge( + $sys_info, array( 'Sunrise Data' => array( 'sunrise-status' => array( @@ -389,7 +356,7 @@ class Sunrise { 'sunrise-data' => array( 'tooltip' => '', 'title' => 'Version', - 'value' => Sunrise::$version + 'value' => self::$version, ), 'sunrise-created' => array( 'tooltip' => '', @@ -410,14 +377,13 @@ class Sunrise { 'tooltip' => '', 'title' => 'Last Modified', 'value' => gmdate('Y-m-d @ H:i:s', $data['last_modified']), - ) + ), ), ) ); return $sys_info; - - } // end system_info; + } /** * Checks if the sunrise extra modules need to be loaded. @@ -427,11 +393,10 @@ class Sunrise { */ public static function should_load_sunrise() { - $meta = \WP_Ultimo\Sunrise::read_sunrise_meta(); + $meta = self::read_sunrise_meta(); return wu_get_isset($meta, 'active', false); - - } // end should_load_sunrise; + } /** * Makes sure the meta file accurately reflects the state of the main plugin. @@ -443,9 +408,8 @@ class Sunrise { $state = function_exists('WP_Ultimo') && WP_Ultimo()->is_loaded(); - \WP_Ultimo\Sunrise::maybe_tap($state ? 'activating' : 'deactivating'); - - } // end maybe_tap_on_init; + self::maybe_tap($state ? 'activating' : 'deactivating'); + } /** * Updates the sunrise meta file, if an update is due. @@ -457,23 +421,18 @@ class Sunrise { */ public static function maybe_tap($mode = 'activating') { - $meta = \WP_Ultimo\Sunrise::read_sunrise_meta(); + $meta = self::read_sunrise_meta(); $is_active = isset($meta['active']) && $meta['active']; if ($is_active && $mode === 'activating') { - return false; - - } elseif (!$is_active && $mode === 'deactivating') { - + } elseif ( ! $is_active && $mode === 'deactivating') { return false; + } - } // end if; - - return (bool) \WP_Ultimo\Sunrise::tap($mode, $meta); - - } // end maybe_tap; + return (bool) self::tap($mode, $meta); + } /** * Updates the sunrise meta file. @@ -488,36 +447,31 @@ class Sunrise { $now = gmdate('U'); - $to_save = wp_parse_args($existing, array( - 'active' => false, - 'created' => $now, - 'last_activated' => 'unknown', - 'last_deactivated' => 'unknown', - )); + $to_save = wp_parse_args( + $existing, + array( + 'active' => false, + 'created' => $now, + 'last_activated' => 'unknown', + 'last_deactivated' => 'unknown', + ) + ); if ($mode === 'activating') { - $to_save['active'] = true; $to_save['last_activated'] = $now; - } elseif ($mode === 'deactivating') { - $to_save['active'] = false; $to_save['last_deactivated'] = $now; - } else { - return false; - - } // end if; + } $to_save['last_modified'] = $now; return update_network_option(null, 'wu_sunrise_meta', $to_save); - - } // end tap; + } // phpcs:ignore - private function __construct() {} // end __construct; - -} // end class Sunrise; + private function __construct() {} +} diff --git a/inc/class-user-switching.php b/inc/class-user-switching.php index d646649..e0fe985 100644 --- a/inc/class-user-switching.php +++ b/inc/class-user-switching.php @@ -29,8 +29,7 @@ class User_Switching { public function __construct() { add_action('plugins_loaded', array($this, 'register_forms')); - - } // end __construct; + } /** * Check if Plugin User Switching is activated * @@ -39,8 +38,7 @@ class User_Switching { public function check_user_switching_is_activated(): bool { return class_exists('user_switching'); - - } // end check_user_switching_is_activated; + } /** * Register forms @@ -51,11 +49,13 @@ class User_Switching { */ public function register_forms() { - wu_register_form('install_user_switching', array( - 'render' => array($this, 'render_install_user_switching'), - )); - - } // end register_forms; + wu_register_form( + 'install_user_switching', + array( + 'render' => array($this, 'render_install_user_switching'), + ) + ); + } /** * Create Install Form of User Switching @@ -79,26 +79,31 @@ class User_Switching { 'classes' => 'button button-primary wu-w-full', 'wrapper_classes' => 'wu-items-end wu-text-center wu-bg-gray-100', 'html_attr' => array( - 'href' => add_query_arg(array( - 's' => 'user-switching', - 'tab' => 'search', - 'type' => 'tag' - ), network_admin_url('plugin-install.php') + 'href' => add_query_arg( + array( + 's' => 'user-switching', + 'tab' => 'search', + 'type' => 'tag', + ), + network_admin_url('plugin-install.php') ), ), ), ); - $form = new \WP_Ultimo\UI\Form('install_user_switching', $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(), - )); + $form = new \WP_Ultimo\UI\Form( + 'install_user_switching', + $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(), + ) + ); $form->render(); - - } // end render_install_user_switching; + } /** * This function return should return the correct url @@ -113,18 +118,12 @@ class User_Switching { $user = new \WP_User($user_id); - if (!$this->check_user_switching_is_activated()) { - + if ( ! $this->check_user_switching_is_activated()) { return wu_get_form_url('install_user_switching'); - } else { - $link = \user_switching::switch_to_url($user); return $link; - - } // end if; - - } // end render; - -} // end class User_Switching; + } + } +} diff --git a/inc/class-views.php b/inc/class-views.php index 3db02d8..3738a8d 100644 --- a/inc/class-views.php +++ b/inc/class-views.php @@ -29,8 +29,7 @@ class Views { public function init() { add_filter('wu_view_override', array($this, 'view_override'), 10, 3); - - } // end init; + } /** * Custom locate template function that allows us to retrieve user overridden templates. @@ -57,44 +56,31 @@ class Views { $located = ''; foreach ((array) $template_names as $template_name) { - - if (!$template_name) { - + if ( ! $template_name) { continue; + } - } // end if; - - if (file_exists( $stylesheet_path . '/' . $template_name)) { - + if (file_exists($stylesheet_path . '/' . $template_name)) { $located = $stylesheet_path . '/' . $template_name; break; - } elseif (file_exists(get_template_directory() . '/' . $template_name)) { - $located = get_template_directory() . '/' . $template_name; break; - } elseif (file_exists(ABSPATH . WPINC . '/theme-compat/' . $template_name)) { - $located = ABSPATH . WPINC . '/theme-compat/' . $template_name; break; - - } // end if; - - } // end foreach; + } + } if ($load && '' !== $located) { - load_template($located, $require_once); - - } // end if; + } return $located; - - } // end custom_locate_template; + } /** * Check if an alternative view exists and override @@ -108,7 +94,5 @@ class Views { $found = $this->custom_locate_template("wp-ultimo/$view.php"); return $found ? $found : $original_path; - - } // end view_override; - -} // end class Views; + } +} diff --git a/inc/class-whitelabel.php b/inc/class-whitelabel.php index 58e99ae..8433298 100644 --- a/inc/class-whitelabel.php +++ b/inc/class-whitelabel.php @@ -68,8 +68,7 @@ class Whitelabel { add_action('init', array($this, 'hooks')); add_filter('gettext', array($this, 'replace_text'), 10, 3); - - } // end init; + } /** * Add the necessary hooks when the feature is enabled. @@ -80,7 +79,6 @@ class Whitelabel { public function hooks() { if (wu_get_setting('hide_wordpress_logo', true)) { - add_action('wp_before_admin_bar_render', array($this, 'wp_logo_admin_bar_remove'), 0); add_action('wp_user_dashboard_setup', array($this, 'remove_dashboard_widgets'), 11); @@ -90,16 +88,12 @@ class Whitelabel { add_action('admin_enqueue_scripts', array($this, 'enqueue_styles')); add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); - - } // end if; + } if (wu_get_setting('hide_sites_menu', true)) { - add_action('network_admin_menu', array($this, 'remove_sites_admin_menu')); - - } // end if; - - } // end hooks; + } + } /** * Loads the custom css file. @@ -112,8 +106,7 @@ class Whitelabel { WP_Ultimo()->scripts->register_style('wu-whitelabel', wu_get_asset('whitelabel.css', 'css')); wp_enqueue_style('wu-whitelabel'); - - } // end enqueue_styles; + } /** * Replaces the terms on the translated strings. @@ -128,19 +121,18 @@ class Whitelabel { public function replace_text($translation, $text, $domain) { if ($this->allowed_domains === null) { + $this->allowed_domains = apply_filters( + 'wu_replace_text_allowed_domains', + array( + 'default', + 'wp-ultimo', + ) + ); + } - $this->allowed_domains = apply_filters('wu_replace_text_allowed_domains', array( - 'default', - 'wp-ultimo', - )); - - } // end if; - - if (!in_array($domain, $this->allowed_domains, true)) { - + if ( ! in_array($domain, $this->allowed_domains, true)) { return $translation; - - } // end if; + } /** * Prevent replacement when dealing with URLs. @@ -153,64 +145,49 @@ class Whitelabel { * @since 2.1.0 */ if (strncmp($translation, 'http', strlen('http')) === 0) { - return $translation; - - } // end if; + } if ($this->init === false) { - $search_and_replace = array(); $site_plural = wu_get_setting('rename_site_plural'); if ($site_plural) { - $search_and_replace['sites'] = strtolower((string) $site_plural); $search_and_replace['Sites'] = ucfirst((string) $site_plural); - - } // end if; + } $site_singular = wu_get_setting('rename_site_singular'); if ($site_singular) { - $search_and_replace['site'] = strtolower((string) $site_singular); $search_and_replace['Site'] = ucfirst((string) $site_singular); - - } // end if; + } $wordpress = wu_get_setting('rename_wordpress'); if ($wordpress) { - $search_and_replace['wordpress'] = strtolower((string) $wordpress); $search_and_replace['WordPress'] = ucfirst((string) $wordpress); $search_and_replace['Wordpress'] = ucfirst((string) $wordpress); $search_and_replace['wordPress'] = ucfirst((string) $wordpress); - - } // end if; + } if ($search_and_replace) { - $this->search = array_keys($search_and_replace); $this->replace = array_values($search_and_replace); - - } // end if; + } $this->init = true; + } - } // end if; - - if (!empty($this->search)) { - + if ( ! empty($this->search)) { return str_replace($this->search, $this->replace, $translation); - - } // end if; + } return $translation; - - } // end replace_text; + } /** * Adds the whitelabel options. @@ -221,61 +198,87 @@ class Whitelabel { */ public function add_settings() { - wu_register_settings_section('whitelabel', array( - 'title' => __('Whitelabel', 'wp-ultimo'), - 'desc' => __('Basic Whitelabel', 'wp-ultimo'), - 'icon' => 'dashicons-wu-eye', - )); + wu_register_settings_section( + 'whitelabel', + array( + 'title' => __('Whitelabel', 'wp-ultimo'), + 'desc' => __('Basic Whitelabel', 'wp-ultimo'), + 'icon' => 'dashicons-wu-eye', + ) + ); - wu_register_settings_field('whitelabel', 'whitelabel_header', array( - 'title' => __('Whitelabel', 'wp-ultimo'), - 'desc' => __('Hide a couple specific WordPress elements and rename others.', 'wp-ultimo'), - 'type' => 'header', - )); + wu_register_settings_field( + 'whitelabel', + 'whitelabel_header', + array( + 'title' => __('Whitelabel', 'wp-ultimo'), + 'desc' => __('Hide a couple specific WordPress elements and rename others.', 'wp-ultimo'), + 'type' => 'header', + ) + ); $preview_image = wu_preview_image(wu_get_asset('settings/settings-hide-wp-logo-preview.png')); - wu_register_settings_field('whitelabel', 'hide_wordpress_logo', array( - 'title' => __('Hide WordPress Logo', 'wp-ultimo') . $preview_image, - 'desc' => __('Hide the WordPress logo from the top-bar and replace the same logo on the My Sites top-bar item with a more generic icon.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + wu_register_settings_field( + 'whitelabel', + 'hide_wordpress_logo', + array( + 'title' => __('Hide WordPress Logo', 'wp-ultimo') . $preview_image, + 'desc' => __('Hide the WordPress logo from the top-bar and replace the same logo on the My Sites top-bar item with a more generic icon.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); - wu_register_settings_field('whitelabel', 'hide_sites_menu', array( - 'title' => __('Hide Sites Admin Menu', 'wp-ultimo'), - 'desc' => __('We recommend that you manage all of your sites using the WP Multisite WaaS → Sites page. To avoid confusion, you can hide the default "Sites" item from the WordPress admin menu by toggling this option.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - )); + wu_register_settings_field( + 'whitelabel', + 'hide_sites_menu', + array( + 'title' => __('Hide Sites Admin Menu', 'wp-ultimo'), + 'desc' => __('We recommend that you manage all of your sites using the WP Multisite WaaS → Sites page. To avoid confusion, you can hide the default "Sites" item from the WordPress admin menu by toggling this option.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + ) + ); - wu_register_settings_field('whitelabel', 'rename_wordpress', array( - 'title' => __('Replace the word "WordPress"', 'wp-ultimo'), - 'placeholder' => __('e.g. My App', 'wp-ultimo'), - 'desc' => __('Replace all occurrences of the word "WordPress" with a different word.', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - )); + wu_register_settings_field( + 'whitelabel', + 'rename_wordpress', + array( + 'title' => __('Replace the word "WordPress"', 'wp-ultimo'), + 'placeholder' => __('e.g. My App', 'wp-ultimo'), + 'desc' => __('Replace all occurrences of the word "WordPress" with a different word.', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + ) + ); - wu_register_settings_field('whitelabel', 'rename_site_singular', array( - 'title' => __('Replace the word "Site" (singular)', 'wp-ultimo'), - 'placeholder' => __('e.g. App', 'wp-ultimo'), - 'desc' => __('Replace all occurrences of the word "Site" with a different word.', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'wrapper_classes' => 'wu-w-1/2', - )); + wu_register_settings_field( + 'whitelabel', + 'rename_site_singular', + array( + 'title' => __('Replace the word "Site" (singular)', 'wp-ultimo'), + 'placeholder' => __('e.g. App', 'wp-ultimo'), + 'desc' => __('Replace all occurrences of the word "Site" with a different word.', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'wrapper_classes' => 'wu-w-1/2', + ) + ); - wu_register_settings_field('whitelabel', 'rename_site_plural', array( - 'title' => __('Replace the word "Sites" (plural)', 'wp-ultimo'), - 'placeholder' => __('e.g. Apps', 'wp-ultimo'), - 'desc' => __('Replace all occurrences of the word "Sites" with a different word.', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'wrapper_classes' => 'wu-w-1/2', - )); - - } // end add_settings; + wu_register_settings_field( + 'whitelabel', + 'rename_site_plural', + array( + 'title' => __('Replace the word "Sites" (plural)', 'wp-ultimo'), + 'placeholder' => __('e.g. Apps', 'wp-ultimo'), + 'desc' => __('Replace all occurrences of the word "Sites" with a different word.', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'wrapper_classes' => 'wu-w-1/2', + ) + ); + } /** * Removes the WordPress original logo from the top-bar. @@ -288,8 +291,7 @@ class Whitelabel { global $wp_admin_bar; $wp_admin_bar->remove_menu('wp-logo'); - - } // end wp_logo_admin_bar_remove; + } /** * Remove the default widgets from the user panel. @@ -309,8 +311,7 @@ class Whitelabel { unset($wp_meta_boxes['dashboard-user']['normal']['core']['dashboard_recent_comments']); unset($wp_meta_boxes['dashboard-user']['side']['core']['dashboard_primary']); unset($wp_meta_boxes['dashboard-user']['side']['core']['dashboard_secondary']); - - } // end remove_dashboard_widgets; + } /** * Removes the WordPress credits from the admin footer. @@ -321,16 +322,13 @@ class Whitelabel { public function clear_footer_texts() { if (current_user_can('manage_network')) { - return; - - } // end if; + } add_filter('admin_footer_text', '__return_empty_string', 11); add_filter('update_footer', '__return_empty_string', 11); - - } // end clear_footer_texts; + } /** * Remove the sites admin menu, if the option is selected. @@ -345,19 +343,13 @@ class Whitelabel { $index = ''; foreach ($menu as $i => $menu_item) { - if ($menu_item[2] === 'sites.php') { - $index = $i; continue; + } + } - } // end if; - - } // end foreach; - - unset($menu[$index]); - - } // end remove_sites_admin_menu; - -} // end class Whitelabel; + unset($menu[ $index ]); + } +} diff --git a/inc/class-wp-ultimo.php b/inc/class-wp-ultimo.php index ec7d14d..1b7f3c5 100644 --- a/inc/class-wp-ultimo.php +++ b/inc/class-wp-ultimo.php @@ -20,7 +20,8 @@ defined('ABSPATH') || exit; */ final class WP_Ultimo { - use \WP_Ultimo\Traits\Singleton, \WP_Ultimo\Traits\WP_Ultimo_Deprecated; + use \WP_Ultimo\Traits\Singleton; + use \WP_Ultimo\Traits\WP_Ultimo_Deprecated; /** * Version of the Plugin. @@ -154,10 +155,8 @@ final class WP_Ultimo { * and have no dependencies outside of the classes loaded so far. */ if (WP_Ultimo\Requirements::met() === false || WP_Ultimo\Requirements::run_setup() === false) { - return; - - } // end if; + } $this->loaded = true; @@ -211,9 +210,7 @@ final class WP_Ultimo { * @todo: move this to a manager in the future? */ $this->load_admin_pages(); - - - } // end init; + } /** * Returns true if all the requirements are met. @@ -224,8 +221,7 @@ final class WP_Ultimo { public function is_loaded() { return $this->loaded; - - } // end is_loaded; + } /** * Setup the plugin text domain to be used in translations. @@ -239,8 +235,7 @@ final class WP_Ultimo { */ load_plugin_textdomain('wp-ultimo', false, dirname((string) WP_ULTIMO_PLUGIN_BASENAME) . '/lang'); load_plugin_textdomain('wp-ultimo-locations', false, dirname((string) WP_ULTIMO_PLUGIN_BASENAME) . '/lang'); - - } // end setup_textdomain; + } /** * Loads the table objects for our custom tables. @@ -251,8 +246,7 @@ final class WP_Ultimo { public function setup_tables() { $this->tables = \WP_Ultimo\Loaders\Table_Loader::get_instance(); - - } // end setup_tables; + } /** * Loads public apis that should be on the global scope @@ -420,12 +414,9 @@ final class WP_Ultimo { * Admin helper functions */ if (is_admin()) { - require_once wu_path('inc/functions/admin.php'); - - } // end if; - - } // end load_public_apis; + } + } /** * Load extra the WP Multisite WaaS elements @@ -562,9 +553,12 @@ final class WP_Ultimo { \WP_Ultimo\Checkout\Checkout_Pages::get_instance(); - add_action('init', function() { - \WP_Ultimo\Checkout\Legacy_Checkout::get_instance(); - }); + add_action( + 'init', + function () { + \WP_Ultimo\Checkout\Legacy_Checkout::get_instance(); + } + ); /* * Dashboard Statistics @@ -633,8 +627,7 @@ final class WP_Ultimo { * Cron Schedules */ \WP_Ultimo\Cron::get_instance(); - - } // end load_extra_components; + } /** * Load the WP Multisite WaaS Admin Pages. @@ -798,8 +791,7 @@ final class WP_Ultimo { new WP_Ultimo\Tax\Dashboard_Taxes_Tab(); do_action('wp_ultimo_admin_pages'); - - } // end load_admin_pages; + } /** * Load extra the WP Multisite WaaS managers. @@ -917,7 +909,5 @@ final class WP_Ultimo { * Loads views overrides */ WP_Ultimo\Views::get_instance(); - - } // end load_managers; - -} // end class WP_Ultimo; + } +} diff --git a/inc/compat/class-as-admin-view.php b/inc/compat/class-as-admin-view.php index ef4212b..106d738 100644 --- a/inc/compat/class-as-admin-view.php +++ b/inc/compat/class-as-admin-view.php @@ -27,6 +27,5 @@ class AS_Admin_View { * @since 2.0.0 * @return void */ - public function init() {} // end init; - -} // end class AS_Admin_View; + public function init() {} +} diff --git a/inc/compat/class-discount-code-compat.php b/inc/compat/class-discount-code-compat.php index 8679726..a35c73f 100644 --- a/inc/compat/class-discount-code-compat.php +++ b/inc/compat/class-discount-code-compat.php @@ -32,8 +32,7 @@ class Discount_Code_Compat { public function init() { add_filter('update_post_metadata', array($this, 'check_update_coupon'), 10, 5); - - } // end init; + } /** * Saves meta data from old plugins on the new plugin. @@ -51,22 +50,18 @@ class Discount_Code_Compat { /* * Check if we are in the main site of the network. */ - if (!is_main_site()) { - + if ( ! is_main_site()) { return; - - } // end if; + } /* * Check if we have a new entity with this ID. */ $migrated_discount_code = wu_get_discount_code($object_id); - if (!$migrated_discount_code) { - + if ( ! $migrated_discount_code) { return; - - } // end if; + } /* * Prevent double prefixing. @@ -83,7 +78,5 @@ class Discount_Code_Compat { * returning anything else will prevent meta data from being saved. */ return null; - - } // end check_update_coupon; - -} // end class Discount_Code_Compat; + } +} diff --git a/inc/compat/class-domain-mapping-compat.php b/inc/compat/class-domain-mapping-compat.php index 48ab705..60094fb 100644 --- a/inc/compat/class-domain-mapping-compat.php +++ b/inc/compat/class-domain-mapping-compat.php @@ -30,7 +30,5 @@ class Domain_Mapping_Compat { * @return void */ public function init() { - - } // end init; - -} // end class Domain_Mapping_Compat; + } +} diff --git a/inc/compat/class-elementor-compat.php b/inc/compat/class-elementor-compat.php index 9bc5e42..c4e1463 100644 --- a/inc/compat/class-elementor-compat.php +++ b/inc/compat/class-elementor-compat.php @@ -36,8 +36,7 @@ class Elementor_Compat { add_filter('wu_should_redirect_to_primary_domain', array($this, 'maybe_prevent_redirection')); add_action('elementor/widget/shortcode/skins_init', array($this, 'maybe_setup_preview')); - - } // end init; + } /** * Makes sure we force elementor to regenerate the styles when necessary. @@ -48,31 +47,24 @@ class Elementor_Compat { */ public function regenerate_css($site) { - if (!class_exists('\Elementor\Plugin')) { - + if ( ! class_exists('\Elementor\Plugin')) { return; + } - } // end if; - - if (!isset($site['site_id'])) { - + if ( ! isset($site['site_id'])) { return; - - } // end if; + } switch_to_blog($site['site_id']); $file_manager = \Elementor\Plugin::$instance->files_manager; // phpcs:ignore - if (!empty($file_manager)) { - + if ( ! empty($file_manager)) { $file_manager->clear_cache(); - - } // end if; + } restore_current_blog(); - - } // end regenerate_css; + } /** * Prevents redirection to primary domain when in Elementor preview mode. @@ -85,8 +77,7 @@ class Elementor_Compat { public function maybe_prevent_redirection($should_redirect) { return wu_request('elementor-preview', false) === false ? $should_redirect : false; - - } // end maybe_prevent_redirection; + } /** * Maybe adds the setup preview for elements inside elementor. @@ -102,11 +93,7 @@ class Elementor_Compat { ); if (in_array(wu_request('action'), $elementor_actions, true)) { - wu_element_setup_preview(); - - } // end if; - - } // end maybe_setup_preview; - -} // end class Elementor_Compat; + } + } +} diff --git a/inc/compat/class-general-compat.php b/inc/compat/class-general-compat.php index 5d2ac8e..4163bbb 100644 --- a/inc/compat/class-general-compat.php +++ b/inc/compat/class-general-compat.php @@ -35,14 +35,14 @@ class General_Compat { * Woocommerce * * Removes the default woocommerce hook on switch_blog to another more performant - * + * * @see https://wordpress.org/plugins/woocommerce/ */ add_action('woocommerce_loaded', array($this, 'replace_wc_wpdb_table_fix')); /** * WP Typography. - * + * * @see https://de.wordpress.org/plugins/wp-typography/ */ add_action('load-settings_page_wp-typography', array($this, 'add_wp_typography_warning_message')); @@ -67,7 +67,7 @@ class General_Compat { /** * WP Hide Pro - * + * * @see https://wp-hide.com/ */ add_filter('wu_append_preview_parameter', array($this, 'fix_wp_hide_preview_url')); @@ -142,15 +142,16 @@ class General_Compat { * @since 2.0.0 * @see https://getkeypress.com/dns-manager/ */ - add_action('wu_before_pending_site_published', function() { + add_action( + 'wu_before_pending_site_published', + function () { - if (function_exists('KPDNS')) { - - KPDNS(); // phpcs:ignore - - } // end if; - - }, 5); // need to hook before 10 + if (function_exists('KPDNS')) { + KPDNS(); // phpcs:ignore + } + }, + 5 + ); // need to hook before 10 /** * Perfmatters. @@ -167,17 +168,16 @@ class General_Compat { * * @since 2.0.5 */ - add_action('wp', function() { + add_action( + 'wp', + function () { - if (wu_request('et_pb_preview')) { - - wu_element_setup_preview(); - - } // end if; - - }); - - } // end init; + if (wu_request('et_pb_preview')) { + wu_element_setup_preview(); + } + } + ); + } /** * Fixes a performance problem with Woocommerce. @@ -205,22 +205,20 @@ class General_Compat { ); foreach ( $tables as $name => $table ) { - $wpdb->tables[] = $table; + } - } // end foreach; + add_action( + 'switch_blog', + function () use ($wpdb, $tables) { - add_action('switch_blog', function() use ($wpdb, $tables) { - - foreach ( $tables as $name => $table ) { - - $wpdb->$name = $wpdb->prefix . $table; - - } // end foreach; - - }, 0); - - } // end replace_wc_wpdb_table_fix; + foreach ( $tables as $name => $table ) { + $wpdb->$name = $wpdb->prefix . $table; + } + }, + 0 + ); + } /** * Fixes incompatibility with the plugin WP Typography. @@ -244,8 +242,7 @@ class General_Compat { $settings['smartQuotes'] = false; return $settings; - - } // end fix_wp_typography; + } /** * Adds a warning message to let customers know why smart quotes are not working. @@ -256,8 +253,7 @@ class General_Compat { public function add_wp_typography_warning_message() { WP_Ultimo()->notices->add(__('WP Typography "Smart Quotes" replacement is not compatible with WP Multisite WaaS and will be automatically disabled.', 'wp-ultimo'), 'warning'); - - } // end add_wp_typography_warning_message; + } /** * Fixes brizy media URLs while on Ultimo's template preview @@ -278,8 +274,7 @@ class General_Compat { public function fix_brizy_preview_url($value) { return class_exists('Brizy_Editor') ? false : $value; - - } // end fix_brizy_preview_url; + } /** * Fix the Brizy editor with domain mapping. @@ -292,20 +287,15 @@ class General_Compat { public function fix_brizy_editor_screen($should_redirect) { if (class_exists('\Brizy_Editor')) { - $key = \Brizy_Editor::prefix('-edit-iframe'); if (wu_request($key, null) !== null) { - return false; - - } // end if; - - } // end if; + } + } return $should_redirect; - - } // end fix_brizy_editor_screen; + } /** * Fix the Divi editor with domain mapping. @@ -318,14 +308,11 @@ class General_Compat { public function fix_divi_editor_screen(bool $should_redirect): bool { if (isset($_GET['et_fb']) && (bool) $_GET['et_fb']) { - return false; - - } // end if; + } return $should_redirect; - - } // end fix_divi_editor_screen; + } /** * Fixes WP Hide Pro URLs while on Ultimo's template preview @@ -337,8 +324,7 @@ class General_Compat { public function fix_wp_hide_preview_url($value) { return class_exists('WPH') ? false : $value; - - } // end fix_wp_hide_preview_url; + } /** * Fix the load URL for WP Frontend Admin. @@ -353,8 +339,7 @@ class General_Compat { public function fix_frontend_admin_loading_url($final_url, $page_path_only, $blog_id) { return wu_restore_original_url($final_url, $blog_id); - - } // end fix_frontend_admin_loading_url; + } /** * Oxygen renders things very strangely, so we need to handle it separately. @@ -369,10 +354,8 @@ class General_Compat { public function maybe_parse_oxygen_content($should_enqueue, $post, $shortcode_tag) { if (function_exists('oxygen_vsb_current_user_can_access') === false) { - return $should_enqueue; - - } // end if; + } $shortcode_content = get_post_meta($post->ID, 'ct_builder_shortcodes', true); @@ -382,17 +365,14 @@ class General_Compat { * Oxygen now base64 encodes shortcodes for some reason... * Supporting third-party page builders is such a pain. */ - if (!$has_shortcode) { - + if ( ! $has_shortcode) { $base64 = base64_encode("[$shortcode_tag]"); $has_shortcode = strpos((string) $shortcode_content, $base64); - - } // end if; + } return $has_shortcode; - - } // end maybe_parse_oxygen_content; + } /** * Prevent Oxygen from removing the real wp_head hook from the template @@ -403,13 +383,15 @@ class General_Compat { */ public function prevent_oxygen_cleanup_on_template_previewer() { - add_action('wp_head', function() { + add_action( + 'wp_head', + function () { - remove_action('wp_head', 'oxy_print_cached_css', 999999); - - }, 10); - - } // end prevent_oxygen_cleanup_on_template_previewer; + remove_action('wp_head', 'oxy_print_cached_css', 999999); + }, + 10 + ); + } /** * Adds SSO to WP Maintenance Mode. @@ -422,8 +404,7 @@ class General_Compat { public function add_sso_to_maintenance_mode($sso) { add_action('wpmm_head', array($sso, 'enqueue_script')); - - } // end add_sso_to_maintenance_mode; + } /** * Run wp action on template previewer to prevent some errors like @@ -434,12 +415,11 @@ class General_Compat { public function run_wp_on_template_previewer() { if (class_exists('Avada')) { - do_action('wp'); //phpcs:disable - } // end if; + } - } // end run_wp_on_template_previewer; + } /** * Run wp action on template previewer to prevent some errors like @@ -467,13 +447,13 @@ class General_Compat { fusion_reset_all_caches(); - } // end if; + } - } // end if; + } restore_current_blog(); - } // end clear_avada_cache; + } /** * Fix the FluentCRM Pro on site duplication due to fc_meta table not exist @@ -491,9 +471,9 @@ class General_Compat { // Here we use this function due FluentCrm($class_name) returns an instance not working with remove_action $this->hard_remove_action('set_user_role', array($class_name, 'maybeAutoAlterTags'), 11); - } // end if; + } - } // end fix_fluent_pro_site_duplication; + } /** * Removes RankMath and RankMath Pro Installer::wpmu_new_blog action @@ -517,11 +497,11 @@ class General_Compat { $this->hard_remove_action('wpmu_new_blog', array($class_name, 'activate_blog'), 10); $this->hard_remove_action('wp_initialize_site', array($class_name, 'initialize_site'), 10); - } // end if; + } - } // end foreach; + } - } // end fix_rank_math_site_creation; + } /** * Removes WP E-Signature and WP E-Signature Business add-ons @@ -545,11 +525,11 @@ class General_Compat { // WP E-Signature does not provide a instance of the activation class $this->hard_remove_action('wpmu_new_blog', array($class_name, 'activate_new_site'), 10); - } // end if; + } - } // end foreach; + } - } // end fix_wp_e_signature_site_creation; + } /** * A way to remove an action if instance is not available @@ -569,7 +549,7 @@ class General_Compat { return; - } // end if; + } $handler_id = ''; @@ -579,19 +559,19 @@ class General_Compat { $handler_id = $handler_key; - } // end if; + } - } // end foreach; + } if (!empty($handler_id)) { remove_filter( $tag, $handler_id, $priority ); - } // end if; + } return; - } // end hard_remove_action; + } /** * Remove action from perfamatters that disabled password strength meter script. @@ -605,8 +585,8 @@ class General_Compat { remove_action('wp_print_scripts', 'perfmatters_disable_password_strength_meter', 100); - } // end if; + } - } // end remove_perfmatters_checkout_dep; + } -} // end class General_Compat; +} diff --git a/inc/compat/class-gutenberg-support.php b/inc/compat/class-gutenberg-support.php index e0961c0..8906292 100644 --- a/inc/compat/class-gutenberg-support.php +++ b/inc/compat/class-gutenberg-support.php @@ -35,14 +35,11 @@ class Gutenberg_Support { public function should_load() { if (function_exists('has_blocks')) { - return true; - - } // end if; + } return apply_filters('wu_gutenberg_support_should_load', true); - - } // end should_load; + } /** * Initializes the Class, if we need it. @@ -53,12 +50,9 @@ class Gutenberg_Support { public function init() { if ($this->should_load()) { - add_action('admin_enqueue_scripts', array($this, 'add_scripts')); - - } // end if; - - } // end init; + } + } /** * Adds the Gutenberg Filters scripts. @@ -70,16 +64,18 @@ class Gutenberg_Support { wp_register_script('wu-gutenberg-support', wu_get_asset('gutenberg-support.js', 'js'), array('jquery'), wu_get_version(), true); - // translators: the placeholder is replaced with the network name. + // translators: the placeholder is replaced with the network name. $preview_message = apply_filters('wu_gutenberg_support_preview_message', sprintf(__('%s is generating the preview...', 'wp-ultimo'), get_network_option(null, 'site_name'))); - wp_localize_script('wu-gutenberg-support', 'wu_gutenberg', array( - 'logo' => esc_url(wu_get_network_logo()), - 'replacement_message' => $preview_message, - )); + wp_localize_script( + 'wu-gutenberg-support', + 'wu_gutenberg', + array( + 'logo' => esc_url(wu_get_network_logo()), + 'replacement_message' => $preview_message, + ) + ); wp_enqueue_script('wu-gutenberg-support'); - - } // end add_scripts; - -} // end class Gutenberg_Support; + } +} diff --git a/inc/compat/class-legacy-shortcodes.php b/inc/compat/class-legacy-shortcodes.php index d0d56d5..bfcdd0f 100644 --- a/inc/compat/class-legacy-shortcodes.php +++ b/inc/compat/class-legacy-shortcodes.php @@ -57,8 +57,7 @@ class Legacy_Shortcodes { add_shortcode('wu_pricing_table', array($this, 'pricing_table')); add_shortcode('wu_templates_list', array($this, 'templates_list')); - - } // end init; + } /** * Return the value of a user meta on the database. @@ -81,39 +80,34 @@ class Legacy_Shortcodes { $customer = $site->get_customer(); if ($customer) { - $customer_id = $customer->get_id(); $user_id = $customer->get_user_id(); + } - } // end if; - - $atts = shortcode_atts(array( - 'user_id' => $user_id, - 'meta_name' => 'first_name', - 'default' => false, - 'unique' => true, - ), $atts, 'wu_user_meta'); + $atts = shortcode_atts( + array( + 'user_id' => $user_id, + 'meta_name' => 'first_name', + 'default' => false, + 'unique' => true, + ), + $atts, + 'wu_user_meta' + ); if ($customer_id) { - $value = $customer->get_meta($atts['meta_name']); - } else { - $value = get_user_meta($atts['user_id'], $atts['meta_name'], $atts['unique']); - - } // end if; + } if (is_array($value)) { - $value = implode(', ', $value); - - } // end if; + } return $value ? $value : '--'; - - } // end user_meta; + } /** * Returns the number of paying users on the platform. @@ -129,13 +123,14 @@ class Legacy_Shortcodes { $atts = shortcode_atts(array(), $atts, 'wu_paying_users'); - $paying_customers = wu_get_customers(array( - 'count' => true, - )); + $paying_customers = wu_get_customers( + array( + 'count' => true, + ) + ); return $paying_customers; - - } // end paying_users; + } /** * Plan Link shortcode. @@ -147,22 +142,24 @@ class Legacy_Shortcodes { */ public function plan_link($atts) { - $atts = shortcode_atts(array( - 'plan_id' => 0, - 'plan_freq' => 1, - 'skip_plan' => 1, - ), $atts, 'wu_plan_link'); + $atts = shortcode_atts( + array( + 'plan_id' => 0, + 'plan_freq' => 1, + 'skip_plan' => 1, + ), + $atts, + 'wu_plan_link' + ); /** * Treat the results to make sure we are getting numbers out of it - * + * * @since 1.5.1 */ foreach (array('plan_id', 'plan_freq') as $att) { - - $atts[$att] = wu_extract_number($atts[$att]); - - } // end foreach; + $atts[ $att ] = wu_extract_number($atts[ $att ]); + } $path = ''; @@ -173,30 +170,23 @@ class Legacy_Shortcodes { $plan = wu_get_product_by('migrated_from_id', $atts['plan_id']); if ($plan) { - $path = $plan->get_slug(); - - } // end if; + } /** * Second pass: try via the real ID, if new customers * decide to use the old shortcode. */ if (empty($path)) { - $plan = wu_get_product($atts['plan_id']); if ($plan) { - $path = $plan->get_slug(); - - } // end if; - - } // end if; + } + } return wu_get_registration_url($path); - - } // end plan_link; + } /** * Renders the restrict content shortcode. @@ -209,40 +199,38 @@ class Legacy_Shortcodes { */ public function restricted_content($atts, $content) { - $atts = shortcode_atts(array( - 'plan_id' => false, - 'product_id' => false, - 'only_active' => true, - 'only_logged' => false, - 'exclude_trials' => false, - 'from_request' => false, - ), $atts, 'wu_restricted_content'); + $atts = shortcode_atts( + array( + 'plan_id' => false, + 'product_id' => false, + 'only_active' => true, + 'only_logged' => false, + 'exclude_trials' => false, + 'from_request' => false, + ), + $atts, + 'wu_restricted_content' + ); - $atts['plan_id'] = !empty($atts['product_id']) ? $atts['product_id'] : $atts['plan_id']; - - if (empty($atts) || !$atts['plan_id']) { + $atts['plan_id'] = ! empty($atts['product_id']) ? $atts['product_id'] : $atts['plan_id']; + if (empty($atts) || ! $atts['plan_id']) { return __('You need to pass a valid plan ID.', 'wp-ultimo'); - - } // end if; + } $query_products = get_query_var('products', array()); $request_products = array(); foreach ($query_products as $product) { - $product = wu_get_product($product); - if (!$product) { - + if ( ! $product) { continue; - - } // end if; + } $request_products[] = $product->get_id(); - - } // end foreach; + } $plan_ids = explode(',', $atts['plan_id']); $plan_ids = array_map('trim', $plan_ids); @@ -251,16 +239,12 @@ class Legacy_Shortcodes { $else = '[wu_default_content]'; if (strpos($content, $else) !== false) { - list($if, $else) = explode($else, $content, 2); - } else { - $if = $content; $else = ''; - - } // end if; + } $condition = false; @@ -268,12 +252,11 @@ class Legacy_Shortcodes { $user_logged_in = is_user_logged_in(); - $should_check = !(bool) $atts['only_logged'] || $user_logged_in; + $should_check = ! (bool) $atts['only_logged'] || $user_logged_in; $from_request = $atts['from_request'] && count(array_intersect($plan_ids, $request_products)) > 0; - if ($membership && $should_check && !$from_request) { - + if ($membership && $should_check && ! $from_request) { $membership_products = array_merge( array($membership->get_plan_id()), $membership->get_addon_ids() @@ -281,29 +264,21 @@ class Legacy_Shortcodes { $condition = in_array('all', $plan_ids, true) || count(array_intersect($membership_products, $plan_ids)) > 0; - if ((bool) $atts['only_active']) { - + if ( (bool) $atts['only_active']) { $condition = $condition && ($membership->is_active() || $membership->get_status() === 'trialing'); + } - } // end if; - - if ((bool) $atts['exclude_trials']) { - - $condition = $condition && !$membership->is_trialing(); - - } // end if; - + if ( (bool) $atts['exclude_trials']) { + $condition = $condition && ! $membership->is_trialing(); + } } else { - $condition = $from_request && $should_check; - - } // end if; + } $final_content = wpautop($condition ? $if : $else); return do_shortcode($final_content); - - } // end restricted_content; + } /** * Adds the pricing table shortcode. @@ -321,27 +296,29 @@ class Legacy_Shortcodes { global $post; - $atts = shortcode_atts(array( - 'primary_color' => wu_get_setting('primary_color', '#00a1ff'), - 'accent_color' => wu_get_setting('accent_color', '#78b336'), - 'default_pricing_option' => wu_get_setting('default_pricing_option', 1), - 'plan_id' => false, - 'show_selector' => true, - // New Options - 'layout' => 'legacy', - 'period_selector_layout' => 'legacy', - ), $atts, 'wu_pricing_table'); + $atts = shortcode_atts( + array( + 'primary_color' => wu_get_setting('primary_color', '#00a1ff'), + 'accent_color' => wu_get_setting('accent_color', '#78b336'), + 'default_pricing_option' => wu_get_setting('default_pricing_option', 1), + 'plan_id' => false, + 'show_selector' => true, + // New Options + 'layout' => 'legacy', + 'period_selector_layout' => 'legacy', + ), + $atts, + 'wu_pricing_table' + ); /** * In the case of the legacy layout, we need to load extra styles. */ if ($atts['layout'] === 'legacy') { - wp_enqueue_style('legacy-signup', wu_get_asset('legacy-signup.css', 'css')); wp_add_inline_style('legacy-signup', \WP_Ultimo\Checkout\Legacy_Checkout::get_instance()->get_legacy_dynamic_styles()); - - } // end if; + } do_action('wu_checkout_scripts', $post); @@ -349,7 +326,7 @@ class Legacy_Shortcodes { $atts['plan_id'] = is_string($atts['plan_id']) && $atts['plan_id'] !== 'all' ? explode(',', $atts['plan_id']) : false; - $checkout_form = new \WP_Ultimo\Models\Checkout_Form; + $checkout_form = new \WP_Ultimo\Models\Checkout_Form(); $fields = array(); @@ -358,13 +335,10 @@ class Legacy_Shortcodes { ); if ($atts['plan_id']) { - $search_arguments['id__in'] = $atts['plan_id']; - - } // end if; + } if ($atts['show_selector']) { - $fields[] = array( 'step' => 'checkout', 'name' => '', @@ -389,8 +363,7 @@ class Legacy_Shortcodes { ), ), ); - - } // end if; + } $layout = $atts['layout']; @@ -410,18 +383,16 @@ class Legacy_Shortcodes { * we'll need a submit field. */ if ($layout !== 'legacy') { - - $fields[] = array ( + $fields[] = array( 'step' => 'checkout', 'name' => __('Get Started →', 'wp-ultimo'), 'type' => 'submit_button', 'id' => 'checkout', ); + } - } // end if; - - $steps = array ( - array ( + $steps = array( + array( 'id' => 'checkout', 'name' => __('Checkout', 'wp-ultimo'), 'desc' => '', @@ -441,14 +412,21 @@ class Legacy_Shortcodes { do_action('wu_setup_checkout'); - wp_add_inline_script('wu-checkout', sprintf(' + wp_add_inline_script( + 'wu-checkout', + sprintf( + ' /** * Set the auto-submittable field, if one exists. */ window.wu_auto_submittable_field = %s; - ', json_encode($auto_submittable_field)), 'after'); + ', + json_encode($auto_submittable_field) + ), + 'after' + ); $final_fields = wu_create_checkout_fields($checkout_form->get_step('checkout', true)['fields']); @@ -469,16 +447,18 @@ class Legacy_Shortcodes { 'value' => 1, ); - return wu_get_template_contents('checkout/form', array( - 'step' => $checkout_form->get_step('checkout', true), - 'step_name' => 'checkout', - 'checkout_form_name' => 'wu_pricing_table', - 'checkout_form_action' => add_query_arg('pre-flight', 1, wu_get_registration_url()), - 'display_title' => '', - 'final_fields' => $final_fields, - )); - - } // end pricing_table; + return wu_get_template_contents( + 'checkout/form', + array( + 'step' => $checkout_form->get_step('checkout', true), + 'step_name' => 'checkout', + 'checkout_form_name' => 'wu_pricing_table', + 'checkout_form_action' => add_query_arg('pre-flight', 1, wu_get_registration_url()), + 'display_title' => '', + 'final_fields' => $final_fields, + ) + ); + } /** * Adds the template sites shortcode. @@ -496,18 +476,22 @@ class Legacy_Shortcodes { global $post; - $atts = shortcode_atts(array( - 'show_filters' => true, - 'show_title' => true, - 'templates' => false, - 'cols' => 3, - 'layout' => 'legacy', - 'checkout_page' => wu_guess_registration_page(), - ), $atts, 'wu_templates_list'); + $atts = shortcode_atts( + array( + 'show_filters' => true, + 'show_title' => true, + 'templates' => false, + 'cols' => 3, + 'layout' => 'legacy', + 'checkout_page' => wu_guess_registration_page(), + ), + $atts, + 'wu_templates_list' + ); /** - * Hide header, if necessary - */ + * Hide header, if necessary + */ add_filter('wu_step_template_display_header', $atts['show_title'] ? '__return_true' : '__return_false'); /** @@ -521,14 +505,12 @@ class Legacy_Shortcodes { * In the case of the legacy layout, we need to load extra styles. */ if ($atts['layout'] === 'legacy') { - wp_enqueue_style('legacy-signup', wu_get_asset('legacy-signup.css', 'css')); wp_add_inline_style('legacy-signup', \WP_Ultimo\Checkout\Legacy_Checkout::get_instance()->get_legacy_dynamic_styles()); + } - } // end if; - - $checkout_form = new \WP_Ultimo\Models\Checkout_Form; + $checkout_form = new \WP_Ultimo\Models\Checkout_Form(); $fields = array(); @@ -549,8 +531,8 @@ class Legacy_Shortcodes { 'element_classes' => $layout === 'legacy' ? 'wu-content-templates' : '', ); - $steps = array ( - array ( + $steps = array( + array( 'id' => 'checkout', 'name' => __('Checkout', 'wp-ultimo'), 'desc' => '', @@ -572,14 +554,21 @@ class Legacy_Shortcodes { do_action('wu_setup_checkout'); - wp_add_inline_script('wu-checkout', sprintf(' + wp_add_inline_script( + 'wu-checkout', + sprintf( + ' /** * Set the auto-submittable field, if one exists. */ window.wu_auto_submittable_field = %s; - ', json_encode($auto_submittable_field)), 'after'); + ', + json_encode($auto_submittable_field) + ), + 'after' + ); $final_fields['pre-flight'] = array( 'type' => 'hidden', @@ -588,16 +577,18 @@ class Legacy_Shortcodes { $page_url = wu_switch_blog_and_run(fn() => get_permalink($atts['checkout_page'])); - return wu_get_template_contents('checkout/form', array( - 'step' => $checkout_form->get_step('checkout', true), - 'step_name' => 'checkout', - 'checkout_form_name' => 'wu_templates_list', - 'checkout_form_action' => add_query_arg('pre-flight', 1, $page_url), - 'display_title' => '', - 'final_fields' => $final_fields, - )); - - } // end templates_list; + return wu_get_template_contents( + 'checkout/form', + array( + 'step' => $checkout_form->get_step('checkout', true), + 'step_name' => 'checkout', + 'checkout_form_name' => 'wu_templates_list', + 'checkout_form_action' => add_query_arg('pre-flight', 1, $page_url), + 'display_title' => '', + 'final_fields' => $final_fields, + ) + ); + } /** * Makes sure we don't return any invalid values. * @@ -609,7 +600,5 @@ class Legacy_Shortcodes { $list = array_map('trim', explode(',', $templates)); return array_filter($list); - - } // end treat_template_list; - -} // end class Legacy_Shortcodes; + } +} diff --git a/inc/compat/class-multiple-accounts-compat.php b/inc/compat/class-multiple-accounts-compat.php index c0ed6d1..350bb26 100644 --- a/inc/compat/class-multiple-accounts-compat.php +++ b/inc/compat/class-multiple-accounts-compat.php @@ -82,10 +82,8 @@ class Multiple_Accounts_Compat { // Adds the number of additional accounts. add_filter('manage_users_custom_column', array($this, 'add_column_content'), 10, 3); - - } // end if; - - } // end init; + } + } /** * Fixes the object cache to allow multiple accounts. @@ -98,16 +96,13 @@ class Multiple_Accounts_Compat { public function fix_object_cache_on_multiple_accounts(): void { $to_remove = array( - 'useremail' + 'useremail', ); if (function_exists('wp_cache_add_non_persistent_groups')) { - wp_cache_add_non_persistent_groups($to_remove); - - } // end if; - - } // end fix_object_cache_on_multiple_accounts; + } + } /** * Filters the database query so that we can get the right user. @@ -124,7 +119,6 @@ class Multiple_Accounts_Compat { $search = "\$db->get_row(\"SELECT * FROM $wpdb->users WHERE user_email"; if ( strpos($wpdb->func_call, $search) === 0) { - $prefix = "SELECT * FROM $wpdb->users WHERE user_email"; $last = substr($query, strlen($prefix)); @@ -135,17 +129,19 @@ class Multiple_Accounts_Compat { * We can't use the $wpdb->prepare() method here because it will * escape the %s placeholder, which will break the query. */ - return sprintf("SELECT u.* + return sprintf( + "SELECT u.* FROM $wpdb->users u JOIN $wpdb->usermeta m on u.id = m.user_id WHERE m.meta_key = \"wp_%d_capabilities\" - AND u.user_email%s", $site_id, $last); - - } // end if; + AND u.user_email%s", + $site_id, + $last + ); + } return $query; - - } // end fix_user_query; + } /** * Hooks into email_exists verification to allow duplicate emails in different sites. @@ -159,16 +155,13 @@ class Multiple_Accounts_Compat { public function allow_duplicate_emails($user_id, string $email) { if ($user_id) { - $site_user = $this->get_right_user($email); return $site_user ? $site_user->ID : false; - - } // end if; + } return $user_id; - - } // end allow_duplicate_emails; + } /** * Prevent WooCommerce from adding users to site without us knowing. @@ -186,8 +179,7 @@ class Multiple_Accounts_Compat { add_filter('can_add_user_to_blog', '__return_false'); return $results; - - } // end prevent_woo_from_adding_to_blog; + } /** * Checks if the user belongs to a site they are currently viewing and unset them if they don't. @@ -200,10 +192,8 @@ class Multiple_Accounts_Compat { global $current_user; if (is_admin() || is_main_site() || current_user_can('manage_network')) { - return; - - } // end if; + } /** * Allow developers to bypass the unset current user code. @@ -222,10 +212,8 @@ class Multiple_Accounts_Compat { * @return mixed */ if (apply_filters('wu_bypass_unset_current_user', null, $current_user) !== null) { - return; - - } // end if; + } $user = wp_get_current_user(); @@ -237,16 +225,13 @@ class Multiple_Accounts_Compat { * currently logged in. */ if ($has_user === false) { - wu_x_header('X-Ultimo-Multiple-Accounts: user-unset'); $current_user = null; wp_set_current_user(0); - - } // end if; - - } // end maybe_unset_current_user; + } + } /** * Allow plugin developers to disable this functionality to prevent compatibility issues. @@ -258,8 +243,7 @@ class Multiple_Accounts_Compat { public function should_load() { return apply_filters('wu_should_load_multiple_accounts_support', wu_get_setting('enable_multiple_accounts', true)); - - } // end should_load; + } // Methods @@ -272,20 +256,27 @@ class Multiple_Accounts_Compat { */ public function add_settings() { - wu_register_settings_field('login-and-registration', 'multiple_accounts_header', array( - 'title' => __('Multiple Accounts', 'wp-ultimo'), - 'desc' => __('Options related to the Multiple Accounts feature.', 'wp-ultimo'), - 'type' => 'header', - )); + wu_register_settings_field( + 'login-and-registration', + 'multiple_accounts_header', + array( + 'title' => __('Multiple Accounts', 'wp-ultimo'), + 'desc' => __('Options related to the Multiple Accounts feature.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - wu_register_settings_field('login-and-registration', 'enable_multiple_accounts', array( - 'title' => __('Enable Multiple Accounts', 'wp-ultimo'), - 'desc' => __('Allow users to have accounts in different sites with the same email address. This is useful when running stores with WooCommerce and other plugins, for example.', 'wp-ultimo') . ' ' . sprintf('%s', wu_get_documentation_url('multiple-accounts'), __('Read More', 'wp-ultimo')), - 'type' => 'toggle', - 'default' => 0, - )); - - } // end add_settings; + wu_register_settings_field( + 'login-and-registration', + 'enable_multiple_accounts', + array( + 'title' => __('Enable Multiple Accounts', 'wp-ultimo'), + 'desc' => __('Allow users to have accounts in different sites with the same email address. This is useful when running stores with WooCommerce and other plugins, for example.', 'wp-ultimo') . ' ' . sprintf('%s', wu_get_documentation_url('multiple-accounts'), __('Read More', 'wp-ultimo')), + 'type' => 'toggle', + 'default' => 0, + ) + ); + } /** * Adds the Multiple accounts column to the users table. @@ -300,8 +291,7 @@ class Multiple_Accounts_Compat { $columns['multiple_accounts'] = __('Multiple Accounts', 'wp-ultimo'); return $columns; - - } // end add_multiple_account_column; + } /** * Renders the content of our custom column. @@ -321,11 +311,13 @@ class Multiple_Accounts_Compat { $user = get_user_by('ID', $user_id); // Get all the accounts with the same email - $users = new \WP_User_Query(array( - 'blog_id' => 0, - 'search' => $user->user_email, - 'fields' => array('ID', 'user_login'), - )); + $users = new \WP_User_Query( + array( + 'blog_id' => 0, + 'search' => $user->user_email, + 'fields' => array('ID', 'user_login'), + ) + ); // translators: the %d is the account count for that email address. $html = sprintf(__('%d accounts using this email.', 'wp-ultimo'), $users->total_users); @@ -333,10 +325,8 @@ class Multiple_Accounts_Compat { $html .= sprintf("
" . __('See all', 'wp-ultimo') . ' »', network_admin_url('users.php?s=' . $user->user_email)); echo $html; - - } // end if; - - } // end add_column_content; + } + } /** * Handles password resetting. @@ -351,18 +341,14 @@ class Multiple_Accounts_Compat { // Only do thing if is login by email if (is_email($_REQUEST['user_login'])) { - $user = $this->get_right_user($_REQUEST['user_login']); $_REQUEST['user_login'] = $user->user_login; $_POST['user_login'] = $user->user_login; - - } // end if; - - } // end if; - - } // end handle_reset_password; + } + } + } /** * Checks if a given user is a member in the site. @@ -391,12 +377,10 @@ class Multiple_Accounts_Compat { * @since 2.0.11 */ if ($user_id) { - $query['include'] = array( absint($user_id), ); - - } // end if; + } // Now we search for the correct user based on the password and the blog information $users = new \WP_User_Query($query); @@ -406,43 +390,36 @@ class Multiple_Accounts_Compat { // Check for the pertinence of that user in this site if ($this->user_can_for_blog($user_with_email, get_current_blog_id(), 'read')) { - $has_user = true; break; - - } // end if; - - } // end foreach; + } + } // If nothing was found return false; return $has_user; + } + /** + * Gets the right user when logging-in. + * + * @since 2.0.0 + * + * @param null|\WP_User|\WP_Error $user The current user object. Usually false. + * @param string $username The username to search for. + * @param string $password The user password. + * @return null|\WP_User|\WP_Error + */ + public function fix_login($user, $username, $password) { - } // end check_for_user_in_site; - /** - * Gets the right user when logging-in. - * - * @since 2.0.0 - * - * @param null|\WP_User|\WP_Error $user The current user object. Usually false. - * @param string $username The username to search for. - * @param string $password The user password. - * @return null|\WP_User|\WP_Error - */ - public function fix_login($user, $username, $password) { - - if (!is_email($username)) { - + if ( ! is_email($username)) { return $user; - - } // end if; + } // Sets the right user to be returned; $user = $this->get_right_user($username, $password); return $user ? $user : null; - - } // end fix_login; + } /** * Check if user can do something in a specific blog. @@ -461,42 +438,35 @@ class Multiple_Accounts_Compat { $current_user = $user; if (empty($current_user)) { - if ($switched) { - restore_current_blog(); - - } // end if; + } return false; - - } // end if; + } $args = array_slice(func_get_args(), 2); $args = array_merge(array($capability), $args); - $can = call_user_func_array(\Closure::fromCallable([$current_user, 'has_cap']), $args); + $can = call_user_func_array(\Closure::fromCallable(array($current_user, 'has_cap')), $args); if ($switched) { - restore_current_blog(); - - } // end if; + } return $can; - - } // end user_can_for_blog; - /** - * Gets the right user for a given domain. - * - * @since 2.0.0 - * - * @param string $email User email address. - * @param boolean $password User password. - * @return \WP_User|false - */ - protected function get_right_user($email, $password = false) { + } + /** + * Gets the right user for a given domain. + * + * @since 2.0.0 + * + * @param string $email User email address. + * @param boolean $password User password. + * @return \WP_User|false + */ + protected function get_right_user($email, $password = false) { // Sets the right user to be returned; $right_user = false; @@ -507,7 +477,6 @@ class Multiple_Accounts_Compat { // Loop the results and check which one is in this group foreach ($users->results as $user_with_email) { - $conditions = $password == false ? true : wp_check_password($password, $user_with_email->user_pass, $user_with_email->ID); // Check for the pertinence of that user in this site @@ -517,14 +486,10 @@ class Multiple_Accounts_Compat { $right_user = $user_with_email; continue; - - } // end if; - - } // end foreach; + } + } // Return right user return $right_user; - - } // end get_right_user; - -} // end class Multiple_Accounts_Compat; + } +} diff --git a/inc/compat/class-product-compat.php b/inc/compat/class-product-compat.php index 0102173..e2f3e63 100644 --- a/inc/compat/class-product-compat.php +++ b/inc/compat/class-product-compat.php @@ -34,8 +34,7 @@ class Product_Compat { add_filter('wu_product_options_sections', array($this, 'add_legacy_section'), 100, 2); add_filter('update_post_metadata', array($this, 'check_update_plan'), 10, 5); - - } // end init; + } /** * Saves meta data from old plugins on the new plugin. @@ -53,22 +52,18 @@ class Product_Compat { /* * Check if we are in the main site of the network. */ - if (!is_main_site()) { - + if ( ! is_main_site()) { return; - - } // end if; + } /* * Check if we have a new entity with this ID. */ $migrated_product = wu_get_product($object_id); - if (!$migrated_product) { - + if ( ! $migrated_product) { return; - - } // end if; + } /* * Prevent double prefixing. @@ -85,8 +80,7 @@ class Product_Compat { * returning anything else will prevent meta data from being saved. */ return null; - - } // end check_update_plan; + } /** * Injects the compatibility panels to products Advanced Options. @@ -142,7 +136,5 @@ class Product_Compat { ); return $sections; - - } // end add_legacy_section; - -} // end class Product_Compat; + } +} diff --git a/inc/contracts/Session.php b/inc/contracts/Session.php index b3b2867..344ec3a 100644 --- a/inc/contracts/Session.php +++ b/inc/contracts/Session.php @@ -12,7 +12,7 @@ interface Session { /** * Gets the value of a session key. - * + * * @param string $key The key to retrieve. * @return mixed */ @@ -55,5 +55,4 @@ interface Session { * @return bool */ public function destroy(); - -} // end interface; +} diff --git a/inc/country/class-country-br.php b/inc/country/class-country-br.php index 1caac15..2c0c8bb 100644 --- a/inc/country/class-country-br.php +++ b/inc/country/class-country-br.php @@ -91,8 +91,7 @@ class Country_BR extends Country { public function get_name() { return __('Brazil', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for BR. @@ -131,7 +130,5 @@ class Country_BR extends Country { 'SP' => __('São Paulo', 'wp-ultimo-locations'), 'TO' => __('Tocantins', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_BR; + } +} diff --git a/inc/country/class-country-ca.php b/inc/country/class-country-ca.php index 501a789..3e4cafc 100644 --- a/inc/country/class-country-ca.php +++ b/inc/country/class-country-ca.php @@ -77,8 +77,7 @@ class Country_CA extends Country { public function get_name() { return __('Canada', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for CA. @@ -103,7 +102,5 @@ class Country_CA extends Country { 'SK' => __('Saskatchewan', 'wp-ultimo-locations'), 'YT' => __('Yukon', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_CA; + } +} diff --git a/inc/country/class-country-cn.php b/inc/country/class-country-cn.php index 2161c1e..6ef40e6 100644 --- a/inc/country/class-country-cn.php +++ b/inc/country/class-country-cn.php @@ -96,8 +96,7 @@ class Country_CN extends Country { public function get_name() { return __('China', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for CN. @@ -143,7 +142,5 @@ class Country_CN extends Country { 'YN' => __('Yunnan', 'wp-ultimo'), 'ZJ' => __('Zhejiang', 'wp-ultimo'), ); - - } // end states; - -} // end class Country_CN; + } +} diff --git a/inc/country/class-country-de.php b/inc/country/class-country-de.php index f0fe8fc..68be42e 100644 --- a/inc/country/class-country-de.php +++ b/inc/country/class-country-de.php @@ -80,8 +80,7 @@ class Country_DE extends Country { public function get_name() { return __('Germany', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for DE. @@ -109,7 +108,5 @@ class Country_DE extends Country { 'SH' => __('Schleswig-Holstein', 'wp-ultimo-locations'), 'TH' => __('Thuringia', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_DE; + } +} diff --git a/inc/country/class-country-default.php b/inc/country/class-country-default.php index 3bf7597..4452171 100644 --- a/inc/country/class-country-default.php +++ b/inc/country/class-country-default.php @@ -40,8 +40,7 @@ class Country_Default extends Country { public function get_name() { return $this->name; - - } // end get_name; + } /** * Creates a country instance with a code and name. @@ -55,18 +54,19 @@ class Country_Default extends Country { */ public static function build($code, $name = null, $attributes = array()) { - $instance = new self; + $instance = new self(); $instance->name = $name ? $name : wu_get_country_name($code); - $instance->attributes = wp_parse_args($attributes, array( - 'country_code' => strtoupper($code), - 'currency' => strtoupper($code), - 'phone_code' => 00, - )); + $instance->attributes = wp_parse_args( + $attributes, + array( + 'country_code' => strtoupper($code), + 'currency' => strtoupper($code), + 'phone_code' => 00, + ) + ); return $instance; - - } // end build; - -} // end class Country_Default; + } +} diff --git a/inc/country/class-country-es.php b/inc/country/class-country-es.php index e432d0a..04c21fb 100644 --- a/inc/country/class-country-es.php +++ b/inc/country/class-country-es.php @@ -82,8 +82,7 @@ class Country_ES extends Country { public function get_name() { return __('Spain', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for ES. @@ -123,7 +122,5 @@ class Country_ES extends Country { 'ZA' => __('Zamora Province', 'wp-ultimo-locations'), 'AV' => __('Ávila', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_ES; + } +} diff --git a/inc/country/class-country-fr.php b/inc/country/class-country-fr.php index 87462ff..36be3d1 100644 --- a/inc/country/class-country-fr.php +++ b/inc/country/class-country-fr.php @@ -77,8 +77,7 @@ class Country_FR extends Country { public function get_name() { return __('France', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for FR. @@ -213,7 +212,5 @@ class Country_FR extends Country { 'WF' => __('Wallis and Futuna', 'wp-ultimo-locations'), 'IDF' => __('Île-de-France', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_FR; + } +} diff --git a/inc/country/class-country-gb.php b/inc/country/class-country-gb.php index bd6c156..b7655f0 100644 --- a/inc/country/class-country-gb.php +++ b/inc/country/class-country-gb.php @@ -68,8 +68,7 @@ class Country_GB extends Country { public function get_name() { return __('United Kingdom', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for GB. @@ -328,7 +327,5 @@ class Country_GB extends Country { 'WOR' => __('Worcestershire', 'wp-ultimo-locations'), 'WRX' => __('Wrexham County Borough', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_GB; + } +} diff --git a/inc/country/class-country-in.php b/inc/country/class-country-in.php index 279c6fe..678356f 100644 --- a/inc/country/class-country-in.php +++ b/inc/country/class-country-in.php @@ -100,8 +100,7 @@ class Country_IN extends Country { public function get_name() { return __('India', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for IN. @@ -149,7 +148,5 @@ class Country_IN extends Country { 'UT' => __('Uttarakhand', 'wp-ultimo-locations'), 'WB' => __('West Bengal', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_IN; + } +} diff --git a/inc/country/class-country-jp.php b/inc/country/class-country-jp.php index 92ddd8a..9ff1521 100644 --- a/inc/country/class-country-jp.php +++ b/inc/country/class-country-jp.php @@ -111,8 +111,7 @@ class Country_JP extends Country { public function get_name() { return __('Japan', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for JP. @@ -171,7 +170,5 @@ class Country_JP extends Country { '09' => __('Tochigi Prefecture', 'wp-ultimo-locations'), '06' => __('Yamagata Prefecture', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_JP; + } +} diff --git a/inc/country/class-country-mx.php b/inc/country/class-country-mx.php index c7dbcea..1feb0a5 100644 --- a/inc/country/class-country-mx.php +++ b/inc/country/class-country-mx.php @@ -96,8 +96,7 @@ class Country_MX extends Country { public function get_name() { return __('Mexico', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for MX. @@ -141,7 +140,5 @@ class Country_MX extends Country { 'YUC' => __('Yucatán', 'wp-ultimo-locations'), 'ZAC' => __('Zacatecas', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_MX; + } +} diff --git a/inc/country/class-country-my.php b/inc/country/class-country-my.php index d3ff656..3f4a38f 100644 --- a/inc/country/class-country-my.php +++ b/inc/country/class-country-my.php @@ -80,8 +80,7 @@ class Country_MY extends Country { public function get_name() { return __('Malaysia', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for MY. @@ -109,7 +108,5 @@ class Country_MY extends Country { '08' => __('Perak', 'wp-ultimo-locations'), '09' => __('Perlis', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_MY; + } +} diff --git a/inc/country/class-country-ne.php b/inc/country/class-country-ne.php index 5734969..15a5925 100644 --- a/inc/country/class-country-ne.php +++ b/inc/country/class-country-ne.php @@ -71,8 +71,7 @@ class Country_NE extends Country { public function get_name() { return __('Niger', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for NE. @@ -91,7 +90,5 @@ class Country_NE extends Country { '6' => __('Tillabéri Region', 'wp-ultimo-locations'), '7' => __('Zinder Region', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_NE; + } +} diff --git a/inc/country/class-country-nl.php b/inc/country/class-country-nl.php index 5d0f55b..886d5c7 100644 --- a/inc/country/class-country-nl.php +++ b/inc/country/class-country-nl.php @@ -76,8 +76,7 @@ class Country_NL extends Country { public function get_name() { return __('Netherlands', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for NL. @@ -104,7 +103,5 @@ class Country_NL extends Country { 'UT' => __('Utrecht', 'wp-ultimo-locations'), 'ZE' => __('Zeeland', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_NL; + } +} diff --git a/inc/country/class-country-ru.php b/inc/country/class-country-ru.php index 268f377..d24dbc1 100644 --- a/inc/country/class-country-ru.php +++ b/inc/country/class-country-ru.php @@ -147,8 +147,7 @@ class Country_RU extends Country { public function get_name() { return __('Russia', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for RU. @@ -244,7 +243,5 @@ class Country_RU extends Country { 'YAR' => __('Yaroslavl Oblast', 'wp-ultimo-locations'), 'ZAB' => __('Zabaykalsky Krai', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_RU; + } +} diff --git a/inc/country/class-country-sg.php b/inc/country/class-country-sg.php index f35ff23..aee2a52 100644 --- a/inc/country/class-country-sg.php +++ b/inc/country/class-country-sg.php @@ -66,8 +66,7 @@ class Country_SG extends Country { public function get_name() { return __('Singapore', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for SG. @@ -84,7 +83,5 @@ class Country_SG extends Country { '04' => __('South East Community Development Council', 'wp-ultimo-locations'), '05' => __('South West Community Development Council', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_SG; + } +} diff --git a/inc/country/class-country-tr.php b/inc/country/class-country-tr.php index 9065024..466bb77 100644 --- a/inc/country/class-country-tr.php +++ b/inc/country/class-country-tr.php @@ -145,8 +145,7 @@ class Country_TR extends Country { public function get_name() { return __('Turkey', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for TR. @@ -239,7 +238,5 @@ class Country_TR extends Country { '09' => __('Aydın', 'wp-ultimo-locations'), '04' => __('Ağrı', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_TR; + } +} diff --git a/inc/country/class-country-us.php b/inc/country/class-country-us.php index f78bbc8..b781daa 100644 --- a/inc/country/class-country-us.php +++ b/inc/country/class-country-us.php @@ -116,8 +116,7 @@ class Country_US extends Country { public function get_name() { return __('United States', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for US. @@ -195,7 +194,5 @@ class Country_US extends Country { 'WI' => __('Wisconsin', 'wp-ultimo-locations'), 'WY' => __('Wyoming', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_US; + } +} diff --git a/inc/country/class-country-za.php b/inc/country/class-country-za.php index 82b4fd0..e66d1b0 100644 --- a/inc/country/class-country-za.php +++ b/inc/country/class-country-za.php @@ -73,8 +73,7 @@ class Country_ZA extends Country { public function get_name() { return __('South Africa', 'wp-ultimo-locations'); - - } // end get_name; + } /** * Returns the list of states for ZA. @@ -95,7 +94,5 @@ class Country_ZA extends Country { 'NC' => __('Northern Cape', 'wp-ultimo-locations'), 'WC' => __('Western Cape', 'wp-ultimo-locations'), ); - - } // end states; - -} // end class Country_ZA; + } +} diff --git a/inc/country/class-country.php b/inc/country/class-country.php index 64dbdfc..d776ba4 100644 --- a/inc/country/class-country.php +++ b/inc/country/class-country.php @@ -59,8 +59,7 @@ abstract class Country { public function __get($attribute) { return wu_get_isset($this->attributes, $attribute, null); - - } // end __get; + } /** * Returns the list of states/provinces of this country. @@ -85,8 +84,7 @@ abstract class Country { * @return array The filtered list of states. */ return apply_filters('wu_country_get_states', $states, $this->country_code, $this); - - } // end get_states; + } /** * Returns states as options. @@ -103,17 +101,14 @@ abstract class Country { $placeholder_option = array(); if ($placeholder !== false && $options) { - $division_name = $this->get_administrative_division_name(); // translators: %s is the name of the administrative division (state, province, etc). $placeholder_option[''] = $placeholder !== '' ? $placeholder : sprintf(__('Select your %s', 'wp-ultimo'), $division_name); - - } // end if; + } return array_merge($placeholder_option, $options); - - } // end get_states_as_options; + } /** * Returns the list of cities for a country and state. @@ -126,20 +121,16 @@ abstract class Country { public function get_cities($state_code = '') { if (empty($state_code)) { - return array(); - - } // end if; + } $repository_file = wu_path("inc/country/{$this->country_code}/{$state_code}.php"); if (file_exists($repository_file) === false) { - return array(); + } - } // end if; - - $cities = include($repository_file); + $cities = include $repository_file; /** * Returns the list of cities for a state in a country. @@ -153,8 +144,7 @@ abstract class Country { * @return array The filtered list of states. */ return apply_filters('wu_country_get_cities', $cities, $this->country_code, $state_code, $this); - - } // end get_cities; + } /** * Get state cities as options. @@ -172,16 +162,13 @@ abstract class Country { $placeholder_option = array(); if ($placeholder !== false && $options) { - $placeholder_option[''] = $placeholder !== '' ? $placeholder : __('Select your city', 'wp-ultimo'); - - } // end if; + } $options = array_combine($options, $options); return array_merge($placeholder_option, $options); - - } // end get_cities_as_options; + } /** * Returns the list of states for a country. @@ -192,8 +179,7 @@ abstract class Country { protected function states() { return array(); - - } // end states; + } /** * Get the name of municipalities for a country/state. @@ -214,8 +200,7 @@ abstract class Country { $name = $ucwords ? ucwords($name) : $name; return apply_filters('wu_country_get_municipality_name', $name, $this->country_code, $state_code, $ucwords, $this); - - } // end get_municipality_name; + } /** * Get the name given to states for a country. @@ -263,7 +248,5 @@ abstract class Country { * @return string The modified division name. */ return apply_filters('wu_country_get_administrative_division_name', $name, $this->country_code, $state_code, $ucwords, $this); - - } // end get_administrative_division_name; - -} // end class Country; + } +} diff --git a/inc/database/broadcasts/class-broadcast-query.php b/inc/database/broadcasts/class-broadcast-query.php index 17d56cc..ea48f15 100644 --- a/inc/database/broadcasts/class-broadcast-query.php +++ b/inc/database/broadcasts/class-broadcast-query.php @@ -78,7 +78,5 @@ class Broadcast_Query extends Post_Query { $query['type__in'] = array('broadcast_email', 'broadcast_notice'); return parent::query($query); - - } // end query; - -} // end class Broadcast_Query; + } +} diff --git a/inc/database/checkout-forms/class-checkout-form-query.php b/inc/database/checkout-forms/class-checkout-form-query.php index 023d2c9..6355810 100644 --- a/inc/database/checkout-forms/class-checkout-form-query.php +++ b/inc/database/checkout-forms/class-checkout-form-query.php @@ -107,7 +107,5 @@ class Checkout_Form_Query extends Query { public function __construct($query = array()) { parent::__construct($query); - - } // end __construct; - -} // end class Checkout_Form_Query; + } +} diff --git a/inc/database/checkout-forms/class-checkout-forms-meta-table.php b/inc/database/checkout-forms/class-checkout-forms-meta-table.php index dcc0443..21e40ef 100644 --- a/inc/database/checkout-forms/class-checkout-forms-meta-table.php +++ b/inc/database/checkout-forms/class-checkout-forms-meta-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Checkout_Forms_Meta_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'formmeta'; /** @@ -55,8 +55,7 @@ final class Checkout_Forms_Meta_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -76,7 +75,5 @@ final class Checkout_Forms_Meta_Table extends Table { PRIMARY KEY (meta_id), KEY wu_form_id (wu_form_id), KEY meta_key (meta_key({$max_index_length}))"; - - } // end set_schema; - -} // end class Checkout_Forms_Meta_Table; + } +} diff --git a/inc/database/checkout-forms/class-checkout-forms-schema.php b/inc/database/checkout-forms/class-checkout-forms-schema.php index 856a6d4..a789c1f 100644 --- a/inc/database/checkout-forms/class-checkout-forms-schema.php +++ b/inc/database/checkout-forms/class-checkout-forms-schema.php @@ -110,5 +110,4 @@ class Checkout_Forms_Schema extends Schema { ), ); - -} // end class Checkout_Forms_Schema; +} diff --git a/inc/database/checkout-forms/class-checkout-forms-table.php b/inc/database/checkout-forms/class-checkout-forms-table.php index d25469d..0112763 100644 --- a/inc/database/checkout-forms/class-checkout-forms-table.php +++ b/inc/database/checkout-forms/class-checkout-forms-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Checkout_Forms_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'forms'; /** @@ -64,8 +64,7 @@ final class Checkout_Forms_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -86,8 +85,7 @@ final class Checkout_Forms_Table extends Table { date_created datetime DEFAULT NULL, date_modified datetime DEFAULT NULL, PRIMARY KEY (id)"; - - } // end set_schema; + } /** * Fixes the datetime columns to accept null. * @@ -101,21 +99,15 @@ final class Checkout_Forms_Table extends Table { ); foreach ($null_columns as $column) { - $query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;"; $result = $this->get_db()->query($query); - if (!$this->is_success($result)) { - + if ( ! $this->is_success($result)) { return false; - - } // end if; - - } // end foreach; + } + } return true; - - } // end __20230601; - -} // end class Checkout_Forms_Table; + } +} diff --git a/inc/database/customers/class-customer-query.php b/inc/database/customers/class-customer-query.php index 5f11d4e..fd68874 100644 --- a/inc/database/customers/class-customer-query.php +++ b/inc/database/customers/class-customer-query.php @@ -109,7 +109,5 @@ class Customer_Query extends Query { // $query['type'] = 'customer'; parent::__construct($query); - - } // end __construct; - -} // end class Customer_Query; + } +} diff --git a/inc/database/customers/class-customers-meta-table.php b/inc/database/customers/class-customers-meta-table.php index a52751a..08d1769 100644 --- a/inc/database/customers/class-customers-meta-table.php +++ b/inc/database/customers/class-customers-meta-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Customers_Meta_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'customermeta'; /** @@ -55,8 +55,7 @@ final class Customers_Meta_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -76,7 +75,5 @@ final class Customers_Meta_Table extends Table { PRIMARY KEY (meta_id), KEY wu_customer_id (wu_customer_id), KEY meta_key (meta_key({$max_index_length}))"; - - } // end set_schema; - -} // end class Customers_Meta_Table; + } +} diff --git a/inc/database/customers/class-customers-schema.php b/inc/database/customers/class-customers-schema.php index f20dda8..34b2295 100644 --- a/inc/database/customers/class-customers-schema.php +++ b/inc/database/customers/class-customers-schema.php @@ -129,5 +129,4 @@ class Customers_Schema extends Schema { ), ); - -} // end class Customers_Schema; +} diff --git a/inc/database/customers/class-customers-table.php b/inc/database/customers/class-customers-table.php index 70131ff..fc7a535 100644 --- a/inc/database/customers/class-customers-table.php +++ b/inc/database/customers/class-customers-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Customers_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'customers'; /** @@ -66,8 +66,7 @@ final class Customers_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -91,8 +90,7 @@ final class Customers_Table extends Table { signup_form varchar(40) DEFAULT 'by-admin', PRIMARY KEY (id), KEY user_id (user_id)"; - - } // end set_schema; + } /** * Adds the signup_form column. @@ -109,17 +107,14 @@ final class Customers_Table extends Table { // Maybe add column if (empty($result)) { - $query = "ALTER TABLE {$this->table_name} ADD COLUMN `signup_form` varchar(40) default 'by-admin' AFTER `ips`;"; $result = $this->get_db()->query($query); - - } // end if; + } // Return success/fail return $this->is_success($result); - - } // end __20210508; + } /** * Adds the signup_form column. @@ -133,27 +128,22 @@ final class Customers_Table extends Table { // Maybe add column if (empty($result)) { - $query_set = "SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';"; $result_set = $this->get_db()->query($query_set); if ($this->is_success($result_set) === false) { - return false; - - } // end if; + } $query = "ALTER TABLE {$this->table_name} ADD COLUMN `signup_form` varchar(40) default 'by-admin' AFTER `ips`;"; $result = $this->get_db()->query($query); - - } // end if; + } // Return success/fail return $this->is_success($result); - - } // end __20210607; + } /** * Fixes the datetime columns to accept null. @@ -169,21 +159,15 @@ final class Customers_Table extends Table { ); foreach ($null_columns as $column) { - $query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;"; $result = $this->get_db()->query($query); - if (!$this->is_success($result)) { - + if ( ! $this->is_success($result)) { return false; - - } // end if; - - } // end foreach; + } + } return true; - - } // end __20230601; - -} // end class Customers_Table; + } +} diff --git a/inc/database/discount-codes/class-discount-code-query.php b/inc/database/discount-codes/class-discount-code-query.php index b4716a0..4a5f938 100644 --- a/inc/database/discount-codes/class-discount-code-query.php +++ b/inc/database/discount-codes/class-discount-code-query.php @@ -107,7 +107,5 @@ class Discount_Code_Query extends Query { public function __construct($query = array()) { parent::__construct($query); - - } // end __construct; - -} // end class Discount_Code_Query; + } +} diff --git a/inc/database/discount-codes/class-discount-codes-meta-table.php b/inc/database/discount-codes/class-discount-codes-meta-table.php index 4590ad4..88a1635 100644 --- a/inc/database/discount-codes/class-discount-codes-meta-table.php +++ b/inc/database/discount-codes/class-discount-codes-meta-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Discount_Codes_Meta_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'discount_codemeta'; /** @@ -55,8 +55,7 @@ final class Discount_Codes_Meta_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -76,7 +75,5 @@ final class Discount_Codes_Meta_Table extends Table { PRIMARY KEY (meta_id), KEY wu_discount_code_id (wu_discount_code_id), KEY meta_key (meta_key({$max_index_length}))"; - - } // end set_schema; - -} // end class Discount_Codes_Meta_Table; + } +} diff --git a/inc/database/discount-codes/class-discount-codes-schema.php b/inc/database/discount-codes/class-discount-codes-schema.php index fc34093..6915726 100644 --- a/inc/database/discount-codes/class-discount-codes-schema.php +++ b/inc/database/discount-codes/class-discount-codes-schema.php @@ -172,5 +172,4 @@ class Discount_Codes_Schema extends Schema { ), ); - -} // end class Discount_Codes_Schema; +} diff --git a/inc/database/discount-codes/class-discount-codes-table.php b/inc/database/discount-codes/class-discount-codes-table.php index 1a6bcb9..1f532b9 100644 --- a/inc/database/discount-codes/class-discount-codes-table.php +++ b/inc/database/discount-codes/class-discount-codes-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Discount_Codes_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'discount_codes'; /** @@ -64,8 +64,7 @@ final class Discount_Codes_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -93,8 +92,7 @@ final class Discount_Codes_Table extends Table { date_created datetime NULL, date_modified datetime NULL, PRIMARY KEY (id)"; - - } // end set_schema; + } /** * Fixes the datetime columns to accept null. * @@ -108,21 +106,15 @@ final class Discount_Codes_Table extends Table { ); foreach ($null_columns as $column) { - $query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;"; $result = $this->get_db()->query($query); - if (!$this->is_success($result)) { - + if ( ! $this->is_success($result)) { return false; - - } // end if; - - } // end foreach; + } + } return true; - - } // end __20230601; - -} // end class Discount_Codes_Table; + } +} diff --git a/inc/database/domains/class-domain-query.php b/inc/database/domains/class-domain-query.php index 93e7d15..f74f1e6 100644 --- a/inc/database/domains/class-domain-query.php +++ b/inc/database/domains/class-domain-query.php @@ -107,7 +107,5 @@ class Domain_Query extends Query { public function __construct($query = array()) { parent::__construct($query); - - } // end __construct; - -} // end class Domain_Query; + } +} diff --git a/inc/database/domains/class-domain-stage.php b/inc/database/domains/class-domain-stage.php index fd2b50e..2b84b96 100644 --- a/inc/database/domains/class-domain-stage.php +++ b/inc/database/domains/class-domain-stage.php @@ -12,7 +12,7 @@ namespace WP_Ultimo\Database\Domains; // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Database\Engine\Enum; +use WP_Ultimo\Database\Engine\Enum; /** * Domain Stage. @@ -47,8 +47,7 @@ class Domain_Stage extends Enum { static::DONE => 'wu-bg-green-200 wu-text-green-700', static::DONE_WITHOUT_SSL => 'wu-bg-gray-800 wu-text-white', ); - - } // end classes; + } /** * Returns an array with values => labels. @@ -65,7 +64,5 @@ class Domain_Stage extends Enum { static::DONE => __('Ready', 'wp-ultimo'), static::DONE_WITHOUT_SSL => __('Ready (without SSL)', 'wp-ultimo'), ); - - } // end labels; - -} // end class Domain_Stage; + } +} diff --git a/inc/database/domains/class-domains-schema.php b/inc/database/domains/class-domains-schema.php index 5db966a..05be786 100644 --- a/inc/database/domains/class-domains-schema.php +++ b/inc/database/domains/class-domains-schema.php @@ -37,7 +37,7 @@ class Domains_Schema extends Schema { 'unsigned' => true, 'extra' => 'auto_increment', 'primary' => true, - 'sortable' => true + 'sortable' => true, ), array( @@ -117,5 +117,4 @@ class Domains_Schema extends Schema { ), ); - -} // end class Domains_Schema; +} diff --git a/inc/database/domains/class-domains-table.php b/inc/database/domains/class-domains-table.php index 5dbc6e3..fe441b3 100644 --- a/inc/database/domains/class-domains-table.php +++ b/inc/database/domains/class-domains-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Domains_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'domain_mappings'; /** @@ -64,8 +64,7 @@ final class Domains_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -88,8 +87,7 @@ final class Domains_Table extends Table { PRIMARY KEY (id), KEY blog_id (blog_id,domain,active), KEY domain (domain)"; - - } // end set_schema; + } /** * Fixes the datetime columns to accept null. * @@ -103,21 +101,15 @@ final class Domains_Table extends Table { ); foreach ($null_columns as $column) { - $query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;"; $result = $this->get_db()->query($query); - if (!$this->is_success($result)) { - + if ( ! $this->is_success($result)) { return false; - - } // end if; - - } // end foreach; + } + } return true; - - } // end __20230601; - -} // end class Domains_Table; + } +} diff --git a/inc/database/emails/class-email-query.php b/inc/database/emails/class-email-query.php index bdd9571..afa316e 100644 --- a/inc/database/emails/class-email-query.php +++ b/inc/database/emails/class-email-query.php @@ -78,7 +78,5 @@ class Email_Query extends Post_Query { $query['type__in'] = array('system_email'); return parent::query($query); - - } // end query; - -} // end class Email_Query; + } +} diff --git a/inc/database/engine/class-base.php b/inc/database/engine/class-base.php index 095672b..00c6b98 100644 --- a/inc/database/engine/class-base.php +++ b/inc/database/engine/class-base.php @@ -20,5 +20,4 @@ defined('ABSPATH') || exit; class Base extends \BerlinDB\Database\Base { protected $prefix = 'wu'; - -} // end class Base; +} diff --git a/inc/database/engine/class-column.php b/inc/database/engine/class-column.php index eed9744..051c619 100644 --- a/inc/database/engine/class-column.php +++ b/inc/database/engine/class-column.php @@ -20,5 +20,4 @@ defined('ABSPATH') || exit; class Column extends \BerlinDB\Database\Column { protected $prefix = 'wu'; - -} // end class Column; +} diff --git a/inc/database/engine/class-compare.php b/inc/database/engine/class-compare.php index 5cc8bc5..77b24ff 100644 --- a/inc/database/engine/class-compare.php +++ b/inc/database/engine/class-compare.php @@ -17,4 +17,4 @@ defined('ABSPATH') || exit; * * @since 1.0.0 */ -class Compare extends \BerlinDB\Database\Compare {} // end class Compare; +class Compare extends \BerlinDB\Database\Compare {} diff --git a/inc/database/engine/class-date.php b/inc/database/engine/class-date.php index 8d6d2e2..ed19021 100644 --- a/inc/database/engine/class-date.php +++ b/inc/database/engine/class-date.php @@ -17,4 +17,4 @@ defined('ABSPATH') || exit; * * @since 1.0.0 */ -class Date extends \BerlinDB\Database\Date {} // end class Date; +class Date extends \BerlinDB\Database\Date {} diff --git a/inc/database/engine/class-enum.php b/inc/database/engine/class-enum.php index 21e1c34..663ad54 100644 --- a/inc/database/engine/class-enum.php +++ b/inc/database/engine/class-enum.php @@ -17,265 +17,242 @@ defined('ABSPATH') || exit; * * @since 2.0.0 */ -abstract class Enum -{ - /** - * The default value. - */ - const __default = false; +abstract class Enum { + + /** + * The default value. + */ + const __default = false; // phpcs:ignore /** - * The options available. - * - * @since 2.0.0 - * @var array - */ - static $options = array(); - /** - * @var string - */ - private $value = ''; - /** - * Constructor method. Takes the value you want to set. - * - * @since 2.0.0 - * - * @param string $value The value to be set. - */ - public function __construct($value = '') - { - $this->value = $value; - } - // end __construct; - // Needs to be Implemented - /** - * Returns an array with values => CSS Classes. - * - * @since 2.0.0 - * @return array - */ - abstract protected function classes(); - /** - * Returns an array with values => labels. - * - * @since 2.0.0 - * @return void - */ - abstract protected function labels(); - /** - * Returns an array with values => labels. - * - * @since 2.0.0 - * @return void - */ - protected function icon_classes() { + * The options available. + * + * @since 2.0.0 + * @var array + */ + static $options = array(); + /** + * @var string + */ + private $value = ''; + /** + * Constructor method. Takes the value you want to set. + * + * @since 2.0.0 + * + * @param string $value The value to be set. + */ + public function __construct($value = '') { + $this->value = $value; + } - return array(); + // Needs to be Implemented + /** + * Returns an array with values => CSS Classes. + * + * @since 2.0.0 + * @return array + */ + abstract protected function classes(); + /** + * Returns an array with values => labels. + * + * @since 2.0.0 + * @return void + */ + abstract protected function labels(); + /** + * Returns an array with values => labels. + * + * @since 2.0.0 + * @return void + */ + protected function icon_classes() { - } - // end icon_classes; - /** - * Returns the options available as constants. - * - * @since 2.0.0 - * @return array - */ - public static function get_options() { + return array(); + } - $hook = static::get_hook_name(); + /** + * Returns the options available as constants. + * + * @since 2.0.0 + * @return array + */ + public static function get_options() { - if (!isset(static::$options[$hook])) { + $hook = static::get_hook_name(); - $reflector = new \ReflectionClass(static::class); + if ( ! isset(static::$options[ $hook ])) { + $reflector = new \ReflectionClass(static::class); - static::$options[$hook] = apply_filters("wu_available_{$hook}_options", $reflector->getConstants()); + static::$options[ $hook ] = apply_filters("wu_available_{$hook}_options", $reflector->getConstants()); + } - } // end if; + return static::$options[ $hook ]; + } - return static::$options[$hook]; + public static function get_allowed_list($string = false) { - } - // end get_options; - public static function get_allowed_list($string = false) { + $options = array_unique(self::get_options()); - $options = array_unique(self::get_options()); + return $string ? implode(',', $options) : $options; + } - return $string ? implode(',', $options) : $options; + /** + * Returns the value loaded here. + * + * This runs through is_valid and returns the + * default value if a invalid value is passed on. + * + * @since 2.0.0 + * @return string + */ + public function get_value() { - } - // end get_allowed_list; - /** - * Returns the value loaded here. - * - * This runs through is_valid and returns the - * default value if a invalid value is passed on. - * - * @since 2.0.0 - * @return string - */ - public function get_value() { + if ($this->is_valid($this->value)) { + return $this->value; + } - if ($this->is_valid($this->value)) { + return static::__default; + } - return $this->value; + /** + * Check for the the validity of the value passed. + * + * @since 2.0.0 + * + * @param string $value The string. + * @return boolean + */ + public function is_valid($value) { - } // end if; + $options = static::get_options(); - return static::__default; + return in_array($value, $options, true); + } - } - // end get_value; - /** - * Check for the the validity of the value passed. - * - * @since 2.0.0 - * - * @param string $value The string. - * @return boolean - */ - public function is_valid($value) { + /** + * Returns the label of a given value. + * + * @since 2.0.0 + * @return string + */ + public function get_label() { - $options = static::get_options(); + $hook = static::get_hook_name(); - return in_array($value, $options, true); + $labels = apply_filters("wu_available_{$hook}_labels", $this->labels()); - } - // end is_valid; - /** - * Returns the label of a given value. - * - * @since 2.0.0 - * @return string - */ - public function get_label() { + return $this->exists_or_default($labels, $this->get_value()); + } - $hook = static::get_hook_name(); + /** + * Returns the classes of a given value. + * + * @since 2.0.0 + * @return string + */ + public function get_classes() { - $labels = apply_filters("wu_available_{$hook}_labels", $this->labels()); + $hook = static::get_hook_name(); - return $this->exists_or_default($labels, $this->get_value()); + $classes = apply_filters("wu_available_{$hook}_classes", $this->classes()); - } - // end get_label; - /** - * Returns the classes of a given value. - * - * @since 2.0.0 - * @return string - */ - public function get_classes() { + return $this->exists_or_default($classes, $this->get_value()); + } - $hook = static::get_hook_name(); + /** + * Returns the classes of a given value. + * + * @since 2.0.0 + * @return string + */ + public function get_icon_classes() { - $classes = apply_filters("wu_available_{$hook}_classes", $this->classes()); + $hook = static::get_hook_name(); - return $this->exists_or_default($classes, $this->get_value()); + $classes = apply_filters("wu_available_{$hook}_icon_classes", $this->icon_classes()); - } - // end get_classes; - /** - * Returns the classes of a given value. - * - * @since 2.0.0 - * @return string - */ - public function get_icon_classes() { + return $this->exists_or_default($classes, $this->get_value()); + } - $hook = static::get_hook_name(); + /** + * Returns an array of options. + * + * @since 2.0.0 + * @return void + */ + public static function to_array() { - $classes = apply_filters("wu_available_{$hook}_icon_classes", $this->icon_classes()); + static $instance; - return $this->exists_or_default($classes, $this->get_value()); + if ($instance === null) { + $instance = new static(); + } - } - // end get_icon_classes; - /** - * Returns an array of options. - * - * @since 2.0.0 - * @return void - */ - public static function to_array() { + $hook = $instance::get_hook_name(); - static $instance; + $labels = apply_filters("wu_{$hook}_to_array", $instance->labels()); - if ($instance === null) { + return $labels; + } - $instance = new static; + /** + * Get the hook name for this class, so we can add filters. + * + * @since 2.0.0 + * @return string + */ + public static function get_hook_name() { - } // end if; + $class_name = (new \ReflectionClass(static::class))->getShortName(); - $hook = $instance::get_hook_name(); + return strtolower($class_name); + } - $labels = apply_filters("wu_{$hook}_to_array", $instance->labels()); + /** + * Checks if a key exists on an array, otherwise returns a default value. + * + * @since 2.0.0 + * + * @param array $array The array to check. + * @param string $key The key to check. + * @param string $default The default value. + * @return string + */ + public function exists_or_default($array, $key, $default = '') { - return $labels; + if (empty($default)) { + $default = isset($array[ static::__default ]) ? $array[ static::__default ] : ''; + } - } - // end to_array; - /** - * Get the hook name for this class, so we can add filters. - * - * @since 2.0.0 - * @return string - */ - public static function get_hook_name() { + return isset($array[ $key ]) ? $array[ $key ] : $default; + } - $class_name = (new \ReflectionClass(static::class))->getShortName(); + /** + * Converts this to string. + * + * @since 2.0.0 + * @return string + */ + public function __toString(): string { - return strtolower($class_name); + return $this->get_value(); + } - } - // end get_hook_name; - /** - * Checks if a key exists on an array, otherwise returns a default value. - * - * @since 2.0.0 - * - * @param array $array The array to check. - * @param string $key The key to check. - * @param string $default The default value. - * @return string - */ - public function exists_or_default($array, $key, $default = '') { + /** + * Magic method to allow for constants to be called. + * + * @since 2.0.0 + * + * @param string $name The name of the constants. + * @param array $arguments The list of arguments. Not really needed here. + * @return string + */ + public static function __callStatic($name, $arguments) { - if (empty($default)) { + $class_name = static::class; - $default = isset($array[static::__default]) ? $array[static::__default] : ''; - - } // end if; - - return isset($array[$key]) ? $array[$key] : $default; - - } - // end exists_or_default; - /** - * Converts this to string. - * - * @since 2.0.0 - * @return string - */ - public function __toString(): string { - - return $this->get_value(); - - } - // end __toString; - /** - * Magic method to allow for constants to be called. - * - * @since 2.0.0 - * - * @param string $name The name of the constants. - * @param array $arguments The list of arguments. Not really needed here. - * @return string - */ - public static function __callStatic($name, $arguments) { - - $class_name = static::class; - - return constant("$class_name::$name"); - - } - // end __callStatic; -} // end class Enum; + return constant("$class_name::$name"); + } +} diff --git a/inc/database/engine/class-meta.php b/inc/database/engine/class-meta.php index d071080..b2bc601 100644 --- a/inc/database/engine/class-meta.php +++ b/inc/database/engine/class-meta.php @@ -17,4 +17,4 @@ defined('ABSPATH') || exit; * * @since 1.0.0 */ -class Meta extends \BerlinDB\Database\Meta {} // end class Meta; +class Meta extends \BerlinDB\Database\Meta {} diff --git a/inc/database/engine/class-query.php b/inc/database/engine/class-query.php index 0b116e3..9f2cb4a 100644 --- a/inc/database/engine/class-query.php +++ b/inc/database/engine/class-query.php @@ -19,7 +19,7 @@ defined('ABSPATH') || exit; */ class Query extends \BerlinDB\Database\Query { - /** + /** * The prefix for the custom table. * * @since 2.0.0 @@ -73,17 +73,14 @@ class Query extends \BerlinDB\Database\Query { $cache_group = $this->apply_prefix($this->cache_group, '-'); - if ($this->global_cache && !in_array($cache_group, self::$added_globals, true)) { - + if ($this->global_cache && ! in_array($cache_group, self::$added_globals, true)) { wp_cache_add_global_groups(array($cache_group)); self::$added_globals[] = $cache_group; - - } // end if; + } parent::__construct($query); - - } // end __construct; + } /** * Get the plural name. @@ -94,7 +91,5 @@ class Query extends \BerlinDB\Database\Query { public function get_plural_name() { return $this->item_name_plural; - - } // end get_plural_name; - -} // end class Query; + } +} diff --git a/inc/database/engine/class-row.php b/inc/database/engine/class-row.php index a164e82..8dd7eb7 100644 --- a/inc/database/engine/class-row.php +++ b/inc/database/engine/class-row.php @@ -20,5 +20,4 @@ defined('ABSPATH') || exit; class Row extends \BerlinDB\Database\Row { protected $prefix = 'wu'; - -} // end class Row; +} diff --git a/inc/database/engine/class-schema.php b/inc/database/engine/class-schema.php index ad3d624..fda65dd 100644 --- a/inc/database/engine/class-schema.php +++ b/inc/database/engine/class-schema.php @@ -20,5 +20,4 @@ defined('ABSPATH') || exit; class Schema extends \BerlinDB\Database\Schema { protected $prefix = 'wu'; - -} // end class Schema; +} diff --git a/inc/database/engine/class-table.php b/inc/database/engine/class-table.php index a786381..5f0aa5f 100644 --- a/inc/database/engine/class-table.php +++ b/inc/database/engine/class-table.php @@ -47,21 +47,16 @@ abstract class Table extends \BerlinDB\Database\Table { */ public function is_upgradeable() { - if (!is_main_network()) { - + if ( ! is_main_network()) { return false; + } - } // end if; - - if (!is_main_site()) { - + if ( ! is_main_site()) { return false; - - } // end if; + } return true; - - } // end is_upgradeable; + } /** * Adds a caching layer to the parent exists method. @@ -72,13 +67,9 @@ abstract class Table extends \BerlinDB\Database\Table { public function exists() { if ($this->_exists === null) { - $this->_exists = parent::exists(); - - } // end if; + } return $this->_exists; - - } // end exists; - -} // end class Table; + } +} diff --git a/inc/database/events/class-event-query.php b/inc/database/events/class-event-query.php index e930d66..2b67f55 100644 --- a/inc/database/events/class-event-query.php +++ b/inc/database/events/class-event-query.php @@ -107,7 +107,5 @@ class Event_Query extends Query { public function __construct($query = array()) { parent::__construct($query); - - } // end __construct; - -} // end class Event_Query; + } +} diff --git a/inc/database/events/class-events-schema.php b/inc/database/events/class-events-schema.php index 4a3462b..b9680e3 100644 --- a/inc/database/events/class-events-schema.php +++ b/inc/database/events/class-events-schema.php @@ -104,5 +104,4 @@ class Events_Schema extends Schema { ), ); - -} // end class Events_Schema; +} diff --git a/inc/database/events/class-events-table.php b/inc/database/events/class-events-table.php index a6087d0..6d1d9ed 100644 --- a/inc/database/events/class-events-table.php +++ b/inc/database/events/class-events-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Events_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'events'; /** @@ -64,8 +64,7 @@ final class Events_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -89,8 +88,7 @@ final class Events_Table extends Table { KEY severity (severity), KEY author_id (author_id), KEY initiator (initiator)"; - - } // end set_schema; + } /** * Fixes the datetime columns to accept null. * @@ -103,21 +101,15 @@ final class Events_Table extends Table { ); foreach ($null_columns as $column) { - $query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;"; $result = $this->get_db()->query($query); - if (!$this->is_success($result)) { - + if ( ! $this->is_success($result)) { return false; - - } // end if; - - } // end foreach; + } + } return true; - - } // end __20230601; - -} // end class Events_Table; + } +} diff --git a/inc/database/memberships/class-membership-query.php b/inc/database/memberships/class-membership-query.php index fdf554a..4035294 100644 --- a/inc/database/memberships/class-membership-query.php +++ b/inc/database/memberships/class-membership-query.php @@ -107,7 +107,5 @@ class Membership_Query extends Query { public function __construct($query = array()) { parent::__construct($query); - - } // end __construct; - -} // end class Membership_Query; + } +} diff --git a/inc/database/memberships/class-membership-status.php b/inc/database/memberships/class-membership-status.php index e794601..92f3492 100644 --- a/inc/database/memberships/class-membership-status.php +++ b/inc/database/memberships/class-membership-status.php @@ -12,7 +12,7 @@ namespace WP_Ultimo\Database\Memberships; // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Database\Engine\Enum; +use WP_Ultimo\Database\Engine\Enum; /** * Membership Status. @@ -49,8 +49,7 @@ class Membership_Status extends Enum { static::EXPIRED => 'wu-bg-yellow-200 wu-text-yellow-700', static::CANCELLED => 'wu-bg-red-200 wu-text-red-700', ); - - } // end classes; + } /** * Returns an array with values => labels. @@ -68,7 +67,5 @@ class Membership_Status extends Enum { static::EXPIRED => __('Expired', 'wp-ultimo'), static::CANCELLED => __('Cancelled', 'wp-ultimo'), ); - - } // end labels; - -} // end class Membership_Status; + } +} diff --git a/inc/database/memberships/class-memberships-meta-table.php b/inc/database/memberships/class-memberships-meta-table.php index 6953a90..0a0cabc 100644 --- a/inc/database/memberships/class-memberships-meta-table.php +++ b/inc/database/memberships/class-memberships-meta-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Memberships_Meta_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'membershipmeta'; /** @@ -55,8 +55,7 @@ final class Memberships_Meta_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -76,7 +75,5 @@ final class Memberships_Meta_Table extends Table { PRIMARY KEY (meta_id), KEY wu_membership_id (wu_membership_id), KEY meta_key (meta_key({$max_index_length}))"; - - } // end set_schema; - -} // end class Memberships_Meta_Table; + } +} diff --git a/inc/database/memberships/class-memberships-schema.php b/inc/database/memberships/class-memberships-schema.php index ccca5b3..c9c985d 100644 --- a/inc/database/memberships/class-memberships-schema.php +++ b/inc/database/memberships/class-memberships-schema.php @@ -57,7 +57,7 @@ class Memberships_Schema extends Schema { 'length' => '20', 'unsigned' => true, 'default' => null, - 'allow_null' => true + 'allow_null' => true, ), array( @@ -76,7 +76,7 @@ class Memberships_Schema extends Schema { 'length' => '20', 'unsigned' => true, 'sortable' => true, - 'transition' => true + 'transition' => true, ), // addons @@ -91,7 +91,7 @@ class Memberships_Schema extends Schema { 'type' => 'varchar', 'length' => '20', 'default' => 'USD', - 'sortable' => true + 'sortable' => true, ), array( @@ -128,7 +128,7 @@ class Memberships_Schema extends Schema { 'unsigned' => true, 'default' => '0', 'sortable' => true, - 'transition' => true + 'transition' => true, ), array( @@ -224,7 +224,7 @@ class Memberships_Schema extends Schema { 'type' => 'smallint', 'unsigned' => true, 'default' => '0', - 'transition' => true + 'transition' => true, ), // times_billed @@ -234,7 +234,7 @@ class Memberships_Schema extends Schema { 'unsigned' => true, 'default' => '0', 'sortable' => true, - 'transition' => true + 'transition' => true, ), // billing_cycles @@ -243,7 +243,7 @@ class Memberships_Schema extends Schema { 'type' => 'smallint', 'unsigned' => true, 'default' => '0', - 'sortable' => true + 'sortable' => true, ), // status @@ -263,7 +263,7 @@ class Memberships_Schema extends Schema { 'default' => '', 'searchable' => true, 'sortable' => true, - 'transition' => true + 'transition' => true, ), // gateway_subscription_id @@ -273,7 +273,7 @@ class Memberships_Schema extends Schema { 'default' => '', 'searchable' => true, 'sortable' => true, - 'transition' => true + 'transition' => true, ), // gateway @@ -298,7 +298,7 @@ class Memberships_Schema extends Schema { 'length' => '32', 'default' => '', 'searchable' => true, - 'sortable' => true + 'sortable' => true, ), // upgraded_from @@ -307,7 +307,7 @@ class Memberships_Schema extends Schema { 'type' => 'bigint', 'length' => '20', 'unsigned' => true, - 'default' => '' + 'default' => '', ), // date_modified @@ -317,7 +317,7 @@ class Memberships_Schema extends Schema { 'default' => null, 'modified' => true, 'date_query' => true, - 'sortable' => true + 'sortable' => true, ), // disabled @@ -326,9 +326,8 @@ class Memberships_Schema extends Schema { 'type' => 'smallint', 'unsigned' => true, 'default' => '', - 'pattern' => '%d' + 'pattern' => '%d', ), ); - -} // end class Memberships_Schema; +} diff --git a/inc/database/memberships/class-memberships-table.php b/inc/database/memberships/class-memberships-table.php index d24010f..77447b6 100644 --- a/inc/database/memberships/class-memberships-table.php +++ b/inc/database/memberships/class-memberships-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Memberships_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'memberships'; /** @@ -64,8 +64,7 @@ final class Memberships_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema. @@ -112,8 +111,7 @@ final class Memberships_Table extends Table { KEY plan_id (plan_id), KEY status (status), KEY disabled (disabled)"; - - } // end set_schema; + } /** * Fixes the datetime columns to accept null. * @@ -133,21 +131,15 @@ final class Memberships_Table extends Table { ); foreach ($null_columns as $column) { - $query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;"; $result = $this->get_db()->query($query); - if (!$this->is_success($result)) { - + if ( ! $this->is_success($result)) { return false; - - } // end if; - - } // end foreach; + } + } return true; - - } // end __20230601; - -} // end class Memberships_Table; + } +} diff --git a/inc/database/payments/class-payment-query.php b/inc/database/payments/class-payment-query.php index af982cc..b058387 100644 --- a/inc/database/payments/class-payment-query.php +++ b/inc/database/payments/class-payment-query.php @@ -107,7 +107,5 @@ class Payment_Query extends Query { public function __construct($query = array()) { parent::__construct($query); - - } // end __construct; - -} // end class Payment_Query; + } +} diff --git a/inc/database/payments/class-payment-status.php b/inc/database/payments/class-payment-status.php index fe9db2c..7acbc14 100644 --- a/inc/database/payments/class-payment-status.php +++ b/inc/database/payments/class-payment-status.php @@ -12,7 +12,7 @@ namespace WP_Ultimo\Database\Payments; // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Database\Engine\Enum; +use WP_Ultimo\Database\Engine\Enum; /** * Payment Status. @@ -51,8 +51,7 @@ class Payment_Status extends Enum { static::FAILED => 'wu-bg-red-200 wu-text-red-700', static::CANCELLED => 'wu-bg-orange-200 wu-text-orange-700', ); - - } // end classes; + } /** * Returns an array with values => CSS Classes. @@ -71,8 +70,7 @@ class Payment_Status extends Enum { static::FAILED => 'wu-align-middle dashicons-wu-circle-with-cross wu-text-red-700', static::CANCELLED => 'wu-align-middle dashicons-wu-circle-with-cross wu-text-orange-700', ); - - } // end icon_classes; + } /** * Returns an array with values => labels. @@ -91,7 +89,5 @@ class Payment_Status extends Enum { static::FAILED => __('Failed', 'wp-ultimo'), static::CANCELLED => __('Cancelled', 'wp-ultimo'), ); - - } // end labels; - -} // end class Payment_Status; + } +} diff --git a/inc/database/payments/class-payments-meta-table.php b/inc/database/payments/class-payments-meta-table.php index f0b0c07..2f1c6eb 100644 --- a/inc/database/payments/class-payments-meta-table.php +++ b/inc/database/payments/class-payments-meta-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Payments_Meta_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'paymentmeta'; /** @@ -55,8 +55,7 @@ final class Payments_Meta_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -76,7 +75,5 @@ final class Payments_Meta_Table extends Table { PRIMARY KEY (meta_id), KEY wu_payment_id (wu_payment_id), KEY meta_key (meta_key({$max_index_length}))"; - - } // end set_schema; - -} // end class Payments_Meta_Table; + } +} diff --git a/inc/database/payments/class-payments-schema.php b/inc/database/payments/class-payments-schema.php index 91387af..eb47fe9 100644 --- a/inc/database/payments/class-payments-schema.php +++ b/inc/database/payments/class-payments-schema.php @@ -101,7 +101,7 @@ class Payments_Schema extends Schema { 'type' => 'varchar', 'length' => '20', 'default' => 'USD', - 'sortable' => true + 'sortable' => true, ), array( @@ -188,5 +188,4 @@ class Payments_Schema extends Schema { ), ); - -} // end class Payments_Schema; +} diff --git a/inc/database/payments/class-payments-table.php b/inc/database/payments/class-payments-table.php index 764a19b..50e8c76 100644 --- a/inc/database/payments/class-payments-table.php +++ b/inc/database/payments/class-payments-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Payments_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'payments'; /** @@ -66,8 +66,7 @@ final class Payments_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema. @@ -102,8 +101,7 @@ final class Payments_Table extends Table { KEY parent_id (parent_id), KEY product_id (product_id), KEY status (status)"; - - } // end set_schema; + } /** * Adds the refund_total column. @@ -120,17 +118,14 @@ final class Payments_Table extends Table { // Maybe add column if (empty($result)) { - $query = "ALTER TABLE {$this->table_name} ADD COLUMN `refund_total` decimal(13,4) default 0 AFTER `subtotal`;"; $result = $this->get_db()->query($query); - - } // end if; + } // Return success/fail return $this->is_success($result); - - } // end __20210417; + } /** * Adds the refund_total column. @@ -144,27 +139,22 @@ final class Payments_Table extends Table { // Maybe add column if (empty($result)) { - $query_set = "SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';"; $result_set = $this->get_db()->query($query_set); if ($this->is_success($result_set) === false) { - return false; - - } // end if; + } $query = "ALTER TABLE {$this->table_name} ADD COLUMN `refund_total` decimal(13,4) default 0 AFTER `subtotal`;"; $result = $this->get_db()->query($query); - - } // end if; + } // Return success/fail return $this->is_success($result); - - } // end __20210607; + } /** * Fixes the datetime columns to accept null. * @@ -178,21 +168,15 @@ final class Payments_Table extends Table { ); foreach ($null_columns as $column) { - $query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;"; $result = $this->get_db()->query($query); - if (!$this->is_success($result)) { - + if ( ! $this->is_success($result)) { return false; - - } // end if; - - } // end foreach; + } + } return true; - - } // end __20230601; - -} // end class Payments_Table; + } +} diff --git a/inc/database/posts/class-post-query.php b/inc/database/posts/class-post-query.php index 2dfef36..e2a057e 100644 --- a/inc/database/posts/class-post-query.php +++ b/inc/database/posts/class-post-query.php @@ -98,14 +98,10 @@ class Post_Query extends Query { */ public function query($query = array()) { - if (!isset($query['type__in'])) { - + if ( ! isset($query['type__in'])) { $query['type'] = $this->item_name; - - } // end if; + } return parent::query($query); - - } // end query; - -} // end class Post_Query; + } +} diff --git a/inc/database/posts/class-posts-meta-table.php b/inc/database/posts/class-posts-meta-table.php index 2a1adfa..8e65e6d 100644 --- a/inc/database/posts/class-posts-meta-table.php +++ b/inc/database/posts/class-posts-meta-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Posts_Meta_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'postmeta'; /** @@ -55,8 +55,7 @@ final class Posts_Meta_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -76,7 +75,5 @@ final class Posts_Meta_Table extends Table { PRIMARY KEY (meta_id), KEY wu_post_id (wu_post_id), KEY meta_key (meta_key({$max_index_length}))"; - - } // end set_schema; - -} // end class Posts_Meta_Table; + } +} diff --git a/inc/database/posts/class-posts-schema.php b/inc/database/posts/class-posts-schema.php index 6cb1002..e9ae0ca 100644 --- a/inc/database/posts/class-posts-schema.php +++ b/inc/database/posts/class-posts-schema.php @@ -37,7 +37,7 @@ class Posts_Schema extends Schema { 'unsigned' => true, 'extra' => 'auto_increment', 'primary' => true, - 'sortable' => true + 'sortable' => true, ), array( @@ -51,35 +51,35 @@ class Posts_Schema extends Schema { 'name' => 'type', 'type' => 'varchar', 'searchable' => true, - 'sortable' => true + 'sortable' => true, ), array( 'name' => 'slug', 'type' => 'varchar', 'searchable' => true, - 'sortable' => true + 'sortable' => true, ), array( 'name' => 'title', 'type' => 'varchar', 'searchable' => true, - 'sortable' => true + 'sortable' => true, ), array( 'name' => 'content', 'type' => 'longtext', 'default' => '', - 'searchable' => true + 'searchable' => true, ), array( 'name' => 'excerpt', 'type' => 'longtext', 'default' => '', - 'searchable' => true + 'searchable' => true, ), array( @@ -121,5 +121,4 @@ class Posts_Schema extends Schema { ), ); - -} // end class Posts_Schema; +} diff --git a/inc/database/posts/class-posts-table.php b/inc/database/posts/class-posts-table.php index d97d518..1aeff3c 100644 --- a/inc/database/posts/class-posts-table.php +++ b/inc/database/posts/class-posts-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Posts_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'posts'; /** @@ -64,8 +64,7 @@ final class Posts_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -88,8 +87,7 @@ final class Posts_Table extends Table { list_order tinyint default 10, status varchar(100) NOT NULL default 'draft', PRIMARY KEY (id)"; - - } // end set_schema; + } /** * Fixes the datetime columns to accept null. * @@ -103,21 +101,15 @@ final class Posts_Table extends Table { ); foreach ($null_columns as $column) { - $query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;"; $result = $this->get_db()->query($query); - if (!$this->is_success($result)) { - + if ( ! $this->is_success($result)) { return false; - - } // end if; - - } // end foreach; + } + } return true; - - } // end __20230601; - -} // end class Posts_Table; + } +} diff --git a/inc/database/products/class-product-query.php b/inc/database/products/class-product-query.php index 43c6bd4..af3da9b 100644 --- a/inc/database/products/class-product-query.php +++ b/inc/database/products/class-product-query.php @@ -107,7 +107,5 @@ class Product_Query extends Query { public function __construct($query = array()) { parent::__construct($query); - - } // end __construct; - -} // end class Product_Query; + } +} diff --git a/inc/database/products/class-product-type.php b/inc/database/products/class-product-type.php index 068bee9..079aacc 100644 --- a/inc/database/products/class-product-type.php +++ b/inc/database/products/class-product-type.php @@ -12,7 +12,7 @@ namespace WP_Ultimo\Database\Products; // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Database\Engine\Enum; +use WP_Ultimo\Database\Engine\Enum; /** * Product Types. @@ -43,8 +43,7 @@ class Product_Type extends Enum { static::PACKAGE => 'wu-bg-gray-200 wu-text-blue-700', static::SERVICE => 'wu-bg-yellow-200 wu-text-yellow-700', ); - - } // end classes; + } /** * Returns an array with values => labels. @@ -59,7 +58,5 @@ class Product_Type extends Enum { static::PACKAGE => __('Package', 'wp-ultimo'), static::SERVICE => __('Service', 'wp-ultimo'), ); - - } // end labels; - -} // end class Product_Type; + } +} diff --git a/inc/database/products/class-products-meta-table.php b/inc/database/products/class-products-meta-table.php index 89a473a..0a529ab 100644 --- a/inc/database/products/class-products-meta-table.php +++ b/inc/database/products/class-products-meta-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Products_Meta_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'productmeta'; /** @@ -55,8 +55,7 @@ final class Products_Meta_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -76,7 +75,5 @@ final class Products_Meta_Table extends Table { PRIMARY KEY (meta_id), KEY wu_product_id (wu_product_id), KEY meta_key (meta_key({$max_index_length}))"; - - } // end set_schema; - -} // end class Products_Meta_Table; + } +} diff --git a/inc/database/products/class-products-schema.php b/inc/database/products/class-products-schema.php index 3b887f7..9e062b0 100644 --- a/inc/database/products/class-products-schema.php +++ b/inc/database/products/class-products-schema.php @@ -37,7 +37,7 @@ class Products_Schema extends Schema { 'unsigned' => true, 'extra' => 'auto_increment', 'primary' => true, - 'sortable' => true + 'sortable' => true, ), array( @@ -70,14 +70,14 @@ class Products_Schema extends Schema { 'name' => 'name', 'type' => 'varchar', 'searchable' => true, - 'sortable' => true + 'sortable' => true, ), array( 'name' => 'description', 'type' => 'longtext', 'default' => '', - 'searchable' => true + 'searchable' => true, ), array( @@ -93,7 +93,7 @@ class Products_Schema extends Schema { 'type' => 'varchar', 'length' => '10', 'default' => 'USD', - 'sortable' => true + 'sortable' => true, ), array( @@ -101,7 +101,7 @@ class Products_Schema extends Schema { 'type' => 'varchar', 'length' => '10', 'default' => 'paid', - 'sortable' => true + 'sortable' => true, ), array( @@ -136,7 +136,7 @@ class Products_Schema extends Schema { 'unsigned' => true, 'default' => '0', 'sortable' => true, - 'transition' => true + 'transition' => true, ), array( @@ -151,7 +151,7 @@ class Products_Schema extends Schema { 'unsigned' => true, 'default' => '0', 'sortable' => true, - 'transition' => true + 'transition' => true, ), array( @@ -166,7 +166,7 @@ class Products_Schema extends Schema { 'unsigned' => true, 'default' => '0', 'sortable' => true, - 'transition' => true + 'transition' => true, ), array( @@ -213,9 +213,8 @@ class Products_Schema extends Schema { 'name' => 'type', 'type' => 'varchar', 'searchable' => true, - 'sortable' => true + 'sortable' => true, ), ); - -} // end class Products_Schema; +} diff --git a/inc/database/products/class-products-table.php b/inc/database/products/class-products-table.php index a5cd7d7..b310fc2 100644 --- a/inc/database/products/class-products-table.php +++ b/inc/database/products/class-products-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Products_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'products'; /** @@ -66,8 +66,7 @@ final class Products_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -101,8 +100,7 @@ final class Products_Table extends Table { date_created datetime NULL, date_modified datetime NULL, PRIMARY KEY (id)"; - - } // end set_schema; + } /** * Adds the product_group column. @@ -119,17 +117,14 @@ final class Products_Table extends Table { // Maybe add column if (empty($result)) { - $query = "ALTER TABLE {$this->table_name} ADD COLUMN `product_group` varchar(20) default '' AFTER `description`;"; $result = $this->get_db()->query($query); - - } // end if; + } // Return success/fail return $this->is_success($result); - - } // end __20210419; + } /** * Adds the product_group column. @@ -143,27 +138,22 @@ final class Products_Table extends Table { // Maybe add column if (empty($result)) { - $query_set = "SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';"; $result_set = $this->get_db()->query($query_set); if ($this->is_success($result_set) === false) { - return false; - - } // end if; + } $query = "ALTER TABLE {$this->table_name} ADD COLUMN `product_group` varchar(20) default '' AFTER `description`;"; $result = $this->get_db()->query($query); - - } // end if; + } // Return success/fail return $this->is_success($result); - - } // end __20210607; + } /** * Fixes the datetime columns to accept null. * @@ -177,21 +167,15 @@ final class Products_Table extends Table { ); foreach ($null_columns as $column) { - $query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;"; $result = $this->get_db()->query($query); - if (!$this->is_success($result)) { - + if ( ! $this->is_success($result)) { return false; - - } // end if; - - } // end foreach; + } + } return true; - - } // end __20230601; - -} // end class Products_Table; + } +} diff --git a/inc/database/sites/class-site-query.php b/inc/database/sites/class-site-query.php index c082ed1..746aff0 100644 --- a/inc/database/sites/class-site-query.php +++ b/inc/database/sites/class-site-query.php @@ -115,7 +115,5 @@ class Site_Query extends Query { public function __construct($query = array()) { parent::__construct($query); - - } // end __construct; - -} // end class Site_Query; + } +} diff --git a/inc/database/sites/class-site-type.php b/inc/database/sites/class-site-type.php index 3a7cbf2..c93bff7 100644 --- a/inc/database/sites/class-site-type.php +++ b/inc/database/sites/class-site-type.php @@ -12,7 +12,7 @@ namespace WP_Ultimo\Database\Sites; // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Database\Engine\Enum; +use WP_Ultimo\Database\Engine\Enum; /** * Site Types. @@ -49,8 +49,7 @@ class Site_Type extends Enum { static::EXTERNAL => 'wu-bg-blue-200 wu-text-blue-700', static::MAIN => 'wu-bg-pink-200 wu-text-pink-700', ); - - } // end classes; + } /** * Returns an array with values => labels. @@ -67,7 +66,5 @@ class Site_Type extends Enum { static::PENDING => __('Pending', 'wp-ultimo'), static::MAIN => __('Main Site', 'wp-ultimo'), ); - - } // end labels; - -} // end class Site_Type; + } +} diff --git a/inc/database/sites/class-sites-meta-table.php b/inc/database/sites/class-sites-meta-table.php index 06abf2e..49960ec 100644 --- a/inc/database/sites/class-sites-meta-table.php +++ b/inc/database/sites/class-sites-meta-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Sites_Meta_Table extends Table { /** - * Table prefix, including the site prefix. - * - * @since 1.0.0 - * @var string - */ + * Table prefix, including the site prefix. + * + * @since 1.0.0 + * @var string + */ protected $prefix = ''; /** @@ -63,8 +63,7 @@ final class Sites_Meta_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -76,7 +75,5 @@ final class Sites_Meta_Table extends Table { protected function set_schema() { $this->schema = false; - - } // end set_schema; - -} // end class Sites_Meta_Table; + } +} diff --git a/inc/database/sites/class-sites-schema.php b/inc/database/sites/class-sites-schema.php index 3c0bbb1..a89a4ed 100644 --- a/inc/database/sites/class-sites-schema.php +++ b/inc/database/sites/class-sites-schema.php @@ -62,14 +62,14 @@ class Sites_Schema extends Schema { 'name' => 'domain', 'type' => 'varchar', 'searchable' => true, - 'sortable' => true + 'sortable' => true, ), array( 'name' => 'path', 'type' => 'varchar', 'searchable' => true, - 'sortable' => true + 'sortable' => true, ), array( @@ -147,5 +147,4 @@ class Sites_Schema extends Schema { ), ); - -} // end class Sites_Schema; +} diff --git a/inc/database/sites/class-sites-table.php b/inc/database/sites/class-sites-table.php index ba5c781..fe39e11 100644 --- a/inc/database/sites/class-sites-table.php +++ b/inc/database/sites/class-sites-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Sites_Table extends Table { /** - * Table prefix, including the site prefix. - * - * @since 1.0.0 - * @var string - */ + * Table prefix, including the site prefix. + * + * @since 1.0.0 + * @var string + */ protected $prefix = ''; /** @@ -63,8 +63,7 @@ final class Sites_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -76,14 +75,12 @@ final class Sites_Table extends Table { protected function set_schema() { $this->schema = false; - - } // end set_schema; + } /** * Do nothing as this table already exists. * * @since 2.0.0 */ - public function install() {} // end install; - -} // end class Sites_Table; + public function install() {} +} diff --git a/inc/database/webhooks/class-webhook-query.php b/inc/database/webhooks/class-webhook-query.php index 78601b6..8983048 100644 --- a/inc/database/webhooks/class-webhook-query.php +++ b/inc/database/webhooks/class-webhook-query.php @@ -107,7 +107,5 @@ class Webhook_Query extends Query { public function __construct($query = array()) { parent::__construct($query); - - } // end __construct; - -} // end class Webhook_Query; + } +} diff --git a/inc/database/webhooks/class-webhooks-schema.php b/inc/database/webhooks/class-webhooks-schema.php index e7f345f..69bfe64 100644 --- a/inc/database/webhooks/class-webhooks-schema.php +++ b/inc/database/webhooks/class-webhooks-schema.php @@ -132,5 +132,4 @@ class Webhooks_Schema extends Schema { ), ); - -} // end class Webhooks_Schema; +} diff --git a/inc/database/webhooks/class-webhooks-table.php b/inc/database/webhooks/class-webhooks-table.php index 8b9464b..8a68090 100644 --- a/inc/database/webhooks/class-webhooks-table.php +++ b/inc/database/webhooks/class-webhooks-table.php @@ -22,11 +22,11 @@ defined('ABSPATH') || exit; final class Webhooks_Table extends Table { /** - * Table name - * - * @since 2.0.0 - * @var string - */ + * Table name + * + * @since 2.0.0 + * @var string + */ protected $name = 'webhooks'; /** @@ -64,8 +64,7 @@ final class Webhooks_Table extends Table { public function __construct() { parent::__construct(); - - } // end __construct; + } /** * Setup the database schema @@ -94,8 +93,7 @@ final class Webhooks_Table extends Table { KEY event (event)"; // phpcs:enable - - } // end set_schema; + } /** * Fixes the datetime columns to accept null. * @@ -109,21 +107,15 @@ final class Webhooks_Table extends Table { ); foreach ($null_columns as $column) { - $query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;"; $result = $this->get_db()->query($query); - if (!$this->is_success($result)) { - + if ( ! $this->is_success($result)) { return false; - - } // end if; - - } // end foreach; + } + } return true; - - } // end __20230601; - -} // end class Webhooks_Table; + } +} diff --git a/inc/debug/class-debug.php b/inc/debug/class-debug.php index 9d5c120..ba89738 100644 --- a/inc/debug/class-debug.php +++ b/inc/debug/class-debug.php @@ -9,7 +9,7 @@ namespace WP_Ultimo\Debug; -use \WP_Ultimo\Faker; +use WP_Ultimo\Faker; // Exit if accessed directly defined('ABSPATH') || exit; @@ -24,11 +24,11 @@ class Debug { use \WP_Ultimo\Traits\Singleton; /** - * The registry of WP Multisite WaaS admin pages. - * - * @since 2.0.0 - * @var array - */ + * The registry of WP Multisite WaaS admin pages. + * + * @since 2.0.0 + * @var array + */ private array $pages = array(); /** @@ -46,8 +46,7 @@ class Debug { add_action('wp_ultimo_debug', array($this, 'add_additional_hooks')); add_action('wp_ultimo_debug', array($this, 'register_forms')); - - } // end init; + } /** * Adds the additional debug links. @@ -58,8 +57,7 @@ class Debug { public function add_additional_hooks() { add_action('wu_header_left', array($this, 'add_debug_links')); - - } // end add_additional_hooks; + } // phpcs:disable @@ -109,7 +107,7 @@ class Debug { array($this, 'render_debug_generator_form'), - 'handler' => array($this, 'handle_debug_generator_form'), - )); + wu_register_form( + 'add_debug_generator_form', + array( + 'render' => array($this, 'render_debug_generator_form'), + 'handler' => array($this, 'handle_debug_generator_form'), + ) + ); /* * Adds Reset Form */ - wu_register_form('add_debug_reset_database_form', array( - 'render' => array($this, 'render_debug_reset_database_form'), - 'handler' => array($this, 'handle_debug_reset_database_form'), - )); + wu_register_form( + 'add_debug_reset_database_form', + array( + 'render' => array($this, 'render_debug_reset_database_form'), + 'handler' => array($this, 'handle_debug_reset_database_form'), + ) + ); /* * Adds Drop Form */ - wu_register_form('add_debug_drop_database_form', array( - 'render' => array($this, 'render_debug_drop_database_form'), - 'handler' => array($this, 'handle_debug_drop_database_form'), - )); - - } // end register_forms; + wu_register_form( + 'add_debug_drop_database_form', + array( + 'render' => array($this, 'render_debug_drop_database_form'), + 'handler' => array($this, 'handle_debug_drop_database_form'), + ) + ); + } /** * Adds the form to generate data. @@ -283,28 +289,33 @@ class Debug { ), ); - $form = new \WP_Ultimo\UI\Form('add_debug_generator_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' => 'debug_generator', - 'data-state' => json_encode(array( - 'customers' => false, - 'products' => false, - 'memberships' => false, - 'sites' => false, - 'domains' => false, - 'discount_codes' => false, - 'webhooks' => false, - 'payments' => false, - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'add_debug_generator_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' => 'debug_generator', + 'data-state' => json_encode( + array( + 'customers' => false, + 'products' => false, + 'memberships' => false, + 'sites' => false, + 'domains' => false, + 'discount_codes' => false, + 'webhooks' => false, + 'payments' => false, + ) + ), + ), + ) + ); $form->render(); - - } // end render_debug_generator_form; + } /** * Handles the checkout @@ -325,72 +336,50 @@ class Debug { $wpdb->query('START TRANSACTION'); try { - if (wu_request('customers')) { - $faker->generate_fake_customers(wu_request('customers_number', 0)); - - } // end if; + } if (wu_request('products')) { - $faker->generate_fake_products(wu_request('products_number', 0)); - - } // end if; + } if (wu_request('memberships')) { - $faker->generate_fake_memberships(wu_request('memberships_number', 0)); - - } // end if; + } if (wu_request('sites')) { - $faker->generate_fake_site(wu_request('sites_number', 0)); - - } // end if; + } if (wu_request('domains')) { - $faker->generate_fake_domain(wu_request('domains_number', 0)); - - } // end if; + } if (wu_request('discount_codes')) { - $faker->generate_fake_discount_code(wu_request('discount_codes_number', 0)); - - } // end if; + } if (wu_request('payments')) { - $faker->generate_fake_payment(wu_request('payments_number', 0)); - - } // end if; - + } } catch (\Throwable $e) { - $wpdb->query('ROLLBACK'); $error = new \WP_Error($e->getCode(), $e->getMessage()); wp_send_json_error($error); - - } // end try; + } $fake_data_generated = $faker->get_fake_data_generated(); $fake_ids_generated = array(); foreach ($fake_data_generated as $key => $model) { - foreach ($model as $object) { - - $fake_ids_generated[$key][] = $object->get_id(); - - } // end foreach; - - } // end foreach; + $fake_ids_generated[ $key ][] = $object->get_id(); + } + } $fake_ids_generated = array_merge_recursive($faker->get_option_debug_faker(), $fake_ids_generated); @@ -398,11 +387,12 @@ class Debug { $wpdb->query('COMMIT'); - wp_send_json_success(array( - 'redirect_url' => wu_network_admin_url('wp-ultimo'), - )); - - } // end handle_debug_generator_form; + wp_send_json_success( + array( + 'redirect_url' => wu_network_admin_url('wp-ultimo'), + ) + ); + } /** * Reset the database form. @@ -431,21 +421,26 @@ class Debug { ), ); - $form = new \WP_Ultimo\UI\Form('debug_reset_database_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' => 'debug_reset_database_form', - 'data-state' => json_encode(array( - 'reset_only' => true, - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'debug_reset_database_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' => 'debug_reset_database_form', + 'data-state' => json_encode( + array( + 'reset_only' => true, + ) + ), + ), + ) + ); $form->render(); - - } // end render_debug_reset_database_form; + } /** * Handles the database reset. @@ -460,36 +455,29 @@ class Debug { $wpdb->query('START TRANSACTION'); try { - if (wu_request('reset_only')) { - $this->reset_fake_data(); - } else { - $this->reset_all_data(); - - } // end if; - + } } catch (Exception $e) { - $wpdb->query('ROLLBACK'); $error = new \WP_Error($e->getCode(), $e->getMessage()); wp_send_json_error($error); - - } // end try; + } $wpdb->query('COMMIT'); wu_delete_option('debug_faker'); - wp_send_json_success(array( - 'redirect_url' => wu_network_admin_url('wp-ultimo-setup'), - )); - - } // end handle_debug_reset_database_form; + wp_send_json_success( + array( + 'redirect_url' => wu_network_admin_url('wp-ultimo-setup'), + ) + ); + } /** * Reset the database form. @@ -513,21 +501,26 @@ class Debug { ), ); - $form = new \WP_Ultimo\UI\Form('debug_drop_database_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' => 'debug_drop_database_form', - 'data-state' => json_encode(array( - 'reset_only' => true, - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'debug_drop_database_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' => 'debug_drop_database_form', + 'data-state' => json_encode( + array( + 'reset_only' => true, + ) + ), + ), + ) + ); $form->render(); - - } // end render_debug_drop_database_form; + } /** * Handles the database reset. @@ -540,28 +533,23 @@ class Debug { global $wpdb; try { - wu_drop_tables(); - } catch (\Throwable $e) { - $error = new \WP_Error($e->getCode(), $e->getMessage()); wp_send_json_error($error); - } catch (\Exception $e) { - $error = new \WP_Error($e->getCode(), $e->getMessage()); wp_send_json_error($error); + } - } // end try; - - wp_send_json_success(array( - 'redirect_url' => wu_network_admin_url('wp-ultimo-setup&step=installation'), - )); - - } // end handle_debug_drop_database_form; + wp_send_json_success( + array( + 'redirect_url' => wu_network_admin_url('wp-ultimo-setup&step=installation'), + ) + ); + } /** * Checks if we need to add the menu or not. @@ -575,8 +563,7 @@ class Debug { public function should_load() { return defined('WP_ULTIMO_DEBUG') && WP_ULTIMO_DEBUG; - - } // end should_load; + } /** * Loads the debug pages and functions if we should. @@ -587,20 +574,19 @@ class Debug { public function load() { if ($this->should_load()) { - add_action('wu_page_added', array($this, 'add_page')); add_filter('wu_tour_finished', '__return_false'); - add_action('plugins_loaded', function() { + add_action( + 'plugins_loaded', + function () { - do_action('wp_ultimo_debug'); - - }); - - } // end if; - - } // end load; + do_action('wp_ultimo_debug'); + } + ); + } + } /** * Add a WP Multisite WaaS page to the registry. @@ -612,9 +598,8 @@ class Debug { */ public function add_page($page_id) { - $this->pages[$page_id] = wu_network_admin_url($page_id); - - } // end add_page; + $this->pages[ $page_id ] = wu_network_admin_url($page_id); + } /** * Returns the pages registred. @@ -625,8 +610,7 @@ class Debug { public function get_pages() { return $this->pages; - - } // end get_pages; + } /** * Adds the debug menu pages. @@ -636,9 +620,8 @@ class Debug { */ public function add_main_debug_menu() { - new \WP_Ultimo\Admin_Pages\Debug\Debug_Admin_Page; - - } // end add_main_debug_menu; + new \WP_Ultimo\Admin_Pages\Debug\Debug_Admin_Page(); + } /** * Reset fake data. @@ -677,8 +660,7 @@ class Debug { $payments_id = wu_get_isset($fake_data_generated, 'payments'); $this->reset_payments($payments_id); - - } // end reset_fake_data; + } /** * Reset all data. @@ -709,8 +691,7 @@ class Debug { $this->reset_events(); $this->reset_settings(); - - } // end reset_all_data; + } /** * Reset table. @@ -726,10 +707,8 @@ class Debug { global $wpdb; - if (!empty($table)) { - - if (!empty($ids)) { - + if ( ! empty($table)) { + if ( ! empty($ids)) { $ids = array_filter($ids); $id_placeholders = implode(', ', array_fill(0, count($ids), '%d')); @@ -737,24 +716,17 @@ class Debug { $result = $wpdb->query( $wpdb->prepare("DELETE FROM $table WHERE $field IN ($id_placeholders)", $ids) // phpcs:ignore ); - } else { - $result = $wpdb->query( "DELETE FROM $table" // phpcs:ignore ); - - } // end if; + } if ($result === false) { - throw new \Exception("Error $table"); - - } // end if; - - } // end if; - - } // end reset_table; + } + } + } /** * Reset customers and customermeta table. @@ -771,33 +743,24 @@ class Debug { $customer_meta_table = "{$wpdb->base_prefix}wu_customermeta"; - if (!empty($ids)) { - + if ( ! empty($ids)) { foreach ($ids as $id) { - $customer = wu_get_customer($id); if ($customer) { - $deleted = wpmu_delete_user($customer->get_user_id()); - if (!$deleted) { - + if ( ! $deleted) { throw new \Exception('Error customer delete'); - - } // end if; - - } // end if; - - } // end foreach; - - } // end if; + } + } + } + } $this->reset_table($customers_table, $ids); $this->reset_table($customer_meta_table, $ids, 'wu_customer_id'); - - } // end reset_customers; + } /** * Reset customers and customermeta table. @@ -809,23 +772,16 @@ class Debug { */ private function reset_sites($ids = array()) { - if (!empty($ids)) { - + if ( ! empty($ids)) { foreach ($ids as $id) { - $site = wu_get_site($id); if ($site) { - wpmu_delete_blog($site->get_id(), true); - - } // end if; - - } // end foreach; - - } // end if; - - } // end reset_sites; + } + } + } + } /** * Reset products and productmeta table. @@ -845,8 +801,7 @@ class Debug { $this->reset_table($products_table, $ids); $this->reset_table($product_meta_table, $ids, 'wu_product_id'); - - } // end reset_products; + } /** * Reset memberships and membershipmeta table. @@ -866,8 +821,7 @@ class Debug { $this->reset_table($memberships_table, $ids); $this->reset_table($membership_meta_table, $ids, 'wu_membership_id'); - - } // end reset_memberships; + } /** * Reset domains table. @@ -883,8 +837,7 @@ class Debug { $domain_table = "{$wpdb->base_prefix}wu_domain_mappings"; $this->reset_table($domain_table, $ids); - - } // end reset_domains; + } /** * Reset discount codes table. @@ -900,8 +853,7 @@ class Debug { $discount_codes_table = "{$wpdb->base_prefix}wu_discount_codes"; $this->reset_table($discount_codes_table, $ids); - - } // end reset_discount_codes; + } /** * Reset webhooks table. @@ -917,8 +869,7 @@ class Debug { $webhooks_table = "{$wpdb->base_prefix}wu_webhooks"; $this->reset_table($webhooks_table, $ids); - - } // end reset_webhooks; + } /** * Reset payments table. @@ -934,8 +885,7 @@ class Debug { $payments_table = "{$wpdb->base_prefix}wu_payments"; $this->reset_table($payments_table, $ids); - - } // end reset_payments; + } /** * Reset checkout forms @@ -955,8 +905,7 @@ class Debug { $this->reset_table($forms_table, $ids); $this->reset_table($form_meta_table, $ids, 'wu_form_id'); - - } // end reset_checkout_forms; + } /** * Reset custom posts. @@ -976,8 +925,7 @@ class Debug { $this->reset_table($posts_table, $ids); $this->reset_table($post_meta_table, $ids, 'wu_post_id'); - - } // end reset_post_like_models; + } /** * Reset events. @@ -993,8 +941,7 @@ class Debug { $events_table = "{$wpdb->base_prefix}wu_events"; $this->reset_table($events_table, $ids); - - } // end reset_events; + } /** * Reset the settings. @@ -1026,13 +973,9 @@ class Debug { ); foreach ($options as $option_name => $should_use_prefix) { - $prefix = $should_use_prefix ? $the_prefix : ''; delete_network_option(null, $prefix . $option_name); - - } // end foreach; - - } // end reset_settings; - -} // end class Debug; + } + } +} diff --git a/inc/deprecated/deprecated.php b/inc/deprecated/deprecated.php index 12997bb..bea5499 100644 --- a/inc/deprecated/deprecated.php +++ b/inc/deprecated/deprecated.php @@ -34,8 +34,7 @@ class WU_Settings { _deprecated_function(__METHOD__, '2.0.0', 'WP_Ultimo()->settings->get_sections()'); return WP_Ultimo()->settings->get_sections(); - - } // end get_sections; + } /** * Deprecated: Get all the settings from the plugin. @@ -49,8 +48,7 @@ class WU_Settings { _deprecated_function(__METHOD__, '2.0.0', 'wu_get_all_settings()'); return wu_get_all_settings(); - - } // end get_settings; + } /** * Deprecated: Handles the saving of the settings after the save button is pressed. @@ -66,8 +64,7 @@ class WU_Settings { _deprecated_function(__METHOD__, '2.0.0', 'WP_Ultimo()->settings->save_settings()'); return WP_Ultimo()->settings->save_settings(array(), $reset); - - } // end save_settings; + } /** * Deprecated: Get a specific settings from the plugin. @@ -85,8 +82,7 @@ class WU_Settings { _deprecated_function(__METHOD__, '2.0.0', 'wu_get_setting()'); return wu_get_setting($setting, $default); - - } // end get_setting; + } /** * Deprecated: Saves a specific setting into the database. @@ -100,8 +96,7 @@ class WU_Settings { _deprecated_function(__METHOD__, '2.0.0', 'wu_save_setting()'); return wu_save_setting($setting, $value); - - } // end save_setting; + } /** * Deprecated: Returns the image being used as a logo. @@ -121,8 +116,7 @@ class WU_Settings { _deprecated_function(__METHOD__, '2.0.0', 'wu_get_network_logo()'); return wu_get_network_logo($size); - - } // end get_logo; + } /** * Deprecated: Return the countries list. @@ -135,10 +129,8 @@ class WU_Settings { _deprecated_function(__METHOD__, '2.0.0', 'wu_get_countries()'); return wu_get_countries(); - - } // end get_countries; - -} // end class WU_Settings; + } +} /** * Deprecated: WU_Page @@ -168,18 +160,21 @@ class WU_Page extends \WP_Ultimo\Admin_Pages\Base_Admin_Page { _deprecated_function(__METHOD__, '2.0.0', 'wu_send_mail()'); - $this->attributes = wp_parse_args($atts, array( - 'badge_count' => 0, - 'position' => 10, - 'submenu_title' => false, - 'id' => 'wp-ultimo-page', - 'type' => 'menu', - 'parent' => 'wp-ultimo', - 'capability' => 'manage_network', - 'menu_icon' => 'dashicons-menu', - 'title' => __('Admin Page', 'wp-ultimo'), - 'menu_title' => __('Admin Page', 'wp-ultimo'), - )); + $this->attributes = wp_parse_args( + $atts, + array( + 'badge_count' => 0, + 'position' => 10, + 'submenu_title' => false, + 'id' => 'wp-ultimo-page', + 'type' => 'menu', + 'parent' => 'wp-ultimo', + 'capability' => 'manage_network', + 'menu_icon' => 'dashicons-menu', + 'title' => __('Admin Page', 'wp-ultimo'), + 'menu_title' => __('Admin Page', 'wp-ultimo'), + ) + ); /* * Sets the defaults. @@ -192,8 +187,7 @@ class WU_Page extends \WP_Ultimo\Admin_Pages\Base_Admin_Page { $this->id = $this->attributes['id'] . '-one'; parent::__construct(); - - } // end __construct; + } /** * Returns the title of the page. Must be declared on the child classes. @@ -204,8 +198,7 @@ class WU_Page extends \WP_Ultimo\Admin_Pages\Base_Admin_Page { public function get_title() { return $this->attributes['title']; - - } // end get_title; + } /** * Returns the title of menu for this page. Must be declared on the child classes. @@ -216,8 +209,7 @@ class WU_Page extends \WP_Ultimo\Admin_Pages\Base_Admin_Page { public function get_menu_title() { return $this->attributes['menu_title']; - - } // end get_menu_title; + } /** * Every child class should implement the output method to display the contents of the page. @@ -225,9 +217,8 @@ class WU_Page extends \WP_Ultimo\Admin_Pages\Base_Admin_Page { * @since 1.8.2 * @return void */ - public function output() {} // end output; - -} // end class WU_Page; + public function output() {} +} /** * Deprecated: WU_Site_Templates @@ -249,10 +240,8 @@ class WU_Site_Templates { _deprecated_function(__METHOD__, '2.0.0', 'WP_Ultimo\UI\Template_Previewer::get_instance()->get_preview_url()'); return \WP_Ultimo\UI\Template_Previewer::get_instance()->get_preview_url($site_id); - - } // end get_template_preview_url; - -} // end class WU_Site_Templates; + } +} /** * Deprecated: WU_Mail @@ -297,12 +286,11 @@ class WU_Mail { 'site_url' => get_site_url(wu_get_main_site_id()), 'attachments' => $attachments, 'type' => $html ? 'html' : 'plain', - 'bcc' => $bcc + 'bcc' => $bcc, ); return wu_send_mail($from, $to, $args); - - } // end send_mail; + } /** * Deprecated: Send an email template registered in our framework. @@ -318,8 +306,7 @@ class WU_Mail { public function send_template($slug, $to, $shortcodes, $attachments = array()) { _deprecated_function(__METHOD__, '2.0.0'); - - } // end send_template; + } /** * Deprecated: Register template of a certain email. @@ -333,10 +320,8 @@ class WU_Mail { public function register_template($slug, $args) { _deprecated_function(__METHOD__, '2.0.0'); - - } // end register_template; - -} // end class WU_Mail; + } +} /** * Deprecated: Returns the WU_Mail instance. @@ -350,8 +335,7 @@ function WU_Mail() { // phpcs:ignore _deprecated_function(__METHOD__, '2.0.0'); return WU_Mail::get_instance(); - -} // end WU_Mail; +} /** * Deprecated: WU_Plans class. @@ -368,9 +352,8 @@ class WU_Plans { */ public static function get_instance() { - return new self; - - } // end get_instance; + return new self(); + } /** * Deprecated: WP_Plans::get_plans(). @@ -385,8 +368,7 @@ class WU_Plans { $plans = wu_get_plans(); return $plans; - - } // end get_plans; + } /** * Deprecated: WU_Plans::get_most_popular_plan() @@ -404,10 +386,8 @@ class WU_Plans { $plans = wu_get_plans(); return $plans ? $plans[0] : false; - - } // end get_most_popular_plan; - -} // end class WU_Plans; + } +} /** * Deprecated: WU_Multi_Network @@ -436,10 +416,8 @@ class WU_Multi_Network { _deprecated_function(__CLASS__ . "::$method_name()", '2.0.0'); return false; - - } // end __callStatic; - -} // end class WU_Multi_Network; + } +} /** * Deprecated: WU_Help_Pointers @@ -462,10 +440,8 @@ class WU_Help_Pointers { public function __construct($pntrs = array()) { _deprecated_function(__CLASS__, '2.0.0'); - - } // end __construct; - -} // end class WU_Help_Pointers; + } +} /** * Deprecated: WU_Util @@ -478,17 +454,16 @@ class WU_Help_Pointers { class WU_Util { /** - * Deprecated: is_login_page() - * - * @deprecated 2.0.0 - */ + * Deprecated: is_login_page() + * + * @deprecated 2.0.0 + */ public static function is_login_page(): bool { _deprecated_function(__METHOD__, '2.0.0'); return false; - - } // end is_login_page; + } /** * Deprecated: format_megabytes @@ -504,8 +479,7 @@ class WU_Util { _deprecated_function(__METHOD__, '2.0.0', 'size_format()'); return size_format($size * MB_IN_BYTES); - - } // end format_megabytes; + } /** * Deprecated: to_float @@ -520,8 +494,7 @@ class WU_Util { _deprecated_function(__METHOD__, '2.0.0', 'wu_to_float()'); return wu_to_float($num); - - } // end to_float; + } /** * Deprecated: tooltip @@ -537,8 +510,7 @@ class WU_Util { _deprecated_function(__METHOD__, '2.0.0', 'wu_tooltip()'); return wu_tooltip($text, $icon); - - } // end tooltip; + } /** * Deprecated: wp_die @@ -557,8 +529,7 @@ class WU_Util { _deprecated_function(__METHOD__, '2.0.0', 'wp_die()'); wp_die($message, $title, $args); - - } // end wp_die; + } /** * Deprecated: display_alert @@ -574,8 +545,7 @@ class WU_Util { public static function display_alert($title, $message, $type = 'success', $arguments = false) { _deprecated_function(__METHOD__, '2.0.0'); - - } // end display_alert; + } /** * Deprecated: registers_today @@ -587,18 +557,19 @@ class WU_Util { _deprecated_function(__METHOD__, '2.0.0', 'wu_get_customers() w/ count = true'); - $signups = wu_get_customers(array( - 'count' => true, - 'date_query' => array( - 'column' => 'date_registered', - 'after' => 'today', - 'inclusive' => true, - ), - )); + $signups = wu_get_customers( + array( + 'count' => true, + 'date_query' => array( + 'column' => 'date_registered', + 'after' => 'today', + 'inclusive' => true, + ), + ) + ); return $signups; - - } // end registers_today; + } /** * Deprecated: users_on_trial * @@ -609,8 +580,7 @@ class WU_Util { _deprecated_function(__METHOD__, '1.5.3'); return 0; - - } // end users_on_trial; + } /** * Deprecated: array_filter_key @@ -629,8 +599,7 @@ class WU_Util { _deprecated_function(__METHOD__, '2.0.0'); return $array; - - } // end array_filter_key; + } /** * Deprecated: generate_csv @@ -646,8 +615,7 @@ class WU_Util { _deprecated_function(__METHOD__, '2.0.0', 'wu_generate_csv()'); wu_generate_csv($file_name, $data); - - } // end generate_csv; + } /** * Deprecated: color @@ -662,10 +630,8 @@ class WU_Util { _deprecated_function(__METHOD__, '2.0.0', 'wu_color()'); return wu_color($hex); - - } // end color; - -} // end class WU_Util; + } +} /** * Deprecated: WU_Logger @@ -691,22 +657,16 @@ class WU_Logger { $alternative = "\\WP_Ultimo\\Logger::$method_name"; if ($method_name === 'add') { - $alternative = 'wu_log_add'; - } elseif ($method_name === 'clear') { - $alternative = 'wu_log_clear'; - - } // end if; + } _deprecated_function(__CLASS__ . "::$method_name()", '2.0.0', "$alternative()"); return call_user_func_array($alternative, $args); - - } // end __callStatic; - -} // end class WU_Logger; + } +} /** * Deprecated: WU_Links @@ -730,10 +690,8 @@ class WU_Links { _deprecated_function(__METHOD__, '2.0.0', 'wu_get_documentation_url()'); return wu_get_documentation_url($slug); - - } // end get_link; - -} // end class WU_Links; + } +} /* * Models @@ -758,22 +716,16 @@ class WU_Site extends \WP_Ultimo\Models\Site { _deprecated_function(__CLASS__, '2.0.0', '\WP_Ultimo\Models\Site'); if (is_numeric($object)) { - $object = wu_get_site($object); - - } // end if; + } if ($object) { - $object = get_object_vars($object); - - } // end if; + } parent::__construct($object); - - } // end __construct; - -} // end class WU_Site; + } +} /** * Deprecated: WU_Site_Template @@ -794,22 +746,16 @@ class WU_Site_Template extends \WP_Ultimo\Models\Site { _deprecated_function(__CLASS__, '2.0.0', '\WP_Ultimo\Models\Site'); if (is_numeric($object)) { - $object = wu_get_site($object); - - } // end if; + } if ($object) { - $object = get_object_vars($object); - - } // end if; + } parent::__construct($object); - - } // end __construct; - -} // end class WU_Site_Template; + } +} /** * Deprecated: WU_Site_Template @@ -826,10 +772,8 @@ class WU_Site_Owner { public function __construct() { _deprecated_function(__CLASS__, '2.0.0'); - - } // end __construct; - -} // end class WU_Site_Owner; + } +} /** * Deprecated Trait. @@ -849,16 +793,13 @@ trait WU_Deprecated_Model { public function __set($key, $value) { if (method_exists($this, "set_$key")) { - call_user_func(array($this, "set_$key"), $value); - - } // end if; + } $this->{$key} = $value; $this->after_set($key, $value); - - } // end __set; + } /** * Generic get method to bypass the protected status of the new models. @@ -870,14 +811,11 @@ trait WU_Deprecated_Model { public function __get($key) { if (method_exists($this, "get_$key")) { - return call_user_func(array($this, "get_$key")); - - } // end if; + } return false; - - } // end __get; + } /** * Generic method to bypass the protected status of the new models. @@ -887,9 +825,8 @@ trait WU_Deprecated_Model { * @param string $key The key to set. * @param mixed $value The value to set. */ - public function after_set($key, $value) {} // end after_set; - -} // end trait WU_Deprecated_Model; + public function after_set($key, $value) {} +} /** * Deprecated: WU_Coupon @@ -912,28 +849,19 @@ class WU_Coupon extends \WP_Ultimo\Models\Discount_Code { _deprecated_function(__CLASS__, '2.0.0', '\WP_Ultimo\Models\Discount_Code'); if (is_numeric($object)) { - $object = wu_get_discount_code($object); - - } // end if; - - if ($object) { - - $object = get_object_vars($object); - - } // end if; - - if (is_array($object)) { - - foreach ($object as $att => $value) { - - $this->{$att} = $value; - - } // end foreach; - } - } // end __construct; + if ($object) { + $object = get_object_vars($object); + } + + if (is_array($object)) { + foreach ($object as $att => $value) { + $this->{$att} = $value; + } + } + } /** * Generic method to bypass the protected status of the new models. @@ -946,18 +874,14 @@ class WU_Coupon extends \WP_Ultimo\Models\Discount_Code { public function after_set($key, $value) { if ($key === 'title') { - $this->set_code($value); $this->set_name($value); $this->set_description($value); - - } // end if; - - } // end after_set; - -} // end class WU_Coupon; + } + } +} /** * Deprecated: WU_Plan @@ -980,32 +904,23 @@ class WU_Plan extends \WP_Ultimo\Models\Product { _deprecated_function(__CLASS__, '2.0.0', '\WP_Ultimo\Models\Product'); if (is_numeric($object)) { - $object = wu_get_product($object); - - } // end if; + } if ($object) { - $object = get_object_vars($object); - - } // end if; + } if (is_array($object)) { - foreach ($object as $att => $value) { - $this->{$att} = $value; - - } // end foreach; - - } // end if; + } + } $this->set_slug(uniqid()); parent::__construct($object); - - } // end __construct; + } /** * Generic get method to bypass the protected status of the new models. @@ -1017,20 +932,15 @@ class WU_Plan extends \WP_Ultimo\Models\Product { public function __get($key) { if ($key === 'price_1') { - return $this->get_amount(); - - } // end if; + } if (method_exists($this, "get_$key")) { - return call_user_func(array($this, "get_$key")); - - } // end if; + } return $this->get_meta('wpu_' . $key, false); - - } // end __get; + } /** * Generic method to bypass the protected status of the new models. @@ -1043,14 +953,10 @@ class WU_Plan extends \WP_Ultimo\Models\Product { public function after_set($key, $value) { if ($key === 'price_1') { - $this->set_amount($value); - - } // end if; - - } // end after_set; - -} // end class WU_Plan; + } + } +} /** * Deprecated: WU_Subscription @@ -1073,20 +979,15 @@ class WU_Subscription extends \WP_Ultimo\Models\Membership { _deprecated_function(__CLASS__, '2.0.0', '\WP_Ultimo\Models\Membership'); if (is_numeric($object)) { - $object = wu_get_membership($object); - - } // end if; + } if ($object) { - $object = get_object_vars($object); - - } // end if; + } parent::__construct($object); - - } // end __construct; + } /** * Generic method to bypass the protected status of the new models. @@ -1096,7 +997,7 @@ class WU_Subscription extends \WP_Ultimo\Models\Membership { * @param string $key The key to set. * @param mixed $value The value to set. */ - public function after_set($key, $value) {} // end after_set; + public function after_set($key, $value) {} /** * Deprecated: Add a valid coupon code to the subscription. @@ -1107,8 +1008,7 @@ class WU_Subscription extends \WP_Ultimo\Models\Membership { public function apply_coupon_code($coupon_code = null) { _deprecated_function(__METHOD__, '2.0.0'); - - } // end apply_coupon_code; + } /** * Deprecated: Add a valid coupon code to the subscription. @@ -1118,10 +1018,8 @@ class WU_Subscription extends \WP_Ultimo\Models\Membership { public function get_price_after_coupon_code() { _deprecated_function(__METHOD__, '2.0.0'); - - } // end get_price_after_coupon_code; - -} // end class WU_Subscription; + } +} /** * Deprecated: WU_Signup @@ -1136,10 +1034,8 @@ class WU_Signup extends \WP_Ultimo\Checkout\Legacy_Checkout { public function __construct() { _deprecated_function(__CLASS__, '2.0.0', '\WP_Ultimo\Checkout\Legacy_Checkout'); - - } // end __construct; - -} // end class WU_Signup; + } +} /** * Deprecated: WU_Gateway @@ -1148,7 +1044,7 @@ class WU_Signup extends \WP_Ultimo\Checkout\Legacy_Checkout { */ abstract class WU_Gateway { -} // end class WU_Gateway; +} /** * Deprecated: WU_Site_Hooks @@ -1174,8 +1070,7 @@ class WU_Site_Hooks { _deprecated_function(__CLASS__, '2.0.0'); return array(); - - } // end get_available_templates; + } /** * Deprecated: Duplicates our template site in the creation of the new user site. @@ -1207,8 +1102,7 @@ class WU_Site_Hooks { ); return \WP_Ultimo\Helpers\Site_Duplicator::duplicate_site($site_to_duplicate, $title, $arguments); - - } // end duplicate_site; + } /** * Deprecated: Returns the preview URL to a given site id. @@ -1224,17 +1118,13 @@ class WU_Site_Hooks { $site = wu_get_site($site_id); - if (!$site) { - + if ( ! $site) { return ''; - - } // end if; + } return $site->get_featured_image(); - - } // end get_template_preview_url; - -} // end class WU_Site_Hooks; + } +} /** * Deprecated: WU_Transactions @@ -1258,10 +1148,8 @@ class WU_Transactions { $date = new \DateTime(); return $type === 'mysql' ? $date->format('Y-m-d H:i:s') : $date->format('U'); - - } // end get_current_time; - -} // end class WU_Transactions; + } +} /* * Functions */ @@ -1281,21 +1169,16 @@ function wu_get_coupon($coupon_code, $return_invalid = false) { $discount_code = wu_get_discount_code_by_code($coupon_code); - if (!$discount_code) { - + if ( ! $discount_code) { return false; + } - } // end if; - - if (!$return_invalid && !$discount_code->is_valid()) { - + if ( ! $return_invalid && ! $discount_code->is_valid()) { return false; - - } // end if; + } return new WU_Coupon($discount_code); - -} // end wu_get_coupon; +} /** * Deprecated: Returns a plan based on the id passed @@ -1311,15 +1194,12 @@ function wu_get_plan($plan_id) { $plan = wu_get_product($plan_id); - if (!$plan) { - + if ( ! $plan) { return false; - - } // end if; + } return new WU_Plan($plan); - -} // end wu_get_plan; +} /** * Deprecated: Gets a plan by its slug. @@ -1335,8 +1215,7 @@ function wu_get_plan_by_slug($plan_slug) { _deprecated_function(__FUNCTION__, '2.0.0', 'wu_get_product_by_slug()'); return wu_get_product_by_slug($plan_slug); - -} // end wu_get_plan_by_slug; +} /** * Deprecated: Returns a subscription object based on the user. * @@ -1354,8 +1233,7 @@ function wu_get_subscription($user_id) { _deprecated_function(__FUNCTION__, '2.0.0', 'wu_get_membership_by()'); return wu_get_membership_by('user_id', $user_id); - -} // end wu_get_subscription; +} /** * Deprecated: Returns a subscription object based on the integration key. * @@ -1369,8 +1247,7 @@ function wu_get_subscription_by_integration_key($integration_key) { _deprecated_function(__FUNCTION__, '2.0.0', 'wu_get_membership_by()'); return wu_get_membership_by('gateway_subscription_id', $integration_key); - -} // end wu_get_subscription_by_integration_key; +} /** * Deprecated: Return a subscription object based on the current user. * @@ -1385,8 +1262,7 @@ function wu_get_current_subscription() { _deprecated_function(__FUNCTION__, '2.0.0', 'wu_get_membership_by()'); return wu_get_membership_by('user_id', $user_id); - -} // end wu_get_current_subscription; +} /** * Deprecated: Checks if the current user is an active subscriber. @@ -1405,18 +1281,13 @@ function wu_is_active_subscriber($user_id = false) { _deprecated_function(__FUNCTION__, '2.0.0'); if ($user_id === false) { - $membership = wu_get_current_site()->get_membership(); - } else { - $membership = wu_get_membership_by('user_id', get_current_user_id()); - - } // end if; + } return $membership && $membership->is_active(); - -} // end wu_is_active_subscriber; +} /** * Deprecated: Checks if a given user is a customer of a given plan. @@ -1440,16 +1311,13 @@ function wu_has_plan($user_id, $plan_id) { * to prevent a fatal error. */ if (function_exists('wu_get_membership_by') === false) { - return false; - - } // end if; + } $membership = wu_get_membership_by('user_id', $user_id); return $membership && absint($membership->get_plan_id()) === absint($plan_id); - -} // end wu_has_plan; +} /** * Deprecated: Returns the gateway being used by the current user at the moment. @@ -1466,8 +1334,7 @@ function wu_get_active_gateway() { $active_gateways = wu_get_active_gateways(); return reset($active_gateways); - -} // end wu_get_active_gateway; +} /** * Deprecated: Generates the price description. * @@ -1483,8 +1350,7 @@ function wu_get_interval_string($price = null, $interval = null, $extended = nul _deprecated_function(__FUNCTION__, '2.0.0', '\WP_Ultimo\Models\Product::get_price_description()'); return ''; - -} // end wu_get_interval_string; +} /** * Deprecated: get_wu_currencies. @@ -1499,8 +1365,7 @@ function get_wu_currencies() { // phpcs:ignore _deprecated_function(__FUNCTION__, '2.0.0', 'wu_get_currencies()'); return wu_get_currencies(); - -} // end get_wu_currencies; +} /** * Deprecated: get_wu_currency_symbol. @@ -1516,5 +1381,4 @@ function get_wu_currency_symbol($currency = '') { // phpcs:ignore _deprecated_function(__FUNCTION__, '2.0.0', 'wu_get_currency_symbol()'); return wu_get_currency_symbol($currency); - -} // end get_wu_currency_symbol; +} diff --git a/inc/deprecated/early-deprecated.php b/inc/deprecated/early-deprecated.php index 619ca14..c9f82ad 100644 --- a/inc/deprecated/early-deprecated.php +++ b/inc/deprecated/early-deprecated.php @@ -34,8 +34,7 @@ class WU_Domain_Mapping { $ip = \WP_Ultimo\Domain_Mapping\Helper::get_network_public_ip(); return apply_filters('wu_domain_mapping_get_ip_address', $ip, $_SERVER['SERVER_ADDR']); - - } // end get_ip_address; + } /** * Deprecated: get_hosting_support_text @@ -48,7 +47,5 @@ class WU_Domain_Mapping { _deprecated_function(__METHOD__, '2.0.0'); return ''; - - } // end get_hosting_support_text; - -} // end class WU_Domain_Mapping; + } +} diff --git a/inc/deprecated/mercator.php b/inc/deprecated/mercator.php index 87b05a0..e959487 100644 --- a/inc/deprecated/mercator.php +++ b/inc/deprecated/mercator.php @@ -32,30 +32,22 @@ class Mapping { _deprecated_function(__METHOD__, '2.0.0', 'wu_get_domain_by_domain($domain)'); - if (!function_exists('wu_get_domain_by_domain')) { - + if ( ! function_exists('wu_get_domain_by_domain')) { return false; - - } // end if; + } $domain = false; foreach ((array) $domains as $url_to_search) { - $found_domain = wu_get_domain_by_domain($url_to_search); if ($found_domain) { - $domain = $found_domain; break; - - } // end if; - - } // end foreach; + } + } return $domain; - - } // end get_by_domain; - -} // end class Mapping; + } +} diff --git a/inc/development/bootstrap.php b/inc/development/bootstrap.php index 7c396c2..8ec038f 100644 --- a/inc/development/bootstrap.php +++ b/inc/development/bootstrap.php @@ -10,7 +10,7 @@ * @since 2.1.0 */ -use \Rarst\wps\Plugin as Whoops; +use Rarst\wps\Plugin as Whoops; return; @@ -19,10 +19,8 @@ return; * or by setting the constant we used to have on previous versions. */ if (isset($_GET['whoops-disable']) || (defined('WP_ULTIMO_DISABLE_WHOOPS') && WP_ULTIMO_DISABLE_WHOOPS)) { - return; - -} // end if; +} $wu_whoops = new Whoops(); diff --git a/inc/development/class-toolkit.php b/inc/development/class-toolkit.php index 56d8f58..5548ea0 100644 --- a/inc/development/class-toolkit.php +++ b/inc/development/class-toolkit.php @@ -81,8 +81,7 @@ class Toolkit { add_filter('qm/collectors', array($this, 'register_collector_overview'), 1, 2); add_filter('qm/outputter/html', array($this, 'add_overview_panel'), 50, 2); - - } // end init; + } /** * Registers the default listeners. @@ -107,8 +106,7 @@ class Toolkit { $this->listen('save-rest-arguments', array($this, 'save_route_arguments'), 'wu_rest_register_routes_general'); $this->listen('save-rest-arguments', array($this, 'save_route_arguments'), 'wu_rest_register_routes_with_id'); - - } // end register_default_listeners; + } /** * Save route arguments to files to deal with opcache. @@ -128,8 +126,7 @@ class Toolkit { $args = $manager->get_arguments_schema($context === 'update'); file_put_contents(wu_path("/mpb/data/endpoint/.endpoint-$class_name-$context"), json_encode($args)); // phpcs:ignore - - } // end save_route_arguments; + } /** * Adds a listener for development purposes. @@ -144,35 +141,38 @@ class Toolkit { */ public function listen($hook, $callback, $wp_hook = 'wp_ultimo_load', $order = 1) { - $this->listeners[$hook] = ($this->listeners[$hook] ?? 0) + 1; + $this->listeners[ $hook ] = ($this->listeners[ $hook ] ?? 0) + 1; - $this->wp_hooks[$wp_hook] = 1; + $this->wp_hooks[ $wp_hook ] = 1; $action = $this->get_action($hook, $wp_hook); $order = $this->get_order($hook, $order); - add_action($action, function(...$arguments) use ($callback, $action, $order) { + add_action( + $action, + function (...$arguments) use ($callback, $action, $order) { - $timing_id = sprintf('%s_%s_%s', $action, $this->run + 1, $order); + $timing_id = sprintf('%s_%s_%s', $action, $this->run + 1, $order); // phpcs:ignore do_action('qm/start', $timing_id); - $result = call_user_func_array($callback, $arguments); + $result = call_user_func_array($callback, $arguments); // phpcs:ignore do_action('qm/stop', $timing_id); - $this->run++; + $this->run++; - return $result; - - }, $order, 100); + return $result; + }, + $order, + 100 + ); return $this; - - } // end listen; + } /** * Sets flags for the development environment. @@ -197,17 +197,12 @@ class Toolkit { ); foreach ($configs as $constant_name => $constant_value) { - if (in_array($constant_name, $allowed_configs, true)) { - // phpcs:ignore defined($constant_name) === false && define($constant_name, $constant_value); - - } // end if; - - } // end foreach; - - } // end config; + } + } + } /** * Marks the development environment to finish execution after all listeners are run. @@ -220,14 +215,11 @@ class Toolkit { public function die($should_die = true) { if ($should_die === true) { - $should_die = is_admin() ? 'admin_enqueue_scripts' : 'wp_enqueue_scripts'; - - } // end if; + } $this->should_die = $should_die; - - } // end die; + } /** * Run a registered listener. @@ -243,20 +235,15 @@ class Toolkit { $listener = wu_request(self::LISTENER_PARAM, 'no-dev-param'); if ($listener === 'no-dev-param') { - return current($arguments); - } elseif ($listener === '') { - $listener = 'index'; - - } // end if; + } $action = $this->get_action($listener, $wp_hook); return do_action_ref_array($action, $arguments); // phpcs:ignore - - } // end run_listener; + } /** * Loads the sandbox environment. @@ -280,26 +267,20 @@ class Toolkit { $toolkit = $this; include $dev_file; - - } // end if; + } $wp_hooks = array_keys($this->wp_hooks); foreach ($wp_hooks as $wp_hook) { - add_action($wp_hook, fn(...$arguments) => $this->run_listener($wp_hook, $arguments), 0, 100); - - } // end foreach; + } add_action('shutdown', array($this, 'setup_query_monitor')); if ($this->should_die) { - $this->dump_and_die(end($wp_hooks)); - - } // end if; - - } // end load_sandbox; + } + } /** * Setups the query monitor integration. @@ -310,7 +291,6 @@ class Toolkit { public function setup_query_monitor() { if (class_exists('\QM_Dispatchers')) { - // phpcs:ignore do_action('qm/debug', sprintf('Actions with listeners: %s', $this->get_wp_hooks_list())); @@ -320,23 +300,17 @@ class Toolkit { // phpcs:ignore $dispatcher = \QM_Dispatchers::get('html'); - if (!$dispatcher) { - + if (! $dispatcher) { return; - - } // end if; + } $dispatcher->did_footer = true; if ($this->should_die && $this->run) { - $this->enqueue_scripts($dispatcher); - - } // end if; - - } // end if; - - } // end setup_query_monitor; + } + } + } /** * Registers the collector overview. @@ -352,8 +326,7 @@ class Toolkit { $collectors['wp-ultimo'] = new Query_Monitor\Collectors\Collector_Overview(); return $collectors; - - } // end register_collector_overview; + } /** * Adds the overview panel. @@ -370,8 +343,7 @@ class Toolkit { $output['wp-ultimo'] = new Query_Monitor\Panel\Overview($collector); return $output; - - } // end add_overview_panel; + } /** * Manually enqueues query monitor and WP Multisite WaaS styles. @@ -383,15 +355,16 @@ class Toolkit { */ protected function enqueue_scripts($dispatcher) { - echo sprintf('', wu_url('inc/development/assets/development.css')); + printf('', wu_url('inc/development/assets/development.css')); - wp_print_styles(array( - 'wu-admin', - )); + wp_print_styles( + array( + 'wu-admin', + ) + ); $dispatcher->manually_print_assets(); // phpcs:ignore - - } // end enqueue_scripts; + } /** * Returns a comma-separated list of listeners. @@ -403,8 +376,7 @@ class Toolkit { $listener_names = array_keys($this->listeners); return implode(', ', $listener_names); - - } // end get_listeners_list; + } /** * Returns a comma-separated list of WordPress hooks. @@ -416,8 +388,7 @@ class Toolkit { $wp_hook_names = array_keys($this->wp_hooks); return implode(', ', $wp_hook_names); - - } // end get_wp_hooks_list; + } /** * Dumps the development content and kill the execution. @@ -429,29 +400,27 @@ class Toolkit { */ protected function dump_and_die($hook) { - add_action($hook, function() use ($hook) { + add_action( + $hook, + function () use ($hook) { - if (did_action($this->should_die) && $this->run) { + if (did_action($this->should_die) && $this->run) { + $this->render_listeners_menu(); - $this->render_listeners_menu(); + do_action('shutdown'); // phpcs:ignore - do_action('shutdown'); // phpcs:ignore + $message = sprintf('Execution killed on %s.', $hook); - $message = sprintf('Execution killed on %s.', $hook); + do_action('qm/info', $message); // phpcs:ignore - do_action('qm/info', $message); // phpcs:ignore - - die(); - - } else { - - return $this->dump_and_die($this->should_die); - - } // end if; - - }, 110); - - } // end dump_and_die; + die(); + } else { + return $this->dump_and_die($this->should_die); + } + }, + 110 + ); + } /** * Get the order of a newly added listener. @@ -464,9 +433,8 @@ class Toolkit { */ protected function get_order($hook, $order = 1) { - return 10 + (absint($this->listeners[$hook]) * $order * 10) + 5; - - } // end get_order; + return 10 + (absint($this->listeners[ $hook ]) * $order * 10) + 5; + } /** * Get the action name based on the listener hook and WP action. @@ -481,8 +449,7 @@ class Toolkit { $hook = str_replace('-', '_', $hook); return sprintf('wu_sandbox_run_%s_%s', $hook, $wp_hook); - - } // end get_action; + } /** * Render the list of listeners with links. @@ -496,10 +463,8 @@ class Toolkit { * Make sure we display it only once. */ if ($this->displayed_footer) { - return; - - } // end if; + } // phpcs:disable echo ' @@ -509,13 +474,13 @@ class Toolkit { foreach (array_keys($this->listeners) as $listener) { - echo sprintf( - '
  • → Listener "%s"
  • ', - add_query_arg(self::LISTENER_PARAM, $listener), - $listener - ); + echo sprintf( +'
  • → Listener "%s"
  • ', +add_query_arg(self::LISTENER_PARAM, $listener), +$listener +); - } // end foreach; + } echo ' @@ -523,6 +488,6 @@ class Toolkit { $this->displayed_footer = true; - } // end render_listeners_menu; + } -} // end class Toolkit; +} diff --git a/inc/development/query-monitor/collectors/class-collector-overview.php b/inc/development/query-monitor/collectors/class-collector-overview.php index db0831e..c7b92a1 100644 --- a/inc/development/query-monitor/collectors/class-collector-overview.php +++ b/inc/development/query-monitor/collectors/class-collector-overview.php @@ -35,8 +35,7 @@ class Collector_Overview extends \QM_Collector { public function set_up() { parent::set_up(); - - } // end set_up; + } /** * Tear down routines. @@ -47,8 +46,7 @@ class Collector_Overview extends \QM_Collector { public function tear_down() { parent::tear_down(); - - } // end tear_down; + } /** * Process the collection. @@ -62,7 +60,5 @@ class Collector_Overview extends \QM_Collector { public function process() { $this->data = $_REQUEST; - - } // end process; - -} // end class Collector_Overview; + } +} diff --git a/inc/development/query-monitor/panel/class-overview.php b/inc/development/query-monitor/panel/class-overview.php index ab548e4..c62affa 100644 --- a/inc/development/query-monitor/panel/class-overview.php +++ b/inc/development/query-monitor/panel/class-overview.php @@ -20,12 +20,12 @@ defined('ABSPATH') || exit; class Overview extends \QM_Output_Html { /** - * Initializes the panel. - * - * @since 2.0.11 - * - * @param \QM_Collector $collector The collector associated with the panel. - */ + * Initializes the panel. + * + * @since 2.0.11 + * + * @param \QM_Collector $collector The collector associated with the panel. + */ public function __construct($collector) { parent::__construct($collector); @@ -33,8 +33,7 @@ class Overview extends \QM_Output_Html { add_filter('qm/output/menus', array($this, 'admin_menu'), 1000); add_filter('qm/output/panel_menus', array($this, 'panel_menu'), 1000); - - } // end __construct; + } /** * The name of the panel. @@ -45,8 +44,7 @@ class Overview extends \QM_Output_Html { public function name() { return __('WP Multisite WaaS', 'wp-ultimo'); - - } // end name; + } /** * Output the contents of the panel. @@ -79,8 +77,7 @@ class Overview extends \QM_Output_Html { $data = $this->collector->get_data(); $this->after_non_tabular_output(); - - } // end output; + } /** * Adds the panel to the admin panel. @@ -93,8 +90,7 @@ class Overview extends \QM_Output_Html { public function admin_menu(array $menu) { return $menu; - - } // end admin_menu; + } /** * Adds a panel menu for the panel. @@ -107,14 +103,14 @@ class Overview extends \QM_Output_Html { public function panel_menu(array $menu) { $new_menu = array( - 'wp-ultimo' => $this->menu(array( - 'title' => esc_html__('WP Multisite WaaS', 'wp-ultimo'), - 'id' => 'wp-ultimo', - )), + 'wp-ultimo' => $this->menu( + array( + 'title' => esc_html__('WP Multisite WaaS', 'wp-ultimo'), + 'id' => 'wp-ultimo', + ) + ), ); return $new_menu + $menu; - - } // end panel_menu; - -} // end class Overview; + } +} diff --git a/inc/domain-mapping/class-helper.php b/inc/domain-mapping/class-helper.php index c506c79..119bf25 100644 --- a/inc/domain-mapping/class-helper.php +++ b/inc/domain-mapping/class-helper.php @@ -12,7 +12,7 @@ namespace WP_Ultimo\Domain_Mapping; use Psr\Log\LogLevel; // Exit if accessed directly -defined( 'ABSPATH' ) || exit; +defined('ABSPATH') || exit; /** * Helper class for domain mapping functionality. @@ -35,7 +35,7 @@ class Helper { /** * Static-only class. */ - private function __construct() {} // end __construct; + private function __construct() {} /** * Checks if we are in development mode. @@ -48,7 +48,7 @@ class Helper { $site_url = site_url(); - $is_development_mode = preg_match( '#(localhost|staging.*\.|\.local|\.test)#', $site_url ); + $is_development_mode = preg_match('#(localhost|staging.*\.|\.local|\.test)#', $site_url); /** * Allow plugin developers to add additional tests @@ -60,8 +60,8 @@ class Helper { * @param string $site_url The site URL. * @return bool */ - return apply_filters( 'wu_is_development_mode', $is_development_mode, $site_url ); - } // end is_development_mode; + return apply_filters('wu_is_development_mode', $is_development_mode, $site_url); + } /** * Gets the local IP address of the network. * @@ -72,8 +72,8 @@ class Helper { */ public static function get_local_network_ip() { - return isset( $_SERVER['SERVER_ADDR'] ) ? $_SERVER['SERVER_ADDR'] : false; - } // end get_local_network_ip; + return isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : false; + } /** * Gets the public IP address of the network using an external HTTP call. @@ -93,10 +93,10 @@ class Helper { /** * See more about this filter below, on this same method. */ - return apply_filters( 'wu_get_network_public_ip', $local_ip, true ); - } // end if; + return apply_filters('wu_get_network_public_ip', $local_ip, true); + } - $_ip_address = get_site_transient( 'wu_public_network_ip' ); + $_ip_address = get_site_transient('wu_public_network_ip'); if ( ! $_ip_address ) { $ip_address = false; @@ -109,17 +109,17 @@ class Helper { ) ); - if ( ! is_wp_error( $response ) ) { - $ip_address = trim( wp_remote_retrieve_body( $response ) ); + if ( ! is_wp_error($response) ) { + $ip_address = trim(wp_remote_retrieve_body($response)); continue; - } // end if; - } // end foreach; + } + } - set_site_transient( 'wu_public_network_ip', $ip_address, 10 * DAY_IN_SECONDS ); + set_site_transient('wu_public_network_ip', $ip_address, 10 * DAY_IN_SECONDS); $_ip_address = $ip_address; - } // end if; + } /** * Allow developers to change the public IP address of the network. @@ -135,8 +135,8 @@ class Helper { * @param bool $local True if this is a local network (localhost, .dev, etc.), false otherwise. * @return string The new IP address. */ - return apply_filters( 'wu_get_network_public_ip', $_ip_address, false ); - } // end get_network_public_ip; + return apply_filters('wu_get_network_public_ip', $_ip_address, false); + } /** * Checks if a given domain name has a valid associated SSL certificate. * @@ -177,7 +177,7 @@ class Helper { ); // If stream could not be established, SSL is invalid. - if (!$stream) { + if ( ! $stream) { throw new \Exception($errstr); } @@ -190,8 +190,8 @@ class Helper { if ($cert) { // Verify the certificate's validity period. $current_time = time(); - $valid_from = $cert['validFrom_time_t'] ?? 0; - $valid_to = $cert['validTo_time_t'] ?? 0; + $valid_from = $cert['validFrom_time_t'] ?? 0; + $valid_to = $cert['validTo_time_t'] ?? 0; // Check if the certificate is currently valid. if ($current_time >= $valid_from && $current_time <= $valid_to) { @@ -199,20 +199,20 @@ class Helper { // Check that the domain matches the certificate. $common_name = $cert['subject']['CN'] ?? ''; // Common Name (CN) - $alt_names = $cert['extensions']['subjectAltName'] ?? ''; // Subject Alternative Names (SAN) + $alt_names = $cert['extensions']['subjectAltName'] ?? ''; // Subject Alternative Names (SAN) // Parse SAN into an array if present. - $alt_names_array = array_filter(array_map('trim', explode(',', str_replace('DNS:', '', $alt_names)))); + $alt_names_array = array_filter(array_map('trim', explode(',', str_replace('DNS:', '', $alt_names)))); $alt_names_array[] = $common_name; // Check if the host matches either the CN, any SAN entry, or supports a wildcard match. if ( $host === $common_name || - in_array( $host, $alt_names_array, true ) + in_array($host, $alt_names_array, true) ) { $is_valid = true; } else { foreach ($alt_names_array as $alt_name) { - if ( strpos($alt_name, '*.') === 0 && str_ends_with( $host, substr($alt_name, 1) )) { + if ( strpos($alt_name, '*.') === 0 && str_ends_with($host, substr($alt_name, 1))) { $is_valid = true; break; } @@ -234,5 +234,5 @@ class Helper { } return $is_valid; - } // end has_valid_ssl_certificate; -} // end class Helper; + } +} diff --git a/inc/domain-mapping/class-primary-domain.php b/inc/domain-mapping/class-primary-domain.php index 158fa5f..ea9150b 100644 --- a/inc/domain-mapping/class-primary-domain.php +++ b/inc/domain-mapping/class-primary-domain.php @@ -32,8 +32,7 @@ class Primary_Domain { public function init() { add_action('wu_domain_mapping_load', array($this, 'add_hooks'), -20); - - } // end init; + } /** * Adds the necessary hooks. @@ -48,8 +47,7 @@ class Primary_Domain { add_action('admin_init', array($this, 'maybe_redirect_to_mapped_or_network_domain')); add_action('login_init', array($this, 'maybe_redirect_to_mapped_or_network_domain')); - - } // end add_hooks; + } /** * Redirects the site to its primary mapped domain, if any. @@ -62,16 +60,12 @@ class Primary_Domain { $should_redirect = true; if (is_preview()) { - $should_redirect = false; - - } // end if; + } if (is_customize_preview()) { - $should_redirect = false; - - } // end if; + } /** * Allow developers to short-circuit the redirection, preventing it @@ -83,34 +77,29 @@ class Primary_Domain { * @return bool */ if (apply_filters('wu_should_redirect_to_primary_domain', $should_redirect) === false) { - return; + } - } // end if; - - if (!function_exists('wu_get_domains')) { - + if ( ! function_exists('wu_get_domains')) { return; + } - } // end if; - - $domains = wu_get_domains(array( - 'blog_id' => get_current_blog_id(), - 'primary_domain' => 1, - 'active' => 1, - 'domain__not_in' => array($_SERVER['HTTP_HOST']), - )); + $domains = wu_get_domains( + array( + 'blog_id' => get_current_blog_id(), + 'primary_domain' => 1, + 'active' => 1, + 'domain__not_in' => array($_SERVER['HTTP_HOST']), + ) + ); if (empty($domains)) { - return; - - } // end if; + } $primary_domain = $domains[0]; if ($_SERVER['HTTP_HOST'] !== $primary_domain->get_domain() && $primary_domain->is_active()) { - $url = wu_get_current_url(); $new_url = Domain_Mapping::get_instance()->replace_url($url, $primary_domain); @@ -118,10 +107,8 @@ class Primary_Domain { wp_redirect(set_url_scheme($new_url)); exit; - - } // end if; - - } // end redirect_to_primary_domain; + } + } /** * Handles redirects to mapped ot network domain for the admin panel. @@ -132,37 +119,29 @@ class Primary_Domain { public function maybe_redirect_to_mapped_or_network_domain() { if ($_SERVER['REQUEST_METHOD'] !== 'GET' || wp_doing_ajax()) { - return; - - } // end if; + } /* * The visitor is actively trying to logout. Let them do it! */ if (wu_request('action', 'nothing') === 'logout' || wu_request('loggedout')) { - return; - - } // end if; + } $site = wu_get_current_site(); $mapped_domain = $site->get_primary_mapped_domain(); - if (!$mapped_domain) { - + if ( ! $mapped_domain) { return; - - } // end if; + } $redirect_settings = wu_get_setting('force_admin_redirect', 'both'); if ($redirect_settings === 'both') { - return; - - } // end if; + } $current_url = wp_parse_url(wu_get_current_url()); @@ -175,35 +154,25 @@ class Primary_Domain { $query_args = array(); if (wu_get_isset($current_url, 'query')) { - wp_parse_str($current_url['query'], $query_args); - - } // end if; + } $redirect_url = false; if ($redirect_settings === 'force_map' && $current_url_to_compare !== $mapped_url_to_compare) { - $redirect_url = Domain_Mapping::get_instance()->replace_url(wu_get_current_url(), $mapped_domain); $query_args = array_map(fn($value) => Domain_Mapping::get_instance()->replace_url($value, $mapped_domain), $query_args); - } elseif ($redirect_settings === 'force_network' && $current_url_to_compare === $mapped_url_to_compare) { - $redirect_url = wu_restore_original_url(wu_get_current_url(), $site->get_id()); $query_args = array_map(fn($value) => wu_restore_original_url($value, $site->get_id()), $query_args); - - } // end if; + } if ($redirect_url) { - wp_redirect(add_query_arg($query_args, $redirect_url)); exit; - - } // end if; - - } // end maybe_redirect_to_mapped_or_network_domain; - -} // end class Primary_Domain; + } + } +} diff --git a/inc/domain-mapping/class-sso.php b/inc/domain-mapping/class-sso.php index dc9ce5b..abb36f3 100644 --- a/inc/domain-mapping/class-sso.php +++ b/inc/domain-mapping/class-sso.php @@ -26,5 +26,4 @@ defined('ABSPATH') || exit; class SSO { use \WP_Ultimo\Traits\Singleton; - -} // end class SSO; +} diff --git a/inc/duplication/data.php b/inc/duplication/data.php index 43171d5..8d67b43 100644 --- a/inc/duplication/data.php +++ b/inc/duplication/data.php @@ -1,465 +1,464 @@ delete(_get_meta_table('blog'), array( - 'blog_id' => $to_site_id, - )); + global $wpdb; - $meta = get_site_meta($from_site_id); + // Delete everything + $wpdb->delete( + _get_meta_table('blog'), + array( + 'blog_id' => $to_site_id, + ) + ); + + $meta = get_site_meta($from_site_id); foreach ($meta as $meta_key => $list) { + foreach ($list as $value) { + add_site_meta($to_site_id, $meta_key, $value); + } + } + } - foreach ($list as $value) { + /** + * Copy tables from a site to another + * + * @since 0.2.0 + * @param int $from_site_id duplicated site id + * @param int $to_site_id new site id + */ + public static function db_copy_tables($from_site_id, $to_site_id) { + global $wpdb; - add_site_meta($to_site_id, $meta_key, $value); + // Source Site information + $from_site_prefix = $wpdb->get_blog_prefix($from_site_id); // prefix + $from_site_prefix_length = strlen((string) $from_site_prefix); // prefix length - } // end foreach; + // Destination Site information + $to_site_prefix = $wpdb->get_blog_prefix($to_site_id); // prefix + $to_site_prefix_length = strlen((string) $to_site_prefix); // prefix length - } // end foreach; + // Options that should be preserved in the new blog. + $saved_options = MUCD_Option::get_saved_option(); - } + foreach ($saved_options as $option_name => $option_value) { + $saved_options[ $option_name ] = get_blog_option($to_site_id, $option_name); + } - /** - * Copy tables from a site to another - * @since 0.2.0 - * @param int $from_site_id duplicated site id - * @param int $to_site_id new site id - */ - public static function db_copy_tables( $from_site_id, $to_site_id ) { - global $wpdb ; - - // Source Site information - $from_site_prefix = $wpdb->get_blog_prefix( $from_site_id ); // prefix - $from_site_prefix_length = strlen((string) $from_site_prefix); // prefix length + // Bugfix : escape '_' , '%' and '/' character for mysql 'like' queries + $from_site_prefix_like = $wpdb->esc_like($from_site_prefix); - // Destination Site information - $to_site_prefix = $wpdb->get_blog_prefix( $to_site_id ); // prefix - $to_site_prefix_length = strlen((string) $to_site_prefix); // prefix length + // SCHEMA - TO FIX for HyperDB + $schema = DB_NAME; - // Options that should be preserved in the new blog. - $saved_options = MUCD_Option::get_saved_option(); + // Get sources Tables + if ($from_site_id == MUCD_PRIMARY_SITE_ID) { + $from_site_table = self::get_primary_tables($from_site_prefix); + } else { + $sql_query = $wpdb->prepare('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = \'%s\' AND TABLE_NAME LIKE \'%s\'', $schema, $from_site_prefix_like . '%'); + $from_site_table = self::do_sql_query($sql_query, 'col'); + } - foreach($saved_options as $option_name => $option_value) { - $saved_options[$option_name] = get_blog_option( $to_site_id, $option_name ); - } + // var_dump($from_site_table); - // Bugfix : escape '_' , '%' and '/' character for mysql 'like' queries - $from_site_prefix_like = $wpdb->esc_like($from_site_prefix); + // $a = 6; + // $b = 9; - // SCHEMA - TO FIX for HyperDB - $schema = DB_NAME; + // [$from_site_table[$a], $from_site_table[$b]] = [$from_site_table[$b], $from_site_table[$a]]; - // Get sources Tables - if($from_site_id == MUCD_PRIMARY_SITE_ID) { - $from_site_table = self::get_primary_tables($from_site_prefix); - } - else { - $sql_query = $wpdb->prepare('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = \'%s\' AND TABLE_NAME LIKE \'%s\'', $schema, $from_site_prefix_like . '%'); - $from_site_table = self::do_sql_query($sql_query, 'col'); - } + // var_dump($from_site_table); - // var_dump($from_site_table); + // die; - // $a = 6; - // $b = 9; + $tables_to_ignore = array( + 'actionscheduler_actions', + 'actionscheduler_claims', + 'actionscheduler_groups', + 'actionscheduler_logs', + ); - // [$from_site_table[$a], $from_site_table[$b]] = [$from_site_table[$b], $from_site_table[$a]]; + foreach ($from_site_table as $table) { + $table_base_name = substr((string) $table, $from_site_prefix_length); - // var_dump($from_site_table); + if (in_array($table_base_name, $tables_to_ignore, true)) { + continue; + } - // die; + $table_name = $to_site_prefix . $table_base_name; - $tables_to_ignore = array( - 'actionscheduler_actions', - 'actionscheduler_claims', - 'actionscheduler_groups', - 'actionscheduler_logs', - ); + // Drop table if exists + self::do_sql_query('DROP TABLE IF EXISTS `' . $table_name . '`'); - foreach ($from_site_table as $table) { + // Create new table from source table + // self::do_sql_query('CREATE TABLE IF NOT EXISTS `' . $table_name . '` LIKE `' . $schema . '`.`' . $table . '`'); - $table_base_name = substr( (string) $table, $from_site_prefix_length ); + $create_statement = self::do_sql_query('SHOW CREATE TABLE `' . $table . '`', 'row_array'); - if (in_array($table_base_name, $tables_to_ignore, true)) { + $create_statement_sql = str_replace($from_site_prefix, $to_site_prefix, (string) $create_statement[1]); - continue; + $wpdb->get_results('SET foreign_key_checks = 0'); - } // end if; + self::do_sql_query($create_statement_sql); - $table_name = $to_site_prefix . $table_base_name; + // echo($create_statement_sql); - // Drop table if exists - self::do_sql_query('DROP TABLE IF EXISTS `' . $table_name . '`'); + // die; - // Create new table from source table - // self::do_sql_query('CREATE TABLE IF NOT EXISTS `' . $table_name . '` LIKE `' . $schema . '`.`' . $table . '`'); + // Populate database with data from source table + self::do_sql_query('INSERT `' . $table_name . '` SELECT * FROM `' . $schema . '`.`' . $table . '`'); - $create_statement = self::do_sql_query('SHOW CREATE TABLE `' . $table . '`', 'row_array'); + $wpdb->get_results('SET foreign_key_checks = 1'); + } - $create_statement_sql = str_replace($from_site_prefix, $to_site_prefix, (string) $create_statement[1]); + // apply key options from new blog. + self::db_restore_data($to_site_id, $saved_options); - $wpdb->get_results('SET foreign_key_checks = 0'); + return $saved_options; + } - self::do_sql_query($create_statement_sql); + /** + * Get tables to copy if duplicated site is primary site + * + * @since 0.2.0 + * @param array of string $from_site_tables all tables of duplicated site + * @param string $from_site_prefix db prefix of duplicated site + * @return array of strings : the tables + */ + public static function get_primary_tables($from_site_prefix) { - // echo($create_statement_sql); + $default_tables = MUCD_Option::get_primary_tables_to_copy(); - // die; + foreach ($default_tables as $k => $default_table) { + $default_tables[ $k ] = $from_site_prefix . $default_table; + } - // Populate database with data from source table - self::do_sql_query('INSERT `' . $table_name . '` SELECT * FROM `' . $schema . '`.`' . $table . '`'); + return $default_tables; + } - $wpdb->get_results('SET foreign_key_checks = 1'); - } + /** + * Updated tables from a site to another + * + * @since 0.2.0 + * @param int $from_site_id duplicated site id + * @param int $to_site_id new site id + */ + public static function db_update_data($from_site_id, $to_site_id, $saved_options) { - // apply key options from new blog. - self::db_restore_data( $to_site_id, $saved_options ); + global $wpdb; - return $saved_options; - } + $to_blog_prefix = $wpdb->get_blog_prefix($to_site_id); - /** - * Get tables to copy if duplicated site is primary site - * @since 0.2.0 - * @param array of string $from_site_tables all tables of duplicated site - * @param string $from_site_prefix db prefix of duplicated site - * @return array of strings : the tables - */ - public static function get_primary_tables($from_site_prefix) { + // Looking for uploads dirs + switch_to_blog($from_site_id); - $default_tables = MUCD_Option::get_primary_tables_to_copy(); + $dir = wp_upload_dir(); + $from_upload_url = str_replace(network_site_url(), get_bloginfo('url') . '/', $dir['baseurl']); + $from_blog_url = get_blog_option($from_site_id, 'siteurl'); - foreach($default_tables as $k => $default_table) { - $default_tables[$k] = $from_site_prefix . $default_table; - } + restore_current_blog(); - return $default_tables; - } + switch_to_blog($to_site_id); + $dir = wp_upload_dir(); + $to_upload_url = str_replace(network_site_url(), get_bloginfo('url') . '/', $dir['baseurl']); + $to_blog_url = get_blog_option($to_site_id, 'siteurl'); - /** - * Updated tables from a site to another - * @since 0.2.0 - * @param int $from_site_id duplicated site id - * @param int $to_site_id new site id - */ - public static function db_update_data( $from_site_id, $to_site_id, $saved_options ) { + restore_current_blog(); - global $wpdb ; + $tables = array(); - $to_blog_prefix = $wpdb->get_blog_prefix( $to_site_id ); + // Bugfix : escape '_' , '%' and '/' character for mysql 'like' queries + $to_blog_prefix_like = $wpdb->esc_like($to_blog_prefix); - // Looking for uploads dirs - switch_to_blog($from_site_id); + $results = self::do_sql_query('SHOW TABLES LIKE \'' . $to_blog_prefix_like . '%\'', 'col', false); - $dir = wp_upload_dir(); - $from_upload_url = str_replace(network_site_url(), get_bloginfo('url').'/',$dir['baseurl']); - $from_blog_url = get_blog_option( $from_site_id, 'siteurl' ); + foreach ( $results as $k => $v ) { + $tables[ str_replace($to_blog_prefix, '', (string) $v) ] = array(); + } - restore_current_blog(); + foreach ( $tables as $table => $col) { + $results = self::do_sql_query('SHOW COLUMNS FROM `' . $to_blog_prefix . $table . '`', 'col', false); - switch_to_blog($to_site_id); + $columns = array(); - $dir = wp_upload_dir(); - $to_upload_url = str_replace(network_site_url(), get_bloginfo('url').'/', $dir['baseurl']); - $to_blog_url = get_blog_option( $to_site_id, 'siteurl' ); + foreach ( $results as $k => $v ) { + $columns[] = $v; + } - restore_current_blog(); + $tables[ $table ] = $columns; + } - $tables = array(); + $default_tables = MUCD_Option::get_fields_to_update(); - // Bugfix : escape '_' , '%' and '/' character for mysql 'like' queries - $to_blog_prefix_like = $wpdb->esc_like($to_blog_prefix); + foreach ( $default_tables as $table => $field) { + $tables[ $table ] = $field; + } - $results = self::do_sql_query('SHOW TABLES LIKE \'' . $to_blog_prefix_like . '%\'', 'col', FALSE); - - foreach( $results as $k => $v ) { - $tables[str_replace($to_blog_prefix, '', (string) $v)] = array(); - } - - foreach( $tables as $table => $col) { - $results = self::do_sql_query('SHOW COLUMNS FROM `' . $to_blog_prefix . $table . '`', 'col', FALSE); - - $columns = array(); - - foreach( $results as $k => $v ) { - $columns[] = $v; - } - - $tables[$table] = $columns; - } - - $default_tables = MUCD_Option::get_fields_to_update(); - - foreach( $default_tables as $table => $field) { - $tables[$table] = $field; - } - - $from_site_prefix = $wpdb->get_blog_prefix( $from_site_id ); - $to_site_prefix = $wpdb->get_blog_prefix( $to_site_id ); - - $string_to_replace = array ( - wu_replace_scheme($from_upload_url) => wu_replace_scheme($to_upload_url), - wu_replace_scheme($from_blog_url) => wu_replace_scheme($to_blog_url), - $from_site_prefix => $to_site_prefix - ); - - $string_to_replace = apply_filters('mucd_string_to_replace', $string_to_replace, $from_site_id, $to_site_id); - - foreach( $tables as $table => $field) { - foreach( $string_to_replace as $from_string => $to_string) { - self::update($to_blog_prefix . $table, $field, $from_string, $to_string); - } - } - - self::db_restore_data( $to_site_id, $saved_options ); - } - - /** - * Restore options that should be preserved in the new blog - * @since 0.2.0 - * @param int $from_site_id duplicated site id - * @param int $to_site_id new site id - */ - public static function db_restore_data( $to_site_id, $saved_options ) { - - switch_to_blog( $to_site_id ); - - foreach ( $saved_options as $option_name => $option_value ) { - - try { - update_option( $option_name, $option_value ); - } catch (\Throwable $exception) { - // ...nothing - } - - } - - restore_current_blog(); - } - - /** - * Updates a table - * @since 0.2.0 - * @param string $table to update - * @param array of string $fields to update - * @param string $from_string original string to replace - * @param string $to_string new string - */ - public static function update($table, $fields, $from_string, $to_string) { - if (is_array($fields) || !empty($fields)) { - - global $wpdb; - - foreach($fields as $field) { - - // Bugfix : escape '_' , '%' and '/' character for mysql 'like' queries - $from_string_like = $wpdb->esc_like($from_string); - - $results = $wpdb->query("SET SQL_MODE='ALLOW_INVALID_DATES';"); - - $sql_query = $wpdb->prepare(' - SELECT `' .$field. '` FROM `'.$table.'` WHERE `' .$field. '` LIKE "%s" ', - '%' . $from_string_like . '%' - ); - - $results = self::do_sql_query($sql_query, 'results', false); - - if ($results) { - $update = 'UPDATE `'.$table.'` SET `'.$field.'` = "%s" WHERE `'.$field.'` = "%s"'; - - foreach($results as $result => $row) { - $old_value = $row[$field]; - $new_value = self::try_replace( $row, $field, $from_string, $to_string ); - $sql_query = $wpdb->prepare($update, $new_value, $old_value); - $results = self::do_sql_query($sql_query); - } - } - } - } - } - - /** - * Replace $from_string with $to_string in $val - * Warning : if $to_string already in $val, no replacement is made - * @since 0.2.0 - * @param string $val - * @param string $from_string - * @param string $to_string - * @return string the new string - */ - public static function replace($val, $from_string, $to_string) { - $new = $val; - if(is_string($val)) { - $pos = strpos($val, $to_string); - if($pos === false) { - $new = str_replace($from_string, $to_string, $val); - } - } - return $new; - } - - /** - * Replace recursively $from_string with $to_string in $val - * @since 0.2.0 - * @param mixte (string|array) $val - * @param string $from_string - * @param string $to_string - * @return string the new string - */ - public static function replace_recursive($val, $from_string, $to_string) { - $unset = array(); - if(is_array($val)) { - foreach($val as $k => $v) { - $val[$k] = self::try_replace( $val, $k, $from_string, $to_string ); - } - } - else - $val = self::replace($val, $from_string, $to_string); - - foreach($unset as $k) - unset($val[$k]); - - return $val; - } - - /** - * Try to replace $from_string with $to_string in a row - * @since 0.2.0 - * @param array $row the row - * @param array $field the field - * @param string $from_string - * @param string $to_string - * @return the new data - */ - public static function try_replace($row, $field, $from_string, $to_string) { - if(is_serialized($row[$field])) { - $double_serialize = FALSE; - $row[$field] = @unserialize($row[$field]); - - // FOR SERIALISED OPTIONS, like in wp_carousel plugin - if(is_serialized($row[$field])) { - $row[$field] = @unserialize($row[$field]); - $double_serialize = TRUE; - } - - if(is_array($row[$field])) { - $row[$field] = self::replace_recursive($row[$field], $from_string, $to_string); - } - else if(is_object($row[$field]) || $row[$field] instanceof __PHP_Incomplete_Class) { - $array_object = (array) $row[$field]; - $array_object = self::replace_recursive($array_object, $from_string, $to_string); - foreach($array_object as $key => $value) { - try { - $row[$field]->$key = $value; - } catch (\Throwable $exception) { - // ...nothing - } - } - } - else { - $row[$field] = self::replace($row[$field], $from_string, $to_string); - } - - $row[$field] = serialize($row[$field]); - - // Pour des options comme wp_carousel... - if($double_serialize) { - $row[$field] = serialize($row[$field]); - } - } - else { - $row[$field] = self::replace($row[$field], $from_string, $to_string); - } - return $row[$field]; - } - - /** - * Runs a WPDB query - * @since 0.2.0 - * @param string $sql_query the query - * @param string $type type of result - * @param boolean $log log the query, or not - * @return $results of the query - */ - public static function do_sql_query($sql_query, $type = '', $log = TRUE) { - global $wpdb; - - $wpdb->suppress_errors(); - - switch ($type) { - case 'col': - $results = $wpdb->get_col($sql_query); - break; - case 'row': - $results = $wpdb->get_row($sql_query); - break; - case 'row_array': - $results = $wpdb->get_row($sql_query, ARRAY_N); - break; - case 'var': - $results = $wpdb->get_var($sql_query); - break; - case 'results': - $results = $wpdb->get_results($sql_query, ARRAY_A); - break; - default: - $results = $wpdb->query($sql_query); - break; - } - - if($log) { - MUCD_Duplicate::write_log('SQL :' .$sql_query); - MUCD_Duplicate::write_log('Result :' . var_export($results, true)); - } - - if ($wpdb->last_error != "") { - self::sql_error($sql_query, $wpdb->last_error); - } - - $wpdb->suppress_errors(false); - - return $results; - } - - /** - * Stop process on SQL Error, print and log error, removes the new blog - * @since 0.2.0 - * @param string $sql_query the query - * @param string $sql_error the error - */ - public static function sql_error($sql_query, $sql_error) { - wu_log_add('site-duplication-errors', sprintf('Got error "%s" while running: %s', $sql_error, $sql_query), LogLevel::ERROR); - } - - } -} \ No newline at end of file + $from_site_prefix = $wpdb->get_blog_prefix($from_site_id); + $to_site_prefix = $wpdb->get_blog_prefix($to_site_id); + + $string_to_replace = array( + wu_replace_scheme($from_upload_url) => wu_replace_scheme($to_upload_url), + wu_replace_scheme($from_blog_url) => wu_replace_scheme($to_blog_url), + $from_site_prefix => $to_site_prefix, + ); + + $string_to_replace = apply_filters('mucd_string_to_replace', $string_to_replace, $from_site_id, $to_site_id); + + foreach ( $tables as $table => $field) { + foreach ( $string_to_replace as $from_string => $to_string) { + self::update($to_blog_prefix . $table, $field, $from_string, $to_string); + } + } + + self::db_restore_data($to_site_id, $saved_options); + } + + /** + * Restore options that should be preserved in the new blog + * + * @since 0.2.0 + * @param int $from_site_id duplicated site id + * @param int $to_site_id new site id + */ + public static function db_restore_data($to_site_id, $saved_options) { + + switch_to_blog($to_site_id); + + foreach ( $saved_options as $option_name => $option_value ) { + try { + update_option($option_name, $option_value); + } catch (\Throwable $exception) { + // ...nothing + } + } + + restore_current_blog(); + } + + /** + * Updates a table + * + * @since 0.2.0 + * @param string $table to update + * @param array of string $fields to update + * @param string $from_string original string to replace + * @param string $to_string new string + */ + public static function update($table, $fields, $from_string, $to_string) { + if (is_array($fields) || ! empty($fields)) { + global $wpdb; + + foreach ($fields as $field) { + + // Bugfix : escape '_' , '%' and '/' character for mysql 'like' queries + $from_string_like = $wpdb->esc_like($from_string); + + $results = $wpdb->query("SET SQL_MODE='ALLOW_INVALID_DATES';"); + + $sql_query = $wpdb->prepare( + ' + SELECT `' . $field . '` FROM `' . $table . '` WHERE `' . $field . '` LIKE "%s" ', + '%' . $from_string_like . '%' + ); + + $results = self::do_sql_query($sql_query, 'results', false); + + if ($results) { + $update = 'UPDATE `' . $table . '` SET `' . $field . '` = "%s" WHERE `' . $field . '` = "%s"'; + + foreach ($results as $result => $row) { + $old_value = $row[ $field ]; + $new_value = self::try_replace($row, $field, $from_string, $to_string); + $sql_query = $wpdb->prepare($update, $new_value, $old_value); + $results = self::do_sql_query($sql_query); + } + } + } + } + } + + /** + * Replace $from_string with $to_string in $val + * Warning : if $to_string already in $val, no replacement is made + * + * @since 0.2.0 + * @param string $val + * @param string $from_string + * @param string $to_string + * @return string the new string + */ + public static function replace($val, $from_string, $to_string) { + $new = $val; + if (is_string($val)) { + $pos = strpos($val, $to_string); + if ($pos === false) { + $new = str_replace($from_string, $to_string, $val); + } + } + return $new; + } + + /** + * Replace recursively $from_string with $to_string in $val + * + * @since 0.2.0 + * @param mixte (string|array) $val + * @param string $from_string + * @param string $to_string + * @return string the new string + */ + public static function replace_recursive($val, $from_string, $to_string) { + $unset = array(); + if (is_array($val)) { + foreach ($val as $k => $v) { + $val[ $k ] = self::try_replace($val, $k, $from_string, $to_string); + } + } else { + $val = self::replace($val, $from_string, $to_string); + } + + foreach ($unset as $k) { + unset($val[ $k ]); + } + + return $val; + } + + /** + * Try to replace $from_string with $to_string in a row + * + * @since 0.2.0 + * @param array $row the row + * @param array $field the field + * @param string $from_string + * @param string $to_string + * @return the new data + */ + public static function try_replace($row, $field, $from_string, $to_string) { + if (is_serialized($row[ $field ])) { + $double_serialize = false; + $row[ $field ] = @unserialize($row[ $field ]); + + // FOR SERIALISED OPTIONS, like in wp_carousel plugin + if (is_serialized($row[ $field ])) { + $row[ $field ] = @unserialize($row[ $field ]); + $double_serialize = true; + } + + if (is_array($row[ $field ])) { + $row[ $field ] = self::replace_recursive($row[ $field ], $from_string, $to_string); + } elseif (is_object($row[ $field ]) || $row[ $field ] instanceof __PHP_Incomplete_Class) { + $array_object = (array) $row[ $field ]; + $array_object = self::replace_recursive($array_object, $from_string, $to_string); + foreach ($array_object as $key => $value) { + try { + $row[ $field ]->$key = $value; + } catch (\Throwable $exception) { + // ...nothing + } + } + } else { + $row[ $field ] = self::replace($row[ $field ], $from_string, $to_string); + } + + $row[ $field ] = serialize($row[ $field ]); + + // Pour des options comme wp_carousel... + if ($double_serialize) { + $row[ $field ] = serialize($row[ $field ]); + } + } else { + $row[ $field ] = self::replace($row[ $field ], $from_string, $to_string); + } + return $row[ $field ]; + } + + /** + * Runs a WPDB query + * + * @since 0.2.0 + * @param string $sql_query the query + * @param string $type type of result + * @param boolean $log log the query, or not + * @return $results of the query + */ + public static function do_sql_query($sql_query, $type = '', $log = true) { + global $wpdb; + + $wpdb->suppress_errors(); + + switch ($type) { + case 'col': + $results = $wpdb->get_col($sql_query); + break; + case 'row': + $results = $wpdb->get_row($sql_query); + break; + case 'row_array': + $results = $wpdb->get_row($sql_query, ARRAY_N); + break; + case 'var': + $results = $wpdb->get_var($sql_query); + break; + case 'results': + $results = $wpdb->get_results($sql_query, ARRAY_A); + break; + default: + $results = $wpdb->query($sql_query); + break; + } + + if ($log) { + MUCD_Duplicate::write_log('SQL :' . $sql_query); + MUCD_Duplicate::write_log('Result :' . var_export($results, true)); + } + + if ($wpdb->last_error != '') { + self::sql_error($sql_query, $wpdb->last_error); + } + + $wpdb->suppress_errors(false); + + return $results; + } + + /** + * Stop process on SQL Error, print and log error, removes the new blog + * + * @since 0.2.0 + * @param string $sql_query the query + * @param string $sql_error the error + */ + public static function sql_error($sql_query, $sql_error) { + wu_log_add('site-duplication-errors', sprintf('Got error "%s" while running: %s', $sql_error, $sql_query), LogLevel::ERROR); + } + } +} diff --git a/inc/duplication/duplicate.php b/inc/duplication/duplicate.php index 7edff19..0a43c95 100644 --- a/inc/duplication/duplicate.php +++ b/inc/duplication/duplicate.php @@ -1,293 +1,301 @@ hide_errors(); - global $wpdb; - $form_message = array(); - $wpdb->hide_errors(); + self::init_log($data); - self::init_log($data); + $email = $data['email']; + $domain = $data['domain']; + $newdomain = $data['newdomain']; + $path = $data['path']; + $title = $data['title']; + $from_site_id = $data['from_site_id']; + $keep_users = $data['keep_users']; + $copy_file = $data['copy_files']; + $public = $data['public']; + $network_id = $data['network_id']; - $email = $data['email']; - $domain = $data['domain']; - $newdomain = $data['newdomain']; - $path = $data['path']; - $title = $data['title']; - $from_site_id = $data['from_site_id']; - $keep_users = $data['keep_users']; - $copy_file = $data['copy_files']; - $public = $data['public']; - $network_id = $data['network_id']; + self::write_log('Start site duplication : from site ' . $from_site_id); + self::write_log('Admin email : ' . $email); + self::write_log('Domain : ' . $newdomain); + self::write_log('Path : ' . $path); + self::write_log('Site title : ' . $title); - MUCD_Duplicate::write_log('Start site duplication : from site ' . $from_site_id); - MUCD_Duplicate::write_log('Admin email : ' . $email); - MUCD_Duplicate::write_log('Domain : ' . $newdomain); - MUCD_Duplicate::write_log('Path : ' . $path); - MUCD_Duplicate::write_log('Site title : ' . $title); + $user_id = isset($data['user_id']) && ! empty($data['user_id']) ? $data['user_id'] : self::create_admin($email, $domain); - $user_id = isset($data['user_id']) && !empty($data['user_id']) ? $data['user_id'] : MUCD_Duplicate::create_admin($email, $domain); + if ( is_wp_error($user_id) ) { + $form_message['error'] = $user_id->get_error_message(); + return $form_message; + } - if ( is_wp_error( $user_id ) ) { - $form_message['error'] = $user_id->get_error_message(); - return $form_message; - } + // Create new site + switch_to_blog(1); + $to_site_id = wpmu_create_blog($newdomain, $path, $title, $user_id, array('public' => $public), $network_id); + $wpdb->show_errors(); - // Create new site - switch_to_blog(1); - $to_site_id = wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' => $public ), $network_id ); - $wpdb->show_errors(); + if ( is_wp_error($to_site_id) ) { + $form_message['error'] = $to_site_id->get_error_message(); + return $form_message; + } - if ( is_wp_error( $to_site_id ) ) { - $form_message['error'] = $to_site_id->get_error_message(); - return $form_message; - } + // User rights adjustments + if ( ! is_super_admin($user_id) && ! get_user_option('primary_blog', $user_id) ) { + update_user_option($user_id, 'primary_blog', $to_site_id, true); + } - // User rights adjustments - if ( !is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) ) { - update_user_option( $user_id, 'primary_blog', $to_site_id, true ); - } + self::bypass_server_limit(); - MUCD_Duplicate::bypass_server_limit(); + // Copy Site - File + if ($copy_file == 'yes') { + do_action('mucd_before_copy_files', $from_site_id, $to_site_id); + $result = MUCD_Files::copy_files($from_site_id, $to_site_id); + do_action('mucd_after_copy_files', $from_site_id, $to_site_id); + } - // Copy Site - File - if($copy_file=='yes') { - do_action( 'mucd_before_copy_files', $from_site_id, $to_site_id ); - $result = MUCD_Files::copy_files($from_site_id, $to_site_id); - do_action( 'mucd_after_copy_files', $from_site_id, $to_site_id ); - } + // Copy Site - Data + do_action('mucd_before_copy_data', $from_site_id, $to_site_id); + $result = MUCD_Data::copy_data($from_site_id, $to_site_id); + do_action('mucd_after_copy_data', $from_site_id, $to_site_id); - // Copy Site - Data - do_action( 'mucd_before_copy_data', $from_site_id, $to_site_id ); - $result = MUCD_Data::copy_data($from_site_id, $to_site_id); - do_action( 'mucd_after_copy_data', $from_site_id, $to_site_id ); + // Copy Site - Users + if ($keep_users == 'yes') { + do_action('mucd_before_copy_users', $from_site_id, $to_site_id); + $result = self::copy_users($from_site_id, $to_site_id); + do_action('mucd_after_copy_users', $from_site_id, $to_site_id); + } - // Copy Site - Users - if($keep_users=='yes') { - do_action( 'mucd_before_copy_users', $from_site_id, $to_site_id ); - $result = MUCD_Duplicate::copy_users($from_site_id, $to_site_id); - do_action( 'mucd_after_copy_users', $from_site_id, $to_site_id ); - } + update_blog_option($to_site_id, 'mucd_duplicable', 'no'); - update_blog_option( $to_site_id, 'mucd_duplicable', "no"); - - $form_message['msg'] = MUCD_NETWORK_PAGE_DUPLICATE_NOTICE_CREATED; - $form_message['site_id'] = $to_site_id; + $form_message['msg'] = MUCD_NETWORK_PAGE_DUPLICATE_NOTICE_CREATED; + $form_message['site_id'] = $to_site_id; - MUCD_Duplicate::write_log('End site duplication : new site ID = ' . $to_site_id); + self::write_log('End site duplication : new site ID = ' . $to_site_id); - wp_cache_flush(); - return $form_message; - } + wp_cache_flush(); + return $form_message; + } - /** - * Creates an admin user if no user exists with this email - * @since 0.2.0 - * @param string $email the email - * @param string $domain the domain - * @return int id of the user - */ - public static function create_admin($email, $domain) { - // Create New site Admin if not exists - $password = 'N/A'; + /** + * Creates an admin user if no user exists with this email + * + * @since 0.2.0 + * @param string $email the email + * @param string $domain the domain + * @return int id of the user + */ + public static function create_admin($email, $domain) { + // Create New site Admin if not exists + $password = 'N/A'; - $user_id = email_exists($email); + $user_id = email_exists($email); - if ( !$user_id ) { // Create a new user with a random password - $password = wp_generate_password( 12, false ); - $user_id = wpmu_create_user( $domain, $password, $email ); - if ( false == $user_id ) { - return new \WP_Error( 'file_copy', MUCD_NETWORK_PAGE_DUPLICATE_ADMIN_ERROR_CREATE_USER); - } - else { - wp_new_user_notification( $user_id, $password ); - } - } + if ( ! $user_id ) { // Create a new user with a random password + $password = wp_generate_password(12, false); + $user_id = wpmu_create_user($domain, $password, $email); + if ( false == $user_id ) { + return new \WP_Error('file_copy', MUCD_NETWORK_PAGE_DUPLICATE_ADMIN_ERROR_CREATE_USER); + } else { + wp_new_user_notification($user_id, $password); + } + } - return $user_id; - } + return $user_id; + } - /** - * Copy users and roles from one site to another - * @since 0.2.0 - * @param int $from_site_id duplicated site id - * @param int $to_site_id new site id - */ - public static function copy_users($from_site_id, $to_site_id) { + /** + * Copy users and roles from one site to another + * + * @since 0.2.0 + * @param int $from_site_id duplicated site id + * @param int $to_site_id new site id + */ + public static function copy_users($from_site_id, $to_site_id) { - global $wpdb; + global $wpdb; - // Bugfix Pierre Dargham : relocating this declaration outside of the loop - // PHP < 5.3 - function user_array_map( $a ){ return $a[0]; } + // Bugfix Pierre Dargham : relocating this declaration outside of the loop + // PHP < 5.3 + function user_array_map($a) { + return $a[0]; } - if (is_main_site($from_site_id)) { - $is_from_main_site = true; - $args = array('fields' => 'ids'); - $all_sites_ids = MUCD_Functions::get_sites($args); - if(!empty($all_sites_ids)) { - $all_sites_ids = array_map( 'user_array_map', $all_sites_ids ); - } - } else { - $is_from_main_site = false; - } + if (is_main_site($from_site_id)) { + $is_from_main_site = true; + $args = array('fields' => 'ids'); + $all_sites_ids = MUCD_Functions::get_sites($args); + if ( ! empty($all_sites_ids)) { + $all_sites_ids = array_map('user_array_map', $all_sites_ids); + } + } else { + $is_from_main_site = false; + } - // Source Site information - $from_site_prefix = $wpdb->get_blog_prefix( $from_site_id ); // prefix - $from_site_prefix_length = strlen((string) $from_site_prefix); // prefix length + // Source Site information + $from_site_prefix = $wpdb->get_blog_prefix($from_site_id); // prefix + $from_site_prefix_length = strlen((string) $from_site_prefix); // prefix length - // Destination Site information - $to_site_prefix = $wpdb->get_blog_prefix( $to_site_id ); // prefix - $to_site_prefix_length = strlen((string) $to_site_prefix); + // Destination Site information + $to_site_prefix = $wpdb->get_blog_prefix($to_site_id); // prefix + $to_site_prefix_length = strlen((string) $to_site_prefix); - $users = get_users('blog_id='.$from_site_id); + $users = get_users('blog_id=' . $from_site_id); - $admin_email = get_blog_option( $to_site_id, 'admin_email' , 'false' ); + $admin_email = get_blog_option($to_site_id, 'admin_email', 'false'); - switch_to_blog($to_site_id); + switch_to_blog($to_site_id); - foreach ($users as $user) { - if($user->user_email != $admin_email) { + foreach ($users as $user) { + if ($user->user_email != $admin_email) { + add_user_to_blog($to_site_id, $user->ID, 'subscriber'); - add_user_to_blog( $to_site_id, $user->ID, 'subscriber'); + $all_meta = array_map('user_array_map', get_user_meta($user->ID)); - $all_meta = array_map( 'user_array_map', get_user_meta( $user->ID ) ); + foreach ($all_meta as $metakey => $metavalue) { + $prefix = substr($metakey, 0, $from_site_prefix_length); + if ($prefix == $from_site_prefix) { + $raw_meta_name = substr($metakey, $from_site_prefix_length); + if ($is_from_main_site) { + $parts = explode('_', $raw_meta_name, 2); + if (count($parts) > 1 && in_array($parts[0], $all_sites_ids)) { + continue; + } + } + update_user_meta($user->ID, $to_site_prefix . $raw_meta_name, maybe_unserialize($metavalue)); + } + } + } + } - foreach ($all_meta as $metakey => $metavalue) { - $prefix = substr($metakey, 0, $from_site_prefix_length); - if($prefix==$from_site_prefix) { - $raw_meta_name = substr($metakey,$from_site_prefix_length); - if($is_from_main_site) { - $parts = explode('_', $raw_meta_name, 2); - if (count($parts) > 1 && in_array($parts[0], $all_sites_ids)) { - continue; - } - } - update_user_meta( $user->ID, $to_site_prefix . $raw_meta_name, maybe_unserialize($metavalue) ); - } - } - } + restore_current_blog(); + } - } + /** + * Init log object + * + * @since 0.2.0 + * @param array $data data from FORM + */ + public static function init_log($data) { + // INIT LOG AND SAVE OPTION + if (isset($data['log']) && $data['log'] == 'yes' ) { + if (isset($data['log-path']) && ! empty($data['log-path'])) { + $log_name = @date('Y_m_d_His') . '-' . $data['domain'] . '.log'; + if (substr_compare((string) $data['log-path'], '/', -strlen('/')) !== 0) { + $data['log-path'] = $data['log-path'] . '/'; + } + self::$log = new MUCD_Log(true, $data['log-path'], $log_name); + } + } else { + self::$log = new MUCD_Log(false); + } + } - restore_current_blog(); - } + /** + * Check if log is active + * + * @since 0.2.0 + * @return boolean + */ + public static function log() { + return (self::$log !== false && self::$log->can_write() && self::$log->mod() !== false); + } - /** - * Init log object - * @since 0.2.0 - * @param array $data data from FORM - */ - public static function init_log($data) { - // INIT LOG AND SAVE OPTION - if(isset($data['log']) && $data['log']=='yes' ) { - if(isset($data['log-path']) && !empty($data['log-path'])) { - $log_name = @date('Y_m_d_His') . '-' . $data['domain'] . '.log'; - if(substr_compare((string) $data['log-path'], "/", -strlen("/")) !== 0) { - $data['log-path'] = $data['log-path'] . '/'; - } - MUCD_Duplicate::$log = new MUCD_Log(true, $data['log-path'], $log_name); - } - } - else { - MUCD_Duplicate::$log = new MUCD_Log(false); - } - } + /** + * Check if log has error + * + * @since 0.2.0 + * @return boolean + */ + public static function log_error() { + return (self::$log !== false && ! (self::$log->can_write()) && self::$log->mod() !== false); + } - /** - * Check if log is active - * @since 0.2.0 - * @return boolean - */ - public static function log() { - return ( self::$log!==false && self::$log->can_write() && self::$log->mod()!==false ); - } + /** + * Writes a message in log file + * + * @since 0.2.0 + * @param string $msg the message + */ + public static function write_log($msg) { + if (self::log() !== false) { + self::$log->write_log($msg); + } + } - /** - * Check if log has error - * @since 0.2.0 - * @return boolean - */ - public static function log_error() { - return (self::$log!==false && !(self::$log->can_write()) && self::$log->mod()!==false ); - } + /** + * Close the log file + * + * @since 0.2.0 + */ + public static function close_log() { + if (self::log() !== false) { + self::$log->close_log(); + } + } - /** - * Writes a message in log file - * @since 0.2.0 - * @param string $msg the message - */ - public static function write_log($msg) { - if(self::log()!==false) { - self::$log->write_log($msg); - } - } + /** + * Get the url of the created log file + * + * @since 0.2.0 + * @return string the url of false if no log file was created + */ + public static function log_url() { + if (self::log() !== false) { + return self::$log->file_url(); + } + return false; + } - /** - * Close the log file - * @since 0.2.0 - */ - public static function close_log() { - if(self::log()!==false) { - self::$log->close_log(); - } - } + /** + * Get log directory + * + * @since 0.2.0 + * @return string the path + */ + public static function log_dir() { + return self::$log->dir_path(); + } - /** - * Get the url of the created log file - * @since 0.2.0 - * @return string the url of false if no log file was created - */ - public static function log_url() { - if(self::log()!==false) { - return self::$log->file_url() ; - } - return false; - } + /** + * Bypass limit server if possible + * + * @since 0.2.0 + */ + public static function bypass_server_limit() { + @ini_set('memory_limit', '1024M'); + @ini_set('max_execution_time', '0'); + } + } - /** - * Get log directory - * @since 0.2.0 - * @return string the path - */ - public static function log_dir() { - return self::$log->dir_path(); - } - - /** - * Bypass limit server if possible - * @since 0.2.0 - */ - public static function bypass_server_limit() { - @ini_set('memory_limit','1024M'); - @ini_set('max_execution_time','0'); - } - } - - MUCD_Duplicate::init(); -} \ No newline at end of file + MUCD_Duplicate::init(); +} diff --git a/inc/duplication/files.php b/inc/duplication/files.php index f240403..7136da7 100644 --- a/inc/duplication/files.php +++ b/inc/duplication/files.php @@ -1,137 +1,142 @@ $from_dir['path'], - 'to_dir_path' => $to_dir, - 'exclude_dirs' => $from_dir['exclude'], - ); + $dirs = array(); + $dirs[] = array( + 'from_dir_path' => $from_dir['path'], + 'to_dir_path' => $to_dir, + 'exclude_dirs' => $from_dir['exclude'], + ); - $dirs = apply_filters('mucd_copy_dirs', $dirs, $from_site_id, $to_site_id); + $dirs = apply_filters('mucd_copy_dirs', $dirs, $from_site_id, $to_site_id); - foreach($dirs as $dir) { - if(isset($dir['to_dir_path']) && !MUCD_Files::init_dir($dir['to_dir_path'])) { - MUCD_Files::mkdir_error($dir['to_dir_path']); - } - MUCD_Duplicate::write_log('Copy files from ' . $dir['from_dir_path'] . ' to ' . $dir['to_dir_path']); - MUCD_Files::recurse_copy($dir['from_dir_path'], $dir['to_dir_path'], $dir['exclude_dirs']); - } + foreach ($dirs as $dir) { + if (isset($dir['to_dir_path']) && ! self::init_dir($dir['to_dir_path'])) { + self::mkdir_error($dir['to_dir_path']); + } + MUCD_Duplicate::write_log('Copy files from ' . $dir['from_dir_path'] . ' to ' . $dir['to_dir_path']); + self::recurse_copy($dir['from_dir_path'], $dir['to_dir_path'], $dir['exclude_dirs']); + } - return true; - } + return true; + } - /** - * Copy files from one directory to another - * @since 0.2.0 - * @param string $src source directory path - * @param string $dst destination directory path - * @param array $exclude_dirs directories to ignore - */ - public static function recurse_copy($src, $dst, $exclude_dirs=array()) { - $src = rtrim( $src, '/' ); - $dst = rtrim( $dst, '/' ); - $dir = opendir($src); - @mkdir($dst); - while(false !== ( $file = readdir($dir)) ) { - if (( $file != '.' ) && ( $file != '..' )) { - if ( is_dir($src . '/' . $file) ) { - if(!in_array($file, $exclude_dirs)) { - MUCD_Files::recurse_copy($src . '/' . $file,$dst . '/' . $file); - } - } - else { - copy($src . '/' . $file,$dst . '/' . $file); - } - } - } - closedir($dir); - } + /** + * Copy files from one directory to another + * + * @since 0.2.0 + * @param string $src source directory path + * @param string $dst destination directory path + * @param array $exclude_dirs directories to ignore + */ + public static function recurse_copy($src, $dst, $exclude_dirs = array()) { + $src = rtrim($src, '/'); + $dst = rtrim($dst, '/'); + $dir = opendir($src); + @mkdir($dst); + while (false !== ($file = readdir($dir)) ) { + if (($file != '.') && ($file != '..')) { + if ( is_dir($src . '/' . $file) ) { + if ( ! in_array($file, $exclude_dirs)) { + self::recurse_copy($src . '/' . $file, $dst . '/' . $file); + } + } else { + copy($src . '/' . $file, $dst . '/' . $file); + } + } + } + closedir($dir); + } - /** - * Set a directory writable, creates it if not exists, or return false - * @since 0.2.0 - * @param string $path the path - * @return boolean True on success, False on failure - */ - public static function init_dir($path) { - $e = error_reporting(0); + /** + * Set a directory writable, creates it if not exists, or return false + * + * @since 0.2.0 + * @param string $path the path + * @return boolean True on success, False on failure + */ + public static function init_dir($path) { + $e = error_reporting(0); - if(!file_exists($path)) { - return @mkdir($path, 0777); - } - else if(is_dir($path)) { - if(!is_writable($path)) { - return chmod($path, 0777); - } - return true; - } + if ( ! file_exists($path)) { + return @mkdir($path, 0777); + } elseif (is_dir($path)) { + if ( ! is_writable($path)) { + return chmod($path, 0777); + } + return true; + } - error_reporting($e); + error_reporting($e); - return false; + return false; + } - } + /** + * Removes a directory and all its content + * + * @since 0.2.0 + * @param string $dir the path + */ + public static function rrmdir($dir) { + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != '.' && $object != '..') { + if (filetype($dir . '/' . $object) == 'dir') { + self::rrmdir($dir . '/' . $object); + } else { + unlink($dir . '/' . $object); + } + } + } + reset($objects); + rmdir($dir); + } + } - /** - * Removes a directory and all its content - * @since 0.2.0 - * @param string $dir the path - */ - public static function rrmdir($dir) { - if (is_dir($dir)) { - $objects = scandir($dir); - foreach ($objects as $object) { - if ($object != "." && $object != "..") { - if (filetype($dir."/".$object) == "dir") self::rrmdir($dir."/".$object); else unlink($dir."/".$object); - } - } - reset($objects); - rmdir($dir); - } - } - - /** - * Stop process on Creating dir Error, print and log error, removes the new blog - * @since 0.2.0 - * @param string $dir_path the path - */ - public static function mkdir_error($dir_path) { - $error_1 = 'ERROR DURING FILE COPY : CANNOT CREATE ' . $dir_path; - MUCD_Duplicate::write_log($error_1 ); - $error_2 = sprintf( MUCD_NETWORK_PAGE_DUPLICATE_COPY_FILE_ERROR , MUCD_Functions::get_primary_upload_dir() ); - MUCD_Duplicate::write_log($error_2 ); - MUCD_Duplicate::write_log('Duplication interrupted on FILE COPY ERROR'); - echo '
    Duplication failed :

    ' . $error_1 . '

    ' . $error_2 . '

    '; - if( $log_url = MUCD_Duplicate::log_url() ) { - echo '' . MUCD_NETWORK_PAGE_DUPLICATE_VIEW_LOG . ''; - } - MUCD_Functions::remove_blog(self::$to_site_id); - wp_die(); - } - - } + /** + * Stop process on Creating dir Error, print and log error, removes the new blog + * + * @since 0.2.0 + * @param string $dir_path the path + */ + public static function mkdir_error($dir_path) { + $error_1 = 'ERROR DURING FILE COPY : CANNOT CREATE ' . $dir_path; + MUCD_Duplicate::write_log($error_1); + $error_2 = sprintf(MUCD_NETWORK_PAGE_DUPLICATE_COPY_FILE_ERROR, MUCD_Functions::get_primary_upload_dir()); + MUCD_Duplicate::write_log($error_2); + MUCD_Duplicate::write_log('Duplication interrupted on FILE COPY ERROR'); + echo '
    Duplication failed :

    ' . $error_1 . '

    ' . $error_2 . '

    '; + if ( $log_url = MUCD_Duplicate::log_url() ) { + echo '' . MUCD_NETWORK_PAGE_DUPLICATE_VIEW_LOG . ''; + } + MUCD_Functions::remove_blog(self::$to_site_id); + wp_die(); + } + } } diff --git a/inc/duplication/functions.php b/inc/duplication/functions.php index 3a4b76d..04185d1 100644 --- a/inc/duplication/functions.php +++ b/inc/duplication/functions.php @@ -1,216 +1,230 @@ |:]*$/',$tmp); - return ($bool == 1); // so that it will return only true and false - } - return false; - } + /** + * Check if a path is valid MS-windows path + * + * @since 0.2.0 + * @param string $path the path + * @return boolean true | false + */ + public static function valid_windows_dir_path($path) { + if (strpos($path, ':') == 1 && preg_match('/[a-zA-Z]/', $path[0])) { + $tmp = substr($path, 2); + $bool = preg_match('/^[^*?"<>|:]*$/', $tmp); + return ($bool == 1); // so that it will return only true and false + } + return false; + } - /** - * Check if a path is valid UNIX path - * @since 0.2.0 - * @param string $path the path - * @return boolean true | false - */ - public static function valid_unix_dir_path($path) { - $reg = "/^(\/([a-zA-Z0-9+\$_.-])+)*\/?$/"; - $bool = preg_match($reg,$path); - return ($bool == 1); - } + /** + * Check if a path is valid UNIX path + * + * @since 0.2.0 + * @param string $path the path + * @return boolean true | false + */ + public static function valid_unix_dir_path($path) { + $reg = '/^(\/([a-zA-Z0-9+$_.-])+)*\/?$/'; + $bool = preg_match($reg, $path); + return ($bool == 1); + } - /** - * Check if a path is valid MS-windows or UNIX path - * @since 0.2.0 - * @param string $path the path - * @return boolean true | false - */ - public static function valid_path($path) { - return ( MUCD_Functions::valid_unix_dir_path($path) || MUCD_Functions::valid_windows_dir_path($path) ); - } + /** + * Check if a path is valid MS-windows or UNIX path + * + * @since 0.2.0 + * @param string $path the path + * @return boolean true | false + */ + public static function valid_path($path) { + return (self::valid_unix_dir_path($path) || self::valid_windows_dir_path($path)); + } - /** - * Removes completely a blog from the network - * @since 0.2.0 - * @param int $blog_id the blog id - */ - public static function remove_blog($blog_id) { - switch_to_blog($blog_id); - $wp_upload_info = wp_upload_dir(); - $dir = str_replace(' ', "\\ ", trailingslashit($wp_upload_info['basedir'])); - restore_current_blog(); + /** + * Removes completely a blog from the network + * + * @since 0.2.0 + * @param int $blog_id the blog id + */ + public static function remove_blog($blog_id) { + switch_to_blog($blog_id); + $wp_upload_info = wp_upload_dir(); + $dir = str_replace(' ', '\\ ', trailingslashit($wp_upload_info['basedir'])); + restore_current_blog(); - wpmu_delete_blog($blog_id, true); + wpmu_delete_blog($blog_id, true); - // wpmu_delete_blog leaves an empty site upload directory, that we want to remove : - MUCD_Files::rrmdir($dir); - } - - /** - * Check if site is duplicable - * @since 0.2.0 - * @param int $blog_id the blog id - * @return boolean true | false - */ - public static function is_duplicable($blog_id): bool { - if( get_site_option( 'mucd_duplicables', 'all', 'selected' ) == 'all') { - return true; - } + // wpmu_delete_blog leaves an empty site upload directory, that we want to remove : + MUCD_Files::rrmdir($dir); + } - if( get_blog_option( $blog_id, 'mucd_duplicable' , 'no' ) == 'yes') { - return true; - } - return false; - } + /** + * Check if site is duplicable + * + * @since 0.2.0 + * @param int $blog_id the blog id + * @return boolean true | false + */ + public static function is_duplicable($blog_id): bool { + if ( get_site_option('mucd_duplicables', 'all', 'selected') == 'all') { + return true; + } - /** - * Get all duplicable sites - * @since 0.2.0 - * @return array of blog data - */ - public static function get_site_list() { - $site_list = array(); - $network_blogs = MUCD_Functions::get_sites(apply_filters( 'mucd_get_site_list_args', array())); - foreach( $network_blogs as $blog ){ - if (MUCD_Functions::is_duplicable($blog['blog_id']) && MUCD_SITE_DUPLICATION_EXCLUDE != $blog['blog_id']) { - $site_list[] = $blog; - } + if ( get_blog_option($blog_id, 'mucd_duplicable', 'no') == 'yes') { + return true; + } + return false; + } - } + /** + * Get all duplicable sites + * + * @since 0.2.0 + * @return array of blog data + */ + public static function get_site_list() { + $site_list = array(); + $network_blogs = self::get_sites(apply_filters('mucd_get_site_list_args', array())); + foreach ( $network_blogs as $blog ) { + if (self::is_duplicable($blog['blog_id']) && MUCD_SITE_DUPLICATION_EXCLUDE != $blog['blog_id']) { + $site_list[] = $blog; + } + } - return $site_list; - } + return $site_list; + } - /** - * Check if a value is in an array for a specific key - * @since 0.2.0 - * @param mixte $value the value - * @param array $array the array - * @param string $key the key - * @return boolean true | false - */ - public static function value_in_array($value, $array, $key): bool { - foreach($array as $row) { - if(isset($row[$key]) && $value == $row[$key]) { - return true; - } - } - return false; - } + /** + * Check if a value is in an array for a specific key + * + * @since 0.2.0 + * @param mixte $value the value + * @param array $array the array + * @param string $key the key + * @return boolean true | false + */ + public static function value_in_array($value, $array, $key): bool { + foreach ($array as $row) { + if (isset($row[ $key ]) && $value == $row[ $key ]) { + return true; + } + } + return false; + } - /** - * Get upload directory of the entire network - * @since 0.2.0 - * @return string path of the upload directory - */ - public static function get_primary_upload_dir() { - $current_blog = get_current_blog_id(); - switch_to_blog(MUCD_PRIMARY_SITE_ID); - $wp_upload_info = wp_upload_dir(); - switch_to_blog($current_blog); + /** + * Get upload directory of the entire network + * + * @since 0.2.0 + * @return string path of the upload directory + */ + public static function get_primary_upload_dir() { + $current_blog = get_current_blog_id(); + switch_to_blog(MUCD_PRIMARY_SITE_ID); + $wp_upload_info = wp_upload_dir(); + switch_to_blog($current_blog); - return $wp_upload_info['basedir']; - } + return $wp_upload_info['basedir']; + } - /** - * Check if site exists - * @since 1.3.0 - * @param int $blog_id the blog id - * @return boolean true | false - */ - public static function site_exists($blog_id) { - return (get_blog_details($blog_id) !== false); - } + /** + * Check if site exists + * + * @since 1.3.0 + * @param int $blog_id the blog id + * @return boolean true | false + */ + public static function site_exists($blog_id) { + return (get_blog_details($blog_id) !== false); + } - /** - * Set locale to en_US - * @since 1.3.1 - */ - public static function set_locale_to_en_US() { + /** + * Set locale to en_US + * + * @since 1.3.1 + */ + public static function set_locale_to_en_US() { - // Bugfix Pierre Dargham : relocating this declaration outside of the call to add_filter - // PHP < 5.3 does not accept anonymous functions - function mucd_locale_en_us( $locale ): string { return 'en_US'; } + // Bugfix Pierre Dargham : relocating this declaration outside of the call to add_filter + // PHP < 5.3 does not accept anonymous functions + function mucd_locale_en_us($locale): string { + return 'en_US'; } - add_filter( 'locale', 'mucd_locale_en_us' ); - } + add_filter('locale', 'mucd_locale_en_us'); + } - /** - * Get network data for a given id. - * - * @author wp-cli - * @see https://github.com/wp-cli/wp-cli/blob/master/php/commands/site.php - * - * @param int $network_id - * @return bool|array False if no network found with given id, array otherwise - */ - public static function get_network( $network_id ) { - global $wpdb; + /** + * Get network data for a given id. + * + * @author wp-cli + * @see https://github.com/wp-cli/wp-cli/blob/master/php/commands/site.php + * + * @param int $network_id + * @return bool|array False if no network found with given id, array otherwise + */ + public static function get_network($network_id) { + global $wpdb; - // Load network data - $networks = $wpdb->get_results( $wpdb->prepare( - "SELECT * FROM $wpdb->site WHERE id = %d", $network_id ) ); + // Load network data + $networks = $wpdb->get_results( + $wpdb->prepare( + "SELECT * FROM $wpdb->site WHERE id = %d", + $network_id + ) + ); - if ( !empty( $networks ) ) { - // Only care about domain and path which are set here - return $networks[0]; - } + if ( ! empty($networks) ) { + // Only care about domain and path which are set here + return $networks[0]; + } - return false; - } + return false; + } - public static function get_sites( $args = array() ) { - if(version_compare(get_bloginfo('version'), '4.6', '>=')) { - $defaults = array('number' => MUCD_MAX_NUMBER_OF_SITE); - $args = wp_parse_args( $args, $defaults ); - $args = apply_filters( 'mucd_get_sites_args', $args ); - $sites = get_sites($args); - foreach($sites as $key => $site) { - $sites[$key] = (array) $site; - } - return $sites; - } else { - $defaults = array('limit' => MUCD_MAX_NUMBER_OF_SITE); - $args = apply_filters( 'mucd_get_sites_args', $args ); - $args = wp_parse_args( $args, $defaults ); - return wp_get_sites( $args ); - } - } + public static function get_sites($args = array()) { + if (version_compare(get_bloginfo('version'), '4.6', '>=')) { + $defaults = array('number' => MUCD_MAX_NUMBER_OF_SITE); + $args = wp_parse_args($args, $defaults); + $args = apply_filters('mucd_get_sites_args', $args); + $sites = get_sites($args); + foreach ($sites as $key => $site) { + $sites[ $key ] = (array) $site; + } + return $sites; + } else { + $defaults = array('limit' => MUCD_MAX_NUMBER_OF_SITE); + $args = apply_filters('mucd_get_sites_args', $args); + $args = wp_parse_args($args, $defaults); + return wp_get_sites($args); + } + } - /** - * Deactivate the plugin if we are not on a multisite installation - * @since 0.2.0 - */ - public static function check_if_multisite() { - if (!function_exists('is_multisite') || !is_multisite()) { - deactivate_plugins( plugin_basename( __FILE__ ) ); - wp_die('multisite-clone-duplicator works only for multisite installation'); - } - } + /** + * Deactivate the plugin if we are not on a multisite installation + * + * @since 0.2.0 + */ + public static function check_if_multisite() { + if ( ! function_exists('is_multisite') || ! is_multisite()) { + deactivate_plugins(plugin_basename(__FILE__)); + wp_die('multisite-clone-duplicator works only for multisite installation'); + } + } - /** - * Deactivate the plugin if we are not on the network admin - * @since 1.4.0 - */ - public static function check_if_network_admin() { - if (!is_network_admin() ) { - deactivate_plugins( plugin_basename( __FILE__ ) ); - wp_die('multisite-clone-duplicator works only as multisite network-wide plugin'); - } - } - - } -} \ No newline at end of file + /** + * Deactivate the plugin if we are not on the network admin + * + * @since 1.4.0 + */ + public static function check_if_network_admin() { + if ( ! is_network_admin() ) { + deactivate_plugins(plugin_basename(__FILE__)); + wp_die('multisite-clone-duplicator works only as multisite network-wide plugin'); + } + } + } +} diff --git a/inc/duplication/log.php b/inc/duplication/log.php index f82d654..a49a6ca 100644 --- a/inc/duplication/log.php +++ b/inc/duplication/log.php @@ -1,144 +1,153 @@ mod = $mod; - $this->log_dir_path = $log_dir_path; - $this->log_file_name = $log_file_name; - $this->log_file_path = $log_dir_path . $log_file_name; + /** + * Constructor + * + * @since 0.2.0 + * @param boolean $mod is log active + * @param string $log_dir_path log directory + * @param string $log_file_name log file name + */ + public function __construct($mod, $log_dir_path = '', $log_file_name = '') { + $this->mod = $mod; + $this->log_dir_path = $log_dir_path; + $this->log_file_name = $log_file_name; + $this->log_file_path = $log_dir_path . $log_file_name; - $this->log_file_url = str_replace(ABSPATH, get_site_url(1, '/'), $log_dir_path) . $log_file_name; + $this->log_file_url = str_replace(ABSPATH, get_site_url(1, '/'), $log_dir_path) . $log_file_name; - if( $mod !== false) { - $this->init_file(); - } - } + if ( $mod !== false) { + $this->init_file(); + } + } - /** - * Returns log directory path - * @since 0.2.0 - * @return string $this->log_dir_path - */ - public function dir_path() { - return $this->log_dir_path; - } + /** + * Returns log directory path + * + * @since 0.2.0 + * @return string $this->log_dir_path + */ + public function dir_path() { + return $this->log_dir_path; + } - /** - * Returns log file path - * @since 0.2.0 - * @return string $this->log_file_path - */ - public function file_path() { - return $this->log_file_path; - } + /** + * Returns log file path + * + * @since 0.2.0 + * @return string $this->log_file_path + */ + public function file_path() { + return $this->log_file_path; + } - /** - * Returns log file name - * @since 0.2.0 - * @return string $this->log_file_name - */ - public function file_name() { - return $this->log_file_name; - } + /** + * Returns log file name + * + * @since 0.2.0 + * @return string $this->log_file_name + */ + public function file_name() { + return $this->log_file_name; + } - /** - * Returns log file url - * @since 0.2.0 - * @return string $this->log_file_url - */ - public function file_url() { - return $this->log_file_url; - } + /** + * Returns log file url + * + * @since 0.2.0 + * @return string $this->log_file_url + */ + public function file_url() { + return $this->log_file_url; + } - /** - * Checks if log is writable - * @since 0.2.0 - * @return boolean True if plugin can writes the log, or false - */ - public function can_write() { - return ( is_resource($this->fp) && is_writable($this->log_file_path) ); - } + /** + * Checks if log is writable + * + * @since 0.2.0 + * @return boolean True if plugin can writes the log, or false + */ + public function can_write() { + return (is_resource($this->fp) && is_writable($this->log_file_path)); + } - /** - * Returns log mod (active or not) - * @since 0.2.0 - * @return boolean $this->mod - */ - public function mod() { - return $this->mod; - } + /** + * Returns log mod (active or not) + * + * @since 0.2.0 + * @return boolean $this->mod + */ + public function mod() { + return $this->mod; + } - /** - * Initialize file before writing - * @since 0.2.0 - * @return boolean True on success, False on failure - */ - private function init_file(): bool { - if(MUCD_Files::init_dir($this->log_dir_path) !==false) { - if( !$this->fp = @fopen($this->log_file_path, 'a') ) { - return false; - } - chmod($this->log_file_path, 0777); - return true; - } - return false; - } - - /** - * Writes a message in log file - * @since 0.2.0 - * @param string $message the message to write - * @return boolean True on success, False on failure - */ - public function write_log($message): bool { - if($this->mod!==false && $this->can_write() ) { - $time = @date('[d/M/Y:H:i:s]'); - fwrite($this->fp, "$time $message" . "\r\n"); - return true; - } - return false; - } + /** + * Initialize file before writing + * + * @since 0.2.0 + * @return boolean True on success, False on failure + */ + private function init_file(): bool { + if (MUCD_Files::init_dir($this->log_dir_path) !== false) { + if ( ! $this->fp = @fopen($this->log_file_path, 'a') ) { + return false; + } + chmod($this->log_file_path, 0777); + return true; + } + return false; + } - /** - * Closes the log file - * @since 0.2.0 - */ - public function close_log() { - @fclose($this->fp); - } + /** + * Writes a message in log file + * + * @since 0.2.0 + * @param string $message the message to write + * @return boolean True on success, False on failure + */ + public function write_log($message): bool { + if ($this->mod !== false && $this->can_write() ) { + $time = @date('[d/M/Y:H:i:s]'); + fwrite($this->fp, "$time $message" . "\r\n"); + return true; + } + return false; + } - } -} \ No newline at end of file + /** + * Closes the log file + * + * @since 0.2.0 + */ + public function close_log() { + @fclose($this->fp); + } + } +} diff --git a/inc/duplication/option.php b/inc/duplication/option.php index 77cf3f3..7ad345a 100644 --- a/inc/duplication/option.php +++ b/inc/duplication/option.php @@ -2,218 +2,214 @@ /** * Option management for the plugin */ -if ( !class_exists( 'MUCD_Option' ) ) { +if ( ! class_exists('MUCD_Option') ) { - class MUCD_Option { + class MUCD_Option { - /** - * Init 'mucd_duplicable' options - * - * @param string $blogs_value the value for blogs options - * @param string $network_value the value for site option - * @since 0.2.0 - */ - public static function init_duplicable_option($blogs_value = 'no', $network_value = 'all') { - $network_blogs = MUCD_Functions::get_sites(); - foreach ( $network_blogs as $blog ) { - $blog_id = $blog['blog_id']; - add_blog_option( $blog_id, 'mucd_duplicable', $blogs_value); - } // end foreach; - add_site_option( 'mucd_duplicables', $network_value ); - } // end init_duplicable_option; + /** + * Init 'mucd_duplicable' options + * + * @param string $blogs_value the value for blogs options + * @param string $network_value the value for site option + * @since 0.2.0 + */ + public static function init_duplicable_option($blogs_value = 'no', $network_value = 'all') { + $network_blogs = MUCD_Functions::get_sites(); + foreach ( $network_blogs as $blog ) { + $blog_id = $blog['blog_id']; + add_blog_option($blog_id, 'mucd_duplicable', $blogs_value); + } + add_site_option('mucd_duplicables', $network_value); + } - /** - * Delete 'mucd_duplicable' option for all sites - * - * @since 0.2.0 - */ - public static function delete_duplicable_option() { - $network_blogs = MUCD_Functions::get_sites(); - foreach ( $network_blogs as $blog ) { - $blog_id = $blog['blog_id']; - delete_blog_option( $blog_id, 'mucd_duplicable'); - } // end foreach; - delete_site_option( 'mucd_duplicables'); - } // end delete_duplicable_option; + /** + * Delete 'mucd_duplicable' option for all sites + * + * @since 0.2.0 + */ + public static function delete_duplicable_option() { + $network_blogs = MUCD_Functions::get_sites(); + foreach ( $network_blogs as $blog ) { + $blog_id = $blog['blog_id']; + delete_blog_option($blog_id, 'mucd_duplicable'); + } + delete_site_option('mucd_duplicables'); + } - /** - * Set 'mucd_duplicable' option to "yes" for the list of blogs, other to "no" - * - * @since 0.2.0 - * @param array $blogs list of blogs we want the option set to "yes" - */ - public static function set_duplicable_option($blogs) { - $network_blogs = MUCD_Functions::get_sites(); - foreach ( $network_blogs as $blog ) { - if (in_array($blog['blog_id'], $blogs)) { - update_blog_option( $blog['blog_id'], 'mucd_duplicable', 'yes'); - } else { - update_blog_option($blog['blog_id'], 'mucd_duplicable', 'no'); - } // end if; - } // end foreach; - } // end set_duplicable_option; + /** + * Set 'mucd_duplicable' option to "yes" for the list of blogs, other to "no" + * + * @since 0.2.0 + * @param array $blogs list of blogs we want the option set to "yes" + */ + public static function set_duplicable_option($blogs) { + $network_blogs = MUCD_Functions::get_sites(); + foreach ( $network_blogs as $blog ) { + if (in_array($blog['blog_id'], $blogs)) { + update_blog_option($blog['blog_id'], 'mucd_duplicable', 'yes'); + } else { + update_blog_option($blog['blog_id'], 'mucd_duplicable', 'no'); + } + } + } - /** - * Add plugin default options - * - * @since 1.3.0 - */ - public static function init_options() { - add_site_option('mucd_copy_files', 'yes'); - add_site_option('mucd_keep_users', 'yes'); - add_site_option('mucd_log', 'no'); - $upload_dir = wp_upload_dir(); - add_site_option('mucd_log_dir', $upload_dir['basedir'] . '/multisite-clone-duplicator-logs/'); - add_site_option('mucd_disable_enhanced_site_select', 'no'); - MUCD_Option::init_duplicable_option(); - } // end init_options; + /** + * Add plugin default options + * + * @since 1.3.0 + */ + public static function init_options() { + add_site_option('mucd_copy_files', 'yes'); + add_site_option('mucd_keep_users', 'yes'); + add_site_option('mucd_log', 'no'); + $upload_dir = wp_upload_dir(); + add_site_option('mucd_log_dir', $upload_dir['basedir'] . '/multisite-clone-duplicator-logs/'); + add_site_option('mucd_disable_enhanced_site_select', 'no'); + self::init_duplicable_option(); + } - /** - * Removes plugin options - * - * @since 1.3.0 - */ - public static function delete_options() { - delete_site_option('mucd_copy_files'); - delete_site_option('mucd_keep_users'); - delete_site_option('mucd_log'); - delete_site_option('mucd_log_dir'); - delete_site_option('mucd_disable_enhanced_site_select'); - MUCD_Option::delete_duplicable_option(); - } // end delete_options; + /** + * Removes plugin options + * + * @since 1.3.0 + */ + public static function delete_options() { + delete_site_option('mucd_copy_files'); + delete_site_option('mucd_keep_users'); + delete_site_option('mucd_log'); + delete_site_option('mucd_log_dir'); + delete_site_option('mucd_disable_enhanced_site_select'); + self::delete_duplicable_option(); + } - /** - * Get log directory option - * - * @since 0.2.0 - * @return string the path - */ - public static function get_option_log_directory() { - $upload_dir = wp_upload_dir(); - return get_site_option('mucd_log_dir', $upload_dir['basedir'] . '/multisite-clone-duplicator-logs/'); - } // end get_option_log_directory; + /** + * Get log directory option + * + * @since 0.2.0 + * @return string the path + */ + public static function get_option_log_directory() { + $upload_dir = wp_upload_dir(); + return get_site_option('mucd_log_dir', $upload_dir['basedir'] . '/multisite-clone-duplicator-logs/'); + } - /** - * Get directories to exclude from file copy when duplicated site is primary site - * - * @since 0.2.0 - * @return array of string - */ - public static function get_primary_dir_exclude() { - return array( - 'sites', - ); - } // end get_primary_dir_exclude; + /** + * Get directories to exclude from file copy when duplicated site is primary site + * + * @since 0.2.0 + * @return array of string + */ + public static function get_primary_dir_exclude() { + return array( + 'sites', + ); + } - /** - * Get default options that should be preserved in the new blog. - * - * @since 0.2.0 - * @return array of string - */ - public static function get_default_saved_option() { - return array( - 'siteurl' => '', - 'home' => '', - 'upload_path' => '', - 'fileupload_url' => '', - 'upload_url_path' => '', - 'admin_email' => '', - 'blogname' => '', - 'schema-ActionScheduler_Abstract_Schema' => '', - 'action_scheduler_hybrid_store_demarkation' => '', - 'schema-ActionScheduler_StoreSchema' => '', - 'schema-ActionScheduler_LoggerSchema' => '', - 'action_scheduler_lock_async-request-runner' => '', - ); - } // end get_default_saved_option; + /** + * Get default options that should be preserved in the new blog. + * + * @since 0.2.0 + * @return array of string + */ + public static function get_default_saved_option() { + return array( + 'siteurl' => '', + 'home' => '', + 'upload_path' => '', + 'fileupload_url' => '', + 'upload_url_path' => '', + 'admin_email' => '', + 'blogname' => '', + 'schema-ActionScheduler_Abstract_Schema' => '', + 'action_scheduler_hybrid_store_demarkation' => '', + 'schema-ActionScheduler_StoreSchema' => '', + 'schema-ActionScheduler_LoggerSchema' => '', + 'action_scheduler_lock_async-request-runner' => '', + ); + } - /** - * Get filtered options that should be preserved in the new blog. - * - * @since 0.2.0 - * @return array of string (filtered) - */ - public static function get_saved_option() { - return apply_filters('mucd_copy_blog_data_saved_options', MUCD_Option::get_default_saved_option()); - } // end get_saved_option; + /** + * Get filtered options that should be preserved in the new blog. + * + * @since 0.2.0 + * @return array of string (filtered) + */ + public static function get_saved_option() { + return apply_filters('mucd_copy_blog_data_saved_options', self::get_default_saved_option()); + } - /** - * Get default fields to scan for an update after data copy - * - * @since 0.2.0 - * @return array '%table_name' => array('%field_name_1','%field_name_2','%field_name_3', ...) - */ - public static function get_default_fields_to_update() { - return array ( - 'commentmeta' => array(), - 'comments' => array(), - 'links' => array('link_url', 'link_image'), - 'options' => array('option_name', 'option_value'), - 'postmeta' => array('meta_value'), - 'posts' => array('post_content', 'guid', 'post_title', 'post_name'), - 'terms' => array(), - 'term_relationships' => array(), - 'term_taxonomy' => array(), - ); - } // end get_default_fields_to_update; + /** + * Get default fields to scan for an update after data copy + * + * @since 0.2.0 + * @return array '%table_name' => array('%field_name_1','%field_name_2','%field_name_3', ...) + */ + public static function get_default_fields_to_update() { + return array( + 'commentmeta' => array(), + 'comments' => array(), + 'links' => array('link_url', 'link_image'), + 'options' => array('option_name', 'option_value'), + 'postmeta' => array('meta_value'), + 'posts' => array('post_content', 'guid', 'post_title', 'post_name'), + 'terms' => array(), + 'term_relationships' => array(), + 'term_taxonomy' => array(), + ); + } - /** - * Get filtered fields to scan for an update after data copy - * - * @since 0.2.0 - * @return array of string (filtered) - */ - public static function get_fields_to_update() { - return apply_filters('mucd_default_fields_to_update', MUCD_Option::get_default_fields_to_update()); - } // end get_fields_to_update; + /** + * Get filtered fields to scan for an update after data copy + * + * @since 0.2.0 + * @return array of string (filtered) + */ + public static function get_fields_to_update() { + return apply_filters('mucd_default_fields_to_update', self::get_default_fields_to_update()); + } - /** - * Get default tables to duplicate when duplicated site is primary site - * - * @since 0.2.0 - * @return array of string - */ - public static function get_default_primary_tables_to_copy() { - return array ( - 'commentmeta', - 'comments', - 'links', - 'options', - 'postmeta', - 'posts', - 'terms', - 'term_relationships', - 'term_taxonomy', - 'termmeta', - ); - } // end get_default_primary_tables_to_copy; + /** + * Get default tables to duplicate when duplicated site is primary site + * + * @since 0.2.0 + * @return array of string + */ + public static function get_default_primary_tables_to_copy() { + return array( + 'commentmeta', + 'comments', + 'links', + 'options', + 'postmeta', + 'posts', + 'terms', + 'term_relationships', + 'term_taxonomy', + 'termmeta', + ); + } - /** - * Get filtered tables to duplicate when duplicated site is primary site - * - * @since 0.2.0 - * @return array of string (filtered) - */ - public static function get_primary_tables_to_copy() { - return apply_filters('mucd_default_primary_tables_to_copy', MUCD_Option::get_default_primary_tables_to_copy()); - } // end get_primary_tables_to_copy; - - - } // end class MUCD_Option; - -} // end if; - + /** + * Get filtered tables to duplicate when duplicated site is primary site + * + * @since 0.2.0 + * @return array of string (filtered) + */ + public static function get_primary_tables_to_copy() { + return apply_filters('mucd_default_primary_tables_to_copy', self::get_default_primary_tables_to_copy()); + } + } +} diff --git a/inc/exception/class-runtime-exception.php b/inc/exception/class-runtime-exception.php index a75c942..4bb42d5 100644 --- a/inc/exception/class-runtime-exception.php +++ b/inc/exception/class-runtime-exception.php @@ -16,4 +16,4 @@ defined('ABSPATH') || exit; * * @since 2.0.11 */ -class Runtime_Exception extends \Exception {} // end class Runtime_Exception; +class Runtime_Exception extends \Exception {} diff --git a/inc/functions/admin.php b/inc/functions/admin.php index 027336d..ea5d21d 100644 --- a/inc/functions/admin.php +++ b/inc/functions/admin.php @@ -19,19 +19,21 @@ defined('ABSPATH') || exit; */ function wu_render_empty_state($args = array()) { - $args = wp_parse_args($args, array( - 'message' => __('This is not yet available...'), - 'sub_message' => __('We\'re still working on this part of the product.'), - 'link_label' => __('← Go Back', 'wp-ultimo'), - 'link_url' => 'javascript:history.go(-1)', - 'link_classes' => '', - 'link_icon' => '', - 'display_background_image' => true, - )); + $args = wp_parse_args( + $args, + array( + 'message' => __('This is not yet available...'), + 'sub_message' => __('We\'re still working on this part of the product.'), + 'link_label' => __('← Go Back', 'wp-ultimo'), + 'link_url' => 'javascript:history.go(-1)', + 'link_classes' => '', + 'link_icon' => '', + 'display_background_image' => true, + ) + ); return wu_get_template_contents('base/empty-state', $args); - -} // end wu_render_empty_state; +} /** * Checks if should use wrap container or not based on user setting. @@ -41,8 +43,7 @@ function wu_render_empty_state($args = array()) { function wu_wrap_use_container() { echo get_user_setting('wu_use_container', false) ? 'admin-lg:wu-container admin-lg:wu-mx-auto' : ''; - -} // end wu_wrap_use_container; +} /** * Renders the responsive table single-line. @@ -56,14 +57,16 @@ function wu_wrap_use_container() { */ function wu_responsive_table_row($args = array(), $first_row = array(), $second_row = array()) { - $args = wp_parse_args($args, array( - 'id' => '', - 'title' => __('No Title', 'wp-ultimo'), - 'url' => '#', - 'status' => '', - 'image' => '', - )); + $args = wp_parse_args( + $args, + array( + 'id' => '', + 'title' => __('No Title', 'wp-ultimo'), + 'url' => '#', + 'status' => '', + 'image' => '', + ) + ); return wu_get_template_contents('base/responsive-table-row', compact('args', 'first_row', 'second_row')); - -} // end wu_responsive_table_row; +} diff --git a/inc/functions/array-helpers.php b/inc/functions/array-helpers.php index 86344ee..17e4ea6 100644 --- a/inc/functions/array-helpers.php +++ b/inc/functions/array-helpers.php @@ -9,7 +9,7 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Helpers\Arr; +use WP_Ultimo\Helpers\Arr; /** * Turns a multi-dimensional array into a flat array. @@ -24,21 +24,20 @@ function wu_array_flatten($array, $indexes = false) { $return = array(); - array_walk_recursive($array, function($x, $index) use (&$return, $indexes) { + array_walk_recursive( + $array, + function ($x, $index) use (&$return, $indexes) { - if ($indexes) { + if ($indexes) { + $return[] = $index; + } - $return[] = $index; - - } // end if; - - $return[] = $x; - - }); + $return[] = $x; + } + ); return $return; - -} // end wu_array_flatten; +} /** * Copy from http://www.php.net/manual/en/function.array-merge-recursive.php#92195 @@ -74,30 +73,17 @@ function wu_array_merge_recursive_distinct(array &$array1, array &$array2, $shou $merged = $array1; foreach ($array2 as $key => &$value) { - - if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) { - - $merged[$key] = wu_array_merge_recursive_distinct($merged[$key], $value, $should_sum); - + if (is_array($value) && isset($merged[ $key ]) && is_array($merged[ $key ])) { + $merged[ $key ] = wu_array_merge_recursive_distinct($merged[ $key ], $value, $should_sum); + } elseif (isset($merged[ $key ]) && is_numeric($merged[ $key ]) && is_numeric($value) && $should_sum) { + $merged[ $key ] = ((int) $merged[ $key ]) + $value; } else { - - if (isset($merged[$key]) && is_numeric($merged[$key]) && is_numeric($value) && $should_sum) { - - $merged[$key] = ((int) $merged[$key]) + $value; - - } else { - - $merged[$key] = $value; - - } // end if; - - } // end if; - - } // end foreach; + $merged[ $key ] = $value; + } + } return $merged; - -} // end wu_array_merge_recursive_distinct; +} /** * Compares two arrays and returns the diff, recursively. @@ -121,40 +107,25 @@ function wu_array_recursive_diff($array1, $array2, $to_keep = array()) { $array2 = (array) $array2; foreach ($array1 as $key => $value) { - if (array_key_exists($key, $array2)) { - if (is_array($value)) { - - $array_recursive_diff = wu_array_recursive_diff($value, $array2[$key], $to_keep); + $array_recursive_diff = wu_array_recursive_diff($value, $array2[ $key ], $to_keep); if (count($array_recursive_diff)) { + $arr_return[ $key ] = $array_recursive_diff; + } + } elseif ((! is_null($value) && $value != $array2[ $key ]) || ($value && $array2[ $key ] && in_array($key, $to_keep, true))) { + // phpcs:ignore - $arr_return[$key] = $array_recursive_diff; - - } // end if; - - } else { - - if ((!is_null($value) && $value != $array2[$key]) || ($value && $array2[$key] && in_array($key, $to_keep, true))) { // phpcs:ignore - - $arr_return[$key] = $value; - - } // end if; - - } // end if; - + $arr_return[ $key ] = $value; + } } else { - - $arr_return[$key] = $value; - - } // end if; - - } // end foreach; + $arr_return[ $key ] = $value; + } + } return $arr_return; - -} // end wu_array_recursive_diff; +} /** * Array map implementation to deal with keys. * @@ -170,8 +141,7 @@ function wu_array_map_keys($callable, $array): array { $keys = array_map($callable, $keys); return array_combine($keys, $array); - -} // end wu_array_map_keys; +} /** * Converts a key => value array into an array of objects with key and value entries. @@ -208,17 +178,14 @@ function wu_key_map_to_array($assoc_array, $key_name = 'id', $value_name = 'valu $results = array(); foreach ($assoc_array as $key => &$value) { - $results[] = array( $key_name => $key, $value_name => $value, ); - - } // end foreach; + } return $results; - -} // end wu_key_map_to_array; +} /** * Find a value inside an array by a particular key or property. @@ -236,8 +203,7 @@ function wu_key_map_to_array($assoc_array, $key_name = 'id', $value_name = 'valu function wu_array_find_by($array, $property, $expected, $flag = 0) { return Arr::filter_by_property($array, $property, $expected, $flag); - -} // end wu_array_find_by; +} /** * Finds all the values inside an array by a particular key or property. @@ -254,8 +220,7 @@ function wu_array_find_by($array, $property, $expected, $flag = 0) { function wu_array_find_all_by($array, $property, $expected) { return wu_array_find_by($array, $property, $expected, Arr::RESULTS_ALL); - -} // end wu_array_find_all_by; +} /** * Finds the first value inside an array by a particular key or property. @@ -272,8 +237,7 @@ function wu_array_find_all_by($array, $property, $expected) { function wu_array_find_first_by($array, $property, $expected) { return wu_array_find_by($array, $property, $expected, Arr::RESULTS_FIRST); - -} // end wu_array_find_first_by; +} /** * Finds the last value inside an array by a particular key or property. @@ -290,5 +254,4 @@ function wu_array_find_first_by($array, $property, $expected) { function wu_array_find_last_by($array, $property, $expected) { return wu_array_find_by($array, $property, $expected, Arr::RESULTS_LAST); - -} // end wu_array_find_last_by; +} diff --git a/inc/functions/assets.php b/inc/functions/assets.php index a814453..d2c1151 100644 --- a/inc/functions/assets.php +++ b/inc/functions/assets.php @@ -21,12 +21,9 @@ defined('ABSPATH') || exit; */ function wu_get_asset($asset, $assets_dir = 'img', $base_dir = 'assets') { - if (!defined('SCRIPT_DEBUG') || !SCRIPT_DEBUG) { - + if ( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG) { $asset = preg_replace('/(? 1, @@ -64,9 +59,8 @@ function wu_get_broadcast_by($column, $value) { $results = \WP_Ultimo\Models\Broadcast::query($query); - return !empty($results) ? array_pop($results) : false; - -} // end wu_get_broadcast_by; + return ! empty($results) ? array_pop($results) : false; +} /** * Gets a broadcast on the ID. @@ -79,8 +73,7 @@ function wu_get_broadcast_by($column, $value) { function wu_get_broadcast($broadcast_id) { return \WP_Ultimo\Models\Broadcast::get_by_id($broadcast_id); - -} // end wu_get_broadcast; +} /** * Gets a broadcast on the ID. @@ -97,19 +90,14 @@ function wu_get_broadcast_targets($broadcast_id, $type) { $targets = $object->get_message_targets(); - if (is_array($targets[$type])) { - - return $targets[$type]; - - } elseif (is_string($targets[$type])) { - - return explode(',', $targets[$type]); - - } // end if; + if (is_array($targets[ $type ])) { + return $targets[ $type ]; + } elseif (is_string($targets[ $type ])) { + return explode(',', $targets[ $type ]); + } return array(); - -} // end wu_get_broadcast_targets; +} /** * Creates a new broadcast. @@ -123,23 +111,25 @@ function wu_get_broadcast_targets($broadcast_id, $type) { */ function wu_create_broadcast($broadcast_data) { - $broadcast_data = wp_parse_args($broadcast_data, array( - 'type' => 'broadcast_notice', - 'notice_type' => 'success', - 'date_created' => wu_get_current_time('mysql', true), - 'date_modified' => wu_get_current_time('mysql', true), - 'migrated_from_id' => 0, - 'skip_validation' => false, - 'message_targets' => array( - 'customers' => array(), - 'products' => array(), - ), - )); + $broadcast_data = wp_parse_args( + $broadcast_data, + array( + 'type' => 'broadcast_notice', + 'notice_type' => 'success', + 'date_created' => wu_get_current_time('mysql', true), + 'date_modified' => wu_get_current_time('mysql', true), + 'migrated_from_id' => 0, + 'skip_validation' => false, + 'message_targets' => array( + 'customers' => array(), + 'products' => array(), + ), + ) + ); $broadcast = new Broadcast($broadcast_data); $saved = $broadcast->save(); return is_wp_error($saved) ? $saved : $broadcast; - -} // end wu_create_broadcast; +} diff --git a/inc/functions/checkout-form.php b/inc/functions/checkout-form.php index a46ac7d..91818d0 100644 --- a/inc/functions/checkout-form.php +++ b/inc/functions/checkout-form.php @@ -9,8 +9,8 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Checkout\Checkout; -use \WP_Ultimo\Models\Checkout_Form; +use WP_Ultimo\Checkout\Checkout; +use WP_Ultimo\Models\Checkout_Form; /** * Returns a checkout_form. @@ -23,8 +23,7 @@ use \WP_Ultimo\Models\Checkout_Form; function wu_get_checkout_form($checkout_form_id) { return \WP_Ultimo\Models\Checkout_Form::get_by_id($checkout_form_id); - -} // end wu_get_checkout_form; +} /** * Queries checkout_forms. @@ -37,8 +36,7 @@ function wu_get_checkout_form($checkout_form_id) { function wu_get_checkout_forms($query = array()) { return \WP_Ultimo\Models\Checkout_Form::query($query); - -} // end wu_get_checkout_forms; +} /** * Returns a checkout_form based on slug. * @@ -59,40 +57,33 @@ function wu_get_checkout_form_by_slug($checkout_form_slug) { * @see wu_checkout_form_membership_change_form_fields filter. */ if ($checkout_form_slug === 'wu-checkout') { - - $checkout_form = new \WP_Ultimo\Models\Checkout_Form; + $checkout_form = new \WP_Ultimo\Models\Checkout_Form(); $checkout_fields = Checkout_Form::membership_change_form_fields(); $checkout_form->set_settings($checkout_fields); return $checkout_form; - } elseif ($checkout_form_slug === 'wu-add-new-site') { - - $checkout_form = new \WP_Ultimo\Models\Checkout_Form; + $checkout_form = new \WP_Ultimo\Models\Checkout_Form(); $checkout_fields = Checkout_Form::add_new_site_form_fields(); $checkout_form->set_settings($checkout_fields); return $checkout_form; - } elseif ($checkout_form_slug === 'wu-finish-checkout') { - - $checkout_form = new \WP_Ultimo\Models\Checkout_Form; + $checkout_form = new \WP_Ultimo\Models\Checkout_Form(); $checkout_fields = Checkout_Form::finish_checkout_form_fields(); $checkout_form->set_settings($checkout_fields); return $checkout_form; - - } // end if; + } return \WP_Ultimo\Models\Checkout_Form::get_by('slug', $checkout_form_slug); - -} // end wu_get_checkout_form_by_slug; +} /** * Creates a new checkout form. * @@ -103,22 +94,24 @@ function wu_get_checkout_form_by_slug($checkout_form_slug) { */ function wu_create_checkout_form($checkout_form_data) { - $checkout_form_data = wp_parse_args($checkout_form_data, array( - 'name' => false, - 'slug' => false, - 'settings' => array(), - 'allowed_countries' => array(), - 'date_created' => wu_get_current_time('mysql', true), - 'date_modified' => wu_get_current_time('mysql', true), - )); + $checkout_form_data = wp_parse_args( + $checkout_form_data, + array( + 'name' => false, + 'slug' => false, + 'settings' => array(), + 'allowed_countries' => array(), + 'date_created' => wu_get_current_time('mysql', true), + 'date_modified' => wu_get_current_time('mysql', true), + ) + ); $checkout_form = new Checkout_Form($checkout_form_data); $saved = $checkout_form->save(); return is_wp_error($saved) ? $saved : $checkout_form; - -} // end wu_create_checkout_form; +} /** * Returns a list of all the available domain options in all registered forms. @@ -133,46 +126,35 @@ function wu_get_available_domain_options() { $main_form = wu_get_checkout_form_by_slug('main-form'); if ($main_form) { - $fields = $main_form->get_all_fields_by_type('site_url'); - } else { - - $forms = wu_get_checkout_forms(array( - 'number' => 1, - )); + $forms = wu_get_checkout_forms( + array( + 'number' => 1, + ) + ); if ($forms) { - $fields = $forms[0]->get_all_fields_by_type('site_url'); - - } // end if; - - } // end if; + } + } $domain_options = array(); if ($fields) { - foreach ($fields as $field) { - $available_domains = isset($field['available_domains']) ? $field['available_domains'] : ''; $field_domain_options = explode(PHP_EOL, (string) $available_domains); if (isset($field['enable_domain_selection']) && $field['enable_domain_selection'] && $field_domain_options) { - $domain_options = array_merge($domain_options, $field_domain_options); - - } // end if; - - } // end foreach; - - } // end if; + } + } + } return $domain_options; - -} // end wu_get_available_domain_options; +} /** * Check if the field is preselected in request. @@ -187,11 +169,10 @@ function wu_is_form_field_pre_selected($field_slug) { $pre_selected = $checkout->request_or_session('pre_selected', array()); - $from_request = stripslashes_deep(wu_get_isset($_GET, $field_slug)) || isset($pre_selected[$field_slug]); + $from_request = stripslashes_deep(wu_get_isset($_GET, $field_slug)) || isset($pre_selected[ $field_slug ]); return wu_request('wu_preselected') === $field_slug || $from_request; - -} // end wu_is_form_field_pre_selected; +} /** * Get the request arg slug from a field. @@ -203,20 +184,15 @@ function wu_is_form_field_pre_selected($field_slug) { function wu_form_field_request_arg($field) { if ($field['type'] === 'template_selection') { - return 'template_id'; - - } // end if; + } if ($field['type'] === 'pricing_table') { - return 'products'; - - } // end if; + } return $field['id']; - -} // end wu_form_field_request_arg; +} /** * Check if the field should be hidden in form @@ -230,5 +206,4 @@ function wu_should_hide_form_field($field) { $hide_preselect = (bool) (int) wu_get_isset($field, "hide_{$field['type']}_when_pre_selected"); return $hide_preselect && wu_is_form_field_pre_selected(wu_form_field_request_arg($field)); - -} // end wu_should_hide_form_field; +} diff --git a/inc/functions/checkout.php b/inc/functions/checkout.php index d34ce88..166089a 100644 --- a/inc/functions/checkout.php +++ b/inc/functions/checkout.php @@ -9,7 +9,7 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Managers\Signup_Fields_Manager; +use WP_Ultimo\Managers\Signup_Fields_Manager; /** * Needs to be removed. @@ -22,15 +22,12 @@ function wu_errors() { global $wu_errors; - if (!is_wp_error($wu_errors)) { - + if ( ! is_wp_error($wu_errors)) { $wu_errors = new \WP_Error(); - - } // end if; + } return $wu_errors; - -} // end wu_errors; +} /** * Generate an idempotency key. @@ -57,8 +54,7 @@ function wu_stripe_generate_idempotency_key($args, $context = 'new') { $idempotency_key = apply_filters('wu_stripe_generate_idempotency_key', $idempotency_key, $args, $context); return $idempotency_key; - -} // end wu_stripe_generate_idempotency_key; +} /** * Loops through the signup field types to return the checkout fields. @@ -75,31 +71,22 @@ function wu_create_checkout_fields($fields = array()) { $actual_fields = array(); // Extra check to prevent error messages from being displayed. - if (!is_array($fields)) { - + if ( ! is_array($fields)) { $fields = array(); - - } // end if; + } foreach ($fields as $field) { - $type = $field['type']; - if (!wu_get_isset($field_types, $type)) { - + if ( ! wu_get_isset($field_types, $type)) { continue; - - } // end if; + } try { - - $field_class = new $field_types[$type](); - + $field_class = new $field_types[ $type ](); } catch (\Throwable $exception) { - continue; - - } // end try; + } $field = wp_parse_args($field, $field_class->defaults()); @@ -111,20 +98,14 @@ function wu_create_checkout_fields($fields = array()) { $visibility = wu_get_isset($field, 'logged', 'always'); if ($visibility !== 'always') { - if ($visibility === 'guests_only' && is_user_logged_in()) { - continue; + } - } // end if; - - if ($visibility === 'logged_only' && !is_user_logged_in()) { - + if ($visibility === 'logged_only' && ! is_user_logged_in()) { continue; - - } // end if; - - } // end if; + } + } /* * Pass the attributes down to the field class. @@ -134,10 +115,13 @@ function wu_create_checkout_fields($fields = array()) { /* * Makes sure we have default indexes. */ - $field = wp_parse_args($field, array( - 'element_classes' => '', - 'classes' => '', - )); + $field = wp_parse_args( + $field, + array( + 'element_classes' => '', + 'classes' => '', + ) + ); $field_array = $field_class->to_fields_array($field); @@ -150,12 +134,10 @@ function wu_create_checkout_fields($fields = array()) { do_action("wu_checkout_add_field_{$field_class->get_type()}", $field_array); $actual_fields = array_merge($actual_fields, $field_array); - - } // end foreach; + } return $actual_fields; - -} // end wu_create_checkout_fields; +} /** * Returns the URL for the registration page. @@ -170,31 +152,28 @@ function wu_get_registration_url($path = false) { $url = $checkout_pages->get_page_url('register'); - if (!$url) { + if ( ! $url) { /** * Just to be extra sure, we try to fetch the URL * for a main site page that has the registration slug. */ - $url = wu_switch_blog_and_run(function() { + $url = wu_switch_blog_and_run( + function () { - $maybe_register_page = get_page_by_path('register'); - - if ($maybe_register_page && has_shortcode($maybe_register_page->post_content, 'wu_checkout')) { - - return get_the_permalink($maybe_register_page->ID); + $maybe_register_page = get_page_by_path('register'); + if ($maybe_register_page && has_shortcode($maybe_register_page->post_content, 'wu_checkout')) { + return get_the_permalink($maybe_register_page->ID); + } } - - }); + ); return $url ?? '#no-registration-url'; - - } // end if; + } return $url . $path; - -} // end wu_get_registration_url; +} /** * Returns the URL for the login page. * @@ -207,15 +186,12 @@ function wu_get_login_url($path = false): string { $url = $checkout_pages->get_page_url('login'); - if (!$url) { - + if ( ! $url) { return '#no-login-url'; - - } // end if; + } return $url . $path; - -} // end wu_get_login_url; +} /** * Checks if we allow for multiple memberships. @@ -227,8 +203,7 @@ function wu_get_login_url($path = false): string { function wu_multiple_memberships_enabled() { return wu_get_setting('enable_multiple_memberships', true); - -} // end wu_multiple_memberships_enabled; +} /** * Get the number of days in a billing cycle. @@ -246,26 +221,25 @@ function wu_get_days_in_cycle($duration_unit, $duration) { $days_in_cycle = 0; switch ($duration_unit) { - case 'day': - $days_in_cycle = $duration; - break; - case 'week': - $days_in_cycle = $duration * 7; - break; - case 'month': - $days_in_cycle = $duration * 30.4375; - break; - case 'year': - $days_in_cycle = $duration * 365.25; - break; - default: - $days_in_cycle = $days_in_cycle; - break; - } // end switch; + case 'day': + $days_in_cycle = $duration; + break; + case 'week': + $days_in_cycle = $duration * 7; + break; + case 'month': + $days_in_cycle = $duration * 30.4375; + break; + case 'year': + $days_in_cycle = $duration * 365.25; + break; + default: + $days_in_cycle = $days_in_cycle; + break; + } return $days_in_cycle; - -} // end wu_get_days_in_cycle; +} /** * Register a new field type. @@ -283,15 +257,16 @@ function wu_get_days_in_cycle($duration_unit, $duration) { */ function wu_register_field_type($field_type_id, $field_type_class_name) { - add_filter('wu_checkout_field_types', function($field_types) use ($field_type_id, $field_type_class_name) { + add_filter( + 'wu_checkout_field_types', + function ($field_types) use ($field_type_id, $field_type_class_name) { - $field_types[$field_type_id] = $field_type_class_name; + $field_types[ $field_type_id ] = $field_type_class_name; - return $field_types; - - }); - -} // end wu_register_field_type; + return $field_types; + } + ); +} /** * Register a new field template for a field type. @@ -311,16 +286,17 @@ function wu_register_field_type($field_type_id, $field_type_class_name) { */ function wu_register_field_template($field_type, $field_template_id, $field_template_class_name) { - add_filter('wu_checkout_field_templates', function($field_templates) use ($field_type, $field_template_id, $field_template_class_name) { + add_filter( + 'wu_checkout_field_templates', + function ($field_templates) use ($field_type, $field_template_id, $field_template_class_name) { - $field_templates_for_field_type = wu_get_isset($field_templates, $field_type, array()); + $field_templates_for_field_type = wu_get_isset($field_templates, $field_type, array()); - $field_templates_for_field_type[$field_template_id] = $field_template_class_name; + $field_templates_for_field_type[ $field_template_id ] = $field_template_class_name; - $field_templates[$field_type] = $field_templates_for_field_type; + $field_templates[ $field_type ] = $field_templates_for_field_type; - return $field_templates; - - }); - -} // end wu_register_field_template; + return $field_templates; + } + ); +} diff --git a/inc/functions/color.php b/inc/functions/color.php index 9bbcba1..5c964f1 100644 --- a/inc/functions/color.php +++ b/inc/functions/color.php @@ -14,7 +14,7 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \Mexitek\PHPColors\Color; +use Mexitek\PHPColors\Color; /** * Returns a Color object. @@ -27,18 +27,13 @@ use \Mexitek\PHPColors\Color; function wu_color($hex) { try { - $color = new Color($hex); - } catch (Exception $exception) { - $color = new Color('#f9f9f9'); - - } // end try; + } return $color; - -} // end wu_color; +} /** * Gets a random color for the progress bar. @@ -61,5 +56,4 @@ function wu_get_random_color($index) { ); return wu_get_isset($colors, $index, $colors[ rand(0, count($colors) - 1) ]); - -} // end wu_get_random_color; +} diff --git a/inc/functions/countries.php b/inc/functions/countries.php index 951b36c..35c9587 100644 --- a/inc/functions/countries.php +++ b/inc/functions/countries.php @@ -17,259 +17,261 @@ defined('ABSPATH') || exit; */ function wu_get_countries() { - return apply_filters('wu_get_countries', array( - 'AF' => __('Afghanistan', 'wp-ultimo-locations'), - 'AX' => __('Åland Islands', 'wp-ultimo-locations'), - 'AL' => __('Albania', 'wp-ultimo-locations'), - 'DZ' => __('Algeria', 'wp-ultimo-locations'), - 'AS' => __('American Samoa', 'wp-ultimo-locations'), - 'AD' => __('Andorra', 'wp-ultimo-locations'), - 'AO' => __('Angola', 'wp-ultimo-locations'), - 'AI' => __('Anguilla', 'wp-ultimo-locations'), - 'AQ' => __('Antarctica', 'wp-ultimo-locations'), - 'AG' => __('Antigua and Barbuda', 'wp-ultimo-locations'), - 'AR' => __('Argentina', 'wp-ultimo-locations'), - 'AM' => __('Armenia', 'wp-ultimo-locations'), - 'AW' => __('Aruba', 'wp-ultimo-locations'), - 'AU' => __('Australia', 'wp-ultimo-locations'), - 'AT' => __('Austria', 'wp-ultimo-locations'), - 'AZ' => __('Azerbaijan', 'wp-ultimo-locations'), - 'BS' => __('Bahamas', 'wp-ultimo-locations'), - 'BH' => __('Bahrain', 'wp-ultimo-locations'), - 'BD' => __('Bangladesh', 'wp-ultimo-locations'), - 'BB' => __('Barbados', 'wp-ultimo-locations'), - 'BY' => __('Belarus', 'wp-ultimo-locations'), - 'BE' => __('Belgium', 'wp-ultimo-locations'), - 'PW' => __('Belau', 'wp-ultimo-locations'), - 'BZ' => __('Belize', 'wp-ultimo-locations'), - 'BJ' => __('Benin', 'wp-ultimo-locations'), - 'BM' => __('Bermuda', 'wp-ultimo-locations'), - 'BT' => __('Bhutan', 'wp-ultimo-locations'), - 'BO' => __('Bolivia', 'wp-ultimo-locations'), - 'BQ' => __('Bonaire, Saint Eustatius and Saba', 'wp-ultimo-locations'), - 'BA' => __('Bosnia and Herzegovina', 'wp-ultimo-locations'), - 'BW' => __('Botswana', 'wp-ultimo-locations'), - 'BV' => __('Bouvet Island', 'wp-ultimo-locations'), - 'BR' => __('Brazil', 'wp-ultimo-locations'), - 'IO' => __('British Indian Ocean Territory', 'wp-ultimo-locations'), - 'VG' => __('British Virgin Islands', 'wp-ultimo-locations'), - 'BN' => __('Brunei', 'wp-ultimo-locations'), - 'BG' => __('Bulgaria', 'wp-ultimo-locations'), - 'BF' => __('Burkina Faso', 'wp-ultimo-locations'), - 'BI' => __('Burundi', 'wp-ultimo-locations'), - 'KH' => __('Cambodia', 'wp-ultimo-locations'), - 'CM' => __('Cameroon', 'wp-ultimo-locations'), - 'CA' => __('Canada', 'wp-ultimo-locations'), - 'CV' => __('Cape Verde', 'wp-ultimo-locations'), - 'KY' => __('Cayman Islands', 'wp-ultimo-locations'), - 'CF' => __('Central African Republic', 'wp-ultimo-locations'), - 'TD' => __('Chad', 'wp-ultimo-locations'), - 'CL' => __('Chile', 'wp-ultimo-locations'), - 'CN' => __('China', 'wp-ultimo-locations'), - 'CX' => __('Christmas Island', 'wp-ultimo-locations'), - 'CC' => __('Cocos (Keeling) Islands', 'wp-ultimo-locations'), - 'CO' => __('Colombia', 'wp-ultimo-locations'), - 'KM' => __('Comoros', 'wp-ultimo-locations'), - 'CG' => __('Congo (Brazzaville)', 'wp-ultimo-locations'), - 'CD' => __('Congo (Kinshasa)', 'wp-ultimo-locations'), - 'CK' => __('Cook Islands', 'wp-ultimo-locations'), - 'CR' => __('Costa Rica', 'wp-ultimo-locations'), - 'HR' => __('Croatia', 'wp-ultimo-locations'), - 'CU' => __('Cuba', 'wp-ultimo-locations'), - 'CW' => __('Curaçao', 'wp-ultimo-locations'), - 'CY' => __('Cyprus', 'wp-ultimo-locations'), - 'CZ' => __('Czech Republic', 'wp-ultimo-locations'), - 'DK' => __('Denmark', 'wp-ultimo-locations'), - 'DJ' => __('Djibouti', 'wp-ultimo-locations'), - 'DM' => __('Dominica', 'wp-ultimo-locations'), - 'DO' => __('Dominican Republic', 'wp-ultimo-locations'), - 'EC' => __('Ecuador', 'wp-ultimo-locations'), - 'EG' => __('Egypt', 'wp-ultimo-locations'), - 'SV' => __('El Salvador', 'wp-ultimo-locations'), - 'GQ' => __('Equatorial Guinea', 'wp-ultimo-locations'), - 'ER' => __('Eritrea', 'wp-ultimo-locations'), - 'EE' => __('Estonia', 'wp-ultimo-locations'), - 'ET' => __('Ethiopia', 'wp-ultimo-locations'), - 'FK' => __('Falkland Islands', 'wp-ultimo-locations'), - 'FO' => __('Faroe Islands', 'wp-ultimo-locations'), - 'FJ' => __('Fiji', 'wp-ultimo-locations'), - 'FI' => __('Finland', 'wp-ultimo-locations'), - 'FR' => __('France', 'wp-ultimo-locations'), - 'GF' => __('French Guiana', 'wp-ultimo-locations'), - 'PF' => __('French Polynesia', 'wp-ultimo-locations'), - 'TF' => __('French Southern Territories', 'wp-ultimo-locations'), - 'GA' => __('Gabon', 'wp-ultimo-locations'), - 'GM' => __('Gambia', 'wp-ultimo-locations'), - 'GE' => __('Georgia', 'wp-ultimo-locations'), - 'DE' => __('Germany', 'wp-ultimo-locations'), - 'GH' => __('Ghana', 'wp-ultimo-locations'), - 'GI' => __('Gibraltar', 'wp-ultimo-locations'), - 'GR' => __('Greece', 'wp-ultimo-locations'), - 'GL' => __('Greenland', 'wp-ultimo-locations'), - 'GD' => __('Grenada', 'wp-ultimo-locations'), - 'GP' => __('Guadeloupe', 'wp-ultimo-locations'), - 'GU' => __('Guam', 'wp-ultimo-locations'), - 'GT' => __('Guatemala', 'wp-ultimo-locations'), - 'GG' => __('Guernsey', 'wp-ultimo-locations'), - 'GN' => __('Guinea', 'wp-ultimo-locations'), - 'GW' => __('Guinea-Bissau', 'wp-ultimo-locations'), - 'GY' => __('Guyana', 'wp-ultimo-locations'), - 'HT' => __('Haiti', 'wp-ultimo-locations'), - 'HM' => __('Heard Island and McDonald Islands', 'wp-ultimo-locations'), - 'HN' => __('Honduras', 'wp-ultimo-locations'), - 'HK' => __('Hong Kong', 'wp-ultimo-locations'), - 'HU' => __('Hungary', 'wp-ultimo-locations'), - 'IS' => __('Iceland', 'wp-ultimo-locations'), - 'IN' => __('India', 'wp-ultimo-locations'), - 'ID' => __('Indonesia', 'wp-ultimo-locations'), - 'IR' => __('Iran', 'wp-ultimo-locations'), - 'IQ' => __('Iraq', 'wp-ultimo-locations'), - 'IE' => __('Ireland', 'wp-ultimo-locations'), - 'IM' => __('Isle of Man', 'wp-ultimo-locations'), - 'IL' => __('Israel', 'wp-ultimo-locations'), - 'IT' => __('Italy', 'wp-ultimo-locations'), - 'CI' => __('Ivory Coast', 'wp-ultimo-locations'), - 'JM' => __('Jamaica', 'wp-ultimo-locations'), - 'JP' => __('Japan', 'wp-ultimo-locations'), - 'JE' => __('Jersey', 'wp-ultimo-locations'), - 'JO' => __('Jordan', 'wp-ultimo-locations'), - 'KZ' => __('Kazakhstan', 'wp-ultimo-locations'), - 'KE' => __('Kenya', 'wp-ultimo-locations'), - 'KI' => __('Kiribati', 'wp-ultimo-locations'), - 'KW' => __('Kuwait', 'wp-ultimo-locations'), - 'KG' => __('Kyrgyzstan', 'wp-ultimo-locations'), - 'LA' => __('Laos', 'wp-ultimo-locations'), - 'LV' => __('Latvia', 'wp-ultimo-locations'), - 'LB' => __('Lebanon', 'wp-ultimo-locations'), - 'LS' => __('Lesotho', 'wp-ultimo-locations'), - 'LR' => __('Liberia', 'wp-ultimo-locations'), - 'LY' => __('Libya', 'wp-ultimo-locations'), - 'LI' => __('Liechtenstein', 'wp-ultimo-locations'), - 'LT' => __('Lithuania', 'wp-ultimo-locations'), - 'LU' => __('Luxembourg', 'wp-ultimo-locations'), - 'MO' => __('Macao S.A.R., China', 'wp-ultimo-locations'), - 'MK' => __('Macedonia', 'wp-ultimo-locations'), - 'MG' => __('Madagascar', 'wp-ultimo-locations'), - 'MW' => __('Malawi', 'wp-ultimo-locations'), - 'MY' => __('Malaysia', 'wp-ultimo-locations'), - 'MV' => __('Maldives', 'wp-ultimo-locations'), - 'ML' => __('Mali', 'wp-ultimo-locations'), - 'MT' => __('Malta', 'wp-ultimo-locations'), - 'MH' => __('Marshall Islands', 'wp-ultimo-locations'), - 'MQ' => __('Martinique', 'wp-ultimo-locations'), - 'MR' => __('Mauritania', 'wp-ultimo-locations'), - 'MU' => __('Mauritius', 'wp-ultimo-locations'), - 'YT' => __('Mayotte', 'wp-ultimo-locations'), - 'MX' => __('Mexico', 'wp-ultimo-locations'), - 'FM' => __('Micronesia', 'wp-ultimo-locations'), - 'MD' => __('Moldova', 'wp-ultimo-locations'), - 'MC' => __('Monaco', 'wp-ultimo-locations'), - 'MN' => __('Mongolia', 'wp-ultimo-locations'), - 'ME' => __('Montenegro', 'wp-ultimo-locations'), - 'MS' => __('Montserrat', 'wp-ultimo-locations'), - 'MA' => __('Morocco', 'wp-ultimo-locations'), - 'MZ' => __('Mozambique', 'wp-ultimo-locations'), - 'MM' => __('Myanmar', 'wp-ultimo-locations'), - 'NA' => __('Namibia', 'wp-ultimo-locations'), - 'NR' => __('Nauru', 'wp-ultimo-locations'), - 'NP' => __('Nepal', 'wp-ultimo-locations'), - 'NL' => __('Netherlands', 'wp-ultimo-locations'), - 'NC' => __('New Caledonia', 'wp-ultimo-locations'), - 'NZ' => __('New Zealand', 'wp-ultimo-locations'), - 'NI' => __('Nicaragua', 'wp-ultimo-locations'), - 'NE' => __('Niger', 'wp-ultimo-locations'), - 'NG' => __('Nigeria', 'wp-ultimo-locations'), - 'NU' => __('Niue', 'wp-ultimo-locations'), - 'NF' => __('Norfolk Island', 'wp-ultimo-locations'), - 'MP' => __('Northern Mariana Islands', 'wp-ultimo-locations'), - 'KP' => __('North Korea', 'wp-ultimo-locations'), - 'NO' => __('Norway', 'wp-ultimo-locations'), - 'OM' => __('Oman', 'wp-ultimo-locations'), - 'PK' => __('Pakistan', 'wp-ultimo-locations'), - 'PS' => __('Palestinian Territory', 'wp-ultimo-locations'), - 'PA' => __('Panama', 'wp-ultimo-locations'), - 'PG' => __('Papua New Guinea', 'wp-ultimo-locations'), - 'PY' => __('Paraguay', 'wp-ultimo-locations'), - 'PE' => __('Peru', 'wp-ultimo-locations'), - 'PH' => __('Philippines', 'wp-ultimo-locations'), - 'PN' => __('Pitcairn', 'wp-ultimo-locations'), - 'PL' => __('Poland', 'wp-ultimo-locations'), - 'PT' => __('Portugal', 'wp-ultimo-locations'), - 'PR' => __('Puerto Rico', 'wp-ultimo-locations'), - 'QA' => __('Qatar', 'wp-ultimo-locations'), - 'RE' => __('Reunion', 'wp-ultimo-locations'), - 'RO' => __('Romania', 'wp-ultimo-locations'), - 'RU' => __('Russia', 'wp-ultimo-locations'), - 'RW' => __('Rwanda', 'wp-ultimo-locations'), - 'BL' => __('Saint Barthélemy', 'wp-ultimo-locations'), - 'SH' => __('Saint Helena', 'wp-ultimo-locations'), - 'KN' => __('Saint Kitts and Nevis', 'wp-ultimo-locations'), - 'LC' => __('Saint Lucia', 'wp-ultimo-locations'), - 'MF' => __('Saint Martin (French part)', 'wp-ultimo-locations'), - 'SX' => __('Saint Martin (Dutch part)', 'wp-ultimo-locations'), - 'PM' => __('Saint Pierre and Miquelon', 'wp-ultimo-locations'), - 'VC' => __('Saint Vincent and the Grenadines', 'wp-ultimo-locations'), - 'SM' => __('San Marino', 'wp-ultimo-locations'), - 'ST' => __('São Tomé and Príncipe', 'wp-ultimo-locations'), - 'SA' => __('Saudi Arabia', 'wp-ultimo-locations'), - 'SN' => __('Senegal', 'wp-ultimo-locations'), - 'RS' => __('Serbia', 'wp-ultimo-locations'), - 'SC' => __('Seychelles', 'wp-ultimo-locations'), - 'SL' => __('Sierra Leone', 'wp-ultimo-locations'), - 'SG' => __('Singapore', 'wp-ultimo-locations'), - 'SK' => __('Slovakia', 'wp-ultimo-locations'), - 'SI' => __('Slovenia', 'wp-ultimo-locations'), - 'SB' => __('Solomon Islands', 'wp-ultimo-locations'), - 'SO' => __('Somalia', 'wp-ultimo-locations'), - 'ZA' => __('South Africa', 'wp-ultimo-locations'), - 'GS' => __('South Georgia/Sandwich Islands', 'wp-ultimo-locations'), - 'KR' => __('South Korea', 'wp-ultimo-locations'), - 'SS' => __('South Sudan', 'wp-ultimo-locations'), - 'ES' => __('Spain', 'wp-ultimo-locations'), - 'LK' => __('Sri Lanka', 'wp-ultimo-locations'), - 'SD' => __('Sudan', 'wp-ultimo-locations'), - 'SR' => __('Suriname', 'wp-ultimo-locations'), - 'SJ' => __('Svalbard and Jan Mayen', 'wp-ultimo-locations'), - 'SZ' => __('Swaziland', 'wp-ultimo-locations'), - 'SE' => __('Sweden', 'wp-ultimo-locations'), - 'CH' => __('Switzerland', 'wp-ultimo-locations'), - 'SY' => __('Syria', 'wp-ultimo-locations'), - 'TW' => __('Taiwan', 'wp-ultimo-locations'), - 'TJ' => __('Tajikistan', 'wp-ultimo-locations'), - 'TZ' => __('Tanzania', 'wp-ultimo-locations'), - 'TH' => __('Thailand', 'wp-ultimo-locations'), - 'TL' => __('Timor-Leste', 'wp-ultimo-locations'), - 'TG' => __('Togo', 'wp-ultimo-locations'), - 'TK' => __('Tokelau', 'wp-ultimo-locations'), - 'TO' => __('Tonga', 'wp-ultimo-locations'), - 'TT' => __('Trinidad and Tobago', 'wp-ultimo-locations'), - 'TN' => __('Tunisia', 'wp-ultimo-locations'), - 'TR' => __('Turkey', 'wp-ultimo-locations'), - 'TM' => __('Turkmenistan', 'wp-ultimo-locations'), - 'TC' => __('Turks and Caicos Islands', 'wp-ultimo-locations'), - 'TV' => __('Tuvalu', 'wp-ultimo-locations'), - 'UG' => __('Uganda', 'wp-ultimo-locations'), - 'UA' => __('Ukraine', 'wp-ultimo-locations'), - 'AE' => __('United Arab Emirates', 'wp-ultimo-locations'), - 'GB' => __('United Kingdom (UK)', 'wp-ultimo-locations'), - 'US' => __('United States (US)', 'wp-ultimo-locations'), - 'UM' => __('United States (US) Minor Outlying Islands', 'wp-ultimo-locations'), - 'VI' => __('United States (US) Virgin Islands', 'wp-ultimo-locations'), - 'UY' => __('Uruguay', 'wp-ultimo-locations'), - 'UZ' => __('Uzbekistan', 'wp-ultimo-locations'), - 'VU' => __('Vanuatu', 'wp-ultimo-locations'), - 'VA' => __('Vatican', 'wp-ultimo-locations'), - 'VE' => __('Venezuela', 'wp-ultimo-locations'), - 'VN' => __('Vietnam', 'wp-ultimo-locations'), - 'WF' => __('Wallis and Futuna', 'wp-ultimo-locations'), - 'EH' => __('Western Sahara', 'wp-ultimo-locations'), - 'WS' => __('Samoa', 'wp-ultimo-locations'), - 'YE' => __('Yemen', 'wp-ultimo-locations'), - 'ZM' => __('Zambia', 'wp-ultimo-locations'), - 'ZW' => __('Zimbabwe', 'wp-ultimo-locations'), - )); - -} // end wu_get_countries; + return apply_filters( + 'wu_get_countries', + array( + 'AF' => __('Afghanistan', 'wp-ultimo-locations'), + 'AX' => __('Åland Islands', 'wp-ultimo-locations'), + 'AL' => __('Albania', 'wp-ultimo-locations'), + 'DZ' => __('Algeria', 'wp-ultimo-locations'), + 'AS' => __('American Samoa', 'wp-ultimo-locations'), + 'AD' => __('Andorra', 'wp-ultimo-locations'), + 'AO' => __('Angola', 'wp-ultimo-locations'), + 'AI' => __('Anguilla', 'wp-ultimo-locations'), + 'AQ' => __('Antarctica', 'wp-ultimo-locations'), + 'AG' => __('Antigua and Barbuda', 'wp-ultimo-locations'), + 'AR' => __('Argentina', 'wp-ultimo-locations'), + 'AM' => __('Armenia', 'wp-ultimo-locations'), + 'AW' => __('Aruba', 'wp-ultimo-locations'), + 'AU' => __('Australia', 'wp-ultimo-locations'), + 'AT' => __('Austria', 'wp-ultimo-locations'), + 'AZ' => __('Azerbaijan', 'wp-ultimo-locations'), + 'BS' => __('Bahamas', 'wp-ultimo-locations'), + 'BH' => __('Bahrain', 'wp-ultimo-locations'), + 'BD' => __('Bangladesh', 'wp-ultimo-locations'), + 'BB' => __('Barbados', 'wp-ultimo-locations'), + 'BY' => __('Belarus', 'wp-ultimo-locations'), + 'BE' => __('Belgium', 'wp-ultimo-locations'), + 'PW' => __('Belau', 'wp-ultimo-locations'), + 'BZ' => __('Belize', 'wp-ultimo-locations'), + 'BJ' => __('Benin', 'wp-ultimo-locations'), + 'BM' => __('Bermuda', 'wp-ultimo-locations'), + 'BT' => __('Bhutan', 'wp-ultimo-locations'), + 'BO' => __('Bolivia', 'wp-ultimo-locations'), + 'BQ' => __('Bonaire, Saint Eustatius and Saba', 'wp-ultimo-locations'), + 'BA' => __('Bosnia and Herzegovina', 'wp-ultimo-locations'), + 'BW' => __('Botswana', 'wp-ultimo-locations'), + 'BV' => __('Bouvet Island', 'wp-ultimo-locations'), + 'BR' => __('Brazil', 'wp-ultimo-locations'), + 'IO' => __('British Indian Ocean Territory', 'wp-ultimo-locations'), + 'VG' => __('British Virgin Islands', 'wp-ultimo-locations'), + 'BN' => __('Brunei', 'wp-ultimo-locations'), + 'BG' => __('Bulgaria', 'wp-ultimo-locations'), + 'BF' => __('Burkina Faso', 'wp-ultimo-locations'), + 'BI' => __('Burundi', 'wp-ultimo-locations'), + 'KH' => __('Cambodia', 'wp-ultimo-locations'), + 'CM' => __('Cameroon', 'wp-ultimo-locations'), + 'CA' => __('Canada', 'wp-ultimo-locations'), + 'CV' => __('Cape Verde', 'wp-ultimo-locations'), + 'KY' => __('Cayman Islands', 'wp-ultimo-locations'), + 'CF' => __('Central African Republic', 'wp-ultimo-locations'), + 'TD' => __('Chad', 'wp-ultimo-locations'), + 'CL' => __('Chile', 'wp-ultimo-locations'), + 'CN' => __('China', 'wp-ultimo-locations'), + 'CX' => __('Christmas Island', 'wp-ultimo-locations'), + 'CC' => __('Cocos (Keeling) Islands', 'wp-ultimo-locations'), + 'CO' => __('Colombia', 'wp-ultimo-locations'), + 'KM' => __('Comoros', 'wp-ultimo-locations'), + 'CG' => __('Congo (Brazzaville)', 'wp-ultimo-locations'), + 'CD' => __('Congo (Kinshasa)', 'wp-ultimo-locations'), + 'CK' => __('Cook Islands', 'wp-ultimo-locations'), + 'CR' => __('Costa Rica', 'wp-ultimo-locations'), + 'HR' => __('Croatia', 'wp-ultimo-locations'), + 'CU' => __('Cuba', 'wp-ultimo-locations'), + 'CW' => __('Curaçao', 'wp-ultimo-locations'), + 'CY' => __('Cyprus', 'wp-ultimo-locations'), + 'CZ' => __('Czech Republic', 'wp-ultimo-locations'), + 'DK' => __('Denmark', 'wp-ultimo-locations'), + 'DJ' => __('Djibouti', 'wp-ultimo-locations'), + 'DM' => __('Dominica', 'wp-ultimo-locations'), + 'DO' => __('Dominican Republic', 'wp-ultimo-locations'), + 'EC' => __('Ecuador', 'wp-ultimo-locations'), + 'EG' => __('Egypt', 'wp-ultimo-locations'), + 'SV' => __('El Salvador', 'wp-ultimo-locations'), + 'GQ' => __('Equatorial Guinea', 'wp-ultimo-locations'), + 'ER' => __('Eritrea', 'wp-ultimo-locations'), + 'EE' => __('Estonia', 'wp-ultimo-locations'), + 'ET' => __('Ethiopia', 'wp-ultimo-locations'), + 'FK' => __('Falkland Islands', 'wp-ultimo-locations'), + 'FO' => __('Faroe Islands', 'wp-ultimo-locations'), + 'FJ' => __('Fiji', 'wp-ultimo-locations'), + 'FI' => __('Finland', 'wp-ultimo-locations'), + 'FR' => __('France', 'wp-ultimo-locations'), + 'GF' => __('French Guiana', 'wp-ultimo-locations'), + 'PF' => __('French Polynesia', 'wp-ultimo-locations'), + 'TF' => __('French Southern Territories', 'wp-ultimo-locations'), + 'GA' => __('Gabon', 'wp-ultimo-locations'), + 'GM' => __('Gambia', 'wp-ultimo-locations'), + 'GE' => __('Georgia', 'wp-ultimo-locations'), + 'DE' => __('Germany', 'wp-ultimo-locations'), + 'GH' => __('Ghana', 'wp-ultimo-locations'), + 'GI' => __('Gibraltar', 'wp-ultimo-locations'), + 'GR' => __('Greece', 'wp-ultimo-locations'), + 'GL' => __('Greenland', 'wp-ultimo-locations'), + 'GD' => __('Grenada', 'wp-ultimo-locations'), + 'GP' => __('Guadeloupe', 'wp-ultimo-locations'), + 'GU' => __('Guam', 'wp-ultimo-locations'), + 'GT' => __('Guatemala', 'wp-ultimo-locations'), + 'GG' => __('Guernsey', 'wp-ultimo-locations'), + 'GN' => __('Guinea', 'wp-ultimo-locations'), + 'GW' => __('Guinea-Bissau', 'wp-ultimo-locations'), + 'GY' => __('Guyana', 'wp-ultimo-locations'), + 'HT' => __('Haiti', 'wp-ultimo-locations'), + 'HM' => __('Heard Island and McDonald Islands', 'wp-ultimo-locations'), + 'HN' => __('Honduras', 'wp-ultimo-locations'), + 'HK' => __('Hong Kong', 'wp-ultimo-locations'), + 'HU' => __('Hungary', 'wp-ultimo-locations'), + 'IS' => __('Iceland', 'wp-ultimo-locations'), + 'IN' => __('India', 'wp-ultimo-locations'), + 'ID' => __('Indonesia', 'wp-ultimo-locations'), + 'IR' => __('Iran', 'wp-ultimo-locations'), + 'IQ' => __('Iraq', 'wp-ultimo-locations'), + 'IE' => __('Ireland', 'wp-ultimo-locations'), + 'IM' => __('Isle of Man', 'wp-ultimo-locations'), + 'IL' => __('Israel', 'wp-ultimo-locations'), + 'IT' => __('Italy', 'wp-ultimo-locations'), + 'CI' => __('Ivory Coast', 'wp-ultimo-locations'), + 'JM' => __('Jamaica', 'wp-ultimo-locations'), + 'JP' => __('Japan', 'wp-ultimo-locations'), + 'JE' => __('Jersey', 'wp-ultimo-locations'), + 'JO' => __('Jordan', 'wp-ultimo-locations'), + 'KZ' => __('Kazakhstan', 'wp-ultimo-locations'), + 'KE' => __('Kenya', 'wp-ultimo-locations'), + 'KI' => __('Kiribati', 'wp-ultimo-locations'), + 'KW' => __('Kuwait', 'wp-ultimo-locations'), + 'KG' => __('Kyrgyzstan', 'wp-ultimo-locations'), + 'LA' => __('Laos', 'wp-ultimo-locations'), + 'LV' => __('Latvia', 'wp-ultimo-locations'), + 'LB' => __('Lebanon', 'wp-ultimo-locations'), + 'LS' => __('Lesotho', 'wp-ultimo-locations'), + 'LR' => __('Liberia', 'wp-ultimo-locations'), + 'LY' => __('Libya', 'wp-ultimo-locations'), + 'LI' => __('Liechtenstein', 'wp-ultimo-locations'), + 'LT' => __('Lithuania', 'wp-ultimo-locations'), + 'LU' => __('Luxembourg', 'wp-ultimo-locations'), + 'MO' => __('Macao S.A.R., China', 'wp-ultimo-locations'), + 'MK' => __('Macedonia', 'wp-ultimo-locations'), + 'MG' => __('Madagascar', 'wp-ultimo-locations'), + 'MW' => __('Malawi', 'wp-ultimo-locations'), + 'MY' => __('Malaysia', 'wp-ultimo-locations'), + 'MV' => __('Maldives', 'wp-ultimo-locations'), + 'ML' => __('Mali', 'wp-ultimo-locations'), + 'MT' => __('Malta', 'wp-ultimo-locations'), + 'MH' => __('Marshall Islands', 'wp-ultimo-locations'), + 'MQ' => __('Martinique', 'wp-ultimo-locations'), + 'MR' => __('Mauritania', 'wp-ultimo-locations'), + 'MU' => __('Mauritius', 'wp-ultimo-locations'), + 'YT' => __('Mayotte', 'wp-ultimo-locations'), + 'MX' => __('Mexico', 'wp-ultimo-locations'), + 'FM' => __('Micronesia', 'wp-ultimo-locations'), + 'MD' => __('Moldova', 'wp-ultimo-locations'), + 'MC' => __('Monaco', 'wp-ultimo-locations'), + 'MN' => __('Mongolia', 'wp-ultimo-locations'), + 'ME' => __('Montenegro', 'wp-ultimo-locations'), + 'MS' => __('Montserrat', 'wp-ultimo-locations'), + 'MA' => __('Morocco', 'wp-ultimo-locations'), + 'MZ' => __('Mozambique', 'wp-ultimo-locations'), + 'MM' => __('Myanmar', 'wp-ultimo-locations'), + 'NA' => __('Namibia', 'wp-ultimo-locations'), + 'NR' => __('Nauru', 'wp-ultimo-locations'), + 'NP' => __('Nepal', 'wp-ultimo-locations'), + 'NL' => __('Netherlands', 'wp-ultimo-locations'), + 'NC' => __('New Caledonia', 'wp-ultimo-locations'), + 'NZ' => __('New Zealand', 'wp-ultimo-locations'), + 'NI' => __('Nicaragua', 'wp-ultimo-locations'), + 'NE' => __('Niger', 'wp-ultimo-locations'), + 'NG' => __('Nigeria', 'wp-ultimo-locations'), + 'NU' => __('Niue', 'wp-ultimo-locations'), + 'NF' => __('Norfolk Island', 'wp-ultimo-locations'), + 'MP' => __('Northern Mariana Islands', 'wp-ultimo-locations'), + 'KP' => __('North Korea', 'wp-ultimo-locations'), + 'NO' => __('Norway', 'wp-ultimo-locations'), + 'OM' => __('Oman', 'wp-ultimo-locations'), + 'PK' => __('Pakistan', 'wp-ultimo-locations'), + 'PS' => __('Palestinian Territory', 'wp-ultimo-locations'), + 'PA' => __('Panama', 'wp-ultimo-locations'), + 'PG' => __('Papua New Guinea', 'wp-ultimo-locations'), + 'PY' => __('Paraguay', 'wp-ultimo-locations'), + 'PE' => __('Peru', 'wp-ultimo-locations'), + 'PH' => __('Philippines', 'wp-ultimo-locations'), + 'PN' => __('Pitcairn', 'wp-ultimo-locations'), + 'PL' => __('Poland', 'wp-ultimo-locations'), + 'PT' => __('Portugal', 'wp-ultimo-locations'), + 'PR' => __('Puerto Rico', 'wp-ultimo-locations'), + 'QA' => __('Qatar', 'wp-ultimo-locations'), + 'RE' => __('Reunion', 'wp-ultimo-locations'), + 'RO' => __('Romania', 'wp-ultimo-locations'), + 'RU' => __('Russia', 'wp-ultimo-locations'), + 'RW' => __('Rwanda', 'wp-ultimo-locations'), + 'BL' => __('Saint Barthélemy', 'wp-ultimo-locations'), + 'SH' => __('Saint Helena', 'wp-ultimo-locations'), + 'KN' => __('Saint Kitts and Nevis', 'wp-ultimo-locations'), + 'LC' => __('Saint Lucia', 'wp-ultimo-locations'), + 'MF' => __('Saint Martin (French part)', 'wp-ultimo-locations'), + 'SX' => __('Saint Martin (Dutch part)', 'wp-ultimo-locations'), + 'PM' => __('Saint Pierre and Miquelon', 'wp-ultimo-locations'), + 'VC' => __('Saint Vincent and the Grenadines', 'wp-ultimo-locations'), + 'SM' => __('San Marino', 'wp-ultimo-locations'), + 'ST' => __('São Tomé and Príncipe', 'wp-ultimo-locations'), + 'SA' => __('Saudi Arabia', 'wp-ultimo-locations'), + 'SN' => __('Senegal', 'wp-ultimo-locations'), + 'RS' => __('Serbia', 'wp-ultimo-locations'), + 'SC' => __('Seychelles', 'wp-ultimo-locations'), + 'SL' => __('Sierra Leone', 'wp-ultimo-locations'), + 'SG' => __('Singapore', 'wp-ultimo-locations'), + 'SK' => __('Slovakia', 'wp-ultimo-locations'), + 'SI' => __('Slovenia', 'wp-ultimo-locations'), + 'SB' => __('Solomon Islands', 'wp-ultimo-locations'), + 'SO' => __('Somalia', 'wp-ultimo-locations'), + 'ZA' => __('South Africa', 'wp-ultimo-locations'), + 'GS' => __('South Georgia/Sandwich Islands', 'wp-ultimo-locations'), + 'KR' => __('South Korea', 'wp-ultimo-locations'), + 'SS' => __('South Sudan', 'wp-ultimo-locations'), + 'ES' => __('Spain', 'wp-ultimo-locations'), + 'LK' => __('Sri Lanka', 'wp-ultimo-locations'), + 'SD' => __('Sudan', 'wp-ultimo-locations'), + 'SR' => __('Suriname', 'wp-ultimo-locations'), + 'SJ' => __('Svalbard and Jan Mayen', 'wp-ultimo-locations'), + 'SZ' => __('Swaziland', 'wp-ultimo-locations'), + 'SE' => __('Sweden', 'wp-ultimo-locations'), + 'CH' => __('Switzerland', 'wp-ultimo-locations'), + 'SY' => __('Syria', 'wp-ultimo-locations'), + 'TW' => __('Taiwan', 'wp-ultimo-locations'), + 'TJ' => __('Tajikistan', 'wp-ultimo-locations'), + 'TZ' => __('Tanzania', 'wp-ultimo-locations'), + 'TH' => __('Thailand', 'wp-ultimo-locations'), + 'TL' => __('Timor-Leste', 'wp-ultimo-locations'), + 'TG' => __('Togo', 'wp-ultimo-locations'), + 'TK' => __('Tokelau', 'wp-ultimo-locations'), + 'TO' => __('Tonga', 'wp-ultimo-locations'), + 'TT' => __('Trinidad and Tobago', 'wp-ultimo-locations'), + 'TN' => __('Tunisia', 'wp-ultimo-locations'), + 'TR' => __('Turkey', 'wp-ultimo-locations'), + 'TM' => __('Turkmenistan', 'wp-ultimo-locations'), + 'TC' => __('Turks and Caicos Islands', 'wp-ultimo-locations'), + 'TV' => __('Tuvalu', 'wp-ultimo-locations'), + 'UG' => __('Uganda', 'wp-ultimo-locations'), + 'UA' => __('Ukraine', 'wp-ultimo-locations'), + 'AE' => __('United Arab Emirates', 'wp-ultimo-locations'), + 'GB' => __('United Kingdom (UK)', 'wp-ultimo-locations'), + 'US' => __('United States (US)', 'wp-ultimo-locations'), + 'UM' => __('United States (US) Minor Outlying Islands', 'wp-ultimo-locations'), + 'VI' => __('United States (US) Virgin Islands', 'wp-ultimo-locations'), + 'UY' => __('Uruguay', 'wp-ultimo-locations'), + 'UZ' => __('Uzbekistan', 'wp-ultimo-locations'), + 'VU' => __('Vanuatu', 'wp-ultimo-locations'), + 'VA' => __('Vatican', 'wp-ultimo-locations'), + 'VE' => __('Venezuela', 'wp-ultimo-locations'), + 'VN' => __('Vietnam', 'wp-ultimo-locations'), + 'WF' => __('Wallis and Futuna', 'wp-ultimo-locations'), + 'EH' => __('Western Sahara', 'wp-ultimo-locations'), + 'WS' => __('Samoa', 'wp-ultimo-locations'), + 'YE' => __('Yemen', 'wp-ultimo-locations'), + 'ZM' => __('Zambia', 'wp-ultimo-locations'), + 'ZW' => __('Zimbabwe', 'wp-ultimo-locations'), + ) + ); +} /** * Returns the list of countries with an additional empty state option. @@ -279,11 +281,13 @@ function wu_get_countries() { */ function wu_get_countries_as_options() { - return array_merge(array( - '' => __('Select Country', 'wp-ultimo'), - ), wu_get_countries()); - -} // end wu_get_countries_as_options; + return array_merge( + array( + '' => __('Select Country', 'wp-ultimo'), + ), + wu_get_countries() + ); +} /** * Returns the country object. @@ -302,14 +306,11 @@ function wu_get_country($country_code, $name = null, $fallback_attributes = arra $country_class = "\\WP_Ultimo\\Country\\Country_{$country_code}"; if (class_exists($country_class)) { - return $country_class::get_instance(); - - } // end if; + } return \WP_Ultimo\Country\Country_Default::build($country_code, $name, $fallback_attributes); - -} // end wu_get_country; +} /** * Get the state list for a country. @@ -330,28 +331,21 @@ function wu_get_country_states($country_code, $key_name = 'id', $value_name = 'v $cache = wu_get_isset($state_options, $country_code, false); if ($cache) { - $options = $cache; - } else { - $country = wu_get_country($country_code); - $state_options[$country_code] = $country->get_states_as_options(false); + $state_options[ $country_code ] = $country->get_states_as_options(false); - $options = $state_options[$country_code]; - - } // end if; + $options = $state_options[ $country_code ]; + } if (empty($key_name)) { - return $options; - - } // end if; + } return wu_key_map_to_array($options, $key_name, $value_name); - -} // end wu_get_country_states; +} /** * Get cities for a collection of states of a country. @@ -373,34 +367,25 @@ function wu_get_country_cities($country_code, $states, $key_name = 'id', $value_ $options = array(); foreach ($states as $state_code) { - $cache = wu_get_isset($city_options, $state_code, false); if ($cache) { - $options = array_merge($options, $cache); - } else { - $country = wu_get_country($country_code); - $city_options[$state_code] = $country->get_cities_as_options($state_code, false); + $city_options[ $state_code ] = $country->get_cities_as_options($state_code, false); - $options = array_merge($options, $city_options[$state_code]); - - } // end if; - - } // end foreach; + $options = array_merge($options, $city_options[ $state_code ]); + } + } if (empty($key_name)) { - return $options; - - } // end if; + } return wu_key_map_to_array($options, $key_name, $value_name); - -} // end wu_get_country_cities; +} /** * Returns the country name for a given country code. @@ -415,8 +400,7 @@ function wu_get_country_name($country_code) { $country_name = wu_get_isset(wu_get_countries(), $country_code, __('Not found', 'wp-ultimo')); return apply_filters('wu_get_country_name', $country_name, $country_code); - -} // end wu_get_country_name; +} /** * Get the list of countries and counts based on customers. @@ -437,12 +421,10 @@ function wu_get_countries_of_customers($count = 10, $start_date = false, $end_da $date_query = ''; if ($start_date || $end_date) { - $date_query = 'AND c.date_registered >= %s AND c.date_registered <= %s'; $date_query = $wpdb->prepare($date_query, $start_date . ' 00:00:00', $end_date . " 23:59:59"); // phpcs:ignore - - } // end if; + } $query = " SELECT m.meta_value as country, COUNT(distinct c.id) as count @@ -462,14 +444,11 @@ function wu_get_countries_of_customers($count = 10, $start_date = false, $end_da $countries = array(); foreach ($results as $result) { - - $countries[$result->country] = $result->count; - - } // end foreach; + $countries[ $result->country ] = $result->count; + } return $countries; - -} // end wu_get_countries_of_customers; +} /** * Get the list of countries and counts based on customers. @@ -493,20 +472,16 @@ function wu_get_states_of_customers($country_code, $count = 100, $start_date = f $date_query = ''; if ($start_date || $end_date) { - $date_query = 'AND c.date_registered >= %s AND c.date_registered <= %s'; $date_query = $wpdb->prepare($date_query, $start_date . ' 00:00:00', $end_date . " 23:59:59"); // phpcs:ignore - - } // end if; + } $states = wu_get_country_states('BR', false); if (empty($states)) { - return array(); - - } // end if; + } $states_in = implode("','", array_keys($states)); @@ -526,21 +501,16 @@ function wu_get_states_of_customers($country_code, $count = 100, $start_date = f $results = $wpdb->get_results($query); // phpcs:ignore if (empty($results)) { - return array(); - - } // end if; + } $_states = array(); foreach ($results as $result) { + $final_label = sprintf('%s (%s)', $states[ $result->state ], $result->state); - $final_label = sprintf('%s (%s)', $states[$result->state], $result->state); - - $_states[$final_label] = absint($result->count); - - } // end foreach; + $_states[ $final_label ] = absint($result->count); + } return $_states; - -} // end wu_get_states_of_customers; +} diff --git a/inc/functions/currency.php b/inc/functions/currency.php index 33d831a..d5f9da8 100644 --- a/inc/functions/currency.php +++ b/inc/functions/currency.php @@ -16,61 +16,63 @@ defined('ABSPATH') || exit; */ function wu_get_currencies(): array { - $currencies = apply_filters('wu_currencies', array( - 'AED' => __('United Arab Emirates Dirham', 'wp-ultimo'), - 'ARS' => __('Argentine Peso', 'wp-ultimo'), - 'AUD' => __('Australian Dollars', 'wp-ultimo'), - 'BDT' => __('Bangladeshi Taka', 'wp-ultimo'), - 'BRL' => __('Brazilian Real', 'wp-ultimo'), - 'BGN' => __('Bulgarian Lev', 'wp-ultimo'), - 'CAD' => __('Canadian Dollars', 'wp-ultimo'), - 'CLP' => __('Chilean Peso', 'wp-ultimo'), - 'CNY' => __('Chinese Yuan', 'wp-ultimo'), - 'COP' => __('Colombian Peso', 'wp-ultimo'), - 'CZK' => __('Czech Koruna', 'wp-ultimo'), - 'DKK' => __('Danish Krone', 'wp-ultimo'), - 'DOP' => __('Dominican Peso', 'wp-ultimo'), - 'EUR' => __('Euros', 'wp-ultimo'), - 'HKD' => __('Hong Kong Dollar', 'wp-ultimo'), - 'HRK' => __('Croatia kuna', 'wp-ultimo'), - 'HUF' => __('Hungarian Forint', 'wp-ultimo'), - 'ISK' => __('Icelandic krona', 'wp-ultimo'), - 'IDR' => __('Indonesia Rupiah', 'wp-ultimo'), - 'INR' => __('Indian Rupee', 'wp-ultimo'), - 'NPR' => __('Nepali Rupee', 'wp-ultimo'), - 'ILS' => __('Israeli Shekel', 'wp-ultimo'), - 'JPY' => __('Japanese Yen', 'wp-ultimo'), - 'KES' => __('Kenyan Shilling', 'wp-ultimo'), - 'KIP' => __('Lao Kip', 'wp-ultimo'), - 'KRW' => __('South Korean Won', 'wp-ultimo'), - 'MYR' => __('Malaysian Ringgits', 'wp-ultimo'), - 'MXN' => __('Mexican Peso', 'wp-ultimo'), - 'NGN' => __('Nigerian Naira', 'wp-ultimo'), - 'NOK' => __('Norwegian Krone', 'wp-ultimo'), - 'NZD' => __('New Zealand Dollar', 'wp-ultimo'), - 'PYG' => __('Paraguayan Guaraní', 'wp-ultimo'), - 'PHP' => __('Philippine Pesos', 'wp-ultimo'), - 'PLN' => __('Polish Zloty', 'wp-ultimo'), - 'GBP' => __('Pounds Sterling', 'wp-ultimo'), - 'RON' => __('Romanian Leu', 'wp-ultimo'), - 'RUB' => __('Russian Ruble', 'wp-ultimo'), - 'SGD' => __('Singapore Dollar', 'wp-ultimo'), - 'ZAR' => __('South African rand', 'wp-ultimo'), - 'SAR' => __('Saudi Riyal', 'wp-ultimo'), - 'SEK' => __('Swedish Krona', 'wp-ultimo'), - 'CHF' => __('Swiss Franc', 'wp-ultimo'), - 'TWD' => __('Taiwan New Dollars', 'wp-ultimo'), - 'THB' => __('Thai Baht', 'wp-ultimo'), - 'TRY' => __('Turkish Lira', 'wp-ultimo'), - 'UAH' => __('Ukrainian Hryvnia', 'wp-ultimo'), - 'USD' => __('US Dollars', 'wp-ultimo'), - 'VND' => __('Vietnamese Dong', 'wp-ultimo'), - 'EGP' => __('Egyptian Pound', 'wp-ultimo'), - )); + $currencies = apply_filters( + 'wu_currencies', + array( + 'AED' => __('United Arab Emirates Dirham', 'wp-ultimo'), + 'ARS' => __('Argentine Peso', 'wp-ultimo'), + 'AUD' => __('Australian Dollars', 'wp-ultimo'), + 'BDT' => __('Bangladeshi Taka', 'wp-ultimo'), + 'BRL' => __('Brazilian Real', 'wp-ultimo'), + 'BGN' => __('Bulgarian Lev', 'wp-ultimo'), + 'CAD' => __('Canadian Dollars', 'wp-ultimo'), + 'CLP' => __('Chilean Peso', 'wp-ultimo'), + 'CNY' => __('Chinese Yuan', 'wp-ultimo'), + 'COP' => __('Colombian Peso', 'wp-ultimo'), + 'CZK' => __('Czech Koruna', 'wp-ultimo'), + 'DKK' => __('Danish Krone', 'wp-ultimo'), + 'DOP' => __('Dominican Peso', 'wp-ultimo'), + 'EUR' => __('Euros', 'wp-ultimo'), + 'HKD' => __('Hong Kong Dollar', 'wp-ultimo'), + 'HRK' => __('Croatia kuna', 'wp-ultimo'), + 'HUF' => __('Hungarian Forint', 'wp-ultimo'), + 'ISK' => __('Icelandic krona', 'wp-ultimo'), + 'IDR' => __('Indonesia Rupiah', 'wp-ultimo'), + 'INR' => __('Indian Rupee', 'wp-ultimo'), + 'NPR' => __('Nepali Rupee', 'wp-ultimo'), + 'ILS' => __('Israeli Shekel', 'wp-ultimo'), + 'JPY' => __('Japanese Yen', 'wp-ultimo'), + 'KES' => __('Kenyan Shilling', 'wp-ultimo'), + 'KIP' => __('Lao Kip', 'wp-ultimo'), + 'KRW' => __('South Korean Won', 'wp-ultimo'), + 'MYR' => __('Malaysian Ringgits', 'wp-ultimo'), + 'MXN' => __('Mexican Peso', 'wp-ultimo'), + 'NGN' => __('Nigerian Naira', 'wp-ultimo'), + 'NOK' => __('Norwegian Krone', 'wp-ultimo'), + 'NZD' => __('New Zealand Dollar', 'wp-ultimo'), + 'PYG' => __('Paraguayan Guaraní', 'wp-ultimo'), + 'PHP' => __('Philippine Pesos', 'wp-ultimo'), + 'PLN' => __('Polish Zloty', 'wp-ultimo'), + 'GBP' => __('Pounds Sterling', 'wp-ultimo'), + 'RON' => __('Romanian Leu', 'wp-ultimo'), + 'RUB' => __('Russian Ruble', 'wp-ultimo'), + 'SGD' => __('Singapore Dollar', 'wp-ultimo'), + 'ZAR' => __('South African rand', 'wp-ultimo'), + 'SAR' => __('Saudi Riyal', 'wp-ultimo'), + 'SEK' => __('Swedish Krona', 'wp-ultimo'), + 'CHF' => __('Swiss Franc', 'wp-ultimo'), + 'TWD' => __('Taiwan New Dollars', 'wp-ultimo'), + 'THB' => __('Thai Baht', 'wp-ultimo'), + 'TRY' => __('Turkish Lira', 'wp-ultimo'), + 'UAH' => __('Ukrainian Hryvnia', 'wp-ultimo'), + 'USD' => __('US Dollars', 'wp-ultimo'), + 'VND' => __('Vietnamese Dong', 'wp-ultimo'), + 'EGP' => __('Egyptian Pound', 'wp-ultimo'), + ) + ); return array_unique($currencies); - -} // end wu_get_currencies; +} /** * Gets the currency symbol of a currency. @@ -82,147 +84,144 @@ function wu_get_currencies(): array { */ function wu_get_currency_symbol($currency = '') { - if (!$currency) { - + if ( ! $currency) { $currency = wu_get_setting('currency_symbol'); - } switch ($currency) { - case 'AED': - $currency_symbol = 'د.إ'; - break; - case 'AUD': - case 'ARS': - case 'CAD': - case 'CLP': - case 'COP': - case 'HKD': - case 'MXN': - case 'NZD': - case 'SGD': - case 'USD': - $currency_symbol = '$'; - break; - case 'BDT': - $currency_symbol = '৳ '; - break; - case 'BGN': - $currency_symbol = 'лв.'; - break; - case 'BRL': - $currency_symbol = 'R$'; - break; - case 'CHF': - $currency_symbol = 'CHF'; - break; - case 'CNY': - case 'JPY': - case 'RMB': - $currency_symbol = '¥'; - break; - case 'CZK': - $currency_symbol = 'Kč'; - break; - case 'DKK': - $currency_symbol = 'DKK'; - break; - case 'DOP': - $currency_symbol = 'RD$'; - break; - case 'EGP': - $currency_symbol = 'EGP'; - break; - case 'EUR': - $currency_symbol = '€'; - break; - case 'GBP': - $currency_symbol = '£'; - break; - case 'HRK': - $currency_symbol = 'Kn'; - break; - case 'HUF': - $currency_symbol = 'Ft'; - break; - case 'IDR': - $currency_symbol = 'Rp'; - break; - case 'ILS': - $currency_symbol = '₪'; - break; - case 'INR': - $currency_symbol = 'Rs.'; - break; - case 'ISK': - $currency_symbol = 'Kr.'; - break; - case 'KES': - $currency_symbol = 'KSh'; - break; - case 'KIP': - $currency_symbol = '₭'; - break; - case 'KRW': - $currency_symbol = '₩'; - break; - case 'MYR': - $currency_symbol = 'RM'; - break; - case 'NGN': - $currency_symbol = '₦'; - break; - case 'NOK': - $currency_symbol = 'kr'; - break; - case 'NPR': - $currency_symbol = 'Rs.'; - break; - case 'PHP': - $currency_symbol = '₱'; - break; - case 'PLN': - $currency_symbol = 'zł'; - break; - case 'PYG': - $currency_symbol = '₲'; - break; - case 'RON': - $currency_symbol = 'lei'; - break; - case 'RUB': - $currency_symbol = 'руб.'; - break; - case 'SEK': - $currency_symbol = 'kr'; - break; - case 'THB': - $currency_symbol = '฿'; - break; - case 'TRY': - $currency_symbol = '₺'; - break; - case 'TWD': - $currency_symbol = 'NT$'; - break; - case 'UAH': - $currency_symbol = '₴'; - break; - case 'VND': - $currency_symbol = '₫'; - break; - case 'ZAR': - $currency_symbol = 'R'; - break; - case 'SAR': - $currency_symbol = 'ر.س'; - break; - default: - $currency_symbol = $currency; - break; - } // end switch; + case 'AED': + $currency_symbol = 'د.إ'; + break; + case 'AUD': + case 'ARS': + case 'CAD': + case 'CLP': + case 'COP': + case 'HKD': + case 'MXN': + case 'NZD': + case 'SGD': + case 'USD': + $currency_symbol = '$'; + break; + case 'BDT': + $currency_symbol = '৳ '; + break; + case 'BGN': + $currency_symbol = 'лв.'; + break; + case 'BRL': + $currency_symbol = 'R$'; + break; + case 'CHF': + $currency_symbol = 'CHF'; + break; + case 'CNY': + case 'JPY': + case 'RMB': + $currency_symbol = '¥'; + break; + case 'CZK': + $currency_symbol = 'Kč'; + break; + case 'DKK': + $currency_symbol = 'DKK'; + break; + case 'DOP': + $currency_symbol = 'RD$'; + break; + case 'EGP': + $currency_symbol = 'EGP'; + break; + case 'EUR': + $currency_symbol = '€'; + break; + case 'GBP': + $currency_symbol = '£'; + break; + case 'HRK': + $currency_symbol = 'Kn'; + break; + case 'HUF': + $currency_symbol = 'Ft'; + break; + case 'IDR': + $currency_symbol = 'Rp'; + break; + case 'ILS': + $currency_symbol = '₪'; + break; + case 'INR': + $currency_symbol = 'Rs.'; + break; + case 'ISK': + $currency_symbol = 'Kr.'; + break; + case 'KES': + $currency_symbol = 'KSh'; + break; + case 'KIP': + $currency_symbol = '₭'; + break; + case 'KRW': + $currency_symbol = '₩'; + break; + case 'MYR': + $currency_symbol = 'RM'; + break; + case 'NGN': + $currency_symbol = '₦'; + break; + case 'NOK': + $currency_symbol = 'kr'; + break; + case 'NPR': + $currency_symbol = 'Rs.'; + break; + case 'PHP': + $currency_symbol = '₱'; + break; + case 'PLN': + $currency_symbol = 'zł'; + break; + case 'PYG': + $currency_symbol = '₲'; + break; + case 'RON': + $currency_symbol = 'lei'; + break; + case 'RUB': + $currency_symbol = 'руб.'; + break; + case 'SEK': + $currency_symbol = 'kr'; + break; + case 'THB': + $currency_symbol = '฿'; + break; + case 'TRY': + $currency_symbol = '₺'; + break; + case 'TWD': + $currency_symbol = 'NT$'; + break; + case 'UAH': + $currency_symbol = '₴'; + break; + case 'VND': + $currency_symbol = '₫'; + break; + case 'ZAR': + $currency_symbol = 'R'; + break; + case 'SAR': + $currency_symbol = 'ر.س'; + break; + default: + $currency_symbol = $currency; + break; + } return apply_filters('wu_currency_symbol', $currency_symbol, $currency); - -} // end wu_get_currency_symbol; +} /** * Formats a value into our defined format @@ -250,13 +249,16 @@ function wu_format_currency($value, $currency = null, $format = null, $thousands // Remove invalid args $args = array_filter($args); - $atts = wp_parse_args($args, array( - 'currency' => wu_get_setting('currency_symbol'), - 'format' => wu_get_setting('currency_position'), - 'thousands_sep' => wu_get_setting('thousand_separator'), - 'decimal_sep' => wu_get_setting('decimal_separator'), - 'precision' => (int) wu_get_setting('precision', 2), - )); + $atts = wp_parse_args( + $args, + array( + 'currency' => wu_get_setting('currency_symbol'), + 'format' => wu_get_setting('currency_position'), + 'thousands_sep' => wu_get_setting('thousand_separator'), + 'decimal_sep' => wu_get_setting('decimal_separator'), + 'precision' => (int) wu_get_setting('precision', 2), + ) + ); $currency_symbol = wu_get_currency_symbol($atts['currency']); @@ -266,8 +268,7 @@ function wu_format_currency($value, $currency = null, $format = null, $thousands $format = str_replace('%s', $currency_symbol, $format); return apply_filters('wu_format_currency', $format, $currency_symbol, $value); - -} // end wu_format_currency; +} /** * Determines if WP Multisite WaaS is using a zero-decimal currency. @@ -298,8 +299,7 @@ function wu_is_zero_decimal_currency($currency = 'USD') { ); return apply_filters('wu_is_zero_decimal_currency', in_array($currency, $zero_dec_currencies, true)); - -} // end wu_is_zero_decimal_currency; +} /** * Sets the number of decimal places based on the currency. @@ -315,14 +315,11 @@ function wu_currency_decimal_filter($decimals = 2) { $currency = 'USD'; if (wu_is_zero_decimal_currency($currency)) { - $decimals = 0; - - } // end if; + } return apply_filters('wu_currency_decimal_filter', $decimals, $currency); - -} // end wu_currency_decimal_filter; +} /** * Returns the multiplier for the currency. Most currencies are multiplied by 100. @@ -338,5 +335,4 @@ function wu_stripe_get_currency_multiplier($currency = 'USD') { $multiplier = (wu_is_zero_decimal_currency($currency)) ? 1 : 100; return apply_filters('wu_stripe_get_currency_multiplier', $multiplier, $currency); - -} // end wu_stripe_get_currency_multiplier; +} diff --git a/inc/functions/customer.php b/inc/functions/customer.php index 2ac944e..b235d39 100644 --- a/inc/functions/customer.php +++ b/inc/functions/customer.php @@ -9,7 +9,7 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Models\Customer; +use WP_Ultimo\Models\Customer; /** * Returns a customer. @@ -22,8 +22,7 @@ use \WP_Ultimo\Models\Customer; function wu_get_customer($customer_id) { return \WP_Ultimo\Models\Customer::get_by_id($customer_id); - -} // end wu_get_customer; +} /** * Returns a single customer defined by a particular column and value. * @@ -36,8 +35,7 @@ function wu_get_customer($customer_id) { function wu_get_customer_by($column, $value) { return \WP_Ultimo\Models\Customer::get_by($column, $value); - -} // end wu_get_customer_by; +} /** * Gets a customer based on the hash. * @@ -49,8 +47,7 @@ function wu_get_customer_by($column, $value) { function wu_get_customer_by_hash($hash) { return \WP_Ultimo\Models\Customer::get_by_hash($hash); - -} // end wu_get_customer_by_hash; +} /** * Queries customers. @@ -62,24 +59,22 @@ function wu_get_customer_by_hash($hash) { */ function wu_get_customers($query = array()) { - if (!empty($query['search'])) { - - $user_ids = get_users(array( - 'blog_id' => 0, - 'number' => -1, - 'search' => '*' . $query['search'] . '*', - 'fields' => 'ids', - )); - - if (!empty($user_ids)) { + if ( ! empty($query['search'])) { + $user_ids = get_users( + array( + 'blog_id' => 0, + 'number' => -1, + 'search' => '*' . $query['search'] . '*', + 'fields' => 'ids', + ) + ); + if ( ! empty($user_ids)) { $query['user_id__in'] = $user_ids; unset($query['search']); - - } // end if; - - } // end if; + } + } /* * Force search limit to customers only. @@ -87,8 +82,7 @@ function wu_get_customers($query = array()) { $query['type'] = 'customer'; return \WP_Ultimo\Models\Customer::query($query); - -} // end wu_get_customers; +} /** * Returns a customer based on user_id. * @@ -100,8 +94,7 @@ function wu_get_customers($query = array()) { function wu_get_customer_by_user_id($user_id) { return \WP_Ultimo\Models\Customer::get_by('user_id', $user_id); - -} // end wu_get_customer_by_user_id; +} /** * Returns the current customer. * @@ -111,8 +104,7 @@ function wu_get_customer_by_user_id($user_id) { function wu_get_current_customer() { return wu_get_customer_by_user_id(get_current_user_id()); - -} // end wu_get_current_customer; +} /** * Creates a new customer. * @@ -126,82 +118,70 @@ function wu_get_current_customer() { */ function wu_create_customer($customer_data) { - $customer_data = wp_parse_args($customer_data, array( - 'user_id' => false, - 'email' => false, - 'username' => false, - 'password' => false, - 'vip' => false, - 'ip' => false, - 'email_verification' => 'none', - 'meta' => array(), - 'date_registered' => wu_get_current_time('mysql', true), - 'date_modified' => wu_get_current_time('mysql', true), - 'last_login' => wu_get_current_time('mysql', true), - 'signup_form' => 'by-admin', - 'billing_address' => array(), - )); + $customer_data = wp_parse_args( + $customer_data, + array( + 'user_id' => false, + 'email' => false, + 'username' => false, + 'password' => false, + 'vip' => false, + 'ip' => false, + 'email_verification' => 'none', + 'meta' => array(), + 'date_registered' => wu_get_current_time('mysql', true), + 'date_modified' => wu_get_current_time('mysql', true), + 'last_login' => wu_get_current_time('mysql', true), + 'signup_form' => 'by-admin', + 'billing_address' => array(), + ) + ); $user = get_user_by('email', $customer_data['email']); - if (!$user) { - + if ( ! $user) { $user = get_user_by('ID', $customer_data['user_id']); + } - } // end if; - - if (!$user) { - + if ( ! $user) { if ($customer_data['password']) { - $user_id = wpmu_create_user($customer_data['username'], $customer_data['password'], $customer_data['email']); - } else { - $user_id = register_new_user($customer_data['username'], $customer_data['email']); - - } // end if; + } if (is_wp_error($user_id)) { - return $user_id; - - } // end if; + } if ($user_id === false) { - return new \WP_Error('user', __('We were not able to create a new user with the provided username and email address combination.', 'wp-ultimo'), $customer_data); - - } // end if; - + } } else { - $user_id = $user->ID; + } - } // end if; - - if (!get_userdata($user_id)) { - + if ( ! get_userdata($user_id)) { return new \WP_Error('user_id', __('We were not able to find a user with the given user_id.', 'wp-ultimo'), $customer_data); + } - } // end if; - - $customer = new Customer(array( - 'user_id' => $user_id, - 'email_verification' => $customer_data['email_verification'], - 'meta' => $customer_data['meta'], - 'date_registered' => $customer_data['date_registered'], - 'signup_form' => $customer_data['signup_form'], - 'billing_address' => $customer_data['billing_address'], - 'last_login' => $customer_data['last_login'], - 'type' => 'customer', - )); + $customer = new Customer( + array( + 'user_id' => $user_id, + 'email_verification' => $customer_data['email_verification'], + 'meta' => $customer_data['meta'], + 'date_registered' => $customer_data['date_registered'], + 'signup_form' => $customer_data['signup_form'], + 'billing_address' => $customer_data['billing_address'], + 'last_login' => $customer_data['last_login'], + 'type' => 'customer', + ) + ); $saved = $customer->save(); return is_wp_error($saved) ? $saved : $customer; - -} // end wu_create_customer; +} /** * Get the customer meta types available. @@ -223,20 +203,16 @@ function wu_get_customer_meta_types($form_slugs = false) { ); if (is_array($form_slugs)) { - $query['slug__in'] = (array) $form_slugs; - - } // end if; + } $forms = wu_get_checkout_forms($query); foreach ($forms as $form) { - $customer_meta_fields = $form->get_all_meta_fields('customer_meta'); foreach ($customer_meta_fields as $customer_meta_field) { - - $meta_keys[$customer_meta_field['id']] = array( + $meta_keys[ $customer_meta_field['id'] ] = array( 'type' => $customer_meta_field['type'], 'title' => $customer_meta_field['name'], 'description' => wu_get_isset($customer_meta_field, 'description', ''), @@ -249,14 +225,11 @@ function wu_get_customer_meta_types($form_slugs = false) { 'value' => '', 'exists' => false, ); - - } // end foreach; - - } // end foreach; + } + } return $meta_keys; - -} // end wu_get_customer_meta_types; +} /** * Returns all the meta data keys present on a customer. @@ -275,38 +248,33 @@ function wu_get_all_customer_meta($customer_id, $include_unset = true) { $customer = wu_get_customer($customer_id); if ($include_unset) { - $form_slugs = $customer ? array($customer->get_signup_form()) : false; $all_meta = array_merge($all_meta, wu_get_customer_meta_types($form_slugs)); + } - } // end if; - - if (!$customer) { - + if ( ! $customer) { return $all_meta; - - } // end if; + } $meta_keys = $customer->get_meta('wu_custom_meta_keys'); if ($meta_keys) { + $meta_keys = array_map( + function ($item) { - $meta_keys = array_map(function($item) { + $item['exists'] = true; - $item['exists'] = true; - - return $item; - - }, $meta_keys); + return $item; + }, + $meta_keys + ); $all_meta = wu_array_merge_recursive_distinct($all_meta, $meta_keys); - - } // end if; + } return $all_meta; - -} // end wu_get_all_customer_meta; +} /** * Returns a customer meta. @@ -323,15 +291,12 @@ function wu_get_customer_meta($customer_id, $meta_key, $default = false, $single $customer = wu_get_customer($customer_id); - if (!$customer) { - + if ( ! $customer) { return $default; - - } // end if; + } return $customer->get_meta($meta_key, $default, $single); - -} // end wu_get_customer_meta; +} /** * Updates a customer meta. @@ -353,30 +318,28 @@ function wu_update_customer_meta($customer_id, $key, $value, $type = null, $titl $customer = wu_get_customer($customer_id); - if (!$customer) { - + if ( ! $customer) { return false; - - } // end if; + } if ($type) { - $custom_keys = $customer->get_meta('wu_custom_meta_keys', array()); - $custom_keys = array_merge($custom_keys, array( - $key => array( - 'type' => $type, - 'title' => $title, - ), - )); + $custom_keys = array_merge( + $custom_keys, + array( + $key => array( + 'type' => $type, + 'title' => $title, + ), + ) + ); $customer->update_meta('wu_custom_meta_keys', $custom_keys); - - } // end if; + } return $customer->update_meta($key, $value); - -} // end wu_update_customer_meta; +} /** * Deletes a customer meta with a custom type field. @@ -391,25 +354,20 @@ function wu_delete_customer_meta($customer_id, $meta_key) { $customer = wu_get_customer($customer_id); - if (!$customer) { - + if ( ! $customer) { return false; - - } // end if; + } $custom_keys = $customer->get_meta('wu_custom_meta_keys', array()); - if (isset($custom_keys[$meta_key])) { - - unset($custom_keys[$meta_key]); + if (isset($custom_keys[ $meta_key ])) { + unset($custom_keys[ $meta_key ]); $customer->update_meta('wu_custom_meta_keys', $custom_keys); - - } // end if; + } return (bool) $customer->delete_meta($meta_key); - -} // end wu_delete_customer_meta; +} /** * Searches for a existing gateway customer among the customer memberships. @@ -422,16 +380,17 @@ function wu_delete_customer_meta($customer_id, $meta_key) { */ function wu_get_customer_gateway_id($customer_id, $allowed_gateways = array()) { - $memberships = wu_get_memberships(array( - 'customer_id' => absint($customer_id), - 'gateway__in' => $allowed_gateways, - 'number' => 1, - 'gateway_customer_id__not_in' => array(''), - )); + $memberships = wu_get_memberships( + array( + 'customer_id' => absint($customer_id), + 'gateway__in' => $allowed_gateways, + 'number' => 1, + 'gateway_customer_id__not_in' => array(''), + ) + ); - return !empty($memberships) ? $memberships[0]->get_gateway_customer_id() : ''; - -} // end wu_get_customer_gateway_id; + return ! empty($memberships) ? $memberships[0]->get_gateway_customer_id() : ''; +} /** * Create a unique username for a new customer based on the email address passed. @@ -452,23 +411,18 @@ function wu_username_from_email($email, $new_user_args = array(), $suffix = '') $username_parts = array(); if (isset($new_user_args['first_name'])) { - $username_parts[] = sanitize_user($new_user_args['first_name'], true); - - } // end if; + } if (isset($new_user_args['last_name'])) { - $username_parts[] = sanitize_user($new_user_args['last_name'], true); - - } // end if; + } // Remove empty parts. $username_parts = array_filter($username_parts); // If there are no parts, e.g. name had unicode chars, or was not provided, fallback to email. if (empty($username_parts)) { - $email_parts = explode('@', $email); $email_username = $email_parts[0]; @@ -485,26 +439,21 @@ function wu_username_from_email($email, $new_user_args = array(), $suffix = '') // Get the domain part, minus the dot. $email_username = strtok($email_parts[1], '.'); - - } // end if; + } $username_parts[] = sanitize_user($email_username, true); - - } // end if; + } $username = strtolower(implode('', $username_parts)); if ($suffix) { - $username .= $suffix; - - } // end if; + } $illegal_logins = (array) apply_filters('illegal_user_logins', array()); // phpcs:ignore // Stop illegal logins and generate a new random username. if (in_array(strtolower($username), array_map('strtolower', $illegal_logins), true)) { - $new_args = array(); /** @@ -525,17 +474,15 @@ function wu_username_from_email($email, $new_user_args = array(), $suffix = '') ); return wu_username_from_email($email, $new_args, $suffix); - - } // end if; + } if (username_exists($username)) { // Generate something unique to append to the username in case of a conflict with another user. $suffix = '-' . zeroise(wp_rand(0, 9999), 4); - return wu_username_from_email( $email, $new_user_args, $suffix ); - - } // end if; + return wu_username_from_email($email, $new_user_args, $suffix); + } /** * Filter new customer username. @@ -547,5 +494,4 @@ function wu_username_from_email($email, $new_user_args = array(), $suffix = '') * @param string $suffix Append string to username to make it unique. */ return apply_filters('wu_username_from_email', $username, $email, $new_user_args, $suffix); - -} // end wu_username_from_email; +} diff --git a/inc/functions/danger.php b/inc/functions/danger.php index c8ef3ca..93f8b08 100644 --- a/inc/functions/danger.php +++ b/inc/functions/danger.php @@ -28,13 +28,8 @@ function wu_drop_tables() { $except = apply_filters('wu_drop_tables_except', $except); foreach ($tables as $table) { - - if (!in_array($table->name, $except, true)) { - + if ( ! in_array($table->name, $except, true)) { $table->uninstall(); - - } // end if; - - } // end foreach; - -} // end wu_drop_tables; + } + } +} diff --git a/inc/functions/date.php b/inc/functions/date.php index e101e3a..973d705 100644 --- a/inc/functions/date.php +++ b/inc/functions/date.php @@ -21,28 +21,19 @@ defined('ABSPATH') || exit; function wu_validate_date($date, $format = 'Y-m-d H:i:s') { if (is_null($date)) { - return true; - - } elseif (!$date) { - + } elseif ( ! $date) { return false; - - } // end if; + } try { - $d = \DateTime::createFromFormat($format, $date); - } catch (\Throwable $exception) { - return false; - - } // end try; + } return $d && $d->format($format) === $date; - -} // end wu_validate_date; +} /** * Returns a Carbon object to deal with dates in a more compelling way. @@ -59,13 +50,12 @@ function wu_validate_date($date, $format = 'Y-m-d H:i:s') { */ function wu_date($date = false) { - if (!wu_validate_date($date)) { + if ( ! wu_validate_date($date)) { $date = date_i18n('Y-m-d H:i:s'); } return \DateTime::createFromFormat('Y-m-d H:i:s', $date); - -} // end wu_date; +} /** * Returns how many days ago the first date was in relation to the second date. @@ -87,8 +77,7 @@ function wu_get_days_ago($date_1, $date_2 = false) { $dateIntervar = $datetime_1->diff($datetime_2, false); return - $dateIntervar->days; - -} // end wu_get_days_ago; +} /** * Returns the current time from the network @@ -106,8 +95,7 @@ function wu_get_current_time($type = 'mysql', $gmt = false) { restore_current_blog(); return $time; - -} // end wu_get_current_time; +} /** * Returns a more user friendly version of the duration unit string. @@ -123,23 +111,22 @@ function wu_filter_duration_unit($unit, $length) { $new_unit = ''; switch ($unit) { - case 'day': - $new_unit = $length > 1 ? __('Days', 'wp-ultimo') : __('Day', 'wp-ultimo'); - break; - case 'month': - $new_unit = $length > 1 ? __('Months', 'wp-ultimo') : __('Month', 'wp-ultimo'); - break; - case 'year': - $new_unit = $length > 1 ? __('Years', 'wp-ultimo') : __('Year', 'wp-ultimo'); - break; - default: - $new_unit = $new_unit; - break; - } + case 'day': + $new_unit = $length > 1 ? __('Days', 'wp-ultimo') : __('Day', 'wp-ultimo'); + break; + case 'month': + $new_unit = $length > 1 ? __('Months', 'wp-ultimo') : __('Month', 'wp-ultimo'); + break; + case 'year': + $new_unit = $length > 1 ? __('Years', 'wp-ultimo') : __('Year', 'wp-ultimo'); + break; + default: + $new_unit = $new_unit; + break; + } return $new_unit; - -} // end wu_filter_duration_unit; +} /** * Get the human time diff. * @@ -159,20 +146,16 @@ function wu_human_time_diff($from, $limit = '-5 days', $to = false): string { // translators: %s: date. return sprintf(__('on %s', 'wp-ultimo'), date_i18n(get_option('date_format'), $timestamp_from)); - - } // end if; + } if ($to === false) { - $to = wu_get_current_time('timestamp'); // phpcs:ignore - - } // end if; + } $placeholder = wu_get_current_time('timestamp') > $timestamp_from ? __('%s ago', 'wp-ultimo') : __('In %s', 'wp-ultimo'); // phpcs:ignore return sprintf($placeholder, human_time_diff($timestamp_from, $to)); - -} // end wu_human_time_diff; +} /** * Converts php DateTime format to Javascript Moment format. @@ -227,11 +210,8 @@ function wu_convert_php_date_format_to_moment_js_format($php_date_format): strin // Converts escaped characters. foreach ($replacements as $from => $to) { - - $replacements['\\' . $from] = '[' . $from . ']'; - - } // end foreach; + $replacements[ '\\' . $from ] = '[' . $from . ']'; + } return strtr($php_date_format, $replacements); - -} // end wu_convert_php_date_format_to_moment_js_format; +} diff --git a/inc/functions/debug.php b/inc/functions/debug.php index 48a3ff3..2f42680 100644 --- a/inc/functions/debug.php +++ b/inc/functions/debug.php @@ -17,13 +17,12 @@ defined('ABSPATH') || exit; */ function wu_try_unlimited_server_limits() { - // Disable memory_limit by setting it to minus 1. + // Disable memory_limit by setting it to minus 1. @ini_set('memory_limit', '-1'); // phpcs:ignore - // Disable the time limit by setting it to 0. + // Disable the time limit by setting it to 0. @set_time_limit(0); // phpcs:ignore - -} // end wu_try_unlimited_server_limits; +} /** * Custom error handler for memory leaks @@ -40,5 +39,4 @@ function wu_setup_memory_limit_trap($return_type = 'plain') { $trap->set_return_type($return_type); $trap->setup(); - -} // end wu_setup_memory_limit_trap; +} diff --git a/inc/functions/discount-code.php b/inc/functions/discount-code.php index c527a7b..5f81ff8 100644 --- a/inc/functions/discount-code.php +++ b/inc/functions/discount-code.php @@ -9,7 +9,7 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Models\Discount_Code; +use WP_Ultimo\Models\Discount_Code; /** * Returns a discount code object searching by the code. @@ -22,8 +22,7 @@ use \WP_Ultimo\Models\Discount_Code; function wu_get_discount_code_by_code($coupon_code) { return \WP_Ultimo\Models\Discount_Code::get_by('code', $coupon_code); - -} // end wu_get_discount_code_by_code; +} /** * Gets a discount code based on the ID. * @@ -35,8 +34,7 @@ function wu_get_discount_code_by_code($coupon_code) { function wu_get_discount_code($discount_code_id) { return \WP_Ultimo\Models\Discount_Code::get_by_id($discount_code_id); - -} // end wu_get_discount_code; +} /** * Queries discount codes. @@ -49,8 +47,7 @@ function wu_get_discount_code($discount_code_id) { function wu_get_discount_codes($query = array()) { return \WP_Ultimo\Models\Discount_Code::query($query); - -} // end wu_get_discount_codes; +} /** * Calculates the discounted price after running it through the discount code. * @@ -65,24 +62,17 @@ function wu_get_discount_codes($query = array()) { function wu_get_discounted_price($base_price, $amount, $type, $format = true) { if ($type === 'percentage') { - $discounted_price = $base_price - ($base_price * ($amount / 100)); - } elseif ($type === 'absolute') { - $discounted_price = $base_price - $amount; + } - } // end if; - - if (!$format) { - + if ( ! $format) { return $discounted_price; - - } // end if; + } return number_format((float) $discounted_price, 2); - -} // end wu_get_discounted_price; +} /** * Creates a new discount code. * @@ -95,24 +85,26 @@ function wu_get_discounted_price($base_price, $amount, $type, $format = true) { */ function wu_create_discount_code($discount_code_data) { - $discount_code_data = wp_parse_args($discount_code_data, array( - 'max_uses' => true, - 'name' => false, - 'code' => false, - 'value' => false, - 'setup_fee_value' => false, - 'start_date' => false, - 'active' => true, - 'expiration_date' => false, - 'date_created' => wu_get_current_time('mysql', true), - 'date_modified' => wu_get_current_time('mysql', true), - 'skip_validation' => false, - )); + $discount_code_data = wp_parse_args( + $discount_code_data, + array( + 'max_uses' => true, + 'name' => false, + 'code' => false, + 'value' => false, + 'setup_fee_value' => false, + 'start_date' => false, + 'active' => true, + 'expiration_date' => false, + 'date_created' => wu_get_current_time('mysql', true), + 'date_modified' => wu_get_current_time('mysql', true), + 'skip_validation' => false, + ) + ); $discount_code = new Discount_Code($discount_code_data); $saved = $discount_code->save(); return is_wp_error($saved) ? $saved : $discount_code; - -} // end wu_create_discount_code; +} diff --git a/inc/functions/documentation.php b/inc/functions/documentation.php index fdf1de5..12d2fed 100644 --- a/inc/functions/documentation.php +++ b/inc/functions/documentation.php @@ -21,5 +21,4 @@ defined('ABSPATH') || exit; function wu_get_documentation_url($slug, $return_default = true) { return \WP_Ultimo\Documentation::get_instance()->get_link($slug, $return_default); - -} // end wu_get_documentation_url; +} diff --git a/inc/functions/domain.php b/inc/functions/domain.php index f1c0c12..60370e3 100644 --- a/inc/functions/domain.php +++ b/inc/functions/domain.php @@ -9,7 +9,7 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Models\Domain; +use WP_Ultimo\Models\Domain; /** * Returns a domain. @@ -22,8 +22,7 @@ use \WP_Ultimo\Models\Domain; function wu_get_domain($domain_id) { return \WP_Ultimo\Models\Domain::get_by_id($domain_id); - -} // end wu_get_domain; +} /** * Queries domains. @@ -36,8 +35,7 @@ function wu_get_domain($domain_id) { function wu_get_domains($query = array()) { return \WP_Ultimo\Models\Domain::query($query); - -} // end wu_get_domains; +} /** * Returns a domain based on domain. * @@ -49,8 +47,7 @@ function wu_get_domains($query = array()) { function wu_get_domain_by_domain($domain) { return \WP_Ultimo\Models\Domain::get_by('domain', $domain); - -} // end wu_get_domain_by_domain; +} /** * Creates a new domain. * @@ -63,26 +60,27 @@ function wu_get_domain_by_domain($domain) { */ function wu_create_domain($domain_data) { - $domain_data = wp_parse_args($domain_data, array( - 'blog_id' => false, - 'domain' => false, - 'active' => true, - 'primary_domain' => false, - 'secure' => false, - 'stage' => 'checking-dns', - 'date_created' => wu_get_current_time('mysql', true), - 'date_modified' => wu_get_current_time('mysql', true), - )); + $domain_data = wp_parse_args( + $domain_data, + array( + 'blog_id' => false, + 'domain' => false, + 'active' => true, + 'primary_domain' => false, + 'secure' => false, + 'stage' => 'checking-dns', + 'date_created' => wu_get_current_time('mysql', true), + 'date_modified' => wu_get_current_time('mysql', true), + ) + ); $domain = new Domain($domain_data); $saved = $domain->save(); if (is_wp_error($saved)) { - return $saved; - - } // end if; + } /* * Add the processing. @@ -90,8 +88,7 @@ function wu_create_domain($domain_data) { wu_enqueue_async_action('wu_async_process_domain_stage', array('domain_id' => $domain->get_id()), 'domain'); return $domain; - -} // end wu_create_domain; +} /** * Restores the original URL for a mapped URL. @@ -107,7 +104,6 @@ function wu_restore_original_url($url, $blog_id) { $site = wu_get_site($blog_id); if ($site) { - $original_site_url = $site->get_site_url(); $mapped_domain_url = $site->get_active_site_url(); @@ -117,16 +113,12 @@ function wu_restore_original_url($url, $blog_id) { $mapped_domain = wp_parse_url($mapped_domain_url, PHP_URL_HOST); if ($original_domain !== $mapped_domain) { - $url = str_replace($mapped_domain, $original_domain, $url); - - } // end if; - - } // end if; + } + } return $url; - -} // end wu_restore_original_url; +} /** * Adds the sso tags to a given URL. @@ -139,8 +131,7 @@ function wu_restore_original_url($url, $blog_id) { function wu_with_sso($url) { return \WP_Ultimo\SSO\SSO::with_sso($url); - -} // end wu_with_sso; +} /** * Compares the current domain to the main network domain. @@ -153,5 +144,4 @@ function wu_is_same_domain() { global $current_blog, $current_site; return wp_parse_url(wu_get_current_url(), PHP_URL_HOST) === $current_blog->domain && $current_blog->domain === $current_site->domain; - -} // end wu_is_same_domain; +} diff --git a/inc/functions/element.php b/inc/functions/element.php index 46851d0..9e566aa 100644 --- a/inc/functions/element.php +++ b/inc/functions/element.php @@ -17,6 +17,5 @@ defined('ABSPATH') || exit; */ function wu_element_setup_preview() { - !did_action('wu_element_preview') && do_action('wu_element_preview'); - -} // end wu_element_setup_preview; + ! did_action('wu_element_preview') && do_action('wu_element_preview'); +} diff --git a/inc/functions/email.php b/inc/functions/email.php index 4187542..9d24729 100644 --- a/inc/functions/email.php +++ b/inc/functions/email.php @@ -9,9 +9,9 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Managers\Email_Manager; -use \WP_Ultimo\Models\Email; -use \WP_Ultimo\Helpers\Sender; +use WP_Ultimo\Managers\Email_Manager; +use WP_Ultimo\Models\Email; +use WP_Ultimo\Helpers\Sender; /** * Returns a email. @@ -24,8 +24,7 @@ use \WP_Ultimo\Helpers\Sender; function wu_get_email($email_id) { return Email::get_by_id($email_id); - -} // end wu_get_email; +} /** * Returns a single email defined by a particular column and value. @@ -39,8 +38,7 @@ function wu_get_email($email_id) { function wu_get_email_by($column, $value) { return Email::get_by($column, $value); - -} // end wu_get_email_by; +} /** * Queries emails. @@ -55,19 +53,16 @@ function wu_get_emails($query = array()) { $query['type__in'] = array('system_email'); if (wu_get_isset($query, 'event')) { - $query['meta_query'] = array( 'event_query' => array( 'key' => 'wu_system_email_event', 'value' => wu_get_isset($query, 'event'), ), ); - - } // end if; + } return Email::query($query); - -} // end wu_get_emails; +} /** * Get all saved system email. @@ -78,12 +73,13 @@ function wu_get_emails($query = array()) { */ function wu_get_all_system_emails() { - return Email::query(array( - 'status__in' => array('draft', 'publish'), - 'type__in' => array('system_email'), - )); - -} // end wu_get_all_system_emails; + return Email::query( + array( + 'status__in' => array('draft', 'publish'), + 'type__in' => array('system_email'), + ) + ); +} /** * Get a single or all default registered system emails. @@ -96,8 +92,7 @@ function wu_get_all_system_emails() { function wu_get_default_system_emails($slug = '') { return Email_Manager::get_instance()->get_default_system_emails($slug); - -} // end wu_get_default_system_emails; +} /** * Create a single default system email. @@ -112,8 +107,7 @@ function wu_create_default_system_email($slug) { $args = wu_get_default_system_emails($slug); return Email_Manager::get_instance()->create_system_email($args); - -} // end wu_create_default_system_email; +} /** * Send an email to one or more users. @@ -128,8 +122,7 @@ function wu_create_default_system_email($slug) { function wu_send_mail($from = array(), $to = array(), $args = array()) { return Sender::send_mail($from, $to, $args); - -} // end wu_send_mail; +} /** * Returns email-like strings. @@ -145,8 +138,7 @@ function wu_send_mail($from = array(), $to = array(), $args = array()) { function wu_format_email_string($email, $name = false) { return $name ? sprintf('%s <%s>', $name, $email) : $email; - -} // end wu_format_email_string; +} /** * Creates a new email. @@ -160,20 +152,22 @@ function wu_format_email_string($email, $name = false) { */ function wu_create_email($email_data) { - $email_data = wp_parse_args($email_data, array( - 'type' => 'system_email', - 'event' => 'Laborum consectetur', - 'title' => 'Lorem Ipsum', - 'slug' => 'lorem-ipsum', - 'target' => 'admin', - 'date_created' => wu_get_current_time('mysql', true), - 'date_modified' => wu_get_current_time('mysql', true), - )); + $email_data = wp_parse_args( + $email_data, + array( + 'type' => 'system_email', + 'event' => 'Laborum consectetur', + 'title' => 'Lorem Ipsum', + 'slug' => 'lorem-ipsum', + 'target' => 'admin', + 'date_created' => wu_get_current_time('mysql', true), + 'date_modified' => wu_get_current_time('mysql', true), + ) + ); $email = new Email($email_data); $saved = $email->save(); return is_wp_error($saved) ? $saved : $email; - -} // end wu_create_email; +} diff --git a/inc/functions/env.php b/inc/functions/env.php index 3bf2b32..7ec7d07 100644 --- a/inc/functions/env.php +++ b/inc/functions/env.php @@ -35,5 +35,4 @@ function wu_env_picker($frontend_content, $backend_content, $is_admin = null) { $is_admin = is_null($is_admin) ? is_admin() : $is_admin; return $is_admin ? $backend_content : $frontend_content; - -} // end wu_env_picker; +} diff --git a/inc/functions/event.php b/inc/functions/event.php index 701553a..5c0812b 100644 --- a/inc/functions/event.php +++ b/inc/functions/event.php @@ -9,8 +9,8 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Managers\Event_Manager; -use \WP_Ultimo\Models\Event; +use WP_Ultimo\Managers\Event_Manager; +use WP_Ultimo\Models\Event; /** * Add a new event to the System. @@ -24,8 +24,7 @@ use \WP_Ultimo\Models\Event; function wu_do_event($slug, $payload) { return Event_Manager::get_instance()->do_event($slug, $payload); - -} // end wu_do_event; +} /** * Register a new event globally in order to set the params. @@ -39,8 +38,7 @@ function wu_do_event($slug, $payload) { function wu_register_event_type($slug, $args) { return Event_Manager::get_instance()->register_event($slug, $args); - -} // end wu_register_event_type; +} /** * Gets all th events registered in the system @@ -52,8 +50,7 @@ function wu_register_event_type($slug, $args) { function wu_get_event_types() { return Event_Manager::get_instance()->get_events(); - -} // end wu_get_event_types; +} /** * Get the available event types as a key => label array. @@ -67,14 +64,11 @@ function wu_get_event_types_as_options() { $event_types = Event_Manager::get_instance()->get_events(); foreach ($event_types as $event_type_key => &$event_type) { - $event_type = $event_type['name']; - - } // end foreach; + } return $event_types; - -} // end wu_get_event_types_as_options; +} /** * Gets all th events registered in the system. @@ -87,8 +81,7 @@ function wu_get_event_types_as_options() { function wu_get_event_type($slug) { return Event_Manager::get_instance()->get_event($slug); - -} // end wu_get_event_type; +} /** * Queries events. @@ -101,8 +94,7 @@ function wu_get_event_type($slug) { function wu_get_events($query = array()) { return \WP_Ultimo\Models\Event::query($query); - -} // end wu_get_events; +} /** * Gets a event on the ID. * @@ -114,8 +106,7 @@ function wu_get_events($query = array()) { function wu_get_event($event_id) { return \WP_Ultimo\Models\Event::get_by_id($event_id); - -} // end wu_get_event; +} /** * Returns a event based on slug. * @@ -127,8 +118,7 @@ function wu_get_event($event_id) { function wu_get_event_by_slug($event_slug) { return \WP_Ultimo\Models\Event::get_by('slug', $event_slug); - -} // end wu_get_event_by_slug; +} /** * Creates a new event. * @@ -143,27 +133,29 @@ function wu_create_event($event_data) { $author_id = function_exists('get_current_user_id') ? get_current_user_id() : 0; - $event_data = wp_parse_args($event_data, array( - 'severity' => Event::SEVERITY_NEUTRAL, - 'initiator' => 'system', - 'author_id' => $author_id, - 'object_type' => 'network', - 'object_id' => 0, - 'date_created' => wu_get_current_time('mysql', true), - 'payload' => array( - 'key' => 'None', - 'old_value' => 'None', - 'new_value' => 'None', - ), - )); + $event_data = wp_parse_args( + $event_data, + array( + 'severity' => Event::SEVERITY_NEUTRAL, + 'initiator' => 'system', + 'author_id' => $author_id, + 'object_type' => 'network', + 'object_id' => 0, + 'date_created' => wu_get_current_time('mysql', true), + 'payload' => array( + 'key' => 'None', + 'old_value' => 'None', + 'new_value' => 'None', + ), + ) + ); $event = new Event($event_data); $saved = $event->save(); return is_wp_error($saved) ? $saved : $event; - -} // end wu_create_event; +} /** * Generates payload arrays for events. @@ -180,10 +172,8 @@ function wu_generate_event_payload($model_name, $model = false): array { $payload = array(); - if (!$model) { - + if ( ! $model) { switch ($model_name) { - case 'product': $model = wu_mock_product(); break; @@ -202,19 +192,14 @@ function wu_generate_event_payload($model_name, $model = false): array { case 'domain': $model = wu_mock_domain(); break; + } - } // end switch; - - if (!$model) { - + if ( ! $model) { return array(); - - } // end if; - - } // end if; + } + } if ($model_name === 'customer') { - $payload = $model->to_search_results(); $payload = array( @@ -225,13 +210,14 @@ function wu_generate_event_payload($model_name, $model = false): array { 'customer_email_verification' => $payload['email_verification'], 'customer_avatar' => $payload['avatar'], 'customer_billing_address' => $payload['billing_address'], - 'customer_manage_url' => wu_network_admin_url('wp-ultimo-edit-customer', array( - 'id' => $model->get_id(), - )), + 'customer_manage_url' => wu_network_admin_url( + 'wp-ultimo-edit-customer', + array( + 'id' => $model->get_id(), + ) + ), ); - } elseif ($model_name === 'membership') { - $payload = $model->to_search_results(); $p = $payload; @@ -248,13 +234,14 @@ function wu_generate_event_payload($model_name, $model = false): array { 'membership_description' => $p['formatted_price'], 'membership_gateway' => $p['gateway'], 'membership_date_expiration' => $p['date_expiration'], - 'membership_manage_url' => wu_network_admin_url('wp-ultimo-edit-membership', array( - 'id' => $model->get_id(), - )), + 'membership_manage_url' => wu_network_admin_url( + 'wp-ultimo-edit-membership', + array( + 'id' => $model->get_id(), + ) + ), ); - } elseif ($model_name === 'product') { - $payload = $model->to_search_results(); $payload = array( @@ -266,13 +253,14 @@ function wu_generate_event_payload($model_name, $model = false): array { 'product_currency' => $payload['currency'], 'product_description' => $payload['formatted_price'], 'product_image' => $payload['image'], - 'product_manage_url' => wu_network_admin_url('wp-ultimo-edit-payment', array( - 'id' => $model->get_id(), - )), + 'product_manage_url' => wu_network_admin_url( + 'wp-ultimo-edit-payment', + array( + 'id' => $model->get_id(), + ) + ), ); - } elseif ($model_name === 'payment') { - $payload = $model->to_search_results(); $payload = array( @@ -290,13 +278,14 @@ function wu_generate_event_payload($model_name, $model = false): array { 'payment_date_created' => $payload['date_created'], 'payment_gateway' => $payload['gateway'], 'payment_invoice_url' => $model->get_invoice_url(), - 'payment_manage_url' => wu_network_admin_url('wp-ultimo-edit-payment', array( - 'id' => $model->get_id(), - )), + 'payment_manage_url' => wu_network_admin_url( + 'wp-ultimo-edit-payment', + array( + 'id' => $model->get_id(), + ) + ), ); - } elseif ($model_name === 'site') { - $payload = $model->to_search_results(); $payload = array( @@ -305,13 +294,14 @@ function wu_generate_event_payload($model_name, $model = false): array { 'site_description' => $payload['description'], 'site_url' => $payload['siteurl'], 'site_admin_url' => get_admin_url($model->get_id()), - 'site_manage_url' => wu_network_admin_url('wp-ultimo-edit-site', array( - 'id' => $model->get_id(), - )), + 'site_manage_url' => wu_network_admin_url( + 'wp-ultimo-edit-site', + array( + 'id' => $model->get_id(), + ) + ), ); - } elseif ($model_name === 'domain') { - $payload = $model->to_search_results(); $payload = array( @@ -323,16 +313,17 @@ function wu_generate_event_payload($model_name, $model = false): array { 'domain_primary' => var_export(wu_string_to_bool($payload['primary_domain']), true), 'domain_secure' => var_export(wu_string_to_bool($payload['secure']), true), 'domain_date_created' => $payload['date_created'], - 'domain_manage_url' => wu_network_admin_url('wp-ultimo-edit-domain', array( - 'id' => $model->get_id(), - )), + 'domain_manage_url' => wu_network_admin_url( + 'wp-ultimo-edit-domain', + array( + 'id' => $model->get_id(), + ) + ), ); - - } // end if; + } return $payload; - -} // end wu_generate_event_payload; +} /** * Checks if the payload is a callable or if it's ready to use. @@ -345,10 +336,8 @@ function wu_generate_event_payload($model_name, $model = false): array { function wu_maybe_lazy_load_payload($payload) { if (is_callable($payload)) { - $payload = (array) call_user_func($payload); - - } // end if; + } /* * Adds the version number for control purposes. @@ -356,5 +345,4 @@ function wu_maybe_lazy_load_payload($payload) { $payload['wu_version'] = wu_get_version(); return $payload; - -} // end wu_maybe_lazy_load_payload; +} diff --git a/inc/functions/financial.php b/inc/functions/financial.php index 7a2c861..7c4907a 100644 --- a/inc/functions/financial.php +++ b/inc/functions/financial.php @@ -9,8 +9,8 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Database\Payments\Payment_Status; -use \WP_Ultimo\Database\Memberships\Membership_Status; +use WP_Ultimo\Database\Payments\Payment_Status; +use WP_Ultimo\Database\Memberships\Membership_Status; /** * Calculates the Monthly Recurring Revenue of the network. @@ -22,22 +22,21 @@ function wu_calculate_mrr() { $total_mrr = 0; - $memberships = wu_get_memberships(array( - 'recurring' => true, - 'status__in' => array( - Membership_Status::ACTIVE, - ), - )); + $memberships = wu_get_memberships( + array( + 'recurring' => true, + 'status__in' => array( + Membership_Status::ACTIVE, + ), + ) + ); foreach ($memberships as $membership) { - $recurring_amount = $membership->get_amount(); - if (!$membership->is_recurring()) { - + if ( ! $membership->is_recurring()) { continue; - - } // end if; + } $duration = $membership->get_duration() ? $membership->get_duration() : 1; @@ -48,12 +47,10 @@ function wu_calculate_mrr() { $mrr = $recurring_amount / ($duration * $normalized_duration_unit); $total_mrr += $mrr; - - } // end foreach; + } return $total_mrr; - -} // end wu_calculate_mrr; +} /** * Converts the duration unit strings such as 'day', 'year' and such into @@ -69,26 +66,25 @@ function wu_convert_duration_unit_to_month($duration_unit) { $months = 1; switch ($duration_unit) { - case 'day': - $months = 1 / 30; - break; - case 'week': - $months = 1 / 4; - break; - case 'month': - $months = 1; - break; - case 'year': - $months = 12; - break; - default: - $months = $months; - break; - } // end switch; + case 'day': + $months = 1 / 30; + break; + case 'week': + $months = 1 / 4; + break; + case 'month': + $months = 1; + break; + case 'year': + $months = 12; + break; + default: + $months = $months; + break; + } return $months; - -} // end wu_convert_duration_unit_to_month; +} /** * Calculates the Annual Recurring Revenue. @@ -101,8 +97,7 @@ function wu_convert_duration_unit_to_month($duration_unit) { function wu_calculate_arr() { return wu_calculate_mrr() * 12; - -} // end wu_calculate_arr; +} /** * Calculates the total revenue. @@ -128,32 +123,25 @@ function wu_calculate_revenue($start_date = false, $end_date = false, $inclusive ); if ($start_date) { - $query_args['date_query']['column'] = 'date_created'; $query_args['date_query']['after'] = $start_date; $query_args['date_query']['inclusive'] = $inclusive; - - } // end if; + } if ($end_date) { - $query_args['date_query']['column'] = 'date_created'; $query_args['date_query']['before'] = $end_date; $query_args['date_query']['inclusive'] = $inclusive; - - } // end if; + } $payments = wu_get_payments($query_args); foreach ($payments as $payment) { - $total_revenue += (float) $payment->total; - - } // end foreach; + } return $total_revenue; - -} // end wu_calculate_revenue; +} /** * Calculates the total refunds. @@ -179,32 +167,25 @@ function wu_calculate_refunds($start_date = false, $end_date = false, $inclusive ); if ($start_date) { - $query_args['date_query']['column'] = 'date_created'; $query_args['date_query']['after'] = $start_date; $query_args['date_query']['inclusive'] = $inclusive; - - } // end if; + } if ($end_date) { - $query_args['date_query']['column'] = 'date_created'; $query_args['date_query']['before'] = $end_date; $query_args['date_query']['inclusive'] = $inclusive; - - } // end if; + } $payments = wu_get_payments($query_args); foreach ($payments as $payment) { - $total_revenue += -(float) $payment->refund_total; - - } // end foreach; + } return $total_revenue; - -} // end wu_calculate_refunds; +} /** * Calculates the taxes collected grouped by the rate. @@ -223,18 +204,14 @@ function wu_calculate_taxes_by_rate($start_date = false, $end_date = false, $inc ); if ($start_date) { - $query_args['date_query']['after'] = $start_date; $query_args['date_query']['inclusive'] = $inclusive; - - } // end if; + } if ($end_date) { - $query_args['date_query']['before'] = $end_date; $query_args['date_query']['inclusive'] = $inclusive; - - } // end if; + } $order = 0; @@ -243,22 +220,17 @@ function wu_calculate_taxes_by_rate($start_date = false, $end_date = false, $inc $line_items_groups = \WP_Ultimo\Checkout\Line_Item::get_line_items($query_args); foreach ($line_items_groups as $line_items_group) { - - $order++; + ++$order; foreach ($line_items_group as $line_item) { - $tax_name = $line_item->get_tax_label(); if ($line_item->get_tax_rate() <= 0) { - continue; + } - } // end if; - - if (!wu_get_isset($taxes_paid_list, $tax_name)) { - - $taxes_paid_list[$tax_name] = array( + if ( ! wu_get_isset($taxes_paid_list, $tax_name)) { + $taxes_paid_list[ $tax_name ] = array( 'title' => $tax_name, 'country' => '', 'state' => '', @@ -266,21 +238,15 @@ function wu_calculate_taxes_by_rate($start_date = false, $end_date = false, $inc 'tax_rate' => $line_item->get_tax_rate(), 'tax_total' => $line_item->get_tax_total(), ); - } else { - - $taxes_paid_list[$tax_name]['tax_total'] += $line_item->get_tax_total(); - $taxes_paid_list[$tax_name]['order_count'] += $order; - - } // end if; - - } // end foreach; - - } // end foreach; + $taxes_paid_list[ $tax_name ]['tax_total'] += $line_item->get_tax_total(); + $taxes_paid_list[ $tax_name ]['order_count'] += $order; + } + } + } return $taxes_paid_list; - -} // end wu_calculate_taxes_by_rate; +} /** * Aggregate financial data on a per product basis. @@ -300,18 +266,14 @@ function wu_calculate_financial_data_by_product($start_date = false, $end_date = ); if ($start_date) { - $query_args['date_query']['after'] = $start_date; $query_args['date_query']['inclusive'] = $inclusive; - - } // end if; + } if ($end_date) { - $query_args['date_query']['before'] = $end_date; $query_args['date_query']['inclusive'] = $inclusive; - - } // end if; + } $line_items_groups = \WP_Ultimo\Checkout\Line_Item::get_line_items($query_args); @@ -320,43 +282,32 @@ function wu_calculate_financial_data_by_product($start_date = false, $end_date = $products = wu_get_products(); foreach ($products as $product) { - - $data[$product->get_id()] = array( + $data[ $product->get_id() ] = array( 'label' => $product->get_name(), 'revenue' => 0, ); - - } // end foreach; + } foreach ($line_items_groups as $line_items_group) { - foreach ($line_items_group as $line_item) { - $product_id = $line_item->get_product_id(); if (empty($product_id)) { - continue; + } - } // end if; - - if (!wu_get_isset($data, $product_id)) { - + if ( ! wu_get_isset($data, $product_id)) { continue; + } - } // end if; - - $data[$product_id]['revenue'] += $line_item->get_total(); - - } // end foreach; - - } // end foreach; + $data[ $product_id ]['revenue'] += $line_item->get_total(); + } + } uasort($data, fn($a, $b) => wu_sort_by_column($b, $a, 'revenue')); return $data; - -} // end wu_calculate_financial_data_by_product; +} /** * Calculates the taxes collected grouped by date. @@ -375,18 +326,14 @@ function wu_calculate_taxes_by_day($start_date = false, $end_date = false, $incl ); if ($start_date) { - $query_args['date_query']['after'] = $start_date; $query_args['date_query']['inclusive'] = $inclusive; - - } // end if; + } if ($end_date) { - $query_args['date_query']['before'] = $end_date; $query_args['date_query']['inclusive'] = $inclusive; - - } // end if; + } $line_items_groups = \WP_Ultimo\Checkout\Line_Item::get_line_items($query_args); @@ -401,47 +348,36 @@ function wu_calculate_taxes_by_day($start_date = false, $end_date = false, $incl $days = array_reverse(iterator_to_array($period)); foreach ($days as $day_datetime) { - - $data[$day_datetime->format('Y-m-d')] = array( + $data[ $day_datetime->format('Y-m-d') ] = array( 'order_count' => 0, 'total' => 0, 'tax_total' => 0, 'net_profit' => 0, ); - - } // end foreach; + } foreach ($line_items_groups as $line_items_group) { - foreach ($line_items_group as $line_item) { - $date = gmdate('Y-m-d', strtotime((string) $line_item->date_created)); - if (!wu_get_isset($data, $date)) { - - $data[$date] = array( + if ( ! wu_get_isset($data, $date)) { + $data[ $date ] = array( 'order_count' => 0, 'total' => $line_item->get_total(), 'tax_total' => $line_item->get_tax_total(), 'net_profit' => $line_item->get_total() - $line_item->get_tax_total(), ); - } else { - - $data[$date]['order_count'] += 1; - $data[$date]['total'] += $line_item->get_total(); - $data[$date]['tax_total'] += $line_item->get_tax_total(); - $data[$date]['net_profit'] += $line_item->get_total() - $line_item->get_tax_total(); - - } // end if; - - } // end foreach; - - } // end foreach; + $data[ $date ]['order_count'] += 1; + $data[ $date ]['total'] += $line_item->get_total(); + $data[ $date ]['tax_total'] += $line_item->get_tax_total(); + $data[ $date ]['net_profit'] += $line_item->get_total() - $line_item->get_tax_total(); + } + } + } return $data; - -} // end wu_calculate_taxes_by_day; +} /** * Calculates the taxes collected this year, segregated by month. @@ -454,10 +390,8 @@ function wu_calculate_taxes_by_month() { $cache = get_site_transient('wu_tax_monthly_stats'); if (is_array($cache)) { - return $cache; - - } // end if; + } $query_args = array( 'date_query' => array( @@ -480,49 +414,38 @@ function wu_calculate_taxes_by_month() { $months = iterator_to_array($period); foreach ($months as $month_datetime) { - - $data[$month_datetime->format('n')] = array( + $data[ $month_datetime->format('n') ] = array( 'order_count' => 0, 'total' => 0, 'tax_total' => 0, 'net_profit' => 0, ); - - } // end foreach; + } foreach ($line_items_groups as $line_items_group) { - foreach ($line_items_group as $line_item) { - $date = gmdate('n', strtotime((string) $line_item->date_created)); - if (!wu_get_isset($data, $date)) { - - $data[$date] = array( + if ( ! wu_get_isset($data, $date)) { + $data[ $date ] = array( 'order_count' => 0, 'total' => $line_item->get_total(), 'tax_total' => $line_item->get_tax_total(), 'net_profit' => $line_item->get_total() - $line_item->get_tax_total(), ); - } else { - - $data[$date]['order_count'] += 1; - $data[$date]['total'] += $line_item->get_total(); - $data[$date]['tax_total'] += $line_item->get_tax_total(); - $data[$date]['net_profit'] += $line_item->get_total() - $line_item->get_tax_total(); - - } // end if; - - } // end foreach; - - } // end foreach; + $data[ $date ]['order_count'] += 1; + $data[ $date ]['total'] += $line_item->get_total(); + $data[ $date ]['tax_total'] += $line_item->get_tax_total(); + $data[ $date ]['net_profit'] += $line_item->get_total() - $line_item->get_tax_total(); + } + } + } set_site_transient('wu_tax_monthly_stats', $data); return $data; - -} // end wu_calculate_taxes_by_month; +} /** * Returns the number of sign-ups by form slug. @@ -543,18 +466,14 @@ function wu_calculate_signups_by_form($start_date = false, $end_date = false, $i ); if ($start_date) { - $query['date_query']['after'] = $start_date; $query['date_query']['inclusive'] = $inclusive; - - } // end if; + } if ($end_date) { - $query['date_query']['before'] = $end_date; $query['date_query']['inclusive'] = $inclusive; - - } // end if; + } $date_query = new \WP_Date_Query($query['date_query']); @@ -577,4 +496,4 @@ function wu_calculate_signups_by_form($start_date = false, $end_date = false, $i return $results; -} // end wu_calculate_signups_by_form; +} diff --git a/inc/functions/form.php b/inc/functions/form.php index 8ca509c..8b21080 100644 --- a/inc/functions/form.php +++ b/inc/functions/form.php @@ -9,7 +9,7 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Managers\Form_Manager; +use WP_Ultimo\Managers\Form_Manager; /** * Registers a new Ajax Form. @@ -28,8 +28,7 @@ use \WP_Ultimo\Managers\Form_Manager; function wu_register_form($form_id, $atts = array()) { return Form_Manager::get_instance()->register_form($form_id, $atts); - -} // end wu_register_form; +} /** * Returns the ajax URL for a given form. @@ -45,21 +44,21 @@ function wu_register_form($form_id, $atts = array()) { function wu_get_form_url($form_id, $atts = array(), $inline = false) { if ($inline) { - - $atts = wp_parse_args($atts, array( - 'inlineId' => $form_id, - 'width' => '400', - 'height' => '360', - )); + $atts = wp_parse_args( + $atts, + array( + 'inlineId' => $form_id, + 'width' => '400', + 'height' => '360', + ) + ); // TB_inline?height=300&width=300&inlineId=wu-add-field return add_query_arg($atts, '#TB_inline'); - - } // end if; + } return Form_Manager::get_instance()->get_form_url($form_id, $atts, $inline); - -} // end wu_get_form_url; +} /** * Adds our fork of the thickbox script. @@ -70,5 +69,4 @@ function wu_get_form_url($form_id, $atts = array(), $inline = false) { function add_wubox() { // phpcs:ignore wp_enqueue_script('wubox'); - -} // end add_wubox; +} diff --git a/inc/functions/fs.php b/inc/functions/fs.php index 5a45c84..c76918a 100644 --- a/inc/functions/fs.php +++ b/inc/functions/fs.php @@ -21,19 +21,16 @@ function wu_get_main_site_upload_dir() { is_multisite() && switch_to_blog($current_site->blog_id); - if (!defined('WP_CONTENT_URL')) { - + if ( ! defined('WP_CONTENT_URL')) { define('WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); - - } // end if; + } $uploads = wp_upload_dir(null, false); is_multisite() && restore_current_blog(); return $uploads; - -} // end wu_get_main_site_upload_dir; +} /** * Creates a WP Multisite WaaS folder inside the uploads folder - if needed - and return its path. @@ -53,7 +50,7 @@ function wu_maybe_create_folder($folder, ...$path) { /* * Checks if the folder exists. */ - if (!file_exists($folder_path)) { + if ( ! file_exists($folder_path)) { // Creates the Folder wp_mkdir_p($folder_path); @@ -61,34 +58,28 @@ function wu_maybe_create_folder($folder, ...$path) { // Creates htaccess $htaccess = $folder_path . '.htaccess'; - if (!file_exists($htaccess)) { - + if ( ! file_exists($htaccess)) { $fp = @fopen($htaccess, 'w'); @fputs($fp, 'deny from all'); // phpcs:ignore @fclose($fp); // phpcs:ignore - - } // end if; + } // Creates index $index = $folder_path . 'index.html'; - if (!file_exists($index)) { - + if ( ! file_exists($index)) { $fp = @fopen($index, 'w'); @fputs($fp, ''); // phpcs:ignore @fclose($fp); // phpcs:ignore - - } // end if; - - } // end if; + } + } return $folder_path . implode('/', $path); - -} // end wu_maybe_create_folder; +} /** * Gets the URL for the folders created with maybe_create_folder(). @@ -106,5 +97,4 @@ function wu_get_folder_url($folder) { $folder_url = trailingslashit($uploads['baseurl'] . '/' . $folder); return set_url_scheme($folder_url); - -} // end wu_get_folder_url; +} diff --git a/inc/functions/gateway.php b/inc/functions/gateway.php index 8a9af6e..675cf99 100644 --- a/inc/functions/gateway.php +++ b/inc/functions/gateway.php @@ -25,15 +25,12 @@ use WP_Ultimo\Managers\Gateway_Manager; */ function wu_register_gateway($id, $title, $desc, $class_name, $hidden = false) { - if (!did_action('wu_register_gateways')) { - + if ( ! did_action('wu_register_gateways')) { _doing_it_wrong(__FUNCTION__, __('You should not register new payment gateways before the wu_register_gateways hook.', 'wp-ultimo'), '2.0.0'); - - } // end if; + } return Gateway_Manager::get_instance()->register_gateway($id, $title, $desc, $class_name, $hidden); - -} // end wu_register_gateway; +} /** * Returns the currently registered gateways. @@ -45,8 +42,7 @@ function wu_register_gateway($id, $title, $desc, $class_name, $hidden = false) { function wu_get_gateways() { return Gateway_Manager::get_instance()->get_registered_gateways(); - -} // end wu_get_gateways; +} /** * Returns the currently registered and active gateways. @@ -61,18 +57,13 @@ function wu_get_active_gateways() { $active_gateways = (array) wu_get_setting('active_gateways', array()); foreach ($active_gateways as $active_gateway) { - if (Gateway_Manager::get_instance()->is_gateway_registered($active_gateway)) { - - $gateways[$active_gateway] = Gateway_Manager::get_instance()->get_gateway($active_gateway); - - } // end if; - - } // end foreach; + $gateways[ $active_gateway ] = Gateway_Manager::get_instance()->get_gateway($active_gateway); + } + } return apply_filters('wu_get_active_gateways', $gateways); - -} // end wu_get_active_gateways; +} /** * Returns a gateway class if it exists. @@ -87,17 +78,14 @@ function wu_get_gateway($id, $subscription = null) { $gateway = Gateway_Manager::get_instance()->get_gateway($id); - if (!$gateway) { - + if ( ! $gateway) { return false; - - } // end if; + } $gateway_class = new $gateway['class_name'](); return $gateway_class; - -} // end wu_get_gateway; +} /** * Returns the list of available gateways as key => name. @@ -110,22 +98,17 @@ function wu_get_gateway_as_options() { $options = array(); foreach (wu_get_gateways() as $gateway_slug => $gateway) { - $instance = class_exists($gateway['class_name']) ? new $gateway['class_name']() : false; if ($instance === false || $gateway['hidden']) { - continue; + } - } // end if; - - $options[$gateway_slug] = $gateway['title']; - - } // end foreach; + $options[ $gateway_slug ] = $gateway['title']; + } return $options; - -} // end wu_get_gateway_as_options; +} /** * Get the active gateways. @@ -138,21 +121,16 @@ function wu_get_active_gateway_as_options() { $options = array(); foreach (wu_get_active_gateways() as $gateway_slug => $gateway) { - $instance = class_exists($gateway['class_name']) ? new $gateway['class_name']() : false; if ($instance === false || $gateway['hidden']) { - continue; - - } // end if; + } $title = $instance->get_public_title(); - $options[$gateway_slug] = apply_filters("wu_gateway_{$gateway_slug}_as_option_title", $title, $gateway); - - } // end foreach; + $options[ $gateway_slug ] = apply_filters("wu_gateway_{$gateway_slug}_as_option_title", $title, $gateway); + } return $options; - -} // end wu_get_active_gateway_as_options; +} diff --git a/inc/functions/generator.php b/inc/functions/generator.php index 43fdc46..81f533e 100644 --- a/inc/functions/generator.php +++ b/inc/functions/generator.php @@ -21,7 +21,6 @@ function wu_generate_csv($file_name, $data = array()) { $fp = fopen('php://output', 'w'); if ($fp && $data) { - header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename="' . $file_name . '.csv"'); @@ -31,19 +30,11 @@ function wu_generate_csv($file_name, $data = array()) { header('Expires: 0'); foreach ($data as $data_line) { - if (is_array($data_line)) { - fputcsv($fp, array_values($data_line)); - } elseif (is_object($data_line)) { - fputcsv($fp, array_values(get_object_vars($data_line))); - - } // end if; - - } // end foreach; - - } // end if; - -} // end wu_generate_csv; + } + } + } +} diff --git a/inc/functions/geolocation.php b/inc/functions/geolocation.php index ff205c2..09ccfee 100644 --- a/inc/functions/geolocation.php +++ b/inc/functions/geolocation.php @@ -20,5 +20,4 @@ function wu_get_ip() { $geolocation = \WP_Ultimo\Geolocation::geolocate_ip('', true); return apply_filters('wu_get_ip', $geolocation['ip']); - -} // end wu_get_ip; +} diff --git a/inc/functions/helper.php b/inc/functions/helper.php index f7a7726..57093fc 100644 --- a/inc/functions/helper.php +++ b/inc/functions/helper.php @@ -9,8 +9,8 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Exception\Runtime_Exception; -use \Psr\Log\LogLevel; +use WP_Ultimo\Exception\Runtime_Exception; +use Psr\Log\LogLevel; /** * Returns the WP Multisite WaaS version. @@ -21,8 +21,7 @@ use \Psr\Log\LogLevel; function wu_get_version() { return class_exists(\WP_Ultimo::class) ? \WP_Ultimo::VERSION : ''; - -} // end wu_get_version; +} /** * Check the debug status. @@ -33,8 +32,7 @@ function wu_get_version() { function wu_is_debug() { return defined('WP_ULTIMO_DEBUG') && WP_ULTIMO_DEBUG; - -} // end wu_is_debug; +} /** * Checks if WP Multisite WaaS is being loaded as a must-use plugin. @@ -45,8 +43,7 @@ function wu_is_debug() { function wu_is_must_use() { return defined('WP_ULTIMO_IS_MUST_USE') && WP_ULTIMO_IS_MUST_USE; - -} // end wu_is_must_use; +} /** * Checks if an array key value is set and returns it. @@ -68,15 +65,12 @@ function wu_is_must_use() { */ function wu_get_isset($array, $key, $default = false) { - if (!is_array($array)) { - + if ( ! is_array($array)) { $array = (array) $array; + } - } // end if; - - return isset($array[$key]) ? $array[$key] : $default; - -} // end wu_get_isset; + return isset($array[ $key ]) ? $array[ $key ] : $default; +} /** * Returns the main site id for the network. @@ -91,8 +85,7 @@ function wu_get_main_site_id() { global $current_site; return $current_site->blog_id; - -} // end wu_get_main_site_id; +} /** * This function return 'slugfied' options terms to be used as options ids. @@ -104,8 +97,7 @@ function wu_get_main_site_id() { function wu_slugify($term) { return "wp-ultimo_$term"; - -} // end wu_slugify; +} /** * Returns the full path to the plugin folder. * @@ -115,8 +107,7 @@ function wu_slugify($term) { function wu_path($dir): string { return WP_ULTIMO_PLUGIN_DIR . $dir; // @phpstan-ignore-line - -} // end wu_path; +} /** * Returns the URL to the plugin folder. @@ -128,8 +119,7 @@ function wu_path($dir): string { function wu_url($dir) { return apply_filters('wp_ultimo_url', WP_ULTIMO_PLUGIN_URL . $dir); // @phpstan-ignore-line - -} // end wu_url; +} /** * Shorthand to retrieving variables from $_GET, $_POST and $_REQUEST; @@ -142,11 +132,10 @@ function wu_url($dir) { */ function wu_request($key, $default = false) { - $value = isset($_REQUEST[$key]) ? stripslashes_deep($_REQUEST[$key]) : $default; + $value = isset($_REQUEST[ $key ]) ? stripslashes_deep($_REQUEST[ $key ]) : $default; return apply_filters('wu_request', $value, $key, $default); - -} // end wu_request; +} /** * Throws an exception if a given hook was not yet run. @@ -159,15 +148,12 @@ function wu_request($key, $default = false) { */ function _wu_require_hook($hook = 'ms_loaded') { // phpcs:ignore - if (!did_action($hook)) { - + if ( ! did_action($hook)) { $message = "This function can not yet be run as it relies on processing that happens on hook {$hook}."; throw new Runtime_Exception($message); - - } // end if; - -} // end _wu_require_hook; + } +} /** * Checks if reflection is available. @@ -183,14 +169,11 @@ function wu_are_code_comments_available() { static $res; if ($res === null) { - $res = (bool) (new \ReflectionFunction(__FUNCTION__))->getDocComment(); - - } // end if; + } return $res; - -} // end wu_are_code_comments_available; +} /** * Join string into a single path string. @@ -202,18 +185,15 @@ function wu_are_code_comments_available() { function wu_path_join(...$parts): string { if (sizeof($parts) === 0) { - return ''; - - } // end if; + } $prefix = ($parts[0] === DIRECTORY_SEPARATOR) ? DIRECTORY_SEPARATOR : ''; - $processed = array_filter(array_map(fn($part) => rtrim((string) $part, DIRECTORY_SEPARATOR), $parts), fn($part) => !empty($part)); + $processed = array_filter(array_map(fn($part) => rtrim((string) $part, DIRECTORY_SEPARATOR), $parts), fn($part) => ! empty($part)); return $prefix . implode(DIRECTORY_SEPARATOR, $processed); - -} // end wu_path_join; +} /** @@ -229,8 +209,7 @@ function wu_path_join(...$parts): string { function wu_log_add($handle, $message, $log_level = LogLevel::INFO) { \WP_Ultimo\Logger::add($handle, $message, $log_level); - -} // end wu_log_add; +} /** * Clear entries from chosen file. @@ -243,8 +222,7 @@ function wu_log_add($handle, $message, $log_level = LogLevel::INFO) { function wu_log_clear($handle) { \WP_Ultimo\Logger::clear($handle); - -} // end wu_log_clear; +} /** * Maybe log errors to the file. @@ -257,12 +235,9 @@ function wu_log_clear($handle) { function wu_maybe_log_error($e) { if (defined('WP_DEBUG') && WP_DEBUG) { - error_log($e); - - } // end if; - -} // end wu_maybe_log_error; + } +} /** * Get the function caller. @@ -276,11 +251,10 @@ function wu_get_function_caller($depth = 1) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $depth + 1); - $caller = isset($backtrace[$depth]['function']) ? $backtrace[$depth]['function'] : null; + $caller = isset($backtrace[ $depth ]['function']) ? $backtrace[ $depth ]['function'] : null; return $caller; - -} // end wu_get_function_caller; +} /** * Checks if a particular plugin is skipped in a CLI context. * @@ -290,25 +264,20 @@ function wu_get_function_caller($depth = 1) { */ function wu_cli_is_plugin_skipped($plugin = null): bool { - if (!class_exists(\WP_CLI::class)) { - + if ( ! class_exists(\WP_CLI::class)) { return false; - - } // end if; + } $skipped_plugins = \WP_CLI::get_config('skip-plugins'); if (is_bool($skipped_plugins)) { - return true; - - } // end if; + } $skipped_plugins = array_map(fn($plugin_slug) => trim((string) $plugin_slug), explode(',', (string) $skipped_plugins)); return in_array($plugin, $skipped_plugins, true); - -} // end wu_cli_is_plugin_skipped; +} /** * Capture errors and exceptions thrown inside the callback to prevent breakage. @@ -324,13 +293,9 @@ function wu_cli_is_plugin_skipped($plugin = null): bool { function wu_ignore_errors($fn, $log = false) { try { - call_user_func($fn); - } catch (\Throwable $exception) { // Ignore it or log it. - - } // end try; - -} // end wu_ignore_errors; + } +} diff --git a/inc/functions/http.php b/inc/functions/http.php index 19eb8f0..ba9183f 100644 --- a/inc/functions/http.php +++ b/inc/functions/http.php @@ -22,8 +22,7 @@ function wu_get_input($raw = false) { $body = @file_get_contents('php://input'); // phpcs:ignore return $raw ? $body : json_decode($body); - -} // end wu_get_input; +} /** * Prevents the current page from being cached. @@ -33,8 +32,7 @@ function wu_get_input($raw = false) { */ function wu_no_cache() { - if (!headers_sent()) { - + if ( ! headers_sent()) { nocache_headers(); header('Pragma: no-cache'); @@ -44,12 +42,10 @@ function wu_no_cache() { * easily spot when no-caching is out fault! */ wu_x_header('X-Ultimo-Cache: prevent-caching'); - - } // end if; + } do_action('wu_no_cache'); - -} // end wu_no_cache; +} /** * Maybe sends a WP Multisite WaaS X Header. @@ -66,9 +62,6 @@ function wu_no_cache() { function wu_x_header($header) { if (apply_filters('wu_should_send_x_headers', defined('WP_DEBUG') && WP_DEBUG)) { - - !headers_sent() && header($header); - - } // end if; - -} // end wu_x_header; + ! headers_sent() && header($header); + } +} diff --git a/inc/functions/invoice.php b/inc/functions/invoice.php index 4b7adfa..3a199da 100644 --- a/inc/functions/invoice.php +++ b/inc/functions/invoice.php @@ -19,5 +19,4 @@ defined('ABSPATH') || exit; function wu_get_invoice_template() { return false; - -} // end wu_get_invoice_template; +} diff --git a/inc/functions/legacy.php b/inc/functions/legacy.php index bffcd1f..e51cc40 100644 --- a/inc/functions/legacy.php +++ b/inc/functions/legacy.php @@ -18,7 +18,7 @@ function WU_Signup() { return \WP_Ultimo\Checkout\Legacy_Checkout::get_instance(); -} // end WU_Signup; +} /** * @@ -31,22 +31,22 @@ if (!function_exists('validate_blog_form')) { $user = ''; if ( is_user_logged_in() ) { $user = wp_get_current_user(); - } // end if; + } return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user); - } // end validate_blog_form; + } -} // end if; +} if (!function_exists('validate_user_form')) { function validate_user_form() { return wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']); - } // end validate_user_form; + } -} // end if; +} /** * Builds HTML attributes from a PHP array @@ -62,15 +62,15 @@ function wu_create_html_attributes_from_array($attributes = array()) { if (is_bool($value)) { if ($value) { $output .= $name . ' '; - } // end if; + } } else { $output .= sprintf('%s="%s"', $name, $value); - } // end if; - } // end foreach; + } + } return $output; -} // end wu_create_html_attributes_from_array; +} /** * Display one single option @@ -85,7 +85,7 @@ function wu_print_signup_field_option($option_value, $option_label, $field = arr '; @@ -114,11 +114,11 @@ function wu_print_signup_field_options($options, $field = array()) { wu_print_signup_field_option($option_value, $option_label, $field); - } // end if; + } - } // end foreach; + } -} // end wu_print_signup_field_options; +} /** * Print sing-up fields @@ -172,7 +172,7 @@ function wu_print_signup_field($field_slug, $field, $results) { return true; - } // end if; + } value = Array.isArray(value) ? value : [value]; @@ -180,7 +180,7 @@ function wu_print_signup_field($field_slug, $field, $results) { conditions_met++; - } // end if; + } }); @@ -194,7 +194,7 @@ function wu_print_signup_field($field_slug, $field, $results) { } // end - } // end display_field; + } display_field(target_field, requires, 0); @@ -209,7 +209,7 @@ function wu_print_signup_field($field_slug, $field, $results) { get_error_message($field_slug)) { echo '

    ' . $error_message . '

    '; - } // end if; + } ?> @@ -303,7 +303,7 @@ function wu_print_signup_field($field_slug, $field, $results) { get_error_message($field_slug)) { echo '

    ' . $error_message . '

    '; - } // end if; + } ?> @@ -367,7 +367,7 @@ function wu_print_signup_field($field_slug, $field, $results) { get_error_message($field_slug)) { echo '

    ' . $error_message . '

    '; - } // end if; + } ?> @@ -398,7 +398,7 @@ function wu_print_signup_field($field_slug, $field, $results) { get_error_message($field_slug)) { echo '

    ' . $error_message . '

    '; - } // end if; + } ?> @@ -409,9 +409,9 @@ function wu_print_signup_field($field_slug, $field, $results) { create_user($user_data, $plan_data, $user_meta); -} // end wu_create_user; +} /** * Alias function to allow creation of sites for WP Multisite WaaS. @@ -446,7 +446,7 @@ function wu_create_site_legacy($user_id, array $site_data, $template_id = false, return WU_Signup()->create_site($user_id, $site_data, $template_id, $site_meta); -} // end wu_create_site_legacy; +} /** * Alias function that adds a new Step to the sign-up flow * @@ -459,7 +459,7 @@ function wu_add_signup_step($id, $order, array $step) { return WU_Signup()->add_signup_step($id, $order, $step); -} // end wu_add_signup_step; +} /** * Alias function that adds a new field to a step the sign-up flow @@ -475,4 +475,4 @@ function wu_add_signup_field($step, $id, $order, $field) { return WU_Signup()->add_signup_field($step, $id, $order, $field); -} // end wu_add_signup_field; +} diff --git a/inc/functions/limitations.php b/inc/functions/limitations.php index cfba9d8..d35ef83 100644 --- a/inc/functions/limitations.php +++ b/inc/functions/limitations.php @@ -54,33 +54,25 @@ defined('ABSPATH') || exit; */ function wu_has_product($product_slug, $blocking = false, $site_id = '') { - if (!is_array($product_slug)) { - + if ( ! is_array($product_slug)) { $product_slug = array($product_slug); - - } // end if; + } if (empty($site_id)) { - $site_id = get_current_blog_id(); - - } // end if; + } $site = wu_get_site($site_id); if (empty($site)) { - return new \WP_Error('site-not-found', __('Invalid site ID', 'wp-ultimo')); - - } // end if; + } $membership = $site->get_membership(); if (empty($membership)) { - return true; - - } // end if; + } $applicable_products_slugs = $membership->get_applicable_product_slugs(); @@ -89,14 +81,11 @@ function wu_has_product($product_slug, $blocking = false, $site_id = '') { $active_status = true; if ($blocking) { - $active_status = $membership->is_active(); - - } // end if; + } return $contains_product && $active_status; - -} // end wu_has_product; +} /** * Checks if the membership associated with a site is active. @@ -109,30 +98,23 @@ function wu_has_product($product_slug, $blocking = false, $site_id = '') { function wu_is_membership_active($site_id = '') { if (empty($site_id)) { - $site_id = get_current_blog_id(); - - } // end if; + } $site = wu_get_site($site_id); if (empty($site)) { - return new \WP_Error('site-not-found', __('Invalid site ID', 'wp-ultimo')); - - } // end if; + } $membership = $site->get_membership(); if (empty($membership)) { - return true; - - } // end if; + } return $membership->is_active(); - -} // end wu_is_membership_active; +} /** * Register a new Limitation module. @@ -145,17 +127,18 @@ function wu_is_membership_active($site_id = '') { */ function wu_register_limit_module($id, $class_name) { - add_filter('wu_limit_classes', function($classes) use ($id, $class_name) { + add_filter( + 'wu_limit_classes', + function ($classes) use ($id, $class_name) { - $id = sanitize_title($id); + $id = sanitize_title($id); - $classes[$id] = $class_name; + $classes[ $id ] = $class_name; - return $classes; - - }); - -} // end wu_register_limit_module; + return $classes; + } + ); +} /** * Generate the modal link to search for an upgrade path. @@ -167,18 +150,19 @@ function wu_register_limit_module($id, $class_name) { */ function wu_generate_upgrade_to_unlock_url($args) { - $args = wp_parse_args($args, array( - 'module' => false, - 'type' => false, - )); + $args = wp_parse_args( + $args, + array( + 'module' => false, + 'type' => false, + ) + ); $membership = wu_get_current_site()->get_membership(); - if (!$membership) { - + if ( ! $membership) { return ''; - - } // end if; + } $upgrade_url = wu_get_membership_update_url($membership); @@ -191,8 +175,7 @@ function wu_generate_upgrade_to_unlock_url($args) { * @param array $args The module and type of limit that needs upgrading. */ return apply_filters('wu_upgrade_to_unlock_url', $url, $args); - -} // end wu_generate_upgrade_to_unlock_url; +} /** * Generates a Unlock to Upgrade button for the upgrade modal. @@ -205,16 +188,21 @@ function wu_generate_upgrade_to_unlock_url($args) { */ function wu_generate_upgrade_to_unlock_button($title, $args) { - $args = wp_parse_args($args, array( - 'module' => false, - 'type' => false, - 'classes' => '', - )); + $args = wp_parse_args( + $args, + array( + 'module' => false, + 'type' => false, + 'classes' => '', + ) + ); - $url = wu_generate_upgrade_to_unlock_url(array( - 'module' => $args['module'], - 'type' => $args['type'], - )); + $url = wu_generate_upgrade_to_unlock_url( + array( + 'module' => $args['module'], + 'type' => $args['type'], + ) + ); $element = sprintf( '%s', @@ -225,8 +213,7 @@ function wu_generate_upgrade_to_unlock_button($title, $args) { ); return $element; - -} // end wu_generate_upgrade_to_unlock_button; +} /** * Activate a plugin(s) via Job Queue. @@ -241,15 +228,17 @@ function wu_generate_upgrade_to_unlock_button($title, $args) { */ function wu_async_activate_plugins($site_id, $plugins, $network_wide = false, $silent = true) { - wu_enqueue_async_action('wu_async_handle_plugins', array( - 'action' => 'activate', - 'site_id' => $site_id, - 'plugins' => $plugins, - 'network_wide' => $network_wide, - 'silent' => $silent, - )); - -} // end wu_async_activate_plugins; + wu_enqueue_async_action( + 'wu_async_handle_plugins', + array( + 'action' => 'activate', + 'site_id' => $site_id, + 'plugins' => $plugins, + 'network_wide' => $network_wide, + 'silent' => $silent, + ) + ); +} /** * Deactivates a plugin(s) via Job Queue. @@ -264,15 +253,17 @@ function wu_async_activate_plugins($site_id, $plugins, $network_wide = false, $s */ function wu_async_deactivate_plugins($site_id, $plugins, $network_wide = false, $silent = true) { - wu_enqueue_async_action('wu_async_handle_plugins', array( - 'action' => 'deactivate', - 'site_id' => $site_id, - 'plugins' => $plugins, - 'network_wide' => $network_wide, - 'silent' => $silent, - )); - -} // end wu_async_deactivate_plugins; + wu_enqueue_async_action( + 'wu_async_handle_plugins', + array( + 'action' => 'deactivate', + 'site_id' => $site_id, + 'plugins' => $plugins, + 'network_wide' => $network_wide, + 'silent' => $silent, + ) + ); +} /** * Switch themes via Job Queue. @@ -285,9 +276,11 @@ function wu_async_deactivate_plugins($site_id, $plugins, $network_wide = false, */ function wu_async_switch_theme($site_id, $theme_stylesheet) { - wu_enqueue_async_action('wu_async_switch_theme', array( - 'site_id' => $site_id, - 'theme_stylesheet' => $theme_stylesheet, - )); - -} // end wu_async_switch_theme; + wu_enqueue_async_action( + 'wu_async_switch_theme', + array( + 'site_id' => $site_id, + 'theme_stylesheet' => $theme_stylesheet, + ) + ); +} diff --git a/inc/functions/markup-helpers.php b/inc/functions/markup-helpers.php index 7a2cfc0..6197dbd 100644 --- a/inc/functions/markup-helpers.php +++ b/inc/functions/markup-helpers.php @@ -22,8 +22,7 @@ function wu_convert_to_state($state_array = array()) { $object = (object) $state_array; // Force object to prevent issues with Vue. return json_encode($object); - -} // end wu_convert_to_state; +} /** * Clean up p tags around block elements. @@ -35,23 +34,26 @@ function wu_convert_to_state($state_array = array()) { */ function wu_remove_empty_p($content): ?string { - $content = preg_replace(array( - '#

    \s*<(div|aside|section|article|header|footer)#', - '#\s*

    #', - '#\s*
    #', - '#<(div|aside|section|article|header|footer)(.*?)>\s*

    #', - '#

    \s*', - '', - '<$1$2>', - '\s*<(div|aside|section|article|header|footer)#', + '#\s*

    #', + '#\s*
    #', + '#<(div|aside|section|article|header|footer)(.*?)>\s*

    #', + '#

    \s*', + '', + '<$1$2>', + '(\s| )*+()*(\s| )*

    #i', '', $content); - -} // end wu_remove_empty_p; +} /** * Generates a string containing html attributes to be used inside html tags. * @@ -76,8 +78,7 @@ function wu_array_to_html_attrs($attributes = array()): string { $attributes = array_map(fn($key, $value) => $key . '="' . htmlspecialchars((string) $value) . '"', array_keys($attributes), $attributes); return implode(' ', $attributes); - -} // end wu_array_to_html_attrs; +} /** * Adds a tooltip icon. @@ -91,28 +92,21 @@ function wu_array_to_html_attrs($attributes = array()): string { function wu_tooltip($tooltip, $icon = 'dashicons-editor-help') { if (empty($tooltip)) { - return ''; - - } // end if; + } $markup = sprintf('', esc_attr($tooltip)); - if (!is_admin()) { - + if ( ! is_admin()) { $markup .= ''; - } else { - $markup .= sprintf('', esc_attr($icon)); - - } // end if; + } $markup .= ''; return $markup; - -} // end wu_tooltip; +} /** * Adds a tooltip to a HTML element. Needs to be echo'ed. * @@ -123,8 +117,7 @@ function wu_tooltip($tooltip, $icon = 'dashicons-editor-help') { function wu_tooltip_text($tooltip): string { return sprintf('role="tooltip" aria-label="%s"', esc_attr($tooltip)); - -} // end wu_tooltip_text; +} /** * Adds a preview tag that displays the image passed on hover. * @@ -136,14 +129,11 @@ function wu_tooltip_text($tooltip): string { function wu_preview_image($image_url, $label = false): string { if (empty($label)) { - $label = __('Preview', 'wp-ultimo'); - - } // end if; + } return sprintf(' %s %s', $image_url, "", $label); - -} // end wu_preview_image; +} /** * Returns the list of available icons. To add more icons you need use the filter @@ -496,7 +486,7 @@ function wu_get_icons_list() { 'dashicons-wu-voicemail', 'dashicons-wu-wallet', 'dashicons-wu-warning', - 'dashicons-wu-wp-ultimo' + 'dashicons-wu-wp-ultimo', ); $all_icons['Dashicons'] = array( @@ -757,8 +747,7 @@ function wu_get_icons_list() { ); return apply_filters('wu_icons_list', $all_icons); - -} // end wu_get_icons_list; +} /** * Checks if the current theme is a block theme. @@ -769,11 +758,8 @@ function wu_get_icons_list() { function wu_is_block_theme() { if (function_exists('wp_is_block_theme')) { - return wp_is_block_theme(); - - } // end if; + } return false; - -} // end wu_is_block_theme; +} diff --git a/inc/functions/membership.php b/inc/functions/membership.php index 84db048..1e0961d 100644 --- a/inc/functions/membership.php +++ b/inc/functions/membership.php @@ -9,10 +9,10 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Models\Membership; -use \WP_Ultimo\Models\Payment; -use \WP_Ultimo\Database\Payments\Payment_Status; -use \WP_Ultimo\Checkout\Cart; +use WP_Ultimo\Models\Membership; +use WP_Ultimo\Models\Payment; +use WP_Ultimo\Database\Payments\Payment_Status; +use WP_Ultimo\Checkout\Cart; /** * Returns a membership. @@ -25,8 +25,7 @@ use \WP_Ultimo\Checkout\Cart; function wu_get_membership($membership_id) { return Membership::get_by_id($membership_id); - -} // end wu_get_membership; +} /** * Returns a single membership defined by a particular column and value. * @@ -39,8 +38,7 @@ function wu_get_membership($membership_id) { function wu_get_membership_by($column, $value) { return Membership::get_by($column, $value); - -} // end wu_get_membership_by; +} /** * Gets a membership based on the hash. * @@ -52,8 +50,7 @@ function wu_get_membership_by($column, $value) { function wu_get_membership_by_hash($hash) { return Membership::get_by_hash($hash); - -} // end wu_get_membership_by_hash; +} /** * Queries memberships. @@ -65,26 +62,23 @@ function wu_get_membership_by_hash($hash) { */ function wu_get_memberships($query = array()) { - if (!empty($query['search'])) { - - $customer_ids = wu_get_customers(array( - 'search' => $query['search'], - 'fields' => 'ids', - )); - - if (!empty($customer_ids)) { + if ( ! empty($query['search'])) { + $customer_ids = wu_get_customers( + array( + 'search' => $query['search'], + 'fields' => 'ids', + ) + ); + if ( ! empty($customer_ids)) { $query['customer_id__in'] = $customer_ids; unset($query['search']); - - } // end if; - - } // end if; + } + } return Membership::query($query); - -} // end wu_get_memberships; +} /** * Creates a new membership. * @@ -98,36 +92,39 @@ function wu_create_membership($membership_data) { * Why do we use shortcode atts here? * Shortcode atts clean the array from not-allowed keys, so we don't need to worry much. */ - $membership_data = shortcode_atts(array( - 'customer_id' => false, - 'user_id' => false, - 'migrated_from_id' => 0, - 'plan_id' => false, - 'addon_products' => false, - 'currency' => false, - 'initial_amount' => false, - 'recurring' => false, - 'duration' => 1, - 'duration_unit' => 'month', - 'amount' => false, - 'auto_renew' => false, - 'times_billed' => 0, - 'billing_cycles' => 0, - 'gateway_customer_id' => false, - 'gateway_subscription_id' => false, - 'gateway' => '', - 'signup_method' => '', - 'upgraded_from' => false, - 'disabled' => false, - 'status' => 'pending', - 'date_created' => wu_get_current_time('mysql', true), - 'date_activate' => null, - 'date_trial_end' => null, - 'date_renewed' => null, - 'date_modified' => wu_get_current_time('mysql', true), - 'date_expiration' => wu_get_current_time('mysql', true), - 'skip_validation' => false, - ), $membership_data); + $membership_data = shortcode_atts( + array( + 'customer_id' => false, + 'user_id' => false, + 'migrated_from_id' => 0, + 'plan_id' => false, + 'addon_products' => false, + 'currency' => false, + 'initial_amount' => false, + 'recurring' => false, + 'duration' => 1, + 'duration_unit' => 'month', + 'amount' => false, + 'auto_renew' => false, + 'times_billed' => 0, + 'billing_cycles' => 0, + 'gateway_customer_id' => false, + 'gateway_subscription_id' => false, + 'gateway' => '', + 'signup_method' => '', + 'upgraded_from' => false, + 'disabled' => false, + 'status' => 'pending', + 'date_created' => wu_get_current_time('mysql', true), + 'date_activate' => null, + 'date_trial_end' => null, + 'date_renewed' => null, + 'date_modified' => wu_get_current_time('mysql', true), + 'date_expiration' => wu_get_current_time('mysql', true), + 'skip_validation' => false, + ), + $membership_data + ); $membership_data['migrated_from_id'] = is_numeric($membership_data['migrated_from_id']) ? $membership_data['migrated_from_id'] : 0; @@ -136,8 +133,7 @@ function wu_create_membership($membership_data) { $saved = $membership->save(); return is_wp_error($saved) ? $saved : $membership; - -} // end wu_create_membership; +} /** * Get all customers with a specific membership using the product_id as reference. @@ -168,8 +164,7 @@ function wu_get_membership_customers($product_id) { is_multisite() && restore_current_blog(); return $results; - -} // end wu_get_membership_customers; +} /** * Returns a membership based on the customer gateway ID. * @@ -200,17 +195,14 @@ function wu_get_membership_by_customer_gateway_id($customer_gateway_id, $allowed 'order' => 'DESC', ); - if (!empty($amount)) { - + if ( ! empty($amount)) { $search_data['initial_amount'] = $amount; - - } // end if; + } $memberships = wu_get_memberships($search_data); - return !empty($memberships) ? current($memberships) : false; - -} // end wu_get_membership_by_customer_gateway_id; + return ! empty($memberships) ? current($memberships) : false; +} /** * Returns the price for a product in a specific membership. @@ -229,56 +221,52 @@ function wu_get_membership_product_price($membership, $product_id, $quantity, $o $address = $membership->get_billing_address(); // Create a Cart with this product - $cart = new Cart(array( - 'duration' => $membership->get_duration(), - 'duration_unit' => $membership->get_duration_unit(), - 'country' => $address->billing_country, - 'state' => $address->billing_state, - 'city' => $address->billing_city, - )); + $cart = new Cart( + array( + 'duration' => $membership->get_duration(), + 'duration_unit' => $membership->get_duration_unit(), + 'country' => $address->billing_country, + 'state' => $address->billing_state, + 'city' => $address->billing_city, + ) + ); $discount_code = $membership->get_discount_code(); if ($discount_code) { - $cart->add_discount_code($discount_code); - - } // end if; + } $added = $cart->add_product($product_id, $quantity); - if (!$added) { - + if ( ! $added) { return $cart->errors; + } - } // end if; - - $payment_data = array_merge($cart->to_payment_data(), array( - 'customer_id' => $membership->get_customer_id(), - 'membership_id' => $membership->get_id(), - 'gateway' => $membership->get_gateway(), - )); + $payment_data = array_merge( + $cart->to_payment_data(), + array( + 'customer_id' => $membership->get_customer_id(), + 'membership_id' => $membership->get_id(), + 'gateway' => $membership->get_gateway(), + ) + ); // create a temporary payment to see the price. $temp_payment = wu_create_payment($payment_data, false); if (is_wp_error($temp_payment)) { - return $temp_payment; - - } // end if; + } if ($only_recurring) { - $temp_payment->remove_non_recurring_items(); - - } // end if; + } $temp_payment->recalculate_totals(); return $temp_payment->get_total(); - -} // end wu_get_membership_product_price; +} /** * Creates a new payment for a membership. * @@ -298,63 +286,53 @@ function wu_membership_create_new_payment($membership, $should_cancel_pending_pa * pending payment, do that. */ if ($should_cancel_pending_payments) { - $pending_payment = $membership->get_last_pending_payment(); /* * Change pending payment to cancelled. */ if ($pending_payment) { - $pending_payment->set_status(Payment_Status::CANCELLED); $pending_payment->save(); - - } // end if; - - } // end if; + } + } $cart = wu_get_membership_new_cart($membership); - $payment_data = array_merge($cart->to_payment_data(), array( - 'customer_id' => $membership->get_customer_id(), - 'membership_id' => $membership->get_id(), - 'gateway' => $membership->get_gateway(), - )); + $payment_data = array_merge( + $cart->to_payment_data(), + array( + 'customer_id' => $membership->get_customer_id(), + 'membership_id' => $membership->get_id(), + 'gateway' => $membership->get_gateway(), + ) + ); // We will save the payment after we recalculate the totals. $new_payment = wu_create_payment($payment_data, false); if (is_wp_error($new_payment)) { - return $new_payment; - - } // end if; + } if ($remove_non_recurring) { - $new_payment->remove_non_recurring_items(); - - } // end if; + } $new_payment->recalculate_totals(); - if (!$save) { - + if ( ! $save) { return $new_payment; - - } // end if; + } $status = $new_payment->save(); if (is_wp_error($status)) { - return $status; - - } // end if; + } return $new_payment; - -} // end wu_membership_create_new_payment; +} /** * Creates a full cart based on a membership. @@ -368,32 +346,29 @@ function wu_get_membership_new_cart($membership) { $address = $membership->get_billing_address(); - $cart = new Cart(array( - 'duration' => $membership->get_duration(), - 'duration_unit' => $membership->get_duration_unit(), - 'country' => $address->billing_country, - 'state' => $address->billing_state, - 'city' => $address->billing_city, - )); + $cart = new Cart( + array( + 'duration' => $membership->get_duration(), + 'duration_unit' => $membership->get_duration_unit(), + 'country' => $address->billing_country, + 'state' => $address->billing_state, + 'city' => $address->billing_city, + ) + ); $discount_code = $membership->get_discount_code(); if ($discount_code) { - $cart->add_discount_code($discount_code); - - } // end if; + } foreach ($membership->get_all_products() as $key => $product) { - $cart->add_product($product['product']->get_id(), $product['quantity']); - - } // end foreach; + } $difference = $membership->get_amount() - $cart->get_recurring_total(); if (round(abs($difference), wu_currency_decimal_filter()) > 0) { - $type_translate = $difference < 0 ? __('credit', 'wp-ultimo') : __('debit', 'wp-ultimo'); $line_item_params = array( @@ -414,11 +389,9 @@ function wu_get_membership_new_cart($membership) { $adjustment_line_item = new \WP_Ultimo\Checkout\Line_Item($line_item_params); $cart->add_line_item($adjustment_line_item); - - } // end if; + } if ($membership->get_initial_amount() !== $cart->get_total()) { - $t = $membership->get_initial_amount(); $y = $cart->get_total(); @@ -441,15 +414,13 @@ function wu_get_membership_new_cart($membership) { $adjustment_line_item = new \WP_Ultimo\Checkout\Line_Item($line_item_params); $cart->add_line_item($adjustment_line_item); - - } // end if; + } $y = $cart->get_total(); $t = $cart->get_recurring_total(); return $cart; - -} // end wu_get_membership_new_cart; +} /** * Generate the modal link to search for an upgrade path. @@ -468,36 +439,38 @@ function wu_get_membership_update_url($membership) { $membership_hash = $membership->get_hash(); if ($url) { + return add_query_arg( + array( + 'membership' => $membership_hash, + ), + $url + ); + } - return add_query_arg(array( - 'membership' => $membership_hash, - ), $url); - - } // end if; - - if (!is_main_site()) { - + if ( ! is_main_site()) { return admin_url('admin.php?page=wu-checkout&membership=' . $membership_hash); - - } // end if; + } $sites = $membership->get_sites(false); if (count($sites) > 0) { - - return add_query_arg(array( - 'page' => 'wu-checkout', - 'membership' => $membership_hash, - ), get_admin_url($sites[0]->get_id())); - - } // end if; + return add_query_arg( + array( + 'page' => 'wu-checkout', + 'membership' => $membership_hash, + ), + get_admin_url($sites[0]->get_id()) + ); + } // In last case we use the default register form $url = $checkout_pages->get_page_url('register'); - return add_query_arg(array( - 'membership' => $membership_hash, - 'wu_form' => 'wu-checkout', - ), $url); - -} // end wu_get_membership_update_url; + return add_query_arg( + array( + 'membership' => $membership_hash, + 'wu_form' => 'wu-checkout', + ), + $url + ); +} diff --git a/inc/functions/mock.php b/inc/functions/mock.php index 26c3af0..5bb8f15 100644 --- a/inc/functions/mock.php +++ b/inc/functions/mock.php @@ -18,23 +18,23 @@ defined('ABSPATH') || exit; */ function wu_mock_site($seed = false) { - $atts = apply_filters('wu_mock_site', array( - 'title' => __('Example Site', 'wp-ultimo'), - 'description' => __('This is an example of a site description.', 'wp-ultimo'), - 'domain' => __('examplesite.dev', 'wp-ultimo'), - 'path' => '/', - )); + $atts = apply_filters( + 'wu_mock_site', + array( + 'title' => __('Example Site', 'wp-ultimo'), + 'description' => __('This is an example of a site description.', 'wp-ultimo'), + 'domain' => __('examplesite.dev', 'wp-ultimo'), + 'path' => '/', + ) + ); if ($seed) { - $atts['title'] .= " {$seed}"; $atts['domain'] = str_replace('.dev', "{$seed}.dev", (string) $atts['domain']); - - } // end if; + } return new \WP_Ultimo\Models\Site($atts); - -} // end wu_mock_site; +} /** * Returns a mock membership object. @@ -44,14 +44,17 @@ function wu_mock_site($seed = false) { */ function wu_mock_membership() { - return new \WP_Ultimo\Models\Membership(array( - 'billing_address' => new \WP_Ultimo\Objects\Billing_Address(array( - 'company_name' => 'Company Co.', - 'billing_email' => 'company@co.dev', - )), - )); - -} // end wu_mock_membership; + return new \WP_Ultimo\Models\Membership( + array( + 'billing_address' => new \WP_Ultimo\Objects\Billing_Address( + array( + 'company_name' => 'Company Co.', + 'billing_email' => 'company@co.dev', + ) + ), + ) + ); +} /** * Returns a mock product object. @@ -61,15 +64,16 @@ function wu_mock_membership() { */ function wu_mock_product() { - $product = new \WP_Ultimo\Models\Product(array( - 'name' => __('Test Product', 'wp-ultimo'), - )); + $product = new \WP_Ultimo\Models\Product( + array( + 'name' => __('Test Product', 'wp-ultimo'), + ) + ); $product->_mocked = true; return $product; - -} // end wu_mock_product; +} /** * Returns a mock customer object. @@ -79,12 +83,16 @@ function wu_mock_product() { */ function wu_mock_customer() { - $customer = new \WP_Ultimo\Models\Customer(array( - 'billing_address' => new \WP_Ultimo\Objects\Billing_Address(array( - 'company_name' => 'Company Co.', - 'billing_email' => 'company@co.dev', - )), - )); + $customer = new \WP_Ultimo\Models\Customer( + array( + 'billing_address' => new \WP_Ultimo\Objects\Billing_Address( + array( + 'company_name' => 'Company Co.', + 'billing_email' => 'company@co.dev', + ) + ), + ) + ); $customer->_user = (object) array( 'data' => (object) array( @@ -104,8 +112,7 @@ function wu_mock_customer() { ); return $customer; - -} // end wu_mock_customer; +} /** * Returns a mock payment object. @@ -117,17 +124,20 @@ function wu_mock_payment() { $payment = new \WP_Ultimo\Models\Payment(); - $line_item = new \WP_Ultimo\Checkout\Line_Item(array( - 'product' => wu_mock_product(), - )); + $line_item = new \WP_Ultimo\Checkout\Line_Item( + array( + 'product' => wu_mock_product(), + ) + ); - $payment->set_line_items(array( - $line_item, - )); + $payment->set_line_items( + array( + $line_item, + ) + ); return $payment; - -} // end wu_mock_payment; +} /** * Returns a mock domain object. @@ -137,15 +147,16 @@ function wu_mock_payment() { */ function wu_mock_domain() { - $domain = new \WP_Ultimo\Models\Domain(array( - 'blog_id' => 1, - 'domain' => 'example.com', - 'active' => true, - 'primary_domain' => true, - 'secure' => true, - 'stage' => 'checking-dns', - )); + $domain = new \WP_Ultimo\Models\Domain( + array( + 'blog_id' => 1, + 'domain' => 'example.com', + 'active' => true, + 'primary_domain' => true, + 'secure' => true, + 'stage' => 'checking-dns', + ) + ); return $domain; - -} // end wu_mock_domain; +} diff --git a/inc/functions/model.php b/inc/functions/model.php index 048387b..f996268 100644 --- a/inc/functions/model.php +++ b/inc/functions/model.php @@ -20,14 +20,11 @@ defined('ABSPATH') || exit; function wu_cast_model_to_array($model) { if (is_a($model, '\\WP_Ultimo\\Models\\Base_Model')) { - $model = $model->to_array(); - - } // end if; + } return $model; - -} // end wu_cast_model_to_array; +} /** * Converts a list of Model objects to a list of ID => $label_field @@ -43,14 +40,11 @@ function wu_models_to_options($models, $label_field = 'name') { $options_list = array(); foreach ($models as $model) { - - $options_list[$model->get_id()] = call_user_func(array($model, "get_{$label_field}")); - - } // end foreach; + $options_list[ $model->get_id() ] = call_user_func(array($model, "get_{$label_field}")); + } return $options_list; - -} // end wu_models_to_options; +} /** * Get the schema of a particular model. @@ -65,14 +59,11 @@ function wu_model_get_schema($class_name) { $schema = array(); if (method_exists($class_name, 'get_schema')) { - $schema = $class_name::get_schema(); - - } // end if; + } return $schema; - -} // end wu_model_get_schema; +} /** * Returns a list of required fields form a model schema. @@ -87,21 +78,14 @@ function wu_model_get_required_fields($class_name) { $required_fields = array(); if (method_exists($class_name, 'validation_rules')) { - - $validation_rules = (new $class_name)->validation_rules(); + $validation_rules = (new $class_name())->validation_rules(); foreach ($validation_rules as $field => $validation_rule) { - if (strpos((string) $validation_rule, 'required|') !== false || $validation_rule === 'required') { - $required_fields[] = $field; - - } // end if; - - } // end foreach; - - } // end if; + } + } + } return $required_fields; - -} // end wu_model_get_required_fields; +} diff --git a/inc/functions/number-helpers.php b/inc/functions/number-helpers.php index 1af768c..7702442 100644 --- a/inc/functions/number-helpers.php +++ b/inc/functions/number-helpers.php @@ -24,8 +24,7 @@ function wu_extract_number($str) { preg_match_all('/\d+/', $str, $matches); return isset($matches[0][0]) ? (int) $matches[0][0] : 0; - -} // end wu_extract_number; +} /** * Converts formatted values back into floats. @@ -39,29 +38,20 @@ function wu_extract_number($str) { function wu_to_float($num, $decimal_separator = false) { if (is_float($num) || is_numeric($num)) { - return (float) $num; - - } // end if; + } if (empty($decimal_separator)) { - $decimal_separator = wu_get_setting('decimal_separator', '.'); - - } // end if; + } if ($decimal_separator) { - $pattern = '/[^0-9\\' . $decimal_separator . '-]+/'; - } else { - $pattern = '/[^0-9-]+/'; - - } // end if; + } $val = preg_replace($pattern, '', (string) $num); return floatval($val); - -} // end wu_to_float; +} diff --git a/inc/functions/options.php b/inc/functions/options.php index 784a9a0..ad36182 100644 --- a/inc/functions/options.php +++ b/inc/functions/options.php @@ -22,8 +22,7 @@ function wu_get_option($option_name = 'settings', $default = array()) { $option_value = get_network_option(null, wu_slugify($option_name), $default); return apply_filters('wu_get_option', $option_value, $option_name, $default); - -} // end wu_get_option; +} /** * Save slugfied network option @@ -36,8 +35,7 @@ function wu_get_option($option_name = 'settings', $default = array()) { function wu_save_option($option_name = 'settings', $value = false) { return update_network_option(null, wu_slugify($option_name), $value); - -} // end wu_save_option; +} /** * Delete slugfied network option @@ -49,5 +47,4 @@ function wu_save_option($option_name = 'settings', $value = false) { function wu_delete_option($option_name) { return delete_network_option(null, wu_slugify($option_name)); - -} // end wu_delete_option; +} diff --git a/inc/functions/pages.php b/inc/functions/pages.php index a86acc7..4bfba78 100644 --- a/inc/functions/pages.php +++ b/inc/functions/pages.php @@ -17,35 +17,31 @@ defined('ABSPATH') || exit; */ function wu_guess_registration_page() { - return wu_switch_blog_and_run(function() { + return wu_switch_blog_and_run( + function () { - $saved_register_page_id = wu_get_setting('default_registration_page', 0); + $saved_register_page_id = wu_get_setting('default_registration_page', 0); - $page = get_post($saved_register_page_id); + $page = get_post($saved_register_page_id); - if ($page) { + if ($page) { + return $page->ID; + } - return $page->ID; + $maybe_register_page = get_page_by_path('register'); + if ($maybe_register_page && has_shortcode($maybe_register_page->post_content, 'wu_checkout') && $maybe_register_page->post_status === 'publish') { + wu_save_setting('default_registration_page', $maybe_register_page->ID); + + function_exists('flush_rewrite_rules') && flush_rewrite_rules(true); + + return $maybe_register_page->ID; + } + + return false; } - - $maybe_register_page = get_page_by_path('register'); - - if ($maybe_register_page && has_shortcode($maybe_register_page->post_content, 'wu_checkout') && $maybe_register_page->post_status === 'publish') { - - wu_save_setting('default_registration_page', $maybe_register_page->ID); - - function_exists('flush_rewrite_rules') && flush_rewrite_rules(true); - - return $maybe_register_page->ID; - - } - - return false; - - }); - -} // end wu_guess_registration_page; + ); +} /** * Checks if the current post is a registration page. @@ -58,21 +54,16 @@ function wu_is_registration_page() { /** @var \WP_Post|null $post */ global $post; - if (!is_main_site()) { - + if ( ! is_main_site()) { return false; + } - } // end if; - - if (!is_a($post, '\WP_Post')) { - + if ( ! is_a($post, '\WP_Post')) { return false; - - } // end if; + } return absint(wu_guess_registration_page()) === $post->ID; - -} // end wu_is_registration_page; +} /** * Checks if the current post is a update page. @@ -84,21 +75,16 @@ function wu_is_update_page() { global $post; - if (!is_main_site()) { - + if ( ! is_main_site()) { return false; + } - } // end if; - - if (!is_a($post, '\WP_Post')) { - + if ( ! is_a($post, '\WP_Post')) { return false; - - } // end if; + } return absint(wu_get_setting('default_update_page', 0)) === $post->ID; - -} // end wu_is_update_page; +} /** * Checks if the current post is a new site page. @@ -110,21 +96,16 @@ function wu_is_new_site_page() { global $post; - if (!is_main_site()) { - + if ( ! is_main_site()) { return false; + } - } // end if; - - if (!is_a($post, '\WP_Post')) { - + if ( ! is_a($post, '\WP_Post')) { return false; - - } // end if; + } return absint(wu_get_setting('default_new_site_page', 0)) === $post->ID; - -} // end wu_is_new_site_page; +} /** * Checks if the current page is a login page. @@ -141,5 +122,4 @@ function wu_is_login_page() { $is_default_wp_login = $pagenow === 'wp-login.php'; return $is_login_element_present || $is_default_wp_login; - -} // end wu_is_login_page; +} diff --git a/inc/functions/payment.php b/inc/functions/payment.php index a1c2beb..7e34752 100644 --- a/inc/functions/payment.php +++ b/inc/functions/payment.php @@ -9,8 +9,8 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Models\Payment; -use \WP_Ultimo\Database\Payments\Payment_Status; +use WP_Ultimo\Models\Payment; +use WP_Ultimo\Database\Payments\Payment_Status; /** * Returns a payment. @@ -23,8 +23,7 @@ use \WP_Ultimo\Database\Payments\Payment_Status; function wu_get_payment($payment_id) { return \WP_Ultimo\Models\Payment::get_by_id($payment_id); - -} // end wu_get_payment; +} /** * Queries payments. @@ -37,8 +36,7 @@ function wu_get_payment($payment_id) { function wu_get_payments($query = array()) { return \WP_Ultimo\Models\Payment::query($query); - -} // end wu_get_payments; +} /** * Returns a line-item. @@ -53,17 +51,14 @@ function wu_get_line_item($line_item_id, $payment_id) { $payment = wu_get_payment($payment_id); - if (!$payment) { - + if ( ! $payment) { return false; - - } // end if; + } $line_items = $payment->get_line_items(); return wu_get_isset($line_items, $line_item_id, false); - -} // end wu_get_line_item; +} /** * Gets a payment based on the hash. * @@ -75,8 +70,7 @@ function wu_get_line_item($line_item_id, $payment_id) { function wu_get_payment_by_hash($hash) { return \WP_Ultimo\Models\Payment::get_by_hash($hash); - -} // end wu_get_payment_by_hash; +} /** * Returns a single payment defined by a particular column and value. * @@ -89,8 +83,7 @@ function wu_get_payment_by_hash($hash) { function wu_get_payment_by($column, $value) { return \WP_Ultimo\Models\Payment::get_by($column, $value); - -} // end wu_get_payment_by; +} /** * Creates a new payment. * @@ -105,41 +98,41 @@ function wu_create_payment($payment_data, $save = true) { * Why do we use shortcode atts here? * Shortcode atts clean the array from not-allowed keys, so we don't need to worry much. */ - $payment_data = shortcode_atts(array( - 'line_items' => array(), - 'meta' => array(), - 'customer_id' => false, - 'membership_id' => false, - 'parent_id' => '', - 'product_id' => false, - 'currency' => wu_get_setting('currency_symbol', 'USD'), - 'discount_code' => '', - 'subtotal' => 0.00, - 'discount_total' => 0.00, - 'tax_total' => 0.00, - 'total' => 0.00, - 'status' => Payment_Status::COMPLETED, - 'gateway' => '', - 'gateway_payment_id' => '', - 'date_created' => wu_get_current_time('mysql', true), - 'date_modified' => wu_get_current_time('mysql', true), - 'migrated_from_id' => 0, - 'skip_validation' => false, - ), $payment_data); + $payment_data = shortcode_atts( + array( + 'line_items' => array(), + 'meta' => array(), + 'customer_id' => false, + 'membership_id' => false, + 'parent_id' => '', + 'product_id' => false, + 'currency' => wu_get_setting('currency_symbol', 'USD'), + 'discount_code' => '', + 'subtotal' => 0.00, + 'discount_total' => 0.00, + 'tax_total' => 0.00, + 'total' => 0.00, + 'status' => Payment_Status::COMPLETED, + 'gateway' => '', + 'gateway_payment_id' => '', + 'date_created' => wu_get_current_time('mysql', true), + 'date_modified' => wu_get_current_time('mysql', true), + 'migrated_from_id' => 0, + 'skip_validation' => false, + ), + $payment_data + ); $payment = new Payment($payment_data); - if (!$save) { - + if ( ! $save) { return $payment; - - } // end if; + } $saved = $payment->save(); return is_wp_error($saved) ? $saved : $payment; - -} // end wu_create_payment; +} /** * Returns a list of the refundable payment types. @@ -158,8 +151,7 @@ function wu_get_refundable_payment_types() { ); return apply_filters('wu_get_refundable_payment_type', $refundable_payment_types); - -} // end wu_get_refundable_payment_types; +} /** * Returns the icon classes for a payment status. @@ -174,5 +166,4 @@ function wu_get_payment_icon_classes($payment_status) { $payment_status_instance = new Payment_Status($payment_status); return $payment_status_instance->get_icon_classes(); - -} // end wu_get_payment_icon_classes; +} diff --git a/inc/functions/product.php b/inc/functions/product.php index 5edf5db..8d5757b 100644 --- a/inc/functions/product.php +++ b/inc/functions/product.php @@ -9,7 +9,7 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Models\Product; +use WP_Ultimo\Models\Product; /** * Returns a product. @@ -22,14 +22,11 @@ use \WP_Ultimo\Models\Product; function wu_get_product($product_id_or_slug) { if (is_numeric($product_id_or_slug) === false) { - return wu_get_product_by_slug($product_id_or_slug); - - } // end if; + } return Product::get_by_id($product_id_or_slug); - -} // end wu_get_product; +} /** * Queries products. @@ -42,8 +39,7 @@ function wu_get_product($product_id_or_slug) { function wu_get_products($query = array()) { return Product::query($query); - -} // end wu_get_products; +} /** * Queries plans. @@ -64,8 +60,7 @@ function wu_get_plans($query = array()) { $query['orderby'] = 'list_order'; return Product::query($query); - -} // end wu_get_plans; +} /** * Returns the list of plans as ID -> Name. @@ -78,14 +73,11 @@ function wu_get_plans_as_options() { $options = array(); foreach (wu_get_plans() as $plan) { - - $options[$plan->get_id()] = $plan->get_name(); - - } // end foreach; + $options[ $plan->get_id() ] = $plan->get_name(); + } return $options; - -} // end wu_get_plans_as_options; +} /** * Returns a product based on slug. @@ -98,8 +90,7 @@ function wu_get_plans_as_options() { function wu_get_product_by_slug($product_slug) { return Product::get_by('slug', $product_slug); - -} // end wu_get_product_by_slug; +} /** * Returns a single product defined by a particular column and value. * @@ -112,8 +103,7 @@ function wu_get_product_by_slug($product_slug) { function wu_get_product_by($column, $value) { return Product::get_by($column, $value); - -} // end wu_get_product_by; +} /** * Creates a new product. @@ -125,40 +115,42 @@ function wu_get_product_by($column, $value) { */ function wu_create_product($product_data) { - $product_data = wp_parse_args($product_data, array( - 'name' => false, - 'description' => false, - 'currency' => false, - 'pricing_type' => false, - 'setup_fee' => false, - 'parent_id' => 0, - 'slug' => false, - 'recurring' => false, - 'trial_duration' => 0, - 'trial_duration_unit' => 'day', - 'duration' => 1, - 'duration_unit' => 'day', - 'amount' => false, - 'billing_cycles' => false, - 'active' => false, - 'type' => false, - 'featured_image_id' => 0, - 'list_order' => 0, - 'date_created' => wu_get_current_time('mysql', true), - 'date_modified' => wu_get_current_time('mysql', true), - 'migrated_from_id' => 0, - 'meta' => array(), - 'available_addons' => array(), - 'group' => '', - )); + $product_data = wp_parse_args( + $product_data, + array( + 'name' => false, + 'description' => false, + 'currency' => false, + 'pricing_type' => false, + 'setup_fee' => false, + 'parent_id' => 0, + 'slug' => false, + 'recurring' => false, + 'trial_duration' => 0, + 'trial_duration_unit' => 'day', + 'duration' => 1, + 'duration_unit' => 'day', + 'amount' => false, + 'billing_cycles' => false, + 'active' => false, + 'type' => false, + 'featured_image_id' => 0, + 'list_order' => 0, + 'date_created' => wu_get_current_time('mysql', true), + 'date_modified' => wu_get_current_time('mysql', true), + 'migrated_from_id' => 0, + 'meta' => array(), + 'available_addons' => array(), + 'group' => '', + ) + ); $product = new Product($product_data); $saved = $product->save(); return is_wp_error($saved) ? $saved : $product; - -} // end wu_create_product; +} /** * Returns a list of available product groups. * @@ -173,8 +165,7 @@ function wu_get_product_groups(): array { $results = array_column($wpdb->get_results($query, ARRAY_A), 'product_group'); // phpcs:ignore return array_combine($results, $results); - -} // end wu_get_product_groups; +} /** * Takes a list of product objects and separates them into plan and addons. @@ -189,31 +180,20 @@ function wu_segregate_products($products) { $results = array(false, array()); foreach ($products as $product) { - if (is_a($product, Product::class) === false) { - $product = wu_get_product($product); - if (!$product) { - + if ( ! $product) { continue; - - } // end if; - - } // end if; + } + } if ($product->get_type() === 'plan' && $results[0] === false) { - $results[0] = $product; - } else { - $results[1][] = $product; - - } // end if; - - } // end foreach; + } + } return $results; - -} // end wu_segregate_products; +} diff --git a/inc/functions/reflection.php b/inc/functions/reflection.php index 5b77cc0..82c0b70 100644 --- a/inc/functions/reflection.php +++ b/inc/functions/reflection.php @@ -9,7 +9,7 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \phpDocumentor\Reflection\DocBlockFactory; +use phpDocumentor\Reflection\DocBlockFactory; /** * Creates the REST API schema blueprint for an object based on setters. @@ -28,8 +28,7 @@ function wu_reflection_parse_object_arguments($class_name) { * @todo add a logger. */ return $base_schema; - - } // end if; + } $reflector = new \ReflectionClass($class_name); @@ -43,75 +42,55 @@ function wu_reflection_parse_object_arguments($class_name) { $db_schema = method_exists($class_name, 'get_schema') ? $class_name::get_schema() : false; foreach ($base_schema as $column) { - try { - $doc_block = $doc_block_factory->create($reflector->getMethod("set_{$column['name']}")->getDocComment()); - } catch (\Throwable $exception) { /** * Something went wrong trying to parse the doc-blocks. */ continue; - - } // end try; + } $param = $doc_block->getTagsByName('param'); if (isset($param[0]) && is_object($param[0])) { - - $arguments[$column['name']] = array( + $arguments[ $column['name'] ] = array( 'description' => (string) $param[0]->getDescription(), 'type' => (string) $param[0]->getType(), 'required' => false, // Actual value set later ); if ($db_schema) { - $db_column = wu_array_find_first_by($db_schema, 'name', $column['name']); if ($db_column && wu_get_isset($db_column, 'type') && preg_match('/^ENUM/', (string) $db_column['type'])) { - preg_match_all("/'(.*?)'/", (string) $db_column['type'], $matches); if (isset($matches[1])) { - - $arguments[$column['name']]['enum'] = array_map('strtolower', $matches[1]); - - } // end if; - - } // end if; - - } // end if; + $arguments[ $column['name'] ]['enum'] = array_map('strtolower', $matches[1]); + } + } + } $option = $doc_block->getTagsByName('options'); if (isset($option[0])) { - $description = (string) $option[0]->getDescription(); if (strpos($description, '\\WP_Ultimo\\') !== false) { - $enum_options = new $description(); - $arguments[$column['name']]['enum'] = array_map('strtolower', array_keys(array_flip($enum_options->get_options()))); - + $arguments[ $column['name'] ]['enum'] = array_map('strtolower', array_keys(array_flip($enum_options->get_options()))); } else { - - $arguments[$column['name']]['enum'] = explode(',', strtolower($description)); - - } // end if; - - } // end if; - - } // end if; - - } // end foreach; + $arguments[ $column['name'] ]['enum'] = explode(',', strtolower($description)); + } + } + } + } return $arguments; - -} // end wu_reflection_parse_object_arguments; +} /** * Use php reflection to generate the documentation for the REST API. @@ -127,28 +106,19 @@ function wu_reflection_parse_arguments_from_setters($class_name, $return_schema $arguments = array(); foreach (get_class_methods($class_name) as $setter_name) { - if (preg_match('/^set_/', $setter_name)) { - $argument = str_replace('set_', '', $setter_name); if ($return_schema) { - $arguments[] = array( 'name' => $argument, 'type' => '', ); - } else { - $arguments[] = $argument; - - } // end if; - - } // end if; - - } // end foreach; + } + } + } return $arguments; - -} // end wu_reflection_parse_arguments_from_setters; +} diff --git a/inc/functions/rest.php b/inc/functions/rest.php index 426d633..32efac6 100644 --- a/inc/functions/rest.php +++ b/inc/functions/rest.php @@ -24,16 +24,13 @@ function wu_rest_get_endpoint_from_class_name($class_name) { $endpoint = $class_name; if (class_exists($class_name)) { - $last_segment = explode('\\', $class_name); $endpoint = strtolower(end($last_segment)); - - } // end if; + } return $endpoint; - -} // end wu_rest_get_endpoint_from_class_name; +} /** * Searches the hard-coded schemas for a arguments list. @@ -56,22 +53,17 @@ function wu_rest_get_endpoint_schema($class_name, $context = 'create', $force_ge $schema_file = wu_path("inc/api/schemas/$endpoint-$context.php"); if (file_exists($schema_file) && apply_filters('wu_rest_get_endpoint_schema_use_cache', true)) { - $schema = include $schema_file; $from_cache = true; - - } // end if; + } if (empty($schema) && $from_cache === false && $force_generate) { - $schema = wu_rest_generate_schema($class_name, $context); - - } // end if; + } return $schema; - -} // end wu_rest_get_endpoint_schema; +} /** * Generates the rest schema for a class name. @@ -89,18 +81,15 @@ function wu_rest_generate_schema($class_name, $context = 'create') { $schema = wu_reflection_parse_object_arguments($class_name); foreach ($schema as $argument_name => &$argument) { - $argument['type'] = wu_rest_treat_argument_type($argument['type']); $argument['required'] = $context === 'create' ? in_array($argument_name, $required_fields, true) : false; - $schema[$argument_name] = $argument; - - } // end foreach; + $schema[ $argument_name ] = $argument; + } return $schema; - -} // end wu_rest_generate_schema; +} /** * Treat argument types to perform additional validations. @@ -115,19 +104,12 @@ function wu_rest_treat_argument_type($type) { $type = (string) $type; if ($type === 'bool') { - $type = 'boolean'; - } elseif ($type === 'int') { - $type = 'integer'; - } elseif ($type === 'float') { - $type = 'number'; - - } // end if; + } return $type; - -} // end wu_rest_treat_argument_type; +} diff --git a/inc/functions/scheduler.php b/inc/functions/scheduler.php index 0035df7..eb5eb80 100644 --- a/inc/functions/scheduler.php +++ b/inc/functions/scheduler.php @@ -18,14 +18,11 @@ defined('ABSPATH') || exit; function wu_get_next_queue_run() { if (class_exists('ActionScheduler')) { - return wu_switch_blog_and_run(fn() => ActionScheduler::lock()->get_expiration('async-request-runner') - time()); - - } // end if; + } return 0; - -} // end wu_get_next_queue_run; +} /** * Enqueue an action to run one time, as soon as possible. @@ -40,8 +37,7 @@ function wu_get_next_queue_run() { function wu_enqueue_async_action($hook, $args = array(), $group = '') { return wu_switch_blog_and_run(fn() => as_enqueue_async_action($hook, $args, $group)); - -} // end wu_enqueue_async_action; +} /** * Schedule an action to run one time. @@ -58,8 +54,7 @@ function wu_enqueue_async_action($hook, $args = array(), $group = '') { function wu_schedule_single_action($timestamp, $hook, $args = array(), $group = '') { return wu_switch_blog_and_run(fn() => as_schedule_single_action($timestamp, $hook, $args, $group)); - -} // end wu_schedule_single_action; +} /** * Schedule a recurring action. @@ -77,8 +72,7 @@ function wu_schedule_single_action($timestamp, $hook, $args = array(), $group = function wu_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args = array(), $group = '') { return wu_switch_blog_and_run(fn() => as_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args, $group)); - -} // end wu_schedule_recurring_action; +} /** * Schedule an action that recurs on a cron-like schedule. @@ -108,8 +102,7 @@ function wu_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $ function wu_schedule_cron_action($timestamp, $schedule, $hook, $args = array(), $group = '') { return wu_switch_blog_and_run(fn() => as_schedule_cron_action($timestamp, $schedule, $hook, $args, $group)); - -} // end wu_schedule_cron_action; +} /** * Cancel the next occurrence of a scheduled action. @@ -125,8 +118,7 @@ function wu_schedule_cron_action($timestamp, $schedule, $hook, $args = array(), function wu_unschedule_action($hook, $args = array(), $group = '') { return wu_switch_blog_and_run(fn() => as_unschedule_action($hook, $args, $group)); - -} // end wu_unschedule_action; +} /** * Cancel all occurrences of a scheduled action. @@ -137,11 +129,10 @@ function wu_unschedule_action($hook, $args = array(), $group = '') { * @param array $args Args that would have been passed to the job. * @param string $group The group the job is assigned to. */ -function wu_unschedule_all_actions($hook, $args = array(), $group = '' ) { +function wu_unschedule_all_actions($hook, $args = array(), $group = '') { return wu_switch_blog_and_run(fn() => as_unschedule_all_actions($hook, $args, $group)); - -} // end wu_unschedule_all_actions; +} /** * Check if there is an existing action in the queue with a given hook, args and group combination. @@ -163,8 +154,7 @@ function wu_unschedule_all_actions($hook, $args = array(), $group = '' ) { function wu_next_scheduled_action($hook, $args = null, $group = '') { return wu_switch_blog_and_run(fn() => as_next_scheduled_action($hook, $args, $group)); - -} // end wu_next_scheduled_action; +} /** * Find scheduled actions. @@ -179,5 +169,4 @@ function wu_next_scheduled_action($hook, $args = null, $group = '') { function wu_get_scheduled_actions($args = array(), $return_format = OBJECT) { return wu_switch_blog_and_run(fn() => as_get_scheduled_actions($args, $return_format)); - -} // end wu_get_scheduled_actions; +} diff --git a/inc/functions/session.php b/inc/functions/session.php index e0c6371..9f5abdc 100644 --- a/inc/functions/session.php +++ b/inc/functions/session.php @@ -25,14 +25,11 @@ function wu_get_session($session_key) { $session = wu_get_isset($wu_session, $session_key, false); - if ($session && is_a( $session, \WP_Ultimo\Session_Cookie::class)) { - + if ($session && is_a($session, \WP_Ultimo\Session_Cookie::class)) { return $session; + } - } // end if; + $wu_session[ $session_key ] = new \WP_Ultimo\Session_Cookie($session_key); - $wu_session[$session_key] = new \WP_Ultimo\Session_Cookie($session_key); - - return $wu_session[$session_key]; - -} // end wu_get_session; + return $wu_session[ $session_key ]; +} diff --git a/inc/functions/settings.php b/inc/functions/settings.php index 55a3001..95fe326 100644 --- a/inc/functions/settings.php +++ b/inc/functions/settings.php @@ -23,8 +23,7 @@ require_once wu_path('inc/functions/options.php'); function wu_get_all_settings() { return WP_Ultimo()->settings->get_all(); - -} // end wu_get_all_settings; +} /** * Get a specific settings from the plugin. @@ -38,8 +37,7 @@ function wu_get_all_settings() { function wu_get_setting($setting, $default = false) { return WP_Ultimo()->settings->get_setting($setting, $default); - -} // end wu_get_setting; +} /** * Saves a specific setting into the database. @@ -53,8 +51,7 @@ function wu_get_setting($setting, $default = false) { function wu_save_setting($setting, $value) { return WP_Ultimo()->settings->save_setting($setting, $value); - -} // end wu_save_setting; +} /** * Adds a new settings section. @@ -72,8 +69,7 @@ function wu_save_setting($setting, $value) { function wu_register_settings_section($section_slug, $atts) { WP_Ultimo()->settings->add_section($section_slug, $atts); - -} // end wu_register_settings_section; +} /** * Adds a new field to a settings section. @@ -91,8 +87,7 @@ function wu_register_settings_section($section_slug, $atts) { function wu_register_settings_field($section_slug, $field_slug, $atts, $priority = 10) { WP_Ultimo()->settings->add_field($section_slug, $field_slug, $atts, $priority); - -} // end wu_register_settings_field; +} /** * Adds a help side-panel to the settings page. @@ -106,36 +101,40 @@ function wu_register_settings_field($section_slug, $field_slug, $atts, $priority function wu_register_settings_side_panel($section_slug, $atts) { if (wu_request('tab', 'general') !== $section_slug && $section_slug !== 'all') { - return; + } - } // end if; - - $atts = wp_parse_args($atts, array( - 'title' => __('Side Panel', 'wp-ultimo'), - 'render' => '__return_false', - 'show' => '__return_true', - )); + $atts = wp_parse_args( + $atts, + array( + 'title' => __('Side Panel', 'wp-ultimo'), + 'render' => '__return_false', + 'show' => '__return_true', + ) + ); $callback = wu_get_isset($atts, 'show', '__return_true'); $should_display = is_callable($callback) && call_user_func($callback); - if (!$should_display) { - + if ( ! $should_display) { return; - - } // end if; + } $id = sanitize_title($atts['title']); - add_meta_box("wp-ultimo-{$id}", $atts['title'], function() use ($atts) { + add_meta_box( + "wp-ultimo-{$id}", + $atts['title'], + function () use ($atts) { - call_user_func($atts['render']); - - }, 'wu_settings_admin_page', 'side', 'low'); - -} // end wu_register_settings_side_panel; + call_user_func($atts['render']); + }, + 'wu_settings_admin_page', + 'side', + 'low' + ); +} /** * Retrieve the network custom logo. @@ -152,24 +151,19 @@ function wu_get_network_logo($size = 'full') { restore_current_blog(); if ($settings_logo) { - return $settings_logo[0]; - - } // end if; + } $logo = wu_get_asset('logo.png', 'img'); $custom_logo = wp_get_attachment_image_src(get_theme_mod('custom_logo'), $size); - if (!empty($custom_logo)) { - + if ( ! empty($custom_logo)) { $logo = $custom_logo[0]; - - } // end if; + } return apply_filters('wu_get_logo', $logo); - -} // end wu_get_network_logo; +} /** * Retrieve the network custom icon. @@ -182,5 +176,4 @@ function wu_get_network_favicon($size = '48') { $custom_icon = get_site_icon_url($size, wu_get_asset('badge.png', 'img'), wu_get_main_site_id()); return $custom_icon; - -} // end wu_get_network_favicon; +} diff --git a/inc/functions/site-context.php b/inc/functions/site-context.php index 4b53d39..03c9b0f 100644 --- a/inc/functions/site-context.php +++ b/inc/functions/site-context.php @@ -20,11 +20,9 @@ defined('ABSPATH') || exit; */ function wu_switch_blog_and_run($callback, $site_id = false) { - if (!$site_id) { - + if ( ! $site_id) { $site_id = wu_get_main_site_id(); - - } // end if; + } is_multisite() && switch_to_blog($site_id); @@ -33,5 +31,4 @@ function wu_switch_blog_and_run($callback, $site_id = false) { is_multisite() && restore_current_blog(); return $result; - -} // end wu_switch_blog_and_run; +} diff --git a/inc/functions/site.php b/inc/functions/site.php index d15ca6f..e68843a 100644 --- a/inc/functions/site.php +++ b/inc/functions/site.php @@ -18,8 +18,7 @@ defined('ABSPATH') || exit; function wu_get_current_site() { return new \WP_Ultimo\Models\Site(get_blog_details()); - -} // end wu_get_current_site; +} /** * Returns the site object @@ -32,8 +31,7 @@ function wu_get_current_site() { function wu_get_site($id) { return \WP_Ultimo\Models\Site::get_by_id($id); - -} // end wu_get_site; +} /** * Gets a site based on the hash. * @@ -45,8 +43,7 @@ function wu_get_site($id) { function wu_get_site_by_hash($hash) { return \WP_Ultimo\Models\Site::get_by_hash($hash); - -} // end wu_get_site_by_hash; +} /** * Queries sites. @@ -58,29 +55,26 @@ function wu_get_site_by_hash($hash) { */ function wu_get_sites($query = array()) { - if (!empty($query['search'])) { - - $domain_ids = wu_get_domains(array( - 'number' => -1, - 'search' => '*' . $query['search'] . '*', - 'fields' => array('blog_id'), - )); + if ( ! empty($query['search'])) { + $domain_ids = wu_get_domains( + array( + 'number' => -1, + 'search' => '*' . $query['search'] . '*', + 'fields' => array('blog_id'), + ) + ); $domain_ids = array_column($domain_ids, 'blog_id'); - if (!empty($domain_ids)) { - + if ( ! empty($domain_ids)) { $query['blog_id__in'] = $domain_ids; unset($query['search']); - - } // end if; - - } // end if; + } + } return \WP_Ultimo\Models\Site::query($query); - -} // end wu_get_sites; +} /** * Returns the list of Site Templates. @@ -92,13 +86,15 @@ function wu_get_sites($query = array()) { */ function wu_get_site_templates($query = array()) { - $query = wp_parse_args($query, array( - 'number' => 9999, // By default, we try to get ALL available templates. - )); + $query = wp_parse_args( + $query, + array( + 'number' => 9999, // By default, we try to get ALL available templates. + ) + ); return \WP_Ultimo\Models\Site::get_all_by_type('site_template', $query); - -} // end wu_get_site_templates; +} /** * Parses a URL and breaks it into different parts @@ -113,16 +109,13 @@ function wu_handle_site_domain($domain) { global $current_site; if (strpos($domain, 'http') === false) { - $domain = "https://{$domain}"; - - } // end if; + } $parsed = parse_url($domain); return (object) $parsed; - -} // end wu_handle_site_domain; +} /** * Creates a new site. * @@ -135,16 +128,19 @@ function wu_create_site($site_data) { $current_site = get_current_site(); - $site_data = wp_parse_args($site_data, array( - 'domain' => $current_site->domain, - 'path' => '/', - 'title' => false, - 'type' => false, - 'template_id' => false, - 'featured_image_id' => 0, - 'duplication_arguments' => false, - 'public' => true, - )); + $site_data = wp_parse_args( + $site_data, + array( + 'domain' => $current_site->domain, + 'path' => '/', + 'title' => false, + 'type' => false, + 'template_id' => false, + 'featured_image_id' => 0, + 'duplication_arguments' => false, + 'public' => true, + ) + ); $site = new \WP_Ultimo\Models\Site($site_data); @@ -153,8 +149,7 @@ function wu_create_site($site_data) { $saved = $site->save(); return is_wp_error($saved) ? $saved : $site; - -} // end wu_create_site; +} /** * Returns the correct domain/path combination when creating a new site. @@ -173,7 +168,7 @@ function wu_get_site_domain_and_path($path_or_subdomain = '/', $base_domain = fa $domain = $base_domain ? $base_domain : $current_site->domain; - $d = new \stdClass; + $d = new \stdClass(); if (is_multisite() && is_subdomain_install()) { /* @@ -186,8 +181,7 @@ function wu_get_site_domain_and_path($path_or_subdomain = '/', $base_domain = fa $d->path = '/'; return $d; - - } // end if; + } $d->domain = $domain; @@ -205,5 +199,4 @@ function wu_get_site_domain_and_path($path_or_subdomain = '/', $base_domain = fa * @return object An object containing a domain and path keys. */ return apply_filters('wu_get_site_domain_and_path', $d, $path_or_subdomain); - -} // end wu_get_site_domain_and_path; +} diff --git a/inc/functions/sort.php b/inc/functions/sort.php index 06df28a..423c2c3 100644 --- a/inc/functions/sort.php +++ b/inc/functions/sort.php @@ -21,13 +21,12 @@ defined('ABSPATH') || exit; */ function wu_sort_by_column($a, $b, $column = 'order') { - $a[$column] = isset($a[$column]) ? (int) $a[$column] : 50; + $a[ $column ] = isset($a[ $column ]) ? (int) $a[ $column ] : 50; - $b[$column] = isset($b[$column]) ? (int) $b[$column] : 50; + $b[ $column ] = isset($b[ $column ]) ? (int) $b[ $column ] : 50; - return $a[$column] - $b[$column]; - -} // end wu_sort_by_column; + return $a[ $column ] - $b[ $column ]; +} /** * Sorts the fields. @@ -39,8 +38,7 @@ function wu_sort_by_column($a, $b, $column = 'order') { function wu_sort_by_order($a, $b) { return wu_sort_by_column($a, $b, 'order'); - -} // end wu_sort_by_order; +} /** * Loops through the list items and adds a order key if none is set, based on the index. @@ -56,19 +54,14 @@ function wu_set_order_from_index($list, $order_key = 'order') { $index = 1; foreach ($list as &$item) { - - if (isset($item[$order_key]) === false) { - + if (isset($item[ $order_key ]) === false) { $index = $index ? $index : 1; // phpcs:ignore - $item[$order_key] = $index * 10; + $item[ $order_key ] = $index * 10; - $index++; - - } // end if; - - } // end foreach; + ++$index; + } + } return $list; - -} // end wu_set_order_from_index; +} diff --git a/inc/functions/string-helpers.php b/inc/functions/string-helpers.php index ce2a52a..517bb2a 100644 --- a/inc/functions/string-helpers.php +++ b/inc/functions/string-helpers.php @@ -20,8 +20,7 @@ defined('ABSPATH') || exit; function wu_string_to_bool($string) { return is_bool($string) ? $string : ('on' === strtolower($string) || 'yes' === strtolower($string) || 1 === $string || 'true' === strtolower($string) || '1' === $string); - -} // end wu_string_to_bool; +} /** * Converts a slug to a name. @@ -38,8 +37,7 @@ function wu_slug_to_name($slug) { $slug = str_replace(array('-', '_'), ' ', $slug); return ucwords($slug); - -} // end wu_slug_to_name; +} /** * Replaces dashes with underscores on strings. @@ -52,8 +50,7 @@ function wu_slug_to_name($slug) { function wu_replace_dashes($str) { return str_replace('-', '_', $str); - -} // end wu_replace_dashes; +} /** * Get the initials for a string. @@ -73,17 +70,12 @@ function wu_get_initials($string, $max_size = 2) { $initials = ''; for ($i = 0; $i < $max_size; $i++) { - - if (!isset($words[$i])) { - + if ( ! isset($words[ $i ])) { break; + } - } // end if; - - $initials .= substr($words[$i], 0, 1); - - } // end for; + $initials .= substr($words[ $i ], 0, 1); + } return strtoupper($initials); - -} // end wu_get_initials; +} diff --git a/inc/functions/sunrise.php b/inc/functions/sunrise.php index a9efe73..9d03ab7 100644 --- a/inc/functions/sunrise.php +++ b/inc/functions/sunrise.php @@ -20,8 +20,7 @@ defined('ABSPATH') || exit; function wu_should_load_sunrise() { return \WP_Ultimo\Sunrise::should_load_sunrise(); - -} // end wu_should_load_sunrise; +} /** * Get a setting value, when te normal APIs are not available. @@ -37,18 +36,15 @@ function wu_should_load_sunrise() { function wu_get_setting_early($setting, $default = false) { if (did_action('wp_ultimo_load')) { - _doing_it_wrong('wu_get_setting_early', __('Regular setting APIs are already available. You should use wu_get_setting() instead.', 'wp-ultimo'), '2.0.0'); - - } // end if; + } $settings_key = \WP_Ultimo\Settings::KEY; $settings = get_network_option(null, 'wp-ultimo_' . $settings_key); return wu_get_isset($settings, $setting, $default); - -} // end wu_get_setting_early; +} /** * Set a setting value, when te normal APIs are not available. @@ -63,20 +59,17 @@ function wu_get_setting_early($setting, $default = false) { function wu_save_setting_early($key, $value) { if (did_action('wp_ultimo_load')) { - _doing_it_wrong('wu_save_setting_early', __('Regular setting APIs are already available. You should use wu_save_setting() instead.', 'wp-ultimo'), '2.0.20'); - - } // end if; + } $settings_key = \WP_Ultimo\Settings::KEY; $settings = get_network_option(null, 'wp-ultimo_' . $settings_key); - $settings[$key] = $value; + $settings[ $key ] = $value; return update_network_option(null, 'wp-ultimo_' . $settings_key, $settings); - -} // end wu_save_setting_early; +} /** * Get the security mode key used to disable security mode @@ -88,8 +81,7 @@ function wu_get_security_mode_key(): string { $hash = md5((string) get_network_option(null, 'admin_email')); return substr($hash, 0, 6); - -} // end wu_get_security_mode_key; +} /** * Early substitute for wp_kses_data before it exists. @@ -106,5 +98,4 @@ function wu_get_security_mode_key(): string { function wu_kses_data($data) { return function_exists('wp_kses_data') ? wp_kses_data($data) : $data; - -} // end wu_kses_data; +} diff --git a/inc/functions/tax.php b/inc/functions/tax.php index ea1f415..1d65092 100644 --- a/inc/functions/tax.php +++ b/inc/functions/tax.php @@ -9,7 +9,7 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Tax\Tax; +use WP_Ultimo\Tax\Tax; /** * Checks if WP Multisite WaaS should collect taxes. @@ -20,8 +20,7 @@ use \WP_Ultimo\Tax\Tax; function wu_should_collect_taxes() { return (bool) wu_get_setting('enable_taxes', false); - -} // end wu_should_collect_taxes; +} /** * Returns the tax categories. @@ -32,8 +31,7 @@ function wu_should_collect_taxes() { function wu_get_tax_categories() { return Tax::get_instance()->get_tax_rates(); - -} // end wu_get_tax_categories; +} /** * Returns a given tax category @@ -46,11 +44,14 @@ function wu_get_tax_category($tax_category = 'default') { $tax_categories = wu_get_tax_categories(); - return wu_get_isset($tax_categories, $tax_category, array( - 'rates' => array(), - )); - -} // end wu_get_tax_category; + return wu_get_isset( + $tax_categories, + $tax_category, + array( + 'rates' => array(), + ) + ); +} /** * Returns the tax categories as a slug => name array. * @@ -59,8 +60,7 @@ function wu_get_tax_category($tax_category = 'default') { function wu_get_tax_categories_as_options(): array { return array_map(fn($item) => $item['name'], wu_get_tax_categories()); - -} // end wu_get_tax_categories_as_options; +} /** * Calculates the tax value. * @@ -81,8 +81,7 @@ function wu_get_tax_amount($base_price, $amount, $type, $format = true, $inclusi $tax_total = $amount; if ($type === 'percentage') { - - if (!$inclusive) { + if ( ! $inclusive) { /** * Exclusive tax @@ -90,7 +89,6 @@ function wu_get_tax_amount($base_price, $amount, $type, $format = true, $inclusi * Calculates tax to be ADDED to the order. */ $tax_total = $base_price * ($amount / 100); - } else { /** @@ -99,24 +97,19 @@ function wu_get_tax_amount($base_price, $amount, $type, $format = true, $inclusi * Calculates the tax value inside the total price. */ $tax_total = $base_price - ($base_price / (1 + ($amount / 100))); - - } // end if; - - } // end if; + } + } /* * Return results */ - if (!$format) { - + if ( ! $format) { return round($tax_total, 2); - - } // end if; + } return number_format((float) $tax_total, 2); - -} // end wu_get_tax_amount; +} /** * Searches for applicable tax rates based on the country. @@ -134,11 +127,9 @@ function wu_get_tax_amount($base_price, $amount, $type, $format = true, $inclusi */ function wu_get_applicable_tax_rates($country, $tax_category = 'default', $state = '*', $city = '*') { - if (!$country) { - + if ( ! $country) { return array(); - - } // end if; + } $tax_category = wu_get_tax_category($tax_category); @@ -146,84 +137,69 @@ function wu_get_applicable_tax_rates($country, $tax_category = 'default', $state foreach ($tax_category['rates'] as &$rate) { /* - * Step 0: Prepare. + * Step 0: Prepare. */ $rate['state'] = explode(',', (string) $rate['state']); $rate['city'] = explode(',', (string) $rate['city']); - $keys_of_interest = array_intersect_key($rate, array( - 'country' => 1, - 'state' => 1, - 'city' => 1, - )); + $keys_of_interest = array_intersect_key( + $rate, + array( + 'country' => 1, + 'state' => 1, + 'city' => 1, + ) + ); $priority = 0; foreach ($keys_of_interest as $key => $value) { - $value = is_array($value) ? array_filter($value) : trim((string) $value); /* * Step 1: The country. */ if ($key === 'country' && $rate['country'] === $country) { - $priority += 10; - - } // end if; + } /* * Step 2: The state / province */ if ($key === 'state' && $state !== '*') { - if (in_array($state, $value, true)) { - $priority += 1; - } elseif (empty($value) || in_array('*', $value, true)) { - $priority += 0.5; - - } // end if; - - } // end if; + } + } /* * Step 3: The city */ if ($key === 'city' && $city !== '*') { - if (in_array($city, $value, true)) { /* * If it's a full match, gives 1 point. */ $priority += 1; - } elseif (empty($value) || in_array('*', $value, true)) { /* * If it is a wildcard, award half a point. */ $priority += 0.5; - - } // end if; - - } // end if; - - } // end foreach; + } + } + } if ($priority >= 10) { - $rate['order'] = $priority; - $results[$rate['id']] = $rate; - - } // end if; - - } // end foreach; + $results[ $rate['id'] ] = $rate; + } + } uasort($results, 'wu_sort_by_order'); return array_values($results); - -} // end wu_get_applicable_tax_rates; +} diff --git a/inc/functions/template.php b/inc/functions/template.php index c6c6776..1bf7646 100644 --- a/inc/functions/template.php +++ b/inc/functions/template.php @@ -34,10 +34,8 @@ function wu_get_template($view, $args = array(), $default_view = false) { // Make passed variables available if (is_array($args)) { - extract($args); // phpcs:ignore - - } // end if; + } /** * Allows developers to add additional folders to the replaceable list. @@ -49,32 +47,30 @@ function wu_get_template($view, $args = array(), $default_view = false) { * @param array $replaceable_views List of allowed folders. * @return array */ - $replaceable_views = apply_filters('wu_view_override_replaceable_views', array( - 'signup', - 'emails', - 'forms', - 'checkout' - )); + $replaceable_views = apply_filters( + 'wu_view_override_replaceable_views', + array( + 'signup', + 'emails', + 'forms', + 'checkout', + ) + ); /* * Only allow template for emails and signup for now */ if (preg_match('/(' . implode('\/?|', $replaceable_views) . '\/?' . ')\w+/', $view)) { - $template = apply_filters('wu_view_override', $template, $view, $default_view); + } - } // end if; - - if (!file_exists($template) && $default_view) { - + if ( ! file_exists($template) && $default_view) { $template = wu_path("views/$default_view.php"); - - } // end if; + } // Load our view include $template; - -} // end wu_get_template; +} /** * Alias function to be used on the templates; @@ -92,5 +88,4 @@ function wu_get_template_contents($view, $args = array(), $default_view = false) wu_get_template($view, $args, $default_view); // phpcs:ignore return ob_get_clean(); - -} // end wu_get_template_contents; +} diff --git a/inc/functions/translation.php b/inc/functions/translation.php index 1c343eb..3ac7936 100644 --- a/inc/functions/translation.php +++ b/inc/functions/translation.php @@ -20,15 +20,12 @@ defined('ABSPATH') || exit; function wu_get_translatable_string($string) { if (is_string($string) === false) { - return $string; - - } // end if; + } $translatable_strings = include WP_ULTIMO_PLUGIN_DIR . '/data/translatable-strings.php'; $translatable_strings = apply_filters('wu_translatable_strings', $translatable_strings, $string); return wu_get_isset($translatable_strings, $string, $string); - -} // end wu_get_translatable_string; +} diff --git a/inc/functions/url.php b/inc/functions/url.php index aa2d45c..9b30269 100644 --- a/inc/functions/url.php +++ b/inc/functions/url.php @@ -21,14 +21,11 @@ function wu_get_current_url() { * the initiator URL. */ if (wp_doing_ajax() && isset($_SERVER['HTTP_REFERER'])) { - return $_SERVER['HTTP_REFERER']; - - } // end if; + } return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; - -} // end wu_get_current_url; +} /** * Replaces or removes the scheme from a URL. @@ -42,8 +39,7 @@ function wu_get_current_url() { function wu_replace_scheme($url, $new_scheme = '') { return preg_replace('(^https?://)', $new_scheme, $url); - -} // end wu_replace_scheme; +} /** * Wrapper to the network_admin_url function for WP Multisite WaaS admin urls. @@ -61,8 +57,7 @@ function wu_network_admin_url($path, $query = array()) { $url = network_admin_url($path); return add_query_arg($query, $url); - -} // end wu_network_admin_url; +} /** * Get the light ajax implementation URL. @@ -78,30 +73,23 @@ function wu_network_admin_url($path, $query = array()) { function wu_ajax_url($when = null, $query_args = array(), $site_id = false, $scheme = null) { if (empty($site_id)) { - $site_id = get_current_blog_id(); - - } // end if; + } $base_url = get_home_url($site_id, '', $scheme); - if (!is_array($query_args)) { - + if ( ! is_array($query_args)) { $query_args = array(); - - } // end if; + } $query_args['wu-ajax'] = 1; $query_args['r'] = wp_create_nonce('wu-ajax-nonce'); if ($when) { - $query_args['wu-when'] = base64_encode($when); - - } // end if; + } $url = add_query_arg($query_args, $base_url); return apply_filters('wu_ajax_url', $url, $query_args, $when, $site_id); - -} // end wu_ajax_url; +} diff --git a/inc/functions/user.php b/inc/functions/user.php index 782a7e8..ec5bc66 100644 --- a/inc/functions/user.php +++ b/inc/functions/user.php @@ -18,28 +18,21 @@ defined('ABSPATH') || exit; */ function wu_get_roles_as_options($add_default_option = false) { - if (!function_exists('get_editable_roles')) { - - require_once(ABSPATH . 'wp-admin/includes/user.php'); - - } // end if; + if ( ! function_exists('get_editable_roles')) { + require_once ABSPATH . 'wp-admin/includes/user.php'; + } $roles = array(); if ($add_default_option) { - $roles['default'] = __('Use WP Multisite WaaS default', 'wp-ultimo'); - - } // end if; + } $editable_roles = get_editable_roles(); foreach ($editable_roles as $role => $details) { - - $roles[esc_attr($role)] = translate_user_role($details['name']); - - } // end foreach; + $roles[ esc_attr($role) ] = translate_user_role($details['name']); + } return $roles; - -} // end wu_get_roles_as_options; +} diff --git a/inc/functions/webhook.php b/inc/functions/webhook.php index deb1266..732c17a 100644 --- a/inc/functions/webhook.php +++ b/inc/functions/webhook.php @@ -9,7 +9,7 @@ // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Models\Webhook; +use WP_Ultimo\Models\Webhook; /** * Queries webhook. @@ -22,8 +22,7 @@ use \WP_Ultimo\Models\Webhook; function wu_get_webhooks($query = array()) { return \WP_Ultimo\Models\Webhook::query($query); - -} // end wu_get_webhooks; +} /** * Gets a webhook on the ID. @@ -36,8 +35,7 @@ function wu_get_webhooks($query = array()) { function wu_get_webhook($webhook_id) { return \WP_Ultimo\Models\Webhook::get_by_id($webhook_id); - -} // end wu_get_webhook; +} /** * Creates a new webhook. @@ -51,21 +49,23 @@ function wu_get_webhook($webhook_id) { */ function wu_create_webhook($webhook_data) { - $webhook_data = wp_parse_args($webhook_data, array( - 'name' => false, - 'webhook_url' => false, - 'event' => false, - 'active' => false, - 'event_count' => 0, - 'date_created' => wu_get_current_time('mysql', true), - 'date_modified' => wu_get_current_time('mysql', true), - 'migrated_from_id' => 0, - )); + $webhook_data = wp_parse_args( + $webhook_data, + array( + 'name' => false, + 'webhook_url' => false, + 'event' => false, + 'active' => false, + 'event_count' => 0, + 'date_created' => wu_get_current_time('mysql', true), + 'date_modified' => wu_get_current_time('mysql', true), + 'migrated_from_id' => 0, + ) + ); $webhook = new Webhook($webhook_data); $saved = $webhook->save(); return is_wp_error($saved) ? $saved : $webhook; - -} // end wu_create_webhook; +} diff --git a/inc/gateways/class-base-gateway.php b/inc/gateways/class-base-gateway.php index 44be3f4..46bf0d2 100644 --- a/inc/gateways/class-base-gateway.php +++ b/inc/gateways/class-base-gateway.php @@ -151,8 +151,7 @@ abstract class Base_Gateway { * Calls the init code. */ $this->init(); - - } // end __construct; + } /** * Sets an order. @@ -169,10 +168,8 @@ abstract class Base_Gateway { public function set_order($order) { if ($order === null) { - return; - - } // end if; + } /* * The only thing we do is to set the order. @@ -188,8 +185,7 @@ abstract class Base_Gateway { $this->membership = $this->order->get_membership(); $this->payment = $this->order->get_payment(); $this->discount_code = $this->order->get_discount_code(); - - } // end set_order; + } /** * Returns the id of the gateway. @@ -197,11 +193,10 @@ abstract class Base_Gateway { * @since 2.0.0 * @return string */ - public final function get_id() { + final public function get_id() { return $this->id; - - } // end get_id; + } /* * Required Methods. @@ -307,7 +302,7 @@ abstract class Base_Gateway { * @since 2.0.0 * @return void */ - public function init() {} // end init; + public function init() {} /** * Adds Settings. @@ -322,7 +317,7 @@ abstract class Base_Gateway { * @since 2.0.0 * @return void */ - public function settings() {} // end settings; + public function settings() {} /** * Checkout fields. @@ -336,7 +331,7 @@ abstract class Base_Gateway { * @since 2.0.0 * @return void */ - public function fields() {} // end fields; + public function fields() {} /** * Declares support for recurring payments. @@ -358,8 +353,7 @@ abstract class Base_Gateway { public function supports_recurring() { return false; - - } // end supports_recurring; + } /** * Declares support for free trials. @@ -383,8 +377,7 @@ abstract class Base_Gateway { public function supports_free_trials() { return false; - - } // end supports_free_trials; + } /** * Declares support for recurring amount updates. @@ -403,8 +396,7 @@ abstract class Base_Gateway { public function supports_amount_update() { return false; - - } // end supports_amount_update; + } /** * Handles payment method updates. @@ -412,7 +404,7 @@ abstract class Base_Gateway { * @since 2.0.0 * @return void */ - public function update_payment_method() {} // end update_payment_method; + public function update_payment_method() {} /** * Defines a public title. @@ -435,18 +427,15 @@ abstract class Base_Gateway { $registered_gateway = wu_get_isset($gateways, $this->get_id()); - if (!$registered_gateway) { - + if ( ! $registered_gateway) { $default = $this->get_id(); $default = str_replace('-', ' ', $default); return ucwords($default); - - } // end if; + } return $registered_gateway['title']; - - } // end get_public_title; + } /** * Adds additional hooks. @@ -460,7 +449,7 @@ abstract class Base_Gateway { * @since 2.0.0 * @return void */ - public function hooks() {} // end hooks; + public function hooks() {} /** * Run preparations before checkout processing. @@ -481,7 +470,7 @@ abstract class Base_Gateway { * @since 2.0.0 * @return void|array */ - public function run_preflight() {} // end run_preflight; + public function run_preflight() {} /** * Registers and Enqueue scripts. @@ -494,7 +483,7 @@ abstract class Base_Gateway { * @since 2.0.0 * @return void */ - public function register_scripts() {} // end register_scripts; + public function register_scripts() {} /** * Gives gateways a chance to run things before backwards compatible webhooks are run. @@ -502,7 +491,7 @@ abstract class Base_Gateway { * @since 2.0.7 * @return void */ - public function before_backwards_compatible_webhook() {} // end before_backwards_compatible_webhook; + public function before_backwards_compatible_webhook() {} /** * Handles webhook calls. @@ -518,7 +507,7 @@ abstract class Base_Gateway { * @since 2.0.0 * @return void */ - public function process_webhooks() {} // end process_webhooks; + public function process_webhooks() {} /** * Handles confirmation windows and extra processing. @@ -532,7 +521,7 @@ abstract class Base_Gateway { * @since 2.0.0 * @return void */ - public function process_confirmation() {} // end process_confirmation; + public function process_confirmation() {} /** * Returns the external link to view the payment on the payment gateway. @@ -544,7 +533,7 @@ abstract class Base_Gateway { * @param string $gateway_payment_id The gateway payment id. * @return void|string */ - public function get_payment_url_on_gateway($gateway_payment_id) {} // end get_payment_url_on_gateway; + public function get_payment_url_on_gateway($gateway_payment_id) {} /** * Returns the external link to view the membership on the membership gateway. @@ -556,7 +545,7 @@ abstract class Base_Gateway { * @param string $gateway_subscription_id The gateway subscription id. * @return void|string. */ - public function get_subscription_url_on_gateway($gateway_subscription_id) {} // end get_subscription_url_on_gateway; + public function get_subscription_url_on_gateway($gateway_subscription_id) {} /** * Returns the external link to view the membership on the membership gateway. @@ -568,7 +557,7 @@ abstract class Base_Gateway { * @param string $gateway_customer_id The gateway customer id. * @return void|string. */ - public function get_customer_url_on_gateway($gateway_customer_id) {} // end get_customer_url_on_gateway; + public function get_customer_url_on_gateway($gateway_customer_id) {} /** * Reflects membership changes on the gateway. @@ -589,20 +578,16 @@ abstract class Base_Gateway { $has_duration_change = $membership->get_duration() !== absint(wu_get_isset($original, 'duration')) || $membership->get_duration_unit() !== wu_get_isset($original, 'duration_unit'); // If there is no change in amount or duration, we don't do anything here. - if (!$has_amount_change && !$has_duration_change) { - + if ( ! $has_amount_change && ! $has_duration_change) { return true; - - } // end if; + } // Cancel the current gateway integration. $cancellation = $this->process_cancellation($membership, $customer); if (is_wp_error($cancellation)) { - return $cancellation; - - } // end if; + } // Reset the gateway in the membership object. $membership->set_gateway(''); @@ -611,8 +596,7 @@ abstract class Base_Gateway { $membership->set_auto_renew(false); return true; - - } // end process_membership_update; + } /* * Helper methods @@ -629,27 +613,20 @@ abstract class Base_Gateway { */ public function get_amount_update_message($to_customer = false) { - if (!$this->supports_amount_update()) { - + if ( ! $this->supports_amount_update()) { $message = __('The current payment integration will be cancelled.', 'wp-ultimo'); if ($to_customer) { - $message .= ' ' . __('You will receive a new invoice on the next billing cycle.', 'wp-ultimo'); - } else { - $message .= ' ' . __('The customer will receive a new invoice on the next billing cycle.', 'wp-ultimo'); - - } // end if; + } return $message; - - } // end if; + } return __('The current payment integration will be updated.', 'wp-ultimo'); - - } // end get_amount_update_message; + } /** * Get the return URL. @@ -660,39 +637,37 @@ abstract class Base_Gateway { public function get_return_url() { if (empty($this->return_url)) { - $this->return_url = wu_get_current_url(); - - } // end if; + } $return_url = is_admin() ? admin_url('admin.php') : $this->return_url; - $return_url = remove_query_arg(array( - 'wu-confirm', - 'token', - 'PayerID', - ), $return_url); + $return_url = remove_query_arg( + array( + 'wu-confirm', + 'token', + 'PayerID', + ), + $return_url + ); if (is_admin()) { - $args = array('page' => 'account'); if ($this->order) { - $args['updated'] = $this->order->get_cart_type(); - - } // end if; + } $return_url = add_query_arg($args, $return_url); - } else { - - $return_url = add_query_arg(array( - 'payment' => $this->payment->get_hash(), - 'status' => 'done', - ), $return_url); - - } // end if; + $return_url = add_query_arg( + array( + 'payment' => $this->payment->get_hash(), + 'status' => 'done', + ), + $return_url + ); + } /** * Allow developers to change the gateway return URL used after checkout processes. @@ -703,11 +678,10 @@ abstract class Base_Gateway { * @param self $gateway the gateway instance. * @param \WP_Ultimo\Models\Payment $payment the WP Multisite WaaS payment instance. * @param \WP_Ultimo\Checkout\Cart $cart the current WP Multisite WaaS cart order. - * @return string + * @return string */ return apply_filters('wu_return_url', $return_url, $this, $this->payment, $this->order); - - } // end get_return_url; + } /** * Get the cancel URL. @@ -718,16 +692,16 @@ abstract class Base_Gateway { public function get_cancel_url() { if (empty($this->cancel_url)) { - $this->cancel_url = wu_get_current_url(); + } - } // end if; - - return add_query_arg(array( - 'payment' => $this->payment->get_hash(), - ), $this->cancel_url); - - } // end get_cancel_url; + return add_query_arg( + array( + 'payment' => $this->payment->get_hash(), + ), + $this->cancel_url + ); + } /** * Get the confirm URL. @@ -738,17 +712,17 @@ abstract class Base_Gateway { public function get_confirm_url() { if (empty($this->confirm_url)) { - $this->confirm_url = wu_get_current_url(); + } - } // end if; - - return add_query_arg(array( - 'payment' => $this->payment->get_hash(), - 'wu-confirm' => $this->get_id(), - ), $this->confirm_url); - - } // end get_confirm_url; + return add_query_arg( + array( + 'payment' => $this->payment->get_hash(), + 'wu-confirm' => $this->get_id(), + ), + $this->confirm_url + ); + } /** * Returns the webhook url for the listener of this gateway events. @@ -761,8 +735,7 @@ abstract class Base_Gateway { $site_url = defined('WU_GATEWAY_LISTENER_URL') ? WU_GATEWAY_LISTENER_URL : get_site_url(wu_get_main_site_id(), '/'); return add_query_arg('wu-gateway', $this->get_id(), $site_url); - - } // end get_webhook_listener_url; + } /** * Set the payment. @@ -774,8 +747,7 @@ abstract class Base_Gateway { public function set_payment($payment) { $this->payment = $payment; - - } // end set_payment; + } /** * Set the membership. @@ -787,8 +759,7 @@ abstract class Base_Gateway { public function set_membership($membership) { $this->membership = $membership; - - } // end set_membership; + } /** * Set the customer. @@ -800,8 +771,7 @@ abstract class Base_Gateway { public function set_customer($customer) { $this->customer = $customer; - - } // end set_customer; + } /** * Triggers the events related to processing a payment. @@ -815,14 +785,11 @@ abstract class Base_Gateway { public function trigger_payment_processed($payment, $membership = null) { if ($membership === null) { - $membership = $payment->get_membership(); - - } // end if; + } do_action('wu_gateway_payment_processed', $payment, $membership, $this); - - } // end trigger_payment_processed; + } /** * Save a cart for a future swap. @@ -839,8 +806,7 @@ abstract class Base_Gateway { set_site_transient($swap_id, $cart, DAY_IN_SECONDS); return $swap_id; - - } // end save_swap; + } /** * Gets a saved swap based on the id. @@ -853,8 +819,7 @@ abstract class Base_Gateway { public function get_saved_swap($swap_id) { return get_site_transient($swap_id); - - } // end get_saved_swap; + } /** * Get the compatibility ids for this gateway. @@ -867,8 +832,7 @@ abstract class Base_Gateway { $all_ids = array_merge(array($this->get_id()), (array) $this->other_ids); return array_unique($all_ids); - - } // end get_all_ids; + } /** * Returns the backwards compatibility id of the gateway from v1. @@ -879,7 +843,5 @@ abstract class Base_Gateway { public function get_backwards_compatibility_v1_id() { return $this->backwards_compatibility_v1_id; - - } // end get_backwards_compatibility_v1_id; - -} // end class Base_Gateway; + } +} diff --git a/inc/gateways/class-base-stripe-gateway.php b/inc/gateways/class-base-stripe-gateway.php index ffe8686..6cb7df4 100644 --- a/inc/gateways/class-base-stripe-gateway.php +++ b/inc/gateways/class-base-stripe-gateway.php @@ -11,15 +11,15 @@ namespace WP_Ultimo\Gateways; -use \Psr\Log\LogLevel; -use \WP_Ultimo\Gateways\Base_Gateway; -use \WP_Ultimo\Gateways\Ignorable_Exception; -use \Stripe; -use \WP_Ultimo\Models\Membership; -use \WP_Ultimo\Database\Payments\Payment_Status; -use \WP_Ultimo\Checkout\Cart; -use \WP_Ultimo\Checkout\Line_Item; -use \WP_Ultimo\Models\Site; +use Psr\Log\LogLevel; +use WP_Ultimo\Gateways\Base_Gateway; +use WP_Ultimo\Gateways\Ignorable_Exception; +use Stripe; +use WP_Ultimo\Models\Membership; +use WP_Ultimo\Database\Payments\Payment_Status; +use WP_Ultimo\Checkout\Cart; +use WP_Ultimo\Checkout\Line_Item; +use WP_Ultimo\Models\Site; // Exit if accessed directly defined('ABSPATH') || exit; @@ -32,14 +32,14 @@ defined('ABSPATH') || exit; class Base_Stripe_Gateway extends Base_Gateway { /** - * Allow gateways to declare multiple additional ids. - * - * These ids can be retrieved alongside the main id, - * via the method get_all_ids(). - * - * @since 2.0.7 - * @var array - */ + * Allow gateways to declare multiple additional ids. + * + * These ids can be retrieved alongside the main id, + * via the method get_all_ids(). + * + * @since 2.0.7 + * @var array + */ protected $other_ids = array('stripe', 'stripe-checkout'); /** @@ -99,8 +99,7 @@ class Base_Stripe_Gateway extends Base_Gateway { public function supports_recurring(): bool { return true; - - } // end supports_recurring; + } /** * Declares support to subscription amount updates. @@ -111,8 +110,7 @@ class Base_Stripe_Gateway extends Base_Gateway { public function supports_amount_update(): bool { return true; - - } // end supports_amount_update; + } /** * Get things going @@ -136,12 +134,9 @@ class Base_Stripe_Gateway extends Base_Gateway { $this->setup_api_keys($id); if (method_exists('Stripe', 'setAppInfo')) { - Stripe\Stripe::setAppInfo('WordPress WP Multisite WaaS', wu_get_version(), esc_url(site_url())); - - } // end if; - - } // end init; + } + } /** * Setup api keys for stripe. @@ -156,26 +151,19 @@ class Base_Stripe_Gateway extends Base_Gateway { $id = $id ? $id : wu_replace_dashes($this->get_id()); if ($this->test_mode) { - $this->publishable_key = wu_get_setting("{$id}_test_pk_key", ''); $this->secret_key = wu_get_setting("{$id}_test_sk_key", ''); - } else { - $this->publishable_key = wu_get_setting("{$id}_live_pk_key", ''); $this->secret_key = wu_get_setting("{$id}_live_sk_key", ''); - - } // end if; + } if ($this->secret_key && Stripe\Stripe::getApiKey() !== $this->secret_key) { - Stripe\Stripe::setApiKey($this->secret_key); Stripe\Stripe::setApiVersion('2019-05-16'); - - } // end if; - - } // end setup_api_keys; + } + } /** * Adds additional hooks. @@ -198,8 +186,7 @@ class Base_Stripe_Gateway extends Base_Gateway { */ add_action('init', array($this, 'maybe_redirect_to_portal'), 11); add_action('wp', array($this, 'maybe_redirect_to_portal'), 11); - - } // end hooks; + } /** * Adds Stripe Billing Portal link to the site actions. @@ -216,36 +203,31 @@ class Base_Stripe_Gateway extends Base_Gateway { $gateway_id = wu_replace_dashes($this->id); - if (!wu_get_setting("{$gateway_id}_enable_portal")) { - + if ( ! wu_get_setting("{$gateway_id}_enable_portal")) { return $actions; - - } // end if; + } $payment_gateway = $membership ? $membership->get_gateway() : false; if (wu_get_isset($atts, 'show_change_payment_method') && in_array($payment_gateway, $this->other_ids, true)) { - $s_subscription_id = $membership->get_gateway_subscription_id(); - if (!empty($s_subscription_id)) { - + if ( ! empty($s_subscription_id)) { $actions['change_payment_method'] = array( 'label' => __('Change Payment Method', 'wp-ultimo'), 'icon_classes' => 'dashicons-wu-edit wu-align-middle', - 'href' => add_query_arg(array( - 'wu-stripe-portal' => true, - 'membership' => $membership->get_hash(), - )), + 'href' => add_query_arg( + array( + 'wu-stripe-portal' => true, + 'membership' => $membership->get_hash(), + ) + ), ); - - } // end if; - - } // end if; + } + } return $actions; - - } // end add_site_actions; + } /** * Maybe redirect to the Stripe Billing Portal. @@ -255,35 +237,33 @@ class Base_Stripe_Gateway extends Base_Gateway { */ public function maybe_redirect_to_portal() { - if (!wu_request('wu-stripe-portal')) { - + if ( ! wu_request('wu-stripe-portal')) { return; - - } // end if; + } $membership = WP_Ultimo()->currents->get_membership(); - if (!$membership) { - + if ( ! $membership) { return; - - } // end if; + } $customer = wu_get_current_customer(); - if (!is_super_admin() && (!$customer || $customer->get_id() !== $membership->get_customer_id())) { - + if ( ! is_super_admin() && (! $customer || $customer->get_id() !== $membership->get_customer_id())) { wp_die(__('You are not allowed to modify this membership.', 'wp-ultimo')); - - } // end if; + } $gateway_id = $membership->get_gateway(); $gateway = wu_get_gateway($gateway_id); - $allowed_payment_method_types = apply_filters('wu_stripe_checkout_allowed_payment_method_types', array( - 'card', - ), $gateway); + $allowed_payment_method_types = apply_filters( + 'wu_stripe_checkout_allowed_payment_method_types', + array( + 'card', + ), + $gateway + ); $customer_id = $membership->get_customer_id(); $s_customer_id = $membership->get_gateway_customer_id(); @@ -291,7 +271,6 @@ class Base_Stripe_Gateway extends Base_Gateway { // If customer is not set, get from checkout session if (empty($s_customer_id)) { - $subscription_data = array( 'payment_method_types' => $allowed_payment_method_types, 'mode' => 'setup', @@ -299,53 +278,52 @@ class Base_Stripe_Gateway extends Base_Gateway { 'cancel_url' => wu_get_current_url(), 'billing_address_collection' => 'required', 'client_reference_id' => $customer_id, - 'customer' => $s_customer_id + 'customer' => $s_customer_id, ); $session = Stripe\Checkout\Session::create($subscription_data); $s_customer_id = $session->subscript_ion_data['customer']; - - } // end if; + } $portal_config_id = get_site_option('wu_stripe_portal_config_id'); - if (!$portal_config_id) { - - $portal_config = Stripe\BillingPortal\Configuration::create(array( - 'features' => array( - 'invoice_history' => array( - 'enabled' => true, - ), - 'payment_method_update' => array( - 'enabled' => true, - ), - 'subscription_cancel' => array( - 'enabled' => true, - 'mode' => 'at_period_end', - 'cancellation_reason' => array( + if ( ! $portal_config_id) { + $portal_config = Stripe\BillingPortal\Configuration::create( + array( + 'features' => array( + 'invoice_history' => array( 'enabled' => true, - 'options' => array( - 'too_expensive', - 'missing_features', - 'switched_service', - 'unused', - 'customer_service', - 'too_complex', - 'other', + ), + 'payment_method_update' => array( + 'enabled' => true, + ), + 'subscription_cancel' => array( + 'enabled' => true, + 'mode' => 'at_period_end', + 'cancellation_reason' => array( + 'enabled' => true, + 'options' => array( + 'too_expensive', + 'missing_features', + 'switched_service', + 'unused', + 'customer_service', + 'too_complex', + 'other', + ), ), ), ), - ), - 'business_profile' => array( - 'headline' => __('Manage your membership payment methods.', 'wp-ultimo'), - ), - )); + 'business_profile' => array( + 'headline' => __('Manage your membership payment methods.', 'wp-ultimo'), + ), + ) + ); $portal_config_id = $portal_config->id; update_site_option('wu_stripe_portal_config_id', $portal_config_id); - - } // end if; + } $subscription_data = array( 'return_url' => $return_url, @@ -357,8 +335,7 @@ class Base_Stripe_Gateway extends Base_Gateway { wp_redirect($session->url); exit; - - } // end maybe_redirect_to_portal; + } /** * Allows Gateways to override the gateway title. @@ -372,8 +349,7 @@ class Base_Stripe_Gateway extends Base_Gateway { $gateway_id = wu_replace_dashes($this->id); return wu_get_setting("{$gateway_id}_public_title", __('Credit Card', 'wp-ultimo')); - - } // end get_public_title; + } /** * Adds the Stripe Gateway settings to the settings screen. @@ -385,18 +361,21 @@ class Base_Stripe_Gateway extends Base_Gateway { $gateway_id = wu_replace_dashes($this->id); - wu_register_settings_field('payment-gateways', "{$gateway_id}_enable_portal", array( - 'title' => __('Use Stripe Billing Portal', 'wp-ultimo'), - 'desc' => 'Add a link to the Billing Portal in the site actions widget so your customer can change the payment method used in Stripe (additional charges from Stripe could be applied).', - 'type' => 'toggle', - 'default' => 0, - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => $this->get_id(), - ), - )); - - } // end settings; + wu_register_settings_field( + 'payment-gateways', + "{$gateway_id}_enable_portal", + array( + 'title' => __('Use Stripe Billing Portal', 'wp-ultimo'), + 'desc' => 'Add a link to the Billing Portal in the site actions widget so your customer can change the payment method used in Stripe (additional charges from Stripe could be applied).', + 'type' => 'toggle', + 'default' => 0, + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => $this->get_id(), + ), + ) + ); + } /** * Checks if we already have a webhook listener installed. @@ -407,53 +386,40 @@ class Base_Stripe_Gateway extends Base_Gateway { public function has_webhook_installed() { try { - $webhook_url = $this->get_webhook_listener_url(); $this->setup_api_keys(); - $search_webhook = Stripe\WebhookEndpoint::all(array( - 'limit' => 100, - )); + $search_webhook = Stripe\WebhookEndpoint::all( + array( + 'limit' => 100, + ) + ); $set_webhook_endpoint = false; foreach ($search_webhook as $webhook_endpoint) { - if ($webhook_endpoint->url === $webhook_url) { - return $webhook_endpoint; - - } // end if; - - } // end foreach; - + } + } } catch (\Throwable $e) { - $error_code = $e->getCode(); // WP Error did not handle empty error code if (empty($error_code)) { - if (method_exists($e, 'getHttpStatus')) { - $error_code = $e->getHttpStatus(); - } else { - $error_code = 500; - - } // end if; - - } // end if; + } + } return new \WP_Error($error_code, $e->getMessage()); - - } // end try; + } return false; - - } // end has_webhook_installed; + } /** * Fix stripe settings @@ -471,24 +437,19 @@ class Base_Stripe_Gateway extends Base_Gateway { $active_gateways = (array) wu_get_isset($settings_to_save, 'active_gateways', array()); - if (!in_array($this->get_id(), $active_gateways, true)) { - + if ( ! in_array($this->get_id(), $active_gateways, true)) { return $settings; + } - } // end if; - - if (!isset($settings_to_save["{$id}_sandbox_mode"])) { - - $settings["{$id}_sandbox_mode"] = false; - - } // end if; + if ( ! isset($settings_to_save[ "{$id}_sandbox_mode" ])) { + $settings[ "{$id}_sandbox_mode" ] = false; + } // Unset webhook url to show the get_webhook_listener_url value to customer - unset($settings["{$id}_webhook_listener_explanation"]); + unset($settings[ "{$id}_webhook_listener_explanation" ]); return $settings; - - } // end fix_saving_settings; + } /** * Check stripe API keys @@ -506,91 +467,81 @@ class Base_Stripe_Gateway extends Base_Gateway { $active_gateways = (array) wu_get_isset($settings_to_save, 'active_gateways', array()); - if (!in_array($this->get_id(), $active_gateways, true)) { - + if ( ! in_array($this->get_id(), $active_gateways, true)) { return; + } - } // end if; - - $stripe_mode = (bool) (int) $settings["{$id}_sandbox_mode"] ? 'test' : 'live'; + $stripe_mode = (bool) (int) $settings[ "{$id}_sandbox_mode" ] ? 'test' : 'live'; /* * Checked if the Stripe Settings changed, so we can install webhooks. */ $changed_settings = array( - $settings["{$id}_sandbox_mode"], - $settings["{$id}_{$stripe_mode}_pk_key"], - $settings["{$id}_{$stripe_mode}_sk_key"], + $settings[ "{$id}_sandbox_mode" ], + $settings[ "{$id}_{$stripe_mode}_pk_key" ], + $settings[ "{$id}_{$stripe_mode}_sk_key" ], ); $original_settings = array( - $saved_settings["{$id}_sandbox_mode"], - $saved_settings["{$id}_{$stripe_mode}_pk_key"], - $saved_settings["{$id}_{$stripe_mode}_sk_key"], + $saved_settings[ "{$id}_sandbox_mode" ], + $saved_settings[ "{$id}_{$stripe_mode}_pk_key" ], + $saved_settings[ "{$id}_{$stripe_mode}_sk_key" ], ); if ($changed_settings == $original_settings) { // phpcs:ignore return; - - } // end if; + } try { + Stripe\Stripe::setApiKey($settings[ "{$id}_{$stripe_mode}_sk_key" ]); - Stripe\Stripe::setApiKey($settings["{$id}_{$stripe_mode}_sk_key"]); - - Stripe\Token::create(array( - 'card' => array( - 'number' => '4242424242424242', - 'exp_month' => 7, - 'exp_year' => 2028, - 'cvc' => '314', - ), - )); + Stripe\Token::create( + array( + 'card' => array( + 'number' => '4242424242424242', + 'exp_month' => 7, + 'exp_year' => 2028, + 'cvc' => '314', + ), + ) + ); wu_save_setting("{$id}_{$stripe_mode}_sk_key_status", ''); - } catch (\Throwable $e) { - if (strncmp($e->getMessage(), 'Invalid API Key provided', strlen('Invalid API Key provided')) === 0) { /** * The secret key is invalid; */ $t = "{$id}_{$stripe_mode}_sk_key_status"; wu_save_setting("{$id}_{$stripe_mode}_sk_key_status", __('Invalid API Key provided', 'wp-ultimo')); - - } // end if; - - } // end try; + } + } try { + Stripe\Stripe::setApiKey($settings[ "{$id}_{$stripe_mode}_pk_key" ]); - Stripe\Stripe::setApiKey($settings["{$id}_{$stripe_mode}_pk_key"]); - - Stripe\Token::create(array( - 'card' => array( - 'number' => '4242424242424242', - 'exp_month' => 7, - 'exp_year' => 2028, - 'cvc' => '314', - ), - )); + Stripe\Token::create( + array( + 'card' => array( + 'number' => '4242424242424242', + 'exp_month' => 7, + 'exp_year' => 2028, + 'cvc' => '314', + ), + ) + ); wu_save_setting("{$id}_{$stripe_mode}_pk_key_status", ''); - } catch (\Throwable $e) { - if (strncmp($e->getMessage(), 'Invalid API Key provided', strlen('Invalid API Key provided')) === 0) { /** * The public key is invalid; */ wu_save_setting("{$id}_{$stripe_mode}_pk_key_status", __('Invalid API Key provided', 'wp-ultimo')); - - } // end if; - - } // end try; - - } // end check_keys_status; + } + } + } /** * Installs webhook urls onto Stripe. @@ -614,46 +565,41 @@ class Base_Stripe_Gateway extends Base_Gateway { $active_gateways = (array) wu_get_isset($settings_to_save, 'active_gateways', array()); - if (!in_array($this->get_id(), $active_gateways, true)) { - + if ( ! in_array($this->get_id(), $active_gateways, true)) { return false; - - } // end if; + } /* * Checked if the Stripe Settings changed, so we can install webhooks. */ $changed_settings = array( - $settings["{$id}_sandbox_mode"], - $settings["{$id}_test_pk_key"], - $settings["{$id}_test_sk_key"], - $settings["{$id}_live_pk_key"], - $settings["{$id}_live_sk_key"], + $settings[ "{$id}_sandbox_mode" ], + $settings[ "{$id}_test_pk_key" ], + $settings[ "{$id}_test_sk_key" ], + $settings[ "{$id}_live_pk_key" ], + $settings[ "{$id}_live_sk_key" ], ); $original_settings = array( - $saved_settings["{$id}_sandbox_mode"], - $saved_settings["{$id}_test_pk_key"], - $saved_settings["{$id}_test_sk_key"], - $saved_settings["{$id}_live_pk_key"], - $saved_settings["{$id}_live_sk_key"], + $saved_settings[ "{$id}_sandbox_mode" ], + $saved_settings[ "{$id}_test_pk_key" ], + $saved_settings[ "{$id}_test_sk_key" ], + $saved_settings[ "{$id}_live_pk_key" ], + $saved_settings[ "{$id}_live_sk_key" ], ); if ($changed_settings == $original_settings) { // phpcs:ignore return false; - - } // end if; + } $webhook_url = $this->get_webhook_listener_url(); $existing_webhook = $this->has_webhook_installed(); if (is_wp_error($existing_webhook)) { - return $existing_webhook; - - } // end if; + } $this->setup_api_keys($id); @@ -662,54 +608,45 @@ class Base_Stripe_Gateway extends Base_Gateway { * If already exists, checks for status */ if ($existing_webhook) { - if ($existing_webhook->status === 'disabled') { - - $status = Stripe\WebhookEndpoint::update($existing_webhook->id, array( - 'status' => 'enabled', - )); - - } // end if; + $status = Stripe\WebhookEndpoint::update( + $existing_webhook->id, + array( + 'status' => 'enabled', + ) + ); + } return true; - - } // end if; + } /* * Otherwise, create it. */ - Stripe\WebhookEndpoint::create(array( - 'enabled_events' => array('*'), - 'url' => $webhook_url, - 'description' => 'Added by WP Multisite WaaS. Required to correctly handle changes in subscription status.', - )); + Stripe\WebhookEndpoint::create( + array( + 'enabled_events' => array('*'), + 'url' => $webhook_url, + 'description' => 'Added by WP Multisite WaaS. Required to correctly handle changes in subscription status.', + ) + ); return true; - } catch (\Throwable $e) { - $error_code = $e->getCode(); // WP Error did not handle empty error code if (empty($error_code)) { - if (method_exists($e, 'getHttpStatus')) { - $error_code = $e->getHttpStatus(); - } else { - $error_code = 500; - - } // end if; - - } // end if; + } + } return new \WP_Error($error_code, $e->getMessage()); - - } // end try; - - } // end install_webhook; + } + } /** * Reflects membership changes on the gateway. @@ -727,15 +664,12 @@ class Base_Stripe_Gateway extends Base_Gateway { $gateway_subscription_id = $membership->get_gateway_subscription_id(); if (empty($gateway_subscription_id)) { - return new \WP_Error('wu_stripe_no_subscription_id', __('Error: No gateway subscription ID found for this membership.', 'wp-ultimo')); - - } // end if; + } $this->setup_api_keys(); try { - $subscription = Stripe\Subscription::retrieve($gateway_subscription_id); /** @@ -753,17 +687,14 @@ class Base_Stripe_Gateway extends Base_Gateway { $s_coupon = ''; foreach ($line_items as $line_item) { - if ($line_item->get_total() < 0) { - $credits[] = array( 'amount' => $line_item->get_total(), 'description' => $line_item->get_title(), ); continue; - - } // end if; + } $sub_total = $line_item->get_quantity() * $line_item->get_unit_price(); $discounts = $line_item->calculate_discounts($sub_total); @@ -772,16 +703,13 @@ class Base_Stripe_Gateway extends Base_Gateway { // We will probably never enter here but just in case. if ($discounted_subtotal < 0) { - continue; - - } // end if; + } $tax_behavior = ''; $s_tax_rate = false; - if ($line_item->is_taxable() && !empty($line_item->get_tax_rate())) { - + if ($line_item->is_taxable() && ! empty($line_item->get_tax_rate())) { $tax_behavior = $line_item->get_tax_inclusive() ? 'inclusive' : 'exclusive'; $tax_args = array( @@ -793,8 +721,7 @@ class Base_Stripe_Gateway extends Base_Gateway { ); $s_tax_rate = $this->maybe_create_tax_rate($tax_args); - - } // end if; + } $s_price = $this->maybe_create_price( $line_item->get_title(), @@ -811,34 +738,25 @@ class Base_Stripe_Gateway extends Base_Gateway { ); if ($s_tax_rate) { - $recurring_item['tax_rates'] = array($s_tax_rate); - - } // end if; + } $recurring_items[] = $recurring_item; + } - } // end foreach; - - if (!empty($credits)) { - + if ( ! empty($credits)) { if (count($credits) > 1) { - $credit = array( 'amount' => array_sum(wp_list_pluck($credits, 'amount')), 'description' => __('Amount adjustment based on custom deal.', 'wp-ultimo'), ); - } else { - $credit = $credits[0]; - - } // end if; + } $s_amount = - round($credit['amount'] * wu_stripe_get_currency_multiplier()); if ($s_amount >= 1) { - $currency = strtolower($membership->get_currency()); $coupon_data = array( @@ -850,15 +768,16 @@ class Base_Stripe_Gateway extends Base_Gateway { ); $s_coupon = $this->get_stripe_coupon($coupon_data); - } + } - } // end if; - - $existing_items = array_map(fn($item) => array( - 'id' => $item->id, - 'deleted' => true - ), $subscription->items->data); + $existing_items = array_map( + fn($item) => array( + 'id' => $item->id, + 'deleted' => true, + ), + $subscription->items->data + ); $update_data = array( 'items' => array_merge($recurring_items, $existing_items), @@ -868,22 +787,16 @@ class Base_Stripe_Gateway extends Base_Gateway { $subscription = Stripe\Subscription::update($gateway_subscription_id, $update_data); - if (empty($s_coupon) && !empty($subscription->discount)) { - + if (empty($s_coupon) && ! empty($subscription->discount)) { $stripe = new Stripe\StripeClient($this->secret_key); $stripe->subscriptions->deleteDiscount($gateway_subscription_id); - - } // end if; - + } } catch (\Throwable $e) { - return new \WP_Error('wu_stripe_update_error', $e->getMessage()); - - } // end try; + } return true; - - } // end process_membership_update; + } /** * Run preparations before checkout processing. @@ -904,18 +817,18 @@ class Base_Stripe_Gateway extends Base_Gateway { * @since 2.0.0 * @return void|array */ - public function run_preflight() {} // end run_preflight; - /** - * Get or create Stripe Customer. - * - * @since 2.0.0 - * - * @param integer $customer_id WP Multisite WaaS customer ID. - * @param integer $user_id The WordPress user ID. - * @param integer $stripe_customer_id The Stripe Customer ID. - * @return \Stripe\Customer|\WP_Error - */ - public function get_or_create_customer($customer_id = 0, $user_id = 0, $stripe_customer_id = 0) { + public function run_preflight() {} + /** + * Get or create Stripe Customer. + * + * @since 2.0.0 + * + * @param integer $customer_id WP Multisite WaaS customer ID. + * @param integer $user_id The WordPress user ID. + * @param integer $stripe_customer_id The Stripe Customer ID. + * @return \Stripe\Customer|\WP_Error + */ + public function get_or_create_customer($customer_id = 0, $user_id = 0, $stripe_customer_id = 0) { /* * Sets flag to control if we need * to create a new customer or not. @@ -927,10 +840,8 @@ class Base_Stripe_Gateway extends Base_Gateway { * database for an existing Stripe customer id. */ if (empty($stripe_customer_id)) { - $stripe_customer_id = wu_get_customer_gateway_id($customer_id, array('stripe', 'stripe-checkout')); - - } // end if; + } /** * Ensure the correct api keys are set @@ -944,30 +855,23 @@ class Base_Stripe_Gateway extends Base_Gateway { * stripe customer object. */ if ($stripe_customer_id) { - try { - $stripe_customer = Stripe\Customer::retrieve($stripe_customer_id); /* * If the customer was deleted, we * cannot use it again... */ - if (!isset($stripe_customer->deleted) || !$stripe_customer->deleted) { - + if ( ! isset($stripe_customer->deleted) || ! $stripe_customer->deleted) { $customer_exists = true; - - } // end if; - + } } catch (\Exception $e) { /** * Silence is golden. */ - - } // end try; - - } // end if; + } + } /* * No customer found. @@ -975,7 +879,6 @@ class Base_Stripe_Gateway extends Base_Gateway { * In this scenario, we'll need to create a new one. */ if (empty($customer_exists)) { - try { /* * Pass the name and email to stripe. @@ -995,35 +898,24 @@ class Base_Stripe_Gateway extends Base_Gateway { * Finally, try to create it. */ $stripe_customer = Stripe\Customer::create($customer_args); - } catch (\Exception $e) { - $error_code = $e->getCode(); // WP Error did not handle empty error code if (empty($error_code)) { - if (method_exists($e, 'getHttpStatus')) { - $error_code = $e->getHttpStatus(); - } else { - $error_code = 500; - - } // end if; - - } // end if; + } + } return new \WP_Error($error_code, $e->getMessage()); - - } // end try; - - } // end if; + } + } return $stripe_customer; - - } // end get_or_create_customer; + } /** * Convert our billing address to the format Stripe is expecting. @@ -1043,8 +935,7 @@ class Base_Stripe_Gateway extends Base_Gateway { 'postal_code' => $billing_address->billing_zip_code, 'state' => $billing_address->billing_state, ); - - } // end convert_to_stripe_address; + } /** * Returns an array with customer meta data. @@ -1063,8 +954,7 @@ class Base_Stripe_Gateway extends Base_Gateway { ); return $meta_data; - - } // end get_customer_metadata; + } /** * Process a checkout. @@ -1084,7 +974,7 @@ class Base_Stripe_Gateway extends Base_Gateway { * * @return void */ - public function process_checkout($payment, $membership, $customer, $cart, $type) {} // end process_checkout; + public function process_checkout($payment, $membership, $customer, $cart, $type) {} /** * Create a recurring subscription in Stripe. @@ -1111,8 +1001,7 @@ class Base_Stripe_Gateway extends Base_Gateway { * Process already start at another point (webhook or sync call). */ return false; - - } // end if; + } /** * Set transient to avoid multiple calls. @@ -1130,10 +1019,8 @@ class Base_Stripe_Gateway extends Base_Gateway { * return a WP_Error object. */ if (is_object($stripe_cart) && is_wp_error($stripe_cart)) { - throw new \Exception($stripe_cart->get_error_message()); - - } // end if; + } // Otherwise, use the calculated expiration date of the membership, modified to current time instead of 23:59. $billing_date = $cart->get_billing_start_date(); @@ -1146,10 +1033,8 @@ class Base_Stripe_Gateway extends Base_Gateway { $start_date = $datetime->getTimestamp() - HOUR_IN_SECONDS; // Reduce by 60 seconds to account for inaccurate server times. if (empty($payment_method)) { - throw new \Exception(__('Invalid payment method', 'wp-ultimo')); - - } // end if; + } /* * Subscription arguments for Stripe @@ -1174,14 +1059,10 @@ class Base_Stripe_Gateway extends Base_Gateway { $stripe_max_anchor = $this->get_stripe_max_billing_cycle_anchor($cart->get_duration(), $cart->get_duration_unit(), 'now'); if ($cart->has_trial() || $start_date > $stripe_max_anchor->getTimestamp()) { - $sub_args['trial_end'] = $start_date; - } else { - $sub_args['billing_cycle_anchor'] = $start_date; - - } // end if; + } /* * Sets the billing anchor. @@ -1199,12 +1080,9 @@ class Base_Stripe_Gateway extends Base_Gateway { $s_coupon = $this->get_credit_coupon($cart); if ($s_coupon) { - $sub_args['coupon'] = $s_coupon; - - } // end if; - - } // end if; + } + } /* * Filters the Stripe subscription arguments. @@ -1221,29 +1099,28 @@ class Base_Stripe_Gateway extends Base_Gateway { * * This may not be completely perfect but it's the best way to try to account for any errors. */ - if (!empty($sub_args['trial_end']) && !empty($sub_args['billing_cycle_anchor'])) { + if ( ! empty($sub_args['trial_end']) && ! empty($sub_args['billing_cycle_anchor'])) { /* * If we set an anchor, remove that, because * this means the customer has set their own `trial_end`. */ if ($set_anchor) { - unset($sub_args['billing_cycle_anchor']); - } else { /* * We set a trial, which means the customer * has set their own `billing_cycle_anchor`. */ unset($sub_args['trial_end']); + } + } - } // end if; - - } // end if; - - $sub_options = apply_filters('wu_stripe_create_subscription_options', array( - 'idempotency_key' => wu_stripe_generate_idempotency_key($sub_args), - )); + $sub_options = apply_filters( + 'wu_stripe_create_subscription_options', + array( + 'idempotency_key' => wu_stripe_generate_idempotency_key($sub_args), + ) + ); try { /* @@ -1251,33 +1128,28 @@ class Base_Stripe_Gateway extends Base_Gateway { * on Stripe! */ $subscription = $s_customer->subscriptions->create($sub_args, $sub_options); - } catch (Stripe\Exception\IdempotencyException $exception) { /** * In this case, the subscription is being created by another call. */ return false; - - } // end try; + } // If we have a trial we need to add fees to next invoice. if ($cart->has_trial()) { - $currency = strtolower($cart->get_currency()); - $fees = array_filter($cart->get_line_items_by_type('fee'), fn($fee) => !$fee->is_recurring()); + $fees = array_filter($cart->get_line_items_by_type('fee'), fn($fee) => ! $fee->is_recurring()); $s_fees = array(); foreach ($fees as $fee) { - $amount = $fee->get_quantity() * $fee->get_unit_price(); $tax_behavior = ''; $s_tax_rate = false; - if ($fee->is_taxable() && !empty($fee->get_tax_rate())) { - + if ($fee->is_taxable() && ! empty($fee->get_tax_rate())) { $tax_behavior = $fee->get_tax_inclusive() ? 'inclusive' : 'exclusive'; $tax_args = array( @@ -1289,8 +1161,7 @@ class Base_Stripe_Gateway extends Base_Gateway { ); $s_tax_rate = $this->maybe_create_tax_rate($tax_args); - - } // end if; + } $s_price = $this->maybe_create_price( $fee->get_title(), @@ -1307,17 +1178,13 @@ class Base_Stripe_Gateway extends Base_Gateway { ); if ($s_tax_rate) { - $s_fee['tax_rates'] = array($s_tax_rate); - - } // end if; + } $s_fees[] = $s_fee; + } - } // end foreach; - - if (!empty($s_fees)) { - + if ( ! empty($s_fees)) { $options = array( 'add_invoice_items' => $s_fees, ); @@ -1327,58 +1194,44 @@ class Base_Stripe_Gateway extends Base_Gateway { ); try { - $subscription = Stripe\Subscription::update($subscription->id, $options, $sub_options); - } catch (Stripe\Exception\IdempotencyException $exception) { /** * In this case, the subscription is being updated by another call. */ return false; - - } // end try; - - } // end if; - - } // end if; + } + } + } return $subscription; - - } // end create_recurring_payment; - /** - * Checks if we need to create a pro-rate/credit coupon based on the cart data. - * - * Will return an array with coupon arguments for stripe if - * there is credit to be added and false if not. - * - * @since 2.0.0 - * - * @param \WP_Ultimo\Checkout\Cart $cart The current cart. - * @return string|false - */ - protected function get_credit_coupon($cart) { + } + /** + * Checks if we need to create a pro-rate/credit coupon based on the cart data. + * + * Will return an array with coupon arguments for stripe if + * there is credit to be added and false if not. + * + * @since 2.0.0 + * + * @param \WP_Ultimo\Checkout\Cart $cart The current cart. + * @return string|false + */ + protected function get_credit_coupon($cart) { $amount = 0; foreach ($cart->get_line_items() as $line_item) { - if ($line_item->get_total() < 0) { - $amount += $line_item->get_total(); - - } elseif (!$line_item->should_apply_discount_to_renewals()) { - + } elseif ( ! $line_item->should_apply_discount_to_renewals()) { $amount += - $line_item->get_discount_total(); - - } // end if; - - } // end foreach; + } + } if (empty($amount)) { - return false; - - } // end if; + } $s_amount = - round($amount * wu_stripe_get_currency_multiplier()); $currency = strtolower($cart->get_currency()); @@ -1392,8 +1245,7 @@ class Base_Stripe_Gateway extends Base_Gateway { ); return $this->get_stripe_coupon($coupon_data); - - } // end get_credit_coupon; + } /** * Checks to see if the coupon exists, and if so, returns the ID of @@ -1408,54 +1260,43 @@ class Base_Stripe_Gateway extends Base_Gateway { // First check to see if a coupon exists with this ID. If so, return that. try { - $coupon = Stripe\Coupon::retrieve($coupon_data['id']); - Stripe\Coupon::update($coupon->id, array( - 'name' => $coupon_data['name'], - )); + Stripe\Coupon::update( + $coupon->id, + array( + 'name' => $coupon_data['name'], + ) + ); return $coupon->id; - } catch (\Exception $e) { // silence is golden - - } // end try; + } // Otherwise, create a new plan. try { - $coupon = Stripe\Coupon::create($coupon_data); return $coupon->id; - } catch (\Exception $e) { - $error_code = $e->getCode(); // WP Error did not handle empty error code if (empty($error_code)) { - if (method_exists($e, 'getHttpStatus')) { - $error_code = $e->getHttpStatus(); - } else { - $error_code = 500; - - } // end if; - - } // end if; + } + } wu_log_add('stripe', sprintf('Error creating Stripe coupon. Code: %s; Message: %s', $error_code, $e->getMessage()), LogLevel::ERROR); throw $e; - - } // end try; - - } // end get_stripe_coupon; + } + } /** * Builds the non-recurring list of items to be paid on Stripe. * @@ -1473,22 +1314,18 @@ class Base_Stripe_Gateway extends Base_Gateway { * Skip recurring items */ if ($line_item->is_recurring() && $include_recurring_products === false) { - continue; - - } // end if; + } /* * Skip negative items. * In cases like this, we need to generate a coupon code. */ if ($line_item->get_unit_price() < 0) { - continue; + } - } // end if; - - $cart_items[$line_item->get_id()] = array( + $cart_items[ $line_item->get_id() ] = array( 'name' => $line_item->get_title(), 'quantity' => $line_item->get_quantity(), 'amount' => $line_item->get_unit_price() * wu_stripe_get_currency_multiplier(), @@ -1497,11 +1334,9 @@ class Base_Stripe_Gateway extends Base_Gateway { $description = $line_item->get_description(); - if (!empty($description)) { - - $cart_items[$line_item->get_id()]['description'] = $description; - - } // end if; + if ( ! empty($description)) { + $cart_items[ $line_item->get_id() ]['description'] = $description; + } /* * Now, we handle the taxable status @@ -1510,8 +1345,7 @@ class Base_Stripe_Gateway extends Base_Gateway { * We might need to create tax rates on * Stripe and apply it on the subscription cart. */ - if ($line_item->is_taxable() && !empty($line_item->get_tax_rate())) { - + if ($line_item->is_taxable() && ! empty($line_item->get_tax_rate())) { $tax_args = array( 'country' => $this->membership->get_billing_address()->billing_country, 'tax_rate' => $line_item->get_tax_rate(), @@ -1520,15 +1354,12 @@ class Base_Stripe_Gateway extends Base_Gateway { 'inclusive' => $line_item->get_tax_inclusive(), ); - $cart_items[$line_item->get_id()]['tax_rates'] = array($this->maybe_create_tax_rate($tax_args)); - - } // end if; - - } // end foreach; + $cart_items[ $line_item->get_id() ]['tax_rates'] = array($this->maybe_create_tax_rate($tax_args)); + } + } return array_values($cart_items); - - } // end build_non_recurring_cart; + } /** * Converts the WP Multisite WaaS cart into Stripe Sub arguments. @@ -1551,70 +1382,58 @@ class Base_Stripe_Gateway extends Base_Gateway { $all_products = $cart->get_all_products(); foreach ($cart->get_line_items() as $line_item) { - $product = $line_item->get_product(); - if (!$product) { - + if ( ! $product) { continue; - - } // end if; + } /* * Exclude products that are not recurring. */ - if (!$product->is_recurring()) { - + if ( ! $product->is_recurring()) { continue; - - } // end if; + } $amount = $product->get_amount(); $discount_code = $cart->get_discount_code(); if ($discount_code) { - if ($discount_code->should_apply_to_renewals() && $cart->get_cart_type() !== 'renewal') { - $amount = wu_get_discounted_price($amount, $discount_code->get_value(), $discount_code->get_type(), false); - - } // end if; - - } // end if; + } + } try { /* * We might need to create the plan on Stripe. * Otherwise, we'll get the stripe plan id in here. */ - $plan_id = $this->maybe_create_plan(array( - 'name' => $product->get_name(), - 'price' => $amount, - 'interval' => $product->get_duration_unit(), - 'interval_count' => $product->get_duration(), - )); + $plan_id = $this->maybe_create_plan( + array( + 'name' => $product->get_name(), + 'price' => $amount, + 'interval' => $product->get_duration_unit(), + 'interval_count' => $product->get_duration(), + ) + ); if (is_wp_error($plan_id)) { - return $plan_id; - - } // end if; + } /* * Adds the new plan ID to the subscription cart. */ - $plans[$plan_id] = array( + $plans[ $plan_id ] = array( 'plan' => $plan_id, ); - } catch (\Exception $e) { - $error_message = sprintf('Failed to create subscription for membership #%d. Message: %s', $this->membership->get_id(), $e->getMessage()); return new \WP_Error('plan-creation-failed', $error_message); - - } // end try; + } /* * Now, we handle the taxable status @@ -1623,8 +1442,7 @@ class Base_Stripe_Gateway extends Base_Gateway { * We might need to create tax rates on * Stripe and apply it on the subscription cart. */ - if ($line_item->is_taxable() && !empty($line_item->get_tax_rate())) { - + if ($line_item->is_taxable() && ! empty($line_item->get_tax_rate())) { $tax_args = array( 'country' => $this->membership->get_billing_address()->billing_country, 'tax_rate' => $line_item->get_tax_rate(), @@ -1633,15 +1451,12 @@ class Base_Stripe_Gateway extends Base_Gateway { 'inclusive' => $line_item->get_tax_inclusive(), ); - $plans[$plan_id]['tax_rates'] = array($this->maybe_create_tax_rate($tax_args)); - - } // end if; - - } // end foreach; + $plans[ $plan_id ]['tax_rates'] = array($this->maybe_create_tax_rate($tax_args)); + } + } return $plans; - - } // end build_stripe_cart; + } /** * Converts the Stripe invoice line items into WP Multisite WaaS line items. @@ -1658,19 +1473,14 @@ class Base_Stripe_Gateway extends Base_Gateway { $membership_products = array(); if ($this->membership) { - $m_products = $this->membership->get_all_products(); foreach ($m_products as $array) { - - $membership_products[$array['product']->get_name()] = $array['product']; - - } // end foreach; - - } // end if; + $membership_products[ $array['product']->get_name() ] = $array['product']; + } + } foreach ($invoice_line_items as $s_line_item) { - $currency = strtoupper((string) $s_line_item->currency); $currency_multiplier = wu_stripe_get_currency_multiplier($currency); @@ -1690,10 +1500,8 @@ class Base_Stripe_Gateway extends Base_Gateway { ); if (wu_get_isset($membership_products, $title)) { - $line_item_data['product'] = wu_get_isset($membership_products, $title); - - } // end if; + } $line_item = new Line_Item($line_item_data); @@ -1702,20 +1510,20 @@ class Base_Stripe_Gateway extends Base_Gateway { $total = $s_line_item->amount / $currency_multiplier; // Set this values after generate the line item to bypass the recalculate_totals - $line_item->attributes(array( - 'discount_total' => 0, - 'subtotal' => $subtotal, - 'tax_total' => $tax_total, - 'total' => $total, - )); + $line_item->attributes( + array( + 'discount_total' => 0, + 'subtotal' => $subtotal, + 'tax_total' => $tax_total, + 'total' => $total, + ) + ); $line_items[] = $line_item; - - } // end foreach; + } return $line_items; - - } // end get_ultimo_line_items_from_invoice; + } /** * Saves a payment method to a customer on Stripe. @@ -1731,25 +1539,27 @@ class Base_Stripe_Gateway extends Base_Gateway { $payment_method = false; try { - $payment_method = Stripe\PaymentMethod::retrieve($payment_intent->payment_method); if (empty($payment_method->customer)) { - - $payment_method->attach(array( - 'customer' => $s_customer->id - )); - - } // end if; + $payment_method->attach( + array( + 'customer' => $s_customer->id, + ) + ); + } /* * Update remote payment methods. */ - Stripe\Customer::update($s_customer->id, array( - 'invoice_settings' => array( - 'default_payment_method' => $payment_intent->payment_method, - ), - )); + Stripe\Customer::update( + $s_customer->id, + array( + 'invoice_settings' => array( + 'default_payment_method' => $payment_intent->payment_method, + ), + ) + ); /* * De-dupe payment methods. @@ -1761,38 +1571,31 @@ class Base_Stripe_Gateway extends Base_Gateway { * has each payment method listed once. Hopefully Stripe will handle this automatically * in the future. */ - $customer_payment_methods = Stripe\PaymentMethod::all(array( - 'customer' => $s_customer->id, - 'type' => 'card' - )); - - if (!empty($customer_payment_methods->data)) { + $customer_payment_methods = Stripe\PaymentMethod::all( + array( + 'customer' => $s_customer->id, + 'type' => 'card', + ) + ); + if ( ! empty($customer_payment_methods->data)) { foreach ($customer_payment_methods->data as $existing_method) { /* * Detach if the fingerprint matches but payment method ID is different. */ if ($existing_method->card->fingerprint === $payment_method->card->fingerprint && $existing_method->id !== $payment_method->id) { - $existing_method->detach(); - - } // end if; - - } // end foreach; - - } // end if; - + } + } + } } catch (\Exception $e) { - $error = sprintf('Stripe Gateway: Failed to attach payment method to customer while activating membership #%d. Message: %s', 0, $e->getMessage()); wu_log_add('stripe', $error, LogLevel::ERROR); - - } // end try; + } return $payment_method; - - } // end save_payment_method; + } /** * Maybe cancel old subscriptions. @@ -1817,32 +1620,25 @@ class Base_Stripe_Gateway extends Base_Gateway { foreach ( $subscriptions->data as $subscription ) { // Cancel subscriptions with the RCP metadata present and matching member ID. - if ( !empty( $subscription->metadata ) ) { - + if ( ! empty($subscription->metadata) ) { $customer_id = (int) $subscription->metadata['customer_id']; // Legacy WP Multisite WaaS uses user_id $user_id = (int) $subscription->metadata['user_id']; if ($customer_id === 0 && $user_id === 0) { - continue; - - } // end if; + } if ($customer_id !== $this->customer->get_id() && $user_id !== $this->customer->get_user_id()) { - continue; - - } // end if; + } $membership_id = (int) $subscription->metadata['membership_id']; if ($allow_multiple_membership && $membership_id !== $this->membership->get_id()) { - continue; - - } // end if; + } if ($membership_id === 0 && $customer_id === 0) { /** @@ -1855,41 +1651,28 @@ class Base_Stripe_Gateway extends Base_Gateway { // Check if it is not a ultimo subscription foreach ($subscription->items->data as $item) { - - if ( !empty( $item->plan ) && !empty($item->plan->metadata) && isset($item->plan->metadata['plan_id'])) { - + if ( ! empty($item->plan) && ! empty($item->plan->metadata) && isset($item->plan->metadata['plan_id'])) { if ( wu_get_product_by('migrated_from_id', $item->plan->metadata['plan_id']) ) { - $stop_here = false; break; - - } // end if; - - } // end if; - - } // end foreach; + } + } + } if ($stop_here) { - continue; - - } // end if; - - } // end if; + } + } // Check if membership exist and is from this customer before delete subscription if ($membership_id !== 0 && $membership_id !== $this->membership->get_id()) { - $membership_from_s = wu_get_membership($membership_id); - if (!$membership_from_s || $membership_from_s->get_customer_id() !== $customer_id) { - + if ( ! $membership_from_s || $membership_from_s->get_customer_id() !== $customer_id) { continue; - - } // end if; - - } // end if; + } + } $subscription->cancel(); @@ -1898,18 +1681,12 @@ class Base_Stripe_Gateway extends Base_Gateway { wu_log_add('stripe', sprintf('Stripe Gateway: Cancelled Stripe subscription %s.', $subscription->id)); continue; - - } // end if; - - } // end foreach; - + } + } } catch ( \Exception $e ) { - - wu_log_add('stripe', sprintf( 'Stripe Gateway: Subscription cleanup failed for customer #%d. Message: %s', $this->customer->get_id(), $e->getMessage()), LogLevel::ERROR); - - } // end try; - - } // end maybe_cancel_old_subscriptions; + wu_log_add('stripe', sprintf('Stripe Gateway: Subscription cleanup failed for customer #%d. Message: %s', $this->customer->get_id(), $e->getMessage()), LogLevel::ERROR); + } + } /** * Process a refund. @@ -1930,10 +1707,8 @@ class Base_Stripe_Gateway extends Base_Gateway { $gateway_payment_id = $payment->get_gateway_payment_id(); if (empty($gateway_payment_id)) { - throw new \Exception(__('Gateway payment ID not found. Cannot process refund automatically.', 'wp-ultimo')); - - } // end if; + } /** * Ensure the correct api keys are set @@ -1945,20 +1720,14 @@ class Base_Stripe_Gateway extends Base_Gateway { * or a charge at hand. */ if (strncmp((string) $gateway_payment_id, 'ch_', strlen('ch_')) === 0) { - $charge_id = $gateway_payment_id; - } elseif (strncmp((string) $gateway_payment_id, 'in_', strlen('in_')) === 0) { - $invoice = Stripe\Invoice::retrieve($gateway_payment_id); $gateway_payment_id = $invoice->charge; - } else { - throw new Exception(__('Gateway payment ID not valid.', 'wp-ultimo')); - - } // end if; + } /* * We need to normalize the value @@ -1967,10 +1736,12 @@ class Base_Stripe_Gateway extends Base_Gateway { */ $normalize_amount = $amount * wu_stripe_get_currency_multiplier(); - Stripe\Refund::create(array( - 'charge' => $charge_id, - 'amount' => $normalize_amount, - )); + Stripe\Refund::create( + array( + 'charge' => $charge_id, + 'amount' => $normalize_amount, + ) + ); /* * You might be asking why we are not @@ -1981,8 +1752,7 @@ class Base_Stripe_Gateway extends Base_Gateway { * that the refund was successful. */ return true; - - } // end process_refund; + } /** * Process a cancellation. @@ -2000,33 +1770,25 @@ class Base_Stripe_Gateway extends Base_Gateway { $subscription_id = $membership->get_gateway_subscription_id(); - if (!empty($subscription_id)) { + if ( ! empty($subscription_id)) { /** * Ensure the correct api keys are set */ $this->setup_api_keys(); try { - $subscription = Stripe\Subscription::retrieve($subscription_id); if ($subscription->status !== 'canceled') { - $subscription->cancel(); - - } // end if; - + } } catch (\Exception $e) { - wu_log_add('stripe', sprintf('Stripe Gateway: Failed to cancel subscription %s. Message: %s', $subscription_id, $e->getMessage()), LogLevel::ERROR); return false; - - } // end try; - - } // end if; - - } // end process_cancellation; + } + } + } /** * Attempt to guess the maximum `billing_cycle_anchor` Stripe will allow us to set, given a signup date @@ -2043,14 +1805,10 @@ class Base_Stripe_Gateway extends Base_Gateway { public function get_stripe_max_billing_cycle_anchor($interval, $interval_unit, $signup_date = 'now') { try { - $signup_date = new \DateTimeImmutable($signup_date); - } catch (Exception $exception) { - $signup_date = new \DateTimeImmutable(); - - } // end try; + } $stripe_max_anchor = $signup_date->modify(sprintf('+%d %s', $interval, $interval_unit)); @@ -2071,20 +1829,15 @@ class Base_Stripe_Gateway extends Base_Gateway { if (date('j', $signup_date->getTimestamp()) > date('t', $proposed_next_bill_date->getTimestamp())) { // phpcs:ignore try { - $stripe_max_anchor = new \DateTime(date('Y-m-t H:i:s', $proposed_next_bill_date->getTimestamp())); // phpcs:ignore - } catch (\Exception $exception) { // Silence is golden - - } // end try; - - } // end if; + } + } return $stripe_max_anchor; - - } // end get_stripe_max_billing_cycle_anchor; + } /** * Get Stripe error from exception @@ -2101,21 +1854,16 @@ class Base_Stripe_Gateway extends Base_Gateway { $wp_error = new \WP_Error(); if (method_exists($e, 'getJsonBody')) { - $body = $e->getJsonBody(); $error = $body['error']; $wp_error->add($error['code'], $this->get_localized_error_message($error['code'], $e->getMessage())); - } else { - $wp_error->add('unknown_error', __('An unknown error has occurred.', 'wp-ultimo')); - - } // end if; + } return $wp_error; - - } // end get_stripe_error; + } /** * Localize common Stripe error messages so they're available for translation. @@ -2133,18 +1881,14 @@ class Base_Stripe_Gateway extends Base_Gateway { $errors = wu_stripe_get_localized_error_messages(); - if (!empty($errors[$error_code])) { - - return $errors[$error_code]; - + if ( ! empty($errors[ $error_code ])) { + return $errors[ $error_code ]; } else { // translators: 1 is the error code and 2 the message. return sprintf(__('An error has occurred (code: %1$s; message: %2$s).', 'wp-ultimo'), $error_code, $error_message); - - } // end if; - - } // end get_localized_error_message; + } + } /** * Gives gateways a chance to run things before backwards compatible webhooks are run. @@ -2155,7 +1899,6 @@ class Base_Stripe_Gateway extends Base_Gateway { public function before_backwards_compatible_webhook() { if (empty($this->secret_key)) { - $other_id = $this->get_id() === 'stripe' ? 'stripe-checkout' : 'stripe'; /* @@ -2164,10 +1907,8 @@ class Base_Stripe_Gateway extends Base_Gateway { * or vice-versa. */ $this->setup_api_keys($other_id); - - } // end if; - - } // end before_backwards_compatible_webhook; + } + } /** * Process webhooks @@ -2186,18 +1927,14 @@ class Base_Stripe_Gateway extends Base_Gateway { $received_event = wu_get_input(); // for extra security, retrieve from the Stripe API - if (!isset($received_event->id)) { - + if ( ! isset($received_event->id)) { throw new \Exception(__('Event ID not found.', 'wp-ultimo')); - - } // end if; + } // Set the right mode for this request - if (isset($received_event->livemode) && !$received_event->livemode !== $this->test_mode) { - - $this->test_mode = !$received_event->livemode; - - } // end if; + if (isset($received_event->livemode) && ! $received_event->livemode !== $this->test_mode) { + $this->test_mode = ! $received_event->livemode; + } /** * Ensure the correct api keys are set @@ -2219,69 +1956,53 @@ class Base_Stripe_Gateway extends Base_Gateway { * Check if we have a customer present. */ if (empty($payment_event->customer)) { - return; - - } // end if; + } /* * Try to get an invoice object from the payment event. */ - if (!empty($payment_event->object) && 'invoice' === $payment_event->object) { - + if ( ! empty($payment_event->object) && 'invoice' === $payment_event->object) { $invoice = $payment_event; - - } elseif (!empty($payment_event->invoice)) { - + } elseif ( ! empty($payment_event->invoice)) { $invoice = Stripe\Invoice::retrieve($payment_event->invoice); - - } // end if; + } /* * Now try to get a subscription from the invoice object. */ - if (!empty($invoice->subscription)) { - + if ( ! empty($invoice->subscription)) { $subscription = Stripe\Subscription::retrieve($invoice->subscription); - - } // end if; + } /* * We can also get the subscription by the * object ID in some circumstances. */ if (empty($subscription) && strpos((string) $payment_event->id, 'sub_') !== false) { - $subscription = Stripe\Subscription::retrieve($payment_event->id); - - } // end if; + } /* * Retrieve the membership by subscription ID. */ - if (!empty($subscription)) { - + if ( ! empty($subscription)) { $membership = wu_get_membership_by('gateway_subscription_id', $subscription->id); - - } // end if; + } // Retrieve the membership by payment meta (one-time charges only). - if (!empty($payment_event->metadata->membership_id)) { - + if ( ! empty($payment_event->metadata->membership_id)) { $membership = wu_get_membership($payment_event->metadata->membership_id); - - } // end if; + } /** * Last ditch effort to retrieve a valid membership. */ - if (empty($membership) && !empty($invoice)) { - + if (empty($membership) && ! empty($invoice)) { $amount = $invoice->amount_paid / wu_stripe_get_currency_multiplier(); $membership = wu_get_membership_by_customer_gateway_id($payment_event->customer, array('stripe', 'stripe-checkout'), $amount); - - } // end if; + } /** * Filters the membership record associated with this webhook. @@ -2296,14 +2017,13 @@ class Base_Stripe_Gateway extends Base_Gateway { $this->membership = $membership; - if (!is_a($membership, '\WP_Ultimo\Models\Membership')) { + if ( ! is_a($membership, '\WP_Ultimo\Models\Membership')) { /** * If we don't have a membership, we can't do anything * and this is not an error. */ return; - - } // end if; + } /** * Ensure the membership is using the current gateway @@ -2312,8 +2032,7 @@ class Base_Stripe_Gateway extends Base_Gateway { // translators: %s is the customer ID. throw new Ignorable_Exception(sprintf(__('Exiting Stripe webhook - This call must be handled by %s webhook', 'wp-ultimo'), $membership->get_gateway())); - - } // end if; + } /* * Set the WP Multisite WaaS customer. @@ -2336,10 +2055,8 @@ class Base_Stripe_Gateway extends Base_Gateway { * First, we'll start customer subscription created. */ if ($event->type === 'customer.subscription.created') { - do_action('wu_webhook_recurring_payment_profile_created', $membership, $this); - - } // end if; + } /* * Deal with Stripe Checkouts case. @@ -2348,7 +2065,6 @@ class Base_Stripe_Gateway extends Base_Gateway { * the webhook call to change the status of things. */ if ($event->type === 'checkout.session.completed') { - $membership->set_gateway_customer_id($payment_event->customer); $membership->set_gateway_subscription_id($payment_event->subscription); @@ -2358,8 +2074,7 @@ class Base_Stripe_Gateway extends Base_Gateway { $membership->save(); return true; - - } // end if; + } /* * Next, let's deal with charges that went through! @@ -2382,29 +2097,23 @@ class Base_Stripe_Gateway extends Base_Gateway { * Successful one-time payment */ if (empty($payment_event->invoice)) { - $payment_data['total'] = $payment_event->amount / wu_stripe_get_currency_multiplier(); $payment_data['gateway_payment_id'] = $payment_event->id; - /* - * Subscription payment received. - */ + /* + * Subscription payment received. + */ } else { - $payment_data['total'] = $invoice->total / wu_stripe_get_currency_multiplier(); $payment_data['subtotal'] = ($invoice->total_excluding_tax / wu_stripe_get_currency_multiplier()) - $payment_data['discount_total']; $payment_data['tax_total'] = $invoice->tax / wu_stripe_get_currency_multiplier(); $payment_data['gateway_payment_id'] = $payment_event->id; - if (!empty($payment_event->discount)) { - + if ( ! empty($payment_event->discount)) { $payment_data['discount_code'] = $payment_event->discount->coupon_id; - - } // end if; - - } // end if; - - } // end if; + } + } + } /* * Let's check if we have the payment @@ -2420,12 +2129,11 @@ class Base_Stripe_Gateway extends Base_Gateway { /* * Payment does not exist. */ - if (!empty($gateway_payment_id) && !$payment) { + if ( ! empty($gateway_payment_id) && ! $payment) { /* * Checks if we have the data about a subscription. */ - if (!empty($subscription)) { - + if ( ! empty($subscription)) { $membership->set_recurring(true); $membership->set_gateway_subscription_id($subscription->id); @@ -2449,31 +2157,27 @@ class Base_Stripe_Gateway extends Base_Gateway { $stripe_estimated_charge_timestamp = $subscription->current_period_end + (2 * HOUR_IN_SECONDS); if ($stripe_estimated_charge_timestamp > $renewal_date->getTimestamp()) { - $renewal_date->setTimestamp($stripe_estimated_charge_timestamp); - - } // end if; + } /* * Set the expiration. */ $expiration = $renewal_date->format('Y-m-d H:i:s'); - - } // end if; + } /* * Checks for a pending payment on the membership. */ $pending_payment = $membership->get_last_pending_payment(); - if (!empty($pending_payment)) { + if ( ! empty($pending_payment)) { /* * Completing a pending payment. */ $pending_payment->attributes($payment_data); $payment = $pending_payment; - } elseif ($event->type === 'charge.succeeded') { /** * These must be retrieved after the status @@ -2484,10 +2188,8 @@ class Base_Stripe_Gateway extends Base_Gateway { $line_items = $this->get_ultimo_line_items_from_invoice($invoice->lines->data); // If we have a tax_total let's add it to line items. - if (!empty($payment_data['tax_total'])) { - + if ( ! empty($payment_data['tax_total'])) { foreach ($line_items as &$line_item) { - $current_total = $line_item->get_total(); $percent_of_subtotal = $current_total / $payment_data['subtotal']; @@ -2498,10 +2200,8 @@ class Base_Stripe_Gateway extends Base_Gateway { $line_item->set_tax_total($item_tax_total); $line_item->set_tax_rate($item_tax_rate); $line_item->set_total($item_total); - - } // end foreach; - - } // end if; + } + } /* * As we add the discount code value into plan price we need @@ -2510,56 +2210,45 @@ class Base_Stripe_Gateway extends Base_Gateway { $discount_code = $membership->get_discount_code(); if ($discount_code && $discount_code->should_apply_to_renewals()) { - $type = $discount_code->get_type(); $old_subtotal = $payment_data['subtotal']; if ($type === 'percentage') { - $payment_data['subtotal'] = $old_subtotal / (1 - ($discount_code->get_value() / 100)); $discount_total = $payment_data['subtotal'] - $old_subtotal; - } elseif ($type === 'absolute') { - $discount_total = $discount_code->get_value(); $payment_data['subtotal'] = $payment_data['subtotal'] - $discount_total; - - } // end if; + } // Now we apply this discount to the line items. foreach ($line_items as &$line_item) { - $current_item_subtotal = $line_item->get_subtotal(); $percent_of_subtotal = $current_item_subtotal / $old_subtotal; $line_item->set_discount_total($discount_total * $percent_of_subtotal); $line_item->set_subtotal($line_item->get_discount_total() + $current_item_subtotal); - - } // end foreach; - - } // end if; + } + } $payment_data['transaction_type'] = 'renewal'; $payment_data['customer_id'] = $customer->get_id(); $payment_data['membership_id'] = $membership->get_id(); $payment_data['line_items'] = $line_items; $payment = wu_create_payment($payment_data); - } else { /** * We do not have a payment to change */ return true; - - } // end if; + } $this->payment = $payment; - if ($payment_event->object === 'charge' && !$subscription && $this->get_id() === 'stripe') { - + if ($payment_event->object === 'charge' && ! $subscription && $this->get_id() === 'stripe') { $cart = $payment->get_meta('wu_original_cart'); $payment_intent_id = (string) $payment->get_meta('stripe_payment_intent_id'); @@ -2567,8 +2256,7 @@ class Base_Stripe_Gateway extends Base_Gateway { // We handle setup intents from process_checkout. $is_setup_intent = strncmp($payment_intent_id, 'seti_', strlen('seti_')) === 0; - if ($cart && $cart->should_auto_renew() && $cart->has_recurring() && !$is_setup_intent) { - + if ($cart && $cart->should_auto_renew() && $cart->has_recurring() && ! $is_setup_intent) { $s_customer = Stripe\Customer::retrieve($payment_event->customer); $payment_method = Stripe\PaymentMethod::retrieve($payment_event->payment_method); @@ -2576,7 +2264,6 @@ class Base_Stripe_Gateway extends Base_Gateway { // If we receive a subscription, we need to update the membership. if ($subscription) { - $membership->set_gateway_subscription_id($subscription->id); $renewal_date = new \DateTime(); @@ -2586,22 +2273,15 @@ class Base_Stripe_Gateway extends Base_Gateway { $stripe_estimated_charge_timestamp = $subscription->current_period_end + (2 * HOUR_IN_SECONDS); if ($stripe_estimated_charge_timestamp > $renewal_date->getTimestamp()) { - $renewal_date->setTimestamp($stripe_estimated_charge_timestamp); - - } // end if; + } $expiration = $renewal_date->format('Y-m-d H:i:s'); - } else { - return true; - - } // end if; - - } // end if; - - } // end if; + } + } + } /** * Renewals the membership @@ -2622,8 +2302,7 @@ class Base_Stripe_Gateway extends Base_Gateway { $this->trigger_payment_processed($payment, $membership); return true; - - } elseif (!empty($gateway_payment_id) && $payment) { + } elseif ( ! empty($gateway_payment_id) && $payment) { /* * The payment already exists. * @@ -2631,16 +2310,13 @@ class Base_Stripe_Gateway extends Base_Gateway { * we have a duplicate payment. */ throw new Ignorable_Exception(__('Duplicate payment.', 'wp-ultimo')); - - } // end if; - - } // end if; + } + } /* * Next, let's deal with charges that went through! */ if ($event->type === 'charge.refunded') { - $payment_data = array( 'gateway' => 'stripe', ); @@ -2650,18 +2326,14 @@ class Base_Stripe_Gateway extends Base_Gateway { $payment = wu_get_payment($payment_id); if (empty($payment)) { - throw new Ignorable_Exception(__('Payment not found on refund webhook call.', 'wp-ultimo')); - - } // end if; + } $is_refundable = in_array($payment->get_status(), wu_get_refundable_payment_types(), true); - if (!$is_refundable) { - + if ( ! $is_refundable) { throw new Ignorable_Exception(__('Payment is not refundable.', 'wp-ultimo')); - - } // end if; + } /* * Let's address the type. @@ -2675,34 +2347,28 @@ class Base_Stripe_Gateway extends Base_Gateway { $status = $payment->refund($amount); return $status; - - } // end if; + } /* * Failed payments. */ if ($event->type === 'invoice.payment_failed') { - $this->webhook_event_id = $event->id; // Make sure this invoice is tied to a subscription and is the user's current subscription. - if (!empty($event->data->object->subscription) && $event->data->object->subscription === $membership->get_gateway_subscription_id()) { - + if ( ! empty($event->data->object->subscription) && $event->data->object->subscription === $membership->get_gateway_subscription_id()) { do_action('wu_recurring_payment_failed', $membership, $this); - - } // end if; + } do_action('wu_stripe_charge_failed', $payment_event, $event, $membership); return true; - - } // end if; + } /* * Cancelled / failed subscription. */ if ($event->type === 'customer.subscription.deleted') { - wu_log_add('stripe', 'Processing Stripe customer.subscription.deleted webhook.'); if ($payment_event->id === $membership->get_gateway_subscription_id()) { @@ -2710,35 +2376,24 @@ class Base_Stripe_Gateway extends Base_Gateway { * If this is a completed payment plan, * we can skip any cancellation actions. */ - if (!$membership->is_forever_recurring() && $membership->at_maximum_renewals()) { - + if ( ! $membership->is_forever_recurring() && $membership->at_maximum_renewals()) { return; - - } // end if; + } if ($membership->is_active()) { - $membership->cancel(); $membership->add_note(__('Membership cancelled via Stripe webhook.', 'wp-ultimo')); - } else { - wu_log_add('stripe', sprintf('Membership #%d is not active - not cancelling account.', $membership->get_id())); - - } // end if; + } return true; - } else { - wu_log_add('stripe', sprintf('Payment event ID (%s) doesn\'t match membership\'s merchant subscription ID (%s).', $payment_event->id, $membership->get_gateway_subscription_id()), true); - - } // end if; - - } // end if; - - } // end process_webhooks; + } + } + } /** * Get saved card options for this customers. @@ -2748,11 +2403,9 @@ class Base_Stripe_Gateway extends Base_Gateway { */ public function get_saved_card_options() { - if (!is_user_logged_in()) { - + if ( ! is_user_logged_in()) { return array(); - - } // end if; + } $options = array(); @@ -2761,19 +2414,16 @@ class Base_Stripe_Gateway extends Base_Gateway { $saved_payment_methods = $this->get_user_saved_payment_methods($user_id); foreach ($saved_payment_methods as $saved_payment_method) { - - $options[$saved_payment_method->id] = sprintf( + $options[ $saved_payment_method->id ] = sprintf( // translators: 1 is the card brand (e.g. VISA), and 2 is the last 4 digits. __('%1$s ending in %2$s', 'wp-ultimo'), strtoupper((string) $saved_payment_method->card->brand), $saved_payment_method->card->last4 ); - - } // end foreach; + } return $options; - - } // end get_saved_card_options; + } /** * Add credit card fields. * @@ -2782,8 +2432,7 @@ class Base_Stripe_Gateway extends Base_Gateway { public function fields(): string { return ''; - - } // end fields; + } /** * Load fields for the Update Billing Card form. @@ -2813,8 +2462,7 @@ class Base_Stripe_Gateway extends Base_Gateway {
    publishable_key) || !in_array($this->get_id(), $active_gateways, true)) { - + if (empty($this->publishable_key) || ! in_array($this->get_id(), $active_gateways, true)) { return; - - } // end if; + } wp_register_script('wu-stripe-sdk', 'https://js.stripe.com/v3/', false, 'v3'); @@ -2840,16 +2486,19 @@ class Base_Stripe_Gateway extends Base_Gateway { $obj_name = 'wu_' . str_replace('-', '_', (string) $this->get_id()); - wp_localize_script("wu-{$this->get_id()}", $obj_name, array( - 'pk_key' => $this->publishable_key, - 'request_billing_address' => $this->request_billing_address, - 'add_new_card' => empty($saved_cards), - 'payment_method' => empty($saved_cards) ? 'add-new' : current(array_keys($saved_cards)), - )); + wp_localize_script( + "wu-{$this->get_id()}", + $obj_name, + array( + 'pk_key' => $this->publishable_key, + 'request_billing_address' => $this->request_billing_address, + 'add_new_card' => empty($saved_cards), + 'payment_method' => empty($saved_cards) ? 'add-new' : current(array_keys($saved_cards)), + ) + ); wp_enqueue_script("wu-{$this->get_id()}"); - - } // end register_scripts; + } /** * Maybe create a new tax rate on Stripe @@ -2864,32 +2513,24 @@ class Base_Stripe_Gateway extends Base_Gateway { $slug = strtolower(sprintf('%s-%s-%s', $args['country'], $args['tax_rate'], $args['type'])); if (wu_get_isset($args, 'inclusive')) { - $slug .= '-inclusive'; - - } // end if; + } static $cache = array(); if (wu_get_isset($cache, $slug)) { - return wu_get_isset($cache, $slug); - - } // end if; + } $stripe_tax_rates = Stripe\TaxRate::all(); foreach ($stripe_tax_rates as $stripe_tax_rate) { - if (isset($stripe_tax_rate->metadata->tax_rate_id) && $stripe_tax_rate->metadata->tax_rate_id === $slug) { - - $cache[$slug] = $stripe_tax_rate->id; + $cache[ $slug ] = $stripe_tax_rate->id; return $stripe_tax_rate->id; - - } // end if; - - } // end foreach; + } + } $args = array( 'display_name' => $args['title'], @@ -2903,19 +2544,15 @@ class Base_Stripe_Gateway extends Base_Gateway { ); try { - $tax_rate = Stripe\TaxRate::create($args); return $tax_rate->id; - } catch (Exception $exception) { // Silence is golden. return ''; - - } // end try; - - } // end maybe_create_tax_rate; + } + } /** * Checks to see if a plan exists with the provided arguments, and if so, returns the ID of @@ -2941,21 +2578,22 @@ class Base_Stripe_Gateway extends Base_Gateway { */ public function maybe_create_plan($args) { - $args = wp_parse_args($args, array( - 'name' => '', - 'price' => 0.00, - 'interval' => 'month', - 'interval_count' => 1, - 'currency' => strtolower((string) wu_get_setting('currency_symbol', 'USD')), - 'id' => '', - )); + $args = wp_parse_args( + $args, + array( + 'name' => '', + 'price' => 0.00, + 'interval' => 'month', + 'interval_count' => 1, + 'currency' => strtolower((string) wu_get_setting('currency_symbol', 'USD')), + 'id' => '', + ) + ); // Name and price are required. if (empty($args['name']) || empty($args['price'])) { - return new \WP_Error('missing_name_price', __('Missing plan name or price.', 'wp-ultimo')); - - } // end if; + } /* * Create a new object that looks like a membership level object. @@ -2963,7 +2601,6 @@ class Base_Stripe_Gateway extends Base_Gateway { * don't actually have one. */ if (empty($args['id'])) { - $plan_level = new \stdClass(); $plan_level->name = $args['name']; $plan_level->price = $args['price']; @@ -2971,25 +2608,19 @@ class Base_Stripe_Gateway extends Base_Gateway { $plan_level->duration_unit = $args['interval']; $plan_level->currency = $args['currency']; $plan_id = $this->generate_plan_id($plan_level); - } else { - $plan_id = $args['id']; - - } // end if; + } if (empty($plan_id)) { - return new \WP_Error('empty_plan_id', __('Empty plan ID.', 'wp-ultimo')); - - } // end if; + } // Convert price to Stripe format. $price = round($args['price'] * wu_stripe_get_currency_multiplier(), 0); // First check to see if a plan exists with this ID. If so, return that. try { - $membership_level = isset($plan_level) ? $plan_level : new \stdClass(); /** @@ -3004,59 +2635,50 @@ class Base_Stripe_Gateway extends Base_Gateway { $plan = Stripe\Plan::retrieve($existing_plan_id); return $plan->id; - } catch (\Exception $e) { // silence is golden - - } // end try; + } // Otherwise, create a new plan. try { + $product = Stripe\Product::create( + array( + 'name' => $args['name'] . ' - ' . $args['currency'], + 'type' => 'service', + ) + ); - $product = Stripe\Product::create(array( - 'name' => $args['name'] . ' - ' . $args['currency'], - 'type' => 'service' - ) ); - - $plan = Stripe\Plan::create(array( - 'amount' => $price, - 'interval' => $args['interval'], - 'interval_count' => $args['interval_count'], - 'currency' => $args['currency'], - 'id' => $plan_id, - 'product' => $product->id - ) ); + $plan = Stripe\Plan::create( + array( + 'amount' => $price, + 'interval' => $args['interval'], + 'interval_count' => $args['interval_count'], + 'currency' => $args['currency'], + 'id' => $plan_id, + 'product' => $product->id, + ) + ); // plan successfully created return $plan->id; - } catch (\Exception $e) { - $error_code = $e->getCode(); // WP Error did not handle empty error code if (empty($error_code)) { - if (method_exists($e, 'getHttpStatus')) { - $error_code = $e->getHttpStatus(); - } else { - $error_code = 500; - - } // end if; - - } // end if; + } + } wu_log_add('stripe', sprintf('Error creating Stripe plan. Code: %s; Message: %s', $error_code, $e->getMessage()), LogLevel::ERROR); return new \WP_Error('stripe_exception', sprintf('Error creating Stripe plan. Code: %s; Message: %s', $error_code, $e->getMessage())); - - } // end try; - - } // end maybe_create_plan; + } + } /** * Checks to see if a product exists with the provided arguments, and if so, returns the ID of @@ -3072,28 +2694,20 @@ class Base_Stripe_Gateway extends Base_Gateway { // Name are required. if (empty($name)) { - return new \WP_Error('missing_name', __('Missing product name.', 'wp-ultimo')); - - } // end if; + } if (empty($id)) { - $product_id = strtolower(str_replace(' ', '', sanitize_title_with_dashes($name))); $product_id = sprintf('wu-%s', $product_id); $product_id = preg_replace('/[^a-z0-9_\-]/', '-', $product_id); - } else { - $product_id = $id; - - } // end if; + } if (empty($product_id)) { - return new \WP_Error('empty_product_id', __('Empty product ID.', 'wp-ultimo')); - - } // end if; + } // First check to see if a product exists with this ID. If so, return that. try { @@ -3109,50 +2723,39 @@ class Base_Stripe_Gateway extends Base_Gateway { $product = Stripe\Product::retrieve($existing_product_id); return $product->id; - } catch (\Exception $e) { // silence is golden - - } // end try; + } // Otherwise, create a new product. try { - - $product = Stripe\Product::create(array( - 'id' => $product_id, - 'name' => $name, - )); + $product = Stripe\Product::create( + array( + 'id' => $product_id, + 'name' => $name, + ) + ); // product successfully created return $product->id; - } catch (\Exception $e) { - $error_code = $e->getCode(); // WP Error did not handle empty error code if (empty($error_code)) { - if (method_exists($e, 'getHttpStatus')) { - $error_code = $e->getHttpStatus(); - } else { - $error_code = 500; - - } // end if; - - } // end if; + } + } wu_log_add('stripe', sprintf('Error creating Stripe product. Code: %s; Message: %s', $error_code, $e->getMessage()), LogLevel::ERROR); return new \WP_Error('stripe_exception', sprintf('Error creating Stripe product. Code: %s; Message: %s', $error_code, $e->getMessage())); - - } // end try; - - } // end maybe_create_product; + } + } /** * Checks to see if a price exists with the provided arguments, @@ -3185,40 +2788,35 @@ class Base_Stripe_Gateway extends Base_Gateway { ); if ($duration && $duration_unit) { - $s_price_data['recurring'] = array( 'interval' => $duration_unit, 'interval_count' => $duration, ); $s_price_data['lookup_key'] .= "-$duration-$duration_unit"; + } - } // end if; - - if (!empty($tax_behavior)) { - + if ( ! empty($tax_behavior)) { $s_price_data['tax_behavior'] = $tax_behavior; $s_price_data['lookup_key'] .= "-$tax_behavior"; - - } // end if; + } // check if price already exists - $existing = Stripe\Price::all(array( - 'lookup_keys' => array($s_price_data['lookup_key']), - 'limit' => 1, - )); - - if (!empty($existing->data)) { + $existing = Stripe\Price::all( + array( + 'lookup_keys' => array($s_price_data['lookup_key']), + 'limit' => 1, + ) + ); + if ( ! empty($existing->data)) { return $existing->data[0]->id; - - } // end if; + } $s_price = Stripe\Price::create($s_price_data); return $s_price->id; - - } // end maybe_create_price; + } /** * Generate a Stripe plan ID string based on a membership level @@ -3241,8 +2839,7 @@ class Base_Stripe_Gateway extends Base_Gateway { $plan_id = preg_replace('/[^a-z0-9_\-]/', '-', $plan_id); return $plan_id; - - } // end generate_plan_id; + } /** * Get the saved Stripe payment methods for a given user ID. @@ -3257,11 +2854,9 @@ class Base_Stripe_Gateway extends Base_Gateway { $customer = wu_get_current_customer(); - if (!$customer) { - + if ( ! $customer) { return array(); - - } // end if; + } $customer_id = $customer->get_id(); @@ -3276,44 +2871,40 @@ class Base_Stripe_Gateway extends Base_Gateway { */ static $existing_payment_methods; - if (!is_null($existing_payment_methods) && array_key_exists($customer_id, $existing_payment_methods)) { - - return $existing_payment_methods[$customer_id]; - - } // end if; + if ( ! is_null($existing_payment_methods) && array_key_exists($customer_id, $existing_payment_methods)) { + return $existing_payment_methods[ $customer_id ]; + } $customer_payment_methods = array(); - $stripe_customer_id = \WP_Ultimo\Models\Membership::query(array( - 'customer_id' => $customer_id, - 'search' => 'cus_*', - 'fields' => array('gateway_customer_id'), - )); + $stripe_customer_id = \WP_Ultimo\Models\Membership::query( + array( + 'customer_id' => $customer_id, + 'search' => 'cus_*', + 'fields' => array('gateway_customer_id'), + ) + ); $stripe_customer_id = current(array_column($stripe_customer_id, 'gateway_customer_id')); - $payment_methods = Stripe\PaymentMethod::all(array( - 'customer' => $stripe_customer_id, - 'type' => 'card' - )); + $payment_methods = Stripe\PaymentMethod::all( + array( + 'customer' => $stripe_customer_id, + 'type' => 'card', + ) + ); foreach ($payment_methods->data as $payment_method) { + $customer_payment_methods[ $payment_method->id ] = $payment_method; + } - $customer_payment_methods[$payment_method->id] = $payment_method; - - } // end foreach; - - $existing_payment_methods[$customer_id] = $customer_payment_methods; - - return $existing_payment_methods[$customer_id]; + $existing_payment_methods[ $customer_id ] = $customer_payment_methods; + return $existing_payment_methods[ $customer_id ]; } catch (\Throwable $exception) { - return array(); - - } // end try; - - } // end get_user_saved_payment_methods; + } + } /** * Returns the external link to view the payment on the payment gateway. @@ -3332,14 +2923,11 @@ class Base_Stripe_Gateway extends Base_Gateway { $path = 'payments'; if (strncmp($gateway_payment_id, 'in_', strlen('in_')) === 0) { - $path = 'invoices'; - - } // end if; + } return sprintf('https://dashboard.stripe.com%s/%s/%s', $route, $path, $gateway_payment_id); - - } // end get_payment_url_on_gateway; + } /** * Returns the external link to view the membership on the membership gateway. @@ -3356,8 +2944,7 @@ class Base_Stripe_Gateway extends Base_Gateway { $route = $this->test_mode ? '/test' : '/'; return sprintf('https://dashboard.stripe.com%s/subscriptions/%s', $route, $gateway_subscription_id); - - } // end get_subscription_url_on_gateway; + } /** * Returns the external link to view the customer on the gateway. @@ -3374,7 +2961,5 @@ class Base_Stripe_Gateway extends Base_Gateway { $route = $this->test_mode ? '/test' : '/'; return sprintf('https://dashboard.stripe.com%s/customers/%s', $route, $gateway_customer_id); - - } // end get_customer_url_on_gateway; - -} // end class Base_Stripe_Gateway; + } +} diff --git a/inc/gateways/class-free-gateway.php b/inc/gateways/class-free-gateway.php index 551a786..0aa63cb 100644 --- a/inc/gateways/class-free-gateway.php +++ b/inc/gateways/class-free-gateway.php @@ -12,8 +12,8 @@ namespace WP_Ultimo\Gateways; use WP_Ultimo\Gateways\Base_Gateway; -use \WP_Ultimo\Database\Memberships\Membership_Status; -use \WP_Ultimo\Database\Payments\Payment_Status; +use WP_Ultimo\Database\Memberships\Membership_Status; +use WP_Ultimo\Database\Payments\Payment_Status; // Exit if accessed directly defined('ABSPATH') || exit; @@ -79,7 +79,6 @@ class Free_Gateway extends Base_Gateway { $status = $membership->save(); return; - } elseif ($type === 'upgrade' || $type === 'downgrade' || $type === 'addon') { /* * A change to another free membership @@ -89,16 +88,14 @@ class Free_Gateway extends Base_Gateway { $membership->swap($cart); $membership->set_status(Membership_Status::ACTIVE); - - } // end if; + } $membership->save(); $payment->set_status(Payment_Status::COMPLETED); $payment->save(); - - } // end process_checkout; + } /** * Process a cancellation. @@ -120,7 +117,7 @@ class Free_Gateway extends Base_Gateway { * @param \WP_Ultimo\Models\Customer $customer The customer checking out. * @return void */ - public function process_cancellation($membership, $customer) {} // end process_cancellation; + public function process_cancellation($membership, $customer) {} /** * Process a refund. @@ -144,6 +141,5 @@ class Free_Gateway extends Base_Gateway { * @param \WP_Ultimo\Models\Customer $customer The customer checking out. * @return void */ - public function process_refund($amount, $payment, $membership, $customer) {} // end process_refund; - -} // end class Free_Gateway; + public function process_refund($amount, $payment, $membership, $customer) {} +} diff --git a/inc/gateways/class-ignorable-exception.php b/inc/gateways/class-ignorable-exception.php index 413c4f6..70ce162 100644 --- a/inc/gateways/class-ignorable-exception.php +++ b/inc/gateways/class-ignorable-exception.php @@ -14,4 +14,4 @@ namespace WP_Ultimo\Gateways; * * @since 2.0.7 */ -class Ignorable_Exception extends \Exception {} // end class Ignorable_Exception; +class Ignorable_Exception extends \Exception {} diff --git a/inc/gateways/class-manual-gateway.php b/inc/gateways/class-manual-gateway.php index 7c990c1..614884c 100644 --- a/inc/gateways/class-manual-gateway.php +++ b/inc/gateways/class-manual-gateway.php @@ -15,9 +15,9 @@ namespace WP_Ultimo\Gateways; -use \WP_Ultimo\Gateways\Base_Gateway; -use \WP_Ultimo\Database\Memberships\Membership_Status; -use \WP_Ultimo\Database\Payments\Payment_Status; +use WP_Ultimo\Gateways\Base_Gateway; +use WP_Ultimo\Database\Memberships\Membership_Status; +use WP_Ultimo\Database\Payments\Payment_Status; // Exit if accessed directly defined('ABSPATH') || exit; @@ -48,8 +48,7 @@ class Manual_Gateway extends Base_Gateway { * Adds payment instructions to the thank you page. */ add_action('wu_thank_you_before_info_blocks', array($this, 'add_payment_instructions_block'), 10, 3); - - } // end hooks; + } /** * Declares support to recurring payments. @@ -63,8 +62,7 @@ class Manual_Gateway extends Base_Gateway { public function supports_recurring(): bool { return false; - - } // end supports_recurring; + } /** * Declares support to free trials @@ -75,8 +73,7 @@ class Manual_Gateway extends Base_Gateway { public function supports_free_trials(): bool { return false; - - } // end supports_free_trials; + } /** * Adds the Stripe Gateway settings to the settings screen. @@ -86,28 +83,35 @@ class Manual_Gateway extends Base_Gateway { */ public function settings() { - wu_register_settings_field('payment-gateways', 'manual_header', array( - 'title' => __('Manual', 'wp-ultimo'), - 'desc' => __('Use the settings section below to configure the manual payment method. This method allows your customers to manually pay for their memberships, but those payments require manual confirmation on your part.', 'wp-ultimo'), - 'type' => 'header', - 'show_as_submenu' => true, - 'require' => array( - 'active_gateways' => 'manual', - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'manual_header', + array( + 'title' => __('Manual', 'wp-ultimo'), + 'desc' => __('Use the settings section below to configure the manual payment method. This method allows your customers to manually pay for their memberships, but those payments require manual confirmation on your part.', 'wp-ultimo'), + 'type' => 'header', + 'show_as_submenu' => true, + 'require' => array( + 'active_gateways' => 'manual', + ), + ) + ); - wu_register_settings_field('payment-gateways', 'manual_payment_instructions', array( - 'title' => __('Payment Instructions', 'wp-ultimo'), - 'desc' => __('This instructions will be shown to the customer on the thank you page, as well as be sent via email.', 'wp-ultimo'), - 'type' => 'wp_editor', - 'allow_html' => true, - 'default' => __('Payment instructions here.', 'wp-ultimo'), - 'require' => array( - 'active_gateways' => 'manual', - ), - )); - - } // end settings; + wu_register_settings_field( + 'payment-gateways', + 'manual_payment_instructions', + array( + 'title' => __('Payment Instructions', 'wp-ultimo'), + 'desc' => __('This instructions will be shown to the customer on the thank you page, as well as be sent via email.', 'wp-ultimo'), + 'type' => 'wp_editor', + 'allow_html' => true, + 'default' => __('Payment instructions here.', 'wp-ultimo'), + 'require' => array( + 'active_gateways' => 'manual', + ), + ) + ); + } /** * Reflects membership changes on the gateway. @@ -123,8 +127,7 @@ class Manual_Gateway extends Base_Gateway { public function process_membership_update(&$membership, $customer) { return true; - - } // end process_membership_update; + } /** * Returns a message about what will happen to the gateway subscription @@ -138,18 +141,13 @@ class Manual_Gateway extends Base_Gateway { public function get_amount_update_message($to_customer = false) { if ($to_customer) { - $message = __('You will receive a updated invoice on the next billing cycle.', 'wp-ultimo'); - } else { - $message = __('The customer will receive a updated invoice on the next billing cycle.', 'wp-ultimo'); - - } // end if; + } return $message; - - } // end get_amount_update_message; + } /** * Process a checkout. * @@ -220,11 +218,9 @@ class Manual_Gateway extends Base_Gateway { if ($type === 'new') { // Your logic here. - } elseif ($type === 'renewal') { // Your logic here. - } elseif ($type === 'downgrade') { /* * When downgrading, we need to schedule a swap for the end of the @@ -242,7 +238,6 @@ class Manual_Gateway extends Base_Gateway { * Saves the membership with the changes. */ $status = $membership->save(); - } elseif ($type === 'upgrade' || $type === 'addon') { /* * After everything is said and done, @@ -271,8 +266,7 @@ class Manual_Gateway extends Base_Gateway { * Saves the membership with the changes. */ $status = $membership->save(); - - } // end if; + } /* * We want to check the status @@ -288,19 +282,15 @@ class Manual_Gateway extends Base_Gateway { * will be undone, including the swap above. */ if (is_wp_error($status)) { - throw new \Exception($status->get_error_message(), $status->get_error_code()); - - } // end if; + } // In case of trials with payment method if ($payment->get_total() === 0.00) { - $payment->set_status(Payment_Status::COMPLETED); $payment->save(); - - } // end if; + } /* * You don't need to return anything, @@ -312,8 +302,7 @@ class Manual_Gateway extends Base_Gateway { * extra redirects. */ return true; - - } // end process_checkout; + } /** * Process a cancellation. @@ -327,7 +316,7 @@ class Manual_Gateway extends Base_Gateway { * @param \WP_Ultimo\Models\Customer $customer The customer checking out. * @return void|bool */ - public function process_cancellation($membership, $customer) {} // end process_cancellation; + public function process_cancellation($membership, $customer) {} /** * Process a checkout. @@ -348,29 +337,25 @@ class Manual_Gateway extends Base_Gateway { $status = $payment->refund($amount); if (is_wp_error($status)) { - throw new \Exception($status->get_error_code(), $status->get_error_message()); - - } // end if; - - } // end process_refund; - /** - * Adds additional fields to the checkout form for a particular gateway. - * - * In this method, you can either return an array of fields (that we will display - * using our form display methods) or you can return plain HTML in a string, - * which will get outputted to the gateway section of the checkout. - * - * @since 2.0.0 - * @return mixed[]|string - */ - public function fields() { + } + } + /** + * Adds additional fields to the checkout form for a particular gateway. + * + * In this method, you can either return an array of fields (that we will display + * using our form display methods) or you can return plain HTML in a string, + * which will get outputted to the gateway section of the checkout. + * + * @since 2.0.0 + * @return mixed[]|string + */ + public function fields() { $message = __('After you finish signing up, we will send you an email with instructions to finalize the payment. Your account will be pending until the payment is finalized and confirmed.', 'wp-ultimo'); return sprintf('

    %s

    ', $message); - - } // end fields; + } /** * Adds the payment instruction block. @@ -385,10 +370,8 @@ class Manual_Gateway extends Base_Gateway { public function add_payment_instructions_block($payment, $membership, $customer) { if ($payment->get_gateway() !== $this->id) { - return; - - } // end if; + } // phpcs:disable @@ -427,7 +410,5 @@ class Manual_Gateway extends Base_Gateway { test_mode) { - $this->api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp'; $this->checkout_url = 'https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token='; @@ -163,8 +160,7 @@ class PayPal_Gateway extends Base_Gateway { $this->signature = wu_get_setting('paypal_test_signature', ''); return; - - } // end if; + } /* * Otherwise, set @@ -176,8 +172,7 @@ class PayPal_Gateway extends Base_Gateway { $this->username = wu_get_setting('paypal_live_username', ''); $this->password = wu_get_setting('paypal_live_password', ''); $this->signature = wu_get_setting('paypal_live_signature', ''); - - } // end init; + } /** * Adds the PayPal Gateway settings to the settings screen. @@ -187,114 +182,145 @@ class PayPal_Gateway extends Base_Gateway { */ public function settings() { - wu_register_settings_field('payment-gateways', 'paypal_header', array( - 'title' => __('PayPal', 'wp-ultimo'), - 'desc' => __('Use the settings section below to configure PayPal Express as a payment method.', 'wp-ultimo'), - 'type' => 'header', - 'show_as_submenu' => true, - 'require' => array( - 'active_gateways' => 'paypal', - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'paypal_header', + array( + 'title' => __('PayPal', 'wp-ultimo'), + 'desc' => __('Use the settings section below to configure PayPal Express as a payment method.', 'wp-ultimo'), + 'type' => 'header', + 'show_as_submenu' => true, + 'require' => array( + 'active_gateways' => 'paypal', + ), + ) + ); - wu_register_settings_field('payment-gateways', 'paypal_sandbox_mode', array( - 'title' => __('PayPal Sandbox Mode', 'wp-ultimo'), - 'desc' => __('Toggle this to put PayPal on sandbox mode. This is useful for testing and making sure PayPal is correctly setup to handle your payments.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - 'html_attr' => array( - 'v-model' => 'paypal_sandbox_mode', - ), - 'require' => array( - 'active_gateways' => 'paypal', - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'paypal_sandbox_mode', + array( + 'title' => __('PayPal Sandbox Mode', 'wp-ultimo'), + 'desc' => __('Toggle this to put PayPal on sandbox mode. This is useful for testing and making sure PayPal is correctly setup to handle your payments.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + 'html_attr' => array( + 'v-model' => 'paypal_sandbox_mode', + ), + 'require' => array( + 'active_gateways' => 'paypal', + ), + ) + ); - wu_register_settings_field('payment-gateways', 'paypal_test_username', array( - 'title' => __('PayPal Test Username', 'wp-ultimo'), - 'desc' => '', - 'tooltip' => __('Make sure you are placing the TEST username, not the live one.', 'wp-ultimo'), - 'placeholder' => __('e.g. username_api1.username.co', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => 'paypal', - 'paypal_sandbox_mode' => 1, - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'paypal_test_username', + array( + 'title' => __('PayPal Test Username', 'wp-ultimo'), + 'desc' => '', + 'tooltip' => __('Make sure you are placing the TEST username, not the live one.', 'wp-ultimo'), + 'placeholder' => __('e.g. username_api1.username.co', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => 'paypal', + 'paypal_sandbox_mode' => 1, + ), + ) + ); - wu_register_settings_field('payment-gateways', 'paypal_test_password', array( - 'title' => __('PayPal Test Password', 'wp-ultimo'), - 'desc' => '', - 'tooltip' => __('Make sure you are placing the TEST password, not the live one.', 'wp-ultimo'), - 'placeholder' => __('e.g. IUOSABK987HJG88N', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => 'paypal', - 'paypal_sandbox_mode' => 1, - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'paypal_test_password', + array( + 'title' => __('PayPal Test Password', 'wp-ultimo'), + 'desc' => '', + 'tooltip' => __('Make sure you are placing the TEST password, not the live one.', 'wp-ultimo'), + 'placeholder' => __('e.g. IUOSABK987HJG88N', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => 'paypal', + 'paypal_sandbox_mode' => 1, + ), + ) + ); - wu_register_settings_field('payment-gateways', 'paypal_test_signature', array( - 'title' => __('PayPal Test Signature', 'wp-ultimo'), - 'desc' => '', - 'tooltip' => __('Make sure you are placing the TEST signature, not the live one.', 'wp-ultimo'), - 'placeholder' => __('e.g. AFcpSSRl31ADOdqnHNv4KZdVHEQzdMEEsWxV21C7fd0v3bYYYRCwYxqo', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => 'paypal', - 'paypal_sandbox_mode' => 1, - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'paypal_test_signature', + array( + 'title' => __('PayPal Test Signature', 'wp-ultimo'), + 'desc' => '', + 'tooltip' => __('Make sure you are placing the TEST signature, not the live one.', 'wp-ultimo'), + 'placeholder' => __('e.g. AFcpSSRl31ADOdqnHNv4KZdVHEQzdMEEsWxV21C7fd0v3bYYYRCwYxqo', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => 'paypal', + 'paypal_sandbox_mode' => 1, + ), + ) + ); - wu_register_settings_field('payment-gateways', 'paypal_live_username', array( - 'title' => __('PayPal Live Username', 'wp-ultimo'), - 'desc' => '', - 'tooltip' => __('Make sure you are placing the LIVE username, not the test one.', 'wp-ultimo'), - 'placeholder' => __('e.g. username_api1.username.co', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => 'paypal', - 'paypal_sandbox_mode' => 0, - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'paypal_live_username', + array( + 'title' => __('PayPal Live Username', 'wp-ultimo'), + 'desc' => '', + 'tooltip' => __('Make sure you are placing the LIVE username, not the test one.', 'wp-ultimo'), + 'placeholder' => __('e.g. username_api1.username.co', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => 'paypal', + 'paypal_sandbox_mode' => 0, + ), + ) + ); - wu_register_settings_field('payment-gateways', 'paypal_live_password', array( - 'title' => __('PayPal Live Password', 'wp-ultimo'), - 'desc' => '', - 'tooltip' => __('Make sure you are placing the LIVE password, not the test one.', 'wp-ultimo'), - 'placeholder' => __('e.g. IUOSABK987HJG88N', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => 'paypal', - 'paypal_sandbox_mode' => 0, - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'paypal_live_password', + array( + 'title' => __('PayPal Live Password', 'wp-ultimo'), + 'desc' => '', + 'tooltip' => __('Make sure you are placing the LIVE password, not the test one.', 'wp-ultimo'), + 'placeholder' => __('e.g. IUOSABK987HJG88N', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => 'paypal', + 'paypal_sandbox_mode' => 0, + ), + ) + ); - wu_register_settings_field('payment-gateways', 'paypal_live_signature', array( - 'title' => __('PayPal Live Signature', 'wp-ultimo'), - 'desc' => '', - 'tooltip' => __('Make sure you are placing the LIVE signature, not the test one.', 'wp-ultimo'), - 'placeholder' => __('e.g. AFcpSSRl31ADOdqnHNv4KZdVHEQzdMEEsWxV21C7fd0v3bYYYRCwYxqo', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => 'paypal', - 'paypal_sandbox_mode' => 0, - ), - )); - - } // end settings; + wu_register_settings_field( + 'payment-gateways', + 'paypal_live_signature', + array( + 'title' => __('PayPal Live Signature', 'wp-ultimo'), + 'desc' => '', + 'tooltip' => __('Make sure you are placing the LIVE signature, not the test one.', 'wp-ultimo'), + 'placeholder' => __('e.g. AFcpSSRl31ADOdqnHNv4KZdVHEQzdMEEsWxV21C7fd0v3bYYYRCwYxqo', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => 'paypal', + 'paypal_sandbox_mode' => 0, + ), + ) + ); + } /** * Reflects membership changes on the gateway. @@ -312,20 +338,16 @@ class PayPal_Gateway extends Base_Gateway { $gateway_subscription_id = $membership->get_gateway_subscription_id(); if (empty($gateway_subscription_id)) { - return new \WP_Error('wu_paypal_no_subscription_id', __('Error: No gateway subscription ID found for this membership.', 'wp-ultimo')); - - } // end if; + } $original = $membership->_get_original(); $has_duration_change = $membership->get_duration() !== absint(wu_get_isset($original, 'duration')) || $membership->get_duration_unit() !== wu_get_isset($original, 'duration_unit'); if ($has_duration_change) { - return new \WP_Error('wu_paypal_no_duration_change', __('Error: PayPal does not support changing the duration of a subscription.', 'wp-ultimo')); - - } // end if; + } /** * Generate a temporary wu payment so we can get the correct line items and amounts. @@ -348,11 +370,14 @@ class PayPal_Gateway extends Base_Gateway { 'TAXAMT' => $temp_payment->get_tax_total(), ); - $request = wp_remote_post($this->api_endpoint, array( - 'timeout' => 45, - 'httpversion' => '1.1', - 'body' => $args, - )); + $request = wp_remote_post( + $this->api_endpoint, + array( + 'timeout' => 45, + 'httpversion' => '1.1', + 'body' => $args, + ) + ); /* * Check for wp-error on the request call @@ -361,28 +386,21 @@ class PayPal_Gateway extends Base_Gateway { * Maybe PayPal is out? We can't be sure. */ if (is_wp_error($request)) { - return $request; - - } // end if; + } $body = wp_remote_retrieve_body($request); if (is_string($body)) { - wp_parse_str($body, $body); - - } // end if; + } if ('failure' === strtolower((string) $body['ACK'])) { - return new \WP_Error($body['L_ERRORCODE0'], __('PayPal Error:', 'wp-ultimo') . ' ' . $body['L_LONGMESSAGE0']); - - } // end if; + } return true; - - } // end process_membership_update; + } /** * Process a checkout. @@ -479,17 +497,14 @@ class PayPal_Gateway extends Base_Gateway { $notes = array(); if ($is_trial_setup) { - $desc = $membership->get_recurring_description(); - $date = wp_date(get_option('date_format'), strtotime( $membership->get_date_trial_end(), wu_get_current_time('timestamp', true))); + $date = wp_date(get_option('date_format'), strtotime($membership->get_date_trial_end(), wu_get_current_time('timestamp', true))); $notes[] = sprintf(__('Your trial period will end on %1$s.', 'wp-ultimo'), $date); - - } // end if; + } if ($is_recurring && $should_auto_renew) { - $recurring_total = $cart->get_recurring_total(); $cart_total = $cart->get_total(); @@ -502,46 +517,25 @@ class PayPal_Gateway extends Base_Gateway { $recurring_total_format = wu_format_currency($recurring_total, $cart->get_currency()); if ($recurring_total !== $cart_total) { - if ($type === 'downgrade') { - if ($is_trial_setup) { - $notes[] = sprintf(__('Your updated membership will start on $1$s, from that date you will be billed %2$s every month.', 'wp-ultimo'), $date, $recurring_total_format); - } else { - - $date_renew = wp_date(get_option('date_format'), strtotime( $membership->get_date_expiration(), wu_get_current_time('timestamp', true))); + $date_renew = wp_date(get_option('date_format'), strtotime($membership->get_date_expiration(), wu_get_current_time('timestamp', true))); $notes[] = sprintf(__('Your updated membership will start on %1$s, from that date you will be billed %2$s %3$s.', 'wp-ultimo'), $date_renew, $recurring_total_format, $desc); - - } // end if; - + } } elseif ($is_trial_setup) { - $notes[] = sprintf(__('After the first payment you will be billed %1$s %2$s.', 'wp-ultimo'), $recurring_total_format, $desc); - } else { - $notes[] = sprintf(__('After this payment you will be billed %1$s %2$s.', 'wp-ultimo'), $recurring_total_format, $desc); - - } // end if; - - } else { - - if ($is_trial_setup) { - + } + } elseif ($is_trial_setup) { $notes[] = sprintf(__('From that date, you will be billed %1$s %2$s.', 'wp-ultimo'), $recurring_total_format, $desc); - - } else { - - $notes[] = sprintf(__('After this payment you will be billed %1$s.', 'wp-ultimo'), $desc); - - } // end if; - - } // end if; - - } // end if; + } else { + $notes[] = sprintf(__('After this payment you will be billed %1$s.', 'wp-ultimo'), $desc); + } + } $args['NOTETOBUYER'] = implode(' ', $notes); @@ -555,7 +549,6 @@ class PayPal_Gateway extends Base_Gateway { * Loop products and add them to the paypal */ foreach ($cart->get_line_items() as $line_item) { - $total = $line_item->get_total(); $sub_total = $line_item->get_subtotal(); $tax_amount = $line_item->get_tax_total(); @@ -574,34 +567,37 @@ class PayPal_Gateway extends Base_Gateway { $args = array_merge($args, $product_args); - $product_index++; - - } // end foreach; + ++$product_index; + } $discounts_total = $cart->get_total_discounts(); - if (!empty($discounts_total)) { - + if ( ! empty($discounts_total)) { __('Account credit and other discounts', 'wp-ultimo'); - $args = array_merge($args, array( - "L_PAYMENTREQUEST_0_NAME{$product_index}" => __('Account credit and other discounts', 'wp-ultimo'), - "L_PAYMENTREQUEST_0_AMT{$product_index}" => $discounts_total, - "L_PAYMENTREQUEST_0_QTY{$product_index}" => 1, - )); + $args = array_merge( + $args, + array( + "L_PAYMENTREQUEST_0_NAME{$product_index}" => __('Account credit and other discounts', 'wp-ultimo'), + "L_PAYMENTREQUEST_0_AMT{$product_index}" => $discounts_total, + "L_PAYMENTREQUEST_0_QTY{$product_index}" => 1, + ) + ); $args['PAYMENTREQUEST_0_ITEMAMT'] = $args['PAYMENTREQUEST_0_ITEMAMT'] + $discounts_total; $args['PAYMENTREQUEST_0_AMT'] = $args['PAYMENTREQUEST_0_AMT'] + $discounts_total; - $product_index++; + ++$product_index; + } - } // end if; - - $request = wp_remote_post($this->api_endpoint, array( - 'timeout' => 45, - 'httpversion' => '1.1', - 'body' => $args - )); + $request = wp_remote_post( + $this->api_endpoint, + array( + 'timeout' => 45, + 'httpversion' => '1.1', + 'body' => $args, + ) + ); $body = wp_remote_retrieve_body($request); $code = wp_remote_retrieve_response_code($request); @@ -616,10 +612,8 @@ class PayPal_Gateway extends Base_Gateway { * Maybe PayPal is out? We can't be sure. */ if (is_wp_error($request)) { - throw new \Exception($request->get_error_message(), $request->get_error_code()); - - } // end if; + } /* * If we get here, we got a 200. @@ -635,15 +629,11 @@ class PayPal_Gateway extends Base_Gateway { * Urrrrgh! Let's parse it. */ if (is_string($body)) { - wp_parse_str($body, $body); - - } // end if; + } if ('failure' === strtolower((string) $body['ACK']) || 'failurewithwarning' === strtolower((string) $body['ACK'])) { - wp_die($body['L_LONGMESSAGE0'], $body['L_ERRORCODE0']); - } else { /* * We do have a valid token. @@ -653,17 +643,14 @@ class PayPal_Gateway extends Base_Gateway { wp_redirect($this->checkout_url . $body['TOKEN']); exit; - - } // end if; - - } // end if; + } + } /* * If we get here, something went wrong. */ throw new \Exception(__('Something has gone wrong, please try again', 'wp-ultimo')); - - } // end process_checkout; + } /** * Process a cancellation. @@ -691,13 +678,15 @@ class PayPal_Gateway extends Base_Gateway { 'ACTION' => 'Cancel', ); - $request = wp_remote_post($this->api_endpoint, array( - 'timeout' => 45, - 'httpversion' => '1.1', - 'body' => $args, - )); - - } // end process_cancellation; + $request = wp_remote_post( + $this->api_endpoint, + array( + 'timeout' => 45, + 'httpversion' => '1.1', + 'body' => $args, + ) + ); + } /** * Process a checkout. @@ -720,18 +709,14 @@ class PayPal_Gateway extends Base_Gateway { $gateway_payment_id = $payment->get_gateway_payment_id(); if (empty($gateway_payment_id)) { - throw new \Exception(__('Gateway payment ID not found. Cannot process refund automatically.', 'wp-ultimo')); - - } // end if; + } $refund_type = 'Partial'; if ($amount >= $payment->get_total()) { - $refund_type = 'Full'; - - } // end if; + } $amount_formatted = number_format($amount, 2); @@ -747,26 +732,25 @@ class PayPal_Gateway extends Base_Gateway { ); if ($refund_type === 'Partial') { - $args['AMT'] = $amount_formatted; + } - } // end if; - - $request = wp_remote_post($this->api_endpoint, array( - 'timeout' => 45, - 'httpversion' => '1.1', - 'body' => $args, - )); + $request = wp_remote_post( + $this->api_endpoint, + array( + 'timeout' => 45, + 'httpversion' => '1.1', + 'body' => $args, + ) + ); $body = wp_remote_retrieve_body($request); $code = wp_remote_retrieve_response_code($request); $message = wp_remote_retrieve_response_message($request); if (is_wp_error($request)) { - throw new \Exception($request->get_error_message()); - - } // end if; + } if (200 === absint($code) && 'OK' === $message) { /* @@ -774,44 +758,37 @@ class PayPal_Gateway extends Base_Gateway { * Urrrrgh! Let's parse it. */ if (is_string($body)) { - wp_parse_str($body, $body); - - } // end if; + } if ('failure' === strtolower((string) $body['ACK'])) { - throw new \Exception($body['L_LONGMESSAGE0']); - - } // end if; + } /* * All good. */ return true; - - } // end if; + } throw new \Exception(__('Something went wrong.', 'wp-ultimo')); - - } // end process_refund; - /** - * Adds additional fields to the checkout form for a particular gateway. - * - * In this method, you can either return an array of fields (that we will display - * using our form display methods) or you can return plain HTML in a string, - * which will get outputted to the gateway section of the checkout. - * - * @since 2.0.0 - * @return mixed[]|string - */ - public function fields() { + } + /** + * Adds additional fields to the checkout form for a particular gateway. + * + * In this method, you can either return an array of fields (that we will display + * using our form display methods) or you can return plain HTML in a string, + * which will get outputted to the gateway section of the checkout. + * + * @since 2.0.0 + * @return mixed[]|string + */ + public function fields() { $message = __('You will be redirected to PayPal to complete the purchase.', 'wp-ultimo'); return sprintf('

    %s

    ', $message); - - } // end fields; + } /** * Process confirmation. @@ -844,12 +821,10 @@ class PayPal_Gateway extends Base_Gateway { $details = $this->get_checkout_details(wu_request('token')); if (empty($details)) { - $error = new \WP_Error(__('PayPal token no longer valid.', 'wp-ultimo')); wp_die($error); - - } // end if; + } /* * Tries to get the payment based on the request @@ -862,12 +837,10 @@ class PayPal_Gateway extends Base_Gateway { * Bail. */ if (empty($payment)) { - $error = new \WP_Error(__('Pending payment does not exist.', 'wp-ultimo')); wp_die($error); - - } // end if; + } /* * Now we need to original cart. @@ -878,12 +851,10 @@ class PayPal_Gateway extends Base_Gateway { $original_cart = $payment->get_meta('wu_original_cart'); if (empty($original_cart)) { - $error = new \WP_Error('no-cart', __('Original cart does not exist.', 'wp-ultimo')); wp_die($error); - - } // end if; + } /* * Set the variables @@ -894,12 +865,10 @@ class PayPal_Gateway extends Base_Gateway { $is_recurring = $original_cart->has_recurring(); if (empty($membership) || empty($customer)) { - $error = new \WP_Error('no-membership', __('Missing membership or customer data.', 'wp-ultimo')); wp_die($error); - - } // end if; + } if ($should_auto_renew && $is_recurring) { /* @@ -908,24 +877,19 @@ class PayPal_Gateway extends Base_Gateway { * auto-renew option is active. */ $this->create_recurring_profile($details, $original_cart, $payment, $membership, $customer); - } else { /* * Otherwise, process * single payment. */ $this->complete_single_payment($details, $original_cart, $payment, $membership, $customer); - - } // end if; - - } elseif (!empty(wu_request('token'))) { + } + } elseif ( ! empty(wu_request('token'))) { // Prints the form $this->confirmation_form(); - - } // end if; - - } // end process_confirmation; + } + } /** * Process webhooks * @@ -941,27 +905,21 @@ class PayPal_Gateway extends Base_Gateway { $customer = false; $membership = false; - $custom = !empty($posted['custom']) ? explode('|', (string) $posted['custom']) : array(); - - if (is_array($custom) && !empty($custom)) { + $custom = ! empty($posted['custom']) ? explode('|', (string) $posted['custom']) : array(); + if (is_array($custom) && ! empty($custom)) { $payment = wu_get_payment(absint($custom[0])); $membership = wu_get_payment(absint($custom[1])); $customer = wu_get_payment(absint($custom[2])); + } - } // end if; - - if (!empty($posted['recurring_payment_id'])) { - + if ( ! empty($posted['recurring_payment_id'])) { $membership = wu_get_membership_by('gateway_subscription_id', $posted['recurring_payment_id']); - - } // end if; + } if (empty($membership)) { - throw new \Exception(__('Exiting PayPal Express IPN - membership ID not found.', 'wp-ultimo')); - - } // end if; + } wu_log_add('paypal', sprintf('Processing IPN for membership #%d.', $membership->get_id())); @@ -979,22 +937,16 @@ class PayPal_Gateway extends Base_Gateway { $amount = isset($posted['mc_gross']) ? wu_to_float($posted['mc_gross']) : false; if ($amount !== false) { - $payment_data['amount'] = $amount; + } - } // end if; - - if (!empty($posted['payment_date'])) { - + if ( ! empty($posted['payment_date'])) { $payment_data['date'] = date('Y-m-d H:i:s', strtotime((string) $posted['payment_date'])); // phpcs:ignore + } - } // end if; - - if (!empty($posted['txn_id'])) { - + if ( ! empty($posted['txn_id'])) { $payment_data['gateway_payment_id'] = sanitize_text_field($posted['txn_id']); - - } // end if; + } /* * Deal with each transaction type @@ -1017,20 +969,14 @@ class PayPal_Gateway extends Base_Gateway { * payment and make sure we have a match. */ if (isset($posted['initial_payment_txn_id'])) { - $transaction_id = ('Completed' === $posted['initial_payment_status']) ? $posted['initial_payment_txn_id'] : ''; - } else { - $transaction_id = $posted['ipn_track_id']; - - } // end if; + } if (empty($transaction_id)) { - throw new \Exception('Breaking out of PayPal Express IPN recurring_payment_profile_created. Transaction ID not given.'); - - } // end if; + } // setup the payment info in an array for storage $payment_data['date'] = date('Y-m-d H:i:s', strtotime($posted['time_created'])); // phpcs:ignore @@ -1039,7 +985,7 @@ class PayPal_Gateway extends Base_Gateway { $payment = wu_get_payment_by('gateway_payment_id', $payment_data['gateway_payment_id']); - $should_use_subscription = !$payment && isset($posted['recurring_payment_id']); + $should_use_subscription = ! $payment && isset($posted['recurring_payment_id']); $payment = $should_use_subscription ? wu_get_payment_by('gateway_payment_id', sanitize_text_field($posted['recurring_payment_id'])) : $payment; @@ -1048,11 +994,9 @@ class PayPal_Gateway extends Base_Gateway { * already exists, update it. */ if ($payment) { - $payment->attributes($payment_data); $payment->save(); - } else { /* * Payment does not exist. Create it and renew the membership. @@ -1066,7 +1010,7 @@ class PayPal_Gateway extends Base_Gateway { $payment->attributes($payment_data); $payment->save(); - } // end if; + } $is_trial_setup = $membership->is_trialing() && empty($payment->get_total()); $status = $is_trial_setup ? Membership_Status::TRIALING : Membership_Status::ACTIVE; @@ -1092,20 +1036,18 @@ class PayPal_Gateway extends Base_Gateway { if ('failed' === strtolower((string) $posted['payment_status'])) { // Recurring payment failed. - $membership->add_note( sprintf( __( 'Transaction ID %s failed in PayPal.', 'wp-ultimo' ), $posted['txn_id'] ) ); - - die( 'Subscription payment failed' ); + $membership->add_note(sprintf(__('Transaction ID %s failed in PayPal.', 'wp-ultimo'), $posted['txn_id'])); + die('Subscription payment failed'); } elseif ('pending' === strtolower((string) $posted['payment_status'])) { // Recurring payment pending (such as echeck). - $pending_reason = !empty( $posted['pending_reason'] ) ? $posted['pending_reason'] : __( 'unknown', 'wp-ultimo' ); + $pending_reason = ! empty($posted['pending_reason']) ? $posted['pending_reason'] : __('unknown', 'wp-ultimo'); - $membership->add_note( sprintf( __( 'Transaction ID %1$s is pending in PayPal for reason: %2$s', 'wp-ultimo' ), $posted['txn_id'], $pending_reason ) ); + $membership->add_note(sprintf(__('Transaction ID %1$s is pending in PayPal for reason: %2$s', 'wp-ultimo'), $posted['txn_id'], $pending_reason)); - die( 'Subscription payment pending' ); - - } // end if; + die('Subscription payment pending'); + } $payment_data['transaction_type'] = 'renewal'; @@ -1116,11 +1058,9 @@ class PayPal_Gateway extends Base_Gateway { * already exists, update it. */ if ($payment) { - $payment->attributes($payment_data); $payment->save(); - } else { /* * Payment does not exist. Create it and renew the membership. @@ -1128,20 +1068,15 @@ class PayPal_Gateway extends Base_Gateway { $payment = wu_create_payment($payment_data); $membership->add_to_times_billed(1); - - } // end if; + } $is_trial_setup = $membership->is_trialing() && empty($payment->get_total()); - if (!$is_trial_setup) { - + if ( ! $is_trial_setup) { $membership->renew(true); - } else { - $membership->save(); - - } // end if; + } break; @@ -1153,27 +1088,23 @@ class PayPal_Gateway extends Base_Gateway { // Initial payment failed, so set the user back to pending. $membership->set_status('pending'); - $membership->add_note(__( 'Initial payment failed in PayPal Express.', 'wp-ultimo')); + $membership->add_note(__('Initial payment failed in PayPal Express.', 'wp-ultimo')); $this->error_message = __('Initial payment failed.', 'wp-ultimo'); - } else { // If this is a completed payment plan, we can skip any cancellation actions. This is handled in renewals. if ($membership->has_payment_plan() && $membership->at_maximum_renewals()) { - wu_log_add('paypal', sprintf('Membership #%d has completed its payment plan - not cancelling.', $membership->get_id())); die('membership payment plan completed'); - - } // end if; + } // user is marked as cancelled but retains access until end of term $membership->cancel(); $membership->add_note(__('Membership cancelled via PayPal Express IPN.', 'wp-ultimo')); - - } // end if; + } break; @@ -1181,20 +1112,15 @@ class PayPal_Gateway extends Base_Gateway { case 'recurring_payment_suspended_due_to_max_failed_payment': // Same case as before wu_log_add('paypal', 'Processing PayPal Express recurring_payment_failed or recurring_payment_suspended_due_to_max_failed_payment IPN.'); - if (!in_array($membership->get_status(), array('cancelled', 'expired'), true)) { - + if ( ! in_array($membership->get_status(), array('cancelled', 'expired'), true)) { $membership->set_status('expired'); + } - } // end if; - - if (!empty($posted['txn_id'])) { - + if ( ! empty($posted['txn_id'])) { $this->webhook_event_id = sanitize_text_field($posted['txn_id']); - - } elseif (!empty($posted['ipn_track_id'])) { - + } elseif ( ! empty($posted['ipn_track_id'])) { $this->webhook_event_id = sanitize_text_field($posted['ipn_track_id']); - } // end if; + } break; @@ -1202,13 +1128,10 @@ class PayPal_Gateway extends Base_Gateway { wu_log_add('paypal', sprintf('Processing PayPal Express web_accept IPN. Payment status: %s', $posted['payment_status'])); switch (strtolower((string) $posted['payment_status'])) : - case 'completed': if (empty($payment_data['gateway_payment_id'])) { - throw new \Exception('Breaking out of PayPal Express IPN recurring_payment_profile_created. Transaction ID not given.'); - - } // end if; + } $payment = wu_get_payment_by('gateway_payment_id', $payment_data['gateway_payment_id']); @@ -1217,21 +1140,18 @@ class PayPal_Gateway extends Base_Gateway { * already exists, update it. */ if ($payment) { - $payment->attributes($payment_data); $payment->save(); - /* - * Payment does not exist. Create it and renew the membership. - */ + /* + * Payment does not exist. Create it and renew the membership. + */ } else { - wu_create_payment($payment_data); $membership->add_to_times_billed(1); - - } // end if; + } // Membership was already activated. @@ -1247,26 +1167,19 @@ class PayPal_Gateway extends Base_Gateway { * Cancel active memberships. */ if ($membership->is_active()) { - $membership->cancel(); - } else { - wu_log_add('paypal', sprintf('Membership #%d is not active - not cancelling account.', $membership->get_id())); - - } // end if; + } break; - endswitch; break; - endswitch; return true; - - } // end process_webhooks; + } /** * Create a recurring profile. @@ -1302,15 +1215,12 @@ class PayPal_Gateway extends Base_Gateway { ); if ($args['INITAMT'] < 0) { - unset($args['INITAMT']); - - } // end if; + } $is_trial_setup = $membership->is_trialing() && empty($payment->get_total()); if ($is_trial_setup) { - $trial_end = strtotime($membership->get_date_trial_end(), wu_get_current_time('timestamp', true)); $args['PROFILESTARTDATE'] = date('Y-m-d\TH:i:s', $trial_end); // phpcs:ignore @@ -1318,30 +1228,28 @@ class PayPal_Gateway extends Base_Gateway { $args['TRIALBILLINGFREQUENCY'] = floor(($trial_end - time()) / 86400); $args['TRIALAMT'] = $membership->get_initial_amount(); $args['TRIALTOTALBILLINGCYCLES'] = 1; + } - } // end if; - - if (!$membership->is_forever_recurring()) { - + if ( ! $membership->is_forever_recurring()) { $args['TOTALBILLINGCYCLES'] = $membership->get_billing_cycles() - $membership->get_times_billed(); + } - } // end if; - - $request = wp_remote_post($this->api_endpoint, array( - 'timeout' => 45, - 'httpversion' => '1.1', - 'body' => $args, - )); + $request = wp_remote_post( + $this->api_endpoint, + array( + 'timeout' => 45, + 'httpversion' => '1.1', + 'body' => $args, + ) + ); $body = wp_remote_retrieve_body($request); $code = wp_remote_retrieve_response_code($request); $message = wp_remote_retrieve_response_message($request); if (is_wp_error($request)) { - wp_die($request); - - } // end if; + } if (200 === absint($code) && 'OK' === $message) { /* @@ -1349,17 +1257,13 @@ class PayPal_Gateway extends Base_Gateway { * Urrrrgh! Let's parse it. */ if (is_string($body)) { - wp_parse_str($body, $body); - - } // end if; + } if ('failure' === strtolower((string) $body['ACK'])) { - $error = new \WP_Error($body['L_ERRORCODE0'], $body['L_LONGMESSAGE0']); wp_die($error); - } else { /* * We were successful, let's update @@ -1374,16 +1278,14 @@ class PayPal_Gateway extends Base_Gateway { // If TRANSACTIONID is not passed we need to wait for webhook $payment_status = Payment_Status::PENDING; - if (!empty($transaction_id) || $profile_status === 'ActiveProfile' || $is_trial_setup) { - + if ( ! empty($transaction_id) || $profile_status === 'ActiveProfile' || $is_trial_setup) { $payment_status = Payment_Status::COMPLETED; - - } // end if; + } /** * If we don't have a transaction ID, let's use the profile ID. */ - $transaction_id = empty($transaction_id) && !empty($body['PROFILEID']) ? $body['PROFILEID'] : $transaction_id; + $transaction_id = empty($transaction_id) && ! empty($body['PROFILEID']) ? $body['PROFILEID'] : $transaction_id; $payment_data = array( 'gateway_payment_id' => $transaction_id, @@ -1410,7 +1312,6 @@ class PayPal_Gateway extends Base_Gateway { $membership->set_gateway('paypal'); if ($payment_status === Payment_Status::COMPLETED) { - $membership->add_to_times_billed(1); /* @@ -1420,34 +1321,23 @@ class PayPal_Gateway extends Base_Gateway { * a membership swap. */ if ($cart->get_cart_type() === 'upgrade' || $cart->get_cart_type() === 'addon') { - $membership->swap($cart); $membership->renew(true); - } elseif ($cart->get_cart_type() === 'downgrade') { - $membership->set_auto_renew(true); $membership->schedule_swap($cart); $membership->save(); - - } elseif (!$is_trial_setup) { - + } elseif ( ! $is_trial_setup) { $membership->renew(true); - } else { - $membership->save(); - - } // end if; - + } } else { - $membership->save(); - - } // end if; + } $this->payment = $payment; $redirect_url = $this->get_return_url(); @@ -1455,16 +1345,18 @@ class PayPal_Gateway extends Base_Gateway { wp_redirect($redirect_url); exit; - - } // end if; - + } } else { - - wp_die( __( 'Something has gone wrong, please try again', 'wp-ultimo' ), __( 'Error', 'wp-ultimo' ), array( 'back_link' => true, 'response' => '401' ) ); - - } // end if; - - } // end create_recurring_profile; + wp_die( + __('Something has gone wrong, please try again', 'wp-ultimo'), + __('Error', 'wp-ultimo'), + array( + 'back_link' => true, + 'response' => '401', + ) + ); + } + } /** * Get the subscription description. @@ -1481,8 +1373,7 @@ class PayPal_Gateway extends Base_Gateway { $desc = html_entity_decode(substr($descriptor, 0, 127), ENT_COMPAT, 'UTF-8'); return $desc; - - } // end get_subscription_description; + } /** * Create a single payment on PayPal. @@ -1513,14 +1404,17 @@ class PayPal_Gateway extends Base_Gateway { 'PAYMENTREQUEST_0_SHIPPINGAMT' => 0, 'PAYMENTREQUEST_0_TAXAMT' => 0, 'PAYMENTREQUEST_0_CURRENCYCODE' => $details['CURRENCYCODE'], - 'BUTTONSOURCE' => 'WP_Ultimo' + 'BUTTONSOURCE' => 'WP_Ultimo', ); - $request = wp_remote_post($this->api_endpoint, array( - 'timeout' => 45, - 'httpversion' => '1.1', - 'body' => $args, - )); + $request = wp_remote_post( + $this->api_endpoint, + array( + 'timeout' => 45, + 'httpversion' => '1.1', + 'body' => $args, + ) + ); /* * Retrieve the results of @@ -1531,25 +1425,18 @@ class PayPal_Gateway extends Base_Gateway { $message = wp_remote_retrieve_response_message($request); if (is_wp_error($request)) { - wp_die($request); - - } // end if; + } if (200 === absint($code) && 'OK' === $message) { - if (is_string($body)) { - wp_parse_str($body, $body); - - } // end if; + } if ('failure' === strtolower((string) $body['ACK'])) { - $error = new \WP_Error($body['L_ERRORCODE0'], $body['L_LONGMESSAGE0']); wp_die($error); - } else { /* * We were successful, let's update @@ -1582,10 +1469,8 @@ class PayPal_Gateway extends Base_Gateway { $membership = $payment->get_membership(); if ($cart->get_total() > 0) { - $membership->add_to_times_billed(1); - - } // end if; + } $is_trial_setup = $membership->is_trialing() && empty($payment->get_total()); @@ -1596,26 +1481,18 @@ class PayPal_Gateway extends Base_Gateway { * a membership swap. */ if ($cart->get_cart_type() === 'upgrade' || $cart->get_cart_type() === 'addon') { - $membership->swap($cart); $membership->renew(false); - } elseif ($cart->get_cart_type() === 'downgrade') { - $membership->schedule_swap($cart); $membership->save(); - - } elseif (!$is_trial_setup) { - + } elseif ( ! $is_trial_setup) { $membership->renew(false); - } else { - $membership->save(); - - } // end if; + } $this->payment = $payment; $redirect_url = $this->get_return_url(); @@ -1623,16 +1500,18 @@ class PayPal_Gateway extends Base_Gateway { wp_redirect($redirect_url); exit; - - } // end if; - + } } else { - - wp_die(__('Something has gone wrong, please try again', 'wp-ultimo' ), __('Error', 'wp-ultimo'), array('back_link' => true, 'response' => '401')); - - } // end if; - - } // end complete_single_payment; + wp_die( + __('Something has gone wrong, please try again', 'wp-ultimo'), + __('Error', 'wp-ultimo'), + array( + 'back_link' => true, + 'response' => '401', + ) + ); + } + } /** * Display the confirmation form. @@ -1646,35 +1525,35 @@ class PayPal_Gateway extends Base_Gateway { $checkout_details = $this->get_checkout_details($token); - if (!is_array($checkout_details)) { - + if ( ! is_array($checkout_details)) { $error = is_wp_error($checkout_details) ? $checkout_details->get_error_message() : __('Invalid response code from PayPal', 'wp-ultimo'); // translators: %s is the paypal error message. return '

    ' . sprintf(__('An unexpected PayPal error occurred. Error message: %s.', 'wp-ultimo'), $error) . '

    '; - - } // end if; + } /* * Compiles the necessary elements. */ $customer = $checkout_details['pending_payment']->get_customer(); // current customer - wu_get_template('checkout/paypal/confirm', array( - 'checkout_details' => $checkout_details, - 'customer' => $customer, - 'payment' => $checkout_details['pending_payment'], - 'membership' => $checkout_details['pending_payment']->get_membership(), - )); - - } // end confirmation_form; - /** - * Get checkout details. - * - * @param string $token PayPal token. - * @return mixed[]|bool|string|\WP_Error - */ - public function get_checkout_details($token = '') { + wu_get_template( + 'checkout/paypal/confirm', + array( + 'checkout_details' => $checkout_details, + 'customer' => $customer, + 'payment' => $checkout_details['pending_payment'], + 'membership' => $checkout_details['pending_payment']->get_membership(), + ) + ); + } + /** + * Get checkout details. + * + * @param string $token PayPal token. + * @return mixed[]|bool|string|\WP_Error + */ + public function get_checkout_details($token = '') { $args = array( 'TOKEN' => $token, @@ -1685,49 +1564,43 @@ class PayPal_Gateway extends Base_Gateway { 'METHOD' => 'GetExpressCheckoutDetails', ); - $request = wp_remote_post($this->api_endpoint, array( - 'timeout' => 45, - 'httpversion' => '1.1', - 'body' => $args - )); + $request = wp_remote_post( + $this->api_endpoint, + array( + 'timeout' => 45, + 'httpversion' => '1.1', + 'body' => $args, + ) + ); $body = wp_remote_retrieve_body($request); $code = wp_remote_retrieve_response_code($request); $message = wp_remote_retrieve_response_message($request); if (is_wp_error($request)) { - return $request; - } elseif (200 === absint($code) && 'OK' === $message) { - if (is_string($body)) { - wp_parse_str($body, $body); - - } // end if; + } $payment_id = absint(wu_request('payment-id')); $pending_payment = $payment_id ? wu_get_payment($payment_id) : wu_get_payment_by_hash(wu_request('payment')); - if (!empty($pending_payment)) { - + if ( ! empty($pending_payment)) { $pending_amount = $pending_payment->get_total(); - - } // end if; + } $body['pending_payment'] = $pending_payment; $custom = explode('|', (string) $body['PAYMENTREQUEST_0_CUSTOM']); return $body; - - } // end if; + } return false; - - } // end get_checkout_details; + } /** * Returns the external link to view the payment on the payment gateway. @@ -1742,8 +1615,7 @@ class PayPal_Gateway extends Base_Gateway { public function get_payment_url_on_gateway($gateway_payment_id): string { return ''; - - } // end get_payment_url_on_gateway; + } /** * Returns the external link to view the membership on the membership gateway. @@ -1762,7 +1634,5 @@ class PayPal_Gateway extends Base_Gateway { $base_url = 'https://www.%spaypal.com/us/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; return sprintf($base_url, $sandbox_prefix, $gateway_subscription_id); - - } // end get_subscription_url_on_gateway; - -} // end class PayPal_Gateway; + } +} diff --git a/inc/gateways/class-stripe-checkout-gateway.php b/inc/gateways/class-stripe-checkout-gateway.php index fd799dc..87c920d 100644 --- a/inc/gateways/class-stripe-checkout-gateway.php +++ b/inc/gateways/class-stripe-checkout-gateway.php @@ -11,9 +11,9 @@ namespace WP_Ultimo\Gateways; -use \WP_Ultimo\Gateways\Base_Stripe_Gateway; -use \Stripe; -use \WP_Ultimo\Checkout\Cart; +use WP_Ultimo\Gateways\Base_Stripe_Gateway; +use Stripe; +use WP_Ultimo\Checkout\Cart; // Exit if accessed directly defined('ABSPATH') || exit; @@ -26,11 +26,11 @@ defined('ABSPATH') || exit; class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { /** - * Holds the ID of a given gateway. - * - * @since 2.0.0 - * @var string - */ + * Holds the ID of a given gateway. + * + * @since 2.0.0 + * @var string + */ protected $id = 'stripe-checkout'; /** @@ -43,121 +43,152 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { $error_message_wrap = '%s'; - wu_register_settings_field('payment-gateways', 'stripe_checkout_header', array( - 'title' => __('Stripe Checkout', 'wp-ultimo'), - 'desc' => __('Use the settings section below to configure Stripe Checkout as a payment method.', 'wp-ultimo'), - 'type' => 'header', - 'show_as_submenu' => true, - 'require' => array( - 'active_gateways' => 'stripe-checkout', - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_checkout_header', + array( + 'title' => __('Stripe Checkout', 'wp-ultimo'), + 'desc' => __('Use the settings section below to configure Stripe Checkout as a payment method.', 'wp-ultimo'), + 'type' => 'header', + 'show_as_submenu' => true, + 'require' => array( + 'active_gateways' => 'stripe-checkout', + ), + ) + ); - wu_register_settings_field('payment-gateways', 'stripe_checkout_public_title', array( - 'title' => __('Stripe Public Name', 'wp-ultimo'), - 'tooltip' => __('The name to display on the payment method selection field. By default, "Credit Card" is used.', 'wp-ultimo'), - 'type' => 'text', - 'default' => __('Credit Card', 'wp-ultimo'), - 'require' => array( - 'active_gateways' => 'stripe-checkout', - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_checkout_public_title', + array( + 'title' => __('Stripe Public Name', 'wp-ultimo'), + 'tooltip' => __('The name to display on the payment method selection field. By default, "Credit Card" is used.', 'wp-ultimo'), + 'type' => 'text', + 'default' => __('Credit Card', 'wp-ultimo'), + 'require' => array( + 'active_gateways' => 'stripe-checkout', + ), + ) + ); - wu_register_settings_field('payment-gateways', 'stripe_checkout_sandbox_mode', array( - 'title' => __('Stripe Checkout Sandbox Mode', 'wp-ultimo'), - 'desc' => __('Toggle this to put Stripe on sandbox mode. This is useful for testing and making sure Stripe is correctly setup to handle your payments.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - 'html_attr' => array( - 'v-model' => 'stripe_checkout_sandbox_mode', - ), - 'require' => array( - 'active_gateways' => 'stripe-checkout', - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_checkout_sandbox_mode', + array( + 'title' => __('Stripe Checkout Sandbox Mode', 'wp-ultimo'), + 'desc' => __('Toggle this to put Stripe on sandbox mode. This is useful for testing and making sure Stripe is correctly setup to handle your payments.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + 'html_attr' => array( + 'v-model' => 'stripe_checkout_sandbox_mode', + ), + 'require' => array( + 'active_gateways' => 'stripe-checkout', + ), + ) + ); $pk_test_status = wu_get_setting('stripe_checkout_test_pk_key_status', ''); - wu_register_settings_field('payment-gateways', 'stripe_checkout_test_pk_key', array( - 'title' => __('Stripe Test Publishable Key', 'wp-ultimo'), - 'desc' => !empty($pk_test_status) ? sprintf($error_message_wrap, $pk_test_status) : '', - 'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'), - 'placeholder' => __('pk_test_***********', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => 'stripe-checkout', - 'stripe_checkout_sandbox_mode' => 1, - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_checkout_test_pk_key', + array( + 'title' => __('Stripe Test Publishable Key', 'wp-ultimo'), + 'desc' => ! empty($pk_test_status) ? sprintf($error_message_wrap, $pk_test_status) : '', + 'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'), + 'placeholder' => __('pk_test_***********', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => 'stripe-checkout', + 'stripe_checkout_sandbox_mode' => 1, + ), + ) + ); $sk_test_status = wu_get_setting('stripe_checkout_test_sk_key_status', ''); - wu_register_settings_field('payment-gateways', 'stripe_checkout_test_sk_key', array( - 'title' => __('Stripe Test Secret Key', 'wp-ultimo'), - 'desc' => !empty($sk_test_status) ? sprintf($error_message_wrap, $sk_test_status) : '', - 'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'), - 'placeholder' => __('sk_test_***********', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => 'stripe-checkout', - 'stripe_checkout_sandbox_mode' => 1, - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_checkout_test_sk_key', + array( + 'title' => __('Stripe Test Secret Key', 'wp-ultimo'), + 'desc' => ! empty($sk_test_status) ? sprintf($error_message_wrap, $sk_test_status) : '', + 'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'), + 'placeholder' => __('sk_test_***********', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => 'stripe-checkout', + 'stripe_checkout_sandbox_mode' => 1, + ), + ) + ); $pk_status = wu_get_setting('stripe_checkout_live_pk_key_status', ''); - wu_register_settings_field('payment-gateways', 'stripe_checkout_live_pk_key', array( - 'title' => __('Stripe Live Publishable Key', 'wp-ultimo'), - 'desc' => !empty($pk_status) ? sprintf($error_message_wrap, $pk_status) : '', - 'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'), - 'placeholder' => __('pk_live_***********', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => 'stripe-checkout', - 'stripe_checkout_sandbox_mode' => 0, - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_checkout_live_pk_key', + array( + 'title' => __('Stripe Live Publishable Key', 'wp-ultimo'), + 'desc' => ! empty($pk_status) ? sprintf($error_message_wrap, $pk_status) : '', + 'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'), + 'placeholder' => __('pk_live_***********', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => 'stripe-checkout', + 'stripe_checkout_sandbox_mode' => 0, + ), + ) + ); $sk_status = wu_get_setting('stripe_checkout_live_sk_key_status', ''); - wu_register_settings_field('payment-gateways', 'stripe_checkout_live_sk_key', array( - 'title' => __('Stripe Live Secret Key', 'wp-ultimo'), - 'desc' => !empty($sk_status) ? sprintf($error_message_wrap, $sk_status) : '', - 'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'), - 'placeholder' => __('sk_live_***********', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => 'stripe-checkout', - 'stripe_checkout_sandbox_mode' => 0, - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_checkout_live_sk_key', + array( + 'title' => __('Stripe Live Secret Key', 'wp-ultimo'), + 'desc' => ! empty($sk_status) ? sprintf($error_message_wrap, $sk_status) : '', + 'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'), + 'placeholder' => __('sk_live_***********', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => 'stripe-checkout', + 'stripe_checkout_sandbox_mode' => 0, + ), + ) + ); $webhook_message = sprintf('%s', __('Whenever you change your Stripe settings, WP Multisite WaaS will automatically check the webhook URLs on your Stripe account to make sure we get notified about changes in subscriptions and payments.', 'wp-ultimo')); - wu_register_settings_field('payment-gateways', 'stripe_checkout_webhook_listener_explanation', array( - 'title' => __('Webhook Listener URL', 'wp-ultimo'), - 'desc' => $webhook_message, - 'tooltip' => __('This is the URL Stripe should send webhook calls to.', 'wp-ultimo'), - 'type' => 'text-display', - 'copy' => true, - 'default' => $this->get_webhook_listener_url(), - 'wrapper_classes' => '', - 'require' => array( - 'active_gateways' => 'stripe-checkout', - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_checkout_webhook_listener_explanation', + array( + 'title' => __('Webhook Listener URL', 'wp-ultimo'), + 'desc' => $webhook_message, + 'tooltip' => __('This is the URL Stripe should send webhook calls to.', 'wp-ultimo'), + 'type' => 'text-display', + 'copy' => true, + 'default' => $this->get_webhook_listener_url(), + 'wrapper_classes' => '', + 'require' => array( + 'active_gateways' => 'stripe-checkout', + ), + ) + ); parent::settings(); - - } // end settings; + } /** * Run preparations before checkout processing. @@ -211,9 +242,13 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { * For those to work, you'll need to activate them on your * Stripe account, and you should also be in live mode. */ - $allowed_payment_method_types = apply_filters('wu_stripe_checkout_allowed_payment_method_types', array( - 'card', - ), $this); + $allowed_payment_method_types = apply_filters( + 'wu_stripe_checkout_allowed_payment_method_types', + array( + 'card', + ), + $this + ); $metadata = array( 'payment_id' => $this->payment->get_id(), @@ -230,9 +265,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { * Verify the card type */ if ($this->order->get_cart_type() === 'new') { - $redirect_url = $this->get_return_url(); - } else { /* * Saves cart for later swap. @@ -242,8 +275,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { $redirect_url = add_query_arg('swap', $swap_id, $this->get_confirm_url()); $metadata['swap_id'] = $swap_id; - - } // end if; + } $subscription_data = array( 'payment_method_types' => $allowed_payment_method_types, @@ -256,7 +288,6 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { ); if ($this->order->should_auto_renew()) { - $stripe_cart = $this->build_stripe_cart($this->order); $stripe_non_recurring_cart = $this->build_non_recurring_cart($this->order); @@ -266,14 +297,12 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { $subscription_data['subscription_data'] = array( 'items' => array_values($stripe_cart), ); - } else { /* * Create non-recurring only cart. */ $stripe_non_recurring_cart = $this->build_non_recurring_cart($this->order, true); - - } // end if; + } /* * Add non-recurring line items @@ -287,12 +316,10 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { $s_coupon = $this->get_credit_coupon($this->order); if ($s_coupon) { - $subscription_data['discounts'] = array( array('coupon' => $s_coupon), ); - - } // end if; + } /** * If its a downgrade, we need to set as a trial, @@ -300,7 +327,6 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { * (https://stripe.com/docs/api/checkout/sessions/create) */ if ($this->order->get_cart_type() === 'downgrade') { - $next_charge = $this->order->get_billing_next_charge_date(); $next_charge_date = \DateTime::createFromFormat('U', $next_charge); $current_time = new \DateTime(); @@ -311,19 +337,15 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { $next_charge = $next_charge_date->diff($current_time)->days > 2 ? $next_charge : strtotime('+2 days'); $subscription_data['subscription_data']['trial_end'] = $next_charge; - - } // end if; - - } // end if; + } + } /* * Handle trial periods. */ if ($this->order->has_trial() && $this->order->has_recurring()) { - $subscription_data['subscription_data']['trial_end'] = $this->order->get_billing_start_date(); - - } // end if; + } $session = Stripe\Checkout\Session::create($subscription_data); @@ -331,8 +353,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { return array( 'stripe_session_id' => sanitize_text_field($session->id), ); - - } // end run_preflight; + } /** * Handles confirmation windows and extra processing. @@ -353,16 +374,11 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { $membership = $this->payment ? $this->payment->get_membership() : wu_get_membership_by_hash(wu_request('membership')); if ($saved_swap && $membership) { - if ($saved_swap->get_cart_type() === 'downgrade') { - $membership->schedule_swap($saved_swap); - } else { - $membership->swap($saved_swap); - - } // end if; + } $membership->save(); @@ -371,10 +387,8 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { wp_redirect($redirect_url); exit; - - } // end if; - - } // end process_confirmation; + } + } /** * Add credit card fields. * @@ -385,8 +399,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { $message = __('You will be redirected to a checkout to complete the purchase.', 'wp-ultimo'); return sprintf('

    %s

    ', $message); - - } // end fields; + } /** * Returns the payment methods. @@ -401,24 +414,19 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { $card_options = $this->get_saved_card_options(); if ($card_options) { - foreach ($card_options as $payment_method => $card) { - $fields = array( "payment_method_{$payment_method}" => array( 'type' => 'text-display', 'title' => __('Saved Cards', 'wp-ultimo'), 'display_value' => $card, - ) + ), ); - - } // end foreach; - - } // end if; + } + } return $fields; - - } // end payment_methods; + } /** * Get the saved Stripe payment methods for a given user ID. @@ -433,11 +441,9 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { $customer = wu_get_current_customer(); - if (!$customer) { - + if ( ! $customer) { return array(); - - } // end if; + } $customer_id = $customer->get_id(); @@ -447,19 +453,19 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { */ static $existing_payment_methods; - if (!is_null($existing_payment_methods) && array_key_exists($customer_id, $existing_payment_methods)) { - - return $existing_payment_methods[$customer_id]; - - } // end if; + if ( ! is_null($existing_payment_methods) && array_key_exists($customer_id, $existing_payment_methods)) { + return $existing_payment_methods[ $customer_id ]; + } $customer_payment_methods = array(); - $stripe_customer_id = \WP_Ultimo\Models\Membership::query(array( - 'customer_id' => $customer_id, - 'search' => 'cus_*', - 'fields' => array('gateway_customer_id'), - )); + $stripe_customer_id = \WP_Ultimo\Models\Membership::query( + array( + 'customer_id' => $customer_id, + 'search' => 'cus_*', + 'fields' => array('gateway_customer_id'), + ) + ); $stripe_customer_id = current(array_column($stripe_customer_id, 'gateway_customer_id')); @@ -468,27 +474,22 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway { */ $this->setup_api_keys(); - $payment_methods = Stripe\PaymentMethod::all(array( - 'customer' => $stripe_customer_id, - 'type' => 'card' - )); + $payment_methods = Stripe\PaymentMethod::all( + array( + 'customer' => $stripe_customer_id, + 'type' => 'card', + ) + ); foreach ($payment_methods->data as $payment_method) { + $customer_payment_methods[ $payment_method->id ] = $payment_method; + } - $customer_payment_methods[$payment_method->id] = $payment_method; - - } // end foreach; - - $existing_payment_methods[$customer_id] = $customer_payment_methods; - - return $existing_payment_methods[$customer_id]; + $existing_payment_methods[ $customer_id ] = $customer_payment_methods; + return $existing_payment_methods[ $customer_id ]; } catch (\Throwable $exception) { - return array(); - - } // end try; - - } // end get_user_saved_payment_methods; - -} // end class Stripe_Checkout_Gateway; + } + } +} diff --git a/inc/gateways/class-stripe-gateway.php b/inc/gateways/class-stripe-gateway.php index 28c006e..7e46fbe 100644 --- a/inc/gateways/class-stripe-gateway.php +++ b/inc/gateways/class-stripe-gateway.php @@ -11,10 +11,10 @@ namespace WP_Ultimo\Gateways; -use \WP_Ultimo\Database\Payments\Payment_Status; -use \WP_Ultimo\Database\Memberships\Membership_Status; -use \WP_Ultimo\Gateways\Base_Stripe_Gateway; -use \Stripe; +use WP_Ultimo\Database\Payments\Payment_Status; +use WP_Ultimo\Database\Memberships\Membership_Status; +use WP_Ultimo\Gateways\Base_Stripe_Gateway; +use Stripe; // Exit if accessed directly defined('ABSPATH') || exit; @@ -27,11 +27,11 @@ defined('ABSPATH') || exit; class Stripe_Gateway extends Base_Stripe_Gateway { /** - * Holds the ID of a given gateway. - * - * @since 2.0.0 - * @var string - */ + * Holds the ID of a given gateway. + * + * @since 2.0.0 + * @var string + */ protected $id = 'stripe'; /** @@ -44,17 +44,20 @@ class Stripe_Gateway extends Base_Stripe_Gateway { parent::hooks(); - add_filter('wu_customer_payment_methods', function($fields, $customer): array { + add_filter( + 'wu_customer_payment_methods', + function ($fields, $customer): array { - $this->customer = $customer; + $this->customer = $customer; - $extra_fields = $this->payment_methods(); + $extra_fields = $this->payment_methods(); - return array_merge($fields, $extra_fields); - - }, 10, 2); - - } // end hooks; + return array_merge($fields, $extra_fields); + }, + 10, + 2 + ); + } /** * Adds the Stripe Gateway settings to the settings screen. @@ -66,121 +69,152 @@ class Stripe_Gateway extends Base_Stripe_Gateway { $error_message_wrap = '%s'; - wu_register_settings_field('payment-gateways', 'stripe_header', array( - 'title' => __('Stripe', 'wp-ultimo'), - 'desc' => __('Use the settings section below to configure Stripe as a payment method.', 'wp-ultimo'), - 'type' => 'header', - 'show_as_submenu' => true, - 'require' => array( - 'active_gateways' => 'stripe', - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_header', + array( + 'title' => __('Stripe', 'wp-ultimo'), + 'desc' => __('Use the settings section below to configure Stripe as a payment method.', 'wp-ultimo'), + 'type' => 'header', + 'show_as_submenu' => true, + 'require' => array( + 'active_gateways' => 'stripe', + ), + ) + ); - wu_register_settings_field('payment-gateways', 'stripe_public_title', array( - 'title' => __('Stripe Public Name', 'wp-ultimo'), - 'tooltip' => __('The name to display on the payment method selection field. By default, "Credit Card" is used.', 'wp-ultimo'), - 'type' => 'text', - 'default' => __('Credit Card', 'wp-ultimo'), - 'require' => array( - 'active_gateways' => 'stripe', - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_public_title', + array( + 'title' => __('Stripe Public Name', 'wp-ultimo'), + 'tooltip' => __('The name to display on the payment method selection field. By default, "Credit Card" is used.', 'wp-ultimo'), + 'type' => 'text', + 'default' => __('Credit Card', 'wp-ultimo'), + 'require' => array( + 'active_gateways' => 'stripe', + ), + ) + ); - wu_register_settings_field('payment-gateways', 'stripe_sandbox_mode', array( - 'title' => __('Stripe Sandbox Mode', 'wp-ultimo'), - 'desc' => __('Toggle this to put Stripe on sandbox mode. This is useful for testing and making sure Stripe is correctly setup to handle your payments.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - 'html_attr' => array( - 'v-model' => 'stripe_sandbox_mode', - ), - 'require' => array( - 'active_gateways' => 'stripe', - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_sandbox_mode', + array( + 'title' => __('Stripe Sandbox Mode', 'wp-ultimo'), + 'desc' => __('Toggle this to put Stripe on sandbox mode. This is useful for testing and making sure Stripe is correctly setup to handle your payments.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + 'html_attr' => array( + 'v-model' => 'stripe_sandbox_mode', + ), + 'require' => array( + 'active_gateways' => 'stripe', + ), + ) + ); $pk_test_status = wu_get_setting('stripe_test_pk_key_status', ''); - wu_register_settings_field('payment-gateways', 'stripe_test_pk_key', array( - 'title' => __('Stripe Test Publishable Key', 'wp-ultimo'), - 'desc' => !empty($pk_test_status) ? sprintf($error_message_wrap, $pk_test_status) : '', - 'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'), - 'placeholder' => __('pk_test_***********', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => 'stripe', - 'stripe_sandbox_mode' => 1, - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_test_pk_key', + array( + 'title' => __('Stripe Test Publishable Key', 'wp-ultimo'), + 'desc' => ! empty($pk_test_status) ? sprintf($error_message_wrap, $pk_test_status) : '', + 'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'), + 'placeholder' => __('pk_test_***********', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => 'stripe', + 'stripe_sandbox_mode' => 1, + ), + ) + ); $sk_test_status = wu_get_setting('stripe_test_sk_key_status', ''); - wu_register_settings_field('payment-gateways', 'stripe_test_sk_key', array( - 'title' => __('Stripe Test Secret Key', 'wp-ultimo'), - 'desc' => !empty($sk_test_status) ? sprintf($error_message_wrap, $sk_test_status) : '', - 'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'), - 'placeholder' => __('sk_test_***********', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => 'stripe', - 'stripe_sandbox_mode' => 1, - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_test_sk_key', + array( + 'title' => __('Stripe Test Secret Key', 'wp-ultimo'), + 'desc' => ! empty($sk_test_status) ? sprintf($error_message_wrap, $sk_test_status) : '', + 'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'), + 'placeholder' => __('sk_test_***********', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => 'stripe', + 'stripe_sandbox_mode' => 1, + ), + ) + ); $pk_status = wu_get_setting('stripe_live_pk_key_status', ''); - wu_register_settings_field('payment-gateways', 'stripe_live_pk_key', array( - 'title' => __('Stripe Live Publishable Key', 'wp-ultimo'), - 'desc' => !empty($pk_status) ? sprintf($error_message_wrap, $pk_status) : '', - 'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'), - 'placeholder' => __('pk_live_***********', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => 'stripe', - 'stripe_sandbox_mode' => 0, - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_live_pk_key', + array( + 'title' => __('Stripe Live Publishable Key', 'wp-ultimo'), + 'desc' => ! empty($pk_status) ? sprintf($error_message_wrap, $pk_status) : '', + 'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'), + 'placeholder' => __('pk_live_***********', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => 'stripe', + 'stripe_sandbox_mode' => 0, + ), + ) + ); $sk_status = wu_get_setting('stripe_live_sk_key_status', ''); - wu_register_settings_field('payment-gateways', 'stripe_live_sk_key', array( - 'title' => __('Stripe Live Secret Key', 'wp-ultimo'), - 'desc' => !empty($sk_status) ? sprintf($error_message_wrap, $sk_status) : '', - 'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'), - 'placeholder' => __('sk_live_***********', 'wp-ultimo'), - 'type' => 'text', - 'default' => '', - 'capability' => 'manage_api_keys', - 'require' => array( - 'active_gateways' => 'stripe', - 'stripe_sandbox_mode' => 0, - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_live_sk_key', + array( + 'title' => __('Stripe Live Secret Key', 'wp-ultimo'), + 'desc' => ! empty($sk_status) ? sprintf($error_message_wrap, $sk_status) : '', + 'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'), + 'placeholder' => __('sk_live_***********', 'wp-ultimo'), + 'type' => 'text', + 'default' => '', + 'capability' => 'manage_api_keys', + 'require' => array( + 'active_gateways' => 'stripe', + 'stripe_sandbox_mode' => 0, + ), + ) + ); $webhook_message = sprintf('%s', __('Whenever you change your Stripe settings, WP Multisite WaaS will automatically check the webhook URLs on your Stripe account to make sure we get notified about changes in subscriptions and payments.', 'wp-ultimo')); - wu_register_settings_field('payment-gateways', 'stripe_webhook_listener_explanation', array( - 'title' => __('Webhook Listener URL', 'wp-ultimo'), - 'desc' => $webhook_message, - 'tooltip' => __('This is the URL Stripe should send webhook calls to.', 'wp-ultimo'), - 'type' => 'text-display', - 'copy' => true, - 'default' => $this->get_webhook_listener_url(), - 'wrapper_classes' => '', - 'require' => array( - 'active_gateways' => 'stripe', - ), - )); + wu_register_settings_field( + 'payment-gateways', + 'stripe_webhook_listener_explanation', + array( + 'title' => __('Webhook Listener URL', 'wp-ultimo'), + 'desc' => $webhook_message, + 'tooltip' => __('This is the URL Stripe should send webhook calls to.', 'wp-ultimo'), + 'type' => 'text-display', + 'copy' => true, + 'default' => $this->get_webhook_listener_url(), + 'wrapper_classes' => '', + 'require' => array( + 'active_gateways' => 'stripe', + ), + ) + ); parent::settings(); - - } // end settings; + } /** * Run preparations before checkout processing. @@ -224,8 +258,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway { // translators: %s is the error message. return new \WP_Error($s_customer->get_error_code(), sprintf(__('Error creating Stripe customer: %s', 'wp-ultimo'), $s_customer->get_error_message())); - - } // end if; + } $this->membership->set_gateway_customer_id($s_customer->id); $this->membership->set_gateway($this->get_id()); @@ -239,14 +272,10 @@ class Stripe_Gateway extends Base_Stripe_Gateway { * a membership swap. */ if ($type === 'upgrade' || $type === 'addon') { - $this->membership->swap($this->order); - } elseif ($type === 'downgrade') { - $this->membership->schedule_swap($this->order); - - } // end if; + } $this->membership->save(); @@ -260,10 +289,8 @@ class Stripe_Gateway extends Base_Stripe_Gateway { * Maybe use an existing payment method. */ if (wu_request('payment_method', 'add-new') !== 'add-new') { - $intent_args['payment_method'] = sanitize_text_field(wu_request('payment_method')); - - } // end if; + } /* * Let's start with the intent options. @@ -298,31 +325,26 @@ class Stripe_Gateway extends Base_Stripe_Gateway { * payment attached to the membership. Those start with a pi_ * id. */ - if (!empty($payment_intent_id) && strncmp((string) $payment_intent_id, 'pi_', strlen('pi_')) === 0) { - + if ( ! empty($payment_intent_id) && strncmp((string) $payment_intent_id, 'pi_', strlen('pi_')) === 0) { $existing_intent = Stripe\PaymentIntent::retrieve($payment_intent_id); - /* - * Setup intents are created with the intent - * of future charging. This is what we use - * when we set up a subscription without a - * initial amount. - */ - } elseif (!empty($payment_intent_id) && strncmp((string) $payment_intent_id, 'seti_', strlen('seti_')) === 0) { - + /* + * Setup intents are created with the intent + * of future charging. This is what we use + * when we set up a subscription without a + * initial amount. + */ + } elseif ( ! empty($payment_intent_id) && strncmp((string) $payment_intent_id, 'seti_', strlen('seti_')) === 0) { $existing_intent = Stripe\SetupIntent::retrieve($payment_intent_id); - - } // end if; + } /* * We can't use cancelled intents * for obvious reasons... */ - if (!empty($existing_intent) && 'canceled' === $existing_intent->status) { - + if ( ! empty($existing_intent) && 'canceled' === $existing_intent->status) { $existing_intent = false; - - } // end if; + } /* * If we have a initial payment, @@ -331,14 +353,16 @@ class Stripe_Gateway extends Base_Stripe_Gateway { * If we have a trial, we need to deal with that via a setup intent. */ if ($this->order->get_total() && $this->order->has_trial() === false) { - - $intent_args = wp_parse_args($intent_args, array( - 'amount' => $this->order->get_total() * wu_stripe_get_currency_multiplier(), - 'confirmation_method' => 'automatic', - 'setup_future_usage' => 'off_session', - 'currency' => strtolower((string) wu_get_setting('currency_symbol', 'USD')), - 'confirm' => false, - )); + $intent_args = wp_parse_args( + $intent_args, + array( + 'amount' => $this->order->get_total() * wu_stripe_get_currency_multiplier(), + 'confirmation_method' => 'automatic', + 'setup_future_usage' => 'off_session', + 'currency' => strtolower((string) wu_get_setting('currency_symbol', 'USD')), + 'confirm' => false, + ) + ); /** * Filters the payment intent arguments. @@ -351,8 +375,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway { */ $intent_args = apply_filters('wu_stripe_create_payment_intent_args', $intent_args, $this); - if (!empty($existing_intent) && 'payment_intent' === $existing_intent->object) { - + if ( ! empty($existing_intent) && 'payment_intent' === $existing_intent->object) { $idempotency_args = $intent_args; $idempotency_args['update'] = true; @@ -370,75 +393,56 @@ class Stripe_Gateway extends Base_Stripe_Gateway { $unset_args = array('confirmation_method', 'confirm'); foreach ($unset_args as $unset_arg) { - - if (isset($intent_args[$unset_arg])) { - - unset($intent_args[$unset_arg]); - - } // end if; - - } // end foreach; + if (isset($intent_args[ $unset_arg ])) { + unset($intent_args[ $unset_arg ]); + } + } /* * Tries to update the payment intent. */ $intent = Stripe\PaymentIntent::update($existing_intent->id, $intent_args, $intent_options); - } else { - $intent_options['idempotency_key'] = wu_stripe_generate_idempotency_key($intent_args); $intent = Stripe\PaymentIntent::create($intent_args, $intent_options); - - } // end if; - + } } else { /* * Create a setup intent instead. */ - $intent_args = wp_parse_args($intent_args, array( - 'usage' => 'off_session' - )); + $intent_args = wp_parse_args( + $intent_args, + array( + 'usage' => 'off_session', + ) + ); if (empty($existing_intent) || 'setup_intent' !== $existing_intent->object) { - $intent_options['idempotency_key'] = wu_stripe_generate_idempotency_key($intent_args); /* * Tries to create in Stripe. */ $intent = Stripe\SetupIntent::create($intent_args, $intent_options); - - } // end if; - - } // end if; - + } + } } catch (Stripe\Stripe\Error\Base $e) { - return $this->get_stripe_error($e); - } catch (\Exception $e) { - $error_code = $e->getCode(); // WP Error did not handle empty error code if (empty($error_code)) { - if (method_exists($e, 'getHttpStatus')) { - $error_code = $e->getHttpStatus(); - } else { - $error_code = 500; - - } // end if; - - } // end if; + } + } return new \WP_Error($error_code, $e->getMessage()); - - } // end try; + } /* * To prevent re-doing all this @@ -463,8 +467,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway { 'stripe_client_secret' => sanitize_text_field($intent->client_secret), 'stripe_intent_type' => sanitize_text_field($intent->object), ); - - } // end run_preflight; + } /** * Process a checkout. @@ -506,10 +509,8 @@ class Stripe_Gateway extends Base_Stripe_Gateway { $payment_intent_id = $payment->get_meta('stripe_payment_intent_id'); if (empty($payment_intent_id)) { - throw new \Exception(__('Missing Stripe payment intent, please try again or contact support if the issue persists.', 'wp-ultimo'), 'missing_stripe_payment_intent'); - - } // end if; + } /** * Ensure the correct api keys are set @@ -529,16 +530,12 @@ class Stripe_Gateway extends Base_Stripe_Gateway { * type depending on the intent ID */ if (strncmp((string) $payment_intent_id, 'seti_', strlen('seti_')) === 0) { - $is_setup_intent = true; $payment_intent = Stripe\SetupIntent::retrieve($payment_intent_id); - } else { - $payment_intent = Stripe\PaymentIntent::retrieve($payment_intent_id); - - } // end if; + } /* * Retrieves the Stripe Customer @@ -550,25 +547,26 @@ class Stripe_Gateway extends Base_Stripe_Gateway { $description = sprintf(__('Customer ID: %1$d - User Email: %2$s', 'wp-ultimo'), $customer->get_id(), $customer->get_email_address()); if (strlen($description) > 350) { - $description = substr($description, 0, 350); - - } // end if; + } /* * Updates the customer on Stripe * to make sure it always has the most * up-to-date info. */ - Stripe\Customer::update($s_customer->id, array( - 'address' => $this->convert_to_stripe_address($customer->get_billing_address()), - 'description' => sanitize_text_field($description), - 'metadata' => array( - 'email' => $customer->get_email_address(), - 'user_id' => $customer->get_user_id(), - 'customer_id' => $customer->get_id(), - ), - )); + Stripe\Customer::update( + $s_customer->id, + array( + 'address' => $this->convert_to_stripe_address($customer->get_billing_address()), + 'description' => sanitize_text_field($description), + 'metadata' => array( + 'email' => $customer->get_email_address(), + 'user_id' => $customer->get_user_id(), + 'customer_id' => $customer->get_id(), + ), + ) + ); /* * Persist payment methods. @@ -580,26 +578,22 @@ class Stripe_Gateway extends Base_Stripe_Gateway { */ $payment_method = $this->save_payment_method($payment_intent, $s_customer); - $payment_completed = $is_setup_intent || (!empty($payment_intent->charges->data[0]['id']) && 'succeeded' === $payment_intent->charges->data[0]['status']); + $payment_completed = $is_setup_intent || (! empty($payment_intent->charges->data[0]['id']) && 'succeeded' === $payment_intent->charges->data[0]['status']); $subscription = false; if ($payment_completed && $should_auto_renew && $is_recurring) { - $subscription = $this->create_recurring_payment($membership, $cart, $payment_method, $s_customer); - if (!$subscription) { + if ( ! $subscription) { /** * Another process is already taking care of this (webhook). */ return; - - } // end if; - - } // end if; + } + } if ($payment_completed) { - $payment_id = $is_setup_intent ? $payment_intent->id : sanitize_text_field($payment_intent->charges->data[0]['id']); $payment->set_status(Payment_Status::COMPLETED); @@ -608,11 +602,9 @@ class Stripe_Gateway extends Base_Stripe_Gateway { $payment->save(); $this->trigger_payment_processed($payment, $membership); - - } // end if; + } if ($subscription) { - $membership->set_gateway($this->get_id()); $membership->set_gateway_customer_id($s_customer->id); $membership->set_gateway_subscription_id($subscription->id); @@ -620,7 +612,6 @@ class Stripe_Gateway extends Base_Stripe_Gateway { $membership->should_auto_renew(true); if ($type !== 'downgrade') { - $membership_status = $cart->has_trial() ? Membership_Status::TRIALING : Membership_Status::ACTIVE; $renewal_date = new \DateTime(); @@ -630,24 +621,17 @@ class Stripe_Gateway extends Base_Stripe_Gateway { $stripe_estimated_charge_timestamp = $subscription->current_period_end + (2 * HOUR_IN_SECONDS); if ($stripe_estimated_charge_timestamp > $renewal_date->getTimestamp()) { - $renewal_date->setTimestamp($stripe_estimated_charge_timestamp); - - } // end if; + } $expiration = $renewal_date->format('Y-m-d H:i:s'); $membership->renew(true, $membership_status, $expiration); - } else { - $membership->save(); - - } // end if; - - } // end if; - - } // end process_checkout; + } + } + } /** * Add credit card fields. @@ -662,7 +646,6 @@ class Stripe_Gateway extends Base_Stripe_Gateway { $card_options = $this->get_saved_card_options(); if ($card_options) { - $card_options['add-new'] = __('Add new card', 'wp-ultimo'); $fields = array( @@ -674,19 +657,22 @@ class Stripe_Gateway extends Base_Stripe_Gateway { 'html_attr' => array( 'v-model' => 'payment_method', ), - ) - ); - - } // end if; - - $stripe_form = new \WP_Ultimo\UI\Form('billing-address-fields', $fields, array( - 'views' => 'checkout/fields', - 'variables' => array( - 'step' => (object) array( - 'classes' => '', ), - ), - )); + ); + } + + $stripe_form = new \WP_Ultimo\UI\Form( + 'billing-address-fields', + $fields, + array( + 'views' => 'checkout/fields', + 'variables' => array( + 'step' => (object) array( + 'classes' => '', + ), + ), + ) + ); ob_start(); @@ -716,8 +702,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway { // phpcs:enable return ob_get_clean(); - - } // end fields; + } /** * Returns the payment methods. @@ -732,24 +717,19 @@ class Stripe_Gateway extends Base_Stripe_Gateway { $card_options = $this->get_saved_card_options(); if ($card_options) { - foreach ($card_options as $payment_method => $card) { - $fields = array( "payment_method_{$payment_method}" => array( 'type' => 'text-display', 'title' => __('Saved Cards', 'wp-ultimo'), 'display_value' => $card, - ) + ), ); - - } // end foreach; - - } // end if; + } + } return $fields; - - } // end payment_methods; + } /** * Get the saved Stripe payment methods for a given user ID. @@ -764,11 +744,9 @@ class Stripe_Gateway extends Base_Stripe_Gateway { $customer = wu_get_current_customer(); - if (!$customer) { - + if ( ! $customer) { return array(); - - } // end if; + } $customer_id = $customer->get_id(); @@ -778,19 +756,19 @@ class Stripe_Gateway extends Base_Stripe_Gateway { */ static $existing_payment_methods; - if (!is_null($existing_payment_methods) && array_key_exists($customer_id, $existing_payment_methods)) { - - return $existing_payment_methods[$customer_id]; - - } // end if; + if ( ! is_null($existing_payment_methods) && array_key_exists($customer_id, $existing_payment_methods)) { + return $existing_payment_methods[ $customer_id ]; + } $customer_payment_methods = array(); - $stripe_customer_id = \WP_Ultimo\Models\Membership::query(array( - 'customer_id' => $customer_id, - 'search' => 'cus_*', - 'fields' => array('gateway_customer_id'), - )); + $stripe_customer_id = \WP_Ultimo\Models\Membership::query( + array( + 'customer_id' => $customer_id, + 'search' => 'cus_*', + 'fields' => array('gateway_customer_id'), + ) + ); $stripe_customer_id = current(array_column($stripe_customer_id, 'gateway_customer_id')); @@ -799,27 +777,22 @@ class Stripe_Gateway extends Base_Stripe_Gateway { */ $this->setup_api_keys(); - $payment_methods = Stripe\PaymentMethod::all(array( - 'customer' => $stripe_customer_id, - 'type' => 'card' - )); + $payment_methods = Stripe\PaymentMethod::all( + array( + 'customer' => $stripe_customer_id, + 'type' => 'card', + ) + ); foreach ($payment_methods->data as $payment_method) { + $customer_payment_methods[ $payment_method->id ] = $payment_method; + } - $customer_payment_methods[$payment_method->id] = $payment_method; - - } // end foreach; - - $existing_payment_methods[$customer_id] = $customer_payment_methods; - - return $existing_payment_methods[$customer_id]; + $existing_payment_methods[ $customer_id ] = $customer_payment_methods; + return $existing_payment_methods[ $customer_id ]; } catch (\Throwable $exception) { - return array(); - - } // end try; - - } // end get_user_saved_payment_methods; - -} // end class Stripe_Gateway; + } + } +} diff --git a/inc/helpers/class-arr.php b/inc/helpers/class-arr.php index 43f141c..f444ed3 100644 --- a/inc/helpers/class-arr.php +++ b/inc/helpers/class-arr.php @@ -51,21 +51,20 @@ class Arr { */ public static function filter_by_property($array, $property, $expected_value, $flag = 0) { - $result = Arr::filter($array, function($value) use ($property, $expected_value) { + $result = self::filter( + $array, + function ($value) use ($property, $expected_value) { return Arr::get($value, $property, null) == $expected_value; // phpcs:ignore - - }); + } + ); if ($flag) { - - $result = $flag === Arr::RESULTS_FIRST ? reset($result) : end($result); - - } // end if; + $result = $flag === self::RESULTS_FIRST ? reset($result) : end($result); + } return $result; - - } // end filter_by_property; + } /** * Filters an array using a callback. @@ -79,26 +78,19 @@ class Arr { public static function filter($array, $closure) { if ($closure) { - $result = array(); foreach ($array as $key => $value) { - if (call_user_func($closure, $value, $key)) { - $result[] = $value; - - } // end if; - - } // end foreach; + } + } return $result; - - } // end if; + } return array_filter($array); - - } // end filter; + } /** * Get a nested value inside an array. Dot notation is supported. @@ -113,32 +105,23 @@ class Arr { public static function get($array, $key, $default = null) { if (is_null($key)) { - return $array; + } - } // end if; - - if (isset($array[$key])) { - - return $array[$key]; - - } // end if; + if (isset($array[ $key ])) { + return $array[ $key ]; + } foreach (explode('.', $key) as $segment) { - - if (!is_array($array) || !array_key_exists($segment, $array)) { - + if ( ! is_array($array) || ! array_key_exists($segment, $array)) { return $default; + } - } // end if; - - $array = $array[$segment]; - - } // end foreach; + $array = $array[ $segment ]; + } return $array; - - } // end get; + } /** * Set a nested value inside an array. Dot notation is supported. @@ -153,38 +136,30 @@ class Arr { public static function set(&$array, $key, $value) { if (is_null($key)) { - return $array = $value; // phpcs:ignore - - } // end if; + } $keys = explode('.', $key); while (count($keys) > 1) { - $key = array_shift($keys); - if (!isset($array[$key]) || !is_array($array[$key])) { + if ( ! isset($array[ $key ]) || ! is_array($array[ $key ])) { + $array[ $key ] = array(); + } - $array[$key] = array(); + $array =& $array[ $key ]; + } - } // end if; - - $array =& $array[$key]; - - } // end while; - - $array[array_shift($keys)] = $value; + $array[ array_shift($keys) ] = $value; return $array; - - } // end set; + } /** * Static class only. * * @since 2.0.11 */ - private function __construct() {} // end __construct; - -} // end class Arr; + private function __construct() {} +} diff --git a/inc/helpers/class-hash.php b/inc/helpers/class-hash.php index 7fc7682..7615b16 100644 --- a/inc/helpers/class-hash.php +++ b/inc/helpers/class-hash.php @@ -29,7 +29,7 @@ class Hash { /** * Static-only class. */ - private function __construct() {} // end __construct; + private function __construct() {} /** * Encodes a number or ID. Do not use to encode strings. @@ -45,8 +45,7 @@ class Hash { $hasher = new Hashids($group, self::LENGTH, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'); return $hasher->encode($number); - - } // end encode; + } /** * Decodes a hash back into an integer. @@ -62,7 +61,5 @@ class Hash { $hasher = new Hashids($group, 10, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'); return current($hasher->decode($hash)); - - } // end decode; - -} // end class Hash; + } +} diff --git a/inc/helpers/class-screenshot.php b/inc/helpers/class-screenshot.php index 1fa6b66..625e8f9 100644 --- a/inc/helpers/class-screenshot.php +++ b/inc/helpers/class-screenshot.php @@ -22,83 +22,77 @@ defined('ABSPATH') || exit; class Screenshot { /** - * Returns the api link for the screenshot. - * - * @since 2.0.0 - * - * @param string $domain Original site domain. - */ + * Returns the api link for the screenshot. + * + * @since 2.0.0 + * + * @param string $domain Original site domain. + */ public static function api_url($domain): string { return 'https://image.thum.io/get/' . $domain; } - /** - * Takes in a URL and creates it as an attachment. - * - * @since 2.0.0 - * - * @param string $url Image URL to download. - * @return string|false - */ - public static function take_screenshot($url) { + /** + * Takes in a URL and creates it as an attachment. + * + * @since 2.0.0 + * + * @param string $url Image URL to download. + * @return string|false + */ + public static function take_screenshot($url) { $url = self::api_url($url); return self::save_image_from_url($url); - - } // end take_screenshot; - /** - * Downloads the image from the URL. - * - * @since 2.0.0 - * - * @param string $url Image URL to download. - * @return int|false - */ - public static function save_image_from_url($url) { + } + /** + * Downloads the image from the URL. + * + * @since 2.0.0 + * + * @param string $url Image URL to download. + * @return int|false + */ + public static function save_image_from_url($url) { // translators: %s is the API URL. $log_prefix = sprintf(__('Downloading image from "%s":'), $url) . ' '; - $response = wp_remote_get($url, array( - 'timeout' => 50, - )); + $response = wp_remote_get( + $url, + array( + 'timeout' => 50, + ) + ); if (wp_remote_retrieve_response_code($response) !== 200) { - wu_log_add('screenshot-generator', $log_prefix . wp_remote_retrieve_response_message($response), LogLevel::ERROR); return false; - - } // end if; + } if (is_wp_error($response)) { - wu_log_add('screenshot-generator', $log_prefix . $response->get_error_message(), LogLevel::ERROR); return false; - - } // end if; + } /* * Check if the results contain a PNG header. */ if (strncmp($response['body'], "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a", strlen("\x89\x50\x4e\x47\x0d\x0a\x1a\x0a")) !== 0) { - wu_log_add('screenshot-generator', $log_prefix . __('Result is not a PNG file.', 'wp-ultimo'), LogLevel::ERROR); return false; - - } // end if; + } $upload = wp_upload_bits('screenshot-' . gmdate('Y-m-d-H-i-s') . '.png', null, $response['body']); - if (!empty($upload['error'])) { - + if ( ! empty($upload['error'])) { wu_log_add('screenshot-generator', $log_prefix . json_encode($upload['error']), LogLevel::ERROR); return false; - - } // end if; + } $file_path = $upload['file']; $file_name = basename($file_path); @@ -118,7 +112,7 @@ class Screenshot { $attach_id = wp_insert_attachment($post_info, $file_path); // Include image.php - require_once(ABSPATH . 'wp-admin/includes/image.php'); + require_once ABSPATH . 'wp-admin/includes/image.php'; // Define attachment metadata $attach_data = wp_generate_attachment_metadata($attach_id, $file_path); @@ -129,7 +123,5 @@ class Screenshot { wu_log_add('screenshot-generator', $log_prefix . __('Success!', 'wp-ultimo')); return $attach_id; - - } // end save_image_from_url; - -} // end class Screenshot; + } +} diff --git a/inc/helpers/class-sender.php b/inc/helpers/class-sender.php index 472185a..b420fdf 100644 --- a/inc/helpers/class-sender.php +++ b/inc/helpers/class-sender.php @@ -47,8 +47,7 @@ class Sender { $args = wp_parse_args($args, $default_args); return $args; - - } // end parse_args; + } /** * Send an email to one or more users. @@ -62,25 +61,23 @@ class Sender { */ public static function send_mail($from = array(), $to = array(), $args = array()) { - if (!$from) { - + if ( ! $from) { $from = array( 'email' => wu_get_setting('from_email'), 'name' => wu_get_setting('from_name'), ); + } - } // end if; - - $args = Sender::parse_args($args); + $args = self::parse_args($args); /* * First, replace shortcodes. */ $payload = wu_get_isset($args, 'payload', array()); - $subject = Sender::process_shortcodes(wu_get_isset($args, 'subject', ''), $payload); + $subject = self::process_shortcodes(wu_get_isset($args, 'subject', ''), $payload); - $content = Sender::process_shortcodes(wu_get_isset($args, 'content', ''), $payload); + $content = self::process_shortcodes(wu_get_isset($args, 'content', ''), $payload); /* * Content type and template @@ -88,7 +85,6 @@ class Sender { $headers = array(); if (wu_get_isset($args, 'style', 'html') === 'html') { - $headers[] = 'Content-Type: text/html; charset=UTF-8'; $default_settings = \WP_Ultimo\Admin_Pages\Email_Template_Customize_Admin_Page::get_default_settings(); @@ -97,23 +93,24 @@ class Sender { $template_settings = wp_parse_args($template_settings, $default_settings); - $template = wu_get_template_contents('broadcast/emails/base', array( - 'site_name' => get_network_option(null, 'site_name'), - 'site_url' => get_site_url(wu_get_main_site_id()), - 'logo_url' => wu_get_network_logo(), - 'is_editor' => false, - 'subject' => $subject, - 'content' => $content, - 'template_settings' => $template_settings, - )); - + $template = wu_get_template_contents( + 'broadcast/emails/base', + array( + 'site_name' => get_network_option(null, 'site_name'), + 'site_url' => get_site_url(wu_get_main_site_id()), + 'logo_url' => wu_get_network_logo(), + 'is_editor' => false, + 'subject' => $subject, + 'content' => $content, + 'template_settings' => $template_settings, + ) + ); } else { - $headers[] = 'Content-Type: text/html; charset=UTF-8'; $template = nl2br(strip_tags($content, '


    ')); // by default, set the plain email content. - } // end if; + } $bcc = ''; @@ -121,7 +118,6 @@ class Sender { * Build the recipients list. */ if (count($to) > 1) { - $to = array_map(fn($item) => wu_format_email_string(wu_get_isset($item, 'email'), wu_get_isset($item, 'name')), $to); /* @@ -132,36 +128,33 @@ class Sender { * emails sent out. */ if (apply_filters('wu_sender_recipients_strategy', 'bcc') === 'bcc') { - $main_to = $to[0]; unset($to[0]); - $bcc_array = array_map(function($item) { + $bcc_array = array_map( + function ($item) { - $email = is_array($item) ? $item['email'] : $item; + $email = is_array($item) ? $item['email'] : $item; - preg_match('/<([^>]+)>/', $email, $matches); + preg_match('/<([^>]+)>/', $email, $matches); - return !empty($matches[1]) ? $matches[1] : $email; - - }, $to); + return ! empty($matches[1]) ? $matches[1] : $email; + }, + $to + ); $bcc = implode(', ', array_filter($bcc_array)); $headers[] = "Bcc: $bcc"; $to = $main_to; - - } // end if; - + } } else { - $to = array( - wu_format_email_string(wu_get_isset($to[0], 'email'), wu_get_isset($to[0], 'name')) + wu_format_email_string(wu_get_isset($to[0], 'email'), wu_get_isset($to[0], 'name')), ); - - } // end if; + } /* * Build From @@ -184,12 +177,11 @@ class Sender { // 'attachments' => $attachments, // )); - // } // end if; + // } // Send the actual email return wp_mail($to, $subject, $template, $headers, $attachments); - - } // end send_mail; + } /** * Change the shortcodes for values in the content. @@ -203,10 +195,8 @@ class Sender { public static function process_shortcodes($content, $payload = array()) { if (empty($payload)) { - return $content; - - } // end if; + } $match = array(); @@ -215,15 +205,11 @@ class Sender { $shortcodes = shortcode_atts(array_flip($match[1]), $payload); foreach ($shortcodes as $shortcode_key => $shortcode_value) { - $shortcode_str = '{{' . $shortcode_key . '}}'; $content = str_replace($shortcode_str, nl2br((string) $shortcode_value), $content); - - } // end foreach; + } return $content; - - } // end process_shortcodes; - -} // end class Sender; + } +} diff --git a/inc/helpers/class-site-duplicator.php b/inc/helpers/class-site-duplicator.php index 1ed9ab3..c0285b6 100644 --- a/inc/helpers/class-site-duplicator.php +++ b/inc/helpers/class-site-duplicator.php @@ -16,11 +16,9 @@ defined('ABSPATH') || exit; require_once WP_ULTIMO_PLUGIN_DIR . '/inc/duplication/duplicate.php'; -if (!defined('MUCD_PRIMARY_SITE_ID')) { - +if ( ! defined('MUCD_PRIMARY_SITE_ID')) { define('MUCD_PRIMARY_SITE_ID', get_current_network_id()); // phpcs:ignore - -} // end if; +} /** * Exposes the public API to handle site duplication. @@ -36,7 +34,7 @@ class Site_Duplicator { /** * Static-only class. */ - private function __construct() {} // end __construct; + private function __construct() {} /** * Duplicate an existing network site. @@ -53,7 +51,7 @@ class Site_Duplicator { $args['from_site_id'] = $from_site_id; $args['title'] = $title; - $duplicate_site = Site_Duplicator::process_duplication($args); + $duplicate_site = self::process_duplication($args); if (is_wp_error($duplicate_site)) { @@ -63,8 +61,7 @@ class Site_Duplicator { wu_log_add('site-duplication', $message, LogLevel::ERROR); return $duplicate_site; - - } // end if; + } // translators: %1$d is the ID of the site template used, and %2$d is the id of the new site. $message = sprintf(__('Attempt to duplicate site %1$d successful - New site id: %2$d', 'wp-ultimo'), $from_site_id, $duplicate_site); @@ -72,8 +69,7 @@ class Site_Duplicator { wu_log_add('site-duplication', $message); return $duplicate_site; - - } // end duplicate_site; + } /** * Replace the contents of a site with the contents of another. @@ -95,14 +91,17 @@ class Site_Duplicator { $to_site_customer = $to_site_membership->get_customer(); - $args = wp_parse_args($args, array( - 'email' => $to_site_customer->get_email_address(), - 'title' => $to_site->get_title(), - 'path' => $to_site->get_path(), - 'from_site_id' => $from_site_id, - 'to_site_id' => $to_site_id, - 'meta' => $to_site->meta - )); + $args = wp_parse_args( + $args, + array( + 'email' => $to_site_customer->get_email_address(), + 'title' => $to_site->get_title(), + 'path' => $to_site->get_path(), + 'from_site_id' => $from_site_id, + 'to_site_id' => $to_site_id, + 'meta' => $to_site->meta, + ) + ); $duplicate_site_id = self::process_duplication($args); @@ -114,8 +113,7 @@ class Site_Duplicator { wu_log_add('site-duplication', $message, LogLevel::ERROR); return false; - - } // end if; + } $new_to_site = wu_get_site($duplicate_site_id); @@ -139,10 +137,8 @@ class Site_Duplicator { wu_log_add('site-duplication', $message); return $saved; - - } // end if; - - } // end override_site; + } + } /** * Processes a site duplication. @@ -166,20 +162,23 @@ class Site_Duplicator { global $current_site, $wpdb; - $args = wp_parse_args($args, array( - 'email' => '', // Required arguments. - 'title' => '', // Required arguments. - 'path' => '/', // Required arguments. - 'from_site_id' => false, // Required arguments. - 'to_site_id' => false, - 'keep_users' => true, - 'public' => true, - 'domain' => $current_site->domain, - 'copy_files' => wu_get_setting('copy_media', true), - 'network_id' => get_current_network_id(), - 'meta' => array(), - 'user_id' => 0, - )); + $args = wp_parse_args( + $args, + array( + 'email' => '', // Required arguments. + 'title' => '', // Required arguments. + 'path' => '/', // Required arguments. + 'from_site_id' => false, // Required arguments. + 'to_site_id' => false, + 'keep_users' => true, + 'public' => true, + 'domain' => $current_site->domain, + 'copy_files' => wu_get_setting('copy_media', true), + 'network_id' => get_current_network_id(), + 'meta' => array(), + 'user_id' => 0, + ) + ); // Checks $args = (object) $args; @@ -188,55 +187,41 @@ class Site_Duplicator { $wpdb->hide_errors(); - if (!$args->from_site_id) { - + if ( ! $args->from_site_id) { return new \WP_Error('from_site_id_required', __('You need to provide a valid site to duplicate.', 'wp-ultimo')); + } - } // end if; - - $user_id = !empty($args->user_id) ? $args->user_id : self::create_admin($args->email, $site_domain); + $user_id = ! empty($args->user_id) ? $args->user_id : self::create_admin($args->email, $site_domain); if (is_wp_error($user_id)) { - return $user_id; + } - } // end if; - - if (!$args->to_site_id) { - + if ( ! $args->to_site_id) { $meta = array_merge($args->meta, array('public' => $args->public)); $args->to_site_id = wpmu_create_blog($args->domain, $args->path, $args->title, $user_id, $meta, $args->network_id); $wpdb->show_errors(); - - } // end if; + } if (is_wp_error($args->to_site_id)) { - return $args->to_site_id; + } - } // end if; - - if (!is_numeric($args->to_site_id)) { - + if ( ! is_numeric($args->to_site_id)) { return new \WP_Error('site_creation_failed', __('An attempt to create a new site failed.', 'wp-ultimo')); + } - } // end if; - - if (!is_super_admin($user_id) && !get_user_option('primary_blog', $user_id)) { - + if ( ! is_super_admin($user_id) && ! get_user_option('primary_blog', $user_id)) { update_user_option($user_id, 'primary_blog', $args->to_site_id, true); - - } // end if; + } \MUCD_Duplicate::bypass_server_limit(); if ($args->copy_files) { - $result = \MUCD_Files::copy_files($args->from_site_id, $args->to_site_id); - - } // end if; + } /** * Supress email change notification on site duplication processes. @@ -246,10 +231,8 @@ class Site_Duplicator { $result = \MUCD_Data::copy_data($args->from_site_id, $args->to_site_id); if ($args->keep_users) { - $result = \MUCD_Duplicate::copy_users($args->from_site_id, $args->to_site_id); - - } // end if; + } wp_cache_flush(); @@ -259,13 +242,15 @@ class Site_Duplicator { * @since 1.9.4 * @return void */ - do_action('wu_duplicate_site', array( - 'site_id' => $args->to_site_id, - )); + do_action( + 'wu_duplicate_site', + array( + 'site_id' => $args->to_site_id, + ) + ); return $args->to_site_id; - - } // end process_duplication; + } /** * Creates an admin user if no user exists with this email. @@ -282,26 +267,19 @@ class Site_Duplicator { $user_id = email_exists($email); - if (!$user_id) { // Create a new user with a random password + if ( ! $user_id) { // Create a new user with a random password $password = wp_generate_password(12, false); $user_id = wpmu_create_user($domain, $password, $email); if (false === $user_id) { - return new \WP_Error('user_creation_error', __('We were not able to create a new admin user for the site being duplicated.', 'wp-ultimo')); - } else { - wp_new_user_notification($user_id); - - } // end if; - - } // end if; + } + } return $user_id; - - } // end create_admin; - -} // end class Site_Duplicator; + } +} diff --git a/inc/helpers/class-validator.php b/inc/helpers/class-validator.php index 47bd1b6..181c69f 100644 --- a/inc/helpers/class-validator.php +++ b/inc/helpers/class-validator.php @@ -9,18 +9,18 @@ namespace WP_Ultimo\Helpers; -use \Rakit\Validation\Validator as Validator_Helper; -use \WP_Ultimo\Helpers\Validation_Rules\Unique; -use \WP_Ultimo\Helpers\Validation_Rules\Unique_Site; -use \WP_Ultimo\Helpers\Validation_Rules\Exists; -use \WP_Ultimo\Helpers\Validation_Rules\Checkout_Steps; -use \WP_Ultimo\Helpers\Validation_Rules\Price_Variations; -use \WP_Ultimo\Helpers\Validation_Rules\Domain; -use \WP_Ultimo\Helpers\Validation_Rules\Site_Template; -use \WP_Ultimo\Helpers\Validation_Rules\Products; -use \WP_Ultimo\Helpers\Validation_Rules\Country; -use \WP_Ultimo\Helpers\Validation_Rules\State; -use \WP_Ultimo\Helpers\Validation_Rules\City; +use Rakit\Validation\Validator as Validator_Helper; +use WP_Ultimo\Helpers\Validation_Rules\Unique; +use WP_Ultimo\Helpers\Validation_Rules\Unique_Site; +use WP_Ultimo\Helpers\Validation_Rules\Exists; +use WP_Ultimo\Helpers\Validation_Rules\Checkout_Steps; +use WP_Ultimo\Helpers\Validation_Rules\Price_Variations; +use WP_Ultimo\Helpers\Validation_Rules\Domain; +use WP_Ultimo\Helpers\Validation_Rules\Site_Template; +use WP_Ultimo\Helpers\Validation_Rules\Products; +use WP_Ultimo\Helpers\Validation_Rules\Country; +use WP_Ultimo\Helpers\Validation_Rules\State; +use WP_Ultimo\Helpers\Validation_Rules\City; // Exit if accessed directly defined('ABSPATH') || exit; @@ -66,44 +66,49 @@ class Validator { // translators: %s is the field name. $field_required_message = sprintf(__('The %s field is required', 'wp-ultimo'), ':attribute'); - $validation_error_messages = apply_filters('wu_validator_error_messages', array( - 'required' => $field_required_message, - 'required_without' => $field_required_message, - 'required_with' => $field_required_message, - // translators: %s is the email field identifier - 'email' => sprintf(__('The %s is not valid email', 'wp-ultimo'), ':attribute'), - // translators: 1st %s is the field name; 2nd is the allowed value - 'min' => sprintf(__('The %1$s minimum is %2$s', 'wp-ultimo'), ':attribute', ':min'), - // translators: 1st %s is the field name; 2nd is the allowed value - 'max' => sprintf(__('The %1$s maximum is %2$s', 'wp-ultimo'), ':attribute', ':max'), - // translators: %s is the field identifier - 'alpha_dash' => sprintf(__('The %s only allows a-z, 0-9, _ and -', 'wp-ultimo'), ':attribute'), - // translators: %s is the field identifier - 'lowercase' => sprintf(__('The %s must be lowercase', 'wp-ultimo'), ':attribute'), - // translators: %s is the field identifier - 'integer' => sprintf(__('The %s must be integer', 'wp-ultimo'), ':attribute') - ), $this); + $validation_error_messages = apply_filters( + 'wu_validator_error_messages', + array( + 'required' => $field_required_message, + 'required_without' => $field_required_message, + 'required_with' => $field_required_message, + // translators: %s is the email field identifier + 'email' => sprintf(__('The %s is not valid email', 'wp-ultimo'), ':attribute'), + // translators: 1st %s is the field name; 2nd is the allowed value + 'min' => sprintf(__('The %1$s minimum is %2$s', 'wp-ultimo'), ':attribute', ':min'), + // translators: 1st %s is the field name; 2nd is the allowed value + 'max' => sprintf(__('The %1$s maximum is %2$s', 'wp-ultimo'), ':attribute', ':max'), + // translators: %s is the field identifier + 'alpha_dash' => sprintf(__('The %s only allows a-z, 0-9, _ and -', 'wp-ultimo'), ':attribute'), + // translators: %s is the field identifier + 'lowercase' => sprintf(__('The %s must be lowercase', 'wp-ultimo'), ':attribute'), + // translators: %s is the field identifier + 'integer' => sprintf(__('The %s must be integer', 'wp-ultimo'), ':attribute'), + ), + $this + ); $this->validator = new Validator_Helper($validation_error_messages); - $this->validator->setTranslations(array( - 'and' => __('and', 'wp-ultimo'), - 'or' => __('or', 'wp-ultimo'), - )); + $this->validator->setTranslations( + array( + 'and' => __('and', 'wp-ultimo'), + 'or' => __('or', 'wp-ultimo'), + ) + ); - $this->validator->addValidator('unique', new Unique); - $this->validator->addValidator('unique_site', new Unique_Site); - $this->validator->addValidator('exists', new Exists); - $this->validator->addValidator('checkout_steps', new Checkout_Steps); - $this->validator->addValidator('price_variations', new Price_Variations); - $this->validator->addValidator('domain', new Domain); - $this->validator->addValidator('site_template', new Site_Template); - $this->validator->addValidator('products', new Products); - $this->validator->addValidator('country', new Country); - $this->validator->addValidator('state', new State); - $this->validator->addValidator('city', new City); - - } // end __construct; + $this->validator->addValidator('unique', new Unique()); + $this->validator->addValidator('unique_site', new Unique_Site()); + $this->validator->addValidator('exists', new Exists()); + $this->validator->addValidator('checkout_steps', new Checkout_Steps()); + $this->validator->addValidator('price_variations', new Price_Variations()); + $this->validator->addValidator('domain', new Domain()); + $this->validator->addValidator('site_template', new Site_Template()); + $this->validator->addValidator('products', new Products()); + $this->validator->addValidator('country', new Country()); + $this->validator->addValidator('state', new State()); + $this->validator->addValidator('city', new City()); + } /** * Validates the data passed according to the rules passed. @@ -118,7 +123,7 @@ class Validator { */ public function validate($data, $rules = array(), $aliases = array()) { - $this->errors = new \WP_Error; + $this->errors = new \WP_Error(); $this->validation = $this->validator->make($data, $rules); @@ -127,8 +132,7 @@ class Validator { $this->validation->validate(); return $this; - - } // end validate; + } /** * Returns true when the validation fails. @@ -139,8 +143,7 @@ class Validator { public function fails() { return $this->validation->fails(); - - } // end fails; + } /** * Returns a WP_Error object containing all validation errors. @@ -155,8 +158,7 @@ class Validator { $this->cast_to_wp_error($errors); return $this->errors; - - } // end get_errors; + } /** * Converts the native error structure to a WP_Error object. @@ -169,16 +171,11 @@ class Validator { protected function cast_to_wp_error($errors) { foreach ($errors as $key => $error_messages) { - foreach ($error_messages as $error_message) { - $this->errors->add($key, $error_message); - - } // end foreach; - - } // end foreach; - - } // end cast_to_wp_error; + } + } + } /** * Get holds an instance of the validation being performed. @@ -189,7 +186,5 @@ class Validator { public function get_validation() { return $this->validation; - - } // end get_validation; - -} // end class Validator; + } +} diff --git a/inc/helpers/class-wp-config.php b/inc/helpers/class-wp-config.php index 1cae6b7..b666390 100644 --- a/inc/helpers/class-wp-config.php +++ b/inc/helpers/class-wp-config.php @@ -22,24 +22,23 @@ class WP_Config { use \WP_Ultimo\Traits\Singleton; /** - * Inject the constant into the wp-config.php file. - * - * @since 2.0.0 - * - * @param string $constant The name of the constant. e.g. WP_ULTIMO_CONSTANT. - * @param string|int $value The value of that constant. - * @return bool|\WP_Error - */ - public function inject_wp_config_constant($constant, $value) { + * Inject the constant into the wp-config.php file. + * + * @since 2.0.0 + * + * @param string $constant The name of the constant. e.g. WP_ULTIMO_CONSTANT. + * @param string|int $value The value of that constant. + * @return bool|\WP_Error + */ + public function inject_wp_config_constant($constant, $value) { $config_path = $this->get_wp_config_path(); - if (!is_writeable($config_path)) { + if ( ! is_writeable($config_path)) { // translators: %s is the file name. return new \WP_Error('not-writeable', sprintf(__('The file %s is not writable', 'wp-ultimo'), $config_path)); - - } // end if; + } $config = file($config_path); @@ -53,32 +52,24 @@ class WP_Config { $hook_line = $this->find_reference_hook_line($config); if ($hook_line === false) { - return new \WP_Error('unknown-wpconfig', __("WP Multisite WaaS can't recognize your wp-config.php, please revert it to original state for further process.", 'wp-ultimo')); - - } // end if; + } $config = $this->inject_contents($config, $hook_line + 1, PHP_EOL . $content . PHP_EOL); return file_put_contents($config_path, implode('', $config), LOCK_EX); - } else { - list($value, $line) = $line; if ($value !== true) { - - $config[$line] = $content . PHP_EOL; + $config[ $line ] = $content . PHP_EOL; return file_put_contents($config_path, implode('', $config), LOCK_EX); - - } // end if; - - } // end if; + } + } return false; - - } // end inject_wp_config_constant; + } /** * Actually inserts the new lines into the array of wp-config.php lines. @@ -92,17 +83,14 @@ class WP_Config { */ public function inject_contents($content_array, $line, $value) { - if (!is_array($value)) { - + if ( ! is_array($value)) { $value = array($value); - - } // end if; + } array_splice($content_array, $line, 0, $value); return $content_array; - - } // end inject_contents; + } /** * Gets the correct path to the wp-config.php file. @@ -113,20 +101,13 @@ class WP_Config { public function get_wp_config_path() { if (file_exists(ABSPATH . 'wp-config.php')) { - return (ABSPATH . 'wp-config.php'); - - } elseif (@file_exists(dirname(ABSPATH) . '/wp-config.php') && !@file_exists(dirname(ABSPATH) . '/wp-settings.php')) { - + } elseif (@file_exists(dirname(ABSPATH) . '/wp-config.php') && ! @file_exists(dirname(ABSPATH) . '/wp-settings.php')) { return (dirname(ABSPATH) . '/wp-config.php'); - } elseif (defined('WP_TESTS_MULTISITE') && constant('WP_TESTS_MULTISITE') === true) { - return '/tmp/wordpress-tests-lib/wp-tests-config.php'; - - } // end if; - - } // end get_wp_config_path; + } + } /** * Find reference line for injection. @@ -159,34 +140,30 @@ class WP_Config { * A negative number of lines can be passed to write before the found line, * instead of writing after it. */ - $patterns = apply_filters('wu_wp_config_reference_hook_line_patterns', array( - '/^\$table_prefix\s*=\s*[\'|\"]' . $wpdb->prefix . '[\'|\"]/' => 0, - '/^( ){0,}\$table_prefix\s*=.*[\'|\"]' . $wpdb->prefix . '[\'|\"]/' => 0, - '/(\/\* That\'s all, stop editing! Happy publishing\. \*\/)/' => -2, - '/<\?php/' => 0, - )); + $patterns = apply_filters( + 'wu_wp_config_reference_hook_line_patterns', + array( + '/^\$table_prefix\s*=\s*[\'|\"]' . $wpdb->prefix . '[\'|\"]/' => 0, + '/^( ){0,}\$table_prefix\s*=.*[\'|\"]' . $wpdb->prefix . '[\'|\"]/' => 0, + '/(\/\* That\'s all, stop editing! Happy publishing\. \*\/)/' => -2, + '/<\?php/' => 0, + ) + ); $line = 1; foreach ($patterns as $pattern => $lines_to_add) { - foreach ($config as $k => $line) { - if (preg_match($pattern, (string) $line)) { - $line = $k + $lines_to_add; break 2; - - } // end if; - - } // end foreach; - - } // end foreach; + } + } + } return $line; - - } // end find_reference_hook_line; + } /** * Revert the injection of a constant in wp-config.php @@ -200,23 +177,19 @@ class WP_Config { $config_path = $this->get_wp_config_path(); - if (!is_writeable($config_path)) { + if ( ! is_writeable($config_path)) { // translators: %s is the file name. return new \WP_Error('not-writeable', sprintf(__('The file %s is not writable', 'wp-ultimo'), $config_path)); - - } // end if; + } $config = file($config_path); $line = $this->find_injected_line($config, $constant); if ($line === false) { - return; - } else { - $value = $line[0]; $line = $line[1]; @@ -224,41 +197,32 @@ class WP_Config { if ($value === 'true' || $value === '1') { // value is true, we will remove this - unset($config[$line]); + unset($config[ $line ]); // save it return file_put_contents($config_path, implode('', $config), LOCK_EX); - - } // end if; - - } // end if; - - } // end revert; - /** - * Checks for the injected line inside of the wp-config.php file. - * - * @since 2.0.0 - * - * @param array $config Array containing the lines of the config file, for searching. - * @param string $constant The constant name. - * @return mixed[]|bool - */ - public function find_injected_line($config, $constant) { + } + } + } + /** + * Checks for the injected line inside of the wp-config.php file. + * + * @since 2.0.0 + * + * @param array $config Array containing the lines of the config file, for searching. + * @param string $constant The constant name. + * @return mixed[]|bool + */ + public function find_injected_line($config, $constant) { $pattern = "/^define\(\s*['|\"]" . $constant . "['|\"],(.*)\)/"; foreach ($config as $k => $line) { - if (preg_match($pattern, (string) $line, $matches)) { - return array(trim($matches[1]), $k); - - } // end if; - - } // end foreach; + } + } return false; - - } // end find_injected_line; - -} // end class WP_Config; + } +} diff --git a/inc/helpers/validation-rules/class-checkout-steps.php b/inc/helpers/validation-rules/class-checkout-steps.php index 83393ab..fbf0c20 100644 --- a/inc/helpers/validation-rules/class-checkout-steps.php +++ b/inc/helpers/validation-rules/class-checkout-steps.php @@ -50,7 +50,7 @@ class Checkout_Steps extends Rule { $value = maybe_unserialize($value); - } // end if; + } $required_fields = Signup_Fields_Manager::get_instance()->get_required_fields(); @@ -60,7 +60,7 @@ class Checkout_Steps extends Rule { return true; - } // end if; + } $fields = array_column($value, 'fields'); @@ -68,7 +68,7 @@ class Checkout_Steps extends Rule { return true; - } // end if; + } $all_fields = call_user_func_array('array_merge', $fields); @@ -87,9 +87,9 @@ class Checkout_Steps extends Rule { return false; - } // end if; + } - } // end if; + } /** * Allow developers to bypass the check if a field is auto-submittable. @@ -124,9 +124,9 @@ class Checkout_Steps extends Rule { return false; - } // end if; + } - } // end foreach; + } /* * @todo: Plan, product selection fields must come before the order summary and payment fields. @@ -134,6 +134,6 @@ class Checkout_Steps extends Rule { return true; - } // end check; + } -} // end class Checkout_Steps; +} diff --git a/inc/helpers/validation-rules/class-city.php b/inc/helpers/validation-rules/class-city.php index 727066f..ba15212 100644 --- a/inc/helpers/validation-rules/class-city.php +++ b/inc/helpers/validation-rules/class-city.php @@ -44,21 +44,15 @@ class City extends Rule { $state = $this->parameter('state') ?? wu_request('billing_state'); if ($country && $state && $city) { - $state = strtoupper((string) $state); $allowed_cities = wu_get_country_cities(strtoupper((string) $country), $state, false); - if (!empty($allowed_cities)) { - + if (! empty($allowed_cities)) { $check = in_array($city, $allowed_cities, true); - - } // end if; - - } // end if; + } + } return $check; - - } // end check; - -} // end class City; + } +} diff --git a/inc/helpers/validation-rules/class-country.php b/inc/helpers/validation-rules/class-country.php index 96c990b..6744f11 100644 --- a/inc/helpers/validation-rules/class-country.php +++ b/inc/helpers/validation-rules/class-country.php @@ -35,22 +35,18 @@ class Country extends Rule { * * @param mixed $country The country value detected. */ - public function check($country) : bool { // phpcs:ignore + public function check($country) : bool { // phpcs:ignore $check = true; if ($country) { - $country = strtoupper((string) $country); $allowed_countries = array_keys(wu_get_countries()); $check = in_array($country, $allowed_countries, true); - - } // end if; + } return $check; - - } // end check; - -} // end class Country; + } +} diff --git a/inc/helpers/validation-rules/class-domain.php b/inc/helpers/validation-rules/class-domain.php index e1e1f6a..6c66b76 100644 --- a/inc/helpers/validation-rules/class-domain.php +++ b/inc/helpers/validation-rules/class-domain.php @@ -46,7 +46,5 @@ class Domain extends Rule { public function check($value) : bool { // phpcs:ignore return (bool) preg_match('/^(?!\-)(?:(?:[a-zA-Z\d][a-zA-Z\d\-]{0,61})?[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$/', (string) $value); - - } // end check; - -} // end class Domain; + } +} diff --git a/inc/helpers/validation-rules/class-exists.php b/inc/helpers/validation-rules/class-exists.php index 47cc190..1fa0102 100644 --- a/inc/helpers/validation-rules/class-exists.php +++ b/inc/helpers/validation-rules/class-exists.php @@ -44,19 +44,19 @@ class Exists extends Rule { * * @param mixed $value Value being checked. */ - public function check($value) : bool { + public function check($value): bool { - $this->requireParameters(array( - 'model', - 'column' - )); + $this->requireParameters( + array( + 'model', + 'column', + ) + ); $column = $this->parameter('column'); $model = $this->parameter('model'); // do query - return !!$model::get_by($column, $value); - - } // end check; - -} // end class Exists; + return (bool) $model::get_by($column, $value); + } +} diff --git a/inc/helpers/validation-rules/class-price-variations.php b/inc/helpers/validation-rules/class-price-variations.php index d3fb5ab..9e7cb2d 100644 --- a/inc/helpers/validation-rules/class-price-variations.php +++ b/inc/helpers/validation-rules/class-price-variations.php @@ -49,13 +49,13 @@ class Price_Variations extends Rule { $value = maybe_unserialize($value); - } // end if; + } if (!is_array($value)) { return false; - } // end if; + } foreach ($value as $price_variation) { @@ -68,7 +68,7 @@ class Price_Variations extends Rule { return false; - } // end if; + } /** * Validation Unit @@ -86,7 +86,7 @@ class Price_Variations extends Rule { return false; - } // end if; + } /** * Check if it is the same as the main duration @@ -97,7 +97,7 @@ class Price_Variations extends Rule { return false; - } // end if; + } /** * Validation Amount @@ -108,18 +108,18 @@ class Price_Variations extends Rule { $amount = wu_to_float($amount); - } // end if; + } if (!is_numeric($amount)) { return false; - } // end if; + } - } // end foreach; + } return true; - } // end check; + } -} // end class Price_Variations; +} diff --git a/inc/helpers/validation-rules/class-products.php b/inc/helpers/validation-rules/class-products.php index 8b81b1d..20f470c 100644 --- a/inc/helpers/validation-rules/class-products.php +++ b/inc/helpers/validation-rules/class-products.php @@ -43,7 +43,7 @@ class Products extends Rule { * * @param mixed $products Value being checked. */ - public function check($products) : bool { // phpcs:ignore + public function check($products) : bool { // phpcs:ignore $products = (array) $products; @@ -52,15 +52,11 @@ class Products extends Rule { list($plan, $additional_products) = wu_segregate_products($product_objects); if ($plan) { - return true; - - } // end if; + } $this->message = __('A plan is required.', 'wp-ultimo'); return false; - - } // end check; - -} // end class Products; + } +} diff --git a/inc/helpers/validation-rules/class-site-template.php b/inc/helpers/validation-rules/class-site-template.php index ac4e1a1..fd09dd7 100644 --- a/inc/helpers/validation-rules/class-site-template.php +++ b/inc/helpers/validation-rules/class-site-template.php @@ -9,9 +9,9 @@ namespace WP_Ultimo\Helpers\Validation_Rules; -use \Rakit\Validation\Rule; -use \WP_Ultimo\Checkout\Checkout; -use \WP_Ultimo\Database\Sites\Site_Type; +use Rakit\Validation\Rule; +use WP_Ultimo\Checkout\Checkout; +use WP_Ultimo\Database\Sites\Site_Type; // Exit if accessed directly defined('ABSPATH') || exit; @@ -45,49 +45,39 @@ class Site_Template extends Rule { * * @param mixed $template_id Value being checked. */ - public function check($template_id) : bool { // phpcs:ignore + public function check($template_id) : bool { // phpcs:ignore $template_id = absint($template_id); - if (!$template_id) { - + if (! $template_id) { return true; - - } // end if; + } $site = wu_get_site($template_id); - if (!$site || ($site->get_type() !== Site_Type::SITE_TEMPLATE && $site->get_type() !== Site_Type::CUSTOMER_OWNED)) { - + if (! $site || ($site->get_type() !== Site_Type::SITE_TEMPLATE && $site->get_type() !== Site_Type::CUSTOMER_OWNED)) { $this->message = __('The Template ID does not correspond to a valid Template', 'wp-ultimo'); return false; - - } // end if; + } if ($site->get_type() === Site_Type::CUSTOMER_OWNED) { - - if (!wu_get_setting('allow_own_site_as_template')) { - + if (! wu_get_setting('allow_own_site_as_template')) { $this->message = __('You can not use your sites as template', 'wp-ultimo'); return false; - - } // end if; + } $customer = wu_get_current_customer(); - if (!$customer || $site->get_customer_id() !== $customer->get_id()) { - + if (! $customer || $site->get_customer_id() !== $customer->get_id()) { $this->message = __('The selected template is not available.', 'wp-ultimo'); return false; - - } // end if; + } return true; - - } // end if; + } $allowed_templates = false; @@ -96,7 +86,6 @@ class Site_Template extends Rule { $product_ids_or_slugs = array_unique($product_ids_or_slugs); if ($product_ids_or_slugs) { - $products = array_map('wu_get_product', $product_ids_or_slugs); $limits = new \WP_Ultimo\Objects\Limitations(); @@ -106,25 +95,19 @@ class Site_Template extends Rule { $products = array_merge(array($plan), $additional_products); foreach ($products as $product) { - $limits = $limits->merge($product->get_limitations()); - - } // end foreach; + } $allowed_templates = $limits->site_templates->get_available_site_templates(); - - } // end if; + } if (is_array($allowed_templates) && !in_array($template_id, $allowed_templates)) { // phpcs:ignore $this->message = __('The selected template is not available for this product.', 'wp-ultimo'); return false; - - } // end if; + } return true; - - } // end check; - -} // end class Site_Template; + } +} diff --git a/inc/helpers/validation-rules/class-state.php b/inc/helpers/validation-rules/class-state.php index a966782..4d955a0 100644 --- a/inc/helpers/validation-rules/class-state.php +++ b/inc/helpers/validation-rules/class-state.php @@ -35,28 +35,22 @@ class State extends Rule { * * @param mixed $state The state value detected. */ - public function check($state) : bool { // phpcs:ignore + public function check($state) : bool { // phpcs:ignore $check = true; $country = $this->parameter('country') ?? wu_request('billing_country'); if ($country && $state) { - $state = strtoupper((string) $state); $allowed_states = array_keys(wu_get_country_states(strtoupper((string) $country), false)); - if (!empty($allowed_states)) { - + if (! empty($allowed_states)) { $check = in_array($state, $allowed_states, true); - - } // end if; - - } // end if; + } + } return $check; - - } // end check; - -} // end class State; + } +} diff --git a/inc/helpers/validation-rules/class-unique-site.php b/inc/helpers/validation-rules/class-unique-site.php index c2bd7a4..5dbbabc 100644 --- a/inc/helpers/validation-rules/class-unique-site.php +++ b/inc/helpers/validation-rules/class-unique-site.php @@ -43,7 +43,7 @@ class Unique_Site extends Rule { * * @param mixed $value Value being checked. */ - public function check($value) : bool { // phpcs:ignore + public function check($value) : bool { // phpcs:ignore $this->requireParameters(array()); @@ -52,15 +52,11 @@ class Unique_Site extends Rule { $results = wpmu_validate_blog_signup($value, 'Test Title'); if ($results['errors']->has_errors()) { - $this->message = $results['errors']->get_error_message(); return false; - - } // end if; + } return true; - - } // end check; - -} // end class Unique_Site; + } +} diff --git a/inc/helpers/validation-rules/class-unique.php b/inc/helpers/validation-rules/class-unique.php index 4e6193a..3011c3f 100644 --- a/inc/helpers/validation-rules/class-unique.php +++ b/inc/helpers/validation-rules/class-unique.php @@ -44,12 +44,14 @@ class Unique extends Rule { * * @param mixed $value Value being checked. */ - public function check($value) : bool { + public function check($value): bool { - $this->requireParameters(array( - 'model', - 'column', - )); + $this->requireParameters( + array( + 'model', + 'column', + ) + ); $column = $this->parameter('column'); $model = $this->parameter('model'); @@ -76,24 +78,18 @@ class Unique extends Rule { * Customize the error message for the customer. */ if (in_array($model, $user_models, true)) { - $this->message = __('A customer with the same email address or username already exists.', 'wp-ultimo'); + } - } // end if; - - if (!$existing) { - + if ( ! $existing) { return true; - - } // end if; + } if ( $existing instanceof \WP_User) { $id = $existing->ID; } else { - $id = method_exists( $existing, 'get_id' ) ? $existing->get_id() : $existing->id; + $id = method_exists($existing, 'get_id') ? $existing->get_id() : $existing->id; } return absint($id) === absint($self_id); - - } // end check; - -} // end class Unique; + } +} diff --git a/inc/installers/class-base-installer.php b/inc/installers/class-base-installer.php index d8c19e4..31188f7 100644 --- a/inc/installers/class-base-installer.php +++ b/inc/installers/class-base-installer.php @@ -36,8 +36,7 @@ class Base_Installer { public function get_steps() { return array(); - - } // end get_steps; + } /** * Runs through all the steps to see if they are all done or not. @@ -51,18 +50,13 @@ class Base_Installer { $all_done = true; foreach ($this->get_steps() as $step) { - if ($step['done'] === false) { - $all_done = false; - - } // end if; - - } // end foreach; + } + } return $all_done; - - } // end all_done; + } /** * Handles the installer. @@ -88,30 +82,22 @@ class Base_Installer { /* * No installer on this class. */ - if (!is_callable($callable)) { - + if ( ! is_callable($callable)) { return $status; - - } // end if; + } try { - $wpdb->query('START TRANSACTION'); call_user_func($callable); - } catch (\Throwable $e) { - $wpdb->query('ROLLBACK'); return new \WP_Error($installer, $e->getMessage()); - - } // end try; + } $wpdb->query('COMMIT'); return $status; - - } // end handle; - -} // end class Base_Installer; + } +} diff --git a/inc/installers/class-core-installer.php b/inc/installers/class-core-installer.php index 2f67b68..4dd689d 100644 --- a/inc/installers/class-core-installer.php +++ b/inc/installers/class-core-installer.php @@ -9,7 +9,7 @@ namespace WP_Ultimo\Installers; -use \WP_Ultimo\Integrations\Host_Providers\Closte_Host_Provider; +use WP_Ultimo\Integrations\Host_Providers\Closte_Host_Provider; // Exit if accessed directly defined('ABSPATH') || exit; @@ -31,30 +31,28 @@ class Core_Installer extends Base_Installer { */ public function init() { - add_filter('wu_core_installer_install_sunrise', function() { + add_filter( + 'wu_core_installer_install_sunrise', + function () { - $is_closte = defined('CLOSTE_CLIENT_API_KEY') && CLOSTE_CLIENT_API_KEY; + $is_closte = defined('CLOSTE_CLIENT_API_KEY') && CLOSTE_CLIENT_API_KEY; - if ($is_closte) { + if ($is_closte) { + if ( ! (defined('SUNRISE') && SUNRISE)) { - if (!(defined('SUNRISE') && SUNRISE)) { + // translators: %s is a URL to a documentation link. + $closte_message = sprintf(__('You are using Closte and they prevent the wp-config.php file from being written to.
    Follow these instructions to do it manually.', 'wp-ultimo'), wu_get_documentation_url('wp-ultimo-closte-config')); - // translators: %s is a URL to a documentation link. - $closte_message = sprintf(__('You are using Closte and they prevent the wp-config.php file from being written to. Follow these instructions to do it manually.', 'wp-ultimo' ), wu_get_documentation_url('wp-ultimo-closte-config')); + throw new \Exception($closte_message); + } - throw new \Exception($closte_message); + return true; + } - } // end if; - - return true; - - } // end if; - - return false; - - }); - - } // end init; + return false; + } + ); + } /** * Returns the list of migration steps. @@ -89,8 +87,7 @@ class Core_Installer extends Base_Installer { ); return $steps; - - } // end get_steps; + } /** * Installs our custom database tables. @@ -112,10 +109,8 @@ class Core_Installer extends Base_Installer { ); if (in_array($table_name, $exclude_list, true)) { - continue; - - } // end if; + } $success = $table->install(); @@ -125,12 +120,9 @@ class Core_Installer extends Base_Installer { $error_message = sprintf(__('Installation of the table %s failed', 'wp-ultimo'), $table->get_name()); throw new \Exception($error_message); - - } // end if; - - } // end foreach; - - } // end _install_database_tables; + } + } + } /** * Copies the sunrise.php file and adds the SUNRISE constant. @@ -144,10 +136,8 @@ class Core_Installer extends Base_Installer { $copy = \WP_Ultimo\Sunrise::try_upgrade(); if (is_wp_error($copy)) { - throw new \Exception($copy->get_error_message()); - - } // end if; + } /** * Allow host providers to install the constant differently. @@ -160,19 +150,13 @@ class Core_Installer extends Base_Installer { $short_circuit = apply_filters('wu_core_installer_install_sunrise', false); if ($short_circuit) { - return; - - } // end if; + } $success = \WP_Ultimo\Helpers\WP_Config::get_instance()->inject_wp_config_constant('SUNRISE', true); if (is_wp_error($success)) { - throw new \Exception($success->get_error_message()); - - } // end if; - - } // end _install_sunrise; - -} // end class Core_Installer; + } + } +} diff --git a/inc/installers/class-default-content-installer.php b/inc/installers/class-default-content-installer.php index f5a5379..3f7d974 100644 --- a/inc/installers/class-default-content-installer.php +++ b/inc/installers/class-default-content-installer.php @@ -9,7 +9,7 @@ namespace WP_Ultimo\Installers; -use \WP_Ultimo\Logger; +use WP_Ultimo\Logger; // Exit if accessed directly defined('ABSPATH') || exit; @@ -42,8 +42,7 @@ class Default_Content_Installer extends Base_Installer { require_once wu_path('inc/functions/product.php'); require_once wu_path('inc/functions/checkout-form.php'); - - } // end init; + } /** * Checks if we already created a template site. @@ -58,8 +57,7 @@ class Default_Content_Installer extends Base_Installer { $d = wu_get_site_domain_and_path('template'); return domain_exists($d->domain, $d->path, get_current_network_id()); - - } // end done_creating_template_site; + } /** * Checks if we already created the base products. @@ -73,15 +71,12 @@ class Default_Content_Installer extends Base_Installer { */ $has_tables_installed = \WP_Ultimo\Loaders\Table_Loader::get_instance()->is_installed(); - if (!$has_tables_installed) { - + if ( ! $has_tables_installed) { return false; + } - } // end if; - - return !empty(wu_get_plans()); - - } // end done_creating_products; + return ! empty(wu_get_plans()); + } /** * Checks if we already created the base checkout form. @@ -95,15 +90,12 @@ class Default_Content_Installer extends Base_Installer { */ $has_tables_installed = \WP_Ultimo\Loaders\Table_Loader::get_instance()->is_installed(); - if (!$has_tables_installed) { - + if ( ! $has_tables_installed) { return false; + } - } // end if; - - return !empty(wu_get_checkout_forms()); - - } // end done_creating_checkout_forms; + return ! empty(wu_get_checkout_forms()); + } /** * Checks if we already created the system emails and the template email. @@ -117,15 +109,12 @@ class Default_Content_Installer extends Base_Installer { */ $has_tables_installed = \WP_Ultimo\Loaders\Table_Loader::get_instance()->is_installed(); - if (!$has_tables_installed) { - + if ( ! $has_tables_installed) { return false; + } - } // end if; - - return !empty(wu_get_all_system_emails()); - - } // end done_creating_emails; + return ! empty(wu_get_all_system_emails()); + } /** * Checks if we already created the custom login page. @@ -137,17 +126,14 @@ class Default_Content_Installer extends Base_Installer { $page_id = wu_get_setting('default_login_page'); - if (!$page_id) { - + if ( ! $page_id) { return false; - - } // end if; + } $page = get_post($page_id); - return !empty($page); - - } // end done_creating_login_page; + return ! empty($page); + } /** * Returns the list of migration steps. @@ -210,8 +196,7 @@ class Default_Content_Installer extends Base_Installer { ); return $steps; - - } // end get_steps; + } // Default_Content_Installers start below @@ -236,20 +221,15 @@ class Default_Content_Installer extends Base_Installer { $status = wu_create_site($template_site); if (is_wp_error($status)) { - throw new \Exception($status->get_error_message()); + } - } // end if; - - if (!$status) { - + if ( ! $status) { $error_message = __('Template Site was not created. Maybe a site with the /template path already exists?', 'wp-ultimo'); throw new \Exception($error_message); - - } // end if; - - } // end _install_create_template_site; + } + } /** * Creates a example products. @@ -333,22 +313,17 @@ class Default_Content_Installer extends Base_Installer { ); foreach ($products as $product_data) { - $status = wu_create_product($product_data); if (is_wp_error($status)) { - throw new \Exception($status->get_error_message()); + } - } // end if; - - $status->set_featured_image_id($images[$product_data['slug']]); + $status->set_featured_image_id($images[ $product_data['slug'] ]); $status->save(); - - } // end foreach; - - } // end _install_create_products; + } + } /** * Creates a new checkout form as an example. @@ -368,16 +343,12 @@ class Default_Content_Installer extends Base_Installer { $status = wu_create_checkout_form($checkout_form); if (is_wp_error($status)) { - throw new \Exception($status->get_error_message()); - } else { - $status->use_template('single-step'); $status->save(); - - } // end if; + } $post_content = ' @@ -400,17 +371,14 @@ class Default_Content_Installer extends Base_Installer { $page_id = wp_insert_post($post_details); if (is_wp_error($page_id)) { - throw new \Exception($page_id->get_error_message()); - - } // end if; + } /* * Set page as the default registration page. */ wu_save_setting('default_registration_page', $page_id); - - } // end _install_create_checkout; + } /** * Creates the template email, invoice template and system emails. @@ -422,8 +390,7 @@ class Default_Content_Installer extends Base_Installer { public function _install_create_emails() { \WP_Ultimo\Managers\Email_Manager::get_instance()->create_all_system_emails(); - - } // end _install_create_emails; + } /** * Creates custom login page. @@ -451,10 +418,8 @@ class Default_Content_Installer extends Base_Installer { $page_id = wp_insert_post($page_args); if (is_wp_error($page_id)) { - throw new \Exception($page_id->get_error_message()); - - } // end if; + } /* * Enable a custom login page. @@ -465,7 +430,5 @@ class Default_Content_Installer extends Base_Installer { * Set page as the default login page. */ wu_save_setting('default_login_page', $page_id); - - } // end _install_create_login_page; - -} // end class Default_Content_Installer; + } +} diff --git a/inc/installers/class-migrator.php b/inc/installers/class-migrator.php index cf9e43b..0b5616f 100644 --- a/inc/installers/class-migrator.php +++ b/inc/installers/class-migrator.php @@ -9,16 +9,16 @@ namespace WP_Ultimo\Installers; -use \Psr\Log\LogLevel; -use \Ifsnop\Mysqldump\Mysqldump as MySQLDump; -use \WP_Ultimo\UI\Template_Previewer; -use \WP_Ultimo\Models\Checkout_Form; -use \WP_Ultimo\Checkout\Legacy_Checkout; -use \WP_Ultimo\Database\Memberships\Membership_Status; -use \WP_Ultimo\Database\Payments\Payment_Status; -use \WP_Ultimo\Database\Sites\Site_Type; -use \WP_Ultimo\Managers\Domain_Manager; -use \WP_Ultimo\Managers\Limitation_Manager; +use Psr\Log\LogLevel; +use Ifsnop\Mysqldump\Mysqldump; +use WP_Ultimo\UI\Template_Previewer; +use WP_Ultimo\Models\Checkout_Form; +use WP_Ultimo\Checkout\Legacy_Checkout; +use WP_Ultimo\Database\Memberships\Membership_Status; +use WP_Ultimo\Database\Payments\Payment_Status; +use WP_Ultimo\Database\Sites\Site_Type; +use WP_Ultimo\Managers\Domain_Manager; +use WP_Ultimo\Managers\Limitation_Manager; // Exit if accessed directly defined('ABSPATH') || exit; @@ -110,14 +110,12 @@ class Migrator extends Base_Installer { public function init() { if ($this->is_migration_screen()) { - $this->session = wu_get_session('migrator'); $this->errors = $this->session->get('errors'); $this->back_traces = $this->session->get('back_traces'); - - } // end if; + } /* * Install the handler for the parallel installer. @@ -125,8 +123,7 @@ class Migrator extends Base_Installer { \WP_Ultimo\Async_Calls::register_listener('parallel_installers', array($this, 'handle_parallel_installers')); \WP_Ultimo\Async_Calls::install_listeners(); - - } // end init; + } /** * Handle the parallel installers via the Async Caller. @@ -143,8 +140,7 @@ class Migrator extends Base_Installer { $results = json_decode(ob_get_clean(), true); return $results; - - } // end handle_parallel_installers; + } /** * Handles unexpected shutdowns of the PHP process. @@ -160,15 +156,14 @@ class Migrator extends Base_Installer { $message = 'The migrator process exit unexpectedly while running the "%s" migration... You might need to increase server resources to run the migrator. Below, a list of the ids of interest collected thus far:'; - wu_log_add(Migrator::LOG_FILE_NAME, sprintf($message, $installer), LogLevel::ERROR); + wu_log_add(self::LOG_FILE_NAME, sprintf($message, $installer), LogLevel::ERROR); $this->log_ids_of_interest(); $e = new \Exception('The migrator process exit unexpectedly'); $this->handle_error_messages($e, $session, $dry_run, $installer); - - } // end on_shutdown; + } /** * Checks if we are on the migration screen to prevent issues. @@ -179,8 +174,7 @@ class Migrator extends Base_Installer { protected function is_migration_screen() { return wu_request('page') === 'wp-ultimo-setup' && wu_request('step') === 'migration'; - - } // end is_migration_screen; + } /** * Checks if the migration is done. @@ -190,10 +184,12 @@ class Migrator extends Base_Installer { */ public static function is_migration_done() { - $plans = get_posts(array( - 'post_type' => 'wpultimo_plan', - 'numberposts' => 1, - )); + $plans = get_posts( + array( + 'post_type' => 'wpultimo_plan', + 'numberposts' => 1, + ) + ); if (empty($plans)) { /* @@ -202,12 +198,10 @@ class Migrator extends Base_Installer { * to migrate. */ return true; - - } // end if; + } return get_network_option(null, 'wu_is_migration_done', false); - - } // end is_migration_done; + } /** * Check if we are running on a network that runs Ultimo 1.X @@ -221,9 +215,8 @@ class Migrator extends Base_Installer { * If we already runned or if this is a fresh install, is_migration_done * will return true, indicating that this is not a legacy network at this moment. */ - return !self::is_migration_done(); - - } // end is_legacy_network; + return ! self::is_migration_done(); + } /** * Returns the list of errors detected. * @@ -232,8 +225,7 @@ class Migrator extends Base_Installer { public function get_errors(): array { return array_unique((array) $this->errors); - - } // end get_errors; + } /** * Returns the list of _backtraces detected. * @@ -242,8 +234,7 @@ class Migrator extends Base_Installer { public function get_back_traces(): array { return array_unique((array) $this->back_traces); - - } // end get_back_traces; + } /** * Returns the list of migration steps. @@ -258,8 +249,7 @@ class Migrator extends Base_Installer { $dry_run = wu_request('dry-run', true); - if ($dry_run && !$force_all) { - + if ($dry_run && ! $force_all) { $steps['dry_run_check'] = array( 'title' => __('Pre-Migration Check', 'wp-ultimo'), 'description' => __('Runs all migrations in a sand-boxed environment to see if it hits an error.', 'wp-ultimo'), @@ -271,11 +261,9 @@ class Migrator extends Base_Installer { ); return $steps; + } - } // end if; - - if (!$dry_run) { - + if ( ! $dry_run) { $steps['backup'] = array( 'title' => __('Prepare for Migration', 'wp-ultimo'), 'description' => __('Verifies the data before going forward with the migration.', 'wp-ultimo'), @@ -285,8 +273,7 @@ class Migrator extends Base_Installer { 'help' => wu_get_documentation_url('migration-errors'), 'done' => false, ); - - } // end if; + } $steps['settings'] = array( 'title' => __('Settings', 'wp-ultimo'), @@ -381,11 +368,17 @@ class Migrator extends Base_Installer { 'done' => false, ); - $steps = array_map(fn($item) => wp_parse_args($item, array( - 'pending' => __('Pending', 'wp-ultimo'), - 'installing' => __('Migrating...', 'wp-ultimo'), - 'success' => __('Success!', 'wp-ultimo'), - )), $steps); + $steps = array_map( + fn($item) => wp_parse_args( + $item, + array( + 'pending' => __('Pending', 'wp-ultimo'), + 'installing' => __('Migrating...', 'wp-ultimo'), + 'success' => __('Success!', 'wp-ultimo'), + ) + ), + $steps + ); /** * Allow developers and add-ons to add new migration steps @@ -397,8 +390,7 @@ class Migrator extends Base_Installer { $steps = apply_filters('wu_get_migration_steps', $steps, $this); return $steps; - - } // end get_steps; + } /** * Tries to bypass server limitations such as memory and time limits. @@ -408,7 +400,7 @@ class Migrator extends Base_Installer { */ protected function bypass_server_limits() { - $error = new \WP_Error; + $error = new \WP_Error(); $message = 'Unable to set %s'; @@ -418,10 +410,8 @@ class Migrator extends Base_Installer { $set_memory_limit = @ini_set('memory_limit', '-1'); // phpcs:ignore if ($set_memory_limit === false) { - $error->add('memory_limit', sprintf($message, 'memory_limit')); - - } // end if; + } /* * Attempt to set the time limit. @@ -429,10 +419,8 @@ class Migrator extends Base_Installer { $set_time_limit = @set_time_limit(0); // phpcs:ignore if ($set_time_limit === false) { - $error->add('time_limit', sprintf($message, 'time_limit')); - - } // end if; + } /* * It's interesting if we can prevent errors from showing up and breaking @@ -444,16 +432,13 @@ class Migrator extends Base_Installer { @ini_set('display_errors', 0); // phpcs:ignore if ($error->has_errors()) { - $this->server_bypass_status = $error; return; - - } // end if; + } return true; - - } // end bypass_server_limits; + } /** * Handles the installer. @@ -487,11 +472,9 @@ class Migrator extends Base_Installer { /* * No installer on this class. */ - if (!is_callable($callable)) { - + if ( ! is_callable($callable)) { return $status; - - } // end if; + } /* * Try to bypass the server limits such as timeouts, etc. @@ -501,12 +484,10 @@ class Migrator extends Base_Installer { $opening_log_message = sprintf('Migration starting for %s with dry mode %s...', $installer, $this->dry_run ? 'on' : 'off'); if ($this->is_parallel()) { - $opening_log_message .= sprintf(' This is a parallel request with a page attribute of %d and a per_page attribute of %d', wu_request('page', 0), wu_request('per_page', 0)); + } - } // end if; - - wu_log_add(Migrator::LOG_FILE_NAME, $opening_log_message); + wu_log_add(self::LOG_FILE_NAME, $opening_log_message); /* * Check if we had any errors on setting the server limits. @@ -525,9 +506,8 @@ class Migrator extends Base_Installer { $log_message = implode(PHP_EOL, $this->server_bypass_status->get_error_messages()); - wu_log_add(Migrator::LOG_FILE_NAME, $log_message, LogLevel::ERROR); - - } // end if; + wu_log_add(self::LOG_FILE_NAME, $log_message, LogLevel::ERROR); + } $session = wu_get_session('migrator'); @@ -537,25 +517,21 @@ class Migrator extends Base_Installer { // register_shutdown_function(array($this, 'on_shutdown'), $session, $this->dry_run, $installer); try { - wp_cache_flush(); $wpdb->query('START TRANSACTION'); call_user_func($callable, wu_request('per_page'), wu_request('page')); - } catch (\Throwable $e) { - $wpdb->query('ROLLBACK'); /* * Log errors to later reference. */ - wu_log_add(Migrator::LOG_FILE_NAME, $e->__toString(), LogLevel::ERROR); + wu_log_add(self::LOG_FILE_NAME, $e->__toString(), LogLevel::ERROR); return $this->handle_error_messages($e, $session, $this->dry_run, $installer); - - } // end try; + } /* * Log ids of interest. @@ -566,28 +542,21 @@ class Migrator extends Base_Installer { * Commit or rollback depending on the status */ if ($this->dry_run) { - $wpdb->query('ROLLBACK'); - } else { - $wpdb->query('COMMIT'); wp_cache_flush(); - - } // end if; + } if ($session) { - $session->set('errors', array()); $session->set('back_traces', array()); - - } // end if; + } return $status; - - } // end handle; + } /** * Handles error messages and exceptions so we can display them and log them. @@ -610,7 +579,6 @@ class Migrator extends Base_Installer { $error_nice_message = sprintf(__('Critical error found when migrating "%s".', 'wp-ultimo'), $caller); if ($session) { - $errors = (array) $session->get('errors'); $back_traces = (array) $session->get('back_traces'); @@ -622,12 +590,10 @@ class Migrator extends Base_Installer { $session->set('errors', $errors); $session->set('back_traces', $back_traces); - - } // end if; + } return new \WP_Error($installer, $error_nice_message); - - } // end handle_error_messages; + } /** * Dumps ids of interest on the log so we can revise them later id needed. @@ -637,33 +603,26 @@ class Migrator extends Base_Installer { */ public function log_ids_of_interest() { - if (!is_array($this->ids_of_interest)) { - - wu_log_add(Migrator::LOG_FILE_NAME, 'The list of IDs of interested got corrupted, this might indicate problems with one or more migrations', LogLevel::ERROR); + if ( ! is_array($this->ids_of_interest)) { + wu_log_add(self::LOG_FILE_NAME, 'The list of IDs of interested got corrupted, this might indicate problems with one or more migrations', LogLevel::ERROR); return; - - } // end if; + } foreach ($this->ids_of_interest as $key => $ids) { - list($installer, $reason) = explode(':', $key); if (empty($ids)) { - continue; - - } // end if; + } $id_list = implode(PHP_EOL, $ids); $message = sprintf('The following IDs where skipped from the "%s" migration due to an status of "%s": %s', $installer, $reason, PHP_EOL . $id_list); - wu_log_add(Migrator::LOG_FILE_NAME, $message, LogLevel::WARNING); - - } // end foreach; - - } // end log_ids_of_interest; + wu_log_add(self::LOG_FILE_NAME, $message, LogLevel::WARNING); + } + } /** * Add an id of interest to the list. @@ -683,9 +642,8 @@ class Migrator extends Base_Installer { $id_or_ids = (array) $id_or_ids; - $this->ids_of_interest[$id_list_key] = array_merge($id_list, $id_or_ids); - - } // end add_id_of_interest; + $this->ids_of_interest[ $id_list_key ] = array_merge($id_list, $id_or_ids); + } /** * Generate the database dump as a backup. @@ -701,16 +659,13 @@ class Migrator extends Base_Installer { $all_steps = $this->get_steps(true); foreach ($all_steps as $installer => $step) { - $wu_migrator_current_installer = $installer; $callable = array($this, "_install_{$installer}"); call_user_func($callable); - - } // end foreach; - - } // end _install_dry_run_check; + } + } /** * Generate the database dump as a backup. @@ -737,8 +692,7 @@ class Migrator extends Base_Installer { ); $dump->start($file_name); - - } // end _install_backup; + } /** * Returns the list of legacy settings on 1.X. @@ -751,10 +705,8 @@ class Migrator extends Base_Installer { global $wpdb; if ($this->settings !== null) { - return $this->settings; - - } // end if; + } $settings = $wpdb->get_var( " @@ -770,8 +722,7 @@ class Migrator extends Base_Installer { $this->settings = maybe_unserialize($settings); return $this->settings; - - } // end get_old_settings; + } /** * Returns the value of a particular legacy setting. @@ -789,8 +740,7 @@ class Migrator extends Base_Installer { $value = wu_get_isset($settings, $setting, $default); return $value; - - } // end get_old_setting; + } /** * Migrates the settings. @@ -931,18 +881,14 @@ class Migrator extends Base_Installer { $to_migrate['paypal_sandbox_mode'] = $is_paypal_sandbox; if ($is_paypal_sandbox) { - $to_migrate['paypal_test_username'] = $this->get_old_setting('paypal_username', ''); $to_migrate['paypal_test_password'] = $this->get_old_setting('paypal_pass', ''); $to_migrate['paypal_test_signature'] = $this->get_old_setting('paypal_signature', ''); - } else { - $to_migrate['paypal_live_username'] = $this->get_old_setting('paypal_username', ''); $to_migrate['paypal_live_password'] = $this->get_old_setting('paypal_pass', ''); $to_migrate['paypal_live_signature'] = $this->get_old_setting('paypal_signature', ''); - - } // end if; + } /* * API Settings @@ -981,8 +927,7 @@ class Migrator extends Base_Installer { * Save Migrated Settings. */ $status = \WP_Ultimo\Settings::get_instance()->save_settings($to_migrate); - - } // end _install_settings; + } /** * Register missing setting keys so they can be saved. @@ -994,33 +939,33 @@ class Migrator extends Base_Installer { */ public function fake_register_settings($to_migrate = array()) { - add_filter('wu_settings_section_core_fields', function($fields) use ($to_migrate) { + add_filter( + 'wu_settings_section_core_fields', + function ($fields) use ($to_migrate) { - $all_keys = \WP_Ultimo\Settings::get_instance()->get_all(); + $all_keys = \WP_Ultimo\Settings::get_instance()->get_all(); - $missing_keys = array_diff_key($to_migrate, $all_keys); + $missing_keys = array_diff_key($to_migrate, $all_keys); - foreach ($missing_keys as $field_slug => $value) { + foreach ($missing_keys as $field_slug => $value) { + $fields[ $field_slug ] = array( + 'type' => 'hidden', + 'setting_id' => $field_slug, + 'raw' => true, + ); + } - $fields[$field_slug] = array( - 'type' => 'hidden', - 'setting_id' => $field_slug, - 'raw' => true, - ); - - } // end foreach; - - return $fields; - - }, 10); + return $fields; + }, + 10 + ); \WP_Ultimo\Settings::get_instance()->default_sections(); $sections = \WP_Ultimo\Settings::get_instance()->get_sections(); return $sections; - - } // end fake_register_settings; + } /** * Migrates Plans. @@ -1068,10 +1013,8 @@ class Migrator extends Base_Installer { * Skip errors if a plan exists. */ if (wu_get_product_by_slug($plan->slug)) { - continue; - - } // end if; + } $product_data = array(); $product_data['type'] = 'plan'; @@ -1102,7 +1045,7 @@ class Migrator extends Base_Installer { $product_data['trial_duration'] = $plan_trial_value ? $plan_trial_value : $default_trial_value; $product_data['trial_duration_unit'] = $duration_unit_day; - $active = !(bool) get_post_meta($plan->ID, 'wpu_hidden', true); + $active = ! (bool) get_post_meta($plan->ID, 'wpu_hidden', true); $product_data['active'] = $active; $is_free = get_post_meta($plan->ID, 'wpu_free', true); @@ -1110,82 +1053,60 @@ class Migrator extends Base_Installer { $price_variations = array(); if ($is_free) { - $product_data['amount'] = 0; $product_data['pricing_type'] = 'free'; - } else { - $price_month = get_post_meta($plan->ID, 'wpu_price_1', true); if ($price_month) { - if (absint($default_billing) === 1) { - $product_data['amount'] = $price_month; $product_data['duration'] = 1; $product_data['duration_unit'] = 'month'; - } else { - $price_variations[] = array( 'amount' => $price_month, 'duration' => 1, 'duration_unit' => 'month', ); - - } // end if; - - } // end if; + } + } $price_3_month = get_post_meta($plan->ID, 'wpu_price_3', true); if ($price_3_month) { - if (absint($default_billing) === 3) { - $product_data['amount'] = $price_3_month; $product_data['duration'] = 3; $product_data['duration_unit'] = 'month'; - } else { - $price_variations[] = array( 'amount' => $price_3_month, 'duration' => 3, 'duration_unit' => 'month', ); - - } // end if; - - } // end if; + } + } $price_12_month = get_post_meta($plan->ID, 'wpu_price_12', true); if ($price_12_month) { - if (absint($default_billing) === 12) { - $product_data['amount'] = $price_12_month; $product_data['duration'] = 1; $product_data['duration_unit'] = 'year'; - } else { - $price_variations[] = array( 'amount' => $price_12_month, 'duration' => 1, 'duration_unit' => 'year', ); - - } // end if; - - } // end if; + } + } $is_contact_us = (bool) get_post_meta($plan->ID, 'wpu_is_contact_us', true); $product_data['pricing_type'] = $is_contact_us ? 'contact_us' : 'paid'; - - } // end if; + } /* * Set the pricing variations. @@ -1213,10 +1134,8 @@ class Migrator extends Base_Installer { $product = wu_create_product($product_data); if (is_wp_error($product)) { - throw new \Exception($product->get_error_message()); - - } // end if; + } /* * Migrate Quota @@ -1235,28 +1154,20 @@ class Migrator extends Base_Installer { $force_template = false; if ($has_template_selection_options === false) { - $force_template = get_post_meta($plan->ID, 'wpu_site_template', true); if ($force_template && wu_get_site($force_template)) { - $site_template_mode = 'assign_template'; - - } // end if; + } $has_custom_template_list = false; - } elseif ($has_custom_template_list) { - $site_template_mode = 'choose_available_templates'; if (empty($templates)) { - $site_template_enabled = false; - - } // end if; - - } // end if; + } + } /* * Build template list. @@ -1266,26 +1177,21 @@ class Migrator extends Base_Installer { $available_site_templates = wu_get_site_templates(); foreach ($available_site_templates as $site_template) { - $site_template_id = absint($site_template->get_id()); $behavior = $has_custom_template_list ? 'not_available' : 'available'; if ($site_template_id === absint($force_template)) { - $behavior = 'pre_selected'; - } elseif (in_array($site_template_id, $templates)) { // phpcs:ignore; $behavior = 'available'; + } - } // end if; - - $site_templates_limit[$site_template_id] = array( + $site_templates_limit[ $site_template_id ] = array( 'behavior' => $behavior, ); - - } // end foreach; + } /** * Limitation modules. @@ -1311,25 +1217,21 @@ class Migrator extends Base_Installer { * @since 2.0.7 */ if (is_array($allowed_plugins)) { - $allowed_plugins = $allowed_plugins; $plugins_limit = array(); foreach (Limitation_Manager::get_instance()->get_all_plugins() as $plugin_path => &$plugin_data) { - - $plugins_limit[$plugin_path] = array( + $plugins_limit[ $plugin_path ] = array( 'visibility' => in_array($plugin_path, $allowed_plugins, true) ? 'visible' : 'hidden', 'behavior' => in_array($plugin_path, $allowed_plugins, true) ? 'available' : 'not_available', ); - - } // end foreach; + } $limitations_modules['plugins'] = array( 'limit' => $plugins_limit, ); - - } // end if; + } /** * Build the themes limitations object. @@ -1337,101 +1239,79 @@ class Migrator extends Base_Installer { * @since 2.0.7 */ if (is_array($allowed_themes)) { - $themes_limit = array(); foreach (Limitation_Manager::get_instance()->get_all_themes() as $stylesheet => &$theme_data) { - - $themes_limit[$stylesheet] = array( + $themes_limit[ $stylesheet ] = array( 'visibility' => in_array($stylesheet, $allowed_themes, true) ? 'visible' : 'hidden', 'behavior' => in_array($stylesheet, $allowed_themes, true) ? 'available' : 'not_available', ); - - } // end foreach; + } $limitations_modules['themes'] = array( 'limit' => $themes_limit, ); - - } // end if; + } $unlimited_users = (bool) get_post_meta($plan->ID, 'wpu_unlimited_extra_users', true); $post_types_limit = array(); foreach ($quotas as $post_type => $quota) { - - if ($post_type === 'users' && !$unlimited_users) { - + if ($post_type === 'users' && ! $unlimited_users) { $user_roles = get_editable_roles(); $roles_limit = array(); foreach ($user_roles as $role => $role_data) { - - $roles_limit[$role] = array( + $roles_limit[ $role ] = array( 'enabled' => true, 'number' => $quota ? absint($quota) : '', ); - - } // end foreach; + } $limitations_modules['users'] = array( 'limit' => $roles_limit, 'enabled' => true, ); - } elseif ($post_type === 'upload') { - $limitations_modules['disk_space'] = array( 'limit' => absint($quota), 'enabled' => true, ); - } elseif ($post_type === 'visits') { - $limitations_modules['visits'] = array( 'limit' => $quota ? absint($quota) : '', 'enabled' => true, ); - } elseif ($post_type === 'sites') { - $limitations_modules['sites'] = array( 'limit' => absint($quota), 'enabled' => true, ); - } else { - - $post_types_limit[$post_type] = array( + $post_types_limit[ $post_type ] = array( 'enabled' => in_array($post_type, $disabled_post_types, true) === false, 'number' => $quota ? absint($quota) : '', ); - - } // end if; - - } // end foreach; + } + } /** * If there's any limitations to post types, add it. */ if ($post_types_limit) { - $limitations_modules['post_types'] = array( 'limit' => $post_types_limit, 'enabled' => true, ); - - } // end if; + } $limitations = new \WP_Ultimo\Objects\Limitations($limitations_modules); $product->update_meta('wu_limitations', $limitations); - - } // end foreach; - - } // end _install_products; + } + } /** * Verifies if we are inside a parallel request or not. @@ -1442,8 +1322,7 @@ class Migrator extends Base_Installer { protected function is_parallel() { return wu_request('parallel') && wu_request('page') && wu_request('per_page'); - - } // end is_parallel; + } /** * Get the installer name based on the request. @@ -1462,8 +1341,7 @@ class Migrator extends Base_Installer { global $wu_migrator_current_installer; return $this->dry_run ? $wu_migrator_current_installer : wu_request('installer', ''); - - } // end get_installer; + } /** * Decides if we should run this in parallel, based on the request. @@ -1477,10 +1355,8 @@ class Migrator extends Base_Installer { protected function maybe_run_in_parallel($total_records, $threshold = 100) { if ($this->dry_run) { - return; - - } // end if; + } /* * If this request is not a parallel one, @@ -1488,9 +1364,7 @@ class Migrator extends Base_Installer { * based on the total number of resources. */ if ($this->is_parallel() === false) { - if ($total_records > $threshold) { - $args = array( 'installer' => $this->get_installer(), 'dry-run' => $this->dry_run, @@ -1499,18 +1373,13 @@ class Migrator extends Base_Installer { $result = \WP_Ultimo\Async_Calls::run('parallel_installers', $args, $total_records, $threshold, 10); if (is_wp_error($result)) { - throw new \Exception($result->get_error_message()); - - } // end if; + } return; - - } // end if; - - } // end if; - - } // end maybe_run_in_parallel; + } + } + } /** * Builds an SQL limit clause to be used inside the installers. @@ -1526,22 +1395,17 @@ class Migrator extends Base_Installer { $limit_clause = ''; if ($this->dry_run) { - return sprintf('LIMIT %d', 10); - } elseif ($this->is_parallel()) { - $page = absint(wu_request('page')); $per_page = absint(wu_request('per_page')); $offset = ($page - 1) * $per_page; $limit_clause = sprintf('LIMIT %d,%d', $offset, $per_page); - - } // end if; + } return $limit_clause; - - } // end build_limit_clause; + } /** * Migrates Customers. @@ -1592,38 +1456,29 @@ class Migrator extends Base_Installer { // phpcs:enable foreach ($users as $user) { - if (wu_get_customer_by_user_id($user->user_id)) { - continue; + } - } // end if; - - $customer = wu_create_customer(array( - 'user_id' => $user->user_id, - 'email_verification' => 'verified', - 'vip' => false, - 'date_registered' => $user->created_at, - 'last_login' => $user->created_at, - )); + $customer = wu_create_customer( + array( + 'user_id' => $user->user_id, + 'email_verification' => 'verified', + 'vip' => false, + 'date_registered' => $user->created_at, + 'last_login' => $user->created_at, + ) + ); if (is_wp_error($customer)) { - if ($customer->get_error_code() !== 'empty_username') { - throw new \Exception($customer->get_error_message()); - } else { - $this->add_id_of_interest($user->user_id, 'not_found', 'customers'); - - } // end if; - - } // end if; - - } // end foreach; - - } // end _install_customers; + } + } + } + } /** * Migrates Memberships. @@ -1693,10 +1548,8 @@ class Migrator extends Base_Installer { * If we have already migrated, no need to do it again. */ if (wu_get_membership_by('migrated_from_id', $subscription->ID)) { - continue; - - } // end if; + } $customer = wu_get_customer_by_user_id($subscription->user_id); @@ -1706,13 +1559,11 @@ class Migrator extends Base_Installer { $membership_data = array(); - if (!$product) { - + if ( ! $product) { $this->add_id_of_interest($subscription->plan_id, 'plan_not_migrated', 'memberships'); $membership_data['skip_validation'] = true; - - } // end if; + } $membership_data['migrated_from_id'] = $subscription->ID; @@ -1738,7 +1589,7 @@ class Migrator extends Base_Installer { case '12': $membership_data['duration_unit'] = 'year'; break; - }; + } switch ( $subscription->freq ) { case '1': @@ -1750,14 +1601,15 @@ class Migrator extends Base_Installer { case '12': $membership_data['duration'] = 1; break; - }; + } /** * Try to fetch the last payment to use it as the last renewal date. * * @since 2.0.7 */ - $last_renewal_date_query = $wpdb->prepare(" + $last_renewal_date_query = $wpdb->prepare( + " SELECT time FROM @@ -1766,22 +1618,23 @@ class Migrator extends Base_Installer { user_id = %d AND type = 'payment' ORDER BY id DESC LIMIT 1 - ", $subscription->user_id); + ", + $subscription->user_id + ); $last_renewal_date = $wpdb->get_var($last_renewal_date_query); // phpcs:ignore if (wu_validate_date($last_renewal_date)) { - $membership_data['date_renewed'] = $last_renewal_date; - - } // end if; + } /** * Try to fetch the initial amount paid. * * @since 2.0.7 */ - $initial_amount_query = $wpdb->prepare(" + $initial_amount_query = $wpdb->prepare( + " SELECT amount, original_amount @@ -1791,21 +1644,20 @@ class Migrator extends Base_Installer { user_id = %d AND type = 'payment' ORDER BY id ASC LIMIT 1 - ", $subscription->user_id); + ", + $subscription->user_id + ); $initial_amount = $wpdb->get_var($initial_amount_query); // phpcs:ignore if (is_numeric($initial_amount)) { - $membership_data['initial_amount'] = (float) $initial_amount; - - } // end if; + } /* * Handle the default gateway integrations: Stripe and Paypal. */ if ($subscription->gateway) { - $membership_data['gateway'] = $subscription->gateway; if ($subscription->gateway === 'stripe') { @@ -1818,7 +1670,6 @@ class Migrator extends Base_Installer { */ $membership_data['gateway_customer_id'] = $subscription->integration_key; $membership_data['gateway_subscription_id'] = $v1_subscription_meta->subscription_id; - } elseif ($subscription->gateway === 'paypal') { /** @@ -1828,16 +1679,12 @@ class Migrator extends Base_Installer { * This is what we use as the subscription id on the new models. */ $membership_data['gateway_subscription_id'] = $subscription->integration_key; - - } // end if; + } if ($subscription->integration_status) { - $membership_data['auto_renew'] = true; - - } // end if; - - } // end if; + } + } if ($subscription->trial > 0) { @@ -1851,7 +1698,7 @@ class Migrator extends Base_Installer { */ $subscription_creation_date = wu_date($subscription->created_at); - $trial_end_date = $subscription_creation_date->add( new \DateInterval( 'P' . $subscription->trial . 'D' ) )->setTime( 23, 59, 59 ); + $trial_end_date = $subscription_creation_date->add(new \DateInterval('P' . $subscription->trial . 'D'))->setTime(23, 59, 59); $date_trial_end = $trial_end_date->format('Y-m-d 23:59:59'); @@ -1861,32 +1708,30 @@ class Migrator extends Base_Installer { * Handle memberships still in trial. */ if (wu_date() < $trial_end_date) { - $membership_data['status'] = Membership_Status::TRIALING; + } + } - } // end if; - - } // end if; - - if (empty(wu_to_float($subscription->price)) || !$subscription->active_until) { - + if (empty(wu_to_float($subscription->price)) || ! $subscription->active_until) { $membership_data['status'] = Membership_Status::ACTIVE; - - } // end if; + } /** * Count the payments made to set the billing count thus far. * * @since 2.0.7 */ - $payments_count_query = $wpdb->prepare(" + $payments_count_query = $wpdb->prepare( + " SELECT count(id) FROM {$wpdb->base_prefix}wu_transactions WHERE user_id = %d AND type = 'payment' - ", $subscription->user_id); + ", + $subscription->user_id + ); $payments_count = $wpdb->get_var($payments_count_query); // phpcs:ignore @@ -1898,32 +1743,25 @@ class Migrator extends Base_Installer { $membership_data ); - if (!$membership_data['customer_id']) { - + if ( ! $membership_data['customer_id']) { $this->add_id_of_interest($subscription->user_id, 'customer_not_migrated', 'memberships'); $membership_data['skip_validation'] = true; - - } // end if; + } $membership = wu_create_membership($membership_data); if (is_wp_error($membership)) { - throw new \Exception($membership->get_error_message()); - - } // end if; + } /* * Update statuses and check for other info. */ if ($membership) { - - } // end if; - - } // end foreach; - - } // end _install_memberships; + } + } + } /** * Migrates Transactions. @@ -2001,16 +1839,12 @@ class Migrator extends Base_Installer { * If we have already migrated, no need to do it again. */ if (wu_get_payment_by('migrated_from_id', $transaction->id)) { - continue; - - } // end if; + } if (in_array($transaction->type, $types_to_skip, true)) { - continue; - - } // end if; + } $membership = wu_get_membership_by('user_id', $transaction->user_id); @@ -2019,15 +1853,15 @@ class Migrator extends Base_Installer { $product = ''; if (isset($transaction->plan_id)) { - $product = wu_get_product_by('migrated_from_id', $transaction->plan_id); + } - } // end if; - - $line_item = new \WP_Ultimo\Checkout\Line_Item(array( - 'product' => $product, - 'quantity' => 1, - )); + $line_item = new \WP_Ultimo\Checkout\Line_Item( + array( + 'product' => $product, + 'quantity' => 1, + ) + ); $line_item->set_title($transaction->description); $line_item->set_description($transaction->description); @@ -2060,33 +1894,25 @@ class Migrator extends Base_Installer { 'date_modified' => $transaction->time, ); - if (!$customer) { - + if ( ! $customer) { $this->add_id_of_interest($transaction->user_id, 'customer_not_migrated', 'transactions'); $payment_data['skip_validation'] = true; + } - } // end if; - - if (!$membership) { - + if ( ! $membership) { $this->add_id_of_interest($transaction->user_id, 'membership_not_migrated', 'transactions'); $payment_data['skip_validation'] = true; - - } // end if; + } $payment = wu_create_payment($payment_data); if (is_wp_error($payment)) { - throw new \Exception($payment->get_error_message()); - - } // end if; - - } // end foreach; - - } // end _install_transactions; + } + } + } /** * Migrates Coupons. @@ -2124,18 +1950,14 @@ class Migrator extends Base_Installer { * If we have already migrated, no need to do it again. */ if (wu_get_discount_code_by_code($coupon->slug)) { - continue; - - } // end if; + } $wpu_expiring_date = get_post_meta($coupon->ID, 'wpu_expiring_date', true); - if (!wu_validate_date($wpu_expiring_date)) { - + if ( ! wu_validate_date($wpu_expiring_date)) { $wpu_expiring_date = false; - - } // end if; + } $allowed_plans = get_post_meta($coupon->ID, 'wpu_allowed_plans', true); @@ -2144,22 +1966,16 @@ class Migrator extends Base_Installer { $allowed_products = array(); if ($allowed_plans) { - $limit_products = true; foreach ($allowed_plans as $key => $plan_id) { - $product = wu_get_product_by('migrated_from_id', $plan_id); if ($product) { - $allowed_products[] = $product->get_id(); - - } // end if; - - } // end foreach; - - } // end if; + } + } + } $discount_code_data = array( 'uses' => get_post_meta($coupon->ID, 'wpu_uses', true), @@ -2184,31 +2000,23 @@ class Migrator extends Base_Installer { * Fix the type name. */ if (wu_get_isset($discount_code_data, 'type') === 'percent') { - $discount_code_data['type'] = 'percentage'; - - } // end if; + } /* * Fix the type name. */ if (wu_get_isset($discount_code_data, 'setup_fee_type') === 'percent') { - $discount_code_data['setup_fee_type'] = 'percentage'; - - } // end if; + } $discount_code = wu_create_discount_code($discount_code_data); if (is_wp_error($discount_code)) { - throw new \Exception($discount_code->get_error_message()); - - } // end if; - - } // end foreach; - - } // end _install_discount_codes; + } + } + } /** * Migrates Sites. @@ -2261,43 +2069,32 @@ class Migrator extends Base_Installer { // phpcs:enable foreach ($site_owners as $site_owner) { - $site = wu_get_site($site_owner->site_id); $customer = wu_get_customer_by_user_id($site_owner->user_id); $membership = wu_get_membership_by('user_id', $site_owner->user_id); - if (!$site) { - + if ( ! $site) { continue; - - } // end if; + } if ($customer) { - $site->set_customer_id($customer->get_id()); - - } // end if; + } if ($membership) { - $site->set_membership_id($membership->get_id()); - - } // end if; + } $site->set_type('customer_owned'); $saved = $site->save(); if (is_wp_error($saved)) { - throw new \Exception($saved->get_error_message()); - - } // end if; - - } // end foreach; - - } // end _install_sites; + } + } + } /** * Migrates Template Sites Sites. @@ -2329,42 +2126,32 @@ class Migrator extends Base_Installer { ); if ($this->dry_run) { - $per_page = 10; $page = 1; $search_arguments['number'] = $per_page; $search_arguments['offset'] = ($page - 1) * $per_page; - } elseif ($this->is_parallel()) { - $per_page = absint(wu_request('per_page', 10)); $page = absint(wu_request('page', 1)); $search_arguments['number'] = $per_page; $search_arguments['offset'] = ($page - 1) * $per_page; - - } // end if; + } $saved_templates = get_sites($search_arguments); if (is_array($saved_templates)) { - foreach ($saved_templates as $template_id) { - $site_template = wu_get_site($template_id); - if (!$site_template) { - + if ( ! $site_template) { continue; - - } // end if; + } if ($site_template->get_type() === Site_Type::CUSTOMER_OWNED) { - continue; - - } // end if; + } $site_template->set_type('site_template'); @@ -2381,9 +2168,7 @@ class Migrator extends Base_Installer { $old_thumbnail_id = get_blog_option($site_template->get_id(), 'template_img', false); if ($old_thumbnail_id) { - $site_template->set_featured_image_id($old_thumbnail_id); - } else { /* * Try to get a custom screenshot previously taken. @@ -2393,51 +2178,44 @@ class Migrator extends Base_Installer { $attachment_id = \WP_Ultimo\Helpers\Screenshot::save_image_from_url($image_url); if ($attachment_id) { - $site_template->set_featured_image_id($attachment_id); - } else { /* * If everything else fails, schedule a thumbnail to be saved. */ - wu_enqueue_async_action('wu_async_take_screenshot', array( - 'site_id' => $site_template->get_id(), - ), 'site'); - - } // end if; - - } // end if; + wu_enqueue_async_action( + 'wu_async_take_screenshot', + array( + 'site_id' => $site_template->get_id(), + ), + 'site' + ); + } + } $saved = $site_template->save(); if (is_wp_error($saved)) { - throw new \Exception($saved->get_error_message()); - - } // end if; - - } // end foreach; - - } // end if; - - } // end _install_site_templates; - /** - * Convert hard-coded thumbnail urls into v2 thumbnails. - * - * @since 2.0.0 - * - * @param int $site_id The site template id. - * @return int|false - */ - protected function maybe_get_screenshot_url($site_id) { + } + } + } + } + /** + * Convert hard-coded thumbnail urls into v2 thumbnails. + * + * @since 2.0.0 + * + * @param int $site_id The site template id. + * @return int|false + */ + protected function maybe_get_screenshot_url($site_id) { $template = get_blog_details($site_id); - if (!$template) { - + if ( ! $template) { return false; - - } // end if; + } // Get filename $filename = sanitize_title($template->siteurl); @@ -2448,8 +2226,7 @@ class Migrator extends Base_Installer { // Return URL return file_exists($filepath) && 0 !== filesize($filepath) ? $dir['baseurl'] . '/' . $filename . '.jpg' : false; - - } // end maybe_get_screenshot_url; + } /** * Migrates domains. @@ -2483,33 +2260,28 @@ class Migrator extends Base_Installer { $https = $this->get_old_setting('force_mapped_https', true); foreach ($domains as $domain) { - $existing_domain = wu_get_domain_by_domain($domain->name); if ($existing_domain) { - continue; + } - } // end if; - - $domain = wu_create_domain(array( - 'stage' => 'done', - 'domain' => $domain->name, - 'blog_id' => $domain->blog_id, - 'active' => $domain->active, - 'primary_domain' => true, - 'secure' => $https, - )); + $domain = wu_create_domain( + array( + 'stage' => 'done', + 'domain' => $domain->name, + 'blog_id' => $domain->blog_id, + 'active' => $domain->active, + 'primary_domain' => true, + 'secure' => $https, + ) + ); if (is_wp_error($domain)) { - throw new \Exception($domain->get_error_message()); - - } // end if; - - } // end foreach; - - } // end _install_domains; + } + } + } /** * Migrates Checkout Forms. @@ -2531,10 +2303,8 @@ class Migrator extends Base_Installer { * Skip errors if a checkout form exists. */ if (wu_get_checkout_form_by_slug('main-form')) { - return; - - } // end if; + } $checkout_form = array( 'name' => __('Signup Form', 'wp-ultimo'), @@ -2546,11 +2316,8 @@ class Migrator extends Base_Installer { $status = wu_create_checkout_form($checkout_form); if (is_wp_error($status)) { - throw new \Exception($status->get_error_message()); - } else { - $steps = Legacy_Checkout::get_instance()->get_steps(); $steps = Checkout_Form::convert_steps_to_v2($steps, $this->get_old_settings()); @@ -2558,8 +2325,7 @@ class Migrator extends Base_Installer { $status->set_settings($steps); $status->save(); - - } // end if; + } $post_content = ' @@ -2588,10 +2354,8 @@ class Migrator extends Base_Installer { $page_id = wp_insert_post($post_details); if (is_wp_error($page_id)) { - throw new \Exception($page_id->get_error_message()); - - } // end if; + } /* * Set the legacy template. @@ -2608,11 +2372,10 @@ class Migrator extends Base_Installer { */ $login_page_slug = $this->get_old_setting('login_url', false); - if (!$login_page_slug) { - + if ( ! $login_page_slug) { return; // Bail if no login customization. - } // end if; + } $login_page_slug = trim((string) $login_page_slug, '/'); @@ -2631,10 +2394,8 @@ class Migrator extends Base_Installer { $login_page_id = wp_insert_post($login_post_details); if (is_wp_error($login_page_id)) { - throw new \Exception($login_page_id->get_error_message()); - - } // end if; + } /* * Set page as the default login page. @@ -2642,8 +2403,7 @@ class Migrator extends Base_Installer { wu_save_setting('default_login_page', $login_page_id); wu_save_setting('enable_custom_login_page', true); - - } // end _install_forms; + } /** * Migrates Emails. @@ -2681,14 +2441,11 @@ class Migrator extends Base_Installer { ); foreach ($broadcasts as $broadcast) { - $existing_broadcast = wu_get_broadcast_by('migrated_from_id', $broadcast->ID); if ($existing_broadcast) { - continue; - - } // end if; + } $old_type = get_post_meta($broadcast->ID, 'wpu_type', true); @@ -2699,60 +2456,58 @@ class Migrator extends Base_Installer { $customer_targets = (array) get_post_meta($broadcast->ID, 'wpu_target_users', true); $product_targets = (array) get_post_meta($broadcast->ID, 'wpu_target_plans', true); - $customer_targets = array_map(function($user_id) { + $customer_targets = array_map( + function ($user_id) { - $customer = wu_get_customer_by_user_id($user_id); + $customer = wu_get_customer_by_user_id($user_id); - if ($customer) { + if ($customer) { + return $customer->get_id(); + } - return $customer->get_id(); + return false; + }, + $customer_targets + ); - } // end if; + $product_targets = array_map( + function ($old_plan_id) { - return false; + $product = wu_get_product_by('migrated_from_id', $old_plan_id); - }, $customer_targets); + if ($product) { + return $product->get_id(); + } - $product_targets = array_map(function($old_plan_id) { - - $product = wu_get_product_by('migrated_from_id', $old_plan_id); - - if ($product) { - - return $product->get_id(); - - } // end if; - - return false; - - }, $product_targets); + return false; + }, + $product_targets + ); $targets = array( 'customers' => array_filter($customer_targets), 'products' => array_filter($product_targets), ); - $broadcast = wu_create_broadcast(array( - 'name' => $broadcast->post_title, - 'content' => $broadcast->post_content, - 'type' => $new_type, - 'style' => $style ? $style : 'success', - 'date_created' => $broadcast->post_date, - 'date_modified' => $broadcast->post_modified, - 'message_targets' => $targets, - 'migrated_from_id' => $broadcast->ID, - 'skip_validation' => true, - )); + $broadcast = wu_create_broadcast( + array( + 'name' => $broadcast->post_title, + 'content' => $broadcast->post_content, + 'type' => $new_type, + 'style' => $style ? $style : 'success', + 'date_created' => $broadcast->post_date, + 'date_modified' => $broadcast->post_modified, + 'message_targets' => $targets, + 'migrated_from_id' => $broadcast->ID, + 'skip_validation' => true, + ) + ); if (is_wp_error($broadcast)) { - throw new \Exception($broadcast->get_error_message()); - - } // end if; - - } // end foreach; - - } // end _install_emails; + } + } + } /** * Migrates Webhooks. @@ -2782,26 +2537,23 @@ class Migrator extends Base_Installer { ); foreach ($webhooks as $webhook) { - - $webhook = wu_create_webhook(array( - 'name' => $webhook->post_title, - 'migrated_from_id' => $webhook->ID, - 'webhook_url' => get_post_meta($webhook->ID, 'wpu_url', true), - 'event' => get_post_meta($webhook->ID, 'wpu_event', true), - 'active' => (bool) get_post_meta($webhook->ID, 'wpu_active', true), - 'date_created' => $webhook->post_date, - 'date_modified' => $webhook->post_modified, - )); + $webhook = wu_create_webhook( + array( + 'name' => $webhook->post_title, + 'migrated_from_id' => $webhook->ID, + 'webhook_url' => get_post_meta($webhook->ID, 'wpu_url', true), + 'event' => get_post_meta($webhook->ID, 'wpu_event', true), + 'active' => (bool) get_post_meta($webhook->ID, 'wpu_active', true), + 'date_created' => $webhook->post_date, + 'date_modified' => $webhook->post_modified, + ) + ); if (is_wp_error($webhook)) { - throw new \Exception($webhook->get_error_message()); - - } // end if; - - } // end foreach; - - } // end _install_webhooks; + } + } + } /** * Migrates other things. @@ -2815,10 +2567,8 @@ class Migrator extends Base_Installer { * No need to run this one while checking. */ if ($this->dry_run) { - return; - - } // end if; + } /* * Loads the integrations. @@ -2835,10 +2585,8 @@ class Migrator extends Base_Installer { * Check if the class exists. */ if (class_exists($integration_class) === false) { - continue; - - } // end if; + } /* * Get the instance of the integration. @@ -2846,13 +2594,8 @@ class Migrator extends Base_Installer { $instance = $integration_class::get_instance(); if ($instance && $instance->is_setup()) { - $instance->enable(); - - } // end if; - - } // end foreach; - - } // end _install_other; - -} // end class Migrator; + } + } + } +} diff --git a/inc/integrations/host-providers/class-base-host-provider.php b/inc/integrations/host-providers/class-base-host-provider.php index bf38247..f512be8 100644 --- a/inc/integrations/host-providers/class-base-host-provider.php +++ b/inc/integrations/host-providers/class-base-host-provider.php @@ -79,8 +79,7 @@ abstract class Base_Host_Provider { add_filter('wu_domain_manager_get_integrations', array($this, 'self_register')); add_action('init', array($this, 'add_to_integration_list')); - - } // end init; + } /** * Loads the hooks and dependencies, but only if the hosting is enabled via is_enabled(). @@ -89,13 +88,12 @@ abstract class Base_Host_Provider { */ final public function __construct() { - if ($this->detect() && !$this->is_enabled()) { + if ($this->detect() && ! $this->is_enabled()) { /* * Adds an admin notice telling the admin that they should probably enable this integration. */ return $this->alert_provider_detected(); - - } // end if; + } /* * Only add hooks if the integration is enabled and correctly setup. @@ -104,13 +102,12 @@ abstract class Base_Host_Provider { /* * Checks if everything was correctly setup. */ - if (!$this->is_setup()) { + if ( ! $this->is_setup()) { /* * Adds an admin notice telling the admin that the provider is not correctly setup. */ return $this->alert_provider_not_setup(); - - } // end if; + } /* * Load the dependencies. @@ -121,10 +118,8 @@ abstract class Base_Host_Provider { * Initialize the hooks. */ $this->register_hooks(); - - } // end if; - - } // end __construct; + } + } /** * Let the class register itself on the manager, allowing us to access the integrations later via the slug. @@ -136,11 +131,10 @@ abstract class Base_Host_Provider { */ final public function self_register($integrations) { - $integrations[$this->get_id()] = get_called_class(); + $integrations[ $this->get_id() ] = get_called_class(); return $integrations; - - } // end self_register; + } /** * Get the list of enabled host integrations. @@ -151,8 +145,7 @@ abstract class Base_Host_Provider { protected function get_enabled_list() { return get_network_option(null, 'wu_host_integrations_enabled', array()); - - } // end get_enabled_list; + } /** * Check if this integration is enabled. @@ -165,8 +158,7 @@ abstract class Base_Host_Provider { $list = $this->get_enabled_list(); return wu_get_isset($list, $this->get_id(), false); - - } // end is_enabled; + } /** * Enables this integration. @@ -178,11 +170,10 @@ abstract class Base_Host_Provider { $list = $this->get_enabled_list(); - $list[$this->get_id()] = true; + $list[ $this->get_id() ] = true; return update_network_option(null, 'wu_host_integrations_enabled', $list); - - } // end enable; + } /** * Disables this integration. @@ -194,11 +185,10 @@ abstract class Base_Host_Provider { $list = $this->get_enabled_list(); - $list[$this->get_id()] = false; + $list[ $this->get_id() ] = false; return update_network_option(null, 'wu_host_integrations_enabled', $list); - - } // end disable; + } /** * Adds the host to the list of integrations. @@ -212,9 +202,12 @@ abstract class Base_Host_Provider { $html = $this->is_enabled() ? sprintf(' %s', __('Activated', 'wp-ultimo')) : ''; - $url = wu_network_admin_url('wp-ultimo-hosting-integration-wizard', array( - 'integration' => $slug, - )); + $url = wu_network_admin_url( + 'wp-ultimo-hosting-integration-wizard', + array( + 'integration' => $slug, + ) + ); $html .= sprintf('%s', $url, __('Configuration', 'wp-ultimo')); @@ -226,13 +219,16 @@ abstract class Base_Host_Provider { __('Go to the setup wizard to setup this integration.', 'wp-ultimo') ); - wu_register_settings_field('integrations', "integration_{$slug}", array( - 'type' => 'note', - 'title' => $title, - 'desc' => $html, - )); - - } // end add_to_integration_list; + wu_register_settings_field( + 'integrations', + "integration_{$slug}", + array( + 'type' => 'note', + 'title' => $title, + 'desc' => $html, + ) + ); + } /** * Adds an admin notice telling the admin that they should probably enable this integration. @@ -243,10 +239,8 @@ abstract class Base_Host_Provider { public function alert_provider_detected() { if (WP_Ultimo()->is_loaded() === false) { - return; - - } // end if; + } // translators: %1$s will be replaced with the integration title. E.g. RunCloud $message = sprintf(__('It looks like you are using %1$s as your hosting provider, yet the %1$s integration module is not active. In order for the domain mapping integration to work with %1$s, you might want to activate that module.', 'wp-ultimo'), $this->get_title()); @@ -257,15 +251,17 @@ abstract class Base_Host_Provider { 'activate' => array( // translators: %s is the integration name. 'title' => sprintf(__('Activate %s', 'wp-ultimo'), $this->get_title()), - 'url' => wu_network_admin_url('wp-ultimo-hosting-integration-wizard', array( - 'integration' => $slug, - )), - ) + 'url' => wu_network_admin_url( + 'wp-ultimo-hosting-integration-wizard', + array( + 'integration' => $slug, + ) + ), + ), ); WP_Ultimo()->notices->add($message, 'info', 'network-admin', "should-enable-{$slug}-integration", $actions); - - } // end alert_provider_detected; + } /** * Adds an admin notice telling the admin that the provider is not correctly setup. @@ -276,10 +272,8 @@ abstract class Base_Host_Provider { public function alert_provider_not_setup() { if (WP_Ultimo()->is_loaded() === false) { - return; - - } // end if; + } // translators: %1$s will be replaced with the integration title. E.g. RunCloud. $message = sprintf(__('It looks like you are using %1$s as your hosting provider, yet the %1$s integration module was not properly setup. In order for the domain mapping integration to work with %1$s, you need to configure that module.', 'wp-ultimo'), $this->get_title()); @@ -290,16 +284,18 @@ abstract class Base_Host_Provider { 'activate' => array( // translators: %s is the integration name 'title' => sprintf(__('Setup %s', 'wp-ultimo'), $this->get_title()), - 'url' => wu_network_admin_url('wp-ultimo-hosting-integration-wizard', array( - 'integration' => $slug, - 'tab' => 'config', - )), - ) + 'url' => wu_network_admin_url( + 'wp-ultimo-hosting-integration-wizard', + array( + 'integration' => $slug, + 'tab' => 'config', + ) + ), + ), ); WP_Ultimo()->notices->add($message, 'warning', 'network-admin', "should-setup-{$slug}-integration", $actions); - - } // end alert_provider_not_setup; + } /** * Get Fields for the integration. @@ -310,8 +306,7 @@ abstract class Base_Host_Provider { public function get_fields() { return array(); - - } // end get_fields; + } /** * Returns the integration id. @@ -322,8 +317,7 @@ abstract class Base_Host_Provider { public function get_id() { return $this->id; - - } // end get_id; + } /** * Returns the integration title. @@ -334,8 +328,7 @@ abstract class Base_Host_Provider { public function get_title() { return $this->title; - - } // end get_title; + } /** * Checks if a feature is supported, like auto-ssl for example. @@ -347,8 +340,7 @@ abstract class Base_Host_Provider { public function supports($feature) { return apply_filters('wu_hosting_support_supports', in_array($feature, $this->supports, true), $this); - - } // end supports; + } /** * Initializes the hooks. @@ -381,8 +373,7 @@ abstract class Base_Host_Provider { * Add additional hooks. */ $this->additional_hooks(); - - } // end register_hooks; + } /** * Lets integrations add additional hooks. @@ -390,7 +381,7 @@ abstract class Base_Host_Provider { * @since 2.0.7 * @return void */ - public function additional_hooks() {} // end additional_hooks; + public function additional_hooks() {} /** * Can be used to load dependencies. @@ -398,7 +389,7 @@ abstract class Base_Host_Provider { * @since 2.0.0 * @return void */ - public function load_dependencies() {} // end load_dependencies; + public function load_dependencies() {} /** * Picks up on tips that a given host provider is being used. @@ -421,22 +412,17 @@ abstract class Base_Host_Provider { $all_set = true; foreach ($this->constants as $constant) { - $constants = is_array($constant) ? $constant : array($constant); $current = false; foreach ($constants as $constant) { - if (defined($constant) && constant($constant)) { - $current = true; break; - - } // end if; - - } // end foreach; + } + } $all_set = $all_set && $current; @@ -444,16 +430,12 @@ abstract class Base_Host_Provider { * If any constant fail, bail. */ if ($all_set === false) { - return false; - - } // end if; - - } // end foreach; + } + } return $all_set; - - } // end is_setup; + } /** * Returns a list of missing constants configured on wp-config.php @@ -466,30 +448,23 @@ abstract class Base_Host_Provider { $missing_constants = array(); foreach ($this->constants as $constant) { - $constants = is_array($constant) ? $constant : array($constant); $current = false; foreach ($constants as $constant) { - if (defined($constant) && constant($constant)) { - $current = true; break; - - } // end if; - - } // end foreach; + } + } $missing_constants = $current ? $missing_constants : array_merge($missing_constants, $constants); - - } // end foreach; + } return $missing_constants; - - } // end get_missing_constants; + } /** * Returns a list of all constants, optional or not. @@ -502,16 +477,13 @@ abstract class Base_Host_Provider { $constants = array(); foreach ($this->constants as $constant) { - $current = is_array($constant) ? $constant : array($constant); $constants = array_merge($constants, $current); - - } // end foreach; + } return array_merge($constants, $this->optional_constants); - - } // end get_all_constants; + } /** * Adds the constants with their respective values into the wp-config.php. @@ -532,12 +504,9 @@ abstract class Base_Host_Provider { $values = shortcode_atts(array_flip($this->get_all_constants()), $constant_values); foreach ($values as $constant => $value) { - WP_Config::get_instance()->inject_wp_config_constant($constant, $value); - - } // end foreach; - - } // end setup_constants; + } + } /** * Generates a define string for manual insertion on-to wp-config.php. @@ -569,10 +538,8 @@ abstract class Base_Host_Provider { * Adds the constants, one by one. */ foreach ($constant_values as $constant => $value) { - $content[] = sprintf("define( '%s', '%s' );", $constant, $value); - - } // end foreach; + } /* * Adds the final line. @@ -580,8 +547,7 @@ abstract class Base_Host_Provider { $content[] = sprintf('// WP Multisite WaaS - Domain Mapping - %s - End', $this->get_title()); return implode(PHP_EOL, $content); - - } // end get_constants_string; + } /** * Returns the explainer lines for the integration. @@ -603,17 +569,14 @@ abstract class Base_Host_Provider { // translators: %s is the name of the integration e.g. RunCloud $explainer_lines['will'][] = sprintf(__('Fetch and install a SSL certificate on %s platform after the domain is added.', 'wp-ultimo'), $this->get_title()); - } else { // translators: %s is the name of the integration e.g. RunCloud $explainer_lines['will_not'][] = sprintf(__('Fetch and install a SSL certificate on %s platform after the domain is added. This needs to be done manually.', 'wp-ultimo'), $this->get_title()); - - } // end if; + } return $explainer_lines; - - } // end get_explainer_lines; + } /** * This method gets called when a new domain is mapped. @@ -670,8 +633,7 @@ abstract class Base_Host_Provider { public function test_connection() { wp_send_json_success(array()); - - } // end test_connection; + } /** * Returns the description of this integration. @@ -682,8 +644,7 @@ abstract class Base_Host_Provider { public function get_description() { return __('No description provided.', 'wp-ultimo'); - - } // end get_description; + } /** * Returns the logo for the integration. @@ -694,7 +655,5 @@ abstract class Base_Host_Provider { public function get_logo() { return ''; - - } // end get_logo; - -} // end class Base_Host_Provider; + } +} diff --git a/inc/integrations/host-providers/class-closte-host-provider.php b/inc/integrations/host-providers/class-closte-host-provider.php index d7f70e9..13cbddf 100644 --- a/inc/integrations/host-providers/class-closte-host-provider.php +++ b/inc/integrations/host-providers/class-closte-host-provider.php @@ -78,8 +78,7 @@ class Closte_Host_Provider extends Base_Host_Provider { public function detect() { return defined('CLOSTE_CLIENT_API_KEY') && CLOSTE_CLIENT_API_KEY; - - } // end detect; + } /** * This method gets called when a new domain is mapped. @@ -91,12 +90,14 @@ class Closte_Host_Provider extends Base_Host_Provider { */ public function on_add_domain($domain, $site_id) { - $this->send_closte_api_request('/adddomainalias', array( - 'domain' => $domain, - 'wildcard' => strncmp($domain, '*.', strlen('*.')) === 0 - )); - - } // end on_add_domain; + $this->send_closte_api_request( + '/adddomainalias', + array( + 'domain' => $domain, + 'wildcard' => strncmp($domain, '*.', strlen('*.')) === 0, + ) + ); + } /** * This method gets called when a mapped domain is removed. @@ -108,12 +109,14 @@ class Closte_Host_Provider extends Base_Host_Provider { */ public function on_remove_domain($domain, $site_id) { - $this->send_closte_api_request('/deletedomainalias', array( - 'domain' => $domain, - 'wildcard' => strncmp($domain, '*.', strlen('*.')) === 0 - )); - - } // end on_remove_domain; + $this->send_closte_api_request( + '/deletedomainalias', + array( + 'domain' => $domain, + 'wildcard' => strncmp($domain, '*.', strlen('*.')) === 0, + ) + ); + } /** * This method gets called when a new subdomain is being added. @@ -125,7 +128,7 @@ class Closte_Host_Provider extends Base_Host_Provider { * @param int $site_id ID of the site that is receiving that mapping. * @return void */ - public function on_add_subdomain($subdomain, $site_id) {} // end on_add_subdomain; + public function on_add_subdomain($subdomain, $site_id) {} /** * This method gets called when a new subdomain is being removed. @@ -137,7 +140,7 @@ class Closte_Host_Provider extends Base_Host_Provider { * @param int $site_id ID of the site that is receiving that mapping. * @return void */ - public function on_remove_subdomain($subdomain, $site_id) {} // end on_remove_subdomain; + public function on_remove_subdomain($subdomain, $site_id) {} /** * Tests the connection with the API. @@ -152,18 +155,17 @@ class Closte_Host_Provider extends Base_Host_Provider { $response = $this->send_closte_api_request('/adddomainalias', array()); if (wu_get_isset($response, 'error') === 'Invalid or empty domain: ') { - - wp_send_json_success(array( - 'message' => __('Access Authorized'), - )); - - } // end if; + wp_send_json_success( + array( + 'message' => __('Access Authorized'), + ) + ); + } $error = new \WP_Error('not-auth', __('Something went wrong', 'wp-ultimo')); wp_send_json_error($error); - - } // end test_connection; + } /** * Sends a request to Closte, with the right API key. @@ -176,47 +178,43 @@ class Closte_Host_Provider extends Base_Host_Provider { public function send_closte_api_request($endpoint, $data) { if (defined('CLOSTE_CLIENT_API_KEY') === false) { - return (object) array( 'success' => false, 'error' => 'Closte API Key not found.', ); - - } // end if; + } $post_fields = array( 'blocking' => true, 'timeout' => 45, 'method' => 'POST', - 'body' => array_merge(array( - 'apikey' => CLOSTE_CLIENT_API_KEY, - ), $data) + 'body' => array_merge( + array( + 'apikey' => CLOSTE_CLIENT_API_KEY, + ), + $data + ), ); $response = wp_remote_post('https://app.closte.com/api/client' . $endpoint, $post_fields); wu_log_add('integration-closte', wp_remote_retrieve_body($response)); - if (!is_wp_error($response)) { - + if ( ! is_wp_error($response)) { $body = json_decode(wp_remote_retrieve_body($response), true); if (json_last_error() === JSON_ERROR_NONE) { - return $body; - - } // end if; + } return (object) array( 'success' => false, - 'error' => 'unknown' + 'error' => 'unknown', ); - - } // end if; + } return $response; - - } // end send_closte_api_request; + } /** * Returns the description of this integration. @@ -227,8 +225,7 @@ class Closte_Host_Provider extends Base_Host_Provider { public function get_description() { return __('Closte is not just another web hosting who advertise their services as a cloud hosting while still provides fixed plans like in 1995.', 'wp-ultimo'); - - } // end get_description; + } /** * Returns the logo for the integration. @@ -239,7 +236,5 @@ class Closte_Host_Provider extends Base_Host_Provider { public function get_logo() { return wu_get_asset('closte.svg', 'img/hosts'); - - } // end get_logo; - -} // end class Closte_Host_Provider; + } +} diff --git a/inc/integrations/host-providers/class-cloudflare-host-provider.php b/inc/integrations/host-providers/class-cloudflare-host-provider.php index 6a03456..33cb147 100644 --- a/inc/integrations/host-providers/class-cloudflare-host-provider.php +++ b/inc/integrations/host-providers/class-cloudflare-host-provider.php @@ -83,21 +83,21 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { $default_zone_id = defined('WU_CLOUDFLARE_ZONE_ID') && WU_CLOUDFLARE_ZONE_ID ? WU_CLOUDFLARE_ZONE_ID : false; if ($default_zone_id) { - $zone_ids[] = $default_zone_id; + } - } // end if; - - $cloudflare_zones = $this->cloudflare_api_call('client/v4/zones', 'GET', array( - 'name' => $domain, - 'status' => 'active', - )); + $cloudflare_zones = $this->cloudflare_api_call( + 'client/v4/zones', + 'GET', + array( + 'name' => $domain, + 'status' => 'active', + ) + ); foreach ($cloudflare_zones->result as $zone) { - $zone_ids[] = $zone->id; - - } // end foreach; + } foreach ($zone_ids as $zone_id) { @@ -105,20 +105,22 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { * First, try to detect the domain as a proxied on the current zone, * if applicable */ - $dns_entries = $this->cloudflare_api_call("client/v4/zones/$zone_id/dns_records/", 'GET', array( - 'name' => $domain, - 'match' => 'any', - 'type' => 'A,AAAA,CNAME', - )); - - if (!empty($dns_entries->result)) { + $dns_entries = $this->cloudflare_api_call( + "client/v4/zones/$zone_id/dns_records/", + 'GET', + array( + 'name' => $domain, + 'match' => 'any', + 'type' => 'A,AAAA,CNAME', + ) + ); + if ( ! empty($dns_entries->result)) { $proxied_tag = sprintf('%s', wu_tooltip_text(__('Proxied', 'wp-ultimo')), __('Cloudflare', 'wp-ultimo')); $not_proxied_tag = sprintf('%s', wu_tooltip_text(__('Not Proxied', 'wp-ultimo')), __('Cloudflare', 'wp-ultimo')); foreach ($dns_entries->result as $entry) { - $dns_records[] = array( 'ttl' => $entry->ttl, 'data' => $entry->content, @@ -126,16 +128,12 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { 'host' => $entry->name, 'tag' => $entry->proxied ? $proxied_tag : $not_proxied_tag, ); - - } // end foreach; - - } // end if; - - } // end foreach; + } + } + } return $dns_records; - - } // end add_cloudflare_dns_entries; + } /** * Picks up on tips that a given host provider is being used. * @@ -152,8 +150,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { * @since 2.1 */ return false; - - } // end detect; + } /** * Returns the list of installation fields. @@ -173,8 +170,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { 'placeholder' => __('e.g. xKGbxxVDpdcUv9dUzRf4i4ngv0QNf1wCtbehiec_o', 'wp-ultimo'), ), ); - - } // end get_fields; + } /** * Tests the connection with the Cloudflare API. @@ -187,14 +183,11 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { $results = $this->cloudflare_api_call('client/v4/user/tokens/verify'); if (is_wp_error($results)) { - wp_send_json_error($results); - - } // end if; + } wp_send_json_success($results); - - } // end test_connection; + } /** * Lets integrations add additional hooks. @@ -205,8 +198,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { public function additional_hooks() { add_filter('wu_domain_dns_get_record', array($this, 'add_cloudflare_dns_entries'), 10, 2); - - } // end additional_hooks; + } /** * This method gets called when a new domain is mapped. @@ -216,7 +208,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { * @param int $site_id ID of the site that is receiving that mapping. * @return void */ - public function on_add_domain($domain, $site_id) {} // end on_add_domain; + public function on_add_domain($domain, $site_id) {} /** * This method gets called when a mapped domain is removed. @@ -226,7 +218,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { * @param int $site_id ID of the site that is receiving that mapping. * @return void */ - public function on_remove_domain($domain, $site_id) {} // end on_remove_domain; + public function on_remove_domain($domain, $site_id) {} /** * This method gets called when a new subdomain is being added. @@ -244,25 +236,20 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { $zone_id = defined('WU_CLOUDFLARE_ZONE_ID') && WU_CLOUDFLARE_ZONE_ID ? WU_CLOUDFLARE_ZONE_ID : ''; - if (!$zone_id) { - + if ( ! $zone_id) { return; - - } // end if; + } if (strpos($subdomain, (string) $current_site->domain) === false) { - return; // Not a sub-domain of the main domain. - } // end if; + } $subdomain = rtrim(str_replace($current_site->domain, '', $subdomain), '.'); - if (!$subdomain) { - + if ( ! $subdomain) { return; - - } // end if; + } $should_add_www = apply_filters('wu_cloudflare_should_add_www', true, $subdomain, $site_id); @@ -272,38 +259,36 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { * Adds the www version, if necessary. */ if (strncmp($subdomain, 'www.', strlen('www.')) !== 0 && $should_add_www) { - $domains_to_send[] = 'www.' . $subdomain; - - } // end if; + } foreach ($domains_to_send as $subdomain) { - $should_proxy = apply_filters('wu_cloudflare_should_proxy', true, $subdomain, $site_id); - $data = apply_filters('wu_cloudflare_on_add_domain_data', array( - 'type' => 'CNAME', - 'name' => $subdomain, - 'content' => '@', - 'proxied' => $should_proxy, - 'ttl' => 1, - ), $subdomain, $site_id); + $data = apply_filters( + 'wu_cloudflare_on_add_domain_data', + array( + 'type' => 'CNAME', + 'name' => $subdomain, + 'content' => '@', + 'proxied' => $should_proxy, + 'ttl' => 1, + ), + $subdomain, + $site_id + ); $results = $this->cloudflare_api_call("client/v4/zones/$zone_id/dns_records/", 'POST', $data); if (is_wp_error($results)) { - wu_log_add('integration-cloudflare', sprintf('Failed to add subdomain "%s" to Cloudflare. Reason: %s', $subdomain, $results->get_error_message()), LogLevel::ERROR); return; - - } // end if; + } wu_log_add('integration-cloudflare', sprintf('Added sub-domain "%s" to Cloudflare.', $subdomain)); - - } // end foreach; - - } // end on_add_subdomain; + } + } /** * This method gets called when a new subdomain is being removed. @@ -321,27 +306,22 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { $zone_id = defined('WU_CLOUDFLARE_ZONE_ID') && WU_CLOUDFLARE_ZONE_ID ? WU_CLOUDFLARE_ZONE_ID : ''; - if (!$zone_id) { - + if ( ! $zone_id) { return; - - } // end if; + } if (strpos($subdomain, (string) $current_site->domain) === false) { - return; // Not a sub-domain of the main domain. - } // end if; + } $original_subdomain = $subdomain; $subdomain = rtrim(str_replace($current_site->domain, '', $subdomain), '.'); - if (!$subdomain) { - + if ( ! $subdomain) { return; - - } // end if; + } /** * Created the list that we should remove. @@ -352,35 +332,32 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { ); foreach ($domains_to_remove as $original_subdomain) { + $dns_entries = $this->cloudflare_api_call( + "client/v4/zones/$zone_id/dns_records/", + 'GET', + array( + 'name' => $original_subdomain, + 'type' => 'CNAME', + ) + ); - $dns_entries = $this->cloudflare_api_call("client/v4/zones/$zone_id/dns_records/", 'GET', array( - 'name' => $original_subdomain, - 'type' => 'CNAME', - )); - - if (!$dns_entries->result) { - + if ( ! $dns_entries->result) { return; - - } // end if; + } $dns_entry_to_remove = $dns_entries->result[0]; $results = $this->cloudflare_api_call("client/v4/zones/$zone_id/dns_records/$dns_entry_to_remove->id", 'DELETE'); if (is_wp_error($results)) { - wu_log_add('integration-cloudflare', sprintf('Failed to remove subdomain "%s" to Cloudflare. Reason: %s', $subdomain, $results->get_error_message()), LogLevel::ERROR); return; - - } // end if; + } wu_log_add('integration-cloudflare', sprintf('Removed sub-domain "%s" to Cloudflare.', $subdomain)); - - } // end foreach; - - } // end on_remove_subdomain; + } + } /** * Sends an API call to Cloudflare. * @@ -389,7 +366,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { * @param string $endpoint The endpoint to call. * @param string $method The HTTP verb. Defaults to GET. * @param array $data The date to send. - * @return object|\WP_Error + * @return object|\WP_Error */ protected function cloudflare_api_call($endpoint = 'client/v4/user/tokens/verify', $method = 'GET', $data = array()): object { @@ -397,37 +374,33 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { $endpoint_url = $api_url . $endpoint; - $response = wp_remote_request($endpoint_url, array( - 'method' => $method, - 'body' => $method === 'GET' ? $data : wp_json_encode($data), - 'data_format' => 'body', - 'headers' => array( - 'Authorization' => sprintf('Bearer %s', defined('WU_CLOUDFLARE_API_KEY') ? WU_CLOUDFLARE_API_KEY : ''), - 'Content-Type' => 'application/json', - ), - )); - - if (!is_wp_error($response)) { + $response = wp_remote_request( + $endpoint_url, + array( + 'method' => $method, + 'body' => $method === 'GET' ? $data : wp_json_encode($data), + 'data_format' => 'body', + 'headers' => array( + 'Authorization' => sprintf('Bearer %s', defined('WU_CLOUDFLARE_API_KEY') ? WU_CLOUDFLARE_API_KEY : ''), + 'Content-Type' => 'application/json', + ), + ) + ); + if ( ! is_wp_error($response)) { $body = wp_remote_retrieve_body($response); if (wp_remote_retrieve_response_code($response) === 200) { - return json_decode($body); - } else { - $error_message = wp_remote_retrieve_response_message($response); $response = new \WP_Error('cloudflare-error', sprintf('%s: %s', $error_message, $body)); - - } // end if; - - } // end if; + } + } return $response; - - } // end cloudflare_api_call; + } /** * Renders the instructions content. @@ -438,8 +411,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { public function get_instructions() { wu_get_template('wizards/host-integrations/cloudflare-instructions'); - - } // end get_instructions; + } /** * Returns the description of this integration. @@ -450,8 +422,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { public function get_description() { return __('Cloudflare secures and ensures the reliability of your external-facing resources such as websites, APIs, and applications. It protects your internal resources such as behind-the-firewall applications, teams, and devices. And it is your platform for developing globally-scalable applications.', 'wp-ultimo'); - - } // end get_description; + } /** * Returns the logo for the integration. @@ -462,8 +433,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { public function get_logo() { return wu_get_asset('cloudflare.svg', 'img/hosts'); - - } // end get_logo; + } /** * Returns the explainer lines for the integration. @@ -479,19 +449,13 @@ class Cloudflare_Host_Provider extends Base_Host_Provider { ); if (is_subdomain_install()) { - $explainer_lines['will']['send_sub_domains'] = __('Add a new proxied subdomain to the configured CloudFlare zone whenever a new site gets created', 'wp-ultimo'); - } else { - $explainer_lines['will']['subdirectory'] = __('Do nothing! The CloudFlare integration has no effect in subdirectory multisite installs such as this one', 'wp-ultimo'); - - } // end if; + } $explainer_lines['will_not']['send_domain'] = __('Add domain mappings as new CloudFlare zones', 'wp-ultimo'); return $explainer_lines; - - } // end get_explainer_lines; - -} // end class Cloudflare_Host_Provider; + } +} diff --git a/inc/integrations/host-providers/class-cloudways-host-provider.php b/inc/integrations/host-providers/class-cloudways-host-provider.php index f0fe640..6ade886 100644 --- a/inc/integrations/host-providers/class-cloudways-host-provider.php +++ b/inc/integrations/host-providers/class-cloudways-host-provider.php @@ -92,8 +92,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider { // Add the action to sync domains SSL. add_action('wu_domain_manager_dns_propagation_finished', array($this, 'request_ssl'), 10, 0); - - } // end init; + } /** * Runs a request to Cloudways API to install SSL, after ensuring that the domain is already mapped. @@ -105,29 +104,25 @@ class Cloudways_Host_Provider extends Base_Host_Provider { /** * If the integration is not active, bail. */ - if (!$this->is_enabled()) { - + if ( ! $this->is_enabled()) { return; - - } // end if; + } $all_domains = $this->get_domains(); - $ssl_response = $this->send_cloudways_request('/security/lets_encrypt_install', array( - 'ssl_domains' => $this->get_valid_ssl_domains($all_domains), - )); + $ssl_response = $this->send_cloudways_request( + '/security/lets_encrypt_install', + array( + 'ssl_domains' => $this->get_valid_ssl_domains($all_domains), + ) + ); if (is_wp_error($ssl_response)) { - wu_log_add('integration-cloudways', '[SSL]' . $ssl_response->get_error_message(), LogLevel::ERROR); - } else { - wu_log_add('integration-cloudways', '[SSL]' . print_r($ssl_response, true)); - - } // end if; - - } // end request_ssl; + } + } /** * Picks up on tips that a given host provider is being used. * @@ -138,8 +133,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider { public function detect(): bool { return strpos(ABSPATH, 'cloudways') !== false; - - } // end detect; + } /** * Returns the list of installation fields. @@ -177,8 +171,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider { 'placeholder' => __('e.g. *.test.com, test.com', 'wp-ultimo'), ), ); - - } // end get_fields; + } /** * This method gets called when a new domain is mapped. @@ -191,8 +184,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider { public function on_add_domain($domain, $site_id) { $this->sync_domains(); - - } // end on_add_domain; + } /** * This method gets called when a mapped domain is removed. @@ -205,8 +197,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider { public function on_remove_domain($domain, $site_id) { $this->sync_domains(); - - } // end on_remove_domain; + } /** * This method gets called when a new subdomain is being added. @@ -219,8 +210,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider { * @return void */ public function on_add_subdomain($subdomain, $site_id) { - - } // end on_add_subdomain; + } /** * This method gets called when a new subdomain is being removed. @@ -233,8 +223,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider { * @return void */ public function on_remove_subdomain($subdomain, $site_id) { - - } // end on_remove_subdomain; + } /** * Syncs the domains with the Cloudways API. @@ -246,21 +235,19 @@ class Cloudways_Host_Provider extends Base_Host_Provider { $all_domains = $this->get_domains(); - $alias_response = $this->send_cloudways_request('/app/manage/aliases', array( - 'aliases' => $all_domains, - )); + $alias_response = $this->send_cloudways_request( + '/app/manage/aliases', + array( + 'aliases' => $all_domains, + ) + ); if (is_wp_error($alias_response)) { - wu_log_add('integration-cloudways', '[Alias]' . $alias_response->get_error_message(), LogLevel::ERROR); - } else { - wu_log_add('integration-cloudways', '[Alias]' . print_r($alias_response, true)); - - } // end if; - - } // end sync_domains; + } + } /** * Returns an array of valid SSL domains to be used with the Cloudways API based on a list of domains. * @@ -269,17 +256,19 @@ class Cloudways_Host_Provider extends Base_Host_Provider { */ private function get_valid_ssl_domains($domains): array { - $ssl_domains = array_unique(array_map(function($domain) { + $ssl_domains = array_unique( + array_map( + function ($domain) { - if (strncmp($domain, '*.', strlen('*.')) === 0) { + if (strncmp($domain, '*.', strlen('*.')) === 0) { + $domain = str_replace('*.', '', $domain); + } - $domain = str_replace('*.', '', $domain); - - } - - return $domain; - - }, $domains)); + return $domain; + }, + $domains + ) + ); $ssl_valid_domains = $this->check_domain_dns($ssl_domains, Helper::get_network_public_ip()); @@ -289,8 +278,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider { $ssl_valid_domains[] = $main_domain; return array_values(array_unique(array_filter($ssl_valid_domains))); - - } // end get_valid_ssl_domains; + } /** * Returns an array of all domains that should be added to Cloudways. * @@ -302,20 +290,15 @@ class Cloudways_Host_Provider extends Base_Host_Provider { $domain_list = $this->get_domain_list(); foreach ($domain_list as $naked_domain) { - if (strncmp((string) $naked_domain, 'www.', strlen('www.')) !== 0 && strncmp((string) $naked_domain, '*.', strlen('*.')) !== 0) { - $domain_list[] = 'www.' . $naked_domain; - - } // end if; - - } // end foreach; + } + } sort($domain_list); return array_values(array_unique(array_filter($domain_list))); - - } // end get_domains; + } /** * Validates the DNS records for the domains. @@ -334,35 +317,25 @@ class Cloudways_Host_Provider extends Base_Host_Provider { $response = wp_remote_get('https://dns.google/resolve?name=' . $domain_name); if (is_wp_error($response)) { - wu_log_add('integration-cloudways', $response->get_error_message(), LogLevel::ERROR); continue; - - } // end if; + } $data = json_decode(wp_remote_retrieve_body($response), true); if (isset($data['Answer'])) { - foreach ($data['Answer'] as $answer) { - if ($answer['data'] === $network_ip) { - $valid_domains[] = $domain_name; break; - - } // end if; - - } // end foreach; - - } // end if; - - } // end foreach; + } + } + } + } return $valid_domains; - - } // end check_domain_dns; + } /** * Tests the connection with the Cloudways API. @@ -375,14 +348,11 @@ class Cloudways_Host_Provider extends Base_Host_Provider { $response = $this->send_cloudways_request('/app/manage/fpm_setting', array(), 'GET'); if (is_wp_error($response) || wu_get_isset($response, 'error')) { - wp_send_json_error($response); - - } // end if; + } wp_send_json_success($response); - - } // end test_connection; + } /** * Returns an array of all the mapped domains currently on the network @@ -396,7 +366,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider { $final_domain_list = array(); - // Prepare the query + // Prepare the query $query = "SELECT domain FROM {$wpdb->base_prefix}wu_domain_mappings"; // Suppress errors in case the table doesn't exist. @@ -405,22 +375,17 @@ class Cloudways_Host_Provider extends Base_Host_Provider { $mappings = $wpdb->get_col($query, 0); // phpcs:ignore foreach ($mappings as $domain) { - $final_domain_list[] = $domain; if (strncmp((string) $domain, 'www.', strlen('www.')) !== 0) { - $final_domain_list[] = "www.$domain"; - - } // end if; - - } // end foreach; + } + } $wpdb->suppress_errors($suppress); return $final_domain_list; - - } // end get_all_mapped_domains; + } /** * Get extra domains for Cloudways @@ -435,16 +400,13 @@ class Cloudways_Host_Provider extends Base_Host_Provider { $extra_domains = defined('WU_CLOUDWAYS_EXTRA_DOMAINS') && WU_CLOUDWAYS_EXTRA_DOMAINS; if ($extra_domains) { - $extra_domains_list = array_filter(array_map('trim', explode(',', (string) WU_CLOUDWAYS_EXTRA_DOMAINS))); $domain_list = array_merge($domain_list, $extra_domains_list); - - } // end if; + } return $domain_list; - - } // end get_domain_list; + } /** * Fetches and saves a Cloudways access token. @@ -456,42 +418,38 @@ class Cloudways_Host_Provider extends Base_Host_Provider { $token = get_site_transient('wu_cloudways_token'); - if (!$token) { - - $response = wp_remote_post('https://api.cloudways.com/api/v1/oauth/access_token', array( - 'blocking' => true, - 'method' => 'POST', - 'headers' => array( - 'cache-control' => 'no-cache', - 'content-type' => 'application/x-www-form-urlencoded', - ), - 'body' => array( - 'email' => defined('WU_CLOUDWAYS_EMAIL') ? WU_CLOUDWAYS_EMAIL : '', - 'api_key' => defined('WU_CLOUDWAYS_API_KEY') ? WU_CLOUDWAYS_API_KEY : '', - ), - )); - - if (!is_wp_error($response)) { + if ( ! $token) { + $response = wp_remote_post( + 'https://api.cloudways.com/api/v1/oauth/access_token', + array( + 'blocking' => true, + 'method' => 'POST', + 'headers' => array( + 'cache-control' => 'no-cache', + 'content-type' => 'application/x-www-form-urlencoded', + ), + 'body' => array( + 'email' => defined('WU_CLOUDWAYS_EMAIL') ? WU_CLOUDWAYS_EMAIL : '', + 'api_key' => defined('WU_CLOUDWAYS_API_KEY') ? WU_CLOUDWAYS_API_KEY : '', + ), + ) + ); + if ( ! is_wp_error($response)) { $body = json_decode(wp_remote_retrieve_body($response), true); if (isset($body['access_token'])) { - $expires_in = isset($body['expires_in']) ? $body['expires_in'] : 50 * MINUTE_IN_SECONDS; set_site_transient('wu_cloudways_token', $body['access_token'], $expires_in); $token = $body['access_token']; - - } // end if; - - } // end if; - - } // end if; + } + } + } return $token; - - } // end get_cloudways_access_token; + } /** * Sends a request to the Cloudways API. @@ -501,7 +459,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider { * @param string $endpoint The API endpoint. * @param array $data The data to send. * @param string $method The HTTP verb. - * @return object|\WP_Error + * @return object|\WP_Error */ protected function send_cloudways_request($endpoint, $data = array(), $method = 'POST'): object { @@ -512,44 +470,43 @@ class Cloudways_Host_Provider extends Base_Host_Provider { $endpoint_url = "https://api.cloudways.com/api/v1$endpoint"; if ($method === 'GET') { - - $endpoint_url = add_query_arg(array( - 'server_id' => defined('WU_CLOUDWAYS_SERVER_ID') ? WU_CLOUDWAYS_SERVER_ID : '', - 'app_id' => defined('WU_CLOUDWAYS_APP_ID') ? WU_CLOUDWAYS_APP_ID : '', - ), $endpoint_url); - + $endpoint_url = add_query_arg( + array( + 'server_id' => defined('WU_CLOUDWAYS_SERVER_ID') ? WU_CLOUDWAYS_SERVER_ID : '', + 'app_id' => defined('WU_CLOUDWAYS_APP_ID') ? WU_CLOUDWAYS_APP_ID : '', + ), + $endpoint_url + ); } else { - $data['server_id'] = defined('WU_CLOUDWAYS_SERVER_ID') ? WU_CLOUDWAYS_SERVER_ID : ''; $data['app_id'] = defined('WU_CLOUDWAYS_APP_ID') ? WU_CLOUDWAYS_APP_ID : ''; $data['ssl_email'] = defined('WU_CLOUDWAYS_EMAIL') ? WU_CLOUDWAYS_EMAIL : ''; $data['wild_card'] = false; + } - } // end if; - - $response = wp_remote_post($endpoint_url, array( - 'blocking' => true, - 'method' => $method, - 'timeout' => 45, - 'body' => $data, - 'headers' => array( - 'cache-control' => 'no-cache', - 'content-type' => 'application/x-www-form-urlencoded', - 'authorization' => "Bearer $token", - ), - )); + $response = wp_remote_post( + $endpoint_url, + array( + 'blocking' => true, + 'method' => $method, + 'timeout' => 45, + 'body' => $data, + 'headers' => array( + 'cache-control' => 'no-cache', + 'content-type' => 'application/x-www-form-urlencoded', + 'authorization' => "Bearer $token", + ), + ) + ); if (is_wp_error($response)) { - return $response; - - } // end if; + } $response_data = wp_remote_retrieve_body($response); return json_decode($response_data); - - } // end send_cloudways_request; + } /** * Renders the instructions content. @@ -560,8 +517,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider { public function get_instructions() { wu_get_template('wizards/host-integrations/cloudways-instructions'); - - } // end get_instructions; + } /** * Returns the description of this integration. @@ -572,8 +528,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider { public function get_description() { return __('Focus on your business and avoid all the web hosting hassles. Our managed hosting guarantees unmatched performance, reliability and choice with 24/7 support that acts as your extended team, making Cloudways an ultimate choice for growing agencies and e-commerce businesses.', 'wp-ultimo'); - - } // end get_description; + } /** * Returns the logo for the integration. @@ -584,7 +539,5 @@ class Cloudways_Host_Provider extends Base_Host_Provider { public function get_logo() { return wu_get_asset('cloudways.png', 'img/hosts'); - - } // end get_logo; - -} // end class Cloudways_Host_Provider; + } +} diff --git a/inc/integrations/host-providers/class-cpanel-host-provider.php b/inc/integrations/host-providers/class-cpanel-host-provider.php index 3a06b88..b8fd82c 100644 --- a/inc/integrations/host-providers/class-cpanel-host-provider.php +++ b/inc/integrations/host-providers/class-cpanel-host-provider.php @@ -78,7 +78,7 @@ class CPanel_Host_Provider extends Base_Host_Provider { */ protected $optional_constants = array( 'WU_CPANEL_PORT', - 'WU_CPANEL_ROOT_DIR' + 'WU_CPANEL_ROOT_DIR', ); /** @@ -90,18 +90,17 @@ class CPanel_Host_Provider extends Base_Host_Provider { protected $api = null; /** - * Picks up on tips that a given host provider is being used. - * - * We use this to suggest that the user should activate an integration module. - * Unfortunately, we don't have a good method of detecting if someone is running from cPanel. - * - * @since 2.0.0 - */ + * Picks up on tips that a given host provider is being used. + * + * We use this to suggest that the user should activate an integration module. + * Unfortunately, we don't have a good method of detecting if someone is running from cPanel. + * + * @since 2.0.0 + */ public function detect(): bool { return false; - - } // end detect; + } /** * Returns the list of installation fields. @@ -136,8 +135,7 @@ class CPanel_Host_Provider extends Base_Host_Provider { 'value' => '/public_html', ), ); - - } // end get_fields; + } /** * This method gets called when a new domain is mapped. @@ -153,15 +151,18 @@ class CPanel_Host_Provider extends Base_Host_Provider { $root_dir = defined('WU_CPANEL_ROOT_DIR') && WU_CPANEL_ROOT_DIR ? WU_CPANEL_ROOT_DIR : '/public_html'; // Send Request - $results = $this->load_api()->api2('AddonDomain', 'addaddondomain', array( - 'dir' => $root_dir, - 'newdomain' => $domain, - 'subdomain' => $this->get_subdomain($domain), - )); + $results = $this->load_api()->api2( + 'AddonDomain', + 'addaddondomain', + array( + 'dir' => $root_dir, + 'newdomain' => $domain, + 'subdomain' => $this->get_subdomain($domain), + ) + ); $this->log_calls($results); - - } // end on_add_domain; + } /** * This method gets called when a mapped domain is removed. @@ -174,14 +175,17 @@ class CPanel_Host_Provider extends Base_Host_Provider { public function on_remove_domain($domain, $site_id) { // Send Request - $results = $this->load_api()->api2('AddonDomain', 'deladdondomain', array( - 'domain' => $domain, - 'subdomain' => $this->get_subdomain($domain) . '_' . $this->get_site_url(), - )); + $results = $this->load_api()->api2( + 'AddonDomain', + 'deladdondomain', + array( + 'domain' => $domain, + 'subdomain' => $this->get_subdomain($domain) . '_' . $this->get_site_url(), + ) + ); $this->log_calls($results); - - } // end on_remove_domain; + } /** * This method gets called when a new subdomain is being added. @@ -203,16 +207,19 @@ class CPanel_Host_Provider extends Base_Host_Provider { $rootdomain = str_replace($subdomain . '.', '', $this->get_site_url($site_id)); // Send Request - $results = $this->load_api()->api2('SubDomain', 'addsubdomain', array( - 'dir' => $root_dir, - 'domain' => $subdomain, - 'rootdomain' => $rootdomain, - )); + $results = $this->load_api()->api2( + 'SubDomain', + 'addsubdomain', + array( + 'dir' => $root_dir, + 'domain' => $subdomain, + 'rootdomain' => $rootdomain, + ) + ); // Check the results $this->log_calls($results); - - } // end on_add_subdomain; + } /** * This method gets called when a new subdomain is being removed. @@ -224,7 +231,7 @@ class CPanel_Host_Provider extends Base_Host_Provider { * @param int $site_id ID of the site that is receiving that mapping. * @return void */ - public function on_remove_subdomain($subdomain, $site_id) {} // end on_remove_subdomain; + public function on_remove_subdomain($subdomain, $site_id) {} /** * Load the CPanel API. @@ -235,7 +242,6 @@ class CPanel_Host_Provider extends Base_Host_Provider { public function load_api() { if ($this->api === null) { - $username = defined('WU_CPANEL_USERNAME') ? WU_CPANEL_USERNAME : ''; $password = defined('WU_CPANEL_PASSWORD') ? WU_CPANEL_PASSWORD : ''; $host = defined('WU_CPANEL_HOST') ? WU_CPANEL_HOST : ''; @@ -245,12 +251,10 @@ class CPanel_Host_Provider extends Base_Host_Provider { * Set up the API. */ $this->api = new CPanel_API($username, $password, preg_replace('#^https?://#', '', (string) $host), $port); - - } // end if; + } return $this->api; - - } // end load_api; + } /** * Returns the Site URL. * @@ -260,8 +264,7 @@ class CPanel_Host_Provider extends Base_Host_Provider { public function get_site_url($site_id = null): string { return trim(preg_replace('#^https?://#', '', get_site_url($site_id)), '/'); - - } // end get_site_url; + } /** * Returns the sub-domain version of the domain. @@ -274,18 +277,15 @@ class CPanel_Host_Provider extends Base_Host_Provider { public function get_subdomain($domain, $mapped_domain = true) { if ($mapped_domain === false) { - $domain_parts = explode('.', $domain); return array_shift($domain_parts); - - } // end if; + } $subdomain = str_replace(array('.', '/'), '', $domain); return $subdomain; - - } // end get_subdomain; + } /** * Logs the results of the calls for debugging purposes @@ -297,18 +297,13 @@ class CPanel_Host_Provider extends Base_Host_Provider { public function log_calls($results) { if (is_object($results->cpanelresult->data)) { - return wu_log_add('integration-cpanel', $results->cpanelresult->data->reason); - - } elseif (!isset($results->cpanelresult->data[0])) { - + } elseif ( ! isset($results->cpanelresult->data[0])) { return wu_log_add('integration-cpanel', __('Unexpected error ocurred trying to sync domains with CPanel', 'wp-ultimo'), LogLevel::ERROR); - - } // end if; + } return wu_log_add('integration-cpanel', $results->cpanelresult->data[0]->reason); - - } // end log_calls; + } /** * Returns the description of this integration. @@ -319,8 +314,7 @@ class CPanel_Host_Provider extends Base_Host_Provider { public function get_description() { return __('cPanel is the management panel being used on a large number of shared and dedicated hosts across the globe.', 'wp-ultimo'); - - } // end get_description; + } /** * Returns the logo for the integration. @@ -331,8 +325,7 @@ class CPanel_Host_Provider extends Base_Host_Provider { public function get_logo() { return wu_get_asset('cpanel.svg', 'img/hosts'); - - } // end get_logo; + } /** * Tests the connection with the Cloudflare API. @@ -346,17 +339,14 @@ class CPanel_Host_Provider extends Base_Host_Provider { $this->log_calls($results); - if (isset($results->cpanelresult->data) && !isset($results->cpanelresult->error)) { - + if (isset($results->cpanelresult->data) && ! isset($results->cpanelresult->error)) { wp_send_json_success($results); exit; - - } // end if; + } wp_send_json_error($results); - - } // end test_connection; + } /** * Returns the explainer lines for the integration. @@ -374,13 +364,9 @@ class CPanel_Host_Provider extends Base_Host_Provider { ); if (is_subdomain_install()) { - $explainer_lines['will']['send_sub_domains'] = __('Add a new SubDomain on cPanel whenever a new site gets created on your network', 'wp-ultimo'); - - } // end if; + } return $explainer_lines; - - } // end get_explainer_lines; - -} // end class CPanel_Host_Provider; + } +} diff --git a/inc/integrations/host-providers/class-gridpane-host-provider.php b/inc/integrations/host-providers/class-gridpane-host-provider.php index 65f0c12..b3fb4f3 100644 --- a/inc/integrations/host-providers/class-gridpane-host-provider.php +++ b/inc/integrations/host-providers/class-gridpane-host-provider.php @@ -77,8 +77,7 @@ class Gridpane_Host_Provider extends Base_Host_Provider { public function detect() { return defined('GRIDPANE') && GRIDPANE; - - } // end detect; + } /** * Enables this integration. @@ -93,8 +92,7 @@ class Gridpane_Host_Provider extends Base_Host_Provider { $success = \WP_Ultimo\Helpers\WP_Config::get_instance()->revert('SUNRISE'); parent::enable(); - - } // end enable; + } /** * Sends a request to the GridPane API. @@ -112,28 +110,26 @@ class Gridpane_Host_Provider extends Base_Host_Provider { 'timeout' => 45, 'blocking' => true, 'method' => $method, - 'body' => array_merge(array( - 'api_token' => WU_GRIDPANE_API_KEY, - ), $data) + 'body' => array_merge( + array( + 'api_token' => WU_GRIDPANE_API_KEY, + ), + $data + ), ); $response = wp_remote_request("https://my.gridpane.com/api/{$endpoint}", $post_fields); - if (!is_wp_error($response)) { - + if ( ! is_wp_error($response)) { $body = json_decode(wp_remote_retrieve_body($response), true); if (json_last_error() === JSON_ERROR_NONE) { - return $body; - - } // end if; - - } // end if; + } + } return $response; - - } // end send_gridpane_api_request; + } /** * This method gets called when a new domain is mapped. @@ -145,13 +141,15 @@ class Gridpane_Host_Provider extends Base_Host_Provider { */ public function on_add_domain($domain, $site_id) { - return $this->send_gridpane_api_request('application/add-domain', array( - 'server_ip' => WU_GRIDPANE_SERVER_ID, - 'site_url' => WU_GRIDPANE_APP_ID, - 'domain_url' => $domain - )); - - } // end on_add_domain; + return $this->send_gridpane_api_request( + 'application/add-domain', + array( + 'server_ip' => WU_GRIDPANE_SERVER_ID, + 'site_url' => WU_GRIDPANE_APP_ID, + 'domain_url' => $domain, + ) + ); + } /** * This method gets called when a mapped domain is removed. @@ -163,13 +161,15 @@ class Gridpane_Host_Provider extends Base_Host_Provider { */ public function on_remove_domain($domain, $site_id) { - return $this->send_gridpane_api_request('application/delete-domain', array( - 'server_ip' => WU_GRIDPANE_SERVER_ID, - 'site_url' => WU_GRIDPANE_APP_ID, - 'domain_url' => $domain - )); - - } // end on_remove_domain; + return $this->send_gridpane_api_request( + 'application/delete-domain', + array( + 'server_ip' => WU_GRIDPANE_SERVER_ID, + 'site_url' => WU_GRIDPANE_APP_ID, + 'domain_url' => $domain, + ) + ); + } /** * This method gets called when a new subdomain is being added. @@ -181,7 +181,7 @@ class Gridpane_Host_Provider extends Base_Host_Provider { * @param int $site_id ID of the site that is receiving that mapping. * @return void */ - public function on_add_subdomain($subdomain, $site_id) {} // end on_add_subdomain; + public function on_add_subdomain($subdomain, $site_id) {} /** * This method gets called when a new subdomain is being removed. @@ -193,7 +193,7 @@ class Gridpane_Host_Provider extends Base_Host_Provider { * @param int $site_id ID of the site that is receiving that mapping. * @return void */ - public function on_remove_subdomain($subdomain, $site_id) {} // end on_remove_subdomain; + public function on_remove_subdomain($subdomain, $site_id) {} /** * Tests the connection with the Gridpane API. @@ -206,26 +206,27 @@ class Gridpane_Host_Provider extends Base_Host_Provider { $results = $this->on_remove_domain('test.com', false); if (wu_get_isset($results, 'message') === 'This action is unauthorized.') { - - wp_send_json_error(array( - 'error' => __('We were not able to successfully establish a connection.', 'wp-ultimo'), - )); - - } // end if; + wp_send_json_error( + array( + 'error' => __('We were not able to successfully establish a connection.', 'wp-ultimo'), + ) + ); + } if (is_wp_error($results)) { + wp_send_json_error( + array( + 'error' => __('We were not able to successfully establish a connection.', 'wp-ultimo'), + ) + ); + } - wp_send_json_error(array( - 'error' => __('We were not able to successfully establish a connection.', 'wp-ultimo'), - )); - - } // end if; - - wp_send_json_success(array( - 'success' => __('Connection successfully established.', 'wp-ultimo'), - )); - - } // end test_connection; + wp_send_json_success( + array( + 'success' => __('Connection successfully established.', 'wp-ultimo'), + ) + ); + } /** * Renders the instructions content. @@ -236,8 +237,7 @@ class Gridpane_Host_Provider extends Base_Host_Provider { public function get_instructions() { wu_get_template('wizards/host-integrations/gridpane-instructions'); - - } // end get_instructions; + } /** * Returns the description of this integration. @@ -248,8 +248,7 @@ class Gridpane_Host_Provider extends Base_Host_Provider { public function get_description() { return __("GridPane is the world's first hosting control panel built exclusively for serious WordPress professionals.", 'wp-ultimo'); - - } // end get_description; + } /** * Returns the logo for the integration. @@ -260,7 +259,5 @@ class Gridpane_Host_Provider extends Base_Host_Provider { public function get_logo() { return wu_get_asset('gridpane.png', 'img/hosts'); - - } // end get_logo; - -} // end class Gridpane_Host_Provider; + } +} diff --git a/inc/integrations/host-providers/class-runcloud-host-provider.php b/inc/integrations/host-providers/class-runcloud-host-provider.php index 2ff6f6e..2034a48 100644 --- a/inc/integrations/host-providers/class-runcloud-host-provider.php +++ b/inc/integrations/host-providers/class-runcloud-host-provider.php @@ -70,17 +70,16 @@ class Runcloud_Host_Provider extends Base_Host_Provider { ); /** - * Picks up on tips that a given host provider is being used. - * - * We use this to suggest that the user should activate an integration module. - * - * @since 2.0.0 - */ + * Picks up on tips that a given host provider is being used. + * + * We use this to suggest that the user should activate an integration module. + * + * @since 2.0.0 + */ public function detect(): bool { return strpos(ABSPATH, 'runcloud') !== false; - - } // end detect; + } /** * Returns the list of installation fields. @@ -112,8 +111,7 @@ class Runcloud_Host_Provider extends Base_Host_Provider { 'placeholder' => __('e.g. 940288', 'wp-ultimo'), ), ); - - } // end get_fields; + } /** * This method gets called when a new domain is mapped. @@ -127,40 +125,35 @@ class Runcloud_Host_Provider extends Base_Host_Provider { $success = false; - $response = $this->send_runcloud_request($this->get_runcloud_base_url('domains'), array( - 'name' => $domain, - 'www' => true, - 'redirection' => 'non-www' - ), 'POST'); + $response = $this->send_runcloud_request( + $this->get_runcloud_base_url('domains'), + array( + 'name' => $domain, + 'www' => true, + 'redirection' => 'non-www', + ), + 'POST' + ); if (is_wp_error($response)) { - wu_log_add('integration-runcloud', $response->get_error_message(), LogLevel::ERROR); - } else { - $success = true; // At least one of the calls was successful; wu_log_add('integration-runcloud', wp_remote_retrieve_body($response)); - - } // end if; + } /** * Only redeploy SSL if at least one of the domains were successfully added */ if ($success) { - $ssl_id = $this->get_runcloud_ssl_id(); if ($ssl_id) { - $this->redeploy_runcloud_ssl($ssl_id); - - } // end if; - - } // end if; - - } // end on_add_domain; + } + } + } /** * This method gets called when a mapped domain is removed. @@ -174,25 +167,18 @@ class Runcloud_Host_Provider extends Base_Host_Provider { $domain_id = $this->get_runcloud_domain_id($domain); - if (!$domain_id) { - + if ( ! $domain_id) { wu_log_add('integration-runcloud', __('Domain name not found on runcloud', 'wp-ultimo')); - - } // end if; + } $response = $this->send_runcloud_request($this->get_runcloud_base_url("domains/$domain_id"), array(), 'DELETE'); if (is_wp_error($response)) { - wu_log_add('integration-runcloud', $response->get_error_message(), LogLevel::ERROR); - } else { - wu_log_add('integration-runcloud', wp_remote_retrieve_body($response)); - - } // end if; - - } // end on_remove_domain; + } + } /** * This method gets called when a new subdomain is being added. @@ -204,7 +190,7 @@ class Runcloud_Host_Provider extends Base_Host_Provider { * @param int $site_id ID of the site that is receiving that mapping. * @return void */ - public function on_add_subdomain($subdomain, $site_id) {} // end on_add_subdomain; + public function on_add_subdomain($subdomain, $site_id) {} /** * This method gets called when a new subdomain is being removed. @@ -216,7 +202,7 @@ class Runcloud_Host_Provider extends Base_Host_Provider { * @param int $site_id ID of the site that is receiving that mapping. * @return void */ - public function on_remove_subdomain($subdomain, $site_id) {} // end on_remove_subdomain; + public function on_remove_subdomain($subdomain, $site_id) {} /** * Tests the connection with the RunCloud API. @@ -229,16 +215,11 @@ class Runcloud_Host_Provider extends Base_Host_Provider { $response = $this->send_runcloud_request($this->get_runcloud_base_url('domains'), array(), 'GET'); if (is_wp_error($response) || wp_remote_retrieve_response_code($response) !== 200) { - wp_send_json_error($response); - } else { - wp_send_json_success($this->maybe_return_runcloud_body($response)); - - } // end if; - - } // end test_connection; + } + } /** * Returns the base domain API url to our calls. @@ -254,8 +235,7 @@ class Runcloud_Host_Provider extends Base_Host_Provider { $appid = defined('WU_RUNCLOUD_APP_ID') ? WU_RUNCLOUD_APP_ID : ''; return "https://manage.runcloud.io/api/v2/servers/{$serverid}/webapps/{$appid}/{$path}"; - - } // end get_runcloud_base_url; + } /** * Sends the request to a given runcloud URL with a given body. @@ -272,19 +252,21 @@ class Runcloud_Host_Provider extends Base_Host_Provider { $password = defined('WU_RUNCLOUD_API_SECRET') ? WU_RUNCLOUD_API_SECRET : ''; - $response = wp_remote_request($url, array( - 'timeout' => 100, - 'redirection' => 5, - 'body' => $data, - 'method' => $method, - 'headers' => array( - 'Authorization' => 'Basic ' . base64_encode($username . ':' . $password), - ), - )); + $response = wp_remote_request( + $url, + array( + 'timeout' => 100, + 'redirection' => 5, + 'body' => $data, + 'method' => $method, + 'headers' => array( + 'Authorization' => 'Basic ' . base64_encode($username . ':' . $password), + ), + ) + ); return $response; - - } // end send_runcloud_request; + } /** * Treats the response, maybe returning the json decoded version @@ -296,16 +278,11 @@ class Runcloud_Host_Provider extends Base_Host_Provider { public function maybe_return_runcloud_body($response) { if (is_wp_error($response)) { - return $response->get_error_message(); - } else { - return json_decode(wp_remote_retrieve_body($response)); - - } // end if; - - } // end maybe_return_runcloud_body; + } + } /** * Returns the RunCloud.io domain id to remove. @@ -320,56 +297,42 @@ class Runcloud_Host_Provider extends Base_Host_Provider { $list = $this->maybe_return_runcloud_body($domains_list); - if (is_object($list) && !empty($list->data)) { - + if (is_object($list) && ! empty($list->data)) { foreach ($list->data as $remote_domain) { - if ($remote_domain->name === $domain) { - return $remote_domain->id; - - } // end if; - - } // end foreach; - - } // end if; + } + } + } return false; - - } // end get_runcloud_domain_id; - /** - * Checks if RunCloud has a SSL cert installed or not, and returns the ID. - * - * @since 1.10.4 - * @return bool|int - */ - public function get_runcloud_ssl_id() { + } + /** + * Checks if RunCloud has a SSL cert installed or not, and returns the ID. + * + * @since 1.10.4 + * @return bool|int + */ + public function get_runcloud_ssl_id() { $ssl_id = false; $response = $this->send_runcloud_request($this->get_runcloud_base_url('ssl'), array(), 'GET'); if (is_wp_error($response)) { - wu_log_add('integration-runcloud', $response->get_error_message(), LogLevel::ERROR); - } else { - $data = $this->maybe_return_runcloud_body($response); wu_log_add('integration-runcloud', json_encode($data)); if (property_exists($data, 'id')) { - $ssl_id = $data->id; - - } // end if; - - } // end if; + } + } return $ssl_id; - - } // end get_runcloud_ssl_id; + } /** * Redeploys the SSL cert when a new domain is added. @@ -383,16 +346,11 @@ class Runcloud_Host_Provider extends Base_Host_Provider { $response = $this->send_runcloud_request($this->get_runcloud_base_url("ssl/$ssl_id"), array(), 'PUT'); if (is_wp_error($response)) { - wu_log_add('integration-runcloud', $response->get_error_message(), LogLevel::ERROR); - } else { - wu_log_add('integration-runcloud', wp_remote_retrieve_body($response)); - - } // end if; - - } // end redeploy_runcloud_ssl; + } + } /** * Renders the instructions content. @@ -403,8 +361,7 @@ class Runcloud_Host_Provider extends Base_Host_Provider { public function get_instructions() { wu_get_template('wizards/host-integrations/runcloud-instructions'); - - } // end get_instructions; + } /** * Returns the description of this integration. @@ -415,8 +372,7 @@ class Runcloud_Host_Provider extends Base_Host_Provider { public function get_description() { return __('With RunCloud, you don’t need to be a Linux expert to build a website powered by DigitalOcean, AWS, or Google Cloud. Use our graphical interface and build a business on the cloud affordably.', 'wp-ultimo'); - - } // end get_description; + } /** * Returns the logo for the integration. @@ -427,7 +383,5 @@ class Runcloud_Host_Provider extends Base_Host_Provider { public function get_logo() { return wu_get_asset('runcloud.svg', 'img/hosts'); - - } // end get_logo; - -} // end class Runcloud_Host_Provider; + } +} diff --git a/inc/integrations/host-providers/class-serverpilot-host-provider.php b/inc/integrations/host-providers/class-serverpilot-host-provider.php index ead12eb..151420c 100644 --- a/inc/integrations/host-providers/class-serverpilot-host-provider.php +++ b/inc/integrations/host-providers/class-serverpilot-host-provider.php @@ -79,8 +79,7 @@ class ServerPilot_Host_Provider extends Base_Host_Provider { public function detect() { return defined('WP_PLUGIN_DIR') && preg_match('/\/srv\/users\/(.+)\/apps\/(.+)/', (string) WP_PLUGIN_DIR); - - } // end detect; + } /** * Returns the list of installation fields. @@ -107,8 +106,7 @@ class ServerPilot_Host_Provider extends Base_Host_Provider { 'placeholder' => __('e.g. 940288', 'wp-ultimo'), ), ); - - } // end get_fields; + } /** * This method gets called when a new domain is mapped. @@ -123,19 +121,19 @@ class ServerPilot_Host_Provider extends Base_Host_Provider { $current_domain_list = $this->get_server_pilot_domains(); if ($current_domain_list && is_array($current_domain_list)) { - - $this->send_server_pilot_api_request('', array( - 'domains' => array_merge($current_domain_list, array($domain, 'www.' . $domain)), - )); + $this->send_server_pilot_api_request( + '', + array( + 'domains' => array_merge($current_domain_list, array($domain, 'www.' . $domain)), + ) + ); /** * Makes sure autoSSL is always on */ $this->turn_server_pilot_auto_ssl_on(); - - } // end if; - - } // end on_add_domain; + } + } /** * This method gets called when a mapped domain is removed. @@ -156,13 +154,14 @@ class ServerPilot_Host_Provider extends Base_Host_Provider { */ $current_domain_list = array_filter($current_domain_list, fn($remote_domain) => $remote_domain !== $domain && $remote_domain !== 'www.' . $domain); - $this->send_server_pilot_api_request('', array( - 'domains' => $current_domain_list - )); - - } // end if; - - } // end on_remove_domain; + $this->send_server_pilot_api_request( + '', + array( + 'domains' => $current_domain_list, + ) + ); + } + } /** * This method gets called when a new subdomain is being added. @@ -179,19 +178,19 @@ class ServerPilot_Host_Provider extends Base_Host_Provider { $current_domain_list = $this->get_server_pilot_domains(); if ($current_domain_list && is_array($current_domain_list)) { - - $this->send_server_pilot_api_request('', array( - 'domains' => array_merge($current_domain_list, array($subdomain)), - )); + $this->send_server_pilot_api_request( + '', + array( + 'domains' => array_merge($current_domain_list, array($subdomain)), + ) + ); /** * Makes sure autoSSL is always on */ $this->turn_server_pilot_auto_ssl_on(); - - } // end if; - - } // end on_add_subdomain; + } + } /** * This method gets called when a new subdomain is being removed. @@ -203,7 +202,7 @@ class ServerPilot_Host_Provider extends Base_Host_Provider { * @param int $site_id ID of the site that is receiving that mapping. * @return void */ - public function on_remove_subdomain($subdomain, $site_id) {} // end on_remove_subdomain; + public function on_remove_subdomain($subdomain, $site_id) {} /** * Sends a request to ServerPilot, with the right API key. @@ -229,19 +228,16 @@ class ServerPilot_Host_Provider extends Base_Host_Provider { $response = wp_remote_request('https://api.serverpilot.io/v1/apps/' . WU_SERVER_PILOT_APP_ID . $endpoint, $post_fields); - if (!is_wp_error($response)) { - + if ( ! is_wp_error($response)) { $body = json_decode(wp_remote_retrieve_body($response), true); if (json_last_error() === JSON_ERROR_NONE) { return $body; - } // end if; - - } // end if; + } + } return $response; - - } // end send_server_pilot_api_request; + } /** * Makes sure ServerPilot autoSSL is always on, when possible. @@ -251,11 +247,13 @@ class ServerPilot_Host_Provider extends Base_Host_Provider { */ public function turn_server_pilot_auto_ssl_on() { - return $this->send_server_pilot_api_request('/ssl', array( - 'auto' => true, - )); - - } // end turn_server_pilot_auto_ssl_on; + return $this->send_server_pilot_api_request( + '/ssl', + array( + 'auto' => true, + ) + ); + } /** * Get the current list of domains added on Server Pilot. @@ -268,10 +266,8 @@ class ServerPilot_Host_Provider extends Base_Host_Provider { $app_info = $this->send_server_pilot_api_request('', array(), 'GET'); if (isset($app_info['data']['domains'])) { - return $app_info['data']['domains']; - - } // end if; + } /* * Log response so we can see what went wrong @@ -281,8 +277,7 @@ class ServerPilot_Host_Provider extends Base_Host_Provider { wu_log_add('integration-serverpilot', sprintf(__('An error occurred while trying to get the current list of domains: %s', 'wp-ultimo'), json_encode($app_info)), LogLevel::ERROR); return false; - - } // end get_server_pilot_domains; + } /** * Tests the connection with the ServerPilot API. @@ -295,14 +290,11 @@ class ServerPilot_Host_Provider extends Base_Host_Provider { $response = $this->send_server_pilot_api_request('', array(), 'GET'); if (is_wp_error($response) || wu_get_isset($response, 'error')) { - wp_send_json_error($response); - - } // end if; + } wp_send_json_success($response); - - } // end test_connection; + } /** * Renders the instructions content. @@ -313,8 +305,7 @@ class ServerPilot_Host_Provider extends Base_Host_Provider { public function get_instructions() { wu_get_template('wizards/host-integrations/serverpilot-instructions'); - - } // end get_instructions; + } /** * Returns the description of this integration. @@ -325,8 +316,7 @@ class ServerPilot_Host_Provider extends Base_Host_Provider { public function get_description() { return __('ServerPilot is a cloud service for hosting WordPress and other PHP websites on servers at DigitalOcean, Amazon, Google, or any other server provider. You can think of ServerPilot as a modern, centralized hosting control panel.', 'wp-ultimo'); - - } // end get_description; + } /** * Returns the logo for the integration. @@ -337,7 +327,5 @@ class ServerPilot_Host_Provider extends Base_Host_Provider { public function get_logo() { return wu_get_asset('serverpilot.svg', 'img/hosts'); - - } // end get_logo; - -} // end class ServerPilot_Host_Provider; + } +} diff --git a/inc/integrations/host-providers/class-wpengine-host-provider.php b/inc/integrations/host-providers/class-wpengine-host-provider.php index 292f92b..f83ef23 100644 --- a/inc/integrations/host-providers/class-wpengine-host-provider.php +++ b/inc/integrations/host-providers/class-wpengine-host-provider.php @@ -78,8 +78,7 @@ class WPEngine_Host_Provider extends Base_Host_Provider { public function detect() { return (defined('WPE_APIKEY') && WPE_APIKEY) || (defined('WPE_API') && WPE_API); - - } // end detect; + } /** * Can be used to load dependencies. @@ -90,15 +89,12 @@ class WPEngine_Host_Provider extends Base_Host_Provider { public function load_dependencies() { // if WP Engine is not defined, then return - if (!defined('WPE_PLUGIN_DIR') || !is_readable(WPE_PLUGIN_DIR . '/class-wpeapi.php')) { - + if ( ! defined('WPE_PLUGIN_DIR') || ! is_readable(WPE_PLUGIN_DIR . '/class-wpeapi.php')) { return; - - } // end if; + } include_once WPE_PLUGIN_DIR . '/class-wpeapi.php'; - - } // end load_dependencies; + } /** * This method gets called when a new domain is mapped. @@ -117,8 +113,7 @@ class WPEngine_Host_Provider extends Base_Host_Provider { $api->set_arg('domain', $domain); $api->get(); - - } // end on_add_domain; + } /** * This method gets called when a mapped domain is removed. @@ -137,8 +132,7 @@ class WPEngine_Host_Provider extends Base_Host_Provider { $api->set_arg('domain', $domain); $api->get(); - - } // end on_remove_domain; + } /** * This method gets called when a new subdomain is being added. @@ -153,8 +147,7 @@ class WPEngine_Host_Provider extends Base_Host_Provider { public function on_add_subdomain($subdomain, $site_id) { $this->on_add_domain($subdomain, $site_id); - - } // end on_add_subdomain; + } /** * This method gets called when a new subdomain is being removed. @@ -169,8 +162,7 @@ class WPEngine_Host_Provider extends Base_Host_Provider { public function on_remove_subdomain($subdomain, $site_id) { $this->on_remove_domain($subdomain, $site_id); - - } // end on_remove_subdomain; + } /** * Returns the description of this integration. @@ -185,8 +177,7 @@ class WPEngine_Host_Provider extends Base_Host_Provider { $description .= '

    ' . __('We recommend to enter in contact with WP Engine support to ask for a Wildcard domain if you are using a subdomain install.', 'wp-ultimo') . ''; return $description; - - } // end get_description; + } /** * Returns the logo for the integration. @@ -197,8 +188,7 @@ class WPEngine_Host_Provider extends Base_Host_Provider { public function get_logo() { return wu_get_asset('wpengine.svg', 'img/hosts'); - - } // end get_logo; + } /** * Tests the connection with the WP Engine API. @@ -215,15 +205,9 @@ class WPEngine_Host_Provider extends Base_Host_Provider { $results = $api->get(); if (is_wp_error($results)) { - wp_send_json_error($results->get_error_message()); - } else { - wp_send_json_success($results); - - } // end if; - - } // end test_connection; - -} // end class WPEngine_Host_Provider; + } + } +} diff --git a/inc/integrations/host-providers/class-wpmudev-host-provider.php b/inc/integrations/host-providers/class-wpmudev-host-provider.php index 539196e..e7d85db 100644 --- a/inc/integrations/host-providers/class-wpmudev-host-provider.php +++ b/inc/integrations/host-providers/class-wpmudev-host-provider.php @@ -83,8 +83,7 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider { * This is needed because, from our tests, WPMU DEV hosting takes a while to get the SSL certificate. */ add_filter('wu_async_process_domain_stage_max_tries', array($this, 'ssl_tries'), 10, 2); - - } // end init; + } /** * Increases the number of tries to get the SSL certificate. @@ -96,21 +95,16 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider { */ public function ssl_tries($max_tries, $domain) { - if (!$this->is_enabled()) { - + if ( ! $this->is_enabled()) { return $max_tries; - - } // end if; + } if ('checking-ssl-cert' === $domain->get_stage()) { - $max_tries = 10; - - } // end if; + } return $max_tries; - - } // end ssl_tries; + } /** * Picks up on tips that a given host provider is being used. @@ -123,8 +117,7 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider { public function detect() { return defined('WPMUDEV_HOSTING_SITE_ID') && WPMUDEV_HOSTING_SITE_ID; - - } // end detect; + } /** * This method gets called when a new domain is mapped. @@ -143,30 +136,29 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider { $domains = array($domain); if (strncmp($domain, 'www.', strlen('www.')) !== 0) { - $domains[] = "www.$domain"; - - } // end if; + } foreach ($domains as $_domain) { - - $response = wp_remote_post("https://premium.wpmudev.org/api/hosting/v1/$site_id/domains", array( - 'timeout' => 50, - 'body' => array( - 'domain' => $_domain, - 'site_id' => $site_id, - ), - 'headers' => array( - 'Authorization' => $api_key, - ), - )); + $response = wp_remote_post( + "https://premium.wpmudev.org/api/hosting/v1/$site_id/domains", + array( + 'timeout' => 50, + 'body' => array( + 'domain' => $_domain, + 'site_id' => $site_id, + ), + 'headers' => array( + 'Authorization' => $api_key, + ), + ) + ); if (is_wp_error($response)) { // translators: The %s placeholder will be replaced with the domain name. wu_log_add('integration-wpmudev', sprintf(__('An error occurred while trying to add the custom domain %s to WPMU Dev hosting.', 'wp-ultimo'), $_domain), LogLevel::ERROR); - - } // end if; + } $body = json_decode(wp_remote_retrieve_body($response)); @@ -174,17 +166,13 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider { // translators: The %1$s will be replaced with the domain name and %2$s is the error message. wu_log_add('integration-wpmudev', sprintf(__('An error occurred while trying to add the custom domain %1$s to WPMU Dev hosting: %2$s', 'wp-ultimo'), $_domain, $body->message->message), LogLevel::ERROR); - } else { // translators: The %s placeholder will be replaced with the domain name. wu_log_add('integration-wpmudev', sprintf(__('Domain %s added to WPMU Dev hosting successfully.', 'wp-ultimo'), $_domain)); - - } // end if; - - } // end foreach; - - } // end on_add_domain; + } + } + } /** * This method gets called when a mapped domain is removed. @@ -202,8 +190,7 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider { * * @todo Implement support to removing domains when a mapping is removed. */ - - } // end on_remove_domain; + } /** * This method gets called when a new subdomain is being added. @@ -215,7 +202,7 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider { * @param int $site_id ID of the site that is receiving that mapping. * @return void */ - public function on_add_subdomain($subdomain, $site_id) {} // end on_add_subdomain; + public function on_add_subdomain($subdomain, $site_id) {} /** * This method gets called when a new subdomain is being removed. @@ -227,7 +214,7 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider { * @param int $site_id ID of the site that is receiving that mapping. * @return void */ - public function on_remove_subdomain($subdomain, $site_id) {} // end on_remove_subdomain; + public function on_remove_subdomain($subdomain, $site_id) {} /** * Tests the connection with the WPMUDEV API. @@ -241,24 +228,22 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider { $api_key = get_site_option('wpmudev_apikey'); - $response = wp_remote_get("https://premium.wpmudev.org/api/hosting/v1/{$site_id}/domains", array( - 'timeout' => 50, - 'headers' => array( - 'Authorization' => $api_key, - ), - )); + $response = wp_remote_get( + "https://premium.wpmudev.org/api/hosting/v1/{$site_id}/domains", + array( + 'timeout' => 50, + 'headers' => array( + 'Authorization' => $api_key, + ), + ) + ); if (is_wp_error($response) || wp_remote_retrieve_response_code($response) !== 200) { - wp_send_json_error($response); - } else { - wp_send_json_success(wp_remote_retrieve_body($response)); - - } // end if; - - } // end test_connection; + } + } /** * Returns the description of this integration. @@ -269,8 +254,7 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider { public function get_description() { return __('WPMU DEV is one of the largest companies in the WordPress space. Founded in 2004, it was one of the first companies to scale the Website as a Service model with products such as Edublogs and CampusPress.', 'wp-ultimo'); - - } // end get_description; + } /** * Returns the logo for the integration. @@ -281,7 +265,5 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider { public function get_logo() { return wu_get_asset('wpmudev.jpg', 'img/hosts'); - - } // end get_logo; - -} // end class WPMUDEV_Host_Provider; + } +} diff --git a/inc/integrations/host-providers/cpanel-api/class-cpanel-api.php b/inc/integrations/host-providers/cpanel-api/class-cpanel-api.php index 4218ad7..91f466d 100644 --- a/inc/integrations/host-providers/cpanel-api/class-cpanel-api.php +++ b/inc/integrations/host-providers/cpanel-api/class-cpanel-api.php @@ -17,11 +17,11 @@ use WP_Ultimo\Logger; class CPanel_API { /** - * Holds the name of the cookis file. - * - * @since 2.0.0 - * @var string - */ + * Holds the name of the cookis file. + * + * @since 2.0.0 + * @var string + */ private $cookie_file; /** @@ -41,40 +41,40 @@ class CPanel_API { private $cpsess; /** - * Holds the cPanel url. - * - * @since 2.0.0 - * @var string|null - */ + * Holds the cPanel url. + * + * @since 2.0.0 + * @var string|null + */ private ?string $homepage = null; /** - * Holds the execution url. - * - * @since 2.0.0 - * @var string|null - */ + * Holds the execution url. + * + * @since 2.0.0 + * @var string|null + */ private ?string $ex_page = null; - /** - * @var string - */ - private $username; - /** - * @var string - */ - private $password; - /** - * @var string - */ - private $host; - /** - * @var integer - */ - private $port = 2083; - /** - * @var boolean - */ - private $log = false; + /** + * @var string + */ + private $username; + /** + * @var string + */ + private $password; + /** + * @var string + */ + private $host; + /** + * @var integer + */ + private $port = 2083; + /** + * @var boolean + */ + private $log = false; /** * Creates the CPanel_API Object. @@ -95,18 +95,17 @@ class CPanel_API { ) { $this->username = $username; - $this->password = $password; - $this->host = $host; - $this->port = $port; - $this->log = $log; - // Generates the cookie file + $this->password = $password; + $this->host = $host; + $this->port = $port; + $this->log = $log; + // Generates the cookie file $this->generate_cookie(); $this->cookie_file = Logger::get_logs_folder() . 'integration-cpanel-cookie.log'; // Signs up $this->sign_in(); - - } // end __construct; + } /** * Generate the Cookie File, that is used to make API requests to CPanel. @@ -117,8 +116,7 @@ class CPanel_API { public function generate_cookie() { wu_log_add('integration-cpanel-cookie', ''); - - } // end generate_cookie; + } /** * Logs error or success messages. @@ -130,8 +128,7 @@ class CPanel_API { public function log($message) { return wu_log_add('integration-cpanel', $message); - - } // end log; + } /** * Sends the request to the CPanel API. @@ -144,36 +141,24 @@ class CPanel_API { private function request($url, $params = array()) { if ($this->log) { - $curl_log = fopen($this->curlfile, 'a+'); + } - } // end if; - - if (!file_exists($this->cookie_file)) { - + if ( ! file_exists($this->cookie_file)) { try { - fopen($this->cookie_file, 'w'); - } catch (Exception $ex) { - - if (!file_exists($this->cookie_file)) { - + if ( ! file_exists($this->cookie_file)) { $this->log($ex . __('Cookie file missing.', 'wp-ultimo')); return false; - - } // end if; - - } // end try; - - } elseif (!is_writable($this->cookie_file)) { - + } + } + } elseif ( ! is_writable($this->cookie_file)) { $this->log(__('Cookie file not writable', 'wp-ultimo')); return false; - - } // end if; + } $ch = curl_init(); @@ -192,24 +177,20 @@ class CPanel_API { 'Accept-Language: en-US,en;q=0.5', 'Accept-Encoding: gzip, deflate', 'Connection: keep-alive', - 'Content-Type: application/x-www-form-urlencoded' + 'Content-Type: application/x-www-form-urlencoded', ), ); - if (!empty($params)) { - - $curl_opts[CURLOPT_POST] = true; - $curl_opts[CURLOPT_POSTFIELDS] = $params; - - } // end if; + if ( ! empty($params)) { + $curl_opts[ CURLOPT_POST ] = true; + $curl_opts[ CURLOPT_POSTFIELDS ] = $params; + } if ($this->log) { - - $curl_opts[CURLOPT_STDERR] = $curl_log; - $curl_opts[CURLOPT_FAILONERROR] = false; - $curl_opts[CURLOPT_VERBOSE] = true; - - } // end if; + $curl_opts[ CURLOPT_STDERR ] = $curl_log; + $curl_opts[ CURLOPT_FAILONERROR ] = false; + $curl_opts[ CURLOPT_VERBOSE ] = true; + } curl_setopt_array($ch, $curl_opts); @@ -221,20 +202,16 @@ class CPanel_API { $this->log(sprintf(__('cPanel API Error: %s', 'wp-ultimo'), curl_error($ch))); return false; - - } // end if; + } curl_close($ch); if ($this->log) { - fclose($curl_log); - - } // end if; + } return (@gzdecode($answer)) ? gzdecode($answer) : $answer; // phpcs:ignore - - } // end request; + } /** * Get the base URL to make the calls. * @@ -243,8 +220,7 @@ class CPanel_API { private function get_base_url(): string { return sprintf('https://%s:%s', $this->host, $this->port); - - } // end get_base_url; + } /** * Signs in on the cPanel. @@ -266,14 +242,10 @@ class CPanel_API { $this->cpsess = $reply['security_token']; $this->homepage = $this->get_base_url() . $reply['redirect']; $this->ex_page = $this->get_base_url() . "/{$this->cpsess}/execute/"; - } else { - return $this->log(__('Cannot connect to your cPanel server : Invalid Credentials', 'wp-ultimo')); - - } // end if; - - } // end sign_in; + } + } /** * Executes API calls, taking the request to the right API version @@ -289,15 +261,14 @@ class CPanel_API { public function execute($api, $module, $function, array $parameters = array()) { switch ($api) { - case 'api2': - return $this->api2($module, $function, $parameters); - case 'uapi': - return $this->uapi($module, $function, $parameters); - default: - throw new Exception('Invalid API type : api2 and uapi are accepted', 1); - } // end switch; - - } // end execute; + case 'api2': + return $this->api2($module, $function, $parameters); + case 'uapi': + return $this->uapi($module, $function, $parameters); + default: + throw new Exception('Invalid API type : api2 and uapi are accepted', 1); + } + } /** * Send the request if the API being used is the UAPI (newer version) @@ -311,18 +282,13 @@ class CPanel_API { public function uapi($module, $function, array $parameters = array()) { if (count($parameters) < 1) { - $parameters = ''; - } else { - $parameters = (http_build_query($parameters)); - - } // end if; + } return json_decode((string) $this->request($this->ex_page . $module . '/' . $function . '?' . $parameters)); - - } // end uapi; + } /** * Send the request if the API being used is the API2 (older version) @@ -336,14 +302,10 @@ class CPanel_API { public function api2($module, $function, array $parameters = array()) { if (count($parameters) < 1) { - $parameters = ''; - } else { - $parameters = (http_build_query($parameters)); - - } // end if; + } $url = $this->get_base_url() . $this->cpsess . '/json-api/cpanel' . '?cpanel_jsonapi_version=2' . @@ -351,7 +313,5 @@ class CPanel_API { "&cpanel_jsonapi_module={$module}&" . $parameters; return json_decode((string) $this->request($url, $parameters)); - - } // end api2; - -} // end class CPanel_API; + } +} diff --git a/inc/internal/class-memory-trap.php b/inc/internal/class-memory-trap.php index e766415..02cf2db 100644 --- a/inc/internal/class-memory-trap.php +++ b/inc/internal/class-memory-trap.php @@ -57,8 +57,7 @@ class Memory_Trap { public function set_return_type($return_type) { $this->return_type = $return_type; - - } // end set_return_type; + } /** * Setup the actual error handler. @@ -72,21 +71,20 @@ class Memory_Trap { !defined('WP_SANDBOX_SCRAPING') && define('WP_SANDBOX_SCRAPING', true); // phpcs:ignore - register_shutdown_function(function() { + register_shutdown_function( + function () { - $this->memory_reserve = null; + $this->memory_reserve = null; - $err = error_get_last(); + $err = error_get_last(); if ((!is_null($err)) && (!in_array($err['type'], array(E_NOTICE, E_WARNING, E_DEPRECATED, E_USER_DEPRECATED)))) { // phpcs:ignore - $this->memory_limit_error_handler($err); - - } // end if; - - }); - - } // end setup; + $this->memory_limit_error_handler($err); + } + } + ); + } /** * Send fatal error messages. @@ -102,21 +100,17 @@ class Memory_Trap { $message = sprintf(__('Your server\'s PHP and WordPress memory limits are too low to perform this check. You might need to contact your host provider and ask the PHP memory limit in particular to be raised.', 'wp-ultimo')); if ($this->return_type === 'json') { - - wp_send_json_error(array( - 'message' => $message, - )); + wp_send_json_error( + array( + 'message' => $message, + ) + ); die; - } else { - echo $message; - - } // end if; + } exit; - - } // end memory_limit_error_handler; - -} // end class Memory_Trap; + } +} diff --git a/inc/invoices/class-invoice.php b/inc/invoices/class-invoice.php index c54eeda..d9097a8 100644 --- a/inc/invoices/class-invoice.php +++ b/inc/invoices/class-invoice.php @@ -12,8 +12,8 @@ namespace WP_Ultimo\Invoices; // Exit if accessed directly defined('ABSPATH') || exit; -use \Mpdf\Mpdf; -use \Mpdf\Output\Destination; +use Mpdf\Mpdf; +use Mpdf\Output\Destination; /** * Handles the generation of PDF Invoices. @@ -63,13 +63,12 @@ class Invoice { $this->set_payment($payment); - $saved_atts = Invoice::get_settings(); + $saved_atts = self::get_settings(); $atts = array_merge($saved_atts, $atts); $this->set_attributes($atts); - - } // end __construct; + } /** * Magic getter for attributes. @@ -81,9 +80,8 @@ class Invoice { */ public function __get($key) { - return isset($this->attributes[$key]) ? $this->attributes[$key] : ''; - - } // end __get; + return isset($this->attributes[ $key ]) ? $this->attributes[ $key ] : ''; + } /** * Setups the printer object. Uses mPdf. @@ -93,12 +91,14 @@ class Invoice { */ private function pdf_setup() { - $this->printer = new Mpdf(array( - 'mode' => '+aCJK', - 'autoScriptToLang' => true, - 'autoLangToFont' => true, - 'tempDir' => get_temp_dir(), - )); + $this->printer = new Mpdf( + array( + 'mode' => '+aCJK', + 'autoScriptToLang' => true, + 'autoLangToFont' => true, + 'tempDir' => get_temp_dir(), + ) + ); $this->printer->setDefaultFont($this->font); @@ -108,11 +108,9 @@ class Invoice { $this->printer->SetAuthor($this->company_name); - if (!$this->payment->is_payable()) { - + if ( ! $this->payment->is_payable()) { $this->printer->SetWatermarkText($this->paid_tag_text); - - } // end if; + } $this->printer->showWatermarkText = true; @@ -123,12 +121,9 @@ class Invoice { $this->printer->SetDisplayMode('fullpage'); if ($this->footer_message) { - $this->printer->SetHTMLFooter($this->footer_message); - - } // end if; - - } // end pdf_setup; + } + } /** * Saves the PDF file to the disk. @@ -143,8 +138,7 @@ class Invoice { $file_name = self::get_folder() . $file_name; $this->pdf($file_name); - - } // end save_file; + } /** * Prints the PDF file to the browser. @@ -155,8 +149,7 @@ class Invoice { public function print_file() { $this->pdf(); - - } // end print_file; + } /** * Generates the HTML content of the Invoice template. @@ -177,8 +170,7 @@ class Invoice { $atts['billing_address'] = $atts['membership'] ? $atts['membership']->get_billing_address()->to_array() : array(); return wu_get_template_contents('invoice/template', $atts); - - } // end render; + } /** * Handles the PDF generation. @@ -199,16 +191,11 @@ class Invoice { $this->printer->WriteHTML($this->render()); if ($file_name) { - $this->printer->Output($file_name, Destination::FILE); - } else { - $this->printer->Output(); - - } // end if; - - } // end pdf; + } + } /** * Get the value of payment. @@ -219,8 +206,7 @@ class Invoice { public function get_payment() { return $this->payment; - - } // end get_payment; + } /** * Set the value of payment. @@ -232,8 +218,7 @@ class Invoice { public function set_payment($payment) { $this->payment = $payment; - - } // end set_payment; + } /** * Get the value of attributes. @@ -244,8 +229,7 @@ class Invoice { public function get_attributes() { return $this->attributes; - - } // end get_attributes; + } /** * Set the value of attributes. @@ -256,21 +240,23 @@ class Invoice { */ public function set_attributes($attributes) { - $attributes = wp_parse_args($attributes, array( - 'company_name' => wu_get_setting('company_name'), - 'company_address' => wu_get_setting('company_address'), - 'primary_color' => '#675645', - 'font' => 'DejaVuSansCondensed', - 'logo_url' => wu_get_network_logo(), - 'use_custom_logo' => false, - 'custom_logo' => false, - 'footer_message' => '', - 'paid_tag_text' => __('Paid', 'wp-ultimo'), - )); + $attributes = wp_parse_args( + $attributes, + array( + 'company_name' => wu_get_setting('company_name'), + 'company_address' => wu_get_setting('company_address'), + 'primary_color' => '#675645', + 'font' => 'DejaVuSansCondensed', + 'logo_url' => wu_get_network_logo(), + 'use_custom_logo' => false, + 'custom_logo' => false, + 'footer_message' => '', + 'paid_tag_text' => __('Paid', 'wp-ultimo'), + ) + ); $this->attributes = $attributes; - - } // end set_attributes; + } /** * Generates the folder to keep invoices and returns the path. @@ -281,8 +267,7 @@ class Invoice { public static function get_folder() { return wu_maybe_create_folder('wu-invoices'); - - } // end get_folder; + } /** * Returns the list of saved settings to customize the invoices.. @@ -292,9 +277,8 @@ class Invoice { */ public static function get_settings() { - return wu_get_option(Invoice::KEY, array()); - - } // end get_settings; + return wu_get_option(self::KEY, array()); + } /** * Save settings. @@ -311,17 +295,11 @@ class Invoice { $allowed_keys = array_keys($invoice->get_attributes()); foreach ($settings_to_save as $setting_to_save => $value) { + if ( ! in_array($setting_to_save, $allowed_keys, true)) { + unset($settings_to_save[ $setting_to_save ]); + } + } - if (!in_array($setting_to_save, $allowed_keys, true)) { - - unset($settings_to_save[$setting_to_save]); - - } // end if; - - } // end foreach; - - return wu_save_option(Invoice::KEY, $settings_to_save); - - } // end save_settings; - -} // end class Invoice; + return wu_save_option(self::KEY, $settings_to_save); + } +} diff --git a/inc/limitations/class-limit-customer-user-role.php b/inc/limitations/class-limit-customer-user-role.php index 1441242..d0193ae 100644 --- a/inc/limitations/class-limit-customer-user-role.php +++ b/inc/limitations/class-limit-customer-user-role.php @@ -37,10 +37,9 @@ class Limit_Customer_User_Role extends Limit { return array( 'enabled' => true, - 'limit' => 'default' + 'limit' => 'default', ); - - } // end default_state; + } /** * The check method is what gets called when allowed is called. @@ -58,8 +57,7 @@ class Limit_Customer_User_Role extends Limit { public function check($value_to_check, $limit, $type = '') { return true; - - } // end check; + } /** * Gets the limit data. @@ -74,7 +72,5 @@ class Limit_Customer_User_Role extends Limit { $default_value = wu_get_setting('default_role', 'administrator'); return empty($this->limit) || $this->limit === 'default' ? $default_value : $this->limit; - - } // end get_limit; - -} // end class Limit_Customer_User_Role; + } +} diff --git a/inc/limitations/class-limit-disk-space.php b/inc/limitations/class-limit-disk-space.php index ade4aba..5f4cbbd 100644 --- a/inc/limitations/class-limit-disk-space.php +++ b/inc/limitations/class-limit-disk-space.php @@ -43,7 +43,5 @@ class Limit_Disk_Space extends Limit { public function check($value_to_check, $limit, $type = '') { return true; - - } // end check; - -} // end class Limit_Disk_Space; + } +} diff --git a/inc/limitations/class-limit-domain-mapping.php b/inc/limitations/class-limit-domain-mapping.php index 17e0d67..667f6db 100644 --- a/inc/limitations/class-limit-domain-mapping.php +++ b/inc/limitations/class-limit-domain-mapping.php @@ -36,11 +36,11 @@ class Limit_Domain_Mapping extends Limit { protected $mode = 'default'; /** - * Allows sub-type limits to set their own default value for enabled. - * - * @since 2.0.0 - * @var bool - */ + * Allows sub-type limits to set their own default value for enabled. + * + * @since 2.0.0 + * @var bool + */ private bool $enabled_default_value = true; /** @@ -56,8 +56,7 @@ class Limit_Domain_Mapping extends Limit { parent::setup($data); $this->mode = wu_get_isset($data, 'mode', 'default'); - - } // end setup; + } /** * Returns the mode. Can be one of three: default, assign_template and choose_available_templates. @@ -68,8 +67,7 @@ class Limit_Domain_Mapping extends Limit { public function get_mode() { return $this->mode; - - } // end get_mode; + } /** * The check method is what gets called when allowed is called. @@ -89,8 +87,7 @@ class Limit_Domain_Mapping extends Limit { $check = true; return $check; - - } // end check; + } /** * Returns default permissions. @@ -105,8 +102,7 @@ class Limit_Domain_Mapping extends Limit { return array( 'behavior' => 'available', ); - - } // end get_default_permissions; + } /** * Returns a default state. @@ -121,7 +117,5 @@ class Limit_Domain_Mapping extends Limit { 'limit' => null, 'mode' => 'default', ); - - } // end default_state; - -} // end class Limit_Domain_Mapping; + } +} diff --git a/inc/limitations/class-limit-plugins.php b/inc/limitations/class-limit-plugins.php index 113d0cd..53c1f4b 100644 --- a/inc/limitations/class-limit-plugins.php +++ b/inc/limitations/class-limit-plugins.php @@ -55,8 +55,7 @@ class Limit_Plugins extends Limit { ); return wu_get_isset($types, $type, false); - - } // end check; + } /** * Adds a magic getter for plugins. @@ -71,8 +70,7 @@ class Limit_Plugins extends Limit { $plugin = (object) wu_get_isset($this->get_limit(), $plugin_name, $this->get_default_permissions($plugin_name)); return (object) wp_parse_args($plugin, $this->get_default_permissions($plugin_name)); - - } // end __get; + } /** * Returns a list of plugins by behavior and visibility. @@ -88,24 +86,22 @@ class Limit_Plugins extends Limit { $search_params = array(); if ($behavior) { - $search_params[] = array('behavior', $behavior); - - } // end if; + } if ($visibility) { - $search_params[] = array('visibility', $visibility); + } - } // end if; - - $results = \Arrch\Arrch::find((array) $this->get_limit(), array( - 'where' => $search_params, - )); + $results = \Arrch\Arrch::find( + (array) $this->get_limit(), + array( + 'where' => $search_params, + ) + ); return $results; - - } // end get_by_type; + } /** * Returns default permissions. @@ -121,8 +117,7 @@ class Limit_Plugins extends Limit { 'visibility' => 'visible', 'behavior' => 'default', ); - - } // end get_default_permissions; + } /** * Checks if a theme exists on the current module. @@ -137,8 +132,7 @@ class Limit_Plugins extends Limit { $results = wu_get_isset($this->get_limit(), $plugin_name, array()); return wu_get_isset($results, 'visibility', 'not-set') !== 'not-set' || wu_get_isset($results, 'behavior', 'not-set') !== 'not-set'; - - } // end exists; + } /** * Checks if the module is enabled. @@ -151,7 +145,5 @@ class Limit_Plugins extends Limit { public function is_enabled($type = '') { return true; - - } // end is_enabled; - -} // end class Limit_Plugins; + } +} diff --git a/inc/limitations/class-limit-post-types.php b/inc/limitations/class-limit-post-types.php index 18a1b76..1539ca5 100644 --- a/inc/limitations/class-limit-post-types.php +++ b/inc/limitations/class-limit-post-types.php @@ -54,8 +54,7 @@ class Limit_Post_Types extends Limit_Subtype { * @param int User id */ return apply_filters('wu_limits_is_post_above_limit', $quota > 0 && $post_count >= $quota); - - } // end is_post_above_limit; + } /** * Get the post count for this site. @@ -85,14 +84,10 @@ class Limit_Post_Types extends Limit_Subtype { $post_statuses = apply_filters('wu_post_count_statuses', $statuses, $post_type); foreach ($post_statuses as $post_status) { - if (isset($post_count->{$post_status})) { - $count += (int) $post_count->{$post_status}; - - } // end if; - - } // end foreach; + } + } /** * Allow plugin developers to change the count total @@ -104,7 +99,5 @@ class Limit_Post_Types extends Limit_Subtype { * @return int New total */ return apply_filters('wu_post_count', $count, $post_count, $post_type); - - } // end get_post_count; - -} // end class Limit_Post_Types; + } +} diff --git a/inc/limitations/class-limit-site-templates.php b/inc/limitations/class-limit-site-templates.php index ee22b66..a23f333 100644 --- a/inc/limitations/class-limit-site-templates.php +++ b/inc/limitations/class-limit-site-templates.php @@ -36,11 +36,11 @@ class Limit_Site_Templates extends Limit { protected $mode = 'default'; /** - * Allows sub-type limits to set their own default value for enabled. - * - * @since 2.0.0 - * @var bool - */ + * Allows sub-type limits to set their own default value for enabled. + * + * @since 2.0.0 + * @var bool + */ private bool $enabled_default_value = true; /** @@ -56,8 +56,7 @@ class Limit_Site_Templates extends Limit { parent::setup($data); $this->mode = wu_get_isset($data, 'mode', 'default'); - - } // end setup; + } /** * Returns the mode. Can be one of three: default, assign_template and choose_available_templates. @@ -68,8 +67,7 @@ class Limit_Site_Templates extends Limit { public function get_mode() { return $this->mode; - - } // end get_mode; + } /** * The check method is what gets called when allowed is called. @@ -95,8 +93,7 @@ class Limit_Site_Templates extends Limit { ); return wu_get_isset($types, $type, true); - - } // end check; + } /** * Adds a magic getter for themes. @@ -113,8 +110,7 @@ class Limit_Site_Templates extends Limit { $template = (object) wu_get_isset($this->get_limit(), $template_id, $this->get_default_permissions($template_id)); return (object) wp_parse_args($template, $this->get_default_permissions($template_id)); - - } // end __get; + } /** * Returns default permissions. @@ -129,8 +125,7 @@ class Limit_Site_Templates extends Limit { return array( 'behavior' => 'available', ); - - } // end get_default_permissions; + } /** * Checks if a theme exists on the current module. @@ -147,8 +142,7 @@ class Limit_Site_Templates extends Limit { $results = wu_get_isset($this->get_limit(), $template_id, array()); return wu_get_isset($results, 'behavior', 'not-set') !== 'not-set'; - - } // end exists; + } /** * Get all themes. @@ -161,8 +155,7 @@ class Limit_Site_Templates extends Limit { $templates = (array) $this->get_limit(); return array_keys($templates); - - } // end get_all_templates; + } /** * Get available themes. @@ -174,31 +167,24 @@ class Limit_Site_Templates extends Limit { $limits = $this->get_limit(); - if (!$limits) { - + if ( ! $limits) { return false; - - } // end if; + } $limits = (array) $limits; $available = array(); foreach ($limits as $site_id => $site_settings) { - $site_settings = (object) $site_settings; if ($site_settings->behavior === 'available' || $site_settings->behavior === 'pre_selected' || $this->mode === 'default') { - $available[] = $site_id; - - } // end if; - - } // end foreach; + } + } return $available; - - } // end get_available_site_templates; + } /** * Get the forced active theme for the current limitations. @@ -212,27 +198,20 @@ class Limit_Site_Templates extends Limit { $pre_selected_site_template = false; - if (!$limits) { - + if ( ! $limits) { return $pre_selected_site_template; - - } // end if; + } foreach ($limits as $site_id => $site_settings) { - $site_settings = (object) $site_settings; if ($site_settings->behavior === 'pre_selected') { - $pre_selected_site_template = $site_id; - - } // end if; - - } // end foreach; + } + } return $pre_selected_site_template; - - } // end get_pre_selected_site_template; + } /** * Handles limits on post submission. @@ -245,8 +224,7 @@ class Limit_Site_Templates extends Limit { $module = wu_get_isset($_POST['modules'], $this->id, array()); return wu_get_isset($module, 'limit', $this->get_limit()); - - } // end handle_limit; + } /** * Handles other elements when saving. Used for custom attributes. @@ -263,8 +241,7 @@ class Limit_Site_Templates extends Limit { $module['mode'] = wu_get_isset($_module, 'mode', 'default'); return $module; - - } // end handle_others; + } /** * Returns a default state. @@ -279,7 +256,5 @@ class Limit_Site_Templates extends Limit { 'limit' => null, 'mode' => 'default', ); - - } // end default_state; - -} // end class Limit_Site_Templates; + } +} diff --git a/inc/limitations/class-limit-sites.php b/inc/limitations/class-limit-sites.php index da21963..093b8b0 100644 --- a/inc/limitations/class-limit-sites.php +++ b/inc/limitations/class-limit-sites.php @@ -43,7 +43,5 @@ class Limit_Sites extends Limit { public function check($value_to_check, $limit, $type = '') { return true; - - } // end check; - -} // end class Limit_Sites; + } +} diff --git a/inc/limitations/class-limit-subtype.php b/inc/limitations/class-limit-subtype.php index d144524..199db44 100644 --- a/inc/limitations/class-limit-subtype.php +++ b/inc/limitations/class-limit-subtype.php @@ -36,11 +36,9 @@ class Limit_Subtype extends Limit { /* * If no type is passed, bail. */ - if (!$type) { - + if ( ! $type) { return false; - - } // end if; + } /* * Set default values for inexistent post types. @@ -51,24 +49,19 @@ class Limit_Subtype extends Limit { /* * Case post type disabled. */ - if (!$post_type_limit->enabled) { - + if ( ! $post_type_limit->enabled) { return false; - - } // end if; + } /* * Case unlimited posts */ if (absint($post_type_limit->number) === 0) { - return true; - - } // end if; + } return absint($value_to_check) < absint($post_type_limit->number); - - } // end check; + } /** * Adds a magic getter for subtypes. @@ -83,8 +76,7 @@ class Limit_Subtype extends Limit { $type = (object) wu_get_isset($this->get_limit(), $sub_type, $this->get_default_permissions($sub_type)); return (object) wp_parse_args($type, $this->get_default_permissions($sub_type)); - - } // end __get; + } /** * Returns default permissions. @@ -100,8 +92,7 @@ class Limit_Subtype extends Limit { 'enabled' => true, 'number' => '', // unlimited ); - - } // end get_default_permissions; + } /** * Checks if a theme exists on the current module. @@ -116,8 +107,7 @@ class Limit_Subtype extends Limit { $results = wu_get_isset($this->get_limit(), $type, array()); return wu_get_isset($results, 'number', 'not-set') !== 'not-set'; - - } // end exists; + } /** * Handles limits on post submission. @@ -127,16 +117,12 @@ class Limit_Subtype extends Limit { */ public function handle_limit() { - $received = wu_get_isset($_POST['modules'][$this->id], 'limit', array()); + $received = wu_get_isset($_POST['modules'][ $this->id ], 'limit', array()); foreach ($received as $post_type => &$limitations) { - - $limitations['enabled'] = (bool) wu_get_isset($_POST['modules'][$this->id]['limit'][$post_type], 'enabled', false); - - } // end foreach; + $limitations['enabled'] = (bool) wu_get_isset($_POST['modules'][ $this->id ]['limit'][ $post_type ], 'enabled', false); + } return $received; - - } // end handle_limit; - -} // end class Limit_Subtype; + } +} diff --git a/inc/limitations/class-limit-themes.php b/inc/limitations/class-limit-themes.php index 12640f4..ac36db4 100644 --- a/inc/limitations/class-limit-themes.php +++ b/inc/limitations/class-limit-themes.php @@ -60,8 +60,7 @@ class Limit_Themes extends Limit { ); return wu_get_isset($types, $type, false); - - } // end check; + } /** * Adds a magic getter for themes. @@ -76,8 +75,7 @@ class Limit_Themes extends Limit { $theme = (object) wu_get_isset($this->get_limit(), $theme_name, $this->get_default_permissions($theme_name)); return (object) wp_parse_args($theme, $this->get_default_permissions($theme_name)); - - } // end __get; + } /** * Returns default permissions. @@ -93,8 +91,7 @@ class Limit_Themes extends Limit { 'visibility' => 'visible', 'behavior' => 'available', ); - - } // end get_default_permissions; + } /** * Checks if a theme exists on the current module. @@ -109,8 +106,7 @@ class Limit_Themes extends Limit { $results = wu_get_isset($this->get_limit(), $theme_name, array()); return wu_get_isset($results, 'visibility', 'not-set') !== 'not-set' || wu_get_isset($results, 'behavior', 'not-set') !== 'not-set'; - - } // end exists; + } /** * Get all themes. @@ -123,8 +119,7 @@ class Limit_Themes extends Limit { $themes = (array) $this->get_limit(); return array_keys($themes); - - } // end get_all_themes; + } /** * Get available themes. @@ -139,20 +134,15 @@ class Limit_Themes extends Limit { $available = array(); foreach ($limits as $theme_slug => $theme_settings) { - $theme_settings = (object) $theme_settings; if ($theme_settings->behavior === 'available') { - $available[] = $theme_slug; - - } // end if; - - } // end foreach; + } + } return $available; - - } // end get_available_themes; + } /** * Get the forced active theme for the current limitations. @@ -167,34 +157,25 @@ class Limit_Themes extends Limit { $limits = $this->get_limit(); if (empty($limits)) { - return $active_theme; - - } // end if; + } if ($this->forced_active_theme !== null) { - return $this->forced_active_theme; - - } // end if; + } foreach ($limits as $theme_slug => $theme_settings) { - $theme_settings = (object) $theme_settings; if ($theme_settings->behavior === 'force_active') { - $active_theme = $theme_slug; - - } // end if; - - } // end foreach; + } + } $this->forced_active_theme = $active_theme; return $this->forced_active_theme; - - } // end get_forced_active_theme; + } /** * Checks if the module is enabled. @@ -207,7 +188,5 @@ class Limit_Themes extends Limit { public function is_enabled($type = '') { return true; - - } // end is_enabled; - -} // end class Limit_Themes; + } +} diff --git a/inc/limitations/class-limit-users.php b/inc/limitations/class-limit-users.php index cfa18ff..8d698e6 100644 --- a/inc/limitations/class-limit-users.php +++ b/inc/limitations/class-limit-users.php @@ -26,5 +26,4 @@ class Limit_Users extends Limit_Subtype { * @var string */ protected $id = 'users'; - -} // end class Limit_Users; +} diff --git a/inc/limitations/class-limit-visits.php b/inc/limitations/class-limit-visits.php index 539babc..60dadb3 100644 --- a/inc/limitations/class-limit-visits.php +++ b/inc/limitations/class-limit-visits.php @@ -43,7 +43,5 @@ class Limit_Visits extends Limit { public function check($value_to_check, $limit, $type = '') { return true; - - } // end check; - -} // end class Limit_Visits; + } +} diff --git a/inc/limitations/class-limit.php b/inc/limitations/class-limit.php index a707267..42e5c06 100644 --- a/inc/limitations/class-limit.php +++ b/inc/limitations/class-limit.php @@ -51,33 +51,33 @@ abstract class Limit implements \JsonSerializable { protected $enabled; /** - * Controls if this limit has its own limit. - * - * When the limit is inherited from other models, - * such as memberships or products. - * - * @since 2.0.0 - * @var bool - */ + * Controls if this limit has its own limit. + * + * When the limit is inherited from other models, + * such as memberships or products. + * + * @since 2.0.0 + * @var bool + */ private bool $has_own_limit = true; /** - * Controls if this limit has its own enabled status. - * - * When the enabled is inherited from other models, - * such as memberships or products. - * - * @since 2.0.0 - * @var bool - */ + * Controls if this limit has its own enabled status. + * + * When the enabled is inherited from other models, + * such as memberships or products. + * + * @since 2.0.0 + * @var bool + */ private bool $has_own_enabled = true; /** - * Allows sub-type limits to set their own default value for enabled. - * - * @since 2.0.0 - * @var bool - */ + * Allows sub-type limits to set their own default value for enabled. + * + * @since 2.0.0 + * @var bool + */ private bool $enabled_default_value = true; /** @@ -89,8 +89,7 @@ abstract class Limit implements \JsonSerializable { public function __construct($data) { $this->setup($data); - - } // end __construct; + } /** * Prepare for serialization. @@ -101,8 +100,7 @@ abstract class Limit implements \JsonSerializable { public function __serialize() { // phpcs:ignore return serialize($this->to_array()); - - } // end __serialize; + } /** * Handles un-serialization. @@ -115,8 +113,7 @@ abstract class Limit implements \JsonSerializable { public function __unserialize($data) { // phpcs:ignore $this->setup(unserialize($data)); - - } // end __unserialize; + } /** * Sets up the module based on the module data. @@ -128,11 +125,9 @@ abstract class Limit implements \JsonSerializable { */ public function setup($data) { - if (!is_array($data)) { - + if ( ! is_array($data)) { $data = (array) $data; - - } // end if; + } $current_limit = wu_get_isset($data, 'limit', 'not-set'); @@ -140,31 +135,29 @@ abstract class Limit implements \JsonSerializable { * Sets the own limit flag, if necessary. */ if ($current_limit === 'not-set' || $current_limit === '') { - $this->has_own_limit = false; - - } // end if; + } /* * Sets the own enabled flag, if necessary. */ if (wu_get_isset($data, 'enabled', 'not-set') === 'not-set') { - $this->has_own_enabled = false; + } - } // end if; - - $data = wp_parse_args($data, array( - 'limit' => null, - 'enabled' => $this->enabled_default_value, - )); + $data = wp_parse_args( + $data, + array( + 'limit' => null, + 'enabled' => $this->enabled_default_value, + ) + ); $this->limit = is_array($data['limit']) ? (object) $data['limit'] : $data['limit']; $this->enabled = (bool) $data['enabled']; do_action("wu_{$this->id}_limit_setup", $data, $this); - - } // end setup; + } /** * Returns the id of the module. @@ -175,8 +168,7 @@ abstract class Limit implements \JsonSerializable { public function get_id() { return $this->id; - - } // end get_id; + } /** * Checks if a value is allowed under this limit. @@ -193,19 +185,16 @@ abstract class Limit implements \JsonSerializable { * @param string $type The type parameter. * @return bool */ - public final function allowed($value_to_check, $type = '') { + final public function allowed($value_to_check, $type = '') { $allowed = $this->is_enabled(); if ($allowed) { - $allowed = $this->check($value_to_check, $this->limit, $type); - - } // end if; + } return apply_filters("wu_limit_{$this->id}_{$type}_allowed", $allowed, $type, $this); - - } // end allowed; + } /** * The check method is what gets called when allowed is called. @@ -233,8 +222,7 @@ abstract class Limit implements \JsonSerializable { public function get_limit($type = '') { return $this->limit; - - } // end get_limit; + } /** * Checks if the module is enabled. @@ -247,8 +235,7 @@ abstract class Limit implements \JsonSerializable { public function is_enabled($type = '') { return $this->enabled; - - } // end is_enabled; + } /** * Converts the limitations list to an array. @@ -268,8 +255,7 @@ abstract class Limit implements \JsonSerializable { unset($array['enabled_default_value']); return $array; - - } // end to_array; + } /** * Prepares for serialization. @@ -281,8 +267,7 @@ abstract class Limit implements \JsonSerializable { public function jsonSerialize() { return json_encode($this->to_array()); - - } // end jsonSerialize; + } /** * Checks if this module has its own limit. @@ -293,8 +278,7 @@ abstract class Limit implements \JsonSerializable { public function has_own_limit() { return $this->has_own_limit; - - } // end has_own_limit; + } /** * Checks if this module has its own enabled. @@ -305,8 +289,7 @@ abstract class Limit implements \JsonSerializable { public function has_own_enabled() { return $this->has_own_enabled; - - } // end has_own_enabled; + } /** * Handles enabled status on post submission. @@ -319,8 +302,7 @@ abstract class Limit implements \JsonSerializable { $module = wu_get_isset($_POST['modules'], $this->id, array()); return (bool) wu_get_isset($module, 'enabled', false); - - } // end handle_enabled; + } /** * Handles other elements when saving. Used for custom attributes. @@ -333,8 +315,7 @@ abstract class Limit implements \JsonSerializable { public function handle_others($module) { return $module; - - } // end handle_others; + } /** * Handles limits on post submission. @@ -347,8 +328,7 @@ abstract class Limit implements \JsonSerializable { $module = wu_get_isset($_POST['modules'], $this->id, array()); return wu_get_isset($module, 'limit', null); - - } // end handle_limit; + } /** * Returns a default state. @@ -362,7 +342,5 @@ abstract class Limit implements \JsonSerializable { 'enabled' => false, 'limit' => null, ); - - } // end default_state; - -} // end class Limit; + } +} diff --git a/inc/limits/class-customer-user-role-limits.php b/inc/limits/class-customer-user-role-limits.php index 89ca273..17f4c63 100644 --- a/inc/limits/class-customer-user-role-limits.php +++ b/inc/limits/class-customer-user-role-limits.php @@ -36,13 +36,10 @@ class Customer_User_Role_Limits { add_filter('editable_roles', array($this, 'filter_editable_roles')); - if (!wu_get_current_site()->has_module_limitation('customer_user_role')) { - + if ( ! wu_get_current_site()->has_module_limitation('customer_user_role')) { return; - - } // end if; - - } // end init; + } + } /** * Block new user page if limit has reached. @@ -52,24 +49,18 @@ class Customer_User_Role_Limits { public function block_new_user_page() { if (is_super_admin()) { - return; - - } // end if; + } $screen = get_current_screen(); - if (!$screen || $screen->id !== 'user') { - + if ( ! $screen || $screen->id !== 'user') { return; + } - } // end if; - - if (!empty(get_editable_roles())) { - + if ( ! empty(get_editable_roles())) { return; - - } // end if; + } $message = __('You reached your membership users limit.', 'wp-ultimo'); @@ -81,8 +72,7 @@ class Customer_User_Role_Limits { $message = apply_filters('wu_users_membership_limit_message', $message); wp_die($message, __('Limit Reached', 'wp-ultimo'), array('back_link' => true)); - - } // end block_new_user_page; + } /** * Filters editable roles offered as options on limitations. @@ -94,20 +84,16 @@ class Customer_User_Role_Limits { */ public function filter_editable_roles($roles) { - if (!wu_get_current_site()->has_module_limitation('users') || is_super_admin()) { - + if ( ! wu_get_current_site()->has_module_limitation('users') || is_super_admin()) { return $roles; - - } // end if; + } $users_limitation = wu_get_current_site()->get_limitations()->users; foreach ($roles as $role => $details) { - $limit = $users_limitation->{$role}; if (property_exists($limit, 'enabled') && $limit->enabled) { - $user_list = get_users(array('role' => $role)); $count = (int) count($user_list); @@ -115,22 +101,15 @@ class Customer_User_Role_Limits { $limit = (int) wu_get_current_site()->get_limitations()->users->{$role}->number; if (0 !== $limit && $count >= $limit) { - - unset($roles[$role]); - - } // end if; - + unset($roles[ $role ]); + } } else { - - unset($roles[$role]); - - } // end if; - - } // end foreach; + unset($roles[ $role ]); + } + } return $roles; - - } // end filter_editable_roles; + } /** * Updates the site user roles after a up/downgrade. @@ -145,27 +124,19 @@ class Customer_User_Role_Limits { $membership = wu_get_membership($membership_id); if ($membership) { - $customer = $membership->get_customer(); - if (!$customer) { - + if ( ! $customer) { return; - - } // end if; + } $sites = $membership->get_sites(false); $role = $membership->get_limitations()->customer_user_role->get_limit(); foreach ($sites as $site) { - add_user_to_blog($site->get_id(), $customer->get_user_id(), $role); - - } // end foreach; - - } // end if; - - } // end update_site_user_roles; - -} // end class Customer_User_Role_Limits; + } + } + } +} diff --git a/inc/limits/class-disk-space-limits.php b/inc/limits/class-disk-space-limits.php index ea728b6..b7e78e2 100644 --- a/inc/limits/class-disk-space-limits.php +++ b/inc/limits/class-disk-space-limits.php @@ -50,8 +50,7 @@ class Disk_Space_Limits { add_filter('site_option_upload_space_check_disabled', array($this, 'upload_space_check_disabled')); add_filter('get_space_allowed', array($this, 'apply_disk_space_limitations')); - - } // end init; + } /** * Disables the upload space check if the site has limitations. @@ -64,15 +63,12 @@ class Disk_Space_Limits { */ public function upload_space_check_disabled($value) { - if (!$this->should_load()) { - + if ( ! $this->should_load()) { return $value; - - } // end if; + } return 0; - - } // end upload_space_check_disabled; + } /** * Checks if the disk space limitations should be loaded. @@ -83,10 +79,8 @@ class Disk_Space_Limits { protected function should_load() { if ($this->started) { - return $this->should_load; - - } // end if; + } $this->started = true; $this->should_load = true; @@ -101,21 +95,16 @@ class Disk_Space_Limits { * @since 1.7.0 * @return bool */ - if (!apply_filters('wu_apply_plan_limits', wu_get_current_site()->has_limitations())) { - + if ( ! apply_filters('wu_apply_plan_limits', wu_get_current_site()->has_limitations())) { $this->should_load = false; + } - } // end if; - - if (!wu_get_current_site()->has_module_limitation('disk_space')) { - + if ( ! wu_get_current_site()->has_module_limitation('disk_space')) { $this->should_load = false; - - } // end if; + } return $this->should_load; - - } // end should_load; + } /** * Changes the disk_space to the one on the product. @@ -127,22 +116,16 @@ class Disk_Space_Limits { */ public function apply_disk_space_limitations($disk_space) { - if (!$this->should_load()) { - + if ( ! $this->should_load()) { return $disk_space; - - } // end if; + } $modified_disk_space = wu_get_current_site()->get_limitations()->disk_space->get_limit(); if (is_numeric($modified_disk_space)) { - return $modified_disk_space; - - } // end if; + } return $disk_space; - - } // end apply_disk_space_limitations; - -} // end class Disk_Space_Limits; + } +} diff --git a/inc/limits/class-plugin-limits.php b/inc/limits/class-plugin-limits.php index e7d00d5..9c6b59b 100644 --- a/inc/limits/class-plugin-limits.php +++ b/inc/limits/class-plugin-limits.php @@ -46,8 +46,7 @@ class Plugin_Limits { public function init() { add_action('wu_sunrise_loaded', array($this, 'load_limitations')); - - } // end init; + } /** * Apply limitations if they are available. @@ -58,7 +57,6 @@ class Plugin_Limits { public function load_limitations() { if (wu_get_current_site()->has_limitations()) { - add_filter('site_option_active_sitewide_plugins', array($this, 'deactivate_network_plugins')); add_filter('option_active_plugins', array($this, 'deactivate_plugins')); @@ -72,14 +70,12 @@ class Plugin_Limits { add_filter('show_network_active_plugins', '__return_true'); add_action('load-plugins.php', array($this, 'admin_page_hooks')); - - } // end if; + } add_action('wu_site_post_save', array($this, 'activate_and_inactive_plugins'), 10, 3); add_action('wu_checkout_done', array($this, 'maybe_activate_and_inactive_plugins'), 10, 5); - - } // end load_limitations; + } /** * Registers scripts onto the plugins page. @@ -88,10 +84,8 @@ class Plugin_Limits { * @return void */ public function admin_page_hooks() { - add_action('admin_enqueue_scripts', 'add_wubox'); - - } // end admin_page_hooks; + } /** * Automatically activate and deactivate plugins when the site is created or a upgrade happens. @@ -100,18 +94,14 @@ class Plugin_Limits { * * @param array $data Saved data. * @param \WP_Ultimo\Models\Site $site_object The site created. - * @param bool $new If this site is a new one. + * @param bool $new_site If this site is a new one. * @return void */ - public function activate_and_inactive_plugins($data, $site_object, $new) { - - if ($site_object && $new) { - + public function activate_and_inactive_plugins($data, $site_object, $new_site) { + if ($site_object && $new_site) { $site_object->sync_plugins(); - - } // end if; - - } // end activate_and_inactive_plugins; + } + } /** * Activate and Deactivate plugins on upgrades and downgrades. @@ -126,14 +116,10 @@ class Plugin_Limits { * @return void */ public function maybe_activate_and_inactive_plugins($payment, $membership, $customer, $cart, $type) { - - if ($type !== 'new' && $membership) { - + if ('new' !== $type && $membership) { $membership->sync_plugins(); - - } // end if; - - } // end maybe_activate_and_inactive_plugins; + } + } /** * Clear the actions of the plugins list table. @@ -146,36 +132,34 @@ class Plugin_Limits { */ public function clear_actions($actions, $plugin_file) { - if (!function_exists('wu_generate_upgrade_to_unlock_url')) { - + if ( ! function_exists('wu_generate_upgrade_to_unlock_url')) { return $actions; - - } // end if; + } $plugin_limits = wu_get_current_site()->get_limitations()->plugins; if (isset($actions['network_active'])) { - - $actions['network_active'] = sprintf(' + $actions['network_active'] = sprintf( + ' %s - ', __('Always Loaded', 'wp-ultimo')); - - } // end if; + ', + __('Always Loaded', 'wp-ultimo') + ); + } if ($plugin_limits->allowed($plugin_file, 'force_active_locked')) { - unset($actions['deactivate']); - } elseif ($plugin_limits->allowed($plugin_file, 'force_inactive_locked')) { - $upgrade = sprintf( '%s', - wu_generate_upgrade_to_unlock_url(array( - 'module' => 'plugins', - 'type' => $plugin_file, - )), + wu_generate_upgrade_to_unlock_url( + array( + 'module' => 'plugins', + 'type' => $plugin_file, + ) + ), __('Upgrade to unlock', 'wp-ultimo'), __('Upgrade to unlock', 'wp-ultimo') ); @@ -183,12 +167,10 @@ class Plugin_Limits { $actions['upgrade'] = $upgrade; unset($actions['activate']); - - } // end if; + } return $actions; - - } // end clear_actions; + } /** * Clears the plugin list. @@ -204,38 +186,27 @@ class Plugin_Limits { public function clear_plugin_list($plugins) { if (is_main_site()) { - return $plugins; - - } // end if; + } $plugin_limits = wu_get_current_site()->get_limitations()->plugins; foreach ($plugins as $plugin_slug => $plugin_data) { - if ($plugin_data['Network']) { - - unset($plugins[$plugin_slug]); - - } // end if; + unset($plugins[ $plugin_slug ]); + } if (strncmp($plugin_slug, 'wp-ultimo', strlen('wp-ultimo')) === 0) { - - unset($plugins[$plugin_slug]); - - } // end if; + unset($plugins[ $plugin_slug ]); + } if ($plugin_limits->allowed($plugin_slug, 'hidden')) { - - unset($plugins[$plugin_slug]); - - } // end if; - - } // end foreach; + unset($plugins[ $plugin_slug ]); + } + } return $plugins; - - } // end clear_plugin_list; + } /** * Deactivates the network plugins that people are not allowed to use. @@ -252,62 +223,45 @@ class Plugin_Limits { * Bail on network admin =) */ if (is_network_admin() || is_main_site()) { - return $plugins; - - } // end if; + } /* * Get the network plugins cache, if they're set. */ if (is_array($this->network_plugins)) { - return $this->network_plugins; - - } // end if; + } $plugin_limits = wu_get_current_site()->get_limitations()->plugins; foreach ($plugins as $plugin_slug => $timestamp) { - if (strpos($plugin_slug, 'wp-ultimo') !== false) { - continue; - - } // end if; + } if ($plugin_limits->allowed($plugin_slug, 'force_inactive_locked')) { - - unset($plugins[$plugin_slug]); - - } // end if; - - } // end foreach; + unset($plugins[ $plugin_slug ]); + } + } // Ensure get_plugins function is loaded. - if (!function_exists('get_plugins')) { - + if ( ! function_exists('get_plugins')) { include ABSPATH . '/wp-admin/includes/plugin.php'; - - } // end if; + } $other_plugins = get_plugins(); foreach ($other_plugins as $plugin_path => $other_plugin) { - - if (!wu_get_isset($plugins, $plugin_path) && $plugin_limits->allowed($plugin_path, 'force_active_locked')) { - - $plugins[$plugin_path] = true; - - } // end if; - - } // end foreach; + if ( ! wu_get_isset($plugins, $plugin_path) && $plugin_limits->allowed($plugin_path, 'force_active_locked')) { + $plugins[ $plugin_path ] = true; + } + } $this->network_plugins = $plugins; return $plugins; - - } // end deactivate_network_plugins; + } /** * Deactivates the plugins that people are not allowed to use. @@ -322,64 +276,46 @@ class Plugin_Limits { * Bail on network admin =) */ if (is_network_admin() || is_main_site()) { - return $plugins; - - } // end if; + } /* * Get the site-level plugins cache, if they're set. */ if (is_array($this->plugins)) { - return $this->plugins; - - } // end if; + } $plugin_limits = wu_get_current_site()->get_limitations()->plugins; foreach ($plugins as $plugin_slug) { - if (strpos((string) $plugin_slug, 'wp-ultimo') !== false) { - continue; - - } // end if; + } if ($plugin_limits->allowed($plugin_slug, 'force_inactive_locked')) { - $index = array_search($plugin_slug, $plugins, true); - - unset($plugins[$index]); - - } // end if; - - } // end foreach; + unset($plugins[ $index ]); + } + } // Ensure get_plugins function is loaded. - if (!function_exists('get_plugins')) { - + if ( ! function_exists('get_plugins')) { include ABSPATH . '/wp-admin/includes/plugin.php'; - - } // end if; + } $other_plugins = get_plugins(); foreach ($other_plugins as $plugin_path => $other_plugin) { - if (in_array($plugin_path, $plugins, true) && $plugin_limits->allowed($plugin_path, 'force_active_locked')) { - $plugins[] = $plugin_path; - - } // end if; - - } // end foreach; + } + } $this->plugins = $plugins; return $plugins; - - } // end deactivate_plugins; + } /** * Remove the unused shortcodes after we disable plugins. @@ -390,11 +326,6 @@ class Plugin_Limits { * @return string */ public function clean_unused_shortcodes($content) { - - $content = preg_replace('/\[.+\].+\[\/.+\]/', '', $content); - - return $content; - - } // end clean_unused_shortcodes; - -} // end class Plugin_Limits; + return preg_replace('/\[.+\].+\[\/.+\]/', '', $content); + } +} diff --git a/inc/limits/class-post-type-limits.php b/inc/limits/class-post-type-limits.php index 599afd1..e5cb904 100644 --- a/inc/limits/class-post-type-limits.php +++ b/inc/limits/class-post-type-limits.php @@ -36,10 +36,8 @@ class Post_Type_Limits { * @since 2.0.6 */ if (is_main_site() && is_network_admin()) { - add_action('init', array($this, 'register_emulated_post_types'), 999); - - } // end if; + } /** * Allow plugin developers to short-circuit the limitations. @@ -51,17 +49,13 @@ class Post_Type_Limits { * @since 1.7.0 * @return bool */ - if (!apply_filters('wu_apply_plan_limits', wu_get_current_site()->has_limitations())) { - + if ( ! apply_filters('wu_apply_plan_limits', wu_get_current_site()->has_limitations())) { return; + } - } // end if; - - if (!wu_get_current_site()->has_module_limitation('post_types')) { - + if ( ! wu_get_current_site()->has_module_limitation('post_types')) { return; - - } // end if; + } add_action('load-post-new.php', array($this, 'limit_posts')); @@ -72,8 +66,7 @@ class Post_Type_Limits { add_action('current_screen', array($this, 'limit_restoring'), 10); add_filter('wp_insert_post_data', array($this, 'limit_draft_publishing'), 10, 2); - - } // end init; + } /** * Emulates post types to avoid having to have plugins active on the main site. @@ -85,35 +78,31 @@ class Post_Type_Limits { $emulated_post_types = wu_get_setting('emulated_post_types', array()); - if (is_array($emulated_post_types) && !empty($emulated_post_types)) { - + if (is_array($emulated_post_types) && ! empty($emulated_post_types)) { foreach ($emulated_post_types as $pt) { - $pt = (object) $pt; $existing_pt = get_post_type_object($pt->post_type); if ($existing_pt) { - continue; + } - } // end if; - - register_post_type($pt->post_type, array( - 'label' => $pt->label, - 'exclude_from_search' => true, - 'public' => true, - 'show_in_menu' => false, - 'has_archive' => false, - 'can_export' => false, - 'delete_with_user' => false, - )); - - } // end foreach; - - } // end if; - - } // end register_emulated_post_types; + register_post_type( + $pt->post_type, + array( + 'label' => $pt->label, + 'exclude_from_search' => true, + 'public' => true, + 'show_in_menu' => false, + 'has_archive' => false, + 'can_export' => false, + 'delete_with_user' => false, + ) + ); + } + } + } /** * Prevents users from trashing posts and restoring them later to bypass the limitation. @@ -124,12 +113,9 @@ class Post_Type_Limits { public function limit_restoring() { if (isset($_REQUEST['action']) && $_REQUEST['action'] === 'untrash') { - $this->limit_posts(); - - } // end if; - - } // end limit_restoring; + } + } /** * Limit the posts after the user reach his plan limits @@ -140,33 +126,26 @@ class Post_Type_Limits { public function limit_posts() { if (is_main_site()) { - return; - - } // end if; + } $screen = get_current_screen(); - if (!wu_get_current_site()->get_limitations()->post_types->{$screen->post_type}->enabled) { - + if ( ! wu_get_current_site()->get_limitations()->post_types->{$screen->post_type}->enabled) { $upgrade_message = __('Your plan does not support this post type.', 'wp-ultimo'); // translators: %s is the URL. wp_die($upgrade_message, __('Limit Reached', 'wp-ultimo'), array('back_link' => true)); - - } // end if; + } // Check if that is more than our limit if (wu_get_current_site()->get_limitations()->post_types->is_post_above_limit($screen->post_type)) { - $upgrade_message = __('You reached your plan\'s post limit.', 'wp-ultimo'); // translators: %s is the URL wp_die($upgrade_message, __('Limit Reached', 'wp-ultimo'), array('back_link' => true)); - - } // end if; - - } // end limit_posts; + } + } /** * Checks if the user is trying to publish a draft post. @@ -183,36 +162,28 @@ class Post_Type_Limits { global $current_screen; if (empty($current_screen)) { - return $data; - - } // end if; + } if (get_post_status($modified_data['ID']) === 'publish') { - return $data; // If the post is already published, no need to make changes - } // end if; + } if (isset($data['post_status']) && $data['post_status'] !== 'publish') { - return $data; - - } // end if; + } $post_type = isset($data['post_type']) ? $data['post_type'] : 'post'; $post_type_limits = wu_get_current_site()->get_limitations()->post_types; - if (!$post_type_limits->{$current_screen->post_type}->enabled || $post_type_limits->is_post_above_limit($post_type)) { - + if ( ! $post_type_limits->{$current_screen->post_type}->enabled || $post_type_limits->is_post_above_limit($post_type)) { $data['post_status'] = 'draft'; - - } // end if; + } return $data; - - } // end limit_draft_publishing; + } /** * Limits uploads of items to the media library. @@ -224,13 +195,11 @@ class Post_Type_Limits { */ public function limit_media($file) { - if (!wu_get_current_site()->get_limitations()->post_types->attachment->enabled) { - + if ( ! wu_get_current_site()->get_limitations()->post_types->attachment->enabled) { $file['error'] = __('Your plan does not support media upload.', 'wp-ultimo'); return $file; - - } // end if; + } $post_count = wp_count_posts('attachment'); @@ -240,33 +209,25 @@ class Post_Type_Limits { // This bit is for the flash uploader if ($file['type'] === 'application/octet-stream' && isset($file['tmp_name'])) { - $file_size = getimagesize($file['tmp_name']); if (isset($file_size['error']) && $file_size['error'] !== 0) { - $file['error'] = "Unexpected Error: {$file_size['error']}"; return $file; - } else { - $file['type'] = $file_size['mime']; - - } // end if; - - } // end if; + } + } if ($quota > 0 && $post_count >= $quota) { // translators: %d is the number of images allowed. $file['error'] = sprintf(__('You reached your media upload limit of %d images. Upgrade your account to unlock more media uploads.', 'wp-ultimo'), $quota, '#'); - - } // end if; + } return $file; - - } // end limit_media; + } /** * Remove the upload tabs if the quota is over. @@ -285,15 +246,11 @@ class Post_Type_Limits { $quota = wu_get_current_site()->get_limitations()->post_types->attachment->number; if ($quota > 0 && $post_count > $quota) { - unset($tabs['type']); unset($tabs['type_url']); - - } // end if; + } return $tabs; - - } // end limit_tabs; - -} // end class Post_Type_Limits; + } +} diff --git a/inc/limits/class-site-template-limits.php b/inc/limits/class-site-template-limits.php index e221b61..01208d6 100644 --- a/inc/limits/class-site-template-limits.php +++ b/inc/limits/class-site-template-limits.php @@ -33,8 +33,7 @@ class Site_Template_Limits { public function init() { add_action('plugins_loaded', array($this, 'setup')); - - } // end init; + } /** * Sets up the hooks and checks. @@ -49,8 +48,7 @@ class Site_Template_Limits { add_filter('wu_checkout_template_id', array($this, 'maybe_force_template_selection'), 10, 2); add_filter('wu_cart_get_extra_params', array($this, 'maybe_force_template_selection_on_cart'), 10, 2); - - } // end setup; + } /** * Maybe filter the template selection options on the template selection field. @@ -68,8 +66,7 @@ class Site_Template_Limits { $products = array_filter($products); - if (!empty($products)) { - + if ( ! empty($products)) { $limits = new \WP_Ultimo\Objects\Limitations(); list($plan, $additional_products) = wu_segregate_products($products); @@ -77,35 +74,25 @@ class Site_Template_Limits { $products = array_merge(array($plan), $additional_products); foreach ($products as $product) { - $limits = $limits->merge($product->get_limitations()); - - } // end foreach; + } if ($limits->site_templates->get_mode() === 'default') { - $attributes['sites'] = wu_get_isset($attributes, 'sites', explode(',', ($attributes['template_selection_sites'] ?? ''))); return $attributes; - } elseif ($limits->site_templates->get_mode() === 'assign_template') { - $attributes['should_display'] = false; - } else { - $site_list = wu_get_isset($attributes, 'sites', explode(',', ($attributes['template_selection_sites'] ?? ''))); $available_templates = $limits->site_templates->get_available_site_templates(); $attributes['sites'] = array_intersect($site_list, $available_templates); - - } // end if; - - } // end if; + } + } return $attributes; - - } // end maybe_filter_template_selection_options; + } /** * Decides if we need to force the selection of a given template during the site creation. @@ -119,14 +106,11 @@ class Site_Template_Limits { public function maybe_force_template_selection($template_id, $membership) { if ($membership && $membership->get_limitations()->site_templates->get_mode() === 'assign_template') { - $template_id = $membership->get_limitations()->site_templates->get_pre_selected_site_template(); - - } // end if; + } return $template_id; - - } // end maybe_force_template_selection; + } /** * Pre-selects a given template on the checkout screen depending on permissions. @@ -150,26 +134,19 @@ class Site_Template_Limits { $products = array_filter($products); foreach ($products as $product) { - $limits = $limits->merge($product->get_limitations()); - - } // end foreach; + } if ($limits->site_templates->get_mode() === 'assign_template') { - $extra['template_id'] = $limits->site_templates->get_pre_selected_site_template(); - } elseif ($limits->site_templates->get_mode() === 'choose_available_templates') { - $template_id = Checkout::get_instance()->request_or_session('template_id'); $extra['template_id'] = $this->is_template_available($products, $template_id) ? $template_id : false; - - } // end if; + } return $extra; - - } // end maybe_force_template_selection_on_cart; + } /** * Check if site template is available in current limits @@ -182,8 +159,7 @@ class Site_Template_Limits { $template_id = (int) $template_id; - if (!empty($products)) { - + if ( ! empty($products)) { $limits = new \WP_Ultimo\Objects\Limitations(); list($plan, $additional_products) = wu_segregate_products($products); @@ -191,27 +167,18 @@ class Site_Template_Limits { $products = array_merge(array($plan), $additional_products); foreach ($products as $product) { - $limits = $limits->merge($product->get_limitations()); - - } // end foreach; + } if ($limits->site_templates->get_mode() === 'assign_template') { - return $limits->site_templates->get_pre_selected_site_template() === $template_id; - } else { - $available_templates = $limits->site_templates->get_available_site_templates(); return in_array($template_id, $available_templates, true); - - } // end if; - - } // end if; + } + } return true; - - } // end is_template_available; - -} // end class Site_Template_Limits; + } +} diff --git a/inc/limits/class-theme-limits.php b/inc/limits/class-theme-limits.php index b983675..3c6f51e 100644 --- a/inc/limits/class-theme-limits.php +++ b/inc/limits/class-theme-limits.php @@ -65,14 +65,11 @@ class Theme_Limits { * @since 2.1.0 */ if (wu_cli_is_plugin_skipped('wp-ultimo')) { - return; - } add_action('wu_sunrise_loaded', array($this, 'load_limitations')); - - } // end init; + } /** * Apply limitations if they are available. @@ -83,7 +80,6 @@ class Theme_Limits { public function load_limitations() { if (wu_get_current_site()->has_limitations()) { - add_filter('stylesheet', array($this, 'force_active_theme_stylesheet')); add_filter('template', array($this, 'force_active_theme_template')); @@ -99,10 +95,8 @@ class Theme_Limits { add_action('admin_footer-themes.php', array($this, 'modify_backbone_template')); add_action('customize_changeset_save_data', array($this, 'prevent_theme_activation_on_customizer'), 99, 2); - - } // end if; - - } // end load_limitations; + } + } /** * Prevents sub-site admins from switching to locked themes inside the customizer. @@ -116,25 +110,20 @@ class Theme_Limits { public function prevent_theme_activation_on_customizer($data, $context) { if (wu_get_current_site()->has_limitations() === false) { - return $data; - - } // end if; + } $pending_theme_switch = $context['manager']->is_theme_active() === false; if ($pending_theme_switch === false) { - return $data; - - } // end if; + } $new_theme = $context['manager']->theme()->stylesheet; $theme_limitations = wu_get_current_site()->get_limitations()->themes; if ($theme_limitations->allowed($new_theme, 'not_available')) { - $response = array( 'code' => 'not-available', 'message' => __('This theme is not available on your current plan.', 'wp-ultimo'), @@ -143,12 +132,10 @@ class Theme_Limits { wp_send_json($response, 'not-available'); exit; - - } // end if; + } return $data; - - } // end prevent_theme_activation_on_customizer; + } /** * Removes the activate button from not available themes. @@ -166,38 +153,38 @@ class Theme_Limits { global $pagenow; - if (!function_exists('wu_generate_upgrade_to_unlock_url')) { - + if ( ! function_exists('wu_generate_upgrade_to_unlock_url')) { return; - - } // end if; + } if ($pagenow !== 'themes.php') { - return; - - } // end if; + } $membership = wu_get_current_site()->get_membership(); - if (!$membership) { - + if ( ! $membership) { return; + } - } // end if; + $upgrade_button = wu_generate_upgrade_to_unlock_button( + __('Upgrade to unlock', 'wp-ultimo'), + array( + 'module' => 'themes', + 'type' => 'EXTENSION', + 'classes' => 'button', + ) + ); - $upgrade_button = wu_generate_upgrade_to_unlock_button(__('Upgrade to unlock', 'wp-ultimo'), array( - 'module' => 'themes', - 'type' => 'EXTENSION', - 'classes' => 'button', - )); - - wp_localize_script('theme', 'wu_theme_settings', array( - 'themes_not_available' => $this->themes_not_available, - 'replacement_message' => $upgrade_button, - )); - - } // end hacky_remove_activate_button; + wp_localize_script( + 'theme', + 'wu_theme_settings', + array( + 'themes_not_available' => $this->themes_not_available, + 'replacement_message' => $upgrade_button, + ) + ); + } /** * Modifies the default WordPress theme page template. @@ -217,13 +204,12 @@ class Theme_Limits { document.getElementById("tmpl-theme").innerHTML = content; - } // end if; + } get_limitations()->themes; foreach ($themes as $stylesheet => &$data) { - $data['notAvailable'] = false; if ($theme_limitations->allowed($stylesheet, 'not_available')) { - $data['actions']['activate'] = ''; /* @@ -262,14 +244,11 @@ class Theme_Limits { * for our hack-y solution. */ $this->themes_not_available[] = $stylesheet; - - } // end if; - - } // end foreach; + } + } return $themes; - - } // end maybe_remove_activate_button; + } /** * Force the activation of one particularly selected theme. @@ -282,16 +261,13 @@ class Theme_Limits { public function force_active_theme_stylesheet($stylesheet) { if (is_main_site()) { - return $stylesheet; - - } // end if; + } $forced_stylesheet = $this->get_forced_theme_stylesheet(); return $forced_stylesheet ? $forced_stylesheet : $stylesheet; - - } // end force_active_theme_stylesheet; + } /** * Force the activation of one particularly selected theme. @@ -304,16 +280,13 @@ class Theme_Limits { public function force_active_theme_template($template) { if (is_main_site()) { - return $template; - - } // end if; + } $forced_template = $this->get_forced_theme_template(); return $forced_template ? $forced_template : $template; - - } // end force_active_theme_template; + } /** * Deactivates the plugins that people are not allowed to use. @@ -328,34 +301,25 @@ class Theme_Limits { * Bail on network admin =) */ if (is_network_admin()) { - return $themes; - - } // end if; + } $theme_limitations = wu_get_current_site()->get_limitations()->themes; $_themes = $theme_limitations->get_all_themes(); foreach ($_themes as $theme_stylesheet) { - $should_appear = $theme_limitations->allowed($theme_stylesheet, 'visible'); - if (!$should_appear && isset($themes[$theme_stylesheet])) { - - unset($themes[$theme_stylesheet]); - - } elseif ($should_appear && !isset($themes[$theme_stylesheet])) { - + if ( ! $should_appear && isset($themes[ $theme_stylesheet ])) { + unset($themes[ $theme_stylesheet ]); + } elseif ($should_appear && ! isset($themes[ $theme_stylesheet ])) { $themes[] = $theme_stylesheet; - - } // end if; - - } // end foreach; + } + } return $themes; - - } // end add_extra_available_themes; + } /** * Get the stylesheet of the theme that is forced to be active. @@ -367,14 +331,11 @@ class Theme_Limits { protected function get_forced_theme_stylesheet() { if ($this->forced_theme_stylesheet === null) { - $this->forced_theme_stylesheet = wu_get_current_site()->get_limitations()->themes->get_forced_active_theme(); - - } // end if; + } return $this->forced_theme_stylesheet; - - } // end get_forced_theme_stylesheet; + } /** * Get the template of the theme that is forced to be active. @@ -386,15 +347,11 @@ class Theme_Limits { protected function get_forced_theme_template() { if ($this->forced_theme_template === null) { - $stylesheet = $this->get_forced_theme_stylesheet(); $this->forced_theme_template = $stylesheet ? wp_get_theme($stylesheet)->get_template() : false; - - } // end if; + } return $this->forced_theme_template; - - } // end get_forced_theme_template; - -} // end class Theme_Limits; + } +} diff --git a/inc/limits/class-trial-limits.php b/inc/limits/class-trial-limits.php index 0823163..d19f494 100644 --- a/inc/limits/class-trial-limits.php +++ b/inc/limits/class-trial-limits.php @@ -28,8 +28,7 @@ class Trial_Limits { * @return void */ public function init() { - - } // end init; + } /** * Apply limitations if they are available. @@ -38,7 +37,5 @@ class Trial_Limits { * @return void */ public function load_limitations() { - - } // end load_limitations; - -} // end class Trial_Limits; + } +} diff --git a/inc/list-tables/class-base-list-table.php b/inc/list-tables/class-base-list-table.php index 6ab1baf..a17754a 100644 --- a/inc/list-tables/class-base-list-table.php +++ b/inc/list-tables/class-base-list-table.php @@ -9,16 +9,14 @@ namespace WP_Ultimo\List_Tables; -use \WP_Ultimo\Helpers\Hash; +use WP_Ultimo\Helpers\Hash; // Exit if accessed directly defined('ABSPATH') || exit; -if (!class_exists('WP_List_Table')) { - +if ( ! class_exists('WP_List_Table')) { require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; - -} // end if; +} /** * Base List Table class. Extends WP_List_Table. @@ -88,15 +86,14 @@ class Base_List_Table extends \WP_List_Table { public $context = 'page'; /** - * Returns the table id. - * - * @since 2.0.0 - */ + * Returns the table id. + * + * @since 2.0.0 + */ public function get_table_id(): string { return strtolower(substr(strrchr(static::class, '\\'), 1)); - - } // end get_table_id; + } /** * Changes the context of the list table. @@ -111,8 +108,7 @@ class Base_List_Table extends \WP_List_Table { public function set_context($context = 'page') { $this->context = $context; - - } // end set_context; + } /** * Initializes the table. @@ -125,9 +121,12 @@ class Base_List_Table extends \WP_List_Table { $this->id = $this->get_table_id(); - $args = wp_parse_args($args, array( - 'screen' => $this->id, - )); + $args = wp_parse_args( + $args, + array( + 'screen' => $this->id, + ) + ); parent::__construct($args); @@ -140,8 +139,7 @@ class Base_List_Table extends \WP_List_Table { $this->set_list_mode(); $this->_args['add_new'] = wu_get_isset($args, 'add_new', array()); - - } // end __construct; + } /** * Adds the screen option fields. @@ -158,8 +156,7 @@ class Base_List_Table extends \WP_List_Table { ); add_screen_option('per_page', $args); - - } // end add_default_screen_options; + } /** * Adds the select all button for the Grid Mode. @@ -172,15 +169,12 @@ class Base_List_Table extends \WP_List_Table { protected function extra_tablenav($which) { if ($this->current_mode === 'grid') { - - echo sprintf( + printf( '', __('Select All', 'wp-ultimo') ); - - } // end if; - - } // end extra_tablenav; + } + } /** * Set the list display mode for the list table. @@ -191,36 +185,27 @@ class Base_List_Table extends \WP_List_Table { public function set_list_mode() { if ($this->context !== 'page') { - $this->current_mode = 'list'; return; - - } // end if; + } $list_table_name = $this->id; - if (!empty($_REQUEST['mode'])) { - + if ( ! empty($_REQUEST['mode'])) { $mode = $_REQUEST['mode']; if (in_array($mode, array_keys($this->modes), true)) { - $mode = $_REQUEST['mode']; - - } // end if; + } set_user_setting("{$list_table_name}_list_mode", $mode); - } else { - $mode = get_user_setting("{$list_table_name}_list_mode", current(array_keys($this->modes))); - - } // end if; + } $this->current_mode = $mode; - - } // end set_list_mode; + } /** * Returns a label. @@ -232,9 +217,8 @@ class Base_List_Table extends \WP_List_Table { */ public function get_label($label = 'singular') { - return isset($this->labels[$label]) ? $this->labels[$label] : 'Object'; - - } // end get_label; + return isset($this->labels[ $label ]) ? $this->labels[ $label ] : 'Object'; + } /** * Uses the query class to return the items to be displayed. @@ -263,37 +247,28 @@ class Base_List_Table extends \WP_List_Table { ); foreach ($extra_query_args as $extra_query_arg) { - $query = wu_request($extra_query_arg, 'all'); if ($query !== 'all') { - - $query_args[$extra_query_arg] = $query; - - } // end if; - - } // end foreach; + $query_args[ $extra_query_arg ] = $query; + } + } /** * Accounts for hashes */ if (isset($query_args['search']) && strlen((string) $query_args['search']) === Hash::LENGTH) { - $item_id = Hash::decode($query_args['search']); if ($item_id) { - unset($query_args['search']); $query_args['id'] = $item_id; - - } // end if; - - } // end if; + } + } return $this->_get_items($query_args); - - } // end get_items; + } /** * General purpose get_items. @@ -314,18 +289,13 @@ class Base_List_Table extends \WP_List_Table { $function_name = 'wu_get_' . $query_class->get_plural_name(); if (function_exists($function_name)) { - $query = $function_name($query_args); - } else { - $query = $query_class->query($query_args); - - } // end if; + } return $query; - - } // end _get_items; + } /** * Checks if we have any items at all. @@ -340,8 +310,7 @@ class Base_List_Table extends \WP_List_Table { $results = $this->get_items(1, 1, false); return (int) $results > 0; - - } // end has_items; + } /** * Returns the total record count. Used on pagination. @@ -352,8 +321,7 @@ class Base_List_Table extends \WP_List_Table { public function record_count() { return $this->get_items(9_999_999, 1, true); - - } // end record_count; + } /** * Returns the slug of the per_page option for this data type. * @@ -362,8 +330,7 @@ class Base_List_Table extends \WP_List_Table { public function get_per_page_option_name(): string { return sprintf('%s_per_page', $this->id); - - } // end get_per_page_option_name; + } /** * Returns the label for the per_page option for this data_type. * @@ -373,8 +340,7 @@ class Base_List_Table extends \WP_List_Table { // translators: %s will be replaced by the data type plural name. e.g. Books. return sprintf(__('%s per page'), $this->get_label('plural')); - - } // end get_per_page_option_label; + } /** * Uses the query class to determine if there's any searchable fields. @@ -385,9 +351,8 @@ class Base_List_Table extends \WP_List_Table { */ protected function has_search() { - return !empty($this->get_schema_columns(array('searchable' => true))); - - } // end has_search; + return ! empty($this->get_schema_columns(array('searchable' => true))); + } /** * Generates the search field label, based on the table labels. * @@ -397,8 +362,7 @@ class Base_List_Table extends \WP_List_Table { // translators: %s will be replaced with the data type plural name. e.g. Books. return sprintf(__('Search %s'), $this->get_label('plural')); - - } // end get_search_input_label; + } /** * Prepare the list table before actually displaying records. @@ -416,14 +380,15 @@ class Base_List_Table extends \WP_List_Table { $total_items = $this->record_count(); - $this->set_pagination_args(array( - 'total_items' => $total_items, // We have to calculate the total number of items. - 'per_page' => $per_page // We have to determine how many items to show on a page. - )); + $this->set_pagination_args( + array( + 'total_items' => $total_items, // We have to calculate the total number of items. + 'per_page' => $per_page, // We have to determine how many items to show on a page. + ) + ); $this->items = $this->get_items($per_page, $current_page); - - } // end prepare_items; + } /** * Register Scripts that might be needed for ajax pagination and so on. @@ -433,17 +398,20 @@ class Base_List_Table extends \WP_List_Table { */ public function register_scripts() { - wp_localize_script('wu-ajax-list-table', 'wu_list_table', array( - 'base_url' => wu_get_form_url('bulk_actions'), - 'model' => strchr($this->get_table_id(), '_', true), - 'i18n' => array( - 'confirm' => __('Confirm Action', 'wp-ultimo'), - ), - )); + wp_localize_script( + 'wu-ajax-list-table', + 'wu_list_table', + array( + 'base_url' => wu_get_form_url('bulk_actions'), + 'model' => strchr($this->get_table_id(), '_', true), + 'i18n' => array( + 'confirm' => __('Confirm Action', 'wp-ultimo'), + ), + ) + ); wp_enqueue_script('wu-ajax-list-table'); - - } // end register_scripts; + } /** * Adds the hidden fields necessary to handle pagination. @@ -467,10 +435,8 @@ class Base_List_Table extends \WP_List_Table { * ID attribute to be used with the push state */ if (wu_request('id')) { - printf('', esc_attr(wu_request('id'))); - - } // end if; + } foreach ($this->get_hidden_fields() as $field_name => $field_value) { @@ -478,10 +444,8 @@ class Base_List_Table extends \WP_List_Table { * Add a hidden field to later be sent via the ajax call. */ printf('', esc_attr($field_name), esc_attr($field_name), esc_attr($field_value)); - - } // end foreach; - - } // end display_ajax_filters; + } + } /** * Handles the default display for list mode. @@ -501,8 +465,7 @@ class Base_List_Table extends \WP_List_Table { parent::display(); echo ''; - - } // end display_view_list; + } /** * Handles the default display for grid mode. @@ -516,13 +479,15 @@ class Base_List_Table extends \WP_List_Table { $this->display_ajax_filters(); - wu_get_template('base/grid', array( - 'table' => $this, - )); + wu_get_template( + 'base/grid', + array( + 'table' => $this, + ) + ); echo ''; - - } // end display_view_grid; + } /** * Displays the table. @@ -536,25 +501,22 @@ class Base_List_Table extends \WP_List_Table { /* * Any items at all? */ - if (!$this->has_items() && $this->context === 'page') { - - echo wu_render_empty_state(array( - 'message' => sprintf(__("You don't have any %s yet.", 'wp-ultimo'), $this->labels['plural']), - 'sub_message' => $this->_args['add_new'] ? __('How about we create a new one?', 'wp-ultimo') : __('...but you will see them here once they get created.', 'wp-ultimo'), - // translators: %s is the singular value of the model, such as Product, or Payment. - 'link_label' => sprintf(__('Create a new %s', 'wp-ultimo'), $this->labels['singular']), - 'link_url' => wu_get_isset($this->_args['add_new'], 'url', ''), - 'link_classes' => wu_get_isset($this->_args['add_new'], 'classes', ''), - 'link_icon' => 'dashicons-wu-circle-with-plus', - )); - + if ( ! $this->has_items() && $this->context === 'page') { + echo wu_render_empty_state( + array( + 'message' => sprintf(__("You don't have any %s yet.", 'wp-ultimo'), $this->labels['plural']), + 'sub_message' => $this->_args['add_new'] ? __('How about we create a new one?', 'wp-ultimo') : __('...but you will see them here once they get created.', 'wp-ultimo'), + // translators: %s is the singular value of the model, such as Product, or Payment. + 'link_label' => sprintf(__('Create a new %s', 'wp-ultimo'), $this->labels['singular']), + 'link_url' => wu_get_isset($this->_args['add_new'], 'url', ''), + 'link_classes' => wu_get_isset($this->_args['add_new'], 'classes', ''), + 'link_icon' => 'dashicons-wu-circle-with-plus', + ) + ); } else { - call_user_func(array($this, "display_view_{$this->current_mode}")); - - } // end if; - - } // end display; + } + } /** * Display the filters if they exist. @@ -570,21 +532,21 @@ class Base_List_Table extends \WP_List_Table { $views = apply_filters("wu_{$this->id}_get_views", $this->get_views()); if (true) { - - $args = array_merge($filters, array( - 'filters_el_id' => sprintf('%s-filters', $this->id), - 'has_search' => $this->has_search(), - 'search_label' => $this->get_search_input_label(), - 'views' => $views, - 'has_view_switch' => !empty($this->modes), - 'table' => $this, - )); + $args = array_merge( + $filters, + array( + 'filters_el_id' => sprintf('%s-filters', $this->id), + 'has_search' => $this->has_search(), + 'search_label' => $this->get_search_input_label(), + 'views' => $views, + 'has_view_switch' => ! empty($this->modes), + 'table' => $this, + ) + ); wu_get_template('base/filter', $args); - - } // end if; - - } // end filters; + } + } /** * Overrides the single row method to create different methods depending on the mode. @@ -597,8 +559,7 @@ class Base_List_Table extends \WP_List_Table { public function single_row($item) { call_user_func(array($this, "single_row_{$this->current_mode}"), $item); - - } // end single_row; + } /** * Handles the item display for list mode. @@ -611,8 +572,7 @@ class Base_List_Table extends \WP_List_Table { public function single_row_list($item) { parent::single_row($item); - - } // end single_row_list; + } /** * Handles the item display for grid mode. @@ -622,7 +582,7 @@ class Base_List_Table extends \WP_List_Table { * @param mixed $item The line item being displayed. * @return void */ - public function single_row_grid($item) {} // end single_row_grid; + public function single_row_grid($item) {} /** * Displays a base div when there is not item. @@ -632,11 +592,13 @@ class Base_List_Table extends \WP_List_Table { */ public function no_items() { - echo sprintf('

    + printf( + '
    %s -
    ', __('No items found', 'wp-ultimo')); - - } // end no_items; +
    ', + __('No items found', 'wp-ultimo') + ); + } /** * Returns an associative array containing the bulk action @@ -649,20 +611,19 @@ class Base_List_Table extends \WP_List_Table { 'delete' => __('Delete', 'wp-ultimo'), ); - $has_active = $this->get_schema_columns(array( - 'name' => 'active', - )); + $has_active = $this->get_schema_columns( + array( + 'name' => 'active', + ) + ); if ($has_active) { - $default_bulk_actions['activate'] = __('Activate', 'wp-ultimo'); $default_bulk_actions['deactivate'] = __('Deactivate', 'wp-ultimo'); - - } // end if; + } return apply_filters('wu_bulk_actions', $default_bulk_actions, $this->id); - - } // end get_bulk_actions; + } /** * Process single action. @@ -670,7 +631,7 @@ class Base_List_Table extends \WP_List_Table { * @since 2.0.0 * @return void */ - public function process_single_action() {} // end process_single_action; + public function process_single_action() {} /** * Handles the bulk processing. @@ -678,7 +639,7 @@ class Base_List_Table extends \WP_List_Table { * @since 2.0.0 * @return bool */ - static public function process_bulk_action() { + public static function process_bulk_action() { global $wpdb; @@ -687,14 +648,10 @@ class Base_List_Table extends \WP_List_Table { $model = wu_request('model'); if ($model === 'checkout') { - $model = 'checkout_form'; - } elseif ($model === 'discount') { - $model = 'discount_code'; - - } // end if; + } $item_ids = explode(',', (string) wu_request('ids', '')); @@ -702,60 +659,49 @@ class Base_List_Table extends \WP_List_Table { $func_name = $prefix . $model; - if (!function_exists($func_name)) { - + if ( ! function_exists($func_name)) { return new \WP_Error('func-not-exists', __('Something went wrong.', 'wp-ultimo')); - - } // end if; + } switch ($bulk_action) { - case 'activate': foreach ($item_ids as $item_id) { - $item = $func_name($item_id); $item->set_active(true); $item->save(); - - } // end foreach; + } break; case 'deactivate': foreach ($item_ids as $item_id) { - $item = $func_name($item_id); $item->set_active(false); $item->save(); - - } // end foreach; + } break; case 'delete': foreach ($item_ids as $item_id) { - $item = $func_name($item_id); $item->delete(); - - } // end foreach; + } break; default: do_action('wu_process_bulk_action', $bulk_action); break; - - } // end switch; + } return true; - - } // end process_bulk_action; + } /** * Handles ajax requests for pagination and filtering. @@ -780,15 +726,11 @@ class Base_List_Table extends \WP_List_Table { */ ob_start(); - if (!empty($_REQUEST['no_placeholder'])) { - + if ( ! empty($_REQUEST['no_placeholder'])) { $this->display_rows(); - } else { - $this->display_rows_or_placeholder(); - - } // end if; + } $rows = ob_get_clean(); @@ -830,17 +772,13 @@ class Base_List_Table extends \WP_List_Table { $response['type'] = wu_request('type', 'all'); if (isset($total_items)) { - $response['total_items_i18n'] = sprintf(_n('1 item', '%s items', $total_items), number_format_i18n($total_items)); // phpcs:ignore - - } // end if; + } if (isset($total_pages)) { - $response['total_pages'] = $total_pages; - $response['total_pages_i18n'] = number_format_i18n( $total_pages ); - - } // end if; + $response['total_pages_i18n'] = number_format_i18n($total_pages); + } /** * Send the response @@ -848,8 +786,7 @@ class Base_List_Table extends \WP_List_Table { wp_send_json($response); exit; - - } // end ajax_response; + } /** * Render a column when no column specific method exist. @@ -863,19 +800,21 @@ class Base_List_Table extends \WP_List_Table { $value = call_user_func(array($item, "get_{$column_name}")); - $datetime_columns = array_column($this->get_schema_columns(array( - 'date_query' => true, - )), 'name'); + $datetime_columns = array_column( + $this->get_schema_columns( + array( + 'date_query' => true, + ) + ), + 'name' + ); if (in_array($column_name, $datetime_columns, true)) { - return $this->_column_datetime($value); - - } // end if; + } return $value; - - } // end column_default; + } /** * Handles the default displaying of datetime columns. @@ -887,11 +826,9 @@ class Base_List_Table extends \WP_List_Table { */ public function _column_datetime($date) { - if (!wu_validate_date($date)) { - + if ( ! wu_validate_date($date)) { return __('--', 'wp-ultimo'); - - } // end if; + } $time = strtotime(get_date_from_gmt((string) $date)); @@ -902,8 +839,7 @@ class Base_List_Table extends \WP_List_Table { $text = $formatted_value . sprintf('
    %s', sprintf($placeholder, human_time_diff($time))); return sprintf('%s', wu_tooltip_text(date_i18n('Y-m-d H:i:s', $time)), $text); - - } // end _column_datetime; + } /** * Returns the membership object associated with this object. @@ -917,8 +853,7 @@ class Base_List_Table extends \WP_List_Table { $membership = $item->get_membership(); - if (!$membership) { - + if ( ! $membership) { $not_found = __('No membership found', 'wp-ultimo'); return "
    @@ -927,8 +862,7 @@ class Base_List_Table extends \WP_List_Table { {$not_found}
    "; - - } // end if; + } $url_atts = array( 'id' => $membership->get_id(), @@ -953,8 +887,7 @@ class Base_List_Table extends \WP_List_Table { "; return $html; - - } // end column_membership; + } /** * Returns the payment object associated with this object. @@ -968,8 +901,7 @@ class Base_List_Table extends \WP_List_Table { $payment = $item->get_payment(); - if (!$payment) { - + if ( ! $payment) { $not_found = __('No payment found', 'wp-ultimo'); return "
    @@ -978,8 +910,7 @@ class Base_List_Table extends \WP_List_Table { {$not_found}
    "; - - } // end if; + } $url_atts = array( 'id' => $payment->get_id(), @@ -1004,8 +935,7 @@ class Base_List_Table extends \WP_List_Table { "; return $html; - - } // end column_payment; + } /** * Returns the customer object associated with this object. @@ -1019,8 +949,7 @@ class Base_List_Table extends \WP_List_Table { $customer = $item->get_customer(); - if (!$customer) { - + if ( ! $customer) { $not_found = __('No customer found', 'wp-ultimo'); return "
    @@ -1029,17 +958,22 @@ class Base_List_Table extends \WP_List_Table { {$not_found}
    "; - - } // end if; + } $url_atts = array( 'id' => $customer->get_id(), ); - $avatar = get_avatar($customer->get_user_id(), 32, 'identicon', '', array( - 'force_display' => true, - 'class' => 'wu-rounded-full wu-mr-2', - )); + $avatar = get_avatar( + $customer->get_user_id(), + 32, + 'identicon', + '', + array( + 'force_display' => true, + 'class' => 'wu-rounded-full wu-mr-2', + ) + ); $display_name = $customer->get_display_name(); @@ -1058,8 +992,7 @@ class Base_List_Table extends \WP_List_Table { "; return $html; - - } // end column_customer; + } /** * Returns the product object associated with this object. @@ -1073,8 +1006,7 @@ class Base_List_Table extends \WP_List_Table { $product = $item->get_plan(); - if (!$product) { - + if ( ! $product) { $not_found = __('No product found', 'wp-ultimo'); return "
    @@ -1083,8 +1015,7 @@ class Base_List_Table extends \WP_List_Table { {$not_found}
    "; - - } // end if; + } $url_atts = array( 'id' => $product->get_id(), @@ -1114,8 +1045,7 @@ class Base_List_Table extends \WP_List_Table { "; return $html; - - } // end column_product; + } /** * Returns the site object associated with this object. @@ -1129,8 +1059,7 @@ class Base_List_Table extends \WP_List_Table { $site = $item->get_site(); - if (!$site) { - + if ( ! $site) { $not_found = __('No site found', 'wp-ultimo'); return "
    @@ -1139,8 +1068,7 @@ class Base_List_Table extends \WP_List_Table { {$not_found}
    "; - - } // end if; + } $url_atts = array( 'id' => $site->get_id(), @@ -1161,8 +1089,7 @@ class Base_List_Table extends \WP_List_Table { "; return $html; - - } // end column_blog_id; + } /** * Display the column for feature image. * @@ -1176,20 +1103,21 @@ class Base_List_Table extends \WP_List_Table { $large_image = $item->get_featured_image('large'); - if (!$image) { - + if ( ! $image) { return '
    '; + } - } // end if; - - return sprintf('
    + return sprintf( + '
    -
    ', $image, $large_image); - - } // end column_featured_image_id; +
    ', + $image, + $large_image + ); + } /** * Render the bulk edit checkbox. @@ -1201,8 +1129,7 @@ class Base_List_Table extends \WP_List_Table { public function column_cb($item) { return sprintf('', $item->get_id()); - - } // end column_cb; + } /** * Return the js var name. This will be used on other places. * @@ -1211,8 +1138,7 @@ class Base_List_Table extends \WP_List_Table { public function _get_js_var_name(): string { return str_replace('-', '_', $this->id); - - } // end _get_js_var_name; + } /** * Overrides the parent method to include the custom ajax functionality for WP Multisite WaaS. @@ -1246,14 +1172,13 @@ class Base_List_Table extends \WP_List_Table { window[table_id] = wu_create_list(table_id).init(); - } // end if; + } }); isset($_REQUEST[$name]['after']) ? $_REQUEST[$name]['after'] : 'all', - 'before' => isset($_REQUEST[$name]['before']) ? $_REQUEST[$name]['before'] : 'all', - 'type' => isset($_REQUEST['filter_' . $name]) ? $_REQUEST['filter_' . $name] : 'all', + 'after' => isset($_REQUEST[ $name ]['after']) ? $_REQUEST[ $name ]['after'] : 'all', + 'before' => isset($_REQUEST[ $name ]['before']) ? $_REQUEST[ $name ]['before'] : 'all', + 'type' => isset($_REQUEST[ 'filter_' . $name ]) ? $_REQUEST[ 'filter_' . $name ] : 'all', ); - - } // end fill_date_type; + } /** * Get the default date filter options. @@ -1342,8 +1265,7 @@ class Base_List_Table extends \WP_List_Table { 'before' => null, ), ); - - } // end get_default_date_filter_options; + } /** * Returns the columns from the BerlinDB Schema. @@ -1370,8 +1292,7 @@ class Base_List_Table extends \WP_List_Table { $method->setAccessible(true); return $method->invoke($query_class, $args, $operator, $field); - - } // end get_schema_columns; + } /** * Returns sortable columns on the schema. @@ -1380,21 +1301,20 @@ class Base_List_Table extends \WP_List_Table { */ public function get_sortable_columns() { - $sortable_columns_from_schema = $this->get_schema_columns(array( - 'sortable' => true, - )); + $sortable_columns_from_schema = $this->get_schema_columns( + array( + 'sortable' => true, + ) + ); $sortable_columns = array(); foreach ($sortable_columns_from_schema as $sortable_column_from_schema) { - - $sortable_columns[$sortable_column_from_schema->name] = array($sortable_column_from_schema->name, false); - - } // end foreach; + $sortable_columns[ $sortable_column_from_schema->name ] = array($sortable_column_from_schema->name, false); + } return $sortable_columns; - - } // end get_sortable_columns; + } /** * Get the extra fields based on the request. @@ -1409,18 +1329,13 @@ class Base_List_Table extends \WP_List_Table { $_filter_fields = array(); if (isset($filters['filters'])) { - foreach ($filters['filters'] as $field_name => $field) { - - $_filter_fields[$field_name] = wu_request($field_name, ''); - - } // end foreach; - - } // end if; + $_filter_fields[ $field_name ] = wu_request($field_name, ''); + } + } return $_filter_fields; - - } // end get_extra_fields; + } /** * Returns the date fields. @@ -1435,30 +1350,21 @@ class Base_List_Table extends \WP_List_Table { $_filter_fields = array(); if (isset($filters['date_filters'])) { - foreach ($filters['date_filters'] as $field_name => $field) { - - if (!isset($_REQUEST[$field_name])) { - + if ( ! isset($_REQUEST[ $field_name ])) { continue; + } - } // end if; - - if (isset($_REQUEST[$field_name]['before']) && isset($_REQUEST[$field_name]['after']) && $_REQUEST[$field_name]['before'] === '' && $_REQUEST[$field_name]['after'] === '') { - + if (isset($_REQUEST[ $field_name ]['before']) && isset($_REQUEST[ $field_name ]['after']) && $_REQUEST[ $field_name ]['before'] === '' && $_REQUEST[ $field_name ]['after'] === '') { continue; + } - } // end if; - - $_filter_fields[$field_name] = wu_request($field_name, ''); - - } // end foreach; - - } // end if; + $_filter_fields[ $field_name ] = wu_request($field_name, ''); + } + } return $_filter_fields; - - } // end get_extra_date_fields; + } /** * Returns a list of filters on the request to be used on the query. @@ -1469,8 +1375,7 @@ class Base_List_Table extends \WP_List_Table { public function get_extra_query_fields() { return array(); - - } // end get_extra_query_fields; + } /** * Returns the hidden fields that are embedded into the page. @@ -1490,8 +1395,7 @@ class Base_List_Table extends \WP_List_Table { ); return $final_fields; - - } // end get_hidden_fields; + } /** * Returns the pre-selected filters on the filter bar. @@ -1509,8 +1413,7 @@ class Base_List_Table extends \WP_List_Table { 'count' => 0, ), ); - - } // end get_views; + } /** * Generates the required HTML for a list of row action links. @@ -1526,8 +1429,5 @@ class Base_List_Table extends \WP_List_Table { $actions = apply_filters('wu_list_row_actions', $actions, $this->id); return parent::row_actions($actions); - - } // end row_actions; - - -} // end class Base_List_Table; + } +} diff --git a/inc/list-tables/class-broadcast-list-table.php b/inc/list-tables/class-broadcast-list-table.php index 003074e..53160e6 100644 --- a/inc/list-tables/class-broadcast-list-table.php +++ b/inc/list-tables/class-broadcast-list-table.php @@ -34,17 +34,18 @@ class Broadcast_List_Table extends Base_List_Table { */ public function __construct() { - parent::__construct(array( - 'singular' => __('Broadcast', 'wp-ultimo'), // singular name of the listed records - 'plural' => __('Broadcasts', 'wp-ultimo'), // plural name of the listed records - 'ajax' => true, // does this table support ajax? - 'add_new' => array( - 'url' => wu_get_form_url('add_new_broadcast_message'), - 'classes' => 'wubox', - ), - )); - - } // end __construct; + parent::__construct( + array( + 'singular' => __('Broadcast', 'wp-ultimo'), // singular name of the listed records + 'plural' => __('Broadcasts', 'wp-ultimo'), // plural name of the listed records + 'ajax' => true, // does this table support ajax? + 'add_new' => array( + 'url' => wu_get_form_url('add_new_broadcast_message'), + 'classes' => 'wubox', + ), + ) + ); + } /** * Overrides the checkbox column to disable the checkboxes on the email types. @@ -57,14 +58,11 @@ class Broadcast_List_Table extends Base_List_Table { public function column_cb($item) { if ($item->get_type() === 'broadcast_email') { - return ''; - - } // end if; + } return parent::column_cb($item); - - } // end column_cb; + } /** * Returns the markup for the type column. @@ -81,40 +79,27 @@ class Broadcast_List_Table extends Base_List_Table { $class = 'wu-bg-gray-200'; if ($type === 'broadcast_email') { - $label = __('Email', 'wp-ultimo'); - - } // end if; + } if ($type === 'broadcast_notice') { - $status = $item->get_notice_type(); $label = __('Notice', 'wp-ultimo'); if ($status === 'info') { - $class = 'wu-bg-blue-200'; - } elseif ($status === 'success') { - $class = 'wu-bg-green-200'; - } elseif ($status === 'warning') { - $class = 'wu-bg-orange-200'; - } elseif ($status === 'error') { - $class = 'wu-bg-red-200'; - - } // end if; - - } // end if; + } + } return "{$label}"; - - } // end column_type; + } /** * Displays the name of the broadcast. * @@ -131,7 +116,7 @@ class Broadcast_List_Table extends Base_List_Table { $url_atts = array( 'id' => $item->get_id(), 'slug' => $item->get_slug(), - 'model' => 'broadcast' + 'model' => 'broadcast', ); $actions = array( @@ -140,8 +125,7 @@ class Broadcast_List_Table extends Base_List_Table { ); return $title . $content . $this->row_actions($actions); - - } // end column_the_content; + } /** * Displays the target customers of the broadcast. @@ -182,10 +166,16 @@ class Broadcast_List_Table extends Base_List_Table { $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(); @@ -205,16 +195,21 @@ class Broadcast_List_Table extends Base_List_Table { break; default: foreach ($targets as $key => $target) { - $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(), @@ -223,11 +218,9 @@ class Broadcast_List_Table extends Base_List_Table { $customer_link = wu_network_admin_url('wp-ultimo-edit-customer', $url_atts); $html .= ""; - - } // end foreach; + } if ($targets_count < 7) { - $modal_atts = array( 'action' => 'wu_modal_targets_display', 'object_id' => $item->get_id(), @@ -236,15 +229,20 @@ class Broadcast_List_Table extends Base_List_Table { 'target_type' => 'customers', ); - $html .= sprintf('
    + $html .= sprintf( + '', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $targets_count, __('Targets', 'wp-ultimo')); +
    ', + wu_get_form_url('view_broadcast_targets', $modal_atts), + __('Targets', 'wp-ultimo'), + $targets_count, + __('Targets', 'wp-ultimo') + ); $html .= ''; return $html; - - } // end if; + } $modal_atts = array( 'action' => 'wu_modal_targets_display', @@ -254,19 +252,23 @@ class Broadcast_List_Table extends Base_List_Table { 'target_type' => 'customers', ); - $html .= sprintf('
    + $html .= sprintf( + '', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $targets_count, __('Targets', 'wp-ultimo')); +
    ', + wu_get_form_url('view_broadcast_targets', $modal_atts), + __('Targets', 'wp-ultimo'), + $targets_count, + __('Targets', 'wp-ultimo') + ); $html .= ''; return $html; break; - - } // end switch; - - } // end column_target_customers; + } + } /** * Displays the target products of the broadcast. @@ -303,16 +305,12 @@ class Broadcast_List_Table extends Base_List_Table { $image = $product->get_featured_image('thumbnail'); if ($image) { - $image = sprintf('', esc_attr($image)); - } else { - $image = '
    '; - - } // end if; + } $name = $product->get_name(); @@ -323,10 +321,8 @@ class Broadcast_List_Table extends Base_List_Table { $customer_count = (int) 0; if ($plan_customers) { - $customer_count = count($plan_customers); - - } // end if; + } $description = sprintf(__('%s customer(s) targeted.', 'wp-ultimo'), $customer_count); @@ -344,19 +340,15 @@ class Broadcast_List_Table extends Base_List_Table { "; break; - - } // end switch; + } if ($html) { - return $html; - - } // end if; + } $html = '
    '; foreach ($products as $product) { - $url_atts = array( 'id' => $product->get_id(), ); @@ -368,23 +360,17 @@ class Broadcast_List_Table extends Base_List_Table { $image = $product->get_featured_image('thumbnail'); if ($image) { - $image = sprintf('', esc_attr($image)); - } else { - $image = '
    '; - - } // end if; + } $html .= ""; - - } // end foreach; + } if ($product_count > 1 && $product_count < 5) { - $modal_atts = array( 'action' => 'wu_modal_targets_display', 'object_id' => $item->get_id(), @@ -393,14 +379,19 @@ class Broadcast_List_Table extends Base_List_Table { 'target_type' => 'products', ); - $html .= sprintf('', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $product_count, __('Targets', 'wp-ultimo')); + $html .= sprintf( + '', + wu_get_form_url('view_broadcast_targets', $modal_atts), + __('Targets', 'wp-ultimo'), + $product_count, + __('Targets', 'wp-ultimo') + ); $html .= '
    '; return $html; - - } // end if; + } $modal_atts = array( 'action' => 'wu_modal_targets_display', @@ -415,8 +406,7 @@ class Broadcast_List_Table extends Base_List_Table { $html .= ''; return $html; - - } // end column_target_products; + } /** * Returns the list of columns for this particular List Table. @@ -437,8 +427,7 @@ class Broadcast_List_Table extends Base_List_Table { ); return $columns; - - } // end get_columns; + } /** * Returns the filters for this page. * @@ -472,8 +461,7 @@ class Broadcast_List_Table extends Base_List_Table { ), ), ); - - } // end get_filters; + } /** * Registers the necessary scripts and styles for this admin page. @@ -484,8 +472,7 @@ class Broadcast_List_Table extends Base_List_Table { public function register_scripts() { parent::register_scripts(); - - } // end register_scripts; + } /** * Returns the pre-selected filters on the filter bar. @@ -515,7 +502,5 @@ class Broadcast_List_Table extends Base_List_Table { 'count' => 0, ), ); - - } // end get_views; - -} // end class Broadcast_List_Table; + } +} diff --git a/inc/list-tables/class-checkout-form-list-table.php b/inc/list-tables/class-checkout-form-list-table.php index 6b46706..52ced53 100644 --- a/inc/list-tables/class-checkout-form-list-table.php +++ b/inc/list-tables/class-checkout-form-list-table.php @@ -34,17 +34,18 @@ class Checkout_Form_List_Table extends Base_List_Table { */ public function __construct() { - parent::__construct(array( - 'singular' => __('Checkout Form', 'wp-ultimo'), // singular name of the listed records - 'plural' => __('Checkout Forms', 'wp-ultimo'), // plural name of the listed records - 'ajax' => true, // does this table support ajax? - 'add_new' => array( - 'url' => wu_get_form_url('add_new_checkout_form'), - 'classes' => 'wubox', - ), - )); - - } // end __construct; + parent::__construct( + array( + 'singular' => __('Checkout Form', 'wp-ultimo'), // singular name of the listed records + 'plural' => __('Checkout Forms', 'wp-ultimo'), // plural name of the listed records + 'ajax' => true, // does this table support ajax? + 'add_new' => array( + 'url' => wu_get_form_url('add_new_checkout_form'), + 'classes' => 'wubox', + ), + ) + ); + } /** * Displays the content of the product column. * @@ -64,14 +65,23 @@ class Checkout_Form_List_Table extends Base_List_Table { $actions = array( 'edit' => sprintf('%s', wu_network_admin_url('wp-ultimo-edit-checkout-form', $url_atts), __('Edit', 'wp-ultimo')), - 'duplicate' => sprintf('%s', wu_network_admin_url('wp-ultimo-checkout-forms', array('action' => 'duplicate', 'id' => $item->get_id())), __('Duplicate', 'wp-ultimo')), + 'duplicate' => sprintf( + '%s', + wu_network_admin_url( + 'wp-ultimo-checkout-forms', + array( + 'action' => 'duplicate', + 'id' => $item->get_id(), + ) + ), + __('Duplicate', 'wp-ultimo') + ), 'get_shortcode' => sprintf('%s', __('Shortcode', 'wp-ultimo'), wu_get_form_url('shortcode_checkout', $url_atts), __('Shortcode', 'wp-ultimo')), 'delete' => sprintf('%s', __('Delete', 'wp-ultimo'), wu_get_form_url('delete_modal', $url_atts), __('Delete', 'wp-ultimo')), ); return $title . $this->row_actions($actions); - - } // end column_name; + } /** * Displays the slug of the form. @@ -86,8 +96,7 @@ class Checkout_Form_List_Table extends Base_List_Table { $slug = $item->get_slug(); return "{$slug}"; - - } // end column_slug; + } /** * Displays the number pof steps and fields. * @@ -98,8 +107,7 @@ class Checkout_Form_List_Table extends Base_List_Table { public function column_steps($item): string { return sprintf(__('%1$d Step(s) and %2$d Field(s)', 'wp-ultimo'), $item->get_step_count(), $item->get_field_count()); - - } // end column_steps; + } /** * Displays the form shortcode. * @@ -109,14 +117,16 @@ class Checkout_Form_List_Table extends Base_List_Table { */ public function column_shortcode($item): string { - $button = sprintf(' + $button = sprintf( + ' ', __('Copy to the Clipboard', 'wp-ultimo')); + ', + __('Copy to the Clipboard', 'wp-ultimo') + ); return sprintf('', esc_attr($item->get_shortcode()), ''); - - } // end column_shortcode; + } /** * Handles the bulk processing adding duplication @@ -129,18 +139,15 @@ class Checkout_Form_List_Table extends Base_List_Table { $bulk_action = $this->current_action(); if ($bulk_action === 'duplicate') { - $checkout_form_id = wu_request('id'); $checkout_form = wu_get_checkout_form($checkout_form_id); - if (!$checkout_form) { - + if ( ! $checkout_form) { WP_Ultimo()->notices->add(__('Checkout form not found.', 'wp-ultimo'), 'error', 'network-admin'); return; - - } // end if; + } $new_checkout_form = $checkout_form->duplicate(); @@ -155,25 +162,24 @@ class Checkout_Form_List_Table extends Base_List_Table { $result = $new_checkout_form->save(); if (is_wp_error($result)) { - WP_Ultimo()->notices->add($result->get_error_message(), 'error', 'network-admin'); return; + } - } // end if; - - $redirect_url = wu_network_admin_url('wp-ultimo-edit-checkout-form', array( - 'id' => $new_checkout_form->get_id(), - 'updated' => 1, - )); + $redirect_url = wu_network_admin_url( + 'wp-ultimo-edit-checkout-form', + array( + 'id' => $new_checkout_form->get_id(), + 'updated' => 1, + ) + ); wp_redirect($redirect_url); exit; - - } // end if; - - } // end process_single_action; + } + } /** * Returns the list of columns for this particular List Table. @@ -192,8 +198,7 @@ class Checkout_Form_List_Table extends Base_List_Table { ); return $columns; - - } // end get_columns; + } /** * Returns the filters for this page. * @@ -205,7 +210,5 @@ class Checkout_Form_List_Table extends Base_List_Table { 'filters' => array(), 'date_filters' => array(), ); - - } // end get_filters; - -} // end class Checkout_Form_List_Table; + } +} diff --git a/inc/list-tables/class-customer-list-table.php b/inc/list-tables/class-customer-list-table.php index b72241d..7803dc3 100644 --- a/inc/list-tables/class-customer-list-table.php +++ b/inc/list-tables/class-customer-list-table.php @@ -40,19 +40,21 @@ class Customer_List_Table extends Base_List_Table { 'list' => __('List View'), ); - $args = wp_parse_args($args, array( - 'singular' => __('Customer', 'wp-ultimo'), // singular name of the listed records - 'plural' => __('Customers', 'wp-ultimo'), // plural name of the listed records - 'ajax' => true, // does this table support ajax? - 'add_new' => array( - 'url' => wu_get_form_url('add_new_customer'), - 'classes' => 'wubox', - ), - )); + $args = wp_parse_args( + $args, + array( + 'singular' => __('Customer', 'wp-ultimo'), // singular name of the listed records + 'plural' => __('Customers', 'wp-ultimo'), // plural name of the listed records + 'ajax' => true, // does this table support ajax? + 'add_new' => array( + 'url' => wu_get_form_url('add_new_customer'), + 'classes' => 'wubox', + ), + ) + ); parent::__construct($args); - - } // end __construct; + } /** * Adds the extra search field when the search element is present. @@ -66,46 +68,40 @@ class Customer_List_Table extends Base_List_Table { $search = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : false; - if (!empty($search)) { + if ( ! empty($search)) { // Search relevant users - $user_ids = get_users(array( - 'number' => -1, - 'search' => '*' . $search . '*', - 'fields' => 'ids', - )); + $user_ids = get_users( + array( + 'number' => -1, + 'search' => '*' . $search . '*', + 'fields' => 'ids', + ) + ); // No results, go back if (empty($user_ids)) { - return $_filter_fields; - - } // end if; + } // Finally, include these user IDs in the customers query. $_filter_fields['user_id__in'] = $user_ids; unset($_filter_fields['search']); - - } // end if; + } $_filter_fields['type'] = 'customer'; if (wu_request('filter', 'all') === 'vip') { - $_filter_fields['vip'] = 1; - } elseif (wu_request('filter', 'all') === 'online') { - $_filter_fields['last_login_query'] = array( 'after' => '-3 minutes', ); - - } // end if; + } return $_filter_fields; - - } // end get_extra_query_fields; + } /** * Displays the content of the name column. * @@ -123,21 +119,26 @@ class Customer_List_Table extends Base_List_Table { ); // Check if user exists - if (!$user) { - + if ( ! $user) { $actions = array( 'delete' => sprintf('%s', __('Delete', 'wp-ultimo'), wu_get_form_url('delete_modal', $url_atts), __('Delete', 'wp-ultimo')), ); return sprintf('#%s - %s', $item->get_user_id(), __('User not found', 'wp-ultimo')) . $this->row_actions($actions); - - } // end if; + } $customer_id = sprintf('#%s', $item->get_id(), $item->get_id()); - $customer_user = sprintf('%s', wu_network_admin_url('wp-ultimo-edit-customer', array( - 'id' => $item->get_id(), - )), $user->display_name); + $customer_user = sprintf( + '%s', + wu_network_admin_url( + 'wp-ultimo-edit-customer', + array( + 'id' => $item->get_id(), + ) + ), + $user->display_name + ); // Concatenate the two blocks $title = "$customer_user"; @@ -159,7 +160,7 @@ class Customer_List_Table extends Base_List_Table { 'delete_modal', array( 'model' => 'customer', - 'id' => $item->get_id() + 'id' => $item->get_id(), ) ), __('Delete', 'wp-ultimo') @@ -169,8 +170,7 @@ class Customer_List_Table extends Base_List_Table { $actions = array_filter($actions); return $title . $desc . $this->row_actions($actions); - - } // end column_name; + } /** * Displays the customer photo and special status. @@ -185,20 +185,23 @@ class Customer_List_Table extends Base_List_Table { $html = '
    '; if ($item->is_vip()) { - $html .= sprintf('%s', __('VIP', 'wp-ultimo')); + } - } // end if; - - $html .= get_avatar($item->get_user_id(), 36, 'identicon', '', array( - 'force_display' => true, - )); + $html .= get_avatar( + $item->get_user_id(), + 36, + 'identicon', + '', + array( + 'force_display' => true, + ) + ); $html .= '
    '; return $html; - - } // end column_customer_status; + } /** * Returns the number of memberships owned by this customer. * @@ -220,8 +223,7 @@ class Customer_List_Table extends Base_List_Table { ); return $subscription_count . $this->row_actions($actions); - - } // end column_memberships; + } /** * Returns the list of columns for this particular List Table. @@ -242,8 +244,7 @@ class Customer_List_Table extends Base_List_Table { ); return $columns; - - } // end get_columns; + } /** * Handles the item display for grid mode. @@ -255,12 +256,14 @@ class Customer_List_Table extends Base_List_Table { */ public function single_row_grid($item) { - wu_get_template('base/customers/grid-item', array( - 'item' => $item, - 'table' => $this, - )); - - } // end single_row_grid; + wu_get_template( + 'base/customers/grid-item', + array( + 'item' => $item, + 'table' => $this, + ) + ); + } /** * Returns the filters for this page. @@ -269,46 +272,46 @@ class Customer_List_Table extends Base_List_Table { */ public function get_filters(): array { - $filters = $this->get_schema_columns(array( - 'searchable' => true, - 'date_query' => true, - ), 'or'); + $filters = $this->get_schema_columns( + array( + 'searchable' => true, + 'date_query' => true, + ), + 'or' + ); $labels = $this->get_columns(); - $filters = array_map(function($item) use ($labels) { + $filters = array_map( + function ($item) use ($labels) { - $label = wu_get_isset($labels, $item->name); - $label = $label ? sprintf('%s (%s)', $item->label, $item->name) : $item->name; + $label = wu_get_isset($labels, $item->name); + $label = $label ? sprintf('%s (%s)', $item->label, $item->name) : $item->name; - $filter_type = 'text'; - $rule = 'is'; + $filter_type = 'text'; + $rule = 'is'; - if ($item->date_query === true) { + if ($item->date_query === true) { + $filter_type = 'date'; + $rule = 'is_after'; + } elseif (in_array(strtolower((string) $item->name), array('smallint'), true)) { + $filter_type = 'bool'; + $rule = 'is_true'; + } - $filter_type = 'date'; - $rule = 'is_after'; - - } elseif (in_array(strtolower((string) $item->name), array('smallint'), true)) { - - $filter_type = 'bool'; - $rule = 'is_true'; - - } // end if; - - return array( - 'field' => $item->name, - 'label' => $label, - 'type' => $filter_type, - 'rule' => $rule, - 'value' => wu_request($item->name, ''), - ); - - }, $filters); + return array( + 'field' => $item->name, + 'label' => $label, + 'type' => $filter_type, + 'rule' => $rule, + 'value' => wu_request($item->name, ''), + ); + }, + $filters + ); return array_values($filters); - - } // end get_filters; + } /** * Returns the pre-selected filters on the filter bar. @@ -321,9 +324,11 @@ class Customer_List_Table extends Base_List_Table { return array( 'all' => array( 'field' => 'filter', - 'url' => add_query_arg(array( - 'filter' => 'all' - )), + 'url' => add_query_arg( + array( + 'filter' => 'all', + ) + ), 'label' => __('All Customers', 'wp-ultimo'), 'count' => 0, ), @@ -340,8 +345,7 @@ class Customer_List_Table extends Base_List_Table { 'count' => 0, ), ); - - } // end get_views; + } /** * Displays the last login. @@ -354,13 +358,9 @@ class Customer_List_Table extends Base_List_Table { public function column_last_login($item) { if ($item->is_online()) { - return '' . __('Online', 'wp-ultimo'); - - } // end if; + } return $this->_column_datetime($item->get_last_login()); - - } // end column_last_login; - -} // end class Customer_List_Table; + } +} diff --git a/inc/list-tables/class-customers-membership-list-table.php b/inc/list-tables/class-customers-membership-list-table.php index ba64dee..48fab15 100644 --- a/inc/list-tables/class-customers-membership-list-table.php +++ b/inc/list-tables/class-customers-membership-list-table.php @@ -32,8 +32,7 @@ class Customers_Membership_List_Table extends Membership_List_Table { ); return $columns; - - } // end get_columns; + } /** * Renders the inside column responsive. @@ -53,43 +52,47 @@ class Customers_Membership_List_Table extends Membership_List_Table { $products_list = $p ? sprintf(_n('Contains %s', 'Contains %1$s and %2$s other product(s)', $product_count, 'wp-ultimo'), $p->get_name(), count($item->get_addon_ids())) : ''; // phpcs:ignore - echo wu_responsive_table_row(array( - 'id' => $item->get_id(), - 'title' => $item->get_hash(), - 'url' => wu_network_admin_url('wp-ultimo-edit-membership', array( - 'id' => $item->get_id(), - )), - 'status' => $this->column_status($item), - ), array( - 'total' => array( - 'icon' => 'dashicons-wu-shopping-bag1 wu-align-middle wu-mr-1', - 'label' => __('Payment Total', 'wp-ultimo'), - 'value' => $item->get_price_description(), + echo wu_responsive_table_row( + array( + 'id' => $item->get_id(), + 'title' => $item->get_hash(), + 'url' => wu_network_admin_url( + 'wp-ultimo-edit-membership', + array( + 'id' => $item->get_id(), + ) + ), + 'status' => $this->column_status($item), ), - 'products' => array( - 'icon' => 'dashicons-wu-package wu-align-middle wu-mr-1', - 'label' => __('Products', 'wp-ultimo'), - 'value' => $products_list, + array( + 'total' => array( + 'icon' => 'dashicons-wu-shopping-bag1 wu-align-middle wu-mr-1', + 'label' => __('Payment Total', 'wp-ultimo'), + 'value' => $item->get_price_description(), + ), + 'products' => array( + 'icon' => 'dashicons-wu-package wu-align-middle wu-mr-1', + 'label' => __('Products', 'wp-ultimo'), + 'value' => $products_list, + ), + 'gateway' => array( + 'icon' => 'dashicons-wu-credit-card2 wu-align-middle wu-mr-1', + 'label' => __('Gateway', 'wp-ultimo'), + 'value' => wu_slug_to_name($item->get_gateway()), + ), ), - 'gateway' => array( - 'icon' => 'dashicons-wu-credit-card2 wu-align-middle wu-mr-1', - 'label' => __('Gateway', 'wp-ultimo'), - 'value' => wu_slug_to_name($item->get_gateway()), - ), - ), - array( - 'date_expiration' => array( - 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', - 'label' => __('Expires', 'wp-ultimo'), - 'value' => sprintf($expired ? __('Expired %s', 'wp-ultimo') : __('Expiring %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_expiration()))), - ), - 'date_created' => array( - 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', - 'label' => __('Created at', 'wp-ultimo'), - 'value' => sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_created()))), - ), - )); - - } // end column_responsive; - -} // end class Customers_Membership_List_Table; + array( + 'date_expiration' => array( + 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', + 'label' => __('Expires', 'wp-ultimo'), + 'value' => sprintf($expired ? __('Expired %s', 'wp-ultimo') : __('Expiring %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_expiration()))), + ), + 'date_created' => array( + 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', + 'label' => __('Created at', 'wp-ultimo'), + 'value' => sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_created()))), + ), + ) + ); + } +} diff --git a/inc/list-tables/class-customers-payment-list-table.php b/inc/list-tables/class-customers-payment-list-table.php index 771f968..7f39a32 100644 --- a/inc/list-tables/class-customers-payment-list-table.php +++ b/inc/list-tables/class-customers-payment-list-table.php @@ -32,8 +32,7 @@ class Customers_Payment_List_Table extends Payment_List_Table { ); return $columns; - - } // end get_columns; + } /** * Renders the inside column responsive. @@ -45,33 +44,37 @@ class Customers_Payment_List_Table extends Payment_List_Table { */ public function column_responsive($item) { - echo wu_responsive_table_row(array( - 'id' => $item->get_id(), - 'title' => $item->get_hash(), - 'url' => wu_network_admin_url('wp-ultimo-edit-payment', array( - 'id' => $item->get_id(), - )), - 'status' => $this->column_status($item), - ), array( - 'total' => array( - 'icon' => 'dashicons-wu-shopping-bag1 wu-align-middle wu-mr-1', - 'label' => __('Payment Total', 'wp-ultimo'), - 'value' => wu_format_currency($item->get_total()), + echo wu_responsive_table_row( + array( + 'id' => $item->get_id(), + 'title' => $item->get_hash(), + 'url' => wu_network_admin_url( + 'wp-ultimo-edit-payment', + array( + 'id' => $item->get_id(), + ) + ), + 'status' => $this->column_status($item), ), - 'gateway' => array( - 'icon' => 'dashicons-wu-credit-card2 wu-align-middle wu-mr-1', - 'label' => __('Gateway', 'wp-ultimo'), - 'value' => wu_slug_to_name($item->get_gateway()), + array( + 'total' => array( + 'icon' => 'dashicons-wu-shopping-bag1 wu-align-middle wu-mr-1', + 'label' => __('Payment Total', 'wp-ultimo'), + 'value' => wu_format_currency($item->get_total()), + ), + 'gateway' => array( + 'icon' => 'dashicons-wu-credit-card2 wu-align-middle wu-mr-1', + 'label' => __('Gateway', 'wp-ultimo'), + 'value' => wu_slug_to_name($item->get_gateway()), + ), ), - ), - array( - 'date_created' => array( - 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', - 'label' => '', - 'value' => sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_created()))), - ), - )); - - } // end column_responsive; - -} // end class Customers_Payment_List_Table; + array( + 'date_created' => array( + 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', + 'label' => '', + 'value' => sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_created()))), + ), + ) + ); + } +} diff --git a/inc/list-tables/class-customers-site-list-table.php b/inc/list-tables/class-customers-site-list-table.php index 5e3e242..026acb4 100644 --- a/inc/list-tables/class-customers-site-list-table.php +++ b/inc/list-tables/class-customers-site-list-table.php @@ -29,8 +29,7 @@ class Customers_Site_List_Table extends Site_List_Table { parent::__construct(); $this->current_mode = 'list'; - - } // end __construct; + } /** * Returns the list of columns for this particular List Table. @@ -45,8 +44,7 @@ class Customers_Site_List_Table extends Site_List_Table { ); return $columns; - - } // end get_columns; + } /** * Renders the inside column responsive. @@ -62,46 +60,54 @@ class Customers_Site_List_Table extends Site_List_Table { $redirect = current_user_can('wu_edit_sites') ? 'wp-ultimo-edit-site' : 'wp-ultimo-sites'; - echo wu_responsive_table_row(array( - 'id' => $item->get_id(), - 'title' => $item->get_title(), - 'url' => wu_network_admin_url($redirect, array( - 'id' => $item->get_id(), - )), - 'image' => $this->column_featured_image_id($item), - 'status' => $this->column_type($item), - ), array( - 'link' => array( - 'icon' => 'dashicons-wu-link1 wu-align-middle wu-mr-1', - 'label' => __('Visit Site', 'wp-ultimo'), - 'url' => $item->get_active_site_url(), - 'value' => $item->get_active_site_url(), + echo wu_responsive_table_row( + array( + 'id' => $item->get_id(), + 'title' => $item->get_title(), + 'url' => wu_network_admin_url( + $redirect, + array( + 'id' => $item->get_id(), + ) + ), + 'image' => $this->column_featured_image_id($item), + 'status' => $this->column_type($item), ), - 'dashboard' => array( - 'icon' => 'dashicons-wu-browser wu-align-middle wu-mr-1', - 'label' => __('Go to the Dashboard', 'wp-ultimo'), - 'value' => __('Dashboard', 'wp-ultimo'), - 'url' => get_admin_url($item->get_id()), + array( + 'link' => array( + 'icon' => 'dashicons-wu-link1 wu-align-middle wu-mr-1', + 'label' => __('Visit Site', 'wp-ultimo'), + 'url' => $item->get_active_site_url(), + 'value' => $item->get_active_site_url(), + ), + 'dashboard' => array( + 'icon' => 'dashicons-wu-browser wu-align-middle wu-mr-1', + 'label' => __('Go to the Dashboard', 'wp-ultimo'), + 'value' => __('Dashboard', 'wp-ultimo'), + 'url' => get_admin_url($item->get_id()), + ), + 'membership' => array( + 'icon' => 'dashicons-wu-rotate-ccw wu-align-middle wu-mr-1', + 'label' => __('Go to the Membership', 'wp-ultimo'), + 'value' => $m ? $m->get_hash() : '', + 'url' => $m ? wu_network_admin_url( + 'wp-ultimo-edit-membership', + array( + 'id' => $m->get_id(), + ) + ) : '', + ), ), - 'membership' => array( - 'icon' => 'dashicons-wu-rotate-ccw wu-align-middle wu-mr-1', - 'label' => __('Go to the Membership', 'wp-ultimo'), - 'value' => $m ? $m->get_hash() : '', - 'url' => $m ? wu_network_admin_url('wp-ultimo-edit-membership', array( - 'id' => $m->get_id(), - )) : '', - ), - ), - array( - 'date_created' => array( - 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', - 'label' => '', - /* translators: the placeholder is a date */ - 'value' => $item->get_type() === 'pending' ? __('Not Available', 'wp-ultimo') : sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_registered()))), - ), - )); - - } // end column_responsive; + array( + 'date_created' => array( + 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', + 'label' => '', + /* translators: the placeholder is a date */ + 'value' => $item->get_type() === 'pending' ? __('Not Available', 'wp-ultimo') : sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_registered()))), + ), + ) + ); + } /** * Overrides the parent method to add pending sites. @@ -118,10 +124,8 @@ class Customers_Site_List_Table extends Site_List_Table { $sites = parent::get_items($per_page, $page_number, $count); if ($count) { - return $sites; - - } // end if; + } $pending_sites = array(); @@ -129,14 +133,11 @@ class Customers_Site_List_Table extends Site_List_Table { $id = wu_request('id'); - if (!$id) { - + if ( ! $id) { return $sites; - - } // end if; + } switch ($page) { - case 'wp-ultimo-edit-membership': $membership = wu_get_membership($id); $pending_sites = $membership && $membership->get_pending_site() ? array($membership->get_pending_site()) : array(); @@ -145,18 +146,13 @@ class Customers_Site_List_Table extends Site_List_Table { $customer = wu_get_customer($id); $pending_sites = $customer ? $customer->get_pending_sites() : array(); break; - - } // end switch; + } foreach ($pending_sites as &$site) { - $site->set_type('pending'); $site->set_blog_id('--'); - - } // end foreach; + } return array_merge($pending_sites, $sites); - - } // end get_items; - -} // end class Customers_Site_List_Table; + } +} diff --git a/inc/list-tables/class-discount-code-list-table.php b/inc/list-tables/class-discount-code-list-table.php index 17e929e..c9cb7dd 100644 --- a/inc/list-tables/class-discount-code-list-table.php +++ b/inc/list-tables/class-discount-code-list-table.php @@ -34,17 +34,18 @@ class Discount_Code_List_Table extends Base_List_Table { */ public function __construct() { - parent::__construct(array( - 'singular' => __('Discount Code', 'wp-ultimo'), // singular name of the listed records - 'plural' => __('Discount Codes', 'wp-ultimo'), // plural name of the listed records - 'ajax' => true, // does this table support ajax? - 'add_new' => array( - 'url' => wu_network_admin_url('wp-ultimo-edit-discount-code'), - 'classes' => '', - ), - )); - - } // end __construct; + parent::__construct( + array( + 'singular' => __('Discount Code', 'wp-ultimo'), // singular name of the listed records + 'plural' => __('Discount Codes', 'wp-ultimo'), // plural name of the listed records + 'ajax' => true, // does this table support ajax? + 'add_new' => array( + 'url' => wu_network_admin_url('wp-ultimo-edit-discount-code'), + 'classes' => '', + ), + ) + ); + } /** * Displays the content of the name column. * @@ -75,8 +76,7 @@ class Discount_Code_List_Table extends Base_List_Table { ); return $title . $this->row_actions($actions); - - } // end column_name; + } /** * Displays the content of the value column. @@ -89,24 +89,19 @@ class Discount_Code_List_Table extends Base_List_Table { */ public function column_value($item) { - if (!$item->get_value()) { - + if ( ! $item->get_value()) { return __('No Discount', 'wp-ultimo'); - - } // end if; + } $value = wu_format_currency($item->get_value()); if ($item->get_type() === 'percentage') { - $value = number_format($item->get_value(), 0) . '%'; - - } // end if; + } // translators: placeholder is the amount of discount. e.g. 10% or $5. return sprintf(__('%s OFF', 'wp-ultimo'), $value); - - } // end column_value; + } /** * Displays the content of the setup fee value column. @@ -119,24 +114,19 @@ class Discount_Code_List_Table extends Base_List_Table { */ public function column_setup_fee_value($item) { - if (!$item->get_setup_fee_value()) { - + if ( ! $item->get_setup_fee_value()) { return __('No Discount', 'wp-ultimo'); - - } // end if; + } $value = wu_format_currency($item->get_setup_fee_value()); if ($item->get_setup_fee_type() === 'percentage') { - $value = number_format($item->get_setup_fee_value()) . '%'; - - } // end if; + } // translators: placeholder is the amount of discount. e.g. 10% or $5. return sprintf(__('%s OFF', 'wp-ultimo'), $value); - - } // end column_setup_fee_value; + } /** * Displays the use limitations. @@ -155,16 +145,12 @@ class Discount_Code_List_Table extends Base_List_Table { // translators: the placeholder is the number of times this coupon can be used before becoming inactive. $html .= '' . sprintf(__('Allowed uses: %d', 'wp-ultimo'), $item->get_max_uses()) . ''; - } else { - $html .= '' . __('No Limits', 'wp-ultimo') . ''; - - } // end if; + } return $html; - - } // end column_uses; + } /** * Shows the code as a tag. @@ -183,14 +169,11 @@ class Discount_Code_List_Table extends Base_List_Table { $valid = $item->is_valid(); if (is_wp_error($valid)) { - $html .= sprintf('%s', wu_tooltip_text($valid->get_error_message()), __('Inactive', 'wp-ultimo')); - - } // end if; + } return $html; - - } // end column_coupon_code; + } /** * Returns the list of columns for this particular List Table. @@ -211,8 +194,7 @@ class Discount_Code_List_Table extends Base_List_Table { ); return $columns; - - } // end get_columns; + } /** * Returns the filters for this page. * @@ -224,7 +206,5 @@ class Discount_Code_List_Table extends Base_List_Table { 'filters' => array(), 'date_filters' => array(), ); - - } // end get_filters; - -} // end class Discount_Code_List_Table; + } +} diff --git a/inc/list-tables/class-domain-list-table.php b/inc/list-tables/class-domain-list-table.php index fa0f72d..72d1f81 100644 --- a/inc/list-tables/class-domain-list-table.php +++ b/inc/list-tables/class-domain-list-table.php @@ -9,7 +9,7 @@ namespace WP_Ultimo\List_Tables; -use \WP_Ultimo\Models\Domain; +use WP_Ultimo\Models\Domain; use WP_Ultimo\Database\Domains\Domain_Stage; // Exit if accessed directly @@ -37,17 +37,18 @@ class Domain_List_Table extends Base_List_Table { */ public function __construct() { - parent::__construct(array( - 'singular' => __('Domain', 'wp-ultimo'), // singular name of the listed records - 'plural' => __('Domains', 'wp-ultimo'), // plural name of the listed records - 'ajax' => true, // does this table support ajax? - 'add_new' => array( - 'url' => wu_get_form_url('add_new_domain'), - 'classes' => 'wubox', - ), - )); - - } // end __construct; + parent::__construct( + array( + 'singular' => __('Domain', 'wp-ultimo'), // singular name of the listed records + 'plural' => __('Domains', 'wp-ultimo'), // plural name of the listed records + 'ajax' => true, // does this table support ajax? + 'add_new' => array( + 'url' => wu_get_form_url('add_new_domain'), + 'classes' => 'wubox', + ), + ) + ); + } /** * Adds the extra search field when the search element is present. @@ -60,14 +61,11 @@ class Domain_List_Table extends Base_List_Table { $_filter_fields = parent::get_extra_query_fields(); if (wu_request('blog_id')) { - $_filter_fields['blog_id'] = wu_request('blog_id'); - - } // end if; + } return $_filter_fields; - - } // end get_extra_query_fields; + } /** * Displays the content of the domain column. * @@ -92,8 +90,7 @@ class Domain_List_Table extends Base_List_Table { ); return $html . $this->row_actions($actions); - - } // end column_domain; + } /** * Displays the content of the active column. @@ -106,8 +103,7 @@ class Domain_List_Table extends Base_List_Table { public function column_active($item) { return $item->is_active() ? __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo'); - - } // end column_active; + } /** * Displays the content of the primary domain column. @@ -120,8 +116,7 @@ class Domain_List_Table extends Base_List_Table { public function column_primary_domain($item) { return $item->is_primary_domain() ? __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo'); - - } // end column_primary_domain; + } /** * Displays the content of the secure column. @@ -134,8 +129,7 @@ class Domain_List_Table extends Base_List_Table { public function column_secure($item) { return $item->is_secure() ? __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo'); - - } // end column_secure; + } /** * Returns the markup for the stage column. @@ -152,8 +146,7 @@ class Domain_List_Table extends Base_List_Table { $class = $item->get_stage_class(); return "{$label}"; - - } // end column_stage; + } /** * Returns the list of columns for this particular List Table. @@ -175,8 +168,7 @@ class Domain_List_Table extends Base_List_Table { ); return $columns; - - } // end get_columns; + } /** * Returns the filters for this page. * @@ -229,11 +221,7 @@ class Domain_List_Table extends Base_List_Table { ), ), - 'date_filters' => array( - - ), + 'date_filters' => array(), ); - - } // end get_filters; - -} // end class Domain_List_Table; + } +} diff --git a/inc/list-tables/class-email-list-table.php b/inc/list-tables/class-email-list-table.php index 3f0b291..0ce2318 100644 --- a/inc/list-tables/class-email-list-table.php +++ b/inc/list-tables/class-email-list-table.php @@ -20,11 +20,11 @@ defined('ABSPATH') || exit; class Email_List_Table extends Base_List_Table { /** - * Holds the query class for the object being listed. - * - * @since 2.0.0 - * @var string - */ + * Holds the query class for the object being listed. + * + * @since 2.0.0 + * @var string + */ protected $query_class = '\\WP_Ultimo\\Database\\Emails\\Email_Query'; /** @@ -34,17 +34,18 @@ class Email_List_Table extends Base_List_Table { */ public function __construct() { - parent::__construct(array( - 'singular' => __('Email', 'wp-ultimo'), // singular name of the listed records - 'plural' => __('Emails', 'wp-ultimo'), // plural name of the listed records - 'ajax' => true, // does this table support ajax? - 'add_new' => array( - 'url' => wu_network_admin_url('wp-ultimo-edit-email'), - 'classes' => '', - ), - )); - - } // end __construct; + parent::__construct( + array( + 'singular' => __('Email', 'wp-ultimo'), // singular name of the listed records + 'plural' => __('Emails', 'wp-ultimo'), // plural name of the listed records + 'ajax' => true, // does this table support ajax? + 'add_new' => array( + 'url' => wu_network_admin_url('wp-ultimo-edit-email'), + 'classes' => '', + ), + ) + ); + } /** * Overrides the parent method to add pending sites. @@ -67,29 +68,24 @@ class Email_List_Table extends Base_List_Table { $search = wu_request('s'); if ($search) { - $query['search'] = $search; - - } // end if; + } $target = wu_request('target'); if ($target && $target !== 'all') { - $query['meta_query'] = array( 'type' => array( 'key' => 'wu_target', 'value' => $target, ), ); - - } // end if; + } $query = apply_filters("wu_{$this->id}_get_items", $query, $this); return wu_get_emails($query); - - } // end get_items; + } /** * Displays the title of the email. * @@ -101,7 +97,7 @@ class Email_List_Table extends Base_List_Table { $url_atts = array( 'id' => $item->get_id(), - 'model' => 'email' + 'model' => 'email', ); $title = sprintf('%s', wu_network_admin_url('wp-ultimo-edit-email', $url_atts), $item->get_title()); @@ -115,24 +111,21 @@ class Email_List_Table extends Base_List_Table { $actions = array( 'edit' => sprintf('%s', wu_network_admin_url('wp-ultimo-edit-email', $url_atts), __('Edit', 'wp-ultimo')), 'duplicate' => sprintf('%s', wu_network_admin_url('wp-ultimo-edit-email', $url_atts), __('Duplicate', 'wp-ultimo')), - 'send-test' => sprintf('%s', __('Send Test Email', 'wp-ultimo'), wu_get_form_url('send_new_test', $url_atts), __('Send Test Email', 'wp-ultimo')) + 'send-test' => sprintf('%s', __('Send Test Email', 'wp-ultimo'), wu_get_form_url('send_new_test', $url_atts), __('Send Test Email', 'wp-ultimo')), ); $slug = $item->get_slug(); $default_system_emails = wu_get_default_system_emails(); - if (isset($default_system_emails[$slug])) { - + if (isset($default_system_emails[ $slug ])) { $actions['reset'] = sprintf('%s', __('Reset', 'wp-ultimo'), wu_get_form_url('reset_confirmation', $url_atts), __('Reset', 'wp-ultimo')); - - } // end if; + } $actions['delete'] = sprintf('%s', __('Delete', 'wp-ultimo'), wu_get_form_url('delete_modal', $url_atts), __('Delete', 'wp-ultimo')); return $title . $content . $this->row_actions($actions); - - } // end column_title; + } /** * Displays the event of the email. @@ -147,8 +140,7 @@ class Email_List_Table extends Base_List_Table { $event = $item->get_event(); return "{$event}"; - - } // end column_event; + } /** * Displays the slug of the email. @@ -163,8 +155,7 @@ class Email_List_Table extends Base_List_Table { $slug = $item->get_slug(); return "{$slug}"; - - } // end column_slug; + } /** * Displays if the email is schedule for later send or not. @@ -177,28 +168,19 @@ class Email_List_Table extends Base_List_Table { public function column_schedule($item) { if ($item->has_schedule()) { - if ($item->get_schedule_type() === 'hours') { - $time = explode(':', (string) $item->get_send_hours()); $text = sprintf(__('%1$s hour(s) and %2$s minute(s) after the event.', 'wp-ultimo'), $time[0], $time[1]); - } elseif ($item->get_schedule_type() === 'days') { - $text = sprintf(__('%s day(s) after the event.', 'wp-ultimo'), $item->get_send_days()); - - } // end if; - + } } else { - $text = __('Sent immediately after the event.', 'wp-ultimo'); - - } // end if; + } return $text; - - } // end column_schedule; + } /** * Returns the list of columns for this particular List Table. @@ -218,10 +200,9 @@ class Email_List_Table extends Base_List_Table { ); return $columns; + } - } // end get_columns; - - /** + /** * Handles the bulk processing adding duplication. * * @since 2.0.0 @@ -232,18 +213,15 @@ class Email_List_Table extends Base_List_Table { $bulk_action = $this->current_action(); if ($bulk_action === 'duplicate') { - $email_id = wu_request('id'); $email = wu_get_email($email_id); - if (!$email) { - + if ( ! $email) { WP_Ultimo()->notices->add(__('Email not found.', 'wp-ultimo'), 'error', 'network-admin'); return; - - } // end if; + } $new_email = $email->duplicate(); @@ -260,30 +238,22 @@ class Email_List_Table extends Base_List_Table { $new_email->set_event($email->get_event()); if ($email->has_schedule()) { - $new_email->set_schedule($email->has_schedule()); if ($email->get_schedule_type() === 'hours') { - $new_email->set_send_hours($email->get_send_hours()); - } elseif ($email->get_schedule_type() === 'days') { - $new_email->set_send_days($email->get_send_days()); - - } // end if; - - } // end if; + } + } if ($email->get_custom_sender()) { - $new_email->set_custom_sender($email->get_custom_sender()); $new_email->set_custom_sender_name($email->get_custom_sender_name()); $new_email->set_custom_sender_email($email->get_custom_sender_email()); - - } // end if; + } $new_email->set_send_copy_to_admin($email->get_send_copy_to_admin()); @@ -292,25 +262,24 @@ class Email_List_Table extends Base_List_Table { $result = $new_email->save(); if (is_wp_error($result)) { - WP_Ultimo()->notices->add($result->get_error_message(), 'error', 'network-admin'); return; + } - } // end if; - - $redirect_url = wu_network_admin_url('wp-ultimo-edit-email', array( - 'id' => $new_email->get_id(), - 'updated' => 1, - )); + $redirect_url = wu_network_admin_url( + 'wp-ultimo-edit-email', + array( + 'id' => $new_email->get_id(), + 'updated' => 1, + ) + ); wp_redirect($redirect_url); exit; - - } // end if; - - } // end process_single_action; + } + } /** * Returns the filters for this page. * @@ -335,8 +304,7 @@ class Email_List_Table extends Base_List_Table { ), ), ); - - } // end get_filters; + } /** * Returns the pre-selected filters on the filter bar. @@ -366,7 +334,5 @@ class Email_List_Table extends Base_List_Table { 'count' => 0, ), ); - - } // end get_views; - -} // end class Email_List_Table; + } +} diff --git a/inc/list-tables/class-event-list-table.php b/inc/list-tables/class-event-list-table.php index 3aa5667..3bf48d1 100644 --- a/inc/list-tables/class-event-list-table.php +++ b/inc/list-tables/class-event-list-table.php @@ -9,7 +9,7 @@ namespace WP_Ultimo\List_Tables; -use \WP_Ultimo\Models\Event; +use WP_Ultimo\Models\Event; // Exit if accessed directly defined('ABSPATH') || exit; @@ -36,13 +36,14 @@ class Event_List_Table extends Base_List_Table { */ public function __construct() { - parent::__construct(array( - 'singular' => __('Event', 'wp-ultimo'), // singular name of the listed records - 'plural' => __('Events', 'wp-ultimo'), // plural name of the listed records - 'ajax' => true // does this table support ajax? - )); - - } // end __construct; + parent::__construct( + array( + 'singular' => __('Event', 'wp-ultimo'), // singular name of the listed records + 'plural' => __('Events', 'wp-ultimo'), // plural name of the listed records + 'ajax' => true, // does this table support ajax? + ) + ); + } /** * Returns the markup for the object_type column. @@ -57,8 +58,7 @@ class Event_List_Table extends Base_List_Table { $object_type = $item->get_object_type(); return "{$object_type}"; - - } // end column_object_type; + } /** * Returns the markup for the initiator column. @@ -79,7 +79,6 @@ class Event_List_Table extends Base_List_Table { $object_label_tooltip = substr($object_severity_label, 0, 1); if ($object_initiator === 'system') { - $avatar = ''; $system_text = ucfirst($object_initiator); @@ -98,13 +97,17 @@ class Event_List_Table extends Base_List_Table { "; // phpcs:enable - } elseif ($object_initiator === 'manual') { - - $avatar = get_avatar($item->get_author_id(), 32, 'identicon', '', array( - 'force_display' => true, - 'class' => 'wu-rounded-full', - )); + $avatar = get_avatar( + $item->get_author_id(), + 32, + 'identicon', + '', + array( + 'force_display' => true, + 'class' => 'wu-rounded-full', + ) + ); $display_name = $item->get_author_display_name(); @@ -133,9 +136,7 @@ class Event_List_Table extends Base_List_Table { {$email} "; - } else { - $not_found = __('No initiator found', 'wp-ultimo'); $html = "
    @@ -144,12 +145,10 @@ class Event_List_Table extends Base_List_Table { {$not_found}
    "; - - } // end if; + } return $html; - - } // end column_initiator; + } /** * Returns the markup for the initiator column. @@ -164,8 +163,7 @@ class Event_List_Table extends Base_List_Table { $object_slug = $item->get_slug(); return "{$object_slug}"; - - } // end column_slug; + } /** * Returns the markup for the message column. * @@ -179,7 +177,7 @@ class Event_List_Table extends Base_List_Table { $url_atts = array( 'id' => $item->get_id(), - 'model' => 'event' + 'model' => 'event', ); $actions = array( @@ -196,8 +194,7 @@ class Event_List_Table extends Base_List_Table { ); return $message . $this->row_actions($actions); - - } // end column_message; + } /** * Returns the list of columns for this particular List Table. @@ -218,8 +215,7 @@ class Event_List_Table extends Base_List_Table { ); return apply_filters('wu_events_list_table_get_columns', $columns, $this); - - } // end get_columns; + } /** * Returns the filters for this page. * @@ -247,7 +243,5 @@ class Event_List_Table extends Base_List_Table { ), ), ); - - } // end get_filters; - -} // end class Event_List_Table; + } +} diff --git a/inc/list-tables/class-inside-events-list-table.php b/inc/list-tables/class-inside-events-list-table.php index c19fc37..21ae48e 100644 --- a/inc/list-tables/class-inside-events-list-table.php +++ b/inc/list-tables/class-inside-events-list-table.php @@ -32,8 +32,7 @@ class Inside_Events_List_Table extends Event_List_Table { ); return $columns; - - } // end get_columns; + } /** * Renders the inside column responsive. @@ -61,39 +60,44 @@ class Inside_Events_List_Table extends Event_List_Table { $object_initiator = $item->get_initiator(); if ($object_initiator === 'system') { - $value = sprintf('%s', __('Automatically processed by WP Multisite WaaS', 'wp-ultimo')); - } elseif ($object_initiator === 'manual') { - - $avatar = get_avatar($item->get_author_id(), 16, 'identicon', '', array( - 'force_display' => true, - 'class' => 'wu-rounded-full wu-mr-1 wu-align-text-bottom', - )); + $avatar = get_avatar( + $item->get_author_id(), + 16, + 'identicon', + '', + array( + 'force_display' => true, + 'class' => 'wu-rounded-full wu-mr-1 wu-align-text-bottom', + ) + ); $display_name = $item->get_author_display_name(); $value = sprintf('%s%s', $avatar, $display_name); + } - } // end if; - - echo wu_responsive_table_row(array( - 'id' => '', - 'title' => sprintf('%s', wp_trim_words($item->get_message(), 15)), - 'url' => wu_network_admin_url('wp-ultimo-view-event', array( - 'id' => $item->get_id(), - )), - 'status' => $value, - ), - $first_row, - array( - 'date_created' => array( - 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', - 'label' => '', - 'value' => sprintf(__('Processed %s', 'wp-ultimo'), wu_human_time_diff($item->get_date_created(), '-1 day')), + echo wu_responsive_table_row( + array( + 'id' => '', + 'title' => sprintf('%s', wp_trim_words($item->get_message(), 15)), + 'url' => wu_network_admin_url( + 'wp-ultimo-view-event', + array( + 'id' => $item->get_id(), + ) + ), + 'status' => $value, ), - )); - - } // end column_responsive; - -} // end class Inside_Events_List_Table; + $first_row, + array( + 'date_created' => array( + 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', + 'label' => '', + 'value' => sprintf(__('Processed %s', 'wp-ultimo'), wu_human_time_diff($item->get_date_created(), '-1 day')), + ), + ) + ); + } +} diff --git a/inc/list-tables/class-line-item-list-table.php b/inc/list-tables/class-line-item-list-table.php index 2a0cc0b..ac68d6d 100644 --- a/inc/list-tables/class-line-item-list-table.php +++ b/inc/list-tables/class-line-item-list-table.php @@ -34,13 +34,14 @@ class Line_Item_List_Table extends Payment_List_Table { */ public function __construct() { - parent::__construct(array( - 'singular' => __('Line Item', 'wp-ultimo'), // singular name of the listed records - 'plural' => __('Line Items', 'wp-ultimo'), // plural name of the listed records - 'ajax' => true // does this table support ajax? - )); - - } // end __construct; + parent::__construct( + array( + 'singular' => __('Line Item', 'wp-ultimo'), // singular name of the listed records + 'plural' => __('Line Items', 'wp-ultimo'), // plural name of the listed records + 'ajax' => true, // does this table support ajax? + ) + ); + } /** * Get the payment object. @@ -53,8 +54,7 @@ class Line_Item_List_Table extends Payment_List_Table { $payment_id = wu_request('id'); return wu_get_payment($payment_id); - - } // end get_payment; + } /** * Overrides the parent get_items to add a total line. @@ -73,14 +73,11 @@ class Line_Item_List_Table extends Payment_List_Table { $items = $payment->get_line_items(); if ($count) { - return count($items); - - } // end if; + } return $items; - - } // end get_items; + } /** * Displays the name of the product and description being hired. @@ -92,11 +89,9 @@ class Line_Item_List_Table extends Payment_List_Table { */ public function column_service($item) { - if (!$item) { - + if ( ! $item) { return '--'; - - } // end if; + } $url_atts = array( 'id' => $this->get_payment()->get_id(), @@ -113,8 +108,7 @@ class Line_Item_List_Table extends Payment_List_Table { $html .= sprintf('%s', $item->get_description()); return $html . $this->row_actions($actions); - - } // end column_service; + } /** * Displays the tax rate for the item. @@ -131,8 +125,7 @@ class Line_Item_List_Table extends Payment_List_Table { $quantity = sprintf(__('Quantity: %s', 'wp-ultimo'), $item->get_quantity()); // phpcs:ignore return $html . sprintf('%s', $quantity); - - } // end column_unit_price; + } /** * Displays the tax rate for the item. @@ -149,16 +142,13 @@ class Line_Item_List_Table extends Payment_List_Table { $tax_rate = ''; if ($item->get_tax_type() === 'percentage' && $item->get_tax_rate()) { - $tax_rate = $item->get_tax_rate() . '%'; - - } // end if; + } $tax_label = $item->get_tax_rate() ? ($item->get_tax_label() ? $item->get_tax_label() : __('Tax Applied', 'wp-ultimo')) : __('No Taxes Applied', 'wp-ultimo'); return $html . sprintf('%s (%s)', $tax_rate, $tax_label); - - } // end column_tax_total; + } /** * Displays the tax rate for the item. @@ -175,16 +165,13 @@ class Line_Item_List_Table extends Payment_List_Table { $tax_rate = ''; if ($item->get_discount_type() === 'percentage' && $item->get_discount_rate()) { - $tax_rate = $item->get_discount_rate() . '%'; - - } // end if; + } $tax_label = $item->get_discount_rate() ? ($item->get_discount_label() ? $item->get_discount_label() : __('Discount', 'wp-ultimo')) : __('No discount', 'wp-ultimo'); return $html . sprintf('%s (%s)', $tax_rate, $tax_label); - - } // end column_discounts_total; + } /** * Displays the total column. @@ -197,8 +184,7 @@ class Line_Item_List_Table extends Payment_List_Table { public function column_total($item) { return wu_format_currency($item->get_total()); - - } // end column_total; + } /** * Displays the subtotal column. @@ -211,8 +197,7 @@ class Line_Item_List_Table extends Payment_List_Table { public function column_subtotal($item) { return wu_format_currency($item->get_subtotal()); - - } // end column_subtotal; + } /** * Returns the list of columns for this particular List Table. @@ -232,8 +217,7 @@ class Line_Item_List_Table extends Payment_List_Table { ); return $columns; - - } // end get_columns; + } /** * Leaves no sortable items on the columns. @@ -244,7 +228,5 @@ class Line_Item_List_Table extends Payment_List_Table { public function get_sortable_columns() { return array(); - - } // end get_sortable_columns; - -} // end class Line_Item_List_Table; + } +} diff --git a/inc/list-tables/class-membership-line-item-list-table.php b/inc/list-tables/class-membership-line-item-list-table.php index 30cab18..cd94848 100644 --- a/inc/list-tables/class-membership-line-item-list-table.php +++ b/inc/list-tables/class-membership-line-item-list-table.php @@ -32,8 +32,7 @@ class Membership_Line_Item_List_Table extends Product_List_Table { ); return $columns; - - } // end get_columns; + } /** * Overrides the parent get_items to add a total line. @@ -52,14 +51,11 @@ class Membership_Line_Item_List_Table extends Product_List_Table { $products = $membership->get_all_products(); if ($count) { - return count($products); - - } // end if; + } return $products; - - } // end get_items; + } /** * Renders the inside column responsive. @@ -77,25 +73,26 @@ class Membership_Line_Item_List_Table extends Product_List_Table { $item = $item['product']; - if (!$item) { - - echo wu_responsive_table_row(array( - 'url' => false, - 'id' => 'not-found', - 'title' => __('Product not found', 'wp-ultimo'), - 'status' => '', - 'image' => $this->column_featured_image_id(new \WP_Ultimo\Models\Product()), - ), array( - 'quantity' => array( - 'icon' => 'dashicons-wu-package wu-align-middle wu-mr-1', - 'label' => __('Quantity', 'wp-ultimo'), - 'value' => sprintf(__('x%d', 'wp-ultimo'), $quantity), + if ( ! $item) { + echo wu_responsive_table_row( + array( + 'url' => false, + 'id' => 'not-found', + 'title' => __('Product not found', 'wp-ultimo'), + 'status' => '', + 'image' => $this->column_featured_image_id(new \WP_Ultimo\Models\Product()), ), - )); + array( + 'quantity' => array( + 'icon' => 'dashicons-wu-package wu-align-middle wu-mr-1', + 'label' => __('Quantity', 'wp-ultimo'), + 'value' => sprintf(__('x%d', 'wp-ultimo'), $quantity), + ), + ) + ); return; - - } // end if; + } $first_row = array( 'quantity' => array( @@ -119,46 +116,50 @@ class Membership_Line_Item_List_Table extends Product_List_Table { ); if ($item->get_type() === 'plan') { - $first_row['change'] = array( 'wrapper_classes' => 'wubox', 'icon' => 'dashicons-wu-edit1 wu-align-middle wu-mr-1', 'label' => '', 'value' => __('Upgrade or Downgrade', 'wp-ultimo'), - 'url' => wu_get_form_url('change_membership_plan', array( - 'id' => $membership_id, - 'product_id' => $item->get_id(), - )), + 'url' => wu_get_form_url( + 'change_membership_plan', + array( + 'id' => $membership_id, + 'product_id' => $item->get_id(), + ) + ), ); - } else { - $first_row['remove'] = array( 'wrapper_classes' => 'wu-text-red-500 wubox', 'icon' => 'dashicons-wu-trash-2 wu-align-middle wu-mr-1', 'label' => '', 'value' => __('Remove', 'wp-ultimo'), - 'url' => wu_get_form_url('remove_membership_product', array( - 'id' => $membership_id, - 'product_id' => $item->get_id(), - )), + 'url' => wu_get_form_url( + 'remove_membership_product', + array( + 'id' => $membership_id, + 'product_id' => $item->get_id(), + ) + ), ); + } - } // end if; - - echo wu_responsive_table_row(array( - 'id' => $item->get_id(), - 'title' => $item->get_name(), - 'url' => wu_network_admin_url('wp-ultimo-edit-product', array( - 'id' => $item->get_id(), - )), - 'image' => $this->column_featured_image_id($item), - 'status' => $this->column_type($item), - ), - $first_row, - $second_row + echo wu_responsive_table_row( + array( + 'id' => $item->get_id(), + 'title' => $item->get_name(), + 'url' => wu_network_admin_url( + 'wp-ultimo-edit-product', + array( + 'id' => $item->get_id(), + ) + ), + 'image' => $this->column_featured_image_id($item), + 'status' => $this->column_type($item), + ), + $first_row, + $second_row ); - - } // end column_responsive; - -} // end class Membership_Line_Item_List_Table; + } +} diff --git a/inc/list-tables/class-membership-list-table-widget.php b/inc/list-tables/class-membership-list-table-widget.php index a4d9710..2c56a00 100644 --- a/inc/list-tables/class-membership-list-table-widget.php +++ b/inc/list-tables/class-membership-list-table-widget.php @@ -12,7 +12,7 @@ namespace WP_Ultimo\List_Tables; // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Helpers\Hash; +use WP_Ultimo\Helpers\Hash; /** * Membership List Table class. @@ -22,11 +22,11 @@ use \WP_Ultimo\Helpers\Hash; class Membership_List_Table_Widget extends Base_List_Table { /** - * Holds the query class for the object being listed. - * - * @since 2.0.0 - * @var string - */ + * Holds the query class for the object being listed. + * + * @since 2.0.0 + * @var string + */ protected $query_class = '\\WP_Ultimo\\Database\\Memberships\\Membership_Query'; /** @@ -36,13 +36,14 @@ class Membership_List_Table_Widget extends Base_List_Table { */ public function __construct() { - parent::__construct(array( - 'singular' => __('Membership', 'wp-ultimo'), // singular name of the listed records - 'plural' => __('Memberships', 'wp-ultimo'), // plural name of the listed records - 'ajax' => true // does this table support ajax? - )); - - } // end __construct; + parent::__construct( + array( + 'singular' => __('Membership', 'wp-ultimo'), // singular name of the listed records + 'plural' => __('Memberships', 'wp-ultimo'), // plural name of the listed records + 'ajax' => true, // does this table support ajax? + ) + ); + } /** * Uses the query class to return the items to be displayed. @@ -71,18 +72,14 @@ class Membership_List_Table_Widget extends Base_List_Table { * Accounts for hashes */ if (isset($query_args['search']) && strlen((string) $query_args['search']) === Hash::LENGTH) { - $item_id = Hash::decode($query_args['search']); if ($item_id) { - unset($query_args['search']); $query_args['id'] = $item_id; - - } // end if; - - } // end if; + } + } $query_args = array_merge($query_args, $this->get_extra_query_fields()); @@ -91,18 +88,13 @@ class Membership_List_Table_Widget extends Base_List_Table { $function_name = 'wu_get_' . $query_class->get_plural_name(); if (function_exists($function_name)) { - $query = $function_name($query_args); - } else { - $query = $query_class->query($query_args); - - } // end if; + } return $query; - - } // end get_items; + } /** * Adds the extra search field when the search element is present. @@ -119,8 +111,7 @@ class Membership_List_Table_Widget extends Base_List_Table { $_filter_fields['customer_id'] = wu_request('customer_id'); return $_filter_fields; - - } // end get_extra_query_fields; + } /** * Displays the membership reference code. * @@ -144,8 +135,7 @@ class Membership_List_Table_Widget extends Base_List_Table { $html = "{$code}"; return $html . $this->row_actions($actions); - - } // end column_hash; + } /** * Displays the status of the membership. @@ -162,8 +152,7 @@ class Membership_List_Table_Widget extends Base_List_Table { $class = $item->get_status_class(); return "{$label}"; - - } // end column_status; + } /** * Displays the price of the membership. @@ -176,15 +165,12 @@ class Membership_List_Table_Widget extends Base_List_Table { public function column_amount($item) { if (empty($item->get_amount())) { - return __('Free', 'wp-ultimo'); - - } // end if; + } $amount = wu_format_currency($item->get_amount(), $item->get_currency()); if ($item->is_recurring()) { - $duration = $item->get_duration(); $message = sprintf( @@ -194,8 +180,7 @@ class Membership_List_Table_Widget extends Base_List_Table { $item->get_duration_unit() ); - if (!$item->is_forever_recurring()) { - + if ( ! $item->is_forever_recurring()) { $billing_cycles_message = sprintf( // translators: %s is the number of billing cycles. _n('for %s cycle', 'for %s cycles', $item->get_billing_cycles(), 'wp-ultimo'), @@ -203,18 +188,13 @@ class Membership_List_Table_Widget extends Base_List_Table { ); $message .= ' ' . $billing_cycles_message; - - } // end if; - + } } else { - $message = __('one time payment', 'wp-ultimo'); - - } // end if; + } return sprintf('%s
    %s', $amount, $message); - - } // end column_amount; + } /** * Displays the customer of the membership. @@ -228,8 +208,7 @@ class Membership_List_Table_Widget extends Base_List_Table { $customer = $item->get_customer(); - if (!$customer) { - + if ( ! $customer) { $not_found = __('No customer found', 'wp-ultimo'); return "
    @@ -238,17 +217,22 @@ class Membership_List_Table_Widget extends Base_List_Table { {$not_found}
    "; - - } // end if; + } $url_atts = array( 'id' => $customer->get_id(), ); - $avatar = get_avatar($customer->get_user_id(), 32, 'identicon', '', array( - 'force_display' => true, - 'class' => 'wu-rounded-full wu-mr-2', - )); + $avatar = get_avatar( + $customer->get_user_id(), + 32, + 'identicon', + '', + array( + 'force_display' => true, + 'class' => 'wu-rounded-full wu-mr-2', + ) + ); $display_name = $customer->get_display_name(); @@ -266,8 +250,7 @@ class Membership_List_Table_Widget extends Base_List_Table { "; return $html; - - } // end column_customer; + } /** * Returns the list of columns for this particular List Table. @@ -285,14 +268,12 @@ class Membership_List_Table_Widget extends Base_List_Table { ); return $columns; - - } // end get_columns; + } /** * Overrides the parent method to include the custom ajax functionality for WP Multisite WaaS. * * @since 2.0.0 * @return void */ - public function _js_vars() {} // end _js_vars; - -} // end class Membership_List_Table_Widget; + public function _js_vars() {} +} diff --git a/inc/list-tables/class-membership-list-table.php b/inc/list-tables/class-membership-list-table.php index 932b1f3..d4f2bde 100644 --- a/inc/list-tables/class-membership-list-table.php +++ b/inc/list-tables/class-membership-list-table.php @@ -34,17 +34,18 @@ class Membership_List_Table extends Base_List_Table { */ public function __construct() { - parent::__construct(array( - 'singular' => __('Membership', 'wp-ultimo'), // singular name of the listed records - 'plural' => __('Memberships', 'wp-ultimo'), // plural name of the listed records - 'ajax' => true, // does this table support ajax? - 'add_new' => array( - 'url' => wu_get_form_url('add_new_membership'), - 'classes' => 'wubox', - ), - )); - - } // end __construct; + parent::__construct( + array( + 'singular' => __('Membership', 'wp-ultimo'), // singular name of the listed records + 'plural' => __('Memberships', 'wp-ultimo'), // plural name of the listed records + 'ajax' => true, // does this table support ajax? + 'add_new' => array( + 'url' => wu_get_form_url('add_new_membership'), + 'classes' => 'wubox', + ), + ) + ); + } /** * Adds the extra search field when the search element is present. @@ -61,8 +62,7 @@ class Membership_List_Table extends Base_List_Table { $_filter_fields['customer_id'] = wu_request('customer_id'); return $_filter_fields; - - } // end get_extra_query_fields; + } /** * Displays the membership reference code. @@ -97,8 +97,7 @@ class Membership_List_Table extends Base_List_Table { $html = "{$code}"; return $html . $this->row_actions($actions); - - } // end column_hash; + } /** * Displays the status of the membership. @@ -117,8 +116,7 @@ class Membership_List_Table extends Base_List_Table { $html = "{$label}"; return $html; - - } // end column_status; + } /** * Displays the price of the membership. @@ -131,13 +129,10 @@ class Membership_List_Table extends Base_List_Table { public function column_amount($item) { if (empty($item->get_amount()) && empty($item->get_initial_amount())) { - return __('Free', 'wp-ultimo'); - - } // end if; + } if ($item->is_recurring()) { - $amount = wu_format_currency($item->get_amount(), $item->get_currency()); $duration = $item->get_duration(); @@ -149,8 +144,7 @@ class Membership_List_Table extends Base_List_Table { $item->get_duration_unit() ); - if (!$item->is_forever_recurring()) { - + if ( ! $item->is_forever_recurring()) { $billing_cycles_message = sprintf( // translators: %s is the number of billing cycles. _n('for %s cycle', 'for %s cycles', $item->get_billing_cycles(), 'wp-ultimo'), @@ -158,20 +152,15 @@ class Membership_List_Table extends Base_List_Table { ); $message .= ' ' . $billing_cycles_message; - - } // end if; - + } } else { - $amount = wu_format_currency($item->get_initial_amount(), $item->get_currency()); $message = __('one time payment', 'wp-ultimo'); - - } // end if; + } return sprintf('%s
    %s', $amount, $message); - - } // end column_amount; + } /** * Returns the list of columns for this particular List Table. @@ -195,8 +184,7 @@ class Membership_List_Table extends Base_List_Table { ); return $columns; - - } // end get_columns; + } /** * Handles the default displaying of datetime columns. @@ -211,16 +199,12 @@ class Membership_List_Table extends Base_List_Table { $date = $item->get_date_expiration(); if (empty($date) || $date === '0000-00-00 00:00:00') { - return sprintf('%s
    %s', __('Lifetime', 'wp-ultimo'), __('It never expires', 'wp-ultimo')); + } - } // end if; - - if (!wu_validate_date($date)) { - + if ( ! wu_validate_date($date)) { return __('--', 'wp-ultimo'); - - } // end if; + } $time = strtotime(get_date_from_gmt($date)); @@ -231,8 +215,7 @@ class Membership_List_Table extends Base_List_Table { $text = $formatted_value . sprintf('
    %s', sprintf($placeholder, human_time_diff($time))); return sprintf('%s', wu_tooltip_text(date_i18n('Y-m-d H:i:s', $time)), $text); - - } // end column_date_expiration; + } /** * Returns the filters for this page. @@ -250,7 +233,7 @@ class Membership_List_Table extends Base_List_Table { * Status */ 'status' => array( - 'label' => __( 'Status', 'wp-ultimo' ), + 'label' => __('Status', 'wp-ultimo'), 'options' => $membership_status::to_array(), ), @@ -282,8 +265,7 @@ class Membership_List_Table extends Base_List_Table { ), ), ); - - } // end get_filters; + } /** * Returns the pre-selected filters on the filter bar. @@ -337,7 +319,5 @@ class Membership_List_Table extends Base_List_Table { 'count' => 0, ), ); - - } // end get_views; - -} // end class Membership_List_Table; + } +} diff --git a/inc/list-tables/class-memberships-site-list-table.php b/inc/list-tables/class-memberships-site-list-table.php index 3f92594..64d7140 100644 --- a/inc/list-tables/class-memberships-site-list-table.php +++ b/inc/list-tables/class-memberships-site-list-table.php @@ -32,8 +32,7 @@ class Memberships_Site_List_Table extends Customers_Site_List_Table { ); return $columns; - - } // end get_columns; + } /** * Renders the inside column responsive. @@ -47,36 +46,40 @@ class Memberships_Site_List_Table extends Customers_Site_List_Table { $redirect = current_user_can('wu_edit_sites') ? 'wp-ultimo-edit-site' : 'wp-ultimo-sites'; - echo wu_responsive_table_row(array( - 'id' => $item->get_id(), - 'title' => $item->get_title(), - 'url' => wu_network_admin_url($redirect, array( - 'id' => $item->get_id(), - )), - 'image' => $this->column_featured_image_id($item), - 'status' => $this->column_type($item), - ), array( - 'link' => array( - 'icon' => 'dashicons-wu-link1 wu-align-middle wu-mr-1', - 'label' => __('Visit Site', 'wp-ultimo'), - 'value' => __('Homepage', 'wp-ultimo'), - 'url' => $item->get_active_site_url(), + echo wu_responsive_table_row( + array( + 'id' => $item->get_id(), + 'title' => $item->get_title(), + 'url' => wu_network_admin_url( + $redirect, + array( + 'id' => $item->get_id(), + ) + ), + 'image' => $this->column_featured_image_id($item), + 'status' => $this->column_type($item), ), - 'dashboard' => array( - 'icon' => 'dashicons-wu-browser wu-align-middle wu-mr-1', - 'label' => __('Go to the Dashboard', 'wp-ultimo'), - 'value' => __('Dashboard', 'wp-ultimo'), - 'url' => get_admin_url($item->get_id()), + array( + 'link' => array( + 'icon' => 'dashicons-wu-link1 wu-align-middle wu-mr-1', + 'label' => __('Visit Site', 'wp-ultimo'), + 'value' => __('Homepage', 'wp-ultimo'), + 'url' => $item->get_active_site_url(), + ), + 'dashboard' => array( + 'icon' => 'dashicons-wu-browser wu-align-middle wu-mr-1', + 'label' => __('Go to the Dashboard', 'wp-ultimo'), + 'value' => __('Dashboard', 'wp-ultimo'), + 'url' => get_admin_url($item->get_id()), + ), ), - ), - array( - 'date_created' => array( - 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', - 'label' => '', - 'value' => $item->get_type() === 'pending' ? __('Not Available', 'wp-ultimo') : sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_registered()))), - ), - )); - - } // end column_responsive; - -} // end class Memberships_Site_List_Table; + array( + 'date_created' => array( + 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', + 'label' => '', + 'value' => $item->get_type() === 'pending' ? __('Not Available', 'wp-ultimo') : sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_registered()))), + ), + ) + ); + } +} diff --git a/inc/list-tables/class-payment-line-item-list-table.php b/inc/list-tables/class-payment-line-item-list-table.php index e1a1b38..f7eeeaa 100644 --- a/inc/list-tables/class-payment-line-item-list-table.php +++ b/inc/list-tables/class-payment-line-item-list-table.php @@ -32,8 +32,7 @@ class Payment_Line_Item_List_Table extends Line_Item_List_Table { ); return $columns; - - } // end get_columns; + } /** * Renders the inside column responsive. @@ -83,16 +82,13 @@ class Payment_Line_Item_List_Table extends Line_Item_List_Table { 'url' => wu_get_form_url('delete_line_item', $url_atts), ); - /* - * Adds discounts - */ + /* + * Adds discounts + */ if ($item->get_discount_total()) { - if ($item->get_discount_type() === 'percentage' && $item->get_discount_rate()) { - $tax_rate = $item->get_discount_rate() . '%'; - - } // end if; + } $tax_label = $item->get_discount_rate() ? ($item->get_discount_label() ? $item->get_discount_label() : __('Discount', 'wp-ultimo')) : __('No discount', 'wp-ultimo'); @@ -103,8 +99,7 @@ class Payment_Line_Item_List_Table extends Line_Item_List_Table { 'label' => $tooltip, 'value' => sprintf(__('Discounts: %s', 'wp-ultimo'), wu_format_currency($item->get_discount_total())), ); - - } // end if; + } $first_row['subtotal'] = array( 'icon' => 'dashicons-wu-info1 wu-align-middle wu-mr-1', @@ -112,16 +107,13 @@ class Payment_Line_Item_List_Table extends Line_Item_List_Table { 'value' => sprintf(__('Subtotal: %s', 'wp-ultimo'), wu_format_currency($item->get_subtotal())), ); - /* - * Adds Taxes - */ + /* + * Adds Taxes + */ if ($item->get_tax_total()) { - if ($item->get_tax_type() === 'percentage' && $item->get_tax_rate()) { - $tax_rate = $item->get_tax_rate() . '%'; - - } // end if; + } $tax_label = $item->get_tax_rate() ? ($item->get_tax_label() ? $item->get_tax_label() : __('Tax Applied', 'wp-ultimo')) : __('No Taxes Applied', 'wp-ultimo'); @@ -132,8 +124,7 @@ class Payment_Line_Item_List_Table extends Line_Item_List_Table { 'label' => $tooltip, 'value' => sprintf(__('Taxes: %s', 'wp-ultimo'), wu_format_currency($item->get_tax_total())), ); - - } // end if; + } $first_row['description'] = array( 'icon' => 'dashicons-wu-file-text wu-align-middle wu-mr-1', @@ -141,17 +132,16 @@ class Payment_Line_Item_List_Table extends Line_Item_List_Table { 'value' => $item->get_description(), ); - echo wu_responsive_table_row(array( - 'id' => '', - 'title' => $item->get_title(), - 'url' => '', - 'image' => '', - 'status' => sprintf('%s', wu_format_currency($item->get_total())), - ), - $first_row, - $second_row + echo wu_responsive_table_row( + array( + 'id' => '', + 'title' => $item->get_title(), + 'url' => '', + 'image' => '', + 'status' => sprintf('%s', wu_format_currency($item->get_total())), + ), + $first_row, + $second_row ); - - } // end column_responsive; - -} // end class Payment_Line_Item_List_Table; + } +} diff --git a/inc/list-tables/class-payment-list-table-widget.php b/inc/list-tables/class-payment-list-table-widget.php index 8b8a629..76542a3 100644 --- a/inc/list-tables/class-payment-list-table-widget.php +++ b/inc/list-tables/class-payment-list-table-widget.php @@ -12,7 +12,7 @@ namespace WP_Ultimo\List_Tables; // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Helpers\Hash; +use WP_Ultimo\Helpers\Hash; /** * Payment List Table class. @@ -22,11 +22,11 @@ use \WP_Ultimo\Helpers\Hash; class Payment_List_Table_Widget extends Base_List_Table { /** - * Holds the query class for the object being listed. - * - * @since 2.0.0 - * @var string - */ + * Holds the query class for the object being listed. + * + * @since 2.0.0 + * @var string + */ protected $query_class = '\\WP_Ultimo\\Database\\Payments\\Payment_Query'; /** @@ -36,13 +36,14 @@ class Payment_List_Table_Widget extends Base_List_Table { */ public function __construct() { - parent::__construct(array( - 'singular' => __('Payment', 'wp-ultimo'), // singular name of the listed records - 'plural' => __('Payments', 'wp-ultimo'), // plural name of the listed records - 'ajax' => true // does this table support ajax? - )); - - } // end __construct; + parent::__construct( + array( + 'singular' => __('Payment', 'wp-ultimo'), // singular name of the listed records + 'plural' => __('Payments', 'wp-ultimo'), // plural name of the listed records + 'ajax' => true, // does this table support ajax? + ) + ); + } /** * Uses the query class to return the items to be displayed. @@ -71,18 +72,14 @@ class Payment_List_Table_Widget extends Base_List_Table { * Accounts for hashes */ if (isset($query_args['search']) && strlen((string) $query_args['search']) === Hash::LENGTH) { - $item_id = Hash::decode($query_args['search']); if ($item_id) { - unset($query_args['search']); $query_args['id'] = $item_id; - - } // end if; - - } // end if; + } + } $query_args = array_merge($query_args, $this->get_extra_query_fields()); @@ -91,18 +88,13 @@ class Payment_List_Table_Widget extends Base_List_Table { $function_name = 'wu_get_' . $query_class->get_plural_name(); if (function_exists($function_name)) { - $query = $function_name($query_args); - } else { - $query = $query_class->query($query_args); - - } // end if; + } return $query; - - } // end get_items; + } /** * Displays the payment reference code. * @@ -126,8 +118,7 @@ class Payment_List_Table_Widget extends Base_List_Table { $html = "{$code}"; return $html . $this->row_actions($actions); - - } // end column_hash; + } /** * Displays the membership photo and special status. @@ -144,8 +135,7 @@ class Payment_List_Table_Widget extends Base_List_Table { $class = $item->get_status_class(); return "{$label}"; - - } // end column_status; + } /** @@ -160,8 +150,7 @@ class Payment_List_Table_Widget extends Base_List_Table { $customer = $item->get_customer(); - if (!$customer) { - + if ( ! $customer) { $not_found = __('No customer found', 'wp-ultimo'); return "
    @@ -170,17 +159,22 @@ class Payment_List_Table_Widget extends Base_List_Table { {$not_found}
    "; - - } // end if; + } $url_atts = array( 'id' => $customer->get_id(), ); - $avatar = get_avatar($customer->get_user_id(), 32, 'identicon', '', array( - 'force_display' => true, - 'class' => 'wu-rounded-full wu-mr-2', - )); + $avatar = get_avatar( + $customer->get_user_id(), + 32, + 'identicon', + '', + array( + 'force_display' => true, + 'class' => 'wu-rounded-full wu-mr-2', + ) + ); $display_name = $customer->get_display_name(); @@ -198,8 +192,7 @@ class Payment_List_Table_Widget extends Base_List_Table { "; return $html; - - } // end column_customer; + } /** * Displays the column for the total amount of the payment. * @@ -212,8 +205,7 @@ class Payment_List_Table_Widget extends Base_List_Table { $gateway = wu_slug_to_name($item->get_gateway()); return wu_format_currency($item->get_total()) . "{$gateway}"; - - } // end column_total; + } /** * Returns the list of columns for this particular List Table. @@ -231,8 +223,7 @@ class Payment_List_Table_Widget extends Base_List_Table { ); return $columns; - - } // end get_columns; + } /** * Returns the filters for this page. @@ -240,7 +231,7 @@ class Payment_List_Table_Widget extends Base_List_Table { * @since 2.0.0 * @return void. */ - public function get_filters() {} // end get_filters; + public function get_filters() {} /** * Overrides the parent method to include the custom ajax functionality for WP Multisite WaaS. @@ -248,6 +239,5 @@ class Payment_List_Table_Widget extends Base_List_Table { * @since 2.0.0 * @return void */ - public function _js_vars() {} // end _js_vars; - -} // end class Payment_List_Table_Widget; + public function _js_vars() {} +} diff --git a/inc/list-tables/class-payment-list-table.php b/inc/list-tables/class-payment-list-table.php index c8693ca..2a8a4ab 100644 --- a/inc/list-tables/class-payment-list-table.php +++ b/inc/list-tables/class-payment-list-table.php @@ -9,7 +9,7 @@ namespace WP_Ultimo\List_Tables; -use \WP_Ultimo\Database\Payments\Payment_Status; +use WP_Ultimo\Database\Payments\Payment_Status; // Exit if accessed directly defined('ABSPATH') || exit; @@ -36,17 +36,18 @@ class Payment_List_Table extends Base_List_Table { */ public function __construct() { - parent::__construct(array( - 'singular' => __('Payment', 'wp-ultimo'), - 'plural' => __('Payments', 'wp-ultimo'), - 'ajax' => true, - 'add_new' => array( - 'url' => wu_get_form_url('add_new_payment'), - 'classes' => 'wubox', - ), - )); - - } // end __construct; + parent::__construct( + array( + 'singular' => __('Payment', 'wp-ultimo'), + 'plural' => __('Payments', 'wp-ultimo'), + 'ajax' => true, + 'add_new' => array( + 'url' => wu_get_form_url('add_new_payment'), + 'classes' => 'wubox', + ), + ) + ); + } /** * Adds the extra search field when the search element is present. @@ -67,8 +68,7 @@ class Payment_List_Table extends Base_List_Table { $_filter_fields['parent_id__in'] = array('0', 0, '', null); return $_filter_fields; - - } // end get_extra_query_fields; + } /** * Displays the payment reference code. @@ -95,7 +95,7 @@ class Payment_List_Table extends Base_List_Table { 'delete_modal', array( 'model' => 'payment', - 'id' => $item->get_id() + 'id' => $item->get_id(), ) ), __('Delete', 'wp-ultimo') @@ -105,8 +105,7 @@ class Payment_List_Table extends Base_List_Table { $html = "{$code}"; return $html . $this->row_actions($actions); - - } // end column_hash; + } /** * Displays the membership photo and special status. @@ -123,8 +122,7 @@ class Payment_List_Table extends Base_List_Table { $class = $item->get_status_class(); return "{$label}"; - - } // end column_status; + } /** * Returns the number of subscriptions owned by this membership. @@ -138,11 +136,9 @@ class Payment_List_Table extends Base_List_Table { $product = $item->get_product(); - if (!$product) { - + if ( ! $product) { return __('No product found', 'wp-ultimo'); - - } // end if; + } $url_atts = array( 'product_id' => $product->get_id(), @@ -155,8 +151,7 @@ class Payment_List_Table extends Base_List_Table { $html = $product->get_name(); return $html . $this->row_actions($actions); - - } // end column_product; + } /** * Displays the column for the total amount of the payment. @@ -171,8 +166,7 @@ class Payment_List_Table extends Base_List_Table { $gateway = wu_slug_to_name($item->get_gateway()); return wu_format_currency($item->get_total()) . "{$gateway}"; - - } // end column_total; + } /** * Returns the list of columns for this particular List Table. @@ -194,8 +188,7 @@ class Payment_List_Table extends Base_List_Table { ); return $columns; - - } // end get_columns; + } /** * Returns the filters for this page. @@ -211,13 +204,13 @@ class Payment_List_Table extends Base_List_Table { * Status */ 'status' => array( - 'label' => __( 'Status', 'wp-ultimo' ), + 'label' => __('Status', 'wp-ultimo'), 'options' => array( - 'pending' => __( 'Pending', 'wp-ultimo' ), - 'completed' => __( 'Completed', 'wp-ultimo' ), - 'refund' => __( 'Refund', 'wp-ultimo' ), - 'partial' => __( 'Partial', 'wp-ultimo' ), - 'failed' => __( 'Failed', 'wp-ultimo' ), + 'pending' => __('Pending', 'wp-ultimo'), + 'completed' => __('Completed', 'wp-ultimo'), + 'refund' => __('Refund', 'wp-ultimo'), + 'partial' => __('Partial', 'wp-ultimo'), + 'failed' => __('Failed', 'wp-ultimo'), ), ), @@ -225,12 +218,12 @@ class Payment_List_Table extends Base_List_Table { * Gateway */ 'gateway' => array( - 'label' => __( 'Gateway', 'wp-ultimo' ), + 'label' => __('Gateway', 'wp-ultimo'), 'options' => array( - 'free' => __( 'Free', 'wp-ultimo' ), - 'manual' => __( 'Manual', 'wp-ultimo' ), - 'paypal' => __( 'Paypal', 'wp-ultimo' ), - 'stripe' => __( 'Stripe', 'wp-ultimo' ), + 'free' => __('Free', 'wp-ultimo'), + 'manual' => __('Manual', 'wp-ultimo'), + 'paypal' => __('Paypal', 'wp-ultimo'), + 'stripe' => __('Stripe', 'wp-ultimo'), ), ), ), @@ -240,13 +233,12 @@ class Payment_List_Table extends Base_List_Table { * Created At */ 'date_created' => array( - 'label' => __( 'Created At', 'wp-ultimo' ), + 'label' => __('Created At', 'wp-ultimo'), 'options' => $this->get_default_date_filter_options(), ), ), ); - - } // end get_filters; + } /** * Returns the pre-selected filters on the filter bar. @@ -294,7 +286,5 @@ class Payment_List_Table extends Base_List_Table { 'count' => 0, ), ); - - } // end get_views; - -} // end class Payment_List_Table; + } +} diff --git a/inc/list-tables/class-product-list-table.php b/inc/list-tables/class-product-list-table.php index e0ad8ab..fbc9278 100644 --- a/inc/list-tables/class-product-list-table.php +++ b/inc/list-tables/class-product-list-table.php @@ -34,17 +34,18 @@ class Product_List_Table extends Base_List_Table { */ public function __construct() { - parent::__construct(array( - 'singular' => __('Product', 'wp-ultimo'), // singular name of the listed records - 'plural' => __('Products', 'wp-ultimo'), // plural name of the listed records - 'ajax' => true, // does this table support ajax? - 'add_new' => array( - 'url' => wu_network_admin_url('wp-ultimo-edit-product'), - 'classes' => '', - ), - )); - - } // end __construct; + parent::__construct( + array( + 'singular' => __('Product', 'wp-ultimo'), // singular name of the listed records + 'plural' => __('Products', 'wp-ultimo'), // plural name of the listed records + 'ajax' => true, // does this table support ajax? + 'add_new' => array( + 'url' => wu_network_admin_url('wp-ultimo-edit-product'), + 'classes' => '', + ), + ) + ); + } /** * Displays the content of the product column. @@ -58,7 +59,7 @@ class Product_List_Table extends Base_List_Table { $url_atts = array( 'id' => $item->get_id(), - 'model' => 'product' + 'model' => 'product', ); $title = sprintf('%s', wu_network_admin_url('wp-ultimo-edit-product', $url_atts), $item->get_name()); @@ -68,13 +69,22 @@ class Product_List_Table extends Base_List_Table { $actions = array( 'edit' => sprintf('%s', wu_network_admin_url('wp-ultimo-edit-product', $url_atts), __('Edit', 'wp-ultimo')), - 'duplicate' => sprintf('%s', wu_network_admin_url('wp-ultimo-products', array('action' => 'duplicate', 'id' => $item->get_id())), __('Duplicate', 'wp-ultimo')), + 'duplicate' => sprintf( + '%s', + wu_network_admin_url( + 'wp-ultimo-products', + array( + 'action' => 'duplicate', + 'id' => $item->get_id(), + ) + ), + __('Duplicate', 'wp-ultimo') + ), 'delete' => sprintf('%s', __('Delete', 'wp-ultimo'), wu_get_form_url('delete_modal', $url_atts), __('Delete', 'wp-ultimo')), ); return $title . $this->row_actions($actions); - - } // end column_name; + } /** * Displays the type of the product. @@ -91,8 +101,7 @@ class Product_List_Table extends Base_List_Table { $class = $item->get_type_class(); return "{$label}"; - - } // end column_type; + } /** * Displays the slug of the product. @@ -107,8 +116,7 @@ class Product_List_Table extends Base_List_Table { $slug = $item->get_slug(); return "{$slug}"; - - } // end column_slug; + } /** * Displays the price of the product. @@ -121,21 +129,16 @@ class Product_List_Table extends Base_List_Table { public function column_amount($item) { if ($item->get_pricing_type() === 'contact_us') { - return __('None', 'wp-ultimo') . sprintf('
    %s', __('Requires contact', 'wp-ultimo')); - - } // end if; + } if (empty($item->get_amount())) { - return __('Free', 'wp-ultimo'); - - } // end if; + } $amount = wu_format_currency($item->get_amount(), $item->get_currency()); if ($item->is_recurring()) { - $duration = $item->get_duration(); $message = sprintf( @@ -145,8 +148,7 @@ class Product_List_Table extends Base_List_Table { $item->get_duration_unit() ); - if (!$item->is_forever_recurring()) { - + if ( ! $item->is_forever_recurring()) { $billing_cycles_message = sprintf( // translators: %s is the number of billing cycles. _n('for %s cycle', 'for %s cycles', $item->get_billing_cycles(), 'wp-ultimo'), @@ -154,18 +156,13 @@ class Product_List_Table extends Base_List_Table { ); $message .= ' ' . $billing_cycles_message; - - } // end if; - + } } else { - $message = __('one time payment', 'wp-ultimo'); - - } // end if; + } return sprintf('%s
    %s', $amount, $message); - - } // end column_amount; + } /** * Displays the setup fee of the product. @@ -178,20 +175,15 @@ class Product_List_Table extends Base_List_Table { public function column_setup_fee($item) { if ($item->get_pricing_type() === 'contact_us') { - return __('None', 'wp-ultimo') . sprintf('
    %s', __('Requires contact', 'wp-ultimo')); + } - } // end if; - - if (!$item->has_setup_fee()) { - + if ( ! $item->has_setup_fee()) { return __('No Setup Fee', 'wp-ultimo'); - - } // end if; + } return wu_format_currency($item->get_setup_fee(), $item->get_currency()); - - } // end column_setup_fee; + } /** * Handles the bulk processing adding duplication. @@ -204,18 +196,15 @@ class Product_List_Table extends Base_List_Table { $bulk_action = $this->current_action(); if ($bulk_action === 'duplicate') { - $product = wu_request('id'); $product = wu_get_product($product); - if (!$product) { - + if ( ! $product) { WP_Ultimo()->notices->add(__('Product not found.', 'wp-ultimo'), 'error', 'network-admin'); return; - - } // end if; + } $new_product = $product->duplicate(); @@ -230,25 +219,24 @@ class Product_List_Table extends Base_List_Table { $result = $new_product->save(); if (is_wp_error($result)) { - WP_Ultimo()->notices->add($result->get_error_message(), 'error', 'network-admin'); return; + } - } // end if; - - $redirect_url = wu_network_admin_url('wp-ultimo-edit-product', array( - 'id' => $new_product->get_id(), - 'updated' => 1, - )); + $redirect_url = wu_network_admin_url( + 'wp-ultimo-edit-product', + array( + 'id' => $new_product->get_id(), + 'updated' => 1, + ) + ); wp_redirect($redirect_url); exit; - - } // end if; - - } // end process_single_action; + } + } /** * Returns the list of columns for this particular List Table. @@ -270,8 +258,7 @@ class Product_List_Table extends Base_List_Table { ); return $columns; - - } // end get_columns; + } /** * Handles the item display for grid mode. @@ -283,12 +270,14 @@ class Product_List_Table extends Base_List_Table { */ public function single_row_grid($item) { - wu_get_template('base/products/grid-item', array( - 'item' => $item, - 'table' => $this, - )); - - } // end single_row_grid; + wu_get_template( + 'base/products/grid-item', + array( + 'item' => $item, + 'table' => $this, + ) + ); + } /** * Returns the filters for this page. @@ -300,8 +289,7 @@ class Product_List_Table extends Base_List_Table { return array( 'filters' => array(), ); - - } // end get_filters; + } /** * Returns the pre-selected filters on the filter bar. @@ -337,7 +325,5 @@ class Product_List_Table extends Base_List_Table { 'count' => 0, ), ); - - } // end get_views; - -} // end class Product_List_Table; + } +} diff --git a/inc/list-tables/class-site-customer-list-table.php b/inc/list-tables/class-site-customer-list-table.php index 8919b9c..b222045 100644 --- a/inc/list-tables/class-site-customer-list-table.php +++ b/inc/list-tables/class-site-customer-list-table.php @@ -20,17 +20,16 @@ defined('ABSPATH') || exit; class Site_Customer_List_Table extends Customer_List_Table { /** - * Initializes the table. - * - * @since 2.0.0 - */ + * Initializes the table. + * + * @since 2.0.0 + */ public function __construct() { parent::__construct(); $this->current_mode = 'list'; - - } // end __construct; + } /** * Returns the list of columns for this particular List Table. @@ -45,8 +44,7 @@ class Site_Customer_List_Table extends Customer_List_Table { ); return $columns; - - } // end get_columns; + } /** * Renders the inside column responsive. @@ -61,42 +59,50 @@ class Site_Customer_List_Table extends Customer_List_Table { $last_login = sprintf(__('Last login %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_last_login()))); if ($item->is_online()) { - $last_login = '' . __('Online', 'wp-ultimo'); + } - } // end if; - - echo wu_responsive_table_row(array( - 'id' => $item->get_id(), - 'title' => $item->get_display_name(), - 'url' => wu_network_admin_url('wp-ultimo-edit-customer', array( - 'id' => $item->get_id(), - )), - 'image' => get_avatar($item->get_user_id(), 36, 'identicon', '', array( - 'force_display' => true, - 'class' => 'wu-rounded-full', - )), - 'status' => $this->column_status($item), - ), array( - 'total' => array( - 'icon' => 'dashicons-wu-at-sign wu-align-middle wu-mr-1', - 'label' => __('Email Address', 'wp-ultimo'), - 'value' => $item->get_email_address(), + echo wu_responsive_table_row( + array( + 'id' => $item->get_id(), + 'title' => $item->get_display_name(), + 'url' => wu_network_admin_url( + 'wp-ultimo-edit-customer', + array( + 'id' => $item->get_id(), + ) + ), + 'image' => get_avatar( + $item->get_user_id(), + 36, + 'identicon', + '', + array( + 'force_display' => true, + 'class' => 'wu-rounded-full', + ) + ), + 'status' => $this->column_status($item), ), - ), - array( - 'date_expiration' => array( - 'icon' => $item->is_online() === false ? 'dashicons-wu-calendar1 wu-align-middle wu-mr-1' : '', - 'label' => __('Last Login', 'wp-ultimo'), - 'value' => $last_login, + array( + 'total' => array( + 'icon' => 'dashicons-wu-at-sign wu-align-middle wu-mr-1', + 'label' => __('Email Address', 'wp-ultimo'), + 'value' => $item->get_email_address(), + ), ), - 'date_created' => array( - 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', - 'label' => '', - 'value' => sprintf(__('Registered %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_registered()))), - ), - )); - - } // end column_responsive; - -} // end class Site_Customer_List_Table; + array( + 'date_expiration' => array( + 'icon' => $item->is_online() === false ? 'dashicons-wu-calendar1 wu-align-middle wu-mr-1' : '', + 'label' => __('Last Login', 'wp-ultimo'), + 'value' => $last_login, + ), + 'date_created' => array( + 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', + 'label' => '', + 'value' => sprintf(__('Registered %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_registered()))), + ), + ) + ); + } +} diff --git a/inc/list-tables/class-site-list-table.php b/inc/list-tables/class-site-list-table.php index a0e6627..38afd7a 100644 --- a/inc/list-tables/class-site-list-table.php +++ b/inc/list-tables/class-site-list-table.php @@ -20,11 +20,11 @@ defined('ABSPATH') || exit; class Site_List_Table extends Base_List_Table { /** - * Holds the query class for the object being listed. - * - * @since 2.0.0 - * @var string - */ + * Holds the query class for the object being listed. + * + * @since 2.0.0 + * @var string + */ protected $query_class = '\\WP_Ultimo\\Database\\Sites\\Site_Query'; /** @@ -39,17 +39,18 @@ class Site_List_Table extends Base_List_Table { 'list' => __('List View'), ); - parent::__construct(array( - 'singular' => __('Site', 'wp-ultimo'), // singular name of the listed records - 'plural' => __('Sites', 'wp-ultimo'), // plural name of the listed records - 'ajax' => true, // does this table support ajax? - 'add_new' => array( - 'url' => wu_get_form_url('add_new_site'), - 'classes' => 'wubox', - ), - )); - - } // end __construct; + parent::__construct( + array( + 'singular' => __('Site', 'wp-ultimo'), // singular name of the listed records + 'plural' => __('Sites', 'wp-ultimo'), // plural name of the listed records + 'ajax' => true, // does this table support ajax? + 'add_new' => array( + 'url' => wu_get_form_url('add_new_site'), + 'classes' => 'wubox', + ), + ) + ); + } /** * Overrides the parent method to add pending sites. @@ -66,12 +67,10 @@ class Site_List_Table extends Base_List_Table { $type = wu_request('type'); if ($type === 'pending') { - $pending_sites = \WP_Ultimo\Models\Site::get_all_by_type('pending'); return $count ? count($pending_sites) : $pending_sites; - - } // end if; + } $query = array( 'number' => $per_page, @@ -81,21 +80,18 @@ class Site_List_Table extends Base_List_Table { ); if ($type && $type !== 'all') { - $query['meta_query'] = array( 'type' => array( 'key' => 'wu_type', 'value' => $type, ), ); - - } // end if; + } $query = apply_filters("wu_{$this->id}_get_items", $query, $this); return wu_get_sites($query); - - } // end get_items; + } /** * Render the bulk edit checkbox. * @@ -104,14 +100,11 @@ class Site_List_Table extends Base_List_Table { public function column_cb($item): string { if ($item->get_type() === 'pending') { - return sprintf('', $item->get_membership_id()); - - } // end if; + } return sprintf('', $item->get_id()); - - } // end column_cb; + } /** * Displays the content of the name column. * @@ -123,7 +116,7 @@ class Site_List_Table extends Base_List_Table { $url_atts = array( 'id' => $item->get_id(), - 'model' => 'site' + 'model' => 'site', ); $title = $item->get_title(); @@ -156,13 +149,13 @@ class Site_List_Table extends Base_List_Table { ); if ($item->get_type() === 'pending') { - $actions = array( 'duplicate' => sprintf( '%s', __('Publish Site', 'wp-ultimo'), wu_get_form_url( - 'publish_pending_site', array('membership_id' => $item->get_membership_id()) + 'publish_pending_site', + array('membership_id' => $item->get_membership_id()) ), __('Publish', 'wp-ultimo') ), @@ -174,21 +167,24 @@ class Site_List_Table extends Base_List_Table { array( 'id' => $item->get_membership_id(), 'model' => 'membership_meta_pending_site', - 'redirect_to' => urlencode((string) wu_network_admin_url('wp-ultimo-sites', array( - 'type' => 'pending', - 'page' => wu_request('page', 1), - ))), + 'redirect_to' => urlencode( + (string) wu_network_admin_url( + 'wp-ultimo-sites', + array( + 'type' => 'pending', + 'page' => wu_request('page', 1), + ) + ) + ), ) ), __('Delete', 'wp-ultimo') ), ); - - } // end if; + } return $title . sprintf('%s', make_clickable($item->get_active_site_url())) . $this->row_actions($actions); - - } // end column_path; + } /** * Returns the date of the customer registration. * @@ -201,8 +197,7 @@ class Site_List_Table extends Base_List_Table { $time = strtotime((string) $item->get_last_login(false)); return $item->get_date_registered() . sprintf('
    %s', human_time_diff($time)); - - } // end column_date_registered; + } /** * Returns the blog_id. @@ -215,8 +210,7 @@ class Site_List_Table extends Base_List_Table { public function column_blog_id($item) { return $item->get_type() === \WP_Ultimo\Database\Sites\Site_Type::PENDING ? '--' : $item->get_blog_id(); - - } // end column_blog_id; + } /** * Displays the type of the site. @@ -233,8 +227,7 @@ class Site_List_Table extends Base_List_Table { $class = $item->get_type_class(); return "{$label}"; - - } // end column_type; + } /** * Column for the domains associated with this site. * @@ -244,10 +237,12 @@ class Site_List_Table extends Base_List_Table { */ public function column_domains($item): string { - $domain = wu_get_domains(array( - 'blog_id' => $item->get_id(), - 'count' => true, - )); + $domain = wu_get_domains( + array( + 'blog_id' => $item->get_id(), + 'count' => true, + ) + ); $url_atts = array( 'blog_id' => $item->get_id(), @@ -258,8 +253,7 @@ class Site_List_Table extends Base_List_Table { ); return $domain . $this->row_actions($actions); - - } // end column_domains; + } /** * Returns the list of columns for this particular List Table. @@ -281,8 +275,7 @@ class Site_List_Table extends Base_List_Table { ); return $columns; - - } // end get_columns; + } /** * Renders the customer card for grid mode. @@ -294,12 +287,14 @@ class Site_List_Table extends Base_List_Table { */ public function single_row_grid($item) { - wu_get_template('base/sites/grid-item', array( - 'item' => $item, - 'list_table' => $this, - )); - - } // end single_row_grid; + wu_get_template( + 'base/sites/grid-item', + array( + 'item' => $item, + 'list_table' => $this, + ) + ); + } /** * Returns the filters for this page. * @@ -328,8 +323,7 @@ class Site_List_Table extends Base_List_Table { ), ), ); - - } // end get_filters; + } /** * Returns the pre-selected filters on the filter bar. @@ -365,8 +359,7 @@ class Site_List_Table extends Base_List_Table { 'count' => 0, ), ); - - } // end get_views; + } /** * Returns an associative array containing the bulk action @@ -379,11 +372,10 @@ class Site_List_Table extends Base_List_Table { 'screenshot' => __('Take Screenshot', 'wp-ultimo'), ); - $actions[wu_request('type', 'all') === 'pending' ? 'delete-pending' : 'delete'] = __('Delete', 'wp-ultimo'); + $actions[ wu_request('type', 'all') === 'pending' ? 'delete-pending' : 'delete' ] = __('Delete', 'wp-ultimo'); return $actions; - - } // end get_bulk_actions; + } /** * Handles the bulk processing. @@ -396,18 +388,15 @@ class Site_List_Table extends Base_List_Table { $action = $this->current_action(); if ($action === 'duplicate') { - $site_id = wu_request('id'); $site = wu_get_site($site_id); - if (!$site) { - + if ( ! $site) { WP_Ultimo()->notices->add(__('Site not found.', 'wp-ultimo'), 'error', 'network-admin'); return; - - } // end if; + } $new_site = $site->duplicate(); @@ -428,24 +417,22 @@ class Site_List_Table extends Base_List_Table { $result = $new_site->save(); if (is_wp_error($result)) { - WP_Ultimo()->notices->add($result->get_error_message(), 'error', 'network-admin'); return; + } - } // end if; - - $redirect_url = wu_network_admin_url('wp-ultimo-edit-site', array( - 'id' => $new_site->get_id(), - 'updated' => 1, - )); + $redirect_url = wu_network_admin_url( + 'wp-ultimo-edit-site', + array( + 'id' => $new_site->get_id(), + 'updated' => 1, + ) + ); wp_redirect($redirect_url); exit; - - } // end if; - - } // end process_single_action; - -} // end class Site_List_Table; + } + } +} diff --git a/inc/list-tables/class-sites-domain-list-table.php b/inc/list-tables/class-sites-domain-list-table.php index 3eb1b18..63197b8 100644 --- a/inc/list-tables/class-sites-domain-list-table.php +++ b/inc/list-tables/class-sites-domain-list-table.php @@ -32,8 +32,7 @@ class Sites_Domain_List_Table extends Domain_List_Table { ); return $columns; - - } // end get_columns; + } /** * Renders the inside column responsive. @@ -45,34 +44,38 @@ class Sites_Domain_List_Table extends Domain_List_Table { */ public function column_responsive($item) { - echo wu_responsive_table_row(array( - 'id' => $item->get_id(), - 'title' => strtolower((string) $item->get_domain()), - 'url' => wu_network_admin_url('wp-ultimo-edit-domain', array( - 'id' => $item->get_id(), - )), - 'status' => $this->column_stage($item), - ), array( - 'primary' => array( - 'icon' => $item->is_primary_domain() ? 'dashicons-wu-filter_1 wu-align-text-bottom wu-mr-1' : 'dashicons-wu-plus-square wu-align-text-bottom wu-mr-1', - 'label' => '', - 'value' => $item->is_primary_domain() ? __('Primary', 'wp-ultimo') : __('Alias', 'wp-ultimo'), + echo wu_responsive_table_row( + array( + 'id' => $item->get_id(), + 'title' => strtolower((string) $item->get_domain()), + 'url' => wu_network_admin_url( + 'wp-ultimo-edit-domain', + array( + 'id' => $item->get_id(), + ) + ), + 'status' => $this->column_stage($item), ), - 'secure' => array( - 'wrapper_classes' => $item->is_secure() ? 'wu-text-green-500' : '', - 'icon' => $item->is_secure() ? 'dashicons-wu-lock1 wu-align-text-bottom wu-mr-1' : 'dashicons-wu-lock1 wu-align-text-bottom wu-mr-1', - 'label' => '', - 'value' => $item->is_secure() ? __('Secure (HTTPS)', 'wp-ultimo') : __('Not Secure (HTTP)', 'wp-ultimo'), + array( + 'primary' => array( + 'icon' => $item->is_primary_domain() ? 'dashicons-wu-filter_1 wu-align-text-bottom wu-mr-1' : 'dashicons-wu-plus-square wu-align-text-bottom wu-mr-1', + 'label' => '', + 'value' => $item->is_primary_domain() ? __('Primary', 'wp-ultimo') : __('Alias', 'wp-ultimo'), + ), + 'secure' => array( + 'wrapper_classes' => $item->is_secure() ? 'wu-text-green-500' : '', + 'icon' => $item->is_secure() ? 'dashicons-wu-lock1 wu-align-text-bottom wu-mr-1' : 'dashicons-wu-lock1 wu-align-text-bottom wu-mr-1', + 'label' => '', + 'value' => $item->is_secure() ? __('Secure (HTTPS)', 'wp-ultimo') : __('Not Secure (HTTP)', 'wp-ultimo'), + ), ), - ), - array( - 'date_created' => array( - 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', - 'label' => '', - 'value' => sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_created()))), - ), - )); - - } // end column_responsive; - -} // end class Sites_Domain_List_Table; + array( + 'date_created' => array( + 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', + 'label' => '', + 'value' => sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_created()))), + ), + ) + ); + } +} diff --git a/inc/list-tables/class-webhook-list-table.php b/inc/list-tables/class-webhook-list-table.php index 8c71042..886c5ae 100644 --- a/inc/list-tables/class-webhook-list-table.php +++ b/inc/list-tables/class-webhook-list-table.php @@ -34,16 +34,18 @@ class Webhook_List_Table extends Base_List_Table { */ public function __construct() { - parent::__construct(array( - 'singular' => __('Webhook', 'wp-ultimo'), // singular name of the listed records - 'plural' => __('Webhooks', 'wp-ultimo'), // plural name of the listed records - 'ajax' => true, // does this table support ajax? - 'add_new' => array( - 'url' => wu_get_form_url('add_new_webhook_modal'), - 'classes' => 'wubox', - ), - )); - } // end __construct; + parent::__construct( + array( + 'singular' => __('Webhook', 'wp-ultimo'), // singular name of the listed records + 'plural' => __('Webhooks', 'wp-ultimo'), // plural name of the listed records + 'ajax' => true, // does this table support ajax? + 'add_new' => array( + 'url' => wu_get_form_url('add_new_webhook_modal'), + 'classes' => 'wubox', + ), + ) + ); + } /** * Displays the content of the name column. * @@ -58,8 +60,14 @@ class Webhook_List_Table extends Base_List_Table { 'model' => 'webhook', ); - $title = sprintf('%s - ', wu_network_admin_url('wp-ultimo-edit-webhook', $url_atts), $item->get_name(), $item->get_id(), __('Sending Test..', 'wp-ultimo')); + $title = sprintf( + '%s + ', + wu_network_admin_url('wp-ultimo-edit-webhook', $url_atts), + $item->get_name(), + $item->get_id(), + __('Sending Test..', 'wp-ultimo') + ); $actions = array( 'edit' => sprintf('%s', wu_network_admin_url('wp-ultimo-edit-webhook', $url_atts), __('Edit', 'wp-ultimo')), @@ -76,8 +84,7 @@ class Webhook_List_Table extends Base_List_Table { ); return $title . $this->row_actions($actions); - - } // end column_name; + } /** * Displays the content of the webhook url column. @@ -92,8 +99,7 @@ class Webhook_List_Table extends Base_List_Table { $trimmed_url = mb_strimwidth((string) $item->get_webhook_url(), 0, 50, '...'); return "{$trimmed_url}"; - - } // end column_webhook_url; + } /** * Displays the content of the event column. @@ -108,8 +114,7 @@ class Webhook_List_Table extends Base_List_Table { $event = $item->get_event(); return "{$event}"; - - } // end column_event; + } /** * Displays the content of the count column. * @@ -126,8 +131,7 @@ class Webhook_List_Table extends Base_List_Table { ); return $count . $this->row_actions($actions); - - } // end column_count; + } /** * Displays the content of the integration column. * @@ -138,8 +142,7 @@ class Webhook_List_Table extends Base_List_Table { public function column_integration($item): string { return ucwords(str_replace(array('_', '-'), ' ', (string) $item->get_integration())); - - } // end column_integration; + } /** * Displays the content of the active column. @@ -152,8 +155,7 @@ class Webhook_List_Table extends Base_List_Table { public function column_active($item) { return $item->is_active() ? __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo'); - - } // end column_active; + } /** * Returns the list of columns for this particular List Table. @@ -175,8 +177,7 @@ class Webhook_List_Table extends Base_List_Table { ); return $columns; - - } // end get_columns; + } /** * Returns the filters for this page. * @@ -188,7 +189,5 @@ class Webhook_List_Table extends Base_List_Table { 'filters' => array(), 'date_filters' => array(), ); - - } // end get_filters; - -} // end class Webhook_List_Table; + } +} diff --git a/inc/list-tables/customer-panel/class-invoice-list-table.php b/inc/list-tables/customer-panel/class-invoice-list-table.php index cf41bfc..17bcda2 100644 --- a/inc/list-tables/customer-panel/class-invoice-list-table.php +++ b/inc/list-tables/customer-panel/class-invoice-list-table.php @@ -37,8 +37,7 @@ class Invoice_List_Table extends Parent_Payment_List_Table { ); return $columns; - - } // end get_columns; + } /** * Clears the bulk actions. @@ -51,8 +50,5 @@ class Invoice_List_Table extends Parent_Payment_List_Table { public function bulk_actions($which = '') { return array(); - - } // end bulk_actions; - -} // end class Invoice_List_Table; - + } +} diff --git a/inc/list-tables/customer-panel/class-product-list-table.php b/inc/list-tables/customer-panel/class-product-list-table.php index a2a2f46..ffd26d9 100644 --- a/inc/list-tables/customer-panel/class-product-list-table.php +++ b/inc/list-tables/customer-panel/class-product-list-table.php @@ -35,8 +35,7 @@ class Product_List_Table extends Parent_Product_List_Table { ); $this->current_mode = 'grid'; - - } // end __construct; + } /** * Returns the list of columns for this particular List Table. @@ -47,8 +46,7 @@ class Product_List_Table extends Parent_Product_List_Table { public function get_columns() { return array(); - - } // end get_columns; + } /** * Resets the filters. @@ -61,8 +59,7 @@ class Product_List_Table extends Parent_Product_List_Table { 'filters' => array(), 'date_filters' => array(), ); - - } // end get_filters; + } /** * Resets bulk actions. @@ -75,8 +72,7 @@ class Product_List_Table extends Parent_Product_List_Table { public function bulk_actions($which = '') { return array(); - - } // end bulk_actions; + } /** * Renders the customer card for grid mode. @@ -88,11 +84,12 @@ class Product_List_Table extends Parent_Product_List_Table { */ public function single_row_grid($item) { - wu_get_template('base/products/grid-item', array( - 'item' => $item, - 'list_table' => $this, - )); - - } // end single_row_grid; - -} // end class Product_List_Table; + wu_get_template( + 'base/products/grid-item', + array( + 'item' => $item, + 'list_table' => $this, + ) + ); + } +} diff --git a/inc/list-tables/customer-panel/class-site-list-table.php b/inc/list-tables/customer-panel/class-site-list-table.php index 8062402..c127155 100644 --- a/inc/list-tables/customer-panel/class-site-list-table.php +++ b/inc/list-tables/customer-panel/class-site-list-table.php @@ -35,8 +35,7 @@ class Site_List_Table extends Parent_Site_List_Table { ); $this->current_mode = 'grid'; - - } // end __construct; + } /** * Returns the list of columns for this particular List Table. @@ -47,8 +46,7 @@ class Site_List_Table extends Parent_Site_List_Table { public function get_columns() { return array(); - - } // end get_columns; + } /** * Clears filters. @@ -61,8 +59,7 @@ class Site_List_Table extends Parent_Site_List_Table { 'filters' => array(), 'date_filters' => array(), ); - - } // end get_filters; + } /** * Clears views. @@ -80,8 +77,7 @@ class Site_List_Table extends Parent_Site_List_Table { 'count' => 0, ), ); - - } // end get_views; + } /** * Get the extra fields based on the request. @@ -93,13 +89,11 @@ class Site_List_Table extends Parent_Site_List_Table { $customer = wu_get_current_customer(); - if (!$customer) { - + if ( ! $customer) { return array( 'blog_id__in' => array('null_id'), // pass absurd value to make sure the query returns nothing. ); - - } // end if; + } $fields = parent::get_extra_fields(); @@ -113,7 +107,5 @@ class Site_List_Table extends Parent_Site_List_Table { ); return $fields; - - } // end get_extra_fields; - -} // end class Site_List_Table; + } +} diff --git a/inc/loaders/class-table-loader.php b/inc/loaders/class-table-loader.php index 2fbaa20..5b316c7 100644 --- a/inc/loaders/class-table-loader.php +++ b/inc/loaders/class-table-loader.php @@ -244,8 +244,7 @@ class Table_Loader { */ $this->checkout_form_table = new \WP_Ultimo\Database\Checkout_Forms\Checkout_Forms_Table(); $this->checkout_formmeta_table = new \WP_Ultimo\Database\Checkout_Forms\Checkout_Forms_Meta_Table(); - - } // end init; + } /** * Returns all the table objects. @@ -256,8 +255,7 @@ class Table_Loader { public function get_tables() { return get_object_vars($this); - - } // end get_tables; + } /** * Checks if we have all the tables installed. @@ -272,17 +270,11 @@ class Table_Loader { $tables = $this->get_tables(); foreach ($tables as $table) { - - if (!$table->exists()) { - + if ( ! $table->exists()) { $all_installed = false; - - } // end if; - - } // end foreach; + } + } return $all_installed; - - } // end is_installed; - -} // end class Table_Loader; + } +} diff --git a/inc/managers/class-base-manager.php b/inc/managers/class-base-manager.php index 8649ecb..d83046a 100644 --- a/inc/managers/class-base-manager.php +++ b/inc/managers/class-base-manager.php @@ -27,6 +27,5 @@ class Base_Manager { * @since 2.0.11 * @return void */ - public function init() {} // end init; - -} // end class Base_Manager; + public function init() {} +} diff --git a/inc/managers/class-block-manager.php b/inc/managers/class-block-manager.php index bfad902..7f2b235 100644 --- a/inc/managers/class-block-manager.php +++ b/inc/managers/class-block-manager.php @@ -38,8 +38,7 @@ class Block_Manager extends Base_Manager { $hook = version_compare($wp_version, '5.8', '<') ? 'block_categories' : 'block_categories_all'; add_filter($hook, array($this, 'add_wp_ultimo_block_category'), 1, 2); - - } // end init; + } /** * Adds wp-ultimo as a Block category on Gutenberg. @@ -52,13 +51,14 @@ class Block_Manager extends Base_Manager { */ public function add_wp_ultimo_block_category($categories, $post) { - return array_merge($categories, array( + return array_merge( + $categories, array( - 'slug' => 'wp-ultimo', - 'title' => __('Multisite WaaS', 'wp-ultimo'), - ), - )); - - } // end add_wp_ultimo_block_category; - -} // end class Block_Manager; + array( + 'slug' => 'wp-ultimo', + 'title' => __('Multisite WaaS', 'wp-ultimo'), + ), + ) + ); + } +} diff --git a/inc/managers/class-broadcast-manager.php b/inc/managers/class-broadcast-manager.php index a9381b9..e7e08f4 100644 --- a/inc/managers/class-broadcast-manager.php +++ b/inc/managers/class-broadcast-manager.php @@ -25,7 +25,9 @@ defined('ABSPATH') || exit; */ class Broadcast_Manager extends Base_Manager { - use \WP_Ultimo\Apis\Rest_Api, \WP_Ultimo\Apis\WP_CLI, \WP_Ultimo\Traits\Singleton; + use \WP_Ultimo\Apis\Rest_Api; + use \WP_Ultimo\Apis\WP_CLI; + use \WP_Ultimo\Traits\Singleton; /** * The manager slug. @@ -58,13 +60,10 @@ class Broadcast_Manager extends Base_Manager { /** * Add unseen broadcast notices to the panel. */ - if (!is_network_admin() && !is_main_site()) { - + if ( ! is_network_admin() && ! is_main_site()) { add_action('init', array($this, 'add_unseen_broadcast_notices')); - - } // end if; - - } // end init; + } + } /** * Add unseen broadcast messages. @@ -76,52 +75,41 @@ class Broadcast_Manager extends Base_Manager { $current_customer = wu_get_current_customer(); - if (!$current_customer) { - + if ( ! $current_customer) { return; + } - } // end if; - - $all_broadcasts = Broadcast::query(array( - 'number' => 10, - 'order' => 'DESC', - 'order_by' => 'id', - 'type__in' => array('broadcast_notice'), - )); + $all_broadcasts = Broadcast::query( + array( + 'number' => 10, + 'order' => 'DESC', + 'order_by' => 'id', + 'type__in' => array('broadcast_notice'), + ) + ); if (isset($all_broadcasts)) { - foreach ($all_broadcasts as $key => $broadcast) { - if (isset($broadcast) && 'broadcast_notice' === $broadcast->get_type()) { - $targets = $this->get_all_notice_customer_targets($broadcast->get_id()); - if (!is_array($targets)) { - + if ( ! is_array($targets)) { $targets = array($targets); - - } // end if; + } $dismissed = get_user_meta(get_current_user_id(), 'wu_dismissed_admin_notices'); - if (in_array($current_customer->get_id(), $targets, true) && !in_array($broadcast->get_id(), $dismissed, true)) { - + if (in_array($current_customer->get_id(), $targets, true) && ! in_array($broadcast->get_id(), $dismissed, true)) { $notice = '' . $broadcast->get_title() . ' ' . $broadcast->get_content() . ''; WP_Ultimo()->notices->add($notice, $broadcast->get_notice_type(), 'admin', strval($broadcast->get_id())); WP_Ultimo()->notices->add($notice, $broadcast->get_notice_type(), 'user', strval($broadcast->get_id())); - - } // end if; - - } // end if; - - } // end foreach; - - } // end if; - - } // end add_unseen_broadcast_notices; + } + } + } + } + } /** * Handles the broadcast message send via modal. @@ -138,21 +126,18 @@ class Broadcast_Manager extends Base_Manager { $target_products = wu_request('target_products', ''); - if (!$target_customers && !$target_products) { - + if ( ! $target_customers && ! $target_products) { wp_send_json_error(new \WP_Error('error', __('No product or customer target was selected.', 'wp-ultimo'))); - - } // end if; + } $broadcast_type = wu_request('type', 'broadcast_notice'); $args['type'] = $broadcast_type; if ($broadcast_type === 'broadcast_notice') { - $targets = array( 'customers' => $target_customers, - 'products' => $target_products + 'products' => $target_products, ); $args['targets'] = $targets; @@ -161,21 +146,19 @@ class Broadcast_Manager extends Base_Manager { $saved = $this->save_broadcast($args); if (is_wp_error($saved)) { - wp_send_json_error($saved); - - } // end if; + } $redirect = current_user_can('wu_edit_broadcasts') ? 'wp-ultimo-edit-broadcast' : 'wp-ultimo-broadcasts'; - wp_send_json_success(array( - 'redirect_url' => add_query_arg('id', $saved->get_id(), wu_network_admin_url($redirect)) - )); - - } // end if; + wp_send_json_success( + array( + 'redirect_url' => add_query_arg('id', $saved->get_id(), wu_network_admin_url($redirect)), + ) + ); + } if ($args['type'] === 'broadcast_email') { - $to = array(); $bcc = array(); @@ -183,28 +166,22 @@ class Broadcast_Manager extends Base_Manager { $targets = array(); if ($args['target_customers']) { - $customers = explode(',', (string) $args['target_customers']); $targets = array_merge($targets, $customers); - - } // end if; + } if ($args['target_products']) { - $product_targets = explode(',', (string) $args['target_products']); $customers = array(); foreach ($product_targets as $product_id) { - $customers = array_merge($customers, wu_get_membership_customers($product_id)); - - } // end foreach; + } $targets = array_merge($targets, $customers); - - } // end if; + } $targets = array_unique($targets); @@ -212,35 +189,27 @@ class Broadcast_Manager extends Base_Manager { * Get name and email based on user id */ foreach ($targets as $target) { - $customer = wu_get_customer($target); if ($customer) { - $to[] = array( 'name' => $customer->get_display_name(), 'email' => $customer->get_email_address(), ); + } + } - } // end if; - - } // end foreach; - - if (!isset($args['custom_sender'])) { - + if ( ! isset($args['custom_sender'])) { $from = array( 'name' => wu_get_setting('from_name', get_network_option(null, 'site_name')), 'email' => wu_get_setting('from_email', get_network_option(null, 'admin_email')), ); - } else { - $from = array( 'name' => $args['custom_sender']['from_name'], 'email' => $args['custom_sender']['from_email'], ); - - } // end if; + } $template_type = wu_get_setting('email_template_type', 'html'); @@ -255,19 +224,14 @@ class Broadcast_Manager extends Base_Manager { ); try { - $status = Sender::send_mail($from, $to, $send_args); - } catch (\Throwable $e) { - $error = new \WP_Error($e->getCode(), $e->getMessage()); wp_send_json_error($error); - - } // end try; + } if ($status) { - $args['targets'] = array( 'customers' => $args['target_customers'], 'products' => $args['target_products'], @@ -276,19 +240,18 @@ class Broadcast_Manager extends Base_Manager { // then we save with the message status (success, fail) $this->save_broadcast($args); - wp_send_json_success(array( - 'redirect_url' => wu_network_admin_url('wp-ultimo-broadcasts') - )); - - } // end if; - - } // end if; + wp_send_json_success( + array( + 'redirect_url' => wu_network_admin_url('wp-ultimo-broadcasts'), + ) + ); + } + } $error = new \WP_Error('mail-error', __('Something wrong happened.', 'wp-ultimo')); wp_send_json_error($error); - - } // end handle_broadcast; + } /** * Saves the broadcast message in the database @@ -310,18 +273,15 @@ class Broadcast_Manager extends Base_Manager { $broadcast = new Broadcast($broadcast_data); if ($args['type'] === 'broadcast_notice') { - $broadcast->set_notice_type($args['notice_type']); - - } // end if; + } $broadcast->set_message_targets($args['targets']); $saved = $broadcast->save(); return is_wp_error($saved) ? $saved : $broadcast; - - } // end save_broadcast; + } /** * Returns targets for a specific broadcast. @@ -338,21 +298,16 @@ class Broadcast_Manager extends Base_Manager { $targets = $broadcast->get_message_targets(); - if (isset($targets[$type])) { + if (isset($targets[ $type ])) { + if (is_string($targets[ $type ])) { + return explode(',', $targets[ $type ]); + } - if (is_string($targets[$type])) { - - return explode(',', $targets[$type]); - - } // end if; - - return (array) $targets[$type]; - - } // end if; + return (array) $targets[ $type ]; + } return array(); - - } // end get_broadcast_targets; + } /** * Returns all customer from targets. @@ -371,41 +326,25 @@ class Broadcast_Manager extends Base_Manager { $product_customers = array(); if (is_array($products) && $products[0]) { - foreach ($products as $product_key => $product) { - $membership_customers = wu_get_membership_customers($product); if ($membership_customers) { - if (is_array($membership_customers)) { - $product_customers = array_merge($membership_customers, $product_customers); - } else { - array_push($product_customers, $membership_customers); - - } // end if; - - } // end if; - - } // end foreach; - - } // end if; + } + } + } + } if (isset($product_customers) ) { - $targets = array_merge($product_customers, $customers_targets); - } else { - $targets = $customers_targets; - - } // end if; + } return array_map('absint', array_filter(array_unique($targets))); - - } // end get_all_notice_customer_targets; - -} // end class Broadcast_Manager; + } +} diff --git a/inc/managers/class-cache-manager.php b/inc/managers/class-cache-manager.php index fec3b96..75ebca5 100644 --- a/inc/managers/class-cache-manager.php +++ b/inc/managers/class-cache-manager.php @@ -38,21 +38,16 @@ class Cache_Manager { * To support more caching plugins, just add a method to this class suffixed with '_cache_flush' */ foreach (get_class_methods($this) as $method) { - if (substr_compare($method, '_cache_flush', -strlen('_cache_flush')) === 0) { - $this->$method(); - - } // end if; - - } // end foreach; + } + } /** * Hook to additional cleaning */ do_action('wu_flush_known_caches'); - - } // end flush_known_caches; + } /** * Flush WPEngine Cache @@ -63,14 +58,12 @@ class Cache_Manager { protected function wp_engine_cache_flush() { if (class_exists('\WpeCommon') && method_exists('\WpeCommon', 'purge_varnish_cache')) { - \WpeCommon::purge_memcached(); // WPEngine Cache Flushing \WpeCommon::clear_maxcdn_cache(); // WPEngine Cache Flushing \WpeCommon::purge_varnish_cache(); // WPEngine Cache Flushing - } // end if; - - } // end wp_engine_cache_flush; + } + } /** * Flush WP Rocket Cache @@ -81,12 +74,9 @@ class Cache_Manager { protected function wp_rocket_cache_flush() { if (function_exists('rocket_clean_domain')) { - \rocket_clean_domain(); - - } // end if; - - } // end wp_rocket_cache_flush; + } + } /** * Flush WP Super Cache @@ -97,12 +87,10 @@ class Cache_Manager { protected function wp_super_cache_flush() { if (function_exists('wp_cache_clear_cache')) { - \wp_cache_clear_cache(); // WP Super Cache Flush - } // end if; - - } // end wp_super_cache_flush; + } + } /** * Flush WP Fastest Cache @@ -113,12 +101,10 @@ class Cache_Manager { protected function wp_fastest_cache_flush() { if (function_exists('wpfc_clear_all_cache')) { - \wpfc_clear_all_cache(); // WP Fastest Cache Flushing - } // end if; - - } // end wp_fastest_cache_flush; + } + } /** * Flush W3 Total Cache @@ -129,12 +115,10 @@ class Cache_Manager { protected function w3_total_cache_flush() { if (function_exists('w3tc_pgcache_flush')) { - \w3tc_pgcache_flush(); // W3TC Cache Flushing - } // end if; - - } // end w3_total_cache_flush; + } + } /** * Flush Hummingbird Cache @@ -145,12 +129,10 @@ class Cache_Manager { protected function hummingbird_cache_flush() { if (class_exists('\Hummingbird\WP_Hummingbird') && method_exists('\Hummingbird\WP_Hummingbird', 'flush_cache')) { - \Hummingbird\WP_Hummingbird::flush_cache(); // Hummingbird Cache Flushing - } // end if; - - } // end hummingbird_cache_flush; + } + } /** * Flush WP Optimize Cache @@ -161,18 +143,14 @@ class Cache_Manager { protected function wp_optimize_cache_flush() { if (class_exists('\WP_Optimize') && method_exists('\WP_Optimize', 'get_page_cache')) { - $wp_optimize = \WP_Optimize()->get_page_cache(); if (method_exists($wp_optimize, 'purge')) { - $wp_optimize->purge(); // WP Optimize Cache Flushing - } // end if; - - } // end if; - - } // end wp_optimize_cache_flush; + } + } + } /** * Flush Comet Cache @@ -183,12 +161,10 @@ class Cache_Manager { protected function comet_cache_flush() { if (class_exists('\Comet_Cache') && method_exists('\Comet_Cache', 'clear')) { - \Comet_Cache::clear(); // Comet Cache Flushing - } // end if; - - } // end comet_cache_flush; + } + } /** * Flush LiteSpeed Cache @@ -199,11 +175,8 @@ class Cache_Manager { protected function litespeed_cache_flush() { if (class_exists('\LiteSpeed_Cache_API') && method_exists('\LiteSpeed_Cache_API', 'purge_all')) { - \LiteSpeed_Cache_API::purge_all(); // LiteSpeed Cache Flushing - } // end if; - - } // end litespeed_cache_flush; - -} // end class Cache_Manager; + } + } +} diff --git a/inc/managers/class-checkout-form-manager.php b/inc/managers/class-checkout-form-manager.php index fb14ec8..76fb6e0 100644 --- a/inc/managers/class-checkout-form-manager.php +++ b/inc/managers/class-checkout-form-manager.php @@ -23,7 +23,9 @@ defined('ABSPATH') || exit; */ class Checkout_Form_Manager extends Base_Manager { - use \WP_Ultimo\Apis\Rest_Api, \WP_Ultimo\Apis\WP_CLI, \WP_Ultimo\Traits\Singleton; + use \WP_Ultimo\Apis\Rest_Api; + use \WP_Ultimo\Apis\WP_CLI; + use \WP_Ultimo\Traits\Singleton; /** * The manager slug. @@ -52,7 +54,5 @@ class Checkout_Form_Manager extends Base_Manager { $this->enable_rest_api(); $this->enable_wp_cli(); - - } // end init; - -} // end class Checkout_Form_Manager; + } +} diff --git a/inc/managers/class-customer-manager.php b/inc/managers/class-customer-manager.php index 11fab65..ef1c854 100644 --- a/inc/managers/class-customer-manager.php +++ b/inc/managers/class-customer-manager.php @@ -11,9 +11,9 @@ namespace WP_Ultimo\Managers; -use \WP_Ultimo\Managers\Base_Manager; -use \WP_Ultimo\Models\Customer; -use \WP_Ultimo\Database\Memberships\Membership_Status; +use WP_Ultimo\Managers\Base_Manager; +use WP_Ultimo\Models\Customer; +use WP_Ultimo\Database\Memberships\Membership_Status; // Exit if accessed directly defined('ABSPATH') || exit; @@ -25,7 +25,9 @@ defined('ABSPATH') || exit; */ class Customer_Manager extends Base_Manager { - use \WP_Ultimo\Apis\Rest_Api, \WP_Ultimo\Apis\WP_CLI, \WP_Ultimo\Traits\Singleton; + use \WP_Ultimo\Apis\Rest_Api; + use \WP_Ultimo\Apis\WP_CLI; + use \WP_Ultimo\Traits\Singleton; /** * The manager slug. @@ -55,11 +57,16 @@ class Customer_Manager extends Base_Manager { $this->enable_wp_cli(); - add_action('init', function () { - Event_Manager::register_model_events( 'customer', - __( 'Customer', 'wp-ultimo' ), - array( 'created', 'updated' ) ); - }); + add_action( + 'init', + function () { + Event_Manager::register_model_events( + 'customer', + __('Customer', 'wp-ultimo'), + array('created', 'updated') + ); + } + ); add_action('wp_login', array($this, 'log_ip_and_last_login'), 10, 2); add_filter('heartbeat_send', array($this, 'on_heartbeat_send')); @@ -71,8 +78,7 @@ class Customer_Manager extends Base_Manager { add_action('wu_maybe_create_customer', array($this, 'maybe_add_to_main_site'), 10, 2); add_action('wp_ajax_wu_resend_verification_email', array($this, 'handle_resend_verification_email')); - - } // end init; + } /** * Handle the resend verification email ajax action. @@ -82,31 +88,26 @@ class Customer_Manager extends Base_Manager { */ public function handle_resend_verification_email() { - if (!check_ajax_referer('wu_resend_verification_email_nonce', false, false)) { - + if ( ! check_ajax_referer('wu_resend_verification_email_nonce', false, false)) { wp_send_json_error(new \WP_Error('not-allowed', __('Error: you are not allowed to perform this action.', 'wp-ultimo'))); exit; - - } // end if; + } $customer = wu_get_current_customer(); - if (!$customer) { - + if ( ! $customer) { wp_send_json_error(new \WP_Error('customer-not-found', __('Error: customer not found.', 'wp-ultimo'))); exit; - - } // end if; + } $customer->send_verification_email(); wp_send_json_success(); exit; - - } // end handle_resend_verification_email; + } /** * Handle heartbeat response sent. @@ -121,8 +122,7 @@ class Customer_Manager extends Base_Manager { $this->log_ip_and_last_login(wp_get_current_user()); return $response; - - } // end on_heartbeat_send; + } /** * Saves the IP address and last_login date onto the user. @@ -134,29 +134,22 @@ class Customer_Manager extends Base_Manager { */ public function log_ip_and_last_login($user) { - if (!is_a($user, '\WP_User')) { - + if ( ! is_a($user, '\WP_User')) { $user = get_user_by('login', $user); + } - } // end if; - - if (!$user) { - + if ( ! $user) { return; - - } // end if; + } $customer = wu_get_customer_by_user_id($user->ID); - if (!$customer) { - + if ( ! $customer) { return; - - } // end if; + } $customer->update_last_login(); - - } // end log_ip_and_last_login; + } /** * Watches the change in customer verification status to take action when needed. @@ -171,20 +164,15 @@ class Customer_Manager extends Base_Manager { public function transition_customer_email_verification($old_status, $new_status, $customer_id) { if ($new_status !== 'pending') { - return; - - } // end if; + } $customer = wu_get_customer($customer_id); if ($customer) { - $customer->send_verification_email(); - - } // end if; - - } // end transition_customer_email_verification; + } + } /** * Verifies a customer by checking the email key. @@ -200,72 +188,58 @@ class Customer_Manager extends Base_Manager { $email_verify_key = wu_request('email-verification-key'); - if (!$email_verify_key) { - + if ( ! $email_verify_key) { return; - - } // end if; + } $customer_hash = wu_request('customer'); $customer_to_verify = wu_get_customer_by_hash($customer_hash); - if (!is_user_logged_in()) { - + if ( ! is_user_logged_in()) { wp_die( sprintf( /* translators: the placeholder is the login URL */ __('You must be authenticated in order to verify your email address. Click here to access your account.', 'wp-ultimo'), - wp_login_url(add_query_arg( - array( - 'email-verification-key' => $email_verify_key, - 'customer' => $customer_hash, + wp_login_url( + add_query_arg( + array( + 'email-verification-key' => $email_verify_key, + 'customer' => $customer_hash, + ) ) - )) + ) ) ); + } - } // end if; - - if (!$customer_to_verify) { - + if ( ! $customer_to_verify) { wp_die(__('Invalid verification key.', 'wp-ultimo')); - - } // end if; + } $current_customer = wu_get_current_customer(); - if (!$current_customer) { - + if ( ! $current_customer) { wp_die(__('Invalid verification key.', 'wp-ultimo')); - - } // end if; + } if ($current_customer->get_id() !== $customer_to_verify->get_id()) { - wp_die(__('Invalid verification key.', 'wp-ultimo')); - - } // end if; + } if ($customer_to_verify->get_email_verification() !== 'pending') { - wp_die(__('Invalid verification key.', 'wp-ultimo')); - - } // end if; + } $key = $customer_to_verify->get_verification_key(); - if (!$key) { - + if ( ! $key) { wp_die(__('Invalid verification key.', 'wp-ultimo')); - - } // end if; + } if ($key !== $email_verify_key) { - wp_die(__('Invalid verification key.', 'wp-ultimo')); - - } // end if; + } /* * Uff! If we got here, we can verify the customer. @@ -285,52 +259,44 @@ class Customer_Manager extends Base_Manager { * which one to manage. */ if (count($memberships) === 1) { - $membership = current($memberships); /* * Only publish pending memberships */ if ($membership->get_status() === Membership_Status::PENDING) { - $membership->publish_pending_site_async(); if ($membership->get_date_trial_end() <= gmdate('Y-m-d 23:59:59')) { - $membership->set_status(Membership_Status::ACTIVE); - - } // end if; + } $membership->save(); - } elseif ($membership->get_status() === Membership_Status::TRIALING) { - $membership->publish_pending_site_async(); - - } // end if; + } $payments = $membership->get_payments(); if ($payments) { - - $redirect_url = add_query_arg(array( - 'payment' => $payments[0]->get_hash(), - 'status' => 'done', - ), wu_get_registration_url()); + $redirect_url = add_query_arg( + array( + 'payment' => $payments[0]->get_hash(), + 'status' => 'done', + ), + wu_get_registration_url() + ); wp_redirect($redirect_url); exit; - - } // end if; - - } // end if; + } + } wp_redirect(get_admin_url($customer_to_verify->get_primary_site_id())); exit; - - } // end maybe_verify_email_address; + } /** * Maybe adds the customer to the main site. @@ -343,24 +309,18 @@ class Customer_Manager extends Base_Manager { */ public function maybe_add_to_main_site($customer, $checkout) { - if (!wu_get_setting('add_users_to_main_site')) { - + if ( ! wu_get_setting('add_users_to_main_site')) { return; - - } // end if; + } $user_id = $customer->get_user_id(); $is_already_user = is_user_member_of_blog($user_id, wu_get_main_site_id()); if ($is_already_user === false) { - $role = wu_get_setting('main_site_default_role', 'subscriber'); add_user_to_blog(wu_get_main_site_id(), $user_id, $role); - - } // end if; - - } // end maybe_add_to_main_site; - -} // end class Customer_Manager; + } + } +} diff --git a/inc/managers/class-discount-code-manager.php b/inc/managers/class-discount-code-manager.php index a3d2577..ae5db16 100644 --- a/inc/managers/class-discount-code-manager.php +++ b/inc/managers/class-discount-code-manager.php @@ -24,7 +24,9 @@ defined('ABSPATH') || exit; */ class Discount_Code_Manager extends Base_Manager { - use \WP_Ultimo\Apis\Rest_Api, \WP_Ultimo\Apis\WP_CLI, \WP_Ultimo\Traits\Singleton; + use \WP_Ultimo\Apis\Rest_Api; + use \WP_Ultimo\Apis\WP_CLI; + use \WP_Ultimo\Traits\Singleton; /** * The manager slug. @@ -55,8 +57,7 @@ class Discount_Code_Manager extends Base_Manager { $this->enable_wp_cli(); add_action('wu_gateway_payment_processed', array($this, 'maybe_add_use_on_payment_received')); - - } // end init; + } /** * Listens for payments received in order to increase the discount code uses. @@ -68,11 +69,9 @@ class Discount_Code_Manager extends Base_Manager { */ public function maybe_add_use_on_payment_received($payment) { - if (!$payment) { - + if ( ! $payment) { return; - - } // end if; + } /* * Try to fetch the original cart of the payment. @@ -82,18 +81,14 @@ class Discount_Code_Manager extends Base_Manager { $original_cart = $payment->get_meta('wu_original_cart'); if (is_a($original_cart, \WP_Ultimo\Checkout\Cart::class) === false) { - return; - - } // end if; + } $discount_code = $original_cart->get_discount_code(); - if (!$discount_code) { - + if ( ! $discount_code) { return; - - } // end if; + } /* * Refetch the object, as the original version @@ -102,13 +97,9 @@ class Discount_Code_Manager extends Base_Manager { $discount_code = wu_get_discount_code($discount_code->get_id()); if ($discount_code) { - $discount_code->add_use(); $discount_code->save(); - - } // end if; - - } // end maybe_add_use_on_payment_received; - -} // end class Discount_Code_Manager; + } + } +} diff --git a/inc/managers/class-domain-manager.php b/inc/managers/class-domain-manager.php index b2a7f21..2096c0b 100644 --- a/inc/managers/class-domain-manager.php +++ b/inc/managers/class-domain-manager.php @@ -25,7 +25,9 @@ defined('ABSPATH') || exit; */ class Domain_Manager extends Base_Manager { - use \WP_Ultimo\Apis\Rest_Api, \WP_Ultimo\Apis\WP_CLI, \WP_Ultimo\Traits\Singleton; + use \WP_Ultimo\Apis\Rest_Api; + use \WP_Ultimo\Apis\WP_CLI; + use \WP_Ultimo\Traits\Singleton; /** * The manager slug. @@ -62,8 +64,7 @@ class Domain_Manager extends Base_Manager { public function get_integrations() { return apply_filters('wu_domain_manager_get_integrations', $this->integrations, $this); - - } // end get_integrations; + } /** * Get the instance of one of the integrations classes. @@ -77,17 +78,14 @@ class Domain_Manager extends Base_Manager { $integrations = $this->get_integrations(); - if (isset($integrations[$id])) { - - $class_name = $integrations[$id]; + if (isset($integrations[ $id ])) { + $class_name = $integrations[ $id ]; return $class_name::get_instance(); - - } // end if; + } return false; - - } // end get_integration_instance; + } /** * Instantiate the necessary hooks. @@ -134,8 +132,7 @@ class Domain_Manager extends Base_Manager { add_action('wp_insert_site', array($this, 'handle_site_created')); add_action('wp_delete_site', array($this, 'handle_site_deleted')); - - } // end init; + } /** * Set COOKIE_DOMAIN if not defined in sites with mapped domains. @@ -146,13 +143,10 @@ class Domain_Manager extends Base_Manager { */ protected function set_cookie_domain() { - if (defined('DOMAIN_CURRENT_SITE') && !defined('COOKIE_DOMAIN') && !preg_match('/' . DOMAIN_CURRENT_SITE . '$/', '.' . $_SERVER['HTTP_HOST'])) { - - define( 'COOKIE_DOMAIN', '.' . $_SERVER['HTTP_HOST'] ); - - } // end if; - - } // end set_cookie_domain; + if (defined('DOMAIN_CURRENT_SITE') && ! defined('COOKIE_DOMAIN') && ! preg_match('/' . DOMAIN_CURRENT_SITE . '$/', '.' . $_SERVER['HTTP_HOST'])) { + define('COOKIE_DOMAIN', '.' . $_SERVER['HTTP_HOST']); + } + } /** * Triggers subdomain mapping events on site creation. @@ -168,11 +162,9 @@ class Domain_Manager extends Base_Manager { $has_subdomain = str_replace($current_site->domain, '', $site->domain); - if (!$has_subdomain) { - + if ( ! $has_subdomain) { return; - - } // end if; + } $args = array( 'subdomain' => $site->domain, @@ -180,8 +172,7 @@ class Domain_Manager extends Base_Manager { ); wu_enqueue_async_action('wu_add_subdomain', $args, 'domain'); - - } // end handle_site_created; + } /** * Triggers subdomain mapping events on site deletion. @@ -197,11 +188,9 @@ class Domain_Manager extends Base_Manager { $has_subdomain = str_replace($current_site->domain, '', $site->domain); - if (!$has_subdomain) { - + if ( ! $has_subdomain) { return; - - } // end if; + } $args = array( 'subdomain' => $site->domain, @@ -209,8 +198,7 @@ class Domain_Manager extends Base_Manager { ); wu_enqueue_async_action('wu_remove_subdomain', $args, 'domain'); - - } // end handle_site_deleted; + } /** * Triggers the do_event of the payment successful. @@ -232,8 +220,7 @@ class Domain_Manager extends Base_Manager { ); wu_do_event('domain_created', $payload); - - } // end handle_domain_created; + } /** * Remove send domain removal event. @@ -247,17 +234,14 @@ class Domain_Manager extends Base_Manager { public function handle_domain_deleted($result, $domain) { if ($result) { - $args = array( 'domain' => $domain->get_domain(), 'site_id' => $domain->get_site_id(), ); wu_enqueue_async_action('wu_remove_domain', $args, 'domain'); - - } // end if; - - } // end handle_domain_deleted; + } + } /** * Add all domain mapping settings. @@ -267,59 +251,78 @@ class Domain_Manager extends Base_Manager { */ public function add_domain_mapping_settings() { - wu_register_settings_field('domain-mapping', 'domain_mapping_header', array( - 'title' => __('Domain Mapping Settings', 'wp-ultimo'), - 'desc' => __('Define the domain mapping settings for your network.', 'wp-ultimo'), - 'type' => 'header', - )); + wu_register_settings_field( + 'domain-mapping', + 'domain_mapping_header', + array( + 'title' => __('Domain Mapping Settings', 'wp-ultimo'), + 'desc' => __('Define the domain mapping settings for your network.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - wu_register_settings_field('domain-mapping', 'enable_domain_mapping', array( - 'title' => __('Enable Domain Mapping?', 'wp-ultimo'), - 'desc' => __('Do you want to enable domain mapping?', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + wu_register_settings_field( + 'domain-mapping', + 'enable_domain_mapping', + array( + 'title' => __('Enable Domain Mapping?', 'wp-ultimo'), + 'desc' => __('Do you want to enable domain mapping?', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); - wu_register_settings_field('domain-mapping', 'force_admin_redirect', array( - 'title' => __('Force Admin Redirect', 'wp-ultimo'), - 'desc' => __('Select how you want your users to access the admin panel if they have mapped domains.', 'wp-ultimo') . '

    ' . __('Force Redirect to Mapped Domain: your users with mapped domains will be redirected to theirdomain.com/wp-admin, even if they access using yournetworkdomain.com/wp-admin.', 'wp-ultimo') . '

    ' . __('Force Redirect to Network Domain: your users with mapped domains will be redirect to yournetworkdomain.com/wp-admin, even if they access using theirdomain.com/wp-admin.', 'wp-ultimo'), - 'tooltip' => '', - 'type' => 'select', - 'default' => 'both', - 'require' => array('enable_domain_mapping' => 1), - 'options' => array( - 'both' => __('Allow access to the admin by both mapped domain and network domain', 'wp-ultimo'), - 'force_map' => __('Force Redirect to Mapped Domain', 'wp-ultimo'), - 'force_network' => __('Force Redirect to Network Domain', 'wp-ultimo'), - ), - )); + wu_register_settings_field( + 'domain-mapping', + 'force_admin_redirect', + array( + 'title' => __('Force Admin Redirect', 'wp-ultimo'), + 'desc' => __('Select how you want your users to access the admin panel if they have mapped domains.', 'wp-ultimo') . '

    ' . __('Force Redirect to Mapped Domain: your users with mapped domains will be redirected to theirdomain.com/wp-admin, even if they access using yournetworkdomain.com/wp-admin.', 'wp-ultimo') . '

    ' . __('Force Redirect to Network Domain: your users with mapped domains will be redirect to yournetworkdomain.com/wp-admin, even if they access using theirdomain.com/wp-admin.', 'wp-ultimo'), + 'tooltip' => '', + 'type' => 'select', + 'default' => 'both', + 'require' => array('enable_domain_mapping' => 1), + 'options' => array( + 'both' => __('Allow access to the admin by both mapped domain and network domain', 'wp-ultimo'), + 'force_map' => __('Force Redirect to Mapped Domain', 'wp-ultimo'), + 'force_network' => __('Force Redirect to Network Domain', 'wp-ultimo'), + ), + ) + ); - wu_register_settings_field('domain-mapping', 'custom_domains', array( - 'title' => __('Enable Custom Domains?', 'wp-ultimo'), - 'desc' => __('Toggle this option if you wish to allow end-customers to add their own domains. This can be controlled on a plan per plan basis.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - 'require' => array( - 'enable_domain_mapping' => true, - ), - )); + wu_register_settings_field( + 'domain-mapping', + 'custom_domains', + array( + 'title' => __('Enable Custom Domains?', 'wp-ultimo'), + 'desc' => __('Toggle this option if you wish to allow end-customers to add their own domains. This can be controlled on a plan per plan basis.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + 'require' => array( + 'enable_domain_mapping' => true, + ), + ) + ); - wu_register_settings_field('domain-mapping', 'domain_mapping_instructions', array( - 'title' => __('Add New Domain Instructions', 'wp-ultimo'), - 'tooltip' => __('Display a customized message with instructions for the mapping and alerting the end-user of the risks of mapping a misconfigured domain.', 'wp-ultimo'), - 'desc' => __('You can use the placeholder %NETWORK_DOMAIN% and %NETWORK_IP%.', 'wp-ultimo'), - 'type' => 'textarea', - 'default' => array($this, 'default_domain_mapping_instructions'), - 'html_attr' => array( - 'rows' => 8, - ), - 'require' => array( - 'enable_domain_mapping' => true, - 'custom_domains' => true, - ), - )); - - } // end add_domain_mapping_settings; + wu_register_settings_field( + 'domain-mapping', + 'domain_mapping_instructions', + array( + 'title' => __('Add New Domain Instructions', 'wp-ultimo'), + 'tooltip' => __('Display a customized message with instructions for the mapping and alerting the end-user of the risks of mapping a misconfigured domain.', 'wp-ultimo'), + 'desc' => __('You can use the placeholder %NETWORK_DOMAIN% and %NETWORK_IP%.', 'wp-ultimo'), + 'type' => 'textarea', + 'default' => array($this, 'default_domain_mapping_instructions'), + 'html_attr' => array( + 'rows' => 8, + ), + 'require' => array( + 'enable_domain_mapping' => true, + 'custom_domains' => true, + ), + ) + ); + } /** * Add all SSO settings. @@ -329,40 +332,55 @@ class Domain_Manager extends Base_Manager { */ public function add_sso_settings() { - wu_register_settings_field('sso', 'sso_header', array( - 'title' => __('Single Sign-On Settings', 'wp-ultimo'), - 'desc' => __('Settings to configure the Single Sign-On functionality of WP Multisite WaaS, responsible for keeping customers and admins logged in across all network domains.', 'wp-ultimo'), - 'type' => 'header', - )); + wu_register_settings_field( + 'sso', + 'sso_header', + array( + 'title' => __('Single Sign-On Settings', 'wp-ultimo'), + 'desc' => __('Settings to configure the Single Sign-On functionality of WP Multisite WaaS, responsible for keeping customers and admins logged in across all network domains.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - wu_register_settings_field('sso', 'enable_sso', array( - 'title' => __('Enable Single Sign-On', 'wp-ultimo'), - 'desc' => __('Enables the Single Sign-on functionality.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + wu_register_settings_field( + 'sso', + 'enable_sso', + array( + 'title' => __('Enable Single Sign-On', 'wp-ultimo'), + 'desc' => __('Enables the Single Sign-on functionality.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); - wu_register_settings_field('sso', 'restrict_sso_to_login_pages', array( - 'title' => __('Restrict SSO Checks to Login Pages', 'wp-ultimo'), - 'desc' => __('The Single Sign-on feature adds one extra ajax calls to every page load on sites with custom domains active to check if it should perform an auth loopback. You can restrict these extra calls to the login pages of sub-sites using this option. If enabled, SSO will only work on login pages.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - 'require' => array( - 'enable_sso' => true, - ), - )); + wu_register_settings_field( + 'sso', + 'restrict_sso_to_login_pages', + array( + 'title' => __('Restrict SSO Checks to Login Pages', 'wp-ultimo'), + 'desc' => __('The Single Sign-on feature adds one extra ajax calls to every page load on sites with custom domains active to check if it should perform an auth loopback. You can restrict these extra calls to the login pages of sub-sites using this option. If enabled, SSO will only work on login pages.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + 'require' => array( + 'enable_sso' => true, + ), + ) + ); - wu_register_settings_field('sso', 'enable_sso_loading_overlay', array( - 'title' => __('Enable SSO Loading Overlay', 'wp-ultimo'), - 'desc' => __('When active, a loading overlay will be added on-top of the site currently being viewed while the SSO auth loopback is performed on the background.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - 'require' => array( - 'enable_sso' => true, - ), - )); - - } // end add_sso_settings; + wu_register_settings_field( + 'sso', + 'enable_sso_loading_overlay', + array( + 'title' => __('Enable SSO Loading Overlay', 'wp-ultimo'), + 'desc' => __('When active, a loading overlay will be added on-top of the site currently being viewed while the SSO auth loopback is performed on the background.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + 'require' => array( + 'enable_sso' => true, + ), + ) + ); + } /** * Returns the default instructions for domain mapping. * @@ -379,8 +397,7 @@ class Domain_Manager extends Base_Manager { $instructions[] = __('After you finish that step, come back to this screen and click the button below.', 'wp-ultimo'); return implode(PHP_EOL . PHP_EOL, $instructions); - - } // end default_domain_mapping_instructions; + } /** * Gets the instructions, filtered and without the shortcodes. @@ -394,11 +411,9 @@ class Domain_Manager extends Base_Manager { $instructions = wu_get_setting('domain_mapping_instructions'); - if (!$instructions) { - + if ( ! $instructions) { $instructions = $this->default_domain_mapping_instructions(); - - } // end if; + } $domain = $current_site->domain; $ip = Helper::get_network_public_ip(); @@ -410,8 +425,7 @@ class Domain_Manager extends Base_Manager { $instructions = str_replace('%NETWORK_IP%', $ip, $instructions); return apply_filters('wu_get_domain_mapping_instructions', $instructions, $domain, $ip); - - } // end get_domain_mapping_instructions; + } /** * Creates the event to save the transition. @@ -426,7 +440,6 @@ class Domain_Manager extends Base_Manager { public function send_domain_to_host($old_value, $new_value, $item_id) { if ($old_value !== $new_value) { - $domain = wu_get_domain($item_id); $args = array( @@ -435,10 +448,8 @@ class Domain_Manager extends Base_Manager { ); wu_enqueue_async_action('wu_add_domain', $args, 'domain'); - - } // end if; - - } // end send_domain_to_host; + } + } /** * Checks the DNS and SSL status of a domain. @@ -453,17 +464,15 @@ class Domain_Manager extends Base_Manager { $domain = wu_get_domain($domain_id); - if (!$domain) { - + if ( ! $domain) { return; - - } // end if; + } $max_tries = apply_filters('wu_async_process_domain_stage_max_tries', 5, $domain); $try_again_time = apply_filters('wu_async_process_domains_try_again_time', 5, $domain); // minutes - $tries++; + ++$tries; $stage = $domain->get_stage(); @@ -473,9 +482,7 @@ class Domain_Manager extends Base_Manager { wu_log_add("domain-{$domain_url}", sprintf(__('Starting Check for %s', 'wp-ultimo'), $domain_url)); if ($stage === 'checking-dns') { - if ($domain->has_correct_dns()) { - $domain->set_stage('checking-ssl-cert'); $domain->save(); @@ -485,18 +492,23 @@ class Domain_Manager extends Base_Manager { __('- DNS propagation finished, advancing domain to next step...', 'wp-ultimo') ); - wu_enqueue_async_action('wu_async_process_domain_stage', array('domain_id' => $domain_id, 'tries' => 0), 'domain'); + wu_enqueue_async_action( + 'wu_async_process_domain_stage', + array( + 'domain_id' => $domain_id, + 'tries' => 0, + ), + 'domain' + ); do_action('wu_domain_manager_dns_propagation_finished', $domain); return; - } else { /* * Max attempts */ if ($tries > $max_tries) { - $domain->set_stage('failed'); $domain->save(); @@ -508,8 +520,7 @@ class Domain_Manager extends Base_Manager { ); return; - - } // end if; + } wu_log_add( "domain-{$domain_url}", @@ -528,13 +539,9 @@ class Domain_Manager extends Base_Manager { ); return; - - } // end if; - + } } elseif ($stage === 'checking-ssl-cert') { - if ($domain->has_valid_ssl_certificate()) { - $domain->set_stage('done'); $domain->set_secure(true); @@ -547,13 +554,11 @@ class Domain_Manager extends Base_Manager { ); return; - } else { /* * Max attempts */ if ($tries > $max_tries) { - $domain->set_stage('done-without-ssl'); $domain->save(); @@ -565,8 +570,7 @@ class Domain_Manager extends Base_Manager { ); return; - - } // end if; + } wu_log_add( "domain-{$domain_url}", @@ -574,15 +578,20 @@ class Domain_Manager extends Base_Manager { sprintf(__('- SSL Cert not found, retrying in %d minute(s)...', 'wp-ultimo'), $try_again_time) ); - wu_schedule_single_action(strtotime("+{$try_again_time} minutes"), 'wu_async_process_domain_stage', array('domain_id' => $domain_id, 'tries' => $tries), 'domain'); + wu_schedule_single_action( + strtotime("+{$try_again_time} minutes"), + 'wu_async_process_domain_stage', + array( + 'domain_id' => $domain_id, + 'tries' => $tries, + ), + 'domain' + ); return; - - } // end if; - - } // end if; - - } // end async_process_domain_stage; + } + } + } /** * Alternative implementation for PHP's native dns_get_record. @@ -606,7 +615,6 @@ class Domain_Manager extends Base_Manager { ); foreach ($record_types as $record_type) { - $chain = new \RemotelyLiving\PHPDNS\Resolvers\Chain( new \RemotelyLiving\PHPDNS\Resolvers\CloudFlare(), new \RemotelyLiving\PHPDNS\Resolvers\GoogleDNS(), @@ -617,7 +625,6 @@ class Domain_Manager extends Base_Manager { $records = $chain->getRecords($domain, $record_type); foreach ($records as $record_data) { - $record = array(); $record['type'] = $record_type; @@ -625,10 +632,8 @@ class Domain_Manager extends Base_Manager { $record['data'] = (string) $record_data->getData(); if (empty($record['data'])) { - $record['data'] = (string) $record_data->getIPAddress(); - - } // end if; + } // Some DNS providers return a trailing dot. $record['data'] = rtrim($record['data'], '.'); @@ -642,14 +647,11 @@ class Domain_Manager extends Base_Manager { $record['tag'] = ''; // Used by integrations. $results[] = $record; - - } // end foreach; - - } // end foreach; + } + } return apply_filters('wu_domain_dns_get_record', $results, $domain); - - } // end dns_get_record; + } /** * Get the DNS records for a given domain. @@ -661,42 +663,41 @@ class Domain_Manager extends Base_Manager { $domain = wu_request('domain'); - if (!$domain) { - + if ( ! $domain) { wp_send_json_error(new \WP_Error('domain-missing', __('A valid domain was not passed.', 'wp-ultimo'))); - - } // end if; + } $auth_ns = array(); $additional = array(); try { - $result = self::dns_get_record($domain); - } catch (\Throwable $e) { - - wp_send_json_error(new \WP_Error('error', __('Not able to fetch DNS entries.', 'wp-ultimo'), array( - 'exception' => $e->getMessage(), - ))); - - } // end try; + wp_send_json_error( + new \WP_Error( + 'error', + __('Not able to fetch DNS entries.', 'wp-ultimo'), + array( + 'exception' => $e->getMessage(), + ) + ) + ); + } if ($result === false) { - wp_send_json_error(new \WP_Error('error', __('Not able to fetch DNS entries.', 'wp-ultimo'))); + } - } // end if; - - wp_send_json_success(array( - 'entries' => $result, - 'auth' => $auth_ns, - 'additional' => $additional, - 'network_ip' => Helper::get_network_public_ip(), - )); - - } // end get_dns_records; + wp_send_json_success( + array( + 'entries' => $result, + 'auth' => $auth_ns, + 'additional' => $additional, + 'network_ip' => Helper::get_network_public_ip(), + ) + ); + } /** * Takes the list of domains and set them to non-primary when a new primary is added. @@ -711,20 +712,15 @@ class Domain_Manager extends Base_Manager { public function async_remove_old_primary_domains($domains) { foreach ($domains as $domain_id) { - $domain = wu_get_domain($domain_id); if ($domain) { - $domain->set_primary_domain(false); $domain->save(); - - } // end if; - - } // end foreach; - - } // end async_remove_old_primary_domains; + } + } + } /** * Tests the integration in the Wizard context. @@ -738,31 +734,30 @@ class Domain_Manager extends Base_Manager { $integration = $this->get_integration_instance($integration_id); - if (!$integration) { - - wp_send_json_error(array( - 'message' => __('Invalid Integration ID', 'wp-ultimo'), - )); - - } // end if; + if ( ! $integration) { + wp_send_json_error( + array( + 'message' => __('Invalid Integration ID', 'wp-ultimo'), + ) + ); + } /* * Checks for the constants... */ - if (!$integration->is_setup()) { - - wp_send_json_error(array( - 'message' => sprintf( - __('The necessary constants were not found on your wp-config.php file: %s', 'wp-ultimo'), - implode(', ', $integration->get_missing_constants()) - ), - )); - - } // end if; + if ( ! $integration->is_setup()) { + wp_send_json_error( + array( + 'message' => sprintf( + __('The necessary constants were not found on your wp-config.php file: %s', 'wp-ultimo'), + implode(', ', $integration->get_missing_constants()) + ), + ) + ); + } return $integration->test_connection(); - - } // end test_integration; + } /** * Loads all the host provider integrations we have available. @@ -818,11 +813,9 @@ class Domain_Manager extends Base_Manager { /** * Allow developers to add their own host provider integrations via wp plugins. - * + * * @since 2.0.0 */ do_action('wp_ultimo_host_providers_load'); - - } // end load_integrations; - -} // end class Domain_Manager; + } +} diff --git a/inc/managers/class-email-manager.php b/inc/managers/class-email-manager.php index fc8634a..6086f77 100644 --- a/inc/managers/class-email-manager.php +++ b/inc/managers/class-email-manager.php @@ -12,10 +12,10 @@ namespace WP_Ultimo\Managers; use Psr\Log\LogLevel; -use \WP_Ultimo\Managers\Base_Manager; -use \WP_Ultimo\Models\Email; -use \WP_Ultimo\Helpers\Sender; -use \WP_Ultimo\Models\Base_Model; +use WP_Ultimo\Managers\Base_Manager; +use WP_Ultimo\Models\Email; +use WP_Ultimo\Helpers\Sender; +use WP_Ultimo\Models\Base_Model; // Exit if accessed directly defined('ABSPATH') || exit; @@ -27,7 +27,9 @@ defined('ABSPATH') || exit; */ class Email_Manager extends Base_Manager { - use \WP_Ultimo\Apis\Rest_Api, \WP_Ultimo\Apis\WP_CLI, \WP_Ultimo\Traits\Singleton; + use \WP_Ultimo\Apis\Rest_Api; + use \WP_Ultimo\Apis\WP_CLI; + use \WP_Ultimo\Traits\Singleton; /** * The manager slug. @@ -65,9 +67,12 @@ class Email_Manager extends Base_Manager { $this->enable_wp_cli(); - add_action('init', function () { - $this->register_all_default_system_emails(); - }); + add_action( + 'init', + function () { + $this->register_all_default_system_emails(); + } + ); /* * Adds the Email fields @@ -87,8 +92,7 @@ class Email_Manager extends Base_Manager { add_action('wp_mail_failed', array($this, 'log_mailer_failure')); add_action('wp_ajax_wu_get_event_payload_placeholders', array($this, 'get_event_placeholders')); - - } // end init; + } /** * Send the email related to the current event. @@ -99,9 +103,11 @@ class Email_Manager extends Base_Manager { */ public function send_system_email($slug, $payload) { - $all_emails = wu_get_emails(array( - 'event' => $slug, - )); + $all_emails = wu_get_emails( + array( + 'event' => $slug, + ) + ); $original_from = array( 'name' => wu_get_setting('from_name'), @@ -112,19 +118,14 @@ class Email_Manager extends Base_Manager { * Loop through all the emails registered. */ foreach ($all_emails as $email) { - if ($email->get_custom_sender()) { - $from = array( 'name' => $email->get_custom_sender_name(), 'email' => $email->get_custom_sender_email(), ); - } else { - $from = $original_from; - - } // end if; + } /* * Compiles the target list. @@ -132,12 +133,10 @@ class Email_Manager extends Base_Manager { $to = $email->get_target_list($payload); if (empty($to)) { - wu_log_add('mailer', __('No targets found.', 'wp-ultimo')); return; - - } // end if; + } $args = array( 'style' => $email->get_style(), @@ -150,26 +149,20 @@ class Email_Manager extends Base_Manager { * Add the invoice attachment, if need be. */ if (wu_get_isset($payload, 'payment_invoice_url') && wu_get_setting('attach_invoice_pdf', true)) { - $file_name = 'invoice-' . $payload['payment_reference_code'] . '.pdf'; $this->attach_file_by_url($payload['payment_invoice_url'], $file_name, $args['subject']); - - } // end if; + } $when_to_send = $email->get_when_to_send(); if ($when_to_send) { - $args['schedule'] = $when_to_send; - - } // end if; + } Sender::send_mail($from, $to, $args); - - } // end foreach; - - } // end send_system_email; + } + } /** * Attach a file by a URL @@ -183,34 +176,35 @@ class Email_Manager extends Base_Manager { */ public function attach_file_by_url($file_url, $file_name, $email_subject = '') { - add_action('phpmailer_init', function($mail) use ($file_url, $file_name, $email_subject) { + add_action( + 'phpmailer_init', + function ($mail) use ($file_url, $file_name, $email_subject) { if ($email_subject && $mail->Subject !== $email_subject) { // phpcs:ignore - return; + return; + } - } // end if; + $response = wp_remote_get( + $file_url, + array( + 'timeout' => 50, + ) + ); - $response = wp_remote_get($file_url, array( - 'timeout' => 50, - )); + if (is_wp_error($response)) { + return; + } - if (is_wp_error($response)) { + $file = wp_remote_retrieve_body($response); - return; - - } // end if; - - $file = wp_remote_retrieve_body($response); - - /* - * Use the default PHPMailer APIs to attach the file. - */ - $mail->addStringAttachment($file, $file_name); - - }); - - } // end attach_file_by_url; + /* + * Use the default PHPMailer APIs to attach the file. + */ + $mail->addStringAttachment($file, $file_name); + } + ); + } /** * Add all email fields. @@ -220,71 +214,98 @@ class Email_Manager extends Base_Manager { */ public function add_email_fields() { - wu_register_settings_field('emails', 'sender_header', array( - 'title' => __('Sender Settings', 'wp-ultimo'), - 'desc' => __('Change the settings of the email headers, like from and name.', 'wp-ultimo'), - 'type' => 'header', - )); + wu_register_settings_field( + 'emails', + 'sender_header', + array( + 'title' => __('Sender Settings', 'wp-ultimo'), + 'desc' => __('Change the settings of the email headers, like from and name.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - wu_register_settings_field('emails', 'from_name', array( - 'title' => __('"From" Name', 'wp-ultimo'), - 'desc' => __('How the sender name will appear in emails sent by WP Multisite WaaS.', 'wp-ultimo'), - 'type' => 'text', - 'placeholder' => get_network_option(null, 'site_name'), - 'default' => get_network_option(null, 'site_name'), - 'html_attr' => array( - 'v-model' => 'from_name', - ), - )); + wu_register_settings_field( + 'emails', + 'from_name', + array( + 'title' => __('"From" Name', 'wp-ultimo'), + 'desc' => __('How the sender name will appear in emails sent by WP Multisite WaaS.', 'wp-ultimo'), + 'type' => 'text', + 'placeholder' => get_network_option(null, 'site_name'), + 'default' => get_network_option(null, 'site_name'), + 'html_attr' => array( + 'v-model' => 'from_name', + ), + ) + ); - wu_register_settings_field('emails', 'from_email', array( - 'title' => __('"From" E-mail', 'wp-ultimo'), - 'desc' => __('How the sender email will appear in emails sent by WP Multisite WaaS.', 'wp-ultimo'), - 'type' => 'email', - 'placeholder' => get_network_option(null, 'admin_email'), - 'default' => get_network_option(null, 'admin_email'), - 'html_attr' => array( - 'v-model' => 'from_email', - ), - )); + wu_register_settings_field( + 'emails', + 'from_email', + array( + 'title' => __('"From" E-mail', 'wp-ultimo'), + 'desc' => __('How the sender email will appear in emails sent by WP Multisite WaaS.', 'wp-ultimo'), + 'type' => 'email', + 'placeholder' => get_network_option(null, 'admin_email'), + 'default' => get_network_option(null, 'admin_email'), + 'html_attr' => array( + 'v-model' => 'from_email', + ), + ) + ); - wu_register_settings_field('emails', 'template_header', array( - 'title' => __('Template Settings', 'wp-ultimo'), - 'desc' => __('Change the settings of the email templates.', 'wp-ultimo'), - 'type' => 'header', - )); + wu_register_settings_field( + 'emails', + 'template_header', + array( + 'title' => __('Template Settings', 'wp-ultimo'), + 'desc' => __('Change the settings of the email templates.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - wu_register_settings_field('emails', 'email_template_type', array( - 'title' => __('Email Templates Style', 'wp-ultimo'), - 'desc' => __('Choose if email body will be sent using the HTML template or in plain text.', 'wp-ultimo'), - 'type' => 'select', - 'default' => 'html', - 'options' => array( - 'html' => __('HTML Emails', 'wp-ultimo'), - 'plain' => __('Plain Emails', 'wp-ultimo'), - ), - 'html_attr' => array( - 'v-model' => 'emails_template', - ), - )); + wu_register_settings_field( + 'emails', + 'email_template_type', + array( + 'title' => __('Email Templates Style', 'wp-ultimo'), + 'desc' => __('Choose if email body will be sent using the HTML template or in plain text.', 'wp-ultimo'), + 'type' => 'select', + 'default' => 'html', + 'options' => array( + 'html' => __('HTML Emails', 'wp-ultimo'), + 'plain' => __('Plain Emails', 'wp-ultimo'), + ), + 'html_attr' => array( + 'v-model' => 'emails_template', + ), + ) + ); - wu_register_settings_field('emails', 'expiring_header', array( - 'title' => __('Expiring Notification Settings', 'wp-ultimo'), - 'desc' => __('Change the settings for the expiring notification (trials and subscriptions) emails.', 'wp-ultimo'), - 'type' => 'header', - )); + wu_register_settings_field( + 'emails', + 'expiring_header', + array( + 'title' => __('Expiring Notification Settings', 'wp-ultimo'), + 'desc' => __('Change the settings for the expiring notification (trials and subscriptions) emails.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - wu_register_settings_field('emails', 'expiring_days', array( - 'title' => __('Days to Expire', 'wp-ultimo'), - 'desc' => __('Select when we should send the notification email. If you select 3 days, for example, a notification email will be sent to every membership (or trial period) expiring in the next 3 days. Memberships are checked hourly.', 'wp-ultimo'), - 'type' => 'number', - 'placeholder' => __('e.g. 3', 'wp-ultimo'), - 'html_attr' => array( - 'v-model' => 'expiring_days', - ), - )); - - } // end add_email_fields; + wu_register_settings_field( + 'emails', + 'expiring_days', + array( + 'title' => __('Days to Expire', 'wp-ultimo'), + 'desc' => __('Select when we should send the notification email. If you select 3 days, for example, a notification email will be sent to every membership (or trial period) expiring in the next 3 days. Memberships are checked hourly.', 'wp-ultimo'), + 'type' => 'number', + 'placeholder' => __('e.g. 3', 'wp-ultimo'), + 'html_attr' => array( + 'v-model' => 'expiring_days', + ), + ) + ); + } /** * Register in the global variable all the default system emails. @@ -296,9 +317,8 @@ class Email_Manager extends Base_Manager { */ public function register_default_system_email($args) { - $this->registered_default_system_emails[$args['slug']] = $args; - - } // end register_default_system_email; + $this->registered_default_system_emails[ $args['slug'] ] = $args; + } /** * Create a system email. @@ -311,33 +331,33 @@ class Email_Manager extends Base_Manager { public function create_system_email($args) { if ($this->is_created($args['slug'])) { - return; + } - } // end if; - - $email_args = wp_parse_args($args, array( - 'event' => '', - 'title' => '', - 'content' => '', - 'slug' => '', - 'target' => 'admin', - 'style' => 'use_default', - 'send_copy_to_admin' => true, - 'active' => true, - 'legacy' => false, - 'date_registered' => wu_get_current_time('mysql', true), - 'date_modified' => wu_get_current_time('mysql', true), - 'status' => 'publish' - )); + $email_args = wp_parse_args( + $args, + array( + 'event' => '', + 'title' => '', + 'content' => '', + 'slug' => '', + 'target' => 'admin', + 'style' => 'use_default', + 'send_copy_to_admin' => true, + 'active' => true, + 'legacy' => false, + 'date_registered' => wu_get_current_time('mysql', true), + 'date_modified' => wu_get_current_time('mysql', true), + 'status' => 'publish', + ) + ); $email = new Email($email_args); $saved = $email->save(); return is_wp_error($saved) ? $saved : $email; - - } // end create_system_email; + } /** * Register all default system emails. @@ -351,12 +371,9 @@ class Email_Manager extends Base_Manager { $system_emails = wu_get_default_system_emails(); foreach ($system_emails as $email_key => $email_value) { - $this->create_system_email($email_value); - - } // end foreach; - - } // end create_all_system_emails; + } + } /** * Register all default system emails. @@ -369,83 +386,96 @@ class Email_Manager extends Base_Manager { /* * Payment Successful - Admin */ - $this->register_default_system_email(array( - 'event' => 'payment_received', - 'slug' => 'payment_received_admin', - 'target' => 'admin', - 'title' => __('You got a new payment!', 'wp-ultimo'), - 'content' => wu_get_template_contents('emails/admin/payment-received'), - )); + $this->register_default_system_email( + array( + 'event' => 'payment_received', + 'slug' => 'payment_received_admin', + 'target' => 'admin', + 'title' => __('You got a new payment!', 'wp-ultimo'), + 'content' => wu_get_template_contents('emails/admin/payment-received'), + ) + ); /* * Payment Successful - Customer */ - $this->register_default_system_email(array( - 'event' => 'payment_received', - 'slug' => 'payment_received_customer', - 'target' => 'customer', - 'title' => __('We got your payment!', 'wp-ultimo'), - 'content' => wu_get_template_contents('emails/customer/payment-received'), - )); + $this->register_default_system_email( + array( + 'event' => 'payment_received', + 'slug' => 'payment_received_customer', + 'target' => 'customer', + 'title' => __('We got your payment!', 'wp-ultimo'), + 'content' => wu_get_template_contents('emails/customer/payment-received'), + ) + ); /* * Site Published - Admin */ - $this->register_default_system_email(array( - 'event' => 'site_published', - 'target' => 'admin', - 'slug' => 'site_published_admin', - 'title' => __('A new site was created on your Network!', 'wp-ultimo'), - 'content' => wu_get_template_contents('emails/admin/site-published'), - )); + $this->register_default_system_email( + array( + 'event' => 'site_published', + 'target' => 'admin', + 'slug' => 'site_published_admin', + 'title' => __('A new site was created on your Network!', 'wp-ultimo'), + 'content' => wu_get_template_contents('emails/admin/site-published'), + ) + ); /* * Site Published - Customer */ - $this->register_default_system_email(array( - 'event' => 'site_published', - 'target' => 'customer', - 'slug' => 'site_published_customer', - 'title' => __('Your site is ready!', 'wp-ultimo'), - 'content' => wu_get_template_contents('emails/customer/site-published'), - )); + $this->register_default_system_email( + array( + 'event' => 'site_published', + 'target' => 'customer', + 'slug' => 'site_published_customer', + 'title' => __('Your site is ready!', 'wp-ultimo'), + 'content' => wu_get_template_contents('emails/customer/site-published'), + ) + ); /* * Site Published - Customer */ - $this->register_default_system_email(array( - 'event' => 'confirm_email_address', - 'target' => 'customer', - 'slug' => 'confirm_email_address', - 'title' => __('Confirm your email address!', 'wp-ultimo'), - 'content' => wu_get_template_contents('emails/customer/confirm-email-address'), - )); + $this->register_default_system_email( + array( + 'event' => 'confirm_email_address', + 'target' => 'customer', + 'slug' => 'confirm_email_address', + 'title' => __('Confirm your email address!', 'wp-ultimo'), + 'content' => wu_get_template_contents('emails/customer/confirm-email-address'), + ) + ); /* * Domain Created - Admin */ - $this->register_default_system_email(array( - 'event' => 'domain_created', - 'target' => 'admin', - 'slug' => 'domain_created_admin', - 'title' => __('A new domain was added to your Network!', 'wp-ultimo'), - 'content' => wu_get_template_contents('emails/admin/domain-created'), - )); + $this->register_default_system_email( + array( + 'event' => 'domain_created', + 'target' => 'admin', + 'slug' => 'domain_created_admin', + 'title' => __('A new domain was added to your Network!', 'wp-ultimo'), + 'content' => wu_get_template_contents('emails/admin/domain-created'), + ) + ); /* * Pending Renewal Payment Created - Customer */ - $this->register_default_system_email(array( - 'event' => 'renewal_payment_created', - 'target' => 'customer', - 'slug' => 'renewal_payment_created', - 'title' => __('You have a new pending payment!', 'wp-ultimo'), - 'content' => wu_get_template_contents('emails/customer/renewal-payment-created'), - )); + $this->register_default_system_email( + array( + 'event' => 'renewal_payment_created', + 'target' => 'customer', + 'slug' => 'renewal_payment_created', + 'title' => __('You have a new pending payment!', 'wp-ultimo'), + 'content' => wu_get_template_contents('emails/customer/renewal-payment-created'), + ) + ); do_action('wu_system_emails_after_register'); - - } // end register_all_default_system_emails; + } /** * Get a single or all default registered system emails. @@ -457,15 +487,12 @@ class Email_Manager extends Base_Manager { */ public function get_default_system_emails($slug = '') { - if ($slug && isset($this->registered_default_system_emails[$slug])) { - - return $this->registered_default_system_emails[$slug]; - - } // end if; + if ($slug && isset($this->registered_default_system_emails[ $slug ])) { + return $this->registered_default_system_emails[ $slug ]; + } return $this->registered_default_system_emails; - - } // end get_default_system_emails; + } /** * Check if the system email already exists. @@ -476,8 +503,7 @@ class Email_Manager extends Base_Manager { public function is_created($slug): bool { return (bool) wu_get_email_by('slug', $slug); - - } // end is_created; + } /** * Get the default template email. @@ -492,43 +518,30 @@ class Email_Manager extends Base_Manager { $placeholders = array(); if (wu_request('email_event')) { - $slug = wu_request('email_event'); - - } // end if; + } if ($slug) { - $event = wu_get_event_type($slug); if ($event) { - foreach (wu_maybe_lazy_load_payload($event['payload']) as $placeholder => $value) { - $name = ucwords(str_replace('_', ' ', $placeholder)); $placeholders[] = array( 'name' => $name, - 'placeholder' => $placeholder + 'placeholder' => $placeholder, ); - - } // end foreach; - - } // end if; - - } // end if; + } + } + } if (wu_request('email_event')) { - wp_send_json($placeholders); - } else { - return $placeholders; - - } // end if; - - } // end get_event_placeholders; + } + } /** * Sends a schedule email. @@ -545,8 +558,7 @@ class Email_Manager extends Base_Manager { public function send_schedule_system_email($to, $subject, $template, $headers, $attachments) { return Sender::send_mail($to, $subject, $template, $headers, $attachments); - - } // end send_schedule_system_email; + } /** * Log failures on the WordPress mailer, just so we have a copy of the issues for debugging. @@ -559,11 +571,7 @@ class Email_Manager extends Base_Manager { public function log_mailer_failure($error) { if (is_wp_error($error)) { - wu_log_add('mailer-errors', $error->get_error_message(), LogLevel::ERROR); - - } // end if; - - } // end log_mailer_failure; - -} // end class Email_Manager; + } + } +} diff --git a/inc/managers/class-event-manager.php b/inc/managers/class-event-manager.php index 89d7dfa..de4b243 100644 --- a/inc/managers/class-event-manager.php +++ b/inc/managers/class-event-manager.php @@ -11,9 +11,9 @@ namespace WP_Ultimo\Managers; -use \WP_Ultimo\Managers\Base_Manager; +use WP_Ultimo\Managers\Base_Manager; use WP_Ultimo\Models\Base_Model; -use \WP_Ultimo\Models\Event; +use WP_Ultimo\Models\Event; // Exit if accessed directly defined('ABSPATH') || exit; @@ -25,7 +25,9 @@ defined('ABSPATH') || exit; */ class Event_Manager extends Base_Manager { - use \WP_Ultimo\Apis\Rest_Api, \WP_Ultimo\Apis\WP_CLI, \WP_Ultimo\Traits\Singleton; + use \WP_Ultimo\Apis\Rest_Api; + use \WP_Ultimo\Apis\WP_CLI; + use \WP_Ultimo\Traits\Singleton; /** * The manager slug. @@ -80,8 +82,7 @@ class Event_Manager extends Base_Manager { add_action('wu_model_post_save', array($this, 'log_transitions'), 10, 4); add_action('wu_daily', array($this, 'clean_old_events')); - - } // end init; + } /** * Returns the payload to be displayed in the payload preview field. @@ -98,45 +99,41 @@ class Event_Manager extends Base_Manager { public function log_transitions($model, $data, $data_unserialized, $object) { if ($model === 'event') { - return; - - } // end if; + } /* * Editing Model */ if (wu_get_isset($data_unserialized, 'id')) { - $original = $object->_get_original(); $diff = wu_array_recursive_diff($data_unserialized, $original); - $keys_to_remove = apply_filters('wu_exclude_transitions_keys', array( - 'meta', - 'last_login', - 'ips', - 'query_class', - 'settings', - '_compiled_product_list', - '_gateway_info', - '_limitations', - )); + $keys_to_remove = apply_filters( + 'wu_exclude_transitions_keys', + array( + 'meta', + 'last_login', + 'ips', + 'query_class', + 'settings', + '_compiled_product_list', + '_gateway_info', + '_limitations', + ) + ); foreach ($keys_to_remove as $key_to_remove) { - - unset($diff[$key_to_remove]); - - } // end foreach; + unset($diff[ $key_to_remove ]); + } /** * If empty, go home. */ if (empty($diff)) { - return; - - } // end if; + } $changed = array(); @@ -144,27 +141,21 @@ class Event_Manager extends Base_Manager { * Loop changed data. */ foreach ($diff as $key => $new_value) { - $old_value = wu_get_isset($original, $key, ''); if ($key === 'id' && intval($old_value) === 0) { - return; - - } // end if; + } if (empty(json_encode($old_value)) && empty(json_encode($new_value))) { - return; + } - } // end if; - - $changed[$key] = array( + $changed[ $key ] = array( 'old_value' => $old_value, 'new_value' => $new_value, ); - - } // end foreach; + } $event_data = array( 'severity' => Event::SEVERITY_INFO, @@ -173,9 +164,7 @@ class Event_Manager extends Base_Manager { 'object_id' => $object->get_id(), 'payload' => $changed, ); - } else { - $event_data = array( 'severity' => Event::SEVERITY_INFO, 'slug' => 'created', @@ -183,19 +172,15 @@ class Event_Manager extends Base_Manager { 'object_id' => $object->get_id(), 'payload' => array(), ); + } - } // end if; - - if (!empty($_POST) && is_user_logged_in()) { - + if ( ! empty($_POST) && is_user_logged_in()) { $event_data['initiator'] = 'manual'; $event_data['author_id'] = get_current_user_id(); - - } // end if; + } return wu_create_event($event_data); - - } // end log_transitions; + } /** * Returns the payload to be displayed in the payload preview field. @@ -205,37 +190,28 @@ class Event_Manager extends Base_Manager { */ public function event_payload_preview() { - if (!wu_request('event')) { - + if ( ! wu_request('event')) { wp_send_json_error(new \WP_Error('error', __('No event was selected.', 'wp-ultimo'))); - - } // end if; + } $slug = wu_request('event'); - if (!$slug) { - + if ( ! $slug) { wp_send_json_error(new \WP_Error('not-found', __('Event was not found.', 'wp-ultimo'))); - - } // end if; + } $event = wu_get_event_type($slug); - if (!$event) { - + if ( ! $event) { wp_send_json_error(new \WP_Error('not-found', __('Data not found.', 'wp-ultimo'))); - } else { - $payload = isset($event['payload']) ? wu_maybe_lazy_load_payload($event['payload']) : '{}'; $payload = array_map('htmlentities2', $payload); wp_send_json_success($payload); - - } // end if; - - } // end event_payload_preview; + } + } /** * Returns the list of event types to register. @@ -263,8 +239,7 @@ class Event_Manager extends Base_Manager { $types = array_filter($types, fn($item) => $item['hidden'] === false); return $types; - - } // end get_event_type_as_options; + } /** * Add a new event. @@ -280,23 +255,17 @@ class Event_Manager extends Base_Manager { $registered_event = $this->get_event($slug); - if (!$registered_event) { - + if ( ! $registered_event) { return array('error' => 'Event not found'); - - } // end if; + } $payload_diff = array_diff_key(wu_maybe_lazy_load_payload($registered_event['payload']), $payload); if (isset($payload_diff[0])) { - foreach ($payload_diff[0] as $diff_key => $diff_value) { - return array('error' => 'Param required:' . $diff_key); - - } // end foreach; - - } // end if; + } + } $payload['wu_version'] = wu_get_version(); @@ -308,8 +277,7 @@ class Event_Manager extends Base_Manager { * Saves in the database */ $this->save_event($slug, $payload); - - } // end do_event; + } /** * Register a new event to be used as param. @@ -323,11 +291,10 @@ class Event_Manager extends Base_Manager { */ public function register_event($slug, $args): bool { - $this->events[$slug] = $args; + $this->events[ $slug ] = $args; return true; - - } // end register_event; + } /** * Returns the list of available webhook events. @@ -338,8 +305,7 @@ class Event_Manager extends Base_Manager { public function get_events() { return $this->events; - - } // end get_events; + } /** * Returns the list of available webhook events. @@ -354,22 +320,15 @@ class Event_Manager extends Base_Manager { $events = $this->get_events(); if ($events) { - foreach ($events as $key => $event) { - if ($key === $slug) { - return $event; - - } // end if; - - } // end foreach; - - } // end if; + } + } + } return false; - - } // end get_event; + } /** * Saves event in the database. @@ -380,18 +339,19 @@ class Event_Manager extends Base_Manager { */ public function save_event($slug, $payload) { - $event = new Event(array( - 'object_id' => wu_get_isset($payload, 'object_id', ''), - 'object_type' => wu_get_isset($payload, 'object_type', ''), - 'severity' => wu_get_isset($payload, 'type', Event::SEVERITY_INFO), - 'date_created' => wu_get_current_time('mysql', true), - 'slug' => strtolower($slug), - 'payload' => $payload, - )); + $event = new Event( + array( + 'object_id' => wu_get_isset($payload, 'object_id', ''), + 'object_type' => wu_get_isset($payload, 'object_type', ''), + 'severity' => wu_get_isset($payload, 'type', Event::SEVERITY_INFO), + 'date_created' => wu_get_current_time('mysql', true), + 'slug' => strtolower($slug), + 'payload' => $payload, + ) + ); $event->save(); - - } // end save_event; + } /** * Registers the list of default events. @@ -404,80 +364,94 @@ class Event_Manager extends Base_Manager { /** * Payment Received. */ - wu_register_event_type('payment_received', array( - 'name' => __('Payment Received', 'wp-ultimo'), - 'desc' => __('This event is fired every time a new payment is received, regardless of the payment status.', 'wp-ultimo'), - 'payload' => fn() => array_merge( + wu_register_event_type( + 'payment_received', + array( + 'name' => __('Payment Received', 'wp-ultimo'), + 'desc' => __('This event is fired every time a new payment is received, regardless of the payment status.', 'wp-ultimo'), + 'payload' => fn() => array_merge( wu_generate_event_payload('payment'), wu_generate_event_payload('membership'), wu_generate_event_payload('customer') ), - 'deprecated_args' => array( - 'user_id' => 'customer_user_id', - 'amount' => 'payment_total', - 'gateway' => 'payment_gateway', - 'status' => 'payment_status', - 'date' => 'payment_date_created', - ), - )); + 'deprecated_args' => array( + 'user_id' => 'customer_user_id', + 'amount' => 'payment_total', + 'gateway' => 'payment_gateway', + 'status' => 'payment_status', + 'date' => 'payment_date_created', + ), + ) + ); /** * Site Published. */ - wu_register_event_type('site_published', array( - 'name' => __('Site Published', 'wp-ultimo'), - 'desc' => __('This event is fired every time a new site is created tied to a membership, or transitions from a pending state to a published state.', 'wp-ultimo'), - 'payload' => fn() => array_merge( + wu_register_event_type( + 'site_published', + array( + 'name' => __('Site Published', 'wp-ultimo'), + 'desc' => __('This event is fired every time a new site is created tied to a membership, or transitions from a pending state to a published state.', 'wp-ultimo'), + 'payload' => fn() => array_merge( wu_generate_event_payload('site'), wu_generate_event_payload('customer'), wu_generate_event_payload('membership') ), - 'deprecated_args' => array(), - )); + 'deprecated_args' => array(), + ) + ); /** * Confirm Email Address */ - wu_register_event_type('confirm_email_address', array( - 'name' => __('Email Verification Needed', 'wp-ultimo'), - 'desc' => __('This event is fired every time a new customer is added with an email verification status of pending.', 'wp-ultimo'), - 'payload' => fn() => array_merge( + wu_register_event_type( + 'confirm_email_address', + array( + 'name' => __('Email Verification Needed', 'wp-ultimo'), + 'desc' => __('This event is fired every time a new customer is added with an email verification status of pending.', 'wp-ultimo'), + 'payload' => fn() => array_merge( array( 'verification_link' => 'https://linktoverifyemail.com', ), wu_generate_event_payload('customer') ), - 'deprecated_args' => array(), - )); + 'deprecated_args' => array(), + ) + ); /** * Domain Mapping Added */ - wu_register_event_type('domain_created', array( - 'name' => __('New Domain Mapping Added', 'wp-ultimo'), - 'desc' => __('This event is fired every time a new domain mapping is added by a customer.', 'wp-ultimo'), - 'payload' => fn() => array_merge( + wu_register_event_type( + 'domain_created', + array( + 'name' => __('New Domain Mapping Added', 'wp-ultimo'), + 'desc' => __('This event is fired every time a new domain mapping is added by a customer.', 'wp-ultimo'), + 'payload' => fn() => array_merge( wu_generate_event_payload('domain'), wu_generate_event_payload('site'), wu_generate_event_payload('membership'), wu_generate_event_payload('customer') ), - 'deprecated_args' => array( - 'user_id' => 1, - 'user_site_id' => 1, - 'mapped_domain' => 'mydomain.com', - 'user_site_url' => 'http://test.mynetwork.com/', - 'network_ip' => '125.399.3.23', - ), - )); + 'deprecated_args' => array( + 'user_id' => 1, + 'user_site_id' => 1, + 'mapped_domain' => 'mydomain.com', + 'user_site_url' => 'http://test.mynetwork.com/', + 'network_ip' => '125.399.3.23', + ), + ) + ); /** * Renewal payment created */ - wu_register_event_type('renewal_payment_created', array( - 'name' => __('New Renewal Payment Created', 'wp-ultimo'), - 'desc' => __('This event is fired every time a new renewal payment is created by WP Multisite WaaS.', 'wp-ultimo'), - 'payload' => fn() => array_merge( + wu_register_event_type( + 'renewal_payment_created', + array( + 'name' => __('New Renewal Payment Created', 'wp-ultimo'), + 'desc' => __('This event is fired every time a new renewal payment is created by WP Multisite WaaS.', 'wp-ultimo'), + 'payload' => fn() => array_merge( array( 'default_payment_url' => 'https://linktopayment.com', ), @@ -485,31 +459,30 @@ class Event_Manager extends Base_Manager { wu_generate_event_payload('membership'), wu_generate_event_payload('customer') ), - 'deprecated_args' => array(), - )); + 'deprecated_args' => array(), + ) + ); $models = $this->models_events; foreach ($models as $model => $params) { - foreach ($params['types'] as $type) { - - wu_register_event_type($model . '_' . $type, array( - 'name' => sprintf(__('%1$s %2$s', 'wp-ultimo'), $params['label'], ucfirst($type)), - 'desc' => sprintf(__('This event is fired every time a %1$s is %2$s by WP Multisite WaaS.', 'wp-ultimo'), $params['label'], $type), - 'deprecated_args' => array(), - 'payload' => fn() => $this->get_model_payload($model), - )); - - } // end foreach; + wu_register_event_type( + $model . '_' . $type, + array( + 'name' => sprintf(__('%1$s %2$s', 'wp-ultimo'), $params['label'], ucfirst($type)), + 'desc' => sprintf(__('This event is fired every time a %1$s is %2$s by WP Multisite WaaS.', 'wp-ultimo'), $params['label'], $type), + 'deprecated_args' => array(), + 'payload' => fn() => $this->get_model_payload($model), + ) + ); + } add_action("wu_{$model}_post_save", array($this, 'dispatch_base_model_event'), 10, 3); - - } // end foreach; + } do_action('wu_register_all_events'); - - } // end register_all_events; + } /** * Register models events @@ -523,12 +496,11 @@ class Event_Manager extends Base_Manager { $instance = self::get_instance(); - $instance->models_events[$slug] = array( + $instance->models_events[ $slug ] = array( 'label' => $label, 'types' => $event_types, ); - - } // end register_model_events; + } /** * Dispatch registered model events @@ -547,17 +519,14 @@ class Event_Manager extends Base_Manager { $registered_model = wu_get_isset($this->models_events, $model); - if (!$registered_model || !in_array($type, $registered_model['types'], true)) { - + if ( ! $registered_model || ! in_array($type, $registered_model['types'], true)) { return; - - } // end if; + } $payload = $this->get_model_payload($model, $obj); wu_do_event($model . '_' . $type, $payload); - - } // end dispatch_base_model_event; + } /** * Returns the full payload for a given model. @@ -574,31 +543,25 @@ class Event_Manager extends Base_Manager { $payload = wu_generate_event_payload($model, $obj); if (method_exists($obj, 'get_membership')) { - $membership = $model_object ? $obj->get_membership() : false; $payload = array_merge( $payload, wu_generate_event_payload('membership', $membership) ); - - } // end if; + } if (method_exists($obj, 'get_customer')) { - $customer = $model_object ? $obj->get_customer() : false; $payload = array_merge( $payload, wu_generate_event_payload('customer', $customer) ); - - } // end if; + } if (method_exists($obj, 'get_billing_address') || method_exists($obj, 'get_membership')) { - if ($model_object) { - $payload = method_exists($obj, 'get_billing_address') ? array_merge( $payload, @@ -607,23 +570,21 @@ class Event_Manager extends Base_Manager { $payload, $obj->get_membership()->get_billing_address()->to_array() ); - } else { - $payload = array_merge( $payload, - array_map(function () { - return ''; - }, \WP_Ultimo\Objects\Billing_Address::fields()) + array_map( + function () { + return ''; + }, + \WP_Ultimo\Objects\Billing_Address::fields() + ) ); - - } // end if; - - } // end if; + } + } return $payload; - - } // end get_model_payload; + } /** * Every day, deletes old events that we don't want to keep. @@ -638,39 +599,34 @@ class Event_Manager extends Base_Manager { $threshold_days = apply_filters('wu_events_threshold_days', 1); if (empty($threshold_days)) { - return false; + } - } // end if; - - $events_to_remove = wu_get_events(array( - 'number' => 100, - 'date_query' => array( - 'column' => 'date_created', - 'before' => "-{$threshold_days} days", - 'inclusive' => true, - ), - )); + $events_to_remove = wu_get_events( + array( + 'number' => 100, + 'date_query' => array( + 'column' => 'date_created', + 'before' => "-{$threshold_days} days", + 'inclusive' => true, + ), + ) + ); $success_count = 0; foreach ($events_to_remove as $event) { - $status = $event->delete(); - if (!is_wp_error($status) && $status) { - - $success_count++; - - } // end if; - - } // end foreach; + if ( ! is_wp_error($status) && $status) { + ++$success_count; + } + } wu_log_add('wu-cron', sprintf(__('Removed %1$d events successfully. Failed to remove %2$d events.', 'wp-ultimo'), $success_count, count($events_to_remove) - $success_count)); return true; - - } // end clean_old_events; + } /** * Create a endpoint to retrieve all available event hooks. @@ -681,21 +637,22 @@ class Event_Manager extends Base_Manager { */ public function hooks_endpoint() { - if (!wu_get_setting('enable_api', true)) { - + if ( ! wu_get_setting('enable_api', true)) { return; - - } // end if; + } $api = \WP_Ultimo\API::get_instance(); - register_rest_route($api->get_namespace(), '/hooks', array( - 'methods' => 'GET', - 'callback' => array($this, 'get_hooks_rest'), - 'permission_callback' => array($api, 'check_authorization'), - )); - - } // end hooks_endpoint; + register_rest_route( + $api->get_namespace(), + '/hooks', + array( + 'methods' => 'GET', + 'callback' => array($this, 'get_hooks_rest'), + 'permission_callback' => array($api, 'check_authorization'), + ) + ); + } /** * Return all event types for the REST API request. @@ -710,19 +667,13 @@ class Event_Manager extends Base_Manager { $response = wu_get_event_types(); foreach ($response as $key => $value) { - $payload = wu_get_isset($value, 'payload'); if (is_callable($payload)) { - - $response[$key]['payload'] = $payload(); - - } // end if; - - } // end foreach; + $response[ $key ]['payload'] = $payload(); + } + } return rest_ensure_response($response); - - } // end get_hooks_rest; - -} // end class Event_Manager; + } +} diff --git a/inc/managers/class-field-templates-manager.php b/inc/managers/class-field-templates-manager.php index 0b53928..ed32687 100644 --- a/inc/managers/class-field-templates-manager.php +++ b/inc/managers/class-field-templates-manager.php @@ -11,7 +11,7 @@ namespace WP_Ultimo\Managers; -use \WP_Ultimo\Managers\Base_Manager; +use WP_Ultimo\Managers\Base_Manager; // Exit if accessed directly defined('ABSPATH') || exit; @@ -44,8 +44,7 @@ class Field_Templates_Manager extends Base_Manager { add_action('wu_ajax_nopriv_wu_render_field_template', array($this, 'serve_field_template')); add_action('wu_ajax_wu_render_field_template', array($this, 'serve_field_template')); - - } // end init; + } /** * Serve the HTML markup for the templates. @@ -61,21 +60,20 @@ class Field_Templates_Manager extends Base_Manager { $template_class = $this->get_template_class($template_parts[0], $template_parts[1]); - if (!$template_class) { - + if ( ! $template_class) { wp_send_json_error(new \WP_Error('template', __('Template not found.', 'wp-ultimo'))); - - } // end if; + } $key = $template_parts[0]; $attributes = apply_filters("wu_{$key}_render_attributes", wu_request('attributes')); - wp_send_json_success(array( - 'html' => $template_class->render($attributes), - )); - - } // end serve_field_template; + wp_send_json_success( + array( + 'html' => $template_class->render($attributes), + ) + ); + } /** * Returns the list of registered signup field types. @@ -157,8 +155,7 @@ class Field_Templates_Manager extends Base_Manager { * @return array */ return apply_filters('wu_checkout_field_templates', $field_templates); - - } // end get_field_templates; + } /** * Get the field templates for a field type. Returns only the class names. @@ -171,8 +168,7 @@ class Field_Templates_Manager extends Base_Manager { public function get_templates($field_type) { return wu_get_isset($this->get_field_templates(), $field_type, array()); - - } // end get_templates; + } /** * Get the instance of the template class. @@ -188,8 +184,7 @@ class Field_Templates_Manager extends Base_Manager { $templates = $this->get_instantiated_field_types($field_type); return wu_get_isset($templates, $field_template_id); - - } // end get_template_class; + } /** * Returns the field templates as a key => title array of options. @@ -206,14 +201,11 @@ class Field_Templates_Manager extends Base_Manager { $options = array(); foreach ($templates as $template_id => $template) { - - $options[$template_id] = $template->get_title(); - - } // end foreach; + $options[ $template_id ] = $template->get_title(); + } return $options; - - } // end get_templates_as_options; + } /** * Returns the field templates as a key => info_array array of fields. @@ -230,19 +222,16 @@ class Field_Templates_Manager extends Base_Manager { $options = array(); foreach ($templates as $template_id => $template) { - - $options[$template_id] = array( + $options[ $template_id ] = array( 'id' => $template_id, 'title' => $template->get_title(), 'description' => $template->get_description(), 'preview' => $template->get_preview(), ); - - } // end foreach; + } return $options; - - } // end get_templates_info; + } /** * Instantiate a field template. @@ -255,8 +244,7 @@ class Field_Templates_Manager extends Base_Manager { public function instantiate_field_template($class_name) { return new $class_name(); - - } // end instantiate_field_template; + } /** * Returns an array with all fields, instantiated. @@ -269,15 +257,12 @@ class Field_Templates_Manager extends Base_Manager { $holder_name = "instantiated_{$field_type}_templates"; - if (!isset($this->holders[$holder_name]) || $this->holders[$holder_name] === null) { + if ( ! isset($this->holders[ $holder_name ]) || $this->holders[ $holder_name ] === null) { + $this->holders[ $holder_name ] = array_map(array($this, 'instantiate_field_template'), $this->get_templates($field_type)); + } - $this->holders[$holder_name] = array_map(array($this, 'instantiate_field_template'), $this->get_templates($field_type)); - - } // end if; - - return $this->holders[$holder_name]; - - } // end get_instantiated_field_types; + return $this->holders[ $holder_name ]; + } /** * Render preview block. @@ -291,22 +276,24 @@ class Field_Templates_Manager extends Base_Manager { $preview_block = '
    '; - foreach (Field_Templates_Manager::get_instance()->get_templates_info($field_type) as $template_slug => $template_info) { - + foreach (self::get_instance()->get_templates_info($field_type) as $template_slug => $template_info) { $image_tag = $template_info['preview'] ? sprintf('', $template_info['preview']) : '
    '; - $preview_block .= sprintf("
    + $preview_block .= sprintf( + "
    %2\$s
    %3\$s
    -
    ", $template_info['id'], $image_tag, $template_info['description'], $field_type); - - } // end foreach; +
    ", + $template_info['id'], + $image_tag, + $template_info['description'], + $field_type + ); + } $preview_block .= '
    '; return $preview_block; - - } // end render_preview_block; - -} // end class Field_Templates_Manager; + } +} diff --git a/inc/managers/class-form-manager.php b/inc/managers/class-form-manager.php index 2fd2b60..6e85c33 100644 --- a/inc/managers/class-form-manager.php +++ b/inc/managers/class-form-manager.php @@ -50,8 +50,7 @@ class Form_Manager extends Base_Manager { add_action('wu_page_load', 'add_wubox'); do_action('wu_register_forms'); - - } // end init; + } /** * Displays the form unavailable message. @@ -68,25 +67,25 @@ class Form_Manager extends Base_Manager { $message = __('Form not available', 'wp-ultimo'); if (is_wp_error($error)) { - $message = $error->get_error_message(); + } - } // end if; - - echo sprintf(' + printf( + '
    %s
    - ', $message); + ', + $message + ); do_action('wu_form_scripts', false); die; - - } // end display_form_unavailable; + } /** * Renders a registered form, when requested. @@ -100,18 +99,27 @@ class Form_Manager extends Base_Manager { $form = $this->get_form(wu_request('form')); - echo sprintf("
    ", - $form['id'], - $this->get_form_url($form['id'], array( - 'action' => 'wu_form_handler', - ))); + printf( + "", + $form['id'], + $this->get_form_url( + $form['id'], + array( + 'action' => 'wu_form_handler', + ) + ) + ); - echo sprintf(' + printf( + '
    • {{ error.message }}
    -
    ', $form['id'] . '_errors', htmlspecialchars(json_encode(array('errors' => array())))); + ', + $form['id'] . '_errors', + htmlspecialchars(json_encode(array('errors' => array()))) + ); call_user_func($form['render']); @@ -124,8 +132,7 @@ class Form_Manager extends Base_Manager { do_action('wu_form_scripts', $form); exit; - - } // end display_form; + } /** * Handles the submission of a registered form. @@ -139,11 +146,9 @@ class Form_Manager extends Base_Manager { $form = $this->get_form(wu_request('form')); - if (!wp_verify_nonce(wu_request('_wpnonce'), 'wu_form_' . $form['id'])) { - + if ( ! wp_verify_nonce(wu_request('_wpnonce'), 'wu_form_' . $form['id'])) { wp_send_json_error(); - - } // end if; + } /** * The handler is supposed to send a wp_json message back. @@ -153,14 +158,11 @@ class Form_Manager extends Base_Manager { $check = call_user_func($form['handler']); if (is_wp_error($check)) { - $this->display_form_unavailable($check); - - } // end if; + } exit; - - } // end handle_form; + } /** * Checks that the form exists and that the user has permission to see it. @@ -173,26 +175,19 @@ class Form_Manager extends Base_Manager { * We only want ajax requests. */ if ((empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower((string) $_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest')) { - wp_die(0); - - } // end if; + } $form = $this->get_form(wu_request('form')); - if (!$form) { - + if ( ! $form) { return $this->display_form_unavailable(); + } - } // end if; - - if (!current_user_can($form['capability'])) { - + if ( ! current_user_can($form['capability'])) { return $this->display_form_unavailable(); - - } // end if; - - } // end security_checks; + } + } /** * Returns a list of all the registered gateways. @@ -203,8 +198,7 @@ class Form_Manager extends Base_Manager { public function get_registered_forms() { return $this->registered_forms; - - } // end get_registered_forms; + } /** * Checks if a form is already registered. @@ -216,9 +210,8 @@ class Form_Manager extends Base_Manager { */ public function is_form_registered($id) { - return is_array($this->registered_forms) && isset($this->registered_forms[$id]); - - } // end is_form_registered; + return is_array($this->registered_forms) && isset($this->registered_forms[ $id ]); + } /** * Returns a registered form. @@ -230,9 +223,8 @@ class Form_Manager extends Base_Manager { */ public function get_form($id) { - return $this->is_form_registered($id) ? $this->registered_forms[$id] : false; - - } // end get_form; + return $this->is_form_registered($id) ? $this->registered_forms[ $id ] : false; + } /** * Registers a new Ajax Form. @@ -249,26 +241,26 @@ class Form_Manager extends Base_Manager { */ public function register_form($id, $atts = array()) { - $atts = wp_parse_args($atts, array( - 'id' => $id, - 'form' => '', - 'capability' => 'manage_network', - 'handler' => '__return_false', - 'render' => '__return_empty_string', - )); + $atts = wp_parse_args( + $atts, + array( + 'id' => $id, + 'form' => '', + 'capability' => 'manage_network', + 'handler' => '__return_false', + 'render' => '__return_empty_string', + ) + ); // Checks if gateway was already added if ($this->is_form_registered($id)) { - return; + } - } // end if; - - $this->registered_forms[$id] = $atts; + $this->registered_forms[ $id ] = $atts; return true; - - } // end register_form; + } /** * Returns the ajax URL for a given form. @@ -281,16 +273,18 @@ class Form_Manager extends Base_Manager { */ public function get_form_url($form_id, $atts = array()) { - $atts = wp_parse_args($atts, array( - 'form' => $form_id, - 'action' => 'wu_form_display', - 'width' => '400', - 'height' => '360', - )); + $atts = wp_parse_args( + $atts, + array( + 'form' => $form_id, + 'action' => 'wu_form_display', + 'width' => '400', + 'height' => '360', + ) + ); return add_query_arg($atts, wu_ajax_url('init')); - - } // end get_form_url; + } /** * Register the confirmation modal form to delete a customer. @@ -301,20 +295,25 @@ class Form_Manager extends Base_Manager { $model = wu_request('model'); - wu_register_form('delete_modal', array( - 'render' => array($this, 'render_model_delete_form'), - 'handler' => array($this, 'handle_model_delete_form'), - 'capability' => "wu_delete_{$model}s", - )); + wu_register_form( + 'delete_modal', + array( + 'render' => array($this, 'render_model_delete_form'), + 'handler' => array($this, 'handle_model_delete_form'), + 'capability' => "wu_delete_{$model}s", + ) + ); - wu_register_form('bulk_actions', array( - 'render' => array($this, 'render_bulk_action_form'), - 'handler' => array($this, 'handle_bulk_action_form'), - )); + wu_register_form( + 'bulk_actions', + array( + 'render' => array($this, 'render_bulk_action_form'), + 'handler' => array($this, 'handle_bulk_action_form'), + ) + ); add_action('wu_handle_bulk_action_form', array($this, 'default_bulk_action_handler'), 100, 3); - - } // end register_action_forms; + } /** * Renders the deletion confirmation form. @@ -335,34 +334,27 @@ class Form_Manager extends Base_Manager { * Handle metadata elements passed as model */ if (strpos((string) $model, '_meta_') !== false) { - $elements = explode('_meta_', (string) $model); $model = $elements[0]; $meta_key = $elements[1]; - - } // end if; + } try { - $object = call_user_func("wu_get_{$model}", $id); - } catch (\Throwable $exception) { // No need to do anything, but cool to stop fatal errors. - - } // end try; + } $object = apply_filters("wu_delete_form_get_object_{$model}", $object, $id, $model); - if (!$object) { - + if ( ! $object) { $this->display_form_unavailable(new \WP_Error('not-found', __('Object not found.', 'wp-ultimo'))); return; - - } // end if; + } $fields = apply_filters( "wu_form_fields_delete_{$model}_modal", @@ -406,28 +398,31 @@ class Form_Manager extends Base_Manager { $object ); - $form_attributes = apply_filters("wu_form_attributes_delete_{$model}_modal", array( - 'title' => 'Delete', - '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_attributes = apply_filters( + "wu_form_attributes_delete_{$model}_modal", + array( + 'title' => 'Delete', + '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, $form_attributes); do_action("wu_before_render_delete_{$model}_modal", $form); $form->render(); - - } // end if; - - } // end render_model_delete_form; + } + } /** * Handles the deletion of customer. @@ -454,7 +449,6 @@ class Form_Manager extends Base_Manager { * Handle meta key deletion */ if ($meta_key) { - $status = delete_metadata('wu_membership', wu_request('id'), 'pending_site'); $data_json_success = array( @@ -464,26 +458,20 @@ class Form_Manager extends Base_Manager { wp_send_json_success($data_json_success); exit; - - } // end if; + } try { - $object = call_user_func("wu_get_{$model}", $id); - } catch (\Throwable $exception) { // No need to do anything, but cool to stop fatal errors. - - } // end try; + } $object = apply_filters("wu_delete_form_get_object_{$model}", $object, $id, $model); - if (!$object) { - + if ( ! $object) { wp_send_json_error(new \WP_Error('not-found', __('Object not found.', 'wp-ultimo'))); - - } // end if; + } /* * Handle objects (default state) @@ -493,26 +481,23 @@ class Form_Manager extends Base_Manager { $saved = $object->delete(); if (is_wp_error($saved)) { - wp_send_json_error($saved); - - } // end if; + } do_action("wu_after_delete_{$model}_modal", $object); - $data_json_success = apply_filters("wu_data_json_success_delete_{$model}_modal", array( - 'redirect_url' => wu_network_admin_url("wp-ultimo-{$plural_name}", array('deleted' => 1)) - )); + $data_json_success = apply_filters( + "wu_data_json_success_delete_{$model}_modal", + array( + 'redirect_url' => wu_network_admin_url("wp-ultimo-{$plural_name}", array('deleted' => 1)), + ) + ); wp_send_json_success($data_json_success); - } else { - wp_send_json_error(new \WP_Error('model-not-found', __('Something went wrong.', 'wp-ultimo'))); - - } // end if; - - } // end handle_model_delete_form; + } + } /** * Renders the deletion confirmation form. @@ -526,57 +511,64 @@ class Form_Manager extends Base_Manager { $model = wu_request('model'); - $fields = apply_filters("wu_bulk_actions_{$model}_{$action}", array( - 'confirm' => array( - 'type' => 'toggle', - 'title' => __('Confirm Action', 'wp-ultimo'), - 'desc' => __('Review this action carefully.', 'wp-ultimo'), - 'html_attr' => array( - 'v-model' => 'confirmed', + $fields = apply_filters( + "wu_bulk_actions_{$model}_{$action}", + array( + 'confirm' => array( + 'type' => 'toggle', + 'title' => __('Confirm Action', 'wp-ultimo'), + 'desc' => __('Review this action carefully.', 'wp-ultimo'), + 'html_attr' => array( + 'v-model' => 'confirmed', + ), ), - ), - 'submit_button' => array( - 'type' => 'submit', - 'title' => wu_slug_to_name($action), - 'placeholder' => wu_slug_to_name($action), - 'value' => 'save', - 'classes' => 'button button-primary wu-w-full', - 'wrapper_classes' => 'wu-items-end', - 'html_attr' => array( - 'v-bind:disabled' => '!confirmed', + 'submit_button' => array( + 'type' => 'submit', + 'title' => wu_slug_to_name($action), + 'placeholder' => wu_slug_to_name($action), + 'value' => 'save', + 'classes' => 'button button-primary wu-w-full', + 'wrapper_classes' => 'wu-items-end', + 'html_attr' => array( + 'v-bind:disabled' => '!confirmed', + ), ), - ), - 'model' => array( - 'type' => 'hidden', - 'value' => $model, - ), - 'bulk_action' => array( - 'type' => 'hidden', - 'value' => wu_request('bulk_action'), - ), - 'ids' => array( - 'type' => 'hidden', - 'value' => implode(',', wu_request('bulk-delete', '')), - ), - )); + 'model' => array( + 'type' => 'hidden', + 'value' => $model, + ), + 'bulk_action' => array( + 'type' => 'hidden', + 'value' => wu_request('bulk_action'), + ), + 'ids' => array( + 'type' => 'hidden', + 'value' => implode(',', wu_request('bulk-delete', '')), + ), + ) + ); - $form_attributes = apply_filters("wu_bulk_actions_{$action}_form", 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_attributes = apply_filters( + "wu_bulk_actions_{$action}_form", + 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, $form_attributes); $form->render(); - - } // end render_bulk_action_form; + } /** * Handles the deletion of customer. @@ -597,8 +589,7 @@ class Form_Manager extends Base_Manager { do_action("wu_handle_bulk_action_form_{$model}_{$action}", $action, $model, $ids); do_action('wu_handle_bulk_action_form', $action, $model, $ids); - - } // end handle_bulk_action_form; + } /** * Default handler for bulk actions. @@ -615,15 +606,13 @@ class Form_Manager extends Base_Manager { $status = \WP_Ultimo\List_Tables\Base_List_Table::process_bulk_action(); if (is_wp_error($status)) { - wp_send_json_error($status); + } - } // end if; - - wp_send_json_success(array( - 'redirect_url' => add_query_arg($action, count($ids), wu_get_current_url()), - )); - - } // end default_bulk_action_handler; - -} // end class Form_Manager; + wp_send_json_success( + array( + 'redirect_url' => add_query_arg($action, count($ids), wu_get_current_url()), + ) + ); + } +} diff --git a/inc/managers/class-gateway-manager.php b/inc/managers/class-gateway-manager.php index 03ff24f..9628a55 100644 --- a/inc/managers/class-gateway-manager.php +++ b/inc/managers/class-gateway-manager.php @@ -12,14 +12,14 @@ namespace WP_Ultimo\Managers; use Psr\Log\LogLevel; -use \WP_Ultimo\Managers\Base_Manager; -use \WP_Ultimo\Gateways\Ignorable_Exception; +use WP_Ultimo\Managers\Base_Manager; +use WP_Ultimo\Gateways\Ignorable_Exception; -use \WP_Ultimo\Gateways\Free_Gateway; -use \WP_Ultimo\Gateways\Stripe_Gateway; -use \WP_Ultimo\Gateways\Stripe_Checkout_Gateway; -use \WP_Ultimo\Gateways\PayPal_Gateway; -use \WP_Ultimo\Gateways\Manual_Gateway; +use WP_Ultimo\Gateways\Free_Gateway; +use WP_Ultimo\Gateways\Stripe_Gateway; +use WP_Ultimo\Gateways\Stripe_Checkout_Gateway; +use WP_Ultimo\Gateways\PayPal_Gateway; +use WP_Ultimo\Gateways\Manual_Gateway; // Exit if accessed directly defined('ABSPATH') || exit; @@ -66,8 +66,7 @@ class Gateway_Manager extends Base_Manager { public function init() { add_action('plugins_loaded', array($this, 'on_load')); - - } // end init; + } /** * Runs after all plugins have been loaded to allow for add-ons to hook into it correctly. @@ -83,9 +82,13 @@ class Gateway_Manager extends Base_Manager { /* * Allow developers to add new gateways. */ - add_action('init', function () { - do_action('wu_register_gateways'); - }, 19); + add_action( + 'init', + function () { + do_action('wu_register_gateways'); + }, + 19 + ); /* * Adds the Gateway selection fields @@ -108,8 +111,7 @@ class Gateway_Manager extends Base_Manager { * Waits for webhook signals and deal with them. */ add_action('admin_init', array($this, 'maybe_process_v1_webhooks'), 1); - - } // end on_load; + } /** * Checks if we need to process webhooks received by gateways. @@ -121,7 +123,7 @@ class Gateway_Manager extends Base_Manager { $gateway = wu_request('wu-gateway'); - if ($gateway && !is_admin() && is_main_site()) { + if ($gateway && ! is_admin() && is_main_site()) { /* * Do not cache this! */ @@ -146,9 +148,7 @@ class Gateway_Manager extends Base_Manager { http_response_code(200); die('Thanks!'); - } catch (Ignorable_Exception $e) { - $message = sprintf('We failed to handle a webhook call, but in this case, no further action is necessary. Message: %s', $e->getMessage()); wu_log_add("wu-{$gateway}-webhook-errors", $message); @@ -157,9 +157,7 @@ class Gateway_Manager extends Base_Manager { * Send the error back, but with a 200. */ wp_send_json_error(new \WP_Error('webhook-error', $message), 200); - } catch (\Throwable $e) { - $file = $e->getFile(); $line = $e->getLine(); @@ -177,12 +175,9 @@ class Gateway_Manager extends Base_Manager { * a non-200 code is returned. */ wp_send_json_error(new \WP_Error('webhook-error', $message), 500); - - } // end try; - - } // end if; - - } // end maybe_process_webhooks; + } + } + } /** * Checks if we need to process webhooks received by legacy gateways. @@ -203,7 +198,6 @@ class Gateway_Manager extends Base_Manager { $gateway = wu_get_gateway($gateway_id); if ($gateway) { - $gateway->before_backwards_compatible_webhook(); /* @@ -230,9 +224,7 @@ class Gateway_Manager extends Base_Manager { http_response_code(200); die('Thanks!'); - } catch (Ignorable_Exception $e) { - $message = sprintf('We failed to handle a webhook call, but in this case, no further action is necessary. Message: %s', $e->getMessage()); wu_log_add("wu-{$gateway_id}-webhook-errors", $message); @@ -241,9 +233,7 @@ class Gateway_Manager extends Base_Manager { * Send the error back, but with a 200. */ wp_send_json_error(new \WP_Error('webhook-error', $message), 200); - } catch (\Throwable $e) { - $message = sprintf('We failed to handle a webhook call. Error: %s', $e->getMessage()); wu_log_add("wu-{$gateway_id}-webhook-errors", $message, LogLevel::ERROR); @@ -257,14 +247,10 @@ class Gateway_Manager extends Base_Manager { http_response_code(500); wp_send_json_error(new \WP_Error('webhook-error', $message)); - - } // end try; - - } // end if; - - } // end if; - - } // end maybe_process_v1_webhooks; + } + } + } + } /** * Let gateways deal with their confirmation steps. @@ -278,11 +264,9 @@ class Gateway_Manager extends Base_Manager { /* * First we check for the confirmation parameter. */ - if (!wu_request('wu-confirm') || (wu_request('status') && wu_request('status') === 'done')) { - + if ( ! wu_request('wu-confirm') || (wu_request('status') && wu_request('status') === 'done')) { return; - - } // end if; + } ob_start(); @@ -292,25 +276,27 @@ class Gateway_Manager extends Base_Manager { $gateway = wu_get_gateway($gateway_id); - if (!$gateway) { - + if ( ! $gateway) { $error = new \WP_Error('missing_gateway', __('Missing gateway parameter.', 'wp-ultimo')); - wp_die($error, __('Error', 'wp-ultimo'), array('back_link' => true, 'response' => '200')); - - } // end if; + wp_die( + $error, + __('Error', 'wp-ultimo'), + array( + 'back_link' => true, + 'response' => '200', + ) + ); + } try { - $payment_hash = wu_request('payment'); $payment = wu_get_payment_by_hash($payment_hash); if ($payment) { - $gateway->set_payment($payment); - - } // end if; + } /* * Pass it down to the gateway. @@ -322,31 +308,38 @@ class Gateway_Manager extends Base_Manager { $results = $gateway->process_confirmation(); if (is_wp_error($results)) { - - wp_die($results, __('Error', 'wp-ultimo'), array('back_link' => true, 'response' => '200')); - - } // end if; - + wp_die( + $results, + __('Error', 'wp-ultimo'), + array( + 'back_link' => true, + 'response' => '200', + ) + ); + } } catch (\Throwable $e) { - $error = new \WP_Error('confirm-error-' . $e->getCode(), $e->getMessage()); - wp_die($error, __('Error', 'wp-ultimo'), array('back_link' => true, 'response' => '200')); - - } // end try; + wp_die( + $error, + __('Error', 'wp-ultimo'), + array( + 'back_link' => true, + 'response' => '200', + ) + ); + } $output = ob_get_clean(); - if (!empty($output)) { + if ( ! empty($output)) { /* * Add a filter to bypass the checkout form. * This is used for PayPal confirmation page. */ add_action('wu_bypass_checkout_form', fn($bypass, $atts) => $output, 10, 2); - - } // end if; - - } // end process_gateway_confirmations; + } + } /** * Adds the field that enabled and disables Payment Gateways on the settings. @@ -356,16 +349,19 @@ class Gateway_Manager extends Base_Manager { */ public function add_gateway_selector_field() { - wu_register_settings_field('payment-gateways', 'active_gateways', array( - 'title' => __('Active Payment Gateways', 'wp-ultimo'), - 'desc' => __('Payment gateways are what your customers will use to pay.', 'wp-ultimo'), - 'type' => 'multiselect', - 'columns' => 2, - 'options' => array($this, 'get_gateways_as_options'), - 'default' => array(), - )); - - } // end add_gateway_selector_field; + wu_register_settings_field( + 'payment-gateways', + 'active_gateways', + array( + 'title' => __('Active Payment Gateways', 'wp-ultimo'), + 'desc' => __('Payment gateways are what your customers will use to pay.', 'wp-ultimo'), + 'type' => 'multiselect', + 'columns' => 2, + 'options' => array($this, 'get_gateways_as_options'), + 'default' => array(), + ) + ); + } /** * Returns the list of registered gateways as options for the gateway selector setting. @@ -384,8 +380,7 @@ class Gateway_Manager extends Base_Manager { $gateways = array_filter($gateways, fn($item) => $item['hidden'] === false); return $gateways; - - } // end get_gateways_as_options; + } /** * Loads the default gateways. @@ -422,8 +417,7 @@ class Gateway_Manager extends Base_Manager { */ $manual_desc = __('Use the Manual Gateway to allow users to pay you directly via bank transfers, checks, or other channels.', 'wp-ultimo'); wu_register_gateway('manual', __('Manual', 'wp-ultimo'), $manual_desc, Manual_Gateway::class); - - } // end add_default_gateways; + } /** * Checks if a gateway was already registered. @@ -434,9 +428,8 @@ class Gateway_Manager extends Base_Manager { */ public function is_gateway_registered($id) { - return is_array($this->registered_gateways) && isset($this->registered_gateways[$id]); - - } // end is_gateway_registered; + return is_array($this->registered_gateways) && isset($this->registered_gateways[ $id ]); + } /** * Returns a list of all the registered gateways @@ -447,8 +440,7 @@ class Gateway_Manager extends Base_Manager { public function get_registered_gateways() { return $this->registered_gateways; - - } // end get_registered_gateways; + } /** * Returns a particular Gateway registered @@ -459,9 +451,8 @@ class Gateway_Manager extends Base_Manager { */ public function get_gateway($id) { - return $this->is_gateway_registered($id) ? $this->registered_gateways[$id] : false; - - } // end get_gateway; + return $this->is_gateway_registered($id) ? $this->registered_gateways[ $id ] : false; + } /** * Adds a new Gateway to the System. Used by gateways to make themselves visible. @@ -479,15 +470,13 @@ class Gateway_Manager extends Base_Manager { // Checks if gateway was already added if ($this->is_gateway_registered($id)) { - return; - - } // end if; + } $active_gateways = (array) wu_get_setting('active_gateways', array()); // Adds to the global - $this->registered_gateways[$id] = array( + $this->registered_gateways[ $id ] = array( 'id' => $id, 'title' => $title, 'desc' => $desc, @@ -502,8 +491,7 @@ class Gateway_Manager extends Base_Manager { // Return the value return true; - - } // end register_gateway; + } /** * Adds additional hooks for each of the gateway registered. @@ -524,17 +512,14 @@ class Gateway_Manager extends Base_Manager { * payments, add it to the list. */ if ($gateway->supports_recurring()) { - $this->auto_renewable_gateways[] = $gateway_id; - - } // end if; + } add_action('wu_checkout_scripts', array($gateway, 'register_scripts')); - $gateway->hooks(); + $gateway->hooks(); add_action('wu_settings_payment_gateways', array($gateway, 'settings')); - add_action("wu_{$gateway_id}_process_webhooks", array($gateway, 'process_webhooks')); add_action("wu_{$gateway_id}_remote_payment_url", array($gateway, 'get_payment_url_on_gateway')); @@ -546,13 +531,15 @@ class Gateway_Manager extends Base_Manager { /* * Renders the gateway fields. */ - add_action('wu_checkout_gateway_fields', function($checkout) use ($gateway) { + add_action( + 'wu_checkout_gateway_fields', + function ($checkout) use ($gateway) { - $field_content = call_user_func(array($gateway, 'fields')); + $field_content = call_user_func(array($gateway, 'fields')); - ob_start(); + ob_start(); - ?> + ?>
    @@ -560,13 +547,12 @@ class Gateway_Manager extends Base_Manager {
    - auto_renewable_gateways; - - } // end get_auto_renewable_gateways; - -} // end class Gateway_Manager; + } +} diff --git a/inc/managers/class-job-manager.php b/inc/managers/class-job-manager.php index a770211..a342bbe 100644 --- a/inc/managers/class-job-manager.php +++ b/inc/managers/class-job-manager.php @@ -32,7 +32,5 @@ class Job_Manager { * @return void */ public function init() { - - } // end init; - -} // end class Job_Manager; + } +} diff --git a/inc/managers/class-limitation-manager.php b/inc/managers/class-limitation-manager.php index 6572b5f..7166434 100644 --- a/inc/managers/class-limitation-manager.php +++ b/inc/managers/class-limitation-manager.php @@ -14,9 +14,9 @@ namespace WP_Ultimo\Managers; // Exit if accessed directly defined('ABSPATH') || exit; -use \Psr\Log\LogLevel; -use \WP_Ultimo\Objects\Limitations; -use \WP_Ultimo\Database\Sites\Site_Type; +use Psr\Log\LogLevel; +use WP_Ultimo\Objects\Limitations; +use WP_Ultimo\Database\Sites\Site_Type; /** * Handles processes related to limitations. @@ -36,10 +36,8 @@ class Limitation_Manager { public function init() { if (WP_Ultimo()->is_loaded() === false) { - return; - - } // end if; + } add_filter('wu_product_options_sections', array($this, 'add_limitation_sections'), 10, 2); @@ -52,8 +50,7 @@ class Limitation_Manager { add_action('wu_async_handle_plugins', array($this, 'async_handle_plugins'), 10, 5); add_action('wu_async_switch_theme', array($this, 'async_switch_theme'), 10, 2); - - } // end init; + } /** * Handles async plugin activation and deactivation. @@ -73,34 +70,25 @@ class Limitation_Manager { // Avoid doing anything on the main site. if (wu_get_main_site_id() === $site_id) { - return $results; - - } // end if; + } switch_to_blog($site_id); if ($action === 'activate') { - $results = activate_plugins($plugins, '', $network_wide, $silent); - } elseif ($action === 'deactivate') { - $results = deactivate_plugins($plugins, $silent, $network_wide); - - } // end if; + } if (is_wp_error($results)) { - wu_log_add('plugins', $results, LogLevel::ERROR); - - } // end if; + } restore_current_blog(); return $results; - - } // end async_handle_plugins; + } /** * Switch themes via Job Queue. @@ -120,8 +108,7 @@ class Limitation_Manager { restore_current_blog(); return true; - - } // end async_switch_theme; + } /** * Register the modal windows to confirm resetting the limitations. @@ -131,12 +118,14 @@ class Limitation_Manager { */ public function register_forms() { - wu_register_form('confirm_limitations_reset', array( - 'render' => array($this, 'render_confirm_limitations_reset'), - 'handler' => array($this, 'handle_confirm_limitations_reset'), - )); - - } // end register_forms; + wu_register_form( + 'confirm_limitations_reset', + array( + 'render' => array($this, 'render_confirm_limitations_reset'), + 'handler' => array($this, 'handle_confirm_limitations_reset'), + ) + ); + } /** * Renders the conformation modal to reset limitations. @@ -182,17 +171,18 @@ class Limitation_Manager { '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_limitations', - 'data-state' => json_encode(array( - 'confirmed' => false, - )), + 'data-state' => json_encode( + array( + 'confirmed' => false, + ) + ), ), ); $form = new \WP_Ultimo\UI\Form('reset_limitations', $fields, $form_attributes); $form->render(); - - } // end render_confirm_limitations_reset; + } /** * Handles the reset of permissions. @@ -206,28 +196,32 @@ class Limitation_Manager { $model = wu_request('model'); - if (!$id || !$model) { - - wp_send_json_error(new \WP_Error( - 'parameters-not-found', - __('Required parameters are missing.', 'wp-ultimo') - )); - - } // end if; + if ( ! $id || ! $model) { + wp_send_json_error( + new \WP_Error( + 'parameters-not-found', + __('Required parameters are missing.', 'wp-ultimo') + ) + ); + } /* * Remove limitations object */ Limitations::remove_limitations($model, $id); - wp_send_json_success(array( - 'redirect_url' => wu_network_admin_url("wp-ultimo-edit-{$model}", array( - 'id' => $id, - 'updated' => 1, - )) - )); - - } // end handle_confirm_limitations_reset; + wp_send_json_success( + array( + 'redirect_url' => wu_network_admin_url( + "wp-ultimo-edit-{$model}", + array( + 'id' => $id, + 'updated' => 1, + ) + ), + ) + ); + } /** * Returns the type of the object that has limitations. @@ -242,22 +236,15 @@ class Limitation_Manager { $model = false; if (is_a($object, \WP_Ultimo\Models\Site::class)) { - $model = 'site'; - } elseif (is_a($object, WP_Ultimo\Models\Membership::class)) { - $model = 'membership'; - } elseif (is_a($object, \WP_Ultimo\Models\Product::class)) { - $model = 'product'; - - } // end if; + } return apply_filters('wu_limitations_get_object_type', $model); - - } // end get_object_type; + } /** * Injects the limitations panels when necessary. @@ -271,7 +258,6 @@ class Limitation_Manager { public function add_limitation_sections($sections, $object) { if ($this->get_object_type($object) === 'site' && $object->get_type() !== Site_Type::CUSTOMER_OWNED) { - $html = sprintf('%s', __('Limitations are only available for customer-owned sites. You need to change the type to Customer-owned and save this site before the options are shown.', 'wp-ultimo')); $sections['sites'] = array( @@ -282,16 +268,14 @@ class Limitation_Manager { 'note' => array( 'type' => 'html', 'content' => $html, - ) - ) + ), + ), ); return $sections; - - } // end if; + } if ($this->get_object_type($object) !== 'site') { - $sections['sites'] = array( 'title' => __('Sites', 'wp-ultimo'), 'desc' => __('Control limitations imposed to the number of sites allowed for memberships attached to this product.', 'wp-ultimo'), @@ -302,14 +286,12 @@ class Limitation_Manager { 'limit_sites' => $object->get_limitations()->sites->is_enabled(), ), ); - - } // end if; + } /* * Add Visits limitation control */ if ((bool) wu_get_setting('enable_visits_limiting', true)) { - $sections['visits'] = array( 'title' => __('Visits', 'wp-ultimo'), 'desc' => __('Control limitations imposed to the number of unique visitors allowed for memberships attached to this product.', 'wp-ultimo'), @@ -325,17 +307,15 @@ class Limitation_Manager { 'desc' => __('Toggle this option to enable unique visits limitation.', 'wp-ultimo'), 'value' => 10, 'html_attr' => array( - 'v-model' => 'limit_visits' + 'v-model' => 'limit_visits', ), ), ), ); if ($object->model !== 'product') { - $sections['visits']['fields']['modules_visits_overwrite'] = $this->override_notice($object->get_limitations(false)->visits->has_own_enabled()); - - } // end if; + } $sections['visits']['fields']['modules[visits][limit]'] = array( 'type' => 'number', @@ -353,17 +333,14 @@ class Limitation_Manager { ); if ($object->model !== 'product') { - $sections['visits']['fields']['allowed_visits_overwrite'] = $this->override_notice($object->get_limitations(false)->visits->has_own_limit(), array('limit_visits')); - - } // end if; + } /* * If this is a site edit screen, show the current values * for visits and the reset date */ if ($this->get_object_type($object) === 'site') { - $sections['visits']['fields']['visits_count'] = array( 'type' => 'text-display', 'title' => __('Current Unique Visits Count this Month', 'wp-ultimo'), @@ -374,10 +351,8 @@ class Limitation_Manager { 'v-cloak' => '1', ), ); - - } // end if; - - } // end if; + } + } $sections['users'] = array( 'title' => __('Users', 'wp-ultimo'), @@ -393,17 +368,15 @@ class Limitation_Manager { 'title' => __('Limit User', 'wp-ultimo'), 'desc' => __('Enable user limitations for this product.', 'wp-ultimo'), 'html_attr' => array( - 'v-model' => 'limit_users' + 'v-model' => 'limit_users', ), ), ), ); if ($object->model !== 'product') { - $sections['users']['fields']['modules_user_overwrite'] = $this->override_notice($object->get_limitations(false)->users->has_own_enabled()); - - } // end if; + } $this->register_user_fields($sections, $object); @@ -429,10 +402,8 @@ class Limitation_Manager { ); if ($object->model !== 'product') { - $sections['post_types']['fields']['post_quota_overwrite'] = $this->override_notice($object->get_limitations(false)->post_types->has_own_enabled()); - - } // end if; + } $sections['post_types']['post_quota_note'] = array( 'type' => 'note', @@ -467,10 +438,8 @@ class Limitation_Manager { ); if ($object->model !== 'product') { - $sections['limit_disk_space']['fields']['disk_space_modules_overwrite'] = $this->override_notice($object->get_limitations(false)->disk_space->has_own_enabled()); - - } // end if; + } $sections['limit_disk_space']['fields']['modules[disk_space][limit]'] = array( 'type' => 'number', @@ -486,10 +455,8 @@ class Limitation_Manager { ); if ($object->model !== 'product') { - $sections['limit_disk_space']['fields']['disk_space_override'] = $this->override_notice($object->get_limitations(false)->disk_space->has_own_limit(), array('limit_disk_space')); - - } // end if; + } $sections['custom_domain'] = array( 'title' => __('Custom Domains', 'wp-ultimo'), @@ -516,10 +483,8 @@ class Limitation_Manager { ); if ($object->model !== 'product') { - $sections['custom_domain']['fields']['custom_domain_override'] = $this->override_notice($object->get_limitations(false)->domain_mapping->has_own_enabled(), array('allow_domain_mapping')); - - } // end if; + } $sections['allowed_themes'] = array( 'title' => __('Themes', 'wp-ultimo'), @@ -554,10 +519,13 @@ class Limitation_Manager { ), ); - $reset_url = wu_get_form_url('confirm_limitations_reset', array( - 'id' => $object->get_id(), - 'model' => $object->model, - )); + $reset_url = wu_get_form_url( + 'confirm_limitations_reset', + array( + 'id' => $object->get_id(), + 'model' => $object->model, + ) + ); $sections['reset_limitations'] = array( 'title' => __('Reset Limitations', 'wp-ultimo'), @@ -573,8 +541,7 @@ class Limitation_Manager { ); return $sections; - - } // end add_limitation_sections; + } /** * Generates the override notice. @@ -599,8 +566,7 @@ class Limitation_Manager { 'style' => 'border-top-width: 0 !important', ), ); - - } // end override_notice; + } /** * Register the user roles fields @@ -618,10 +584,9 @@ class Limitation_Manager { $sections['users']['state']['roles'] = array(); foreach ($user_roles as $user_role_slug => $user_role) { + $sections['users']['state']['roles'][ $user_role_slug ] = $object->get_limitations()->users->{$user_role_slug}; - $sections['users']['state']['roles'][$user_role_slug] = $object->get_limitations()->users->{$user_role_slug}; - - $sections['users']['fields']["control_{$user_role_slug}"] = array( + $sections['users']['fields'][ "control_{$user_role_slug}" ] = array( 'type' => 'group', 'title' => sprintf(__('Limit %s Role', 'wp-ultimo'), $user_role['name']), 'desc' => sprintf(__('The customer will be able to create %s users(s) of this user role.', 'wp-ultimo'), "{{ roles['{$user_role_slug}'].enabled ? ( parseInt(roles['{$user_role_slug}'].number, 10) ? roles['{$user_role_slug}'].number : '" . __('unlimited', 'wp-ultimo') . "' ) : '" . __('no', 'wp-ultimo') . "' }}"), @@ -656,14 +621,10 @@ class Limitation_Manager { * Add override notice. */ if ($object->model !== 'product') { - - $sections['users']['fields']["override_{$user_role_slug}"] = $this->override_notice($object->get_limitations(false)->users->exists($user_role_slug), array('limit_users')); - - } // end if; - - } // end foreach; - - } // end register_user_fields; + $sections['users']['fields'][ "override_{$user_role_slug}" ] = $this->override_notice($object->get_limitations(false)->users->exists($user_role_slug), array('limit_users')); + } + } + } /** * Register the post type fields @@ -681,10 +642,9 @@ class Limitation_Manager { $sections['post_types']['state']['types'] = array(); foreach ($post_types as $post_type_slug => $post_type) { + $sections['post_types']['state']['types'][ $post_type_slug ] = $object->get_limitations()->post_types->{$post_type_slug}; - $sections['post_types']['state']['types'][$post_type_slug] = $object->get_limitations()->post_types->{$post_type_slug}; - - $sections['post_types']['fields']["control_{$post_type_slug}"] = array( + $sections['post_types']['fields'][ "control_{$post_type_slug}" ] = array( 'type' => 'group', 'title' => sprintf(__('Limit %s', 'wp-ultimo'), $post_type->label), 'desc' => sprintf(__('The customer will be able to create %s post(s) of this post type.', 'wp-ultimo'), "{{ types['{$post_type_slug}'].enabled ? ( parseInt(types['{$post_type_slug}'].number, 10) ? types['{$post_type_slug}'].number : '" . __('unlimited', 'wp-ultimo') . "' ) : '" . __('no', 'wp-ultimo') . "' }}"), @@ -719,16 +679,15 @@ class Limitation_Manager { * Add override notice. */ if ($object->model !== 'product') { - - $sections['post_types']['fields']["override_{$post_type_slug}"] = $this->override_notice($object->get_limitations(false)->post_types->exists($post_type_slug), array( - 'limit_post_types' - )); - - } // end if; - - } // end foreach; - - } // end register_post_type_fields; + $sections['post_types']['fields'][ "override_{$post_type_slug}" ] = $this->override_notice( + $object->get_limitations(false)->post_types->exists($post_type_slug), + array( + 'limit_post_types', + ) + ); + } + } + } /** * Returns the list of fields for the site tab. @@ -747,16 +706,14 @@ class Limitation_Manager { 'desc' => __('Enable site limitations for this product.', 'wp-ultimo'), 'value' => $object->get_limitations()->sites->is_enabled(), 'html_attr' => array( - 'v-model' => 'limit_sites' + 'v-model' => 'limit_sites', ), ), ); if ($object->model !== 'product') { - $fields['sites_overwrite'] = $this->override_notice($object->get_limitations(false)->sites->has_own_enabled()); - - } // end if; + } /* * Sites not supported on this type @@ -785,14 +742,11 @@ class Limitation_Manager { ); if ($object->model !== 'product') { - $fields['sites_overwrite_2'] = $this->override_notice($object->get_limitations(false)->sites->has_own_limit(), array("get_state_value('product_type', 'none') !== 'service' && limit_sites")); - - } // end if; + } return apply_filters('wu_limitations_get_sites_fields', $fields, $object, $this); - - } // end get_sites_fields; + } /** * Returns the HTML markup for the plugin selector list. @@ -806,12 +760,14 @@ class Limitation_Manager { $all_plugins = $this->get_all_plugins(); - return wu_get_template_contents('limitations/plugin-selector', array( - 'plugins' => $all_plugins, - 'object' => $object, - )); - - } // end get_plugin_selection_list; + return wu_get_template_contents( + 'limitations/plugin-selector', + array( + 'plugins' => $all_plugins, + 'object' => $object, + ) + ); + } /** * Returns the HTML markup for the plugin selector list. @@ -826,13 +782,15 @@ class Limitation_Manager { $all_themes = $this->get_all_themes(); - return wu_get_template_contents('limitations/theme-selector', array( - 'section' => $section, - 'themes' => $all_themes, - 'object' => $object, - )); - - } // end get_theme_selection_list; + return wu_get_template_contents( + 'limitations/theme-selector', + array( + 'section' => $section, + 'themes' => $all_themes, + 'object' => $object, + ) + ); + } /** * Returns a list of all plugins available as options, excluding WP Multisite WaaS. @@ -849,26 +807,19 @@ class Limitation_Manager { $listed_plugins = array(); foreach ($all_plugins as $plugin_path => $plugin_info) { - if (wu_get_isset($plugin_info, 'Network') === true) { - continue; - - } // end if; + } if (in_array($plugin_path, $this->plugin_exclusion_list(), true)) { - continue; + } - } // end if; - - $listed_plugins[$plugin_path] = $plugin_info; - - } // end foreach; + $listed_plugins[ $plugin_path ] = $plugin_info; + } return $listed_plugins; - - } // end get_all_plugins; + } /** * Returns a list of all themes available as options, after filtering. * @@ -878,9 +829,8 @@ class Limitation_Manager { $all_plugins = wp_get_themes(); - return array_filter($all_plugins, fn($path) => !in_array($path, $this->theme_exclusion_list(), true), ARRAY_FILTER_USE_KEY); - - } // end get_all_themes; + return array_filter($all_plugins, fn($path) => ! in_array($path, $this->theme_exclusion_list(), true), ARRAY_FILTER_USE_KEY); + } /** * Returns the exclusion list for plugins. @@ -898,8 +848,7 @@ class Limitation_Manager { ); return apply_filters('wu_limitations_plugin_exclusion_list', $exclusion_list); - - } // end plugin_exclusion_list; + } /** * Returns the exclusion list for themes. @@ -912,7 +861,5 @@ class Limitation_Manager { $exclusion_list = array(); return apply_filters('wu_limitations_theme_exclusion_list', $exclusion_list); - - } // end theme_exclusion_list; - -} // end class Limitation_Manager; + } +} diff --git a/inc/managers/class-membership-manager.php b/inc/managers/class-membership-manager.php index 5712456..8be4ec3 100644 --- a/inc/managers/class-membership-manager.php +++ b/inc/managers/class-membership-manager.php @@ -11,9 +11,9 @@ namespace WP_Ultimo\Managers; -use \Psr\Log\LogLevel; -use \WP_Ultimo\Managers\Base_Manager; -use \WP_Ultimo\Database\Memberships\Membership_Status; +use Psr\Log\LogLevel; +use WP_Ultimo\Managers\Base_Manager; +use WP_Ultimo\Database\Memberships\Membership_Status; // Exit if accessed directly defined('ABSPATH') || exit; @@ -25,7 +25,9 @@ defined('ABSPATH') || exit; */ class Membership_Manager extends Base_Manager { - use \WP_Ultimo\Apis\Rest_Api, \WP_Ultimo\Apis\WP_CLI, \WP_Ultimo\Traits\Singleton; + use \WP_Ultimo\Apis\Rest_Api; + use \WP_Ultimo\Apis\WP_CLI; + use \WP_Ultimo\Traits\Singleton; /** * The manager slug. @@ -55,9 +57,12 @@ class Membership_Manager extends Base_Manager { $this->enable_wp_cli(); - add_action('init', function (){ - Event_Manager::register_model_events('membership', __('Membership', 'wp-ultimo'), array('created', 'updated')); - }); + add_action( + 'init', + function () { + Event_Manager::register_model_events('membership', __('Membership', 'wp-ultimo'), array('created', 'updated')); + } + ); add_action('wu_async_transfer_membership', array($this, 'async_transfer_membership'), 10, 2); @@ -83,8 +88,7 @@ class Membership_Manager extends Base_Manager { add_action('wp_ajax_wu_check_pending_site_created', array($this, 'check_pending_site_created')); add_action('wu_async_publish_pending_site', array($this, 'async_publish_pending_site'), 10); - - } // end init; + } /** * Processes a delayed site publish action. @@ -98,50 +102,42 @@ class Membership_Manager extends Base_Manager { ignore_user_abort(true); // Don't make the request block till we finish, if possible. - if ( function_exists( 'fastcgi_finish_request' ) && version_compare( phpversion(), '7.0.16', '>=' ) ) { - - wp_send_json(array( 'status' => 'creating-site')); + if ( function_exists('fastcgi_finish_request') && version_compare(phpversion(), '7.0.16', '>=') ) { + wp_send_json(array('status' => 'creating-site')); fastcgi_finish_request(); - - } // end if; + } $membership_id = wu_request('membership_id'); $this->async_publish_pending_site($membership_id); exit; // Just exit the request - - } // end publish_pending_site; - /** - * Processes a delayed site publish action. - * - * @since 2.0.0 - * - * @param int $membership_id The membership id. - * @return bool|\WP_Error - */ - public function async_publish_pending_site($membership_id) { + } + /** + * Processes a delayed site publish action. + * + * @since 2.0.0 + * + * @param int $membership_id The membership id. + * @return bool|\WP_Error + */ + public function async_publish_pending_site($membership_id) { $membership = wu_get_membership($membership_id); - if (!$membership) { - + if ( ! $membership) { return new \WP_Error('error', __('An unexpected error happened.', 'wp-ultimo')); - - } // end if; + } $status = $membership->publish_pending_site(); if (is_wp_error($status)) { - wu_log_add('site-errors', $status, LogLevel::ERROR); - - } // end if; + } return $status; - - } // end async_publish_pending_site; + } /** * Processes a delayed site publish action. @@ -154,82 +150,68 @@ class Membership_Manager extends Base_Manager { $membership = wu_get_membership_by_hash($membership_id); - if (!$membership) { - + if ( ! $membership) { return new \WP_Error('error', __('An unexpected error happened.', 'wp-ultimo')); - - } // end if; + } $pending_site = $membership->get_pending_site(); - if (!$pending_site) { + if ( ! $pending_site) { /** * We do not have a pending site, so we can assume the site was created. */ wp_send_json(array('publish_status' => 'completed')); exit; - - } // end if; + } wp_send_json(array('publish_status' => $pending_site->is_publishing() ? 'running' : 'stopped')); exit; - - } // end check_pending_site_created; - /** - * Processes a membership swap. - * - * @since 2.0.0 - * - * @param int $membership_id The membership id. - * @return bool|\WP_Error - */ - public function async_membership_swap($membership_id) { + } + /** + * Processes a membership swap. + * + * @since 2.0.0 + * + * @param int $membership_id The membership id. + * @return bool|\WP_Error + */ + public function async_membership_swap($membership_id) { global $wpdb; $membership = wu_get_membership($membership_id); - if (!$membership) { - + if ( ! $membership) { return new \WP_Error('error', __('An unexpected error happened.', 'wp-ultimo')); - - } // end if; + } $scheduled_swap = $membership->get_scheduled_swap(); if (empty($scheduled_swap)) { - return new \WP_Error('error', __('An unexpected error happened.', 'wp-ultimo')); - - } // end if; + } $order = $scheduled_swap->order; $wpdb->query('START TRANSACTION'); try { - $membership->swap($order); $status = $membership->save(); if (is_wp_error($status)) { - $wpdb->query('ROLLBACK'); return new \WP_Error('error', __('An unexpected error happened.', 'wp-ultimo')); - - } // end if; - + } } catch (\Throwable $exception) { - $wpdb->query('ROLLBACK'); return new \WP_Error('error', __('An unexpected error happened.', 'wp-ultimo')); - - } // end try; + } /* * Clean up the membership swap order. @@ -239,8 +221,7 @@ class Membership_Manager extends Base_Manager { $wpdb->query('COMMIT'); return true; - - } // end async_membership_swap; + } /** * Watches the change in payment status to take action when needed. @@ -261,22 +242,18 @@ class Membership_Manager extends Base_Manager { Membership_Status::ON_HOLD, ); - if (!in_array($old_status, $allowed_previous_status, true)) { - + if ( ! in_array($old_status, $allowed_previous_status, true)) { return; - - } // end if; + } $allowed_status = array( Membership_Status::ACTIVE, Membership_Status::TRIALING, ); - if (!in_array($new_status, $allowed_status, true)) { - + if ( ! in_array($new_status, $allowed_status, true)) { return; - - } // end if; + } /* * Create pending sites. @@ -286,12 +263,9 @@ class Membership_Manager extends Base_Manager { $status = $membership->publish_pending_site_async(); if (is_wp_error($status)) { - wu_log_add('site-errors', $status, LogLevel::ERROR); - - } // end if; - - } // end transition_membership_status; + } + } /** * Mark the membership date of cancellation. @@ -306,16 +280,13 @@ class Membership_Manager extends Base_Manager { public function mark_cancelled_date($old_value, $new_value, $item_id) { if ($new_value === 'cancelled' && $new_value !== $old_value) { - $membership = wu_get_membership($item_id); $membership->set_date_cancellation(wu_get_current_time('mysql', true)); $membership->save(); - - } // end if; - - } // end mark_cancelled_date; + } + } /** * Transfer a membership from a user to another. @@ -334,11 +305,9 @@ class Membership_Manager extends Base_Manager { $target_customer = wu_get_customer($target_customer_id); - if (!$membership || !$target_customer || absint($membership->get_customer_id()) === absint($target_customer->get_id())) { - + if ( ! $membership || ! $target_customer || absint($membership->get_customer_id()) === absint($target_customer->get_id())) { return new \WP_Error('error', __('An unexpected error happened.', 'wp-ultimo')); - - } // end if; + } $wpdb->query('START TRANSACTION'); @@ -346,30 +315,28 @@ class Membership_Manager extends Base_Manager { /* * Get Sites and move them over. */ - $sites = wu_get_sites(array( - 'meta_query' => array( - 'membership_id' => array( - 'key' => 'wu_membership_id', - 'value' => $membership->get_id(), + $sites = wu_get_sites( + array( + 'meta_query' => array( + 'membership_id' => array( + 'key' => 'wu_membership_id', + 'value' => $membership->get_id(), + ), ), - ), - )); + ) + ); foreach ($sites as $site) { - $site->set_customer_id($target_customer_id); $saved = $site->save(); if (is_wp_error($saved)) { - $wpdb->query('ROLLBACK'); return $saved; - - } // end if; - - } // end foreach; + } + } /* * Change the membership @@ -379,28 +346,22 @@ class Membership_Manager extends Base_Manager { $saved = $membership->save(); if (is_wp_error($saved)) { - $wpdb->query('ROLLBACK'); return $saved; - - } // end if; - + } } catch (\Throwable $e) { - $wpdb->query('ROLLBACK'); return new \WP_Error('exception', $e->getMessage()); - - } // end try; + } $wpdb->query('COMMIT'); $membership->unlock(); return true; - - } // end async_transfer_membership; + } /** * Delete a membership. @@ -416,11 +377,9 @@ class Membership_Manager extends Base_Manager { $membership = wu_get_membership($membership_id); - if (!$membership) { - + if ( ! $membership) { return new \WP_Error('error', __('An unexpected error happened.', 'wp-ultimo')); - - } // end if; + } $wpdb->query('START TRANSACTION'); @@ -428,28 +387,26 @@ class Membership_Manager extends Base_Manager { /* * Get Sites and delete them. */ - $sites = wu_get_sites(array( - 'meta_query' => array( - 'membership_id' => array( - 'key' => 'wu_membership_id', - 'value' => $membership->get_id(), + $sites = wu_get_sites( + array( + 'meta_query' => array( + 'membership_id' => array( + 'key' => 'wu_membership_id', + 'value' => $membership->get_id(), + ), ), - ), - )); + ) + ); foreach ($sites as $site) { - $saved = $site->delete(); if (is_wp_error($saved)) { - $wpdb->query('ROLLBACK'); return $saved; - - } // end if; - - } // end foreach; + } + } /* * Delete the membership @@ -457,25 +414,18 @@ class Membership_Manager extends Base_Manager { $saved = $membership->delete(); if (is_wp_error($saved)) { - $wpdb->query('ROLLBACK'); return $saved; - - } // end if; - + } } catch (\Throwable $e) { - $wpdb->query('ROLLBACK'); return new \WP_Error('exception', $e->getMessage()); - - } // end try; + } $wpdb->query('COMMIT'); return true; - - } // end async_delete_membership; - -} // end class Membership_Manager; + } +} diff --git a/inc/managers/class-notes-manager.php b/inc/managers/class-notes-manager.php index c6f0380..a47fee9 100644 --- a/inc/managers/class-notes-manager.php +++ b/inc/managers/class-notes-manager.php @@ -11,7 +11,7 @@ namespace WP_Ultimo\Managers; -use \WP_Ultimo\Managers\Base_Manager; +use WP_Ultimo\Managers\Base_Manager; // Exit if accessed directly defined('ABSPATH') || exit; @@ -58,10 +58,9 @@ class Notes_Manager extends Base_Manager { add_filter('wu_customer_options_sections', array($this, 'add_notes_options_section'), 10, 2); add_filter('wu_site_options_sections', array($this, 'add_notes_options_section'), 10, 2); + } - } // end init; - - /** + /** * Register ajax forms that we use for object. * * @since 2.0.0 @@ -71,33 +70,41 @@ class Notes_Manager extends Base_Manager { /* * Add note */ - wu_register_form('add_note', array( - 'render' => array($this, 'render_add_note_modal'), - 'handler' => array($this, 'handle_add_note_modal'), - 'capability' => 'edit_notes', - )); + wu_register_form( + 'add_note', + array( + 'render' => array($this, 'render_add_note_modal'), + 'handler' => array($this, 'handle_add_note_modal'), + 'capability' => 'edit_notes', + ) + ); /* * Clear notes */ - wu_register_form('clear_notes', array( - 'render' => array($this, 'render_clear_notes_modal'), - 'handler' => array($this, 'handle_clear_notes_modal'), - 'capability' => 'delete_notes', - )); + wu_register_form( + 'clear_notes', + array( + 'render' => array($this, 'render_clear_notes_modal'), + 'handler' => array($this, 'handle_clear_notes_modal'), + 'capability' => 'delete_notes', + ) + ); /* * Clear notes */ - wu_register_form('delete_note', array( - 'render' => array($this, 'render_delete_note_modal'), - 'handler' => array($this, 'handle_delete_note_modal'), - 'capability' => 'delete_notes', - )); + wu_register_form( + 'delete_note', + array( + 'render' => array($this, 'render_delete_note_modal'), + 'handler' => array($this, 'handle_delete_note_modal'), + 'capability' => 'delete_notes', + ) + ); + } - } // end register_forms; - - /** + /** * Add all domain mapping settings. * * @since 2.0.0 @@ -109,11 +116,9 @@ class Notes_Manager extends Base_Manager { */ public function add_notes_options_section($sections, $object) { - if (!current_user_can('read_notes') && !current_user_can('edit_notes')) { - + if ( ! current_user_can('read_notes') && ! current_user_can('edit_notes')) { return $sections; - - } // end if; + } $fields = array(); @@ -123,50 +128,55 @@ class Notes_Manager extends Base_Manager { 'wrapper_html_attr' => array( 'style' => sprintf('min-height: 500px; background: url("%s");', wu_get_asset('pattern-wp-ultimo.png')), ), - 'content' => wu_get_template_contents('base/edit/display-notes', array( - 'notes' => $object->get_notes(), - 'model' => $object->model, - )), + 'content' => wu_get_template_contents( + 'base/edit/display-notes', + array( + 'notes' => $object->get_notes(), + 'model' => $object->model, + ) + ), ); $fields_buttons = array(); if (current_user_can('delete_notes')) { - $fields_buttons['button_clear_notes'] = array( 'type' => 'link', 'display_value' => __('Clear Notes', 'wp-ultimo'), 'wrapper_classes' => 'wu-mb-0', 'classes' => 'button wubox', 'html_attr' => array( - 'href' => wu_get_form_url('clear_notes', array( - 'object_id' => $object->get_id(), - 'model' => $object->model, - )), + 'href' => wu_get_form_url( + 'clear_notes', + array( + 'object_id' => $object->get_id(), + 'model' => $object->model, + ) + ), 'title' => __('Clear Notes', 'wp-ultimo'), ), ); - - } // end if; + } if (current_user_can('edit_notes')) { - $fields_buttons['button_add_note'] = array( 'type' => 'link', 'display_value' => __('Add new Note', 'wp-ultimo'), 'wrapper_classes' => 'wu-mb-0', 'classes' => 'button button-primary wubox wu-absolute wu-right-5', 'html_attr' => array( - 'href' => wu_get_form_url('add_note', array( - 'object_id' => $object->get_id(), - 'model' => $object->model, - 'height' => 306, - )), + 'href' => wu_get_form_url( + 'add_note', + array( + 'object_id' => $object->get_id(), + 'model' => $object->model, + 'height' => 306, + ) + ), 'title' => __('Add new Note', 'wp-ultimo'), ), ); - - } // end if; + } $fields['buttons'] = array( 'type' => 'group', @@ -183,8 +193,7 @@ class Notes_Manager extends Base_Manager { ); return $sections; - - } // end add_notes_options_section; + } /** * Renders the notes form. @@ -229,21 +238,26 @@ class Notes_Manager extends Base_Manager { $fields = apply_filters('wu_notes_options_section_fields', $fields); - $form = new \WP_Ultimo\UI\Form('add_note', $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_note', - 'data-state' => wu_convert_to_state(array( - 'content' => '', - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'add_note', + $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_note', + 'data-state' => wu_convert_to_state( + array( + 'content' => '', + ) + ), + ), + ) + ); $form->render(); - - } // end render_add_note_modal; + } /** * Handles the notes form. @@ -257,27 +271,31 @@ class Notes_Manager extends Base_Manager { $function_name = "wu_get_{$model}"; $object = $function_name(wu_request('object_id')); - $status = $object->add_note(array( - 'text' => wu_remove_empty_p(wu_request('content')), - 'author_id' => get_current_user_id(), - 'note_id' => uniqid(), - )); + $status = $object->add_note( + array( + 'text' => wu_remove_empty_p(wu_request('content')), + 'author_id' => get_current_user_id(), + 'note_id' => uniqid(), + ) + ); if (is_wp_error($status)) { - wp_send_json_error($status); + } - } // end if; - - wp_send_json_success(array( - 'redirect_url' => wu_network_admin_url("wp-ultimo-edit-{$model}", array( - 'id' => $object->get_id(), - 'updated' => 1, - 'options' => 'notes', - )), - )); - - } // end handle_add_note_modal; + wp_send_json_success( + array( + 'redirect_url' => wu_network_admin_url( + "wp-ultimo-edit-{$model}", + array( + 'id' => $object->get_id(), + 'updated' => 1, + 'options' => 'notes', + ) + ), + ) + ); + } /** * Renders the clear notes confirmation form. @@ -317,21 +335,26 @@ class Notes_Manager extends Base_Manager { ), ); - $form = new \WP_Ultimo\UI\Form('clear_notes', $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' => 'clear_notes', - 'data-state' => wu_convert_to_state(array( - 'confirmed' => false, - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'clear_notes', + $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' => 'clear_notes', + 'data-state' => wu_convert_to_state( + array( + 'confirmed' => false, + ) + ), + ), + ) + ); $form->render(); - - } // end render_clear_notes_modal; + } /** * Handles the clear notes modal. @@ -345,29 +368,29 @@ class Notes_Manager extends Base_Manager { $function_name = "wu_get_{$model}"; $object = $function_name(wu_request('object_id')); - if (!$object) { - + if ( ! $object) { return; - - } // end if; + } $status = $object->clear_notes(); if (is_wp_error($status)) { - wp_send_json_error($status); + } - } // end if; - - wp_send_json_success(array( - 'redirect_url' => wu_network_admin_url("wp-ultimo-edit-{$model}", array( - 'id' => $object->get_id(), - 'deleted' => 1, - 'options' => 'notes', - )), - )); - - } // end handle_clear_notes_modal; + wp_send_json_success( + array( + 'redirect_url' => wu_network_admin_url( + "wp-ultimo-edit-{$model}", + array( + 'id' => $object->get_id(), + 'deleted' => 1, + 'options' => 'notes', + ) + ), + ) + ); + } /** * Renders the delete note confirmation form. @@ -411,21 +434,26 @@ class Notes_Manager extends Base_Manager { ), ); - $form = new \WP_Ultimo\UI\Form('delete_note', $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' => 'delete_note', - 'data-state' => wu_convert_to_state(array( - 'confirmed' => false, - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'delete_note', + $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' => 'delete_note', + 'data-state' => wu_convert_to_state( + array( + 'confirmed' => false, + ) + ), + ), + ) + ); $form->render(); - - } // end render_delete_note_modal; + } /** * Handles the delete note modal. @@ -440,28 +468,27 @@ class Notes_Manager extends Base_Manager { $object = $function_name(wu_request('object_id')); $note_id = wu_request('note_id'); - if (!$object) { - + if ( ! $object) { return; - - } // end if; + } $status = $object->delete_note($note_id); if (is_wp_error($status) || $status === false) { - wp_send_json_error(new \WP_Error('not-found', __('Note not found', 'wp-ultimo'))); + } - } // end if; - - wp_send_json_success(array( - 'redirect_url' => wu_network_admin_url("wp-ultimo-edit-{$model}", array( - 'id' => $object->get_id(), - 'deleted' => 1, - 'options' => 'notes', - )), - )); - - } // end handle_delete_note_modal; - -} // end class Notes_Manager; + wp_send_json_success( + array( + 'redirect_url' => wu_network_admin_url( + "wp-ultimo-edit-{$model}", + array( + 'id' => $object->get_id(), + 'deleted' => 1, + 'options' => 'notes', + ) + ), + ) + ); + } +} diff --git a/inc/managers/class-notification-manager.php b/inc/managers/class-notification-manager.php index 2d98c3d..fa883c5 100644 --- a/inc/managers/class-notification-manager.php +++ b/inc/managers/class-notification-manager.php @@ -41,13 +41,10 @@ class Notification_Manager { add_action('wp_ultimo_load', array($this, 'add_settings')); - if (is_admin() && !is_network_admin()) { - + if (is_admin() && ! is_network_admin()) { add_action('admin_init', array($this, 'hide_notifications_subsites')); - - } // end if; - - } // end init; + } + } /** * Hide notifications on subsites if settings was enabled. @@ -57,36 +54,32 @@ class Notification_Manager { */ public function hide_notifications_subsites() { - if (!wu_get_setting('hide_notifications_subsites')) { - + if ( ! wu_get_setting('hide_notifications_subsites')) { return; - - } // end if; + } global $wp_filter; /* * List of callbacks to keep, for backwards compatibility purposes. */ - $this->backwards_compatibility_list = apply_filters('wu_hide_notifications_exclude_list', array( - 'inject_admin_head_ads', - )); + $this->backwards_compatibility_list = apply_filters( + 'wu_hide_notifications_exclude_list', + array( + 'inject_admin_head_ads', + ) + ); $cleaner = array($this, 'clear_callback_list'); if (wu_get_isset($wp_filter, 'admin_notices')) { - - $wp_filter['admin_notices']->callbacks = array_filter($wp_filter['admin_notices']->callbacks, $cleaner === null ? fn($v, $k): bool => !empty($v) : $cleaner, $cleaner === null ? ARRAY_FILTER_USE_BOTH : 0); - - } // end if; + $wp_filter['admin_notices']->callbacks = array_filter($wp_filter['admin_notices']->callbacks, $cleaner === null ? fn($v, $k): bool => ! empty($v) : $cleaner, $cleaner === null ? ARRAY_FILTER_USE_BOTH : 0); + } if (wu_get_isset($wp_filter, 'all_admin_notices')) { - - $wp_filter['all_admin_notices']->callbacks = array_filter($wp_filter['all_admin_notices']->callbacks, $cleaner === null ? fn($v, $k): bool => !empty($v) : $cleaner, $cleaner === null ? ARRAY_FILTER_USE_BOTH : 0); - - } // end if; - - } // end hide_notifications_subsites; + $wp_filter['all_admin_notices']->callbacks = array_filter($wp_filter['all_admin_notices']->callbacks, $cleaner === null ? fn($v, $k): bool => ! empty($v) : $cleaner, $cleaner === null ? ARRAY_FILTER_USE_BOTH : 0); + } + } /** * Keeps the allowed callbacks. @@ -99,30 +92,21 @@ class Notification_Manager { public function clear_callback_list($callbacks): bool { if (empty($this->backwards_compatibility_list)) { - return false; - - } // end if; + } $keys = array_keys($callbacks); foreach ($keys as $key) { - foreach ($this->backwards_compatibility_list as $key_to_keep) { - if (strpos($key, (string) $key_to_keep) !== false) { - return true; - - } // end if; - - } // end foreach; - - } // end foreach; + } + } + } return false; - - } // end clear_callback_list; + } /** * Filter the WP Multisite WaaS settings to add Notifications Options @@ -133,14 +117,16 @@ class Notification_Manager { */ public function add_settings() { - wu_register_settings_field('sites', 'hide_notifications_subsites', array( - 'title' => __('Hide Admin Notices on Sites', 'wp-ultimo'), - 'desc' => __('Hide all admin notices on network sites, except for WP Multisite WaaS broadcasts.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - 'order' => 25, - )); - - } // end add_settings; - -} // end class Notification_Manager; + wu_register_settings_field( + 'sites', + 'hide_notifications_subsites', + array( + 'title' => __('Hide Admin Notices on Sites', 'wp-ultimo'), + 'desc' => __('Hide all admin notices on network sites, except for WP Multisite WaaS broadcasts.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + 'order' => 25, + ) + ); + } +} diff --git a/inc/managers/class-payment-manager.php b/inc/managers/class-payment-manager.php index 6b88250..0a418ee 100644 --- a/inc/managers/class-payment-manager.php +++ b/inc/managers/class-payment-manager.php @@ -11,11 +11,11 @@ namespace WP_Ultimo\Managers; -use \WP_Ultimo\Managers\Base_Manager; -use \WP_Ultimo\Models\Payment; -use \WP_Ultimo\Logger; -use \WP_Ultimo\Invoices\Invoice; -use \WP_Ultimo\Checkout\Cart; +use WP_Ultimo\Managers\Base_Manager; +use WP_Ultimo\Models\Payment; +use WP_Ultimo\Logger; +use WP_Ultimo\Invoices\Invoice; +use WP_Ultimo\Checkout\Cart; // Exit if accessed directly defined('ABSPATH') || exit; @@ -27,7 +27,9 @@ defined('ABSPATH') || exit; */ class Payment_Manager extends Base_Manager { - use \WP_Ultimo\Apis\Rest_Api, \WP_Ultimo\Apis\WP_CLI, \WP_Ultimo\Traits\Singleton; + use \WP_Ultimo\Apis\Rest_Api; + use \WP_Ultimo\Apis\WP_CLI; + use \WP_Ultimo\Traits\Singleton; /** * The manager slug. @@ -59,11 +61,16 @@ class Payment_Manager extends Base_Manager { $this->register_forms(); - add_action('init', function () { - Event_Manager::register_model_events( 'payment', - __( 'Payment', 'wp-ultimo' ), - array( 'created', 'updated' ) ); - }); + add_action( + 'init', + function () { + Event_Manager::register_model_events( + 'payment', + __('Payment', 'wp-ultimo'), + array('created', 'updated') + ); + } + ); add_action('wp_login', array($this, 'check_pending_payments'), 10); add_action('wp_enqueue_scripts', array($this, 'show_pending_payments'), 10); @@ -79,8 +86,7 @@ class Payment_Manager extends Base_Manager { add_action('wu_gateway_payment_processed', array($this, 'handle_payment_success'), 10, 3); add_action('wu_transition_payment_status', array($this, 'transition_payment_status'), 10, 3); - - } // end init; + } /** * Triggers the do_event of the payment successful. @@ -101,8 +107,7 @@ class Payment_Manager extends Base_Manager { ); wu_do_event('payment_received', $payload); - - } // end handle_payment_success; + } /** * Check if current customer haves pending payments @@ -112,47 +117,34 @@ class Payment_Manager extends Base_Manager { */ public function check_pending_payments($user) { - if (!is_main_site()) { - + if ( ! is_main_site()) { return; + } - } // end if; - - if (!is_a($user, '\WP_User')) { - + if ( ! is_a($user, '\WP_User')) { $user = get_user_by('login', $user); + } - } // end if; - - if (!$user) { - + if ( ! $user) { return; - - } // end if; + } $customer = wu_get_customer_by_user_id($user->ID); - if (!$customer) { - + if ( ! $customer) { return; - - } // end if; + } foreach ($customer->get_memberships() as $membership) { - $pending_payment = $membership->get_last_pending_payment(); if ($pending_payment) { - add_user_meta($user->ID, 'wu_show_pending_payment_popup', true, true); break; - - } // end if; - - } // end foreach; - - } // end check_pending_payments; + } + } + } /** * Add and trigger a popup in screen with the pending payments @@ -161,21 +153,17 @@ class Payment_Manager extends Base_Manager { */ public function show_pending_payments() { - if (!is_user_logged_in()) { - + if ( ! is_user_logged_in()) { return; - - } // end if; + } $user_id = get_current_user_id(); $show_pending_payment = get_user_meta($user_id, 'wu_show_pending_payment_popup', true); - if (!$show_pending_payment) { - + if ( ! $show_pending_payment) { return; - - } // end if; + } wp_enqueue_style('dashicons'); wp_enqueue_style('wu-admin'); @@ -184,12 +172,11 @@ class Payment_Manager extends Base_Manager { $form_title = __('Pending Payments', 'wp-ultimo'); $form_url = wu_get_form_url('pending_payments'); - wp_add_inline_script( 'wubox', "document.addEventListener('DOMContentLoaded', function(){wubox.show('$form_title', '$form_url');});" ); + wp_add_inline_script('wubox', "document.addEventListener('DOMContentLoaded', function(){wubox.show('$form_title', '$form_url');});"); // Show only after user login delete_user_meta($user_id, 'wu_show_pending_payment_popup'); - - } // end show_pending_payments; + } /** * Register the form showing the pending payments of current customer @@ -199,15 +186,15 @@ class Payment_Manager extends Base_Manager { public function register_forms() { if (function_exists('wu_register_form')) { - - wu_register_form('pending_payments', array( - 'render' => array($this, 'render_pending_payments'), - 'capability' => 'exist', - )); - - } // end if; - - } // end register_forms; + wu_register_form( + 'pending_payments', + array( + 'render' => array($this, 'render_pending_payments'), + 'capability' => 'exist', + ) + ); + } + } /** * Add customerr pending payments @@ -216,37 +203,29 @@ class Payment_Manager extends Base_Manager { */ public function render_pending_payments() { - if (!is_user_logged_in()) { - + if ( ! is_user_logged_in()) { return; - - } // end if; + } $user_id = get_current_user_id(); $customer = wu_get_customer_by_user_id($user_id); - if (!$customer) { - + if ( ! $customer) { return; - - } // end if; + } $pending_payments = array(); foreach ($customer->get_memberships() as $membership) { - $pending_payment = $membership->get_last_pending_payment(); if ($pending_payment) { - $pending_payments[] = $pending_payment; + } + } - } // end if; - - } // end foreach; - - $message = !empty($pending_payments) ? __('You have pending payments on your account!', 'wp-ultimo') : __('You do not have pending payments on your account!', 'wp-ultimo'); + $message = ! empty($pending_payments) ? __('You have pending payments on your account!', 'wp-ultimo') : __('You do not have pending payments on your account!', 'wp-ultimo'); /** * Allow user to change the message about the pending payments. @@ -269,7 +248,6 @@ class Payment_Manager extends Base_Manager { ); foreach ($pending_payments as $payment) { - $slug = $payment->get_hash(); $url = $payment->get_payment_url(); @@ -283,18 +261,20 @@ class Payment_Manager extends Base_Manager { 'title' => $title, 'desc' => $html, ); + } - } // end foreach; - - $form = new \WP_Ultimo\UI\Form('pending-payments', $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', - )); + $form = new \WP_Ultimo\UI\Form( + 'pending-payments', + $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', + ) + ); $form->render(); - - } // end render_pending_payments; + } /** * Adds an init endpoint to render the invoices. @@ -309,19 +289,16 @@ class Payment_Manager extends Base_Manager { /* * Validates nonce. */ - if (!wp_verify_nonce(wu_request('key'), 'see_invoice')) { + if ( ! wp_verify_nonce(wu_request('key'), 'see_invoice')) { // wp_die(__('You do not have permissions to access this file.', 'wp-ultimo')); - - } // end if; + } $payment = wu_get_payment_by_hash(wu_request('reference')); - if (!$payment) { - + if ( ! $payment) { wp_die(__('This invoice does not exist.', 'wp-ultimo')); - - } // end if; + } $invoice = new Invoice($payment); @@ -331,10 +308,8 @@ class Payment_Manager extends Base_Manager { $invoice->print_file(); exit; - - } // end if; - - } // end invoice_viewer; + } + } /** * Transfer a payment from a user to another. @@ -353,11 +328,9 @@ class Payment_Manager extends Base_Manager { $target_customer = wu_get_customer($target_customer_id); - if (!$payment || !$target_customer || $payment->get_customer_id() === $target_customer->get_id()) { - + if ( ! $payment || ! $target_customer || $payment->get_customer_id() === $target_customer->get_id()) { return new \WP_Error('error', __('An unexpected error happened.', 'wp-ultimo')); - - } // end if; + } $wpdb->query('START TRANSACTION'); @@ -371,26 +344,20 @@ class Payment_Manager extends Base_Manager { $saved = $payment->save(); if (is_wp_error($saved)) { - $wpdb->query('ROLLBACK'); return $saved; - - } // end if; - + } } catch (\Throwable $e) { - $wpdb->query('ROLLBACK'); return new \WP_Error('exception', $e->getMessage()); - - } // end try; + } $wpdb->query('COMMIT'); return true; - - } // end async_transfer_payment; + } /** * Delete a payment. @@ -406,11 +373,9 @@ class Payment_Manager extends Base_Manager { $payment = wu_get_payment($payment_id); - if (!$payment) { - + if ( ! $payment) { return new \WP_Error('error', __('An unexpected error happened.', 'wp-ultimo')); - - } // end if; + } $wpdb->query('START TRANSACTION'); @@ -422,26 +387,20 @@ class Payment_Manager extends Base_Manager { $saved = $payment->delete(); if (is_wp_error($saved)) { - $wpdb->query('ROLLBACK'); return $saved; - - } // end if; - + } } catch (\Throwable $e) { - $wpdb->query('ROLLBACK'); return new \WP_Error('exception', $e->getMessage()); - - } // end try; + } $wpdb->query('COMMIT'); return true; - - } // end async_delete_payment; + } /** * Watches the change in payment status to take action when needed. @@ -459,19 +418,15 @@ class Payment_Manager extends Base_Manager { 'completed', ); - if (!in_array($new_status, $completable_statuses, true)) { - + if ( ! in_array($new_status, $completable_statuses, true)) { return; - - } // end if; + } $payment = wu_get_payment($payment_id); - if (!$payment || $payment->get_saved_invoice_number()) { - + if ( ! $payment || $payment->get_saved_invoice_number()) { return; - - } // end if; + } $current_invoice_number = absint(wu_get_setting('next_invoice_number', 1)); @@ -480,7 +435,5 @@ class Payment_Manager extends Base_Manager { $payment->save(); return wu_save_setting('next_invoice_number', $current_invoice_number + 1); - - } // end transition_payment_status; - -} // end class Payment_Manager; + } +} diff --git a/inc/managers/class-product-manager.php b/inc/managers/class-product-manager.php index c753b12..f100085 100644 --- a/inc/managers/class-product-manager.php +++ b/inc/managers/class-product-manager.php @@ -24,7 +24,9 @@ defined('ABSPATH') || exit; */ class Product_Manager extends Base_Manager { - use \WP_Ultimo\Apis\Rest_Api, \WP_Ultimo\Apis\WP_CLI, \WP_Ultimo\Traits\Singleton; + use \WP_Ultimo\Apis\Rest_Api; + use \WP_Ultimo\Apis\WP_CLI; + use \WP_Ultimo\Traits\Singleton; /** * The manager slug. @@ -53,7 +55,5 @@ class Product_Manager extends Base_Manager { $this->enable_rest_api(); $this->enable_wp_cli(); - - } // end init; - -} // end class Product_Manager; + } +} diff --git a/inc/managers/class-signup-fields-manager.php b/inc/managers/class-signup-fields-manager.php index 81ab690..b595fe1 100644 --- a/inc/managers/class-signup-fields-manager.php +++ b/inc/managers/class-signup-fields-manager.php @@ -90,8 +90,7 @@ class Signup_Fields_Manager extends Base_Manager { * @return array */ return apply_filters('wu_checkout_field_types', $field_types); - - } // end get_field_types; + } /** * Instantiate a field type. @@ -104,8 +103,7 @@ class Signup_Fields_Manager extends Base_Manager { public function instantiate_field_type($class_name) { return new $class_name(); - - } // end instantiate_field_type; + } /** * Returns an array with all fields, instantiated. @@ -116,14 +114,11 @@ class Signup_Fields_Manager extends Base_Manager { public function get_instantiated_field_types() { if ($this->instantiated_field_types === null) { - $this->instantiated_field_types = array_map(array($this, 'instantiate_field_type'), $this->get_field_types()); - - } // end if; + } return $this->instantiated_field_types; - - } // end get_instantiated_field_types; + } /** * Returns a list of all the required fields that must be present on a CF. @@ -138,8 +133,7 @@ class Signup_Fields_Manager extends Base_Manager { $fields = array_filter($fields, fn($item) => $item->is_required()); return $fields; - - } // end get_required_fields; + } /** * Returns a list of all the user fields. @@ -154,8 +148,7 @@ class Signup_Fields_Manager extends Base_Manager { $fields = array_filter($fields, fn($item) => $item->is_user_field()); return $fields; - - } // end get_user_fields; + } /** * Returns a list of all the site fields. @@ -170,8 +163,7 @@ class Signup_Fields_Manager extends Base_Manager { $fields = array_filter($fields, fn($item) => $item->is_site_field()); return $fields; - - } // end get_site_fields; + } /** * Returns a list of all editor fields registered. @@ -186,13 +178,9 @@ class Signup_Fields_Manager extends Base_Manager { $field_types = $this->get_instantiated_field_types(); foreach ($field_types as $field_type) { - $all_editor_fields = array_merge($all_editor_fields, $field_class->get_fields()); - - } // end foreach; + } return $all_editor_fields; - - } // end get_all_editor_fields; - -} // end class Signup_Fields_Manager; + } +} diff --git a/inc/managers/class-site-manager.php b/inc/managers/class-site-manager.php index b18bcd9..0f61a7a 100644 --- a/inc/managers/class-site-manager.php +++ b/inc/managers/class-site-manager.php @@ -11,10 +11,10 @@ namespace WP_Ultimo\Managers; -use \WP_Ultimo\Managers\Base_Manager; -use \WP_Ultimo\Helpers\Screenshot; -use \WP_Ultimo\Database\Sites\Site_Type; -use \WP_Ultimo\Database\Memberships\Membership_Status; +use WP_Ultimo\Managers\Base_Manager; +use WP_Ultimo\Helpers\Screenshot; +use WP_Ultimo\Database\Sites\Site_Type; +use WP_Ultimo\Database\Memberships\Membership_Status; // Exit if accessed directly defined('ABSPATH') || exit; @@ -26,7 +26,9 @@ defined('ABSPATH') || exit; */ class Site_Manager extends Base_Manager { - use \WP_Ultimo\Apis\Rest_Api, \WP_Ultimo\Apis\WP_CLI, \WP_Ultimo\Traits\Singleton; + use \WP_Ultimo\Apis\Rest_Api; + use \WP_Ultimo\Apis\WP_CLI; + use \WP_Ultimo\Traits\Singleton; /** * The manager slug. @@ -97,8 +99,7 @@ class Site_Manager extends Base_Manager { add_filter('wpmu_validate_blog_signup', array($this, 'allow_hyphens_in_site_name'), 10, 1); add_action('wu_daily', array($this, 'delete_pending_sites')); - - } // end init; + } /** * Allows for hyphens to be used, since WordPress supports it. @@ -123,27 +124,20 @@ class Site_Manager extends Base_Manager { * if so, we remove it and re-validate with our custom rule * which is the same, but also allows for hyphens. */ - if (!empty($blogname_errors) && $error_key !== false) { - - unset($result['errors']->errors['blogname'][$error_key]); + if ( ! empty($blogname_errors) && $error_key !== false) { + unset($result['errors']->errors['blogname'][ $error_key ]); if (empty($result['errors']->errors['blogname'])) { - unset($result['errors']->errors['blogname']); - - } // end if; + } if (preg_match('/[^a-z0-9-]+/', (string) $result['blogname'])) { - $result['errors']->add('blogname', __('Site names can only contain lowercase letters (a-z), numbers, and hyphens.', 'wp-ultimo')); - - } // end if; - - } // end if; + } + } return $result; - - } // end allow_hyphens_in_site_name; + } /** * Handles the request to add a new site, if that's the case. @@ -158,8 +152,7 @@ class Site_Manager extends Base_Manager { global $wpdb; if (wu_request('create-new-site') && wp_verify_nonce(wu_request('create-new-site'), 'create-new-site')) { - - $errors = new \WP_Error; + $errors = new \WP_Error(); $rules = array( 'site_title' => 'min:4', @@ -167,73 +160,57 @@ class Site_Manager extends Base_Manager { ); if ($checkout->is_last_step()) { - $membership = WP_Ultimo()->currents->get_membership(); $customer = wu_get_current_customer(); - if (!$customer || !$membership || $customer->get_id() !== $membership->get_customer_id()) { - + if ( ! $customer || ! $membership || $customer->get_id() !== $membership->get_customer_id()) { $errors->add('not-owner', __('You do not have the necessary permissions to create a site to this membership', 'wp-ultimo')); - - } // end if; + } if ($errors->has_errors() === false) { - $d = wu_get_site_domain_and_path(wu_request('site_url', ''), $checkout->request_or_session('site_domain')); - $pending_site = $membership->create_pending_site(array( - 'domain' => $d->domain, - 'path' => $d->path, - 'template_id' => $checkout->request_or_session('template_id'), - 'title' => $checkout->request_or_session('site_title'), - 'customer_id' => $customer->get_id(), - 'membership_id' => $membership->get_id(), - )); + $pending_site = $membership->create_pending_site( + array( + 'domain' => $d->domain, + 'path' => $d->path, + 'template_id' => $checkout->request_or_session('template_id'), + 'title' => $checkout->request_or_session('site_title'), + 'customer_id' => $customer->get_id(), + 'membership_id' => $membership->get_id(), + ) + ); if (is_wp_error($pending_site)) { - wp_send_json_error($pending_site); exit; - - } // end if; + } $results = $membership->publish_pending_site(); if (is_wp_error($results)) { - wp_send_json_error($errors); - - } // end if; - + } } else { - wp_send_json_error($errors); - - } // end if; + } wp_send_json_success(array()); - } else { - $validation = $checkout->validate($rules); if (is_wp_error($validation)) { - wp_send_json_error($validation); - - } // end if; + } $wpdb->query('COMMIT'); wp_send_json_success(array()); - - } // end if; - - } // end if; - - } // end maybe_validate_add_new_site; + } + } + } /** * Checks if the current request is a add new site request. @@ -244,20 +221,20 @@ class Site_Manager extends Base_Manager { public function maybe_add_new_site() { if (wu_request('create-new-site') && wp_verify_nonce(wu_request('create-new-site'), 'create-new-site')) { - $redirect_url = wu_request('redirect_url', admin_url('admin.php?page=sites')); - $redirect_url = add_query_arg(array( - 'new_site_created' => true, - ), $redirect_url); + $redirect_url = add_query_arg( + array( + 'new_site_created' => true, + ), + $redirect_url + ); wp_redirect($redirect_url); exit; - - } // end if; - - } // end maybe_add_new_site; + } + } /** * Triggers the do_event of the site publish successful. @@ -277,8 +254,7 @@ class Site_Manager extends Base_Manager { ); wu_do_event('site_published', $payload); - - } // end handle_site_published; + } /** * Locks the site front-end if the site is not public. @@ -291,10 +267,8 @@ class Site_Manager extends Base_Manager { public function lock_site() { if (is_main_site() || is_admin() || wu_is_login_page() || wp_doing_ajax() || wu_request('wu-ajax')) { - return; - - } // end if; + } $can_access = true; @@ -302,11 +276,9 @@ class Site_Manager extends Base_Manager { $site = wu_get_current_site(); - if (!$site->is_active()) { - + if ( ! $site->is_active()) { $can_access = false; - - } // end if; + } $membership = $site->get_membership(); @@ -314,7 +286,7 @@ class Site_Manager extends Base_Manager { $is_cancelled = $status === Membership_Status::CANCELLED; - $is_inactive = $status && !$membership->is_active() && $status !== Membership_Status::TRIALING; + $is_inactive = $status && ! $membership->is_active() && $status !== Membership_Status::TRIALING; if ($is_cancelled || ($is_inactive && wu_get_setting('block_frontend', false))) { @@ -324,40 +296,36 @@ class Site_Manager extends Base_Manager { $expiration_time = wu_date($membership->get_date_expiration())->getTimestamp() + $grace_period * DAY_IN_SECONDS; if ($expiration_time < wu_date()->getTimestamp()) { - $checkout_pages = \WP_Ultimo\Checkout\Checkout_Pages::get_instance(); // We only show the url field when block_frontend is true $redirect_url = wu_get_setting('block_frontend', false) ? $checkout_pages->get_page_url('block_frontend') : false; $can_access = false; - - } // end if; - - } // end if; + } + } if ($can_access === false) { - if ($redirect_url) { - wp_redirect($redirect_url); exit; + } - } // end if; - - wp_die(new \WP_Error( - 'not-available', + wp_die( + new \WP_Error( + 'not-available', // phpcs:ignore sprintf( __('This site is not available at the moment.
    If you are the site admin, click here to login.', 'wp-ultimo'), wp_login_url()), - array( - 'title' => __('Site not available', 'wp-ultimo'), - ) - ), '', array('code' => 200)); - - } // end if; - - } // end lock_site; + array( + 'title' => __('Site not available', 'wp-ultimo'), + ) + ), + '', + array('code' => 200) + ); + } + } /** * Takes screenshots asynchronously. @@ -371,27 +339,22 @@ class Site_Manager extends Base_Manager { $site = wu_get_site($site_id); - if (!$site) { - + if ( ! $site) { return false; - - } // end if; + } $domain = $site->get_active_site_url(); $attachment_id = Screenshot::take_screenshot($domain); - if (!$attachment_id) { - + if ( ! $attachment_id) { return false; - - } // end if; + } $site->set_featured_image_id($attachment_id); return $site->save(); - - } // end async_get_site_screenshot; + } /** * Listens for the ajax endpoint and generate the screenshot. @@ -405,34 +368,31 @@ class Site_Manager extends Base_Manager { $site = wu_get_site($site_id); - if (!$site) { - + if ( ! $site) { wp_send_json_error( new \WP_Error('missing-site', __('Site not found.', 'wp-ultimo')) ); - - } // end if; + } $domain = $site->get_active_site_url(); $attachment_id = Screenshot::take_screenshot($domain); - if (!$attachment_id) { - + if ( ! $attachment_id) { wp_send_json_error( new \WP_Error('error', __('We were not able to fetch the screenshot.', 'wp-ultimo')) ); - - } // end if; + } $attachment_url = wp_get_attachment_image_src($attachment_id, 'wu-thumb-medium'); - wp_send_json_success(array( - 'attachment_id' => $attachment_id, - 'attachment_url' => $attachment_url[0], - )); - - } // end get_site_screenshot; + wp_send_json_success( + array( + 'attachment_id' => $attachment_id, + 'attachment_url' => $attachment_url[0], + ) + ); + } /** * Add the additional sizes required by WP Multisite WaaS. @@ -445,14 +405,12 @@ class Site_Manager extends Base_Manager { public function additional_thumbnail_sizes() { if (is_main_site()) { - add_image_size('wu-thumb-large', 900, 675, array('center', 'top')); // (cropped) add_image_size('wu-thumb-medium', 400, 300, array('center', 'top')); // (cropped) - } // end if; - - } // end additional_thumbnail_sizes; + } + } /** * Adds a notification if the no-index setting is active. @@ -463,12 +421,9 @@ class Site_Manager extends Base_Manager { public function add_no_index_warning() { if (wu_get_setting('stop_template_indexing', false)) { - add_meta_box('wu-warnings', __('WP Multisite WaaS - Search Engines', 'wp-ultimo'), array($this, 'render_no_index_warning'), 'dashboard-network', 'normal', 'high'); - - } // end if; - - } // end add_no_index_warning; + } + } /** * Renders the no indexing warning. @@ -491,8 +446,7 @@ class Site_Manager extends Base_Manager { get_type() === Site_Type::SITE_TEMPLATE) { - if (function_exists('wp_robots_no_robots')) { - add_filter('wp_robots', 'wp_robots_no_robots'); // WordPress 5.7+ } else { - wp_no_robots(); - - } // end if; - - } // end if; - - } // end prevent_site_template_indexing; + } + } + } /** * Check if sub-site has a custom logo and change login logo. @@ -535,23 +481,17 @@ class Site_Manager extends Base_Manager { */ public function custom_login_logo() { - if (!wu_get_setting('subsite_custom_login_logo', false) || !has_custom_logo()) { - + if ( ! wu_get_setting('subsite_custom_login_logo', false) || ! has_custom_logo()) { $logo = wu_get_network_logo(); - } else { - $logo = wp_get_attachment_image_src(get_theme_mod('custom_logo'), 'full'); $logo = wu_get_isset($logo, 0, false); - - } // end if; + } if (empty($logo)) { - return; - - } // end if; + } // phpcs:disable @@ -568,8 +508,7 @@ class Site_Manager extends Base_Manager { If you want to avoid confusion, you can also hide this page from the admin panel completely on the WP Multisite WaaS → Settings → Whitelabel options.', 'wp-ultimo'); - WP_Ultimo()->notices->add($notice, 'info', 'network-admin', 'wu-sites-use-wp-ultimo', array( + WP_Ultimo()->notices->add( + $notice, + 'info', + 'network-admin', + 'wu-sites-use-wp-ultimo', array( - 'title' => __('Go to the WP Multisite WaaS Sites page →', 'wp-ultimo'), - 'url' => wu_network_admin_url('wp-ultimo-sites'), - ), - array( - 'title' => __('Go to the Whitelabel Settings →', 'wp-ultimo'), - 'url' => wu_network_admin_url('wp-ultimo-settings', array( - 'tab' => 'whitelabel', - )), - ), - )); - - } // end add_notices_to_default_site_page; + array( + 'title' => __('Go to the WP Multisite WaaS Sites page →', 'wp-ultimo'), + 'url' => wu_network_admin_url('wp-ultimo-sites'), + ), + array( + 'title' => __('Go to the Whitelabel Settings →', 'wp-ultimo'), + 'url' => wu_network_admin_url( + 'wp-ultimo-settings', + array( + 'tab' => 'whitelabel', + ) + ), + ), + ) + ); + } /** * Add search and replace filter to be used on site duplication. @@ -638,8 +583,7 @@ class Site_Manager extends Base_Manager { $final_list = array_merge($search_and_replace, $additional_duplication); return $this->filter_illegal_search_keys($final_list); - - } // end search_and_replace_on_duplication; + } /** * Get search and replace settings @@ -654,18 +598,13 @@ class Site_Manager extends Base_Manager { $pairs = array(); foreach ($search_and_replace as $item) { - - if ((isset($item['search']) && !empty($item['search'])) && isset($item['replace'])) { - - $pairs[$item['search']] = $item['replace']; - - } // end if; - - } // end foreach; + if ((isset($item['search']) && ! empty($item['search'])) && isset($item['replace'])) { + $pairs[ $item['search'] ] = $item['replace']; + } + } return $pairs; - - } // end get_search_and_replace_settings; + } /** * Handles search and replace for new blogs from WordPress. @@ -679,11 +618,9 @@ class Site_Manager extends Base_Manager { $to_site_id = $site->get_id(); - if (!$to_site_id) { - + if ( ! $to_site_id) { return; - - } // end if; + } /** * In order to be backwards compatible here, we'll have to do some crazy stuff, @@ -706,46 +643,33 @@ class Site_Manager extends Base_Manager { $results = \MUCD_Data::do_sql_query('SHOW TABLES LIKE \'' . $to_blog_prefix_like . '%\'', 'col', false); foreach ($results as $k => $v) { - - $tables[str_replace($to_blog_prefix, '', (string) $v)] = array(); - - } // end foreach; + $tables[ str_replace($to_blog_prefix, '', (string) $v) ] = array(); + } foreach ( $tables as $table => $col) { - $results = \MUCD_Data::do_sql_query('SHOW COLUMNS FROM `' . $to_blog_prefix . $table . '`', 'col', false); $columns = array(); foreach ($results as $k => $v) { - $columns[] = $v; + } - } // end foreach; - - $tables[$table] = $columns; - - } // end foreach; + $tables[ $table ] = $columns; + } $default_tables = \MUCD_Option::get_fields_to_update(); foreach ($default_tables as $table => $field) { - - $tables[$table] = $field; - - } // end foreach; + $tables[ $table ] = $field; + } foreach ($tables as $table => $field) { - foreach ($string_to_replace as $from_string => $to_string) { - \MUCD_Data::update($to_blog_prefix . $table, $field, $from_string, $to_string); - - } // end foreach; - - } // end foreach; - - } // end search_and_replace_for_new_site; + } + } + } /** * Makes sure the search and replace array have no illegal values, such as null, false, etc * @@ -754,9 +678,8 @@ class Site_Manager extends Base_Manager { */ public function filter_illegal_search_keys($search_and_replace): array { - return array_filter($search_and_replace, fn($k) => !is_null($k) && $k !== false && !empty($k), ARRAY_FILTER_USE_KEY); - - } // end filter_illegal_search_keys; + return array_filter($search_and_replace, fn($k) => ! is_null($k) && $k !== false && ! empty($k), ARRAY_FILTER_USE_KEY); + } /** * Handle the deletion of pending sites. @@ -771,7 +694,6 @@ class Site_Manager extends Base_Manager { public function handle_delete_pending_sites($action, $model, $ids) { foreach ($ids as $membership_id) { - $membership = wu_get_membership($membership_id); if (empty($membership)) { @@ -782,18 +704,17 @@ class Site_Manager extends Base_Manager { delete_metadata('wu_membership', $membership_id, 'pending_site'); continue; - - } // end if; + } $membership->delete_pending_site(); + } - } // end foreach; - - wp_send_json_success(array( - 'redirect_url' => add_query_arg('deleted', count($ids), wu_get_current_url()), - )); - - } // end handle_delete_pending_sites; + wp_send_json_success( + array( + 'redirect_url' => add_query_arg('deleted', count($ids), wu_get_current_url()), + ) + ); + } /** * Hide the super admin user from the sub-site table list. @@ -805,15 +726,12 @@ class Site_Manager extends Base_Manager { */ public function hide_super_admin_from_list($args) { - if (!is_super_admin()) { - + if ( ! is_super_admin()) { $args['login__not_in'] = get_super_admins(); - - } // end if; + } return $args; - - } // end hide_super_admin_from_list; + } /** * Hides customer sites from the super admin user on listing. @@ -829,60 +747,46 @@ class Site_Manager extends Base_Manager { global $wpdb; - if (!is_super_admin()) { - + if ( ! is_super_admin()) { return $sites; - - } // end if; + } $keys = get_user_meta($user_id); if (empty($keys)) { - return $sites; - - } // end if; + } // List the main site at beginning of array. - if (isset($keys[$wpdb->base_prefix . 'capabilities']) && defined('MULTISITE')) { - + if (isset($keys[ $wpdb->base_prefix . 'capabilities' ]) && defined('MULTISITE')) { $site_ids[] = 1; - unset($keys[$wpdb->base_prefix . 'capabilities']); - - } // end if; + unset($keys[ $wpdb->base_prefix . 'capabilities' ]); + } $keys = array_keys($keys); foreach ($keys as $key) { - if (substr_compare($key, 'capabilities', -strlen('capabilities')) !== 0) { - continue; - - } // end if; + } if ($wpdb->base_prefix && strncmp($key, (string) $wpdb->base_prefix, strlen((string) $wpdb->base_prefix)) !== 0) { - continue; - - } // end if; + } $site_id = str_replace(array($wpdb->base_prefix, '_capabilities'), '', $key); - if (!is_numeric($site_id)) { - + if ( ! is_numeric($site_id)) { continue; - - } // end if; + } $site_ids[] = (int) $site_id; - - } // end foreach; + } $sites = array(); - if (!empty($site_ids)) { + if ( ! empty($site_ids)) { /** * Here we change the default WP behavior to filter @@ -908,13 +812,11 @@ class Site_Manager extends Base_Manager { ), ); - if (!$all) { - + if ( ! $all) { $args['archived'] = 0; $args['spam'] = 0; $args['deleted'] = 0; - - } // end if; + } $_sites = array_merge( array( @@ -924,14 +826,11 @@ class Site_Manager extends Base_Manager { ); foreach ($_sites as $site) { - - if (!$site) { - + if ( ! $site) { continue; + } - } // end if; - - $sites[$site->id] = (object) array( + $sites[ $site->id ] = (object) array( 'userblog_id' => $site->id, 'blogname' => $site->blogname, 'domain' => $site->domain, @@ -943,10 +842,8 @@ class Site_Manager extends Base_Manager { 'spam' => $site->spam, 'deleted' => $site->deleted, ); - - } // end foreach; - - } // end if; + } + } /** * Replicates the original WP Filter here, for good measure. @@ -961,8 +858,7 @@ class Site_Manager extends Base_Manager { * those marked 'deleted', 'archived', or 'spam'. Default false. */ return apply_filters('get_blogs_of_user', $sites, $user_id, $all); // phpcs:ignore - - } // end hide_customer_sites_from_super_admin_list; + } /** * Delete pending sites from non-pending memberships @@ -974,12 +870,9 @@ class Site_Manager extends Base_Manager { $pending_sites = \WP_Ultimo\Models\Site::get_all_by_type('pending'); foreach ($pending_sites as $site) { - if ($site->is_publishing()) { - continue; - - } // end if; + } $membership = $site->get_membership(); @@ -987,15 +880,9 @@ class Site_Manager extends Base_Manager { // Check if the last modify has more than some time, to avoid the deletion of sites on creation process if ($membership->get_date_modified() < gmdate('Y-m-d H:i:s', strtotime('-1 days'))) { - $membership->delete_pending_site(); - - } // end if; - - } // end if; - - } // end foreach; - - } // end delete_pending_sites; - -} // end class Site_Manager; + } + } + } + } +} diff --git a/inc/managers/class-visits-manager.php b/inc/managers/class-visits-manager.php index 662abce..a4a7013 100644 --- a/inc/managers/class-visits-manager.php +++ b/inc/managers/class-visits-manager.php @@ -32,10 +32,9 @@ class Visits_Manager { public function init() { if ((bool) wu_get_setting('enable_visits_limiting', true) === false || is_main_site()) { - return; // Feature not active, bail. - } // end if; + } /* * Due to how caching plugins work, we need to count visits via ajax. @@ -46,8 +45,7 @@ class Visits_Manager { add_action('wp_enqueue_scripts', array($this, 'enqueue_visit_counter_script')); add_action('template_redirect', array($this, 'maybe_lock_site')); - - } // end init; + } /** * Check if the limits for visits was set. If that's the case, lock the site. @@ -59,28 +57,21 @@ class Visits_Manager { $site = wu_get_current_site(); - if (!$site) { - + if ( ! $site) { return; - - } // end if; + } /* * Case unlimited visits */ if (empty($site->get_limitations()->visits->get_limit())) { - return; - - } // end if; + } if ($site->has_limitations() && $site->get_visits_count() > $site->get_limitations()->visits->get_limit()) { - wp_die(__('This site is not available at this time.', 'wp-ultimo'), __('Not available', 'wp-ultimo'), 404); - - } // end if; - - } // end maybe_lock_site; + } + } /** * Counts visits to network sites. @@ -98,18 +89,15 @@ class Visits_Manager { public function count_visits() { if (is_main_site() && is_admin()) { - return; // bail on main site. - } // end if; + } $site = wu_get_current_site(); if ($site->get_type() !== 'customer_owned') { - return; - - } // end if; + } $visits_manager = new \WP_Ultimo\Objects\Visits($site->get_id()); @@ -122,18 +110,15 @@ class Visits_Manager { * Checks against the limitations. */ if (false) { - Cache_Manager::get_instance()->flush_known_caches(); echo 'flushing caches'; die('2'); - - } // end if; + } die('1'); - - } // end count_visits; + } /** * Enqueues the visits count script when necessary. @@ -144,20 +129,21 @@ class Visits_Manager { public function enqueue_visit_counter_script() { if (is_user_logged_in()) { - return; // bail if user is logged in. - } // end if; + } wp_register_script('wu-visits-counter', wu_get_asset('visits-counter.js', 'js'), array(), wu_get_version()); - wp_localize_script('wu-visits-counter', 'wu_visits_counter', array( - 'ajaxurl' => admin_url('admin-ajax.php'), - 'code' => wp_create_nonce('wu-visit-counter'), - )); + wp_localize_script( + 'wu-visits-counter', + 'wu_visits_counter', + array( + 'ajaxurl' => admin_url('admin-ajax.php'), + 'code' => wp_create_nonce('wu-visit-counter'), + ) + ); wp_enqueue_script('wu-visits-counter'); - - } // end enqueue_visit_counter_script; - -} // end class Visits_Manager; + } +} diff --git a/inc/managers/class-webhook-manager.php b/inc/managers/class-webhook-manager.php index 5fb89af..002d254 100644 --- a/inc/managers/class-webhook-manager.php +++ b/inc/managers/class-webhook-manager.php @@ -25,7 +25,9 @@ defined('ABSPATH') || exit; */ class Webhook_Manager extends Base_Manager { - use \WP_Ultimo\Apis\Rest_Api, \WP_Ultimo\Apis\WP_CLI, \WP_Ultimo\Traits\Singleton; + use \WP_Ultimo\Apis\Rest_Api; + use \WP_Ultimo\Apis\WP_CLI; + use \WP_Ultimo\Traits\Singleton; /** * The manager slug. @@ -74,8 +76,7 @@ class Webhook_Manager extends Base_Manager { add_action('init', array($this, 'register_webhook_listeners')); add_action('wp_ajax_wu_send_test_event', array($this, 'send_test_event')); - - } // end init; + } /** * Adds the listeners to the webhook callers, extend this by adding actions to wu_register_webhook_listeners @@ -86,12 +87,9 @@ class Webhook_Manager extends Base_Manager { public function register_webhook_listeners() { foreach (wu_get_event_types() as $key => $event) { - add_action('wu_event_' . $key, array($this, 'send_webhooks')); - - } // end foreach; - - } // end register_webhook_listeners; + } + } /** * Sends all the webhooks that are triggered by a specific event. @@ -106,18 +104,13 @@ class Webhook_Manager extends Base_Manager { $webhooks = Webhook::get_all(); foreach ($webhooks as $webhook) { - if ('wu_event_' . $webhook->get_event() === current_filter()) { - $blocking = wu_get_setting('webhook_calls_blocking', false); $this->send_webhook($webhook, $args, $blocking); - - } // end if; - - } // end foreach; - - } // end send_webhooks; + } + } + } /** * Sends a specific webhook. @@ -132,30 +125,31 @@ class Webhook_Manager extends Base_Manager { */ public function send_webhook($webhook, $data, $blocking = true, $count = true) { - if (!$data) { - + if ( ! $data) { return; + } - } // end if; - - $request = wp_remote_post($webhook->get_webhook_url(), array( - 'method' => 'POST', - 'timeout' => 45, - 'redirection' => 5, - 'headers' => array( - 'Content-Type' => 'application/json', + $request = wp_remote_post( + $webhook->get_webhook_url(), + array( + 'method' => 'POST', + 'timeout' => 45, + 'redirection' => 5, + 'headers' => array( + 'Content-Type' => 'application/json', + ), + 'cookies' => array(), + 'body' => wp_json_encode($data), + 'blocking' => $blocking, ), - 'cookies' => array(), - 'body' => wp_json_encode($data), - 'blocking' => $blocking, - ), current_filter(), $webhook); + current_filter(), + $webhook + ); if (is_wp_error($request)) { - $error_message = $request->get_error_message(); if ($count) { - $this->create_event( $webhook->get_event(), $webhook->get_id(), @@ -164,24 +158,19 @@ class Webhook_Manager extends Base_Manager { $error_message, true ); - - } // end if; + } return $error_message; - - } // end if; + } $response = ''; // if blocking, we have a response if ($blocking) { - $response = wp_remote_retrieve_body($request); - - } // end if; + } if ($count) { - $this->create_event( $webhook->get_event(), $webhook->get_id(), @@ -194,12 +183,10 @@ class Webhook_Manager extends Base_Manager { $webhook->set_event_count($new_count); $webhook->save(); - - } // end if; + } return $response; - - } // end send_webhook; + } /** * Send a test event of the webhook @@ -208,14 +195,14 @@ class Webhook_Manager extends Base_Manager { */ public function send_test_event() { - if (!current_user_can('manage_network')) { - - wp_send_json(array( - 'response' => __('You do not have enough permissions to send a test event.', 'wp-ultimo'), - 'webhooks' => Webhook::get_items_as_array(), - )); - - } // end if; + if ( ! current_user_can('manage_network')) { + wp_send_json( + array( + 'response' => __('You do not have enough permissions to send a test event.', 'wp-ultimo'), + 'webhooks' => Webhook::get_items_as_array(), + ) + ); + } $event = wu_get_event_type($_POST['webhook_event']); @@ -229,12 +216,13 @@ class Webhook_Manager extends Base_Manager { $response = $this->send_webhook($webhook, wu_maybe_lazy_load_payload($event['payload']), true, false); - wp_send_json(array( - 'response' => htmlentities2($response), - 'id' => wu_request('webhook_id') - )); - - } // end send_test_event; + wp_send_json( + array( + 'response' => htmlentities2($response), + 'id' => wu_request('webhook_id'), + ) + ); + } /** * Reads the log file and displays the content. @@ -262,34 +250,33 @@ class Webhook_Manager extends Base_Manager { '; - if (!current_user_can('manage_network')) { - + if ( ! current_user_can('manage_network')) { echo __('You do not have enough permissions to read the logs of this webhook.', 'wp-ultimo'); exit; - - } // end if; + } $id = absint($_REQUEST['id']); - $logs = array_map(function($line): string { + $logs = array_map( + function ($line): string { - $line = str_replace(' - ', ' - ', $line); + $line = str_replace(' - ', ' - ', $line); - $matches = array(); + $matches = array(); - $line = str_replace('\'', '\\\'', $line); - $line = preg_replace('~(\{(?:[^{}]|(?R))*\})~', '
    ', $line); + $line = str_replace('\'', '\\\'', $line); + $line = preg_replace('~(\{(?:[^{}]|(?R))*\})~', '
    ', $line); - return '' . $line . '
    '; - - }, Logger::read_lines("webhook-$id", 5)); + return '' . $line . '
    '; + }, + Logger::read_lines("webhook-$id", 5) + ); echo implode('', $logs); exit; - - } // end serve_logs; + } /** * Log a webhook sent for later reference. @@ -308,15 +295,11 @@ class Webhook_Manager extends Base_Manager { $message = sprintf('Sent a %s event to the URL %s with data: %s ', $event_name, $url, json_encode($data)); - if (!$is_error) { - + if ( ! $is_error) { $message .= empty($response) ? sprintf('Got response: %s', $response) : 'To debug the remote server response, turn the "Wait for Response" option on the WP Multisite WaaS Settings > API & Webhooks Tab'; - } else { - $message .= sprintf('Got error: %s', $response); - - } // end if; + } $event_data = array( 'object_id' => $id, @@ -328,7 +311,5 @@ class Webhook_Manager extends Base_Manager { ); wu_create_event($event_data); - - } // end create_event; - -} // end class Webhook_Manager; + } +} diff --git a/inc/models/class-base-model.php b/inc/models/class-base-model.php index c0b0f51..b01b96f 100644 --- a/inc/models/class-base-model.php +++ b/inc/models/class-base-model.php @@ -9,7 +9,7 @@ namespace WP_Ultimo\Models; -use \WP_Ultimo\Helpers\Hash; +use WP_Ultimo\Helpers\Hash; // Exit if accessed directly defined('ABSPATH') || exit; @@ -25,11 +25,11 @@ defined('ABSPATH') || exit; abstract class Base_Model implements \JsonSerializable { /** - * ID of the object - * - * @since 2.0.0 - * @var integer - */ + * ID of the object + * + * @since 2.0.0 + * @var integer + */ protected $id = 0; /** @@ -140,20 +140,15 @@ abstract class Base_Model implements \JsonSerializable { $this->model = sanitize_key((new \ReflectionClass($this))->getShortName()); if (is_array($object)) { - $object = (object) $object; + } - } // end if; - - if (!is_object($object)) { - + if ( ! is_object($object)) { return; - - } // end if; + } $this->setup_model($object); - - } // end __construct; + } /** * Get the value of slug @@ -163,8 +158,7 @@ abstract class Base_Model implements \JsonSerializable { public function get_slug() { return $this->slug; - - } // end get_slug; + } /** * Set the value of slug @@ -174,8 +168,7 @@ abstract class Base_Model implements \JsonSerializable { public function set_slug($slug) { $this->slug = $slug; - - } // end set_slug; + } /** * Returns a hashed version of the id. Useful for displaying data publicly. @@ -188,17 +181,14 @@ abstract class Base_Model implements \JsonSerializable { $value = call_user_func(array($this, "get_{$field}")); - if (!is_numeric($value)) { - + if ( ! is_numeric($value)) { _doing_it_wrong(__METHOD__, __('You can only use numeric fields to generate hashes.', 'wp-ultimo'), '2.0.0'); return false; - - } // end if; + } return Hash::encode($value, $this->model); - - } // end get_hash; + } /** * Setup properties. @@ -211,25 +201,20 @@ abstract class Base_Model implements \JsonSerializable { */ private function setup_model($object) { - if (!is_object($object)) { - + if ( ! is_object($object)) { return false; - - } // end if; + } $vars = get_object_vars($object); $this->attributes($vars); if (empty($this->id)) { - return false; - - } // end if; + } return true; - - } // end setup_model; + } /** * Sets the attributes of the model using the setters available. @@ -242,45 +227,34 @@ abstract class Base_Model implements \JsonSerializable { public function attributes($atts) { foreach ($atts as $key => $value) { - if ($key === 'meta' && is_array($value)) { - $this->meta = is_array($this->meta) ? array_merge($this->meta, $value) : $value; - - } // end if; + } if (method_exists($this, "set_$key")) { - call_user_func(array($this, "set_$key"), $value); - - } // end if; + } $mapping = wu_get_isset($this->_mappings, $key); if ($mapping && method_exists($this, "set_$mapping")) { - call_user_func(array($this, "set_$mapping"), $value); - - } // end if; - - } // end foreach; + } + } /* * Keeps the original. */ if ($this->_original === null) { - $original = get_object_vars($this); unset($original['_original']); $this->_original = $original; - - } // end if; + } return $this; - - } // end attributes; + } /** * Return the model schema. useful to list all models fields. @@ -306,8 +280,7 @@ abstract class Base_Model implements \JsonSerializable { fn($column) => $column->to_array(), $columns ); - - } // end get_schema; + } /** * Checks if this model was already saved to the database. @@ -317,9 +290,8 @@ abstract class Base_Model implements \JsonSerializable { */ public function exists() { - return !empty($this->id); - - } // end exists; + return ! empty($this->id); + } /** * Gets a single database row by the primary column ID, possibly from cache. @@ -333,18 +305,15 @@ abstract class Base_Model implements \JsonSerializable { public static function get_by_id($item_id) { if (empty($item_id)) { - return false; - - } // end if; + } $instance = new static(); $query_class = new $instance->query_class(); return $query_class->get_item($item_id); - - } // end get_by_id; + } /** * Gets a single database row by the hash, possibly from cache. @@ -364,8 +333,7 @@ abstract class Base_Model implements \JsonSerializable { $query_class = new $instance->query_class(); return $query_class->get_item($item_id); - - } // end get_by_hash; + } /** * Gets a model instance by a column value. @@ -383,8 +351,7 @@ abstract class Base_Model implements \JsonSerializable { $query_class = new $instance->query_class(); return $query_class->get_item_by($column, $value); - - } // end get_by; + } /** * Wrapper for a Query call. @@ -399,8 +366,7 @@ abstract class Base_Model implements \JsonSerializable { $instance = new static(); return (new $instance->query_class($query))->query(); - - } // end get_items; + } /** * Wrapper for a Query call, but returns the list as arrays. @@ -417,8 +383,7 @@ abstract class Base_Model implements \JsonSerializable { $list = (new $instance->query_class($query))->query(); return array_map(fn($item) => $item->to_array(), $list); - - } // end get_items_as_array; + } /** * Get the ID of the model. @@ -430,8 +395,7 @@ abstract class Base_Model implements \JsonSerializable { public function get_id() { return absint($this->id); - - } // end get_id; + } /** * Check if this model has a job running. @@ -441,16 +405,17 @@ abstract class Base_Model implements \JsonSerializable { */ public function has_running_jobs() { - $jobs = wu_get_scheduled_actions(array( - 'status' => \ActionScheduler_Store::STATUS_RUNNING, - 'args' => array( - "{$this->model}_id" => $this->get_id(), - ), - )); + $jobs = wu_get_scheduled_actions( + array( + 'status' => \ActionScheduler_Store::STATUS_RUNNING, + 'args' => array( + "{$this->model}_id" => $this->get_id(), + ), + ) + ); return $jobs; - - } // end has_running_jobs; + } /** * Set iD of the object. @@ -462,8 +427,7 @@ abstract class Base_Model implements \JsonSerializable { private function set_id($id) { $this->id = $id; - - } // end set_id; + } /** * Set the validation rules for this particular model. @@ -478,8 +442,7 @@ abstract class Base_Model implements \JsonSerializable { public function validation_rules() { return array(); - - } // end validation_rules; + } /** * Validates the rules and make sure we only save models when necessary. @@ -490,30 +453,23 @@ abstract class Base_Model implements \JsonSerializable { public function validate() { if ($this->skip_validation) { - return true; + } - } // end if; - - $validator = new \WP_Ultimo\Helpers\Validator; + $validator = new \WP_Ultimo\Helpers\Validator(); $validator->validate($this->to_array(), $this->validation_rules()); if ($validator->fails()) { - return $validator->get_errors(); - - } // end if; + } foreach ($validator->get_validation()->getValidData() as $key => $value) { - $this->{$key} = $value; - - } // end foreach; + } return true; - - } // end validate; + } /** * Save (create or update) the model on the database. @@ -529,10 +485,8 @@ abstract class Base_Model implements \JsonSerializable { $data = get_object_vars($this); if (isset($data['id']) && empty($data['id'])) { - unset($data['id']); - - } // end if; + } unset($data['_original']); @@ -540,7 +494,7 @@ abstract class Base_Model implements \JsonSerializable { $meta = wu_get_isset($data, 'meta', array()); - $new = !$this->exists(); + $new = ! $this->exists(); /** * Filters the data meta before it is serialized to be stored into the database. @@ -559,26 +513,24 @@ abstract class Base_Model implements \JsonSerializable { ); foreach ($blocked_attributes as $attribute) { - - unset($data[$attribute]); - - } // end foreach; + unset($data[ $attribute ]); + } $this->validate(); $data = array_map('maybe_serialize', $data); - $data = array_map(function($_data) { + $data = array_map( + function ($_data) { - if (is_serialized($_data)) { + if (is_serialized($_data)) { + $_data = addslashes($_data); + } - $_data = addslashes($_data); - - } // end if; - - return $_data; - - }, $data); + return $_data; + }, + $data + ); /** * Filters the object data before it is stored into the database. @@ -593,39 +545,29 @@ abstract class Base_Model implements \JsonSerializable { $is_valid_data = $this->validate(); - if (is_wp_error($is_valid_data) && !$this->skip_validation) { - + if (is_wp_error($is_valid_data) && ! $this->skip_validation) { return $is_valid_data; - - } // end if; + } $saved = false; - if (!$this->get_id()) { - + if ( ! $this->get_id()) { $new_id = $query_class->add_item($data); if ($new_id) { - $this->id = $new_id; $saved = true; - - } // end if; - + } } else { - $saved = $query_class->update_item($this->get_id(), $data); + } - } // end if; - - if (!empty($meta)) { - + if ( ! empty($meta)) { $this->update_meta_batch($meta); $saved = true; - - } // end if; + } /** * Delete object cache to prevent errors. @@ -658,8 +600,7 @@ abstract class Base_Model implements \JsonSerializable { do_action("wu_{$this->model}_post_save", $data, $this, $new); return $saved; - - } // end save; + } /** * Delete the model from the database. @@ -670,11 +611,9 @@ abstract class Base_Model implements \JsonSerializable { */ public function delete() { - if (!$this->get_id()) { - + if ( ! $this->get_id()) { return new \WP_Error("wu_{$this->model}_delete_unsaved_item", __('Item not found.', 'wp-ultimo')); - - } // end if; + } /** * Fires after an object is stored into the database. @@ -700,8 +639,7 @@ abstract class Base_Model implements \JsonSerializable { do_action("wu_{$this->model}_post_delete", $result, $this); return $result; - - } // end delete; + } /** * Returns the meta type name. @@ -715,14 +653,13 @@ abstract class Base_Model implements \JsonSerializable { $query_class = new $this->query_class(); // Maybe apply table prefix - $table = !empty($query_class->prefix) + $table = ! empty($query_class->prefix) ? "{$query_class->prefix}_{$query_class->item_name}" : $query_class->item_name; // Return table if exists, or false if not return $table; - - } // end get_meta_type_name; + } /** * Returns the meta table name. @@ -736,8 +673,7 @@ abstract class Base_Model implements \JsonSerializable { $table = $this->get_meta_type_name(); return _get_meta_table($table); - - } // end get_meta_table_name; + } /** * Checks if metadata handling is available, i.e., if there is a meta table @@ -748,25 +684,22 @@ abstract class Base_Model implements \JsonSerializable { */ protected function is_meta_available() { - if (!$this->get_meta_table_name()) { + if ( ! $this->get_meta_table_name()) { // _doing_it_wrong(__METHOD__, __('This model does not support metadata.', 'wp-ultimo'), '2.0.0'); return false; + } - } // end if; - - if (!$this->get_id() && !$this->_mocked) { + if ( ! $this->get_id() && ! $this->_mocked) { // _doing_it_wrong(__METHOD__, __('Model metadata only works for already saved models.', 'wp-ultimo'), '2.0.0'); return false; - - } // end if; + } return true; - - } // end is_meta_available; + } /** * Returns the meta data, if set. Otherwise, returns the default. @@ -780,23 +713,18 @@ abstract class Base_Model implements \JsonSerializable { */ public function get_meta($key, $default = false, $single = true) { - if (!$this->is_meta_available()) { - + if ( ! $this->is_meta_available()) { return $default; - - } // end if; + } $meta_type = $this->get_meta_type_name(); if (metadata_exists($meta_type, $this->get_id(), $key)) { - return get_metadata($meta_type, $this->get_id(), $key, $single); - - } // end if; + } return $default; - - } // end get_meta; + } /** * Adds or updates meta data in batch. @@ -808,33 +736,26 @@ abstract class Base_Model implements \JsonSerializable { */ public function update_meta_batch($meta) { - if (!$this->is_meta_available()) { - + if ( ! $this->is_meta_available()) { return false; + } - } // end if; - - if (!is_array($meta)) { - + if ( ! is_array($meta)) { _doing_it_wrong(__METHOD__, __('This method expects an array as argument.', 'wp-ultimo'), '2.0.0'); return false; - - } // end if; + } $meta_type = $this->get_meta_type_name(); $success = true; foreach ($meta as $key => $value) { - update_metadata($meta_type, $this->get_id(), $key, $value); - - } // end foreach; + } return $success; - - } // end update_meta_batch; + } /** * Adds or updates the meta data. @@ -848,17 +769,14 @@ abstract class Base_Model implements \JsonSerializable { */ public function update_meta($key, $value) { - if (!$this->is_meta_available()) { - + if ( ! $this->is_meta_available()) { return false; - - } // end if; + } $meta_type = $this->get_meta_type_name(); return update_metadata($meta_type, $this->get_id(), $key, $value); - - } // end update_meta; + } /** * Deletes the meta data. @@ -870,17 +788,14 @@ abstract class Base_Model implements \JsonSerializable { */ public function delete_meta($key) { - if (!$this->is_meta_available()) { - + if ( ! $this->is_meta_available()) { return false; - - } // end if; + } $meta_type = $this->get_meta_type_name(); return delete_metadata($meta_type, $this->get_id(), $key); - - } // end delete_meta; + } /** * Queries object in the database. @@ -899,8 +814,7 @@ abstract class Base_Model implements \JsonSerializable { $items = $query_class->query($args); return $items; - - } // end query; + } /** * Transform the object into an assoc array. @@ -921,18 +835,13 @@ abstract class Base_Model implements \JsonSerializable { unset($array['_mocked']); foreach ($array as $key => $value) { - if (strncmp('_', $key, strlen($key)) === 0) { - - unset($array[$key]); - - } // end if; - - } // end foreach; + unset($array[ $key ]); + } + } return $array; - - } // end to_array; + } /** * Convert data to Mapping instance @@ -945,8 +854,7 @@ abstract class Base_Model implements \JsonSerializable { protected static function to_instance($data) { return new static($data); - - } // end to_instance; + } /** * Convert list of data to Mapping instances @@ -957,8 +865,7 @@ abstract class Base_Model implements \JsonSerializable { protected static function to_instances($data) { return array_map(array(get_called_class(), 'to_instance'), $data); - - } // end to_instances; + } /** * By default, we just use the to_array method, but you can rewrite this. @@ -969,8 +876,7 @@ abstract class Base_Model implements \JsonSerializable { public function to_search_results() { return $this->to_array(); - - } // end to_search_results; + } /** * Defines how we should encode this. @@ -982,14 +888,11 @@ abstract class Base_Model implements \JsonSerializable { public function jsonSerialize() { if (wp_doing_ajax() && wu_request('action') === 'wu_search') { - return $this->to_search_results(); - - } // end if; + } return $this->to_array(); - - } // end jsonSerialize; + } /** * Get the date when this model was created. @@ -999,15 +902,12 @@ abstract class Base_Model implements \JsonSerializable { */ public function get_date_created() { - if (!wu_validate_date($this->date_created)) { - + if ( ! wu_validate_date($this->date_created)) { return wu_get_current_time('mysql'); - - } // end if; + } return $this->date_created; - - } // end get_date_created; + } /** * Get the date when this model was last modified. @@ -1017,15 +917,12 @@ abstract class Base_Model implements \JsonSerializable { */ public function get_date_modified() { - if (!wu_validate_date($this->date_modified)) { - + if ( ! wu_validate_date($this->date_modified)) { return wu_get_current_time('mysql'); - - } // end if; + } return $this->date_modified; - - } // end get_date_modified; + } /** * Set model creation date. @@ -1037,8 +934,7 @@ abstract class Base_Model implements \JsonSerializable { public function set_date_created($date_created) { $this->date_created = $date_created; - - } // end set_date_created; + } /** * Set model last modification date. @@ -1050,8 +946,7 @@ abstract class Base_Model implements \JsonSerializable { public function set_date_modified($date_modified) { $this->date_modified = $date_modified; - - } // end set_date_modified; + } /** * Get the id of the original 1.X model that was used to generate this item on migration. @@ -1062,8 +957,7 @@ abstract class Base_Model implements \JsonSerializable { public function get_migrated_from_id() { return $this->migrated_from_id; - - } // end get_migrated_from_id; + } /** * Set the id of the original 1.X model that was used to generate this item on migration. @@ -1075,8 +969,7 @@ abstract class Base_Model implements \JsonSerializable { public function set_migrated_from_id($migrated_from_id) { $this->migrated_from_id = absint($migrated_from_id); - - } // end set_migrated_from_id; + } /** * Checks if this model is a migration from 1.X. @@ -1086,9 +979,8 @@ abstract class Base_Model implements \JsonSerializable { */ public function is_migrated() { - return !empty($this->get_migrated_from_id()); - - } // end is_migrated; + return ! empty($this->get_migrated_from_id()); + } /** * Helper method to return formatted values. @@ -1106,14 +998,11 @@ abstract class Base_Model implements \JsonSerializable { $value = (float) $this->{"get_{$key}"}(); if (is_numeric($value)) { - return wu_format_currency($value); - - } // end if; + } return $value; - - } // end get_formatted_amount; + } /** * Helper method to return formatted dates. @@ -1131,14 +1020,11 @@ abstract class Base_Model implements \JsonSerializable { $value = $this->{"get_{$key}"}(); if (wu_validate_date($value)) { - return date_i18n(get_option('date_format'), wu_date($value)->format('U')); - - } // end if; + } return $value; - - } // end get_formatted_date; + } /** * Get all items. @@ -1157,8 +1043,7 @@ abstract class Base_Model implements \JsonSerializable { $items = $query_class->query($query_args); return $items; - - } // end get_all; + } /** * Creates a copy of the given model adn resets it's id to a 'new' state. @@ -1175,14 +1060,11 @@ abstract class Base_Model implements \JsonSerializable { $clone->set_id(0); if (method_exists($clone, 'set_date_created')) { - $clone->set_date_created(wu_get_current_time('mysql')); - - } // end if; + } return $clone; - - } // end duplicate; + } /** * Populate the data the resides on meta tables. @@ -1198,7 +1080,6 @@ abstract class Base_Model implements \JsonSerializable { unset($attributes['meta']); foreach ($attributes as $attribute => $maybe_null) { - $possible_setters = array( "get_{$attribute}", "is_{$attribute}", @@ -1207,21 +1088,16 @@ abstract class Base_Model implements \JsonSerializable { foreach ($possible_setters as $setter) { $setter = method_exists($this, $setter) ? $setter : ''; - if (!$setter || !method_exists($this, "set_{$attribute}")) { - + if ( ! $setter || ! method_exists($this, "set_{$attribute}")) { continue; - - } // end if; + } $value = $this->{$setter}(); $this->{"set_{$attribute}"}($value); - - } // end foreach; - - } // end foreach; - - } // end hydrate; + } + } + } /** * Set set this to true to skip validations when saving.. @@ -1233,8 +1109,7 @@ abstract class Base_Model implements \JsonSerializable { public function set_skip_validation($skip_validation = false) { $this->skip_validation = $skip_validation; - - } // end set_skip_validation; + } /** * Returns the original parameters of the object. @@ -1245,8 +1120,7 @@ abstract class Base_Model implements \JsonSerializable { public function _get_original() { return $this->_original; - - } // end _get_original; + } /** * Locks this model. @@ -1257,8 +1131,7 @@ abstract class Base_Model implements \JsonSerializable { public function lock() { return $this->update_meta('wu_lock', true); - - } // end lock; + } /** * Check ths lock status of the model. @@ -1269,8 +1142,7 @@ abstract class Base_Model implements \JsonSerializable { public function is_locked() { return $this->get_meta('wu_lock', false); - - } // end is_locked; + } /** * Unlocks the model. @@ -1281,7 +1153,5 @@ abstract class Base_Model implements \JsonSerializable { public function unlock() { return $this->delete_meta('wu_lock'); - - } // end unlock; - -} // end class Base_Model; + } +} diff --git a/inc/models/class-broadcast.php b/inc/models/class-broadcast.php index f7cf007..b84e22c 100644 --- a/inc/models/class-broadcast.php +++ b/inc/models/class-broadcast.php @@ -88,15 +88,12 @@ class Broadcast extends Post_Base_Model { $object = (array) $object; - if (!wu_get_isset($object, 'migrated_from_id')) { - + if ( ! wu_get_isset($object, 'migrated_from_id')) { unset($object['migrated_from_id']); - - } // end if; + } parent::__construct($object); - - } // end __construct; + } /** * Set the validation rules for this particular model. @@ -118,8 +115,7 @@ class Broadcast extends Post_Base_Model { 'content' => 'required|min:3', 'type' => 'required|in:broadcast_email,broadcast_notice|default:broadcast_notice', ); - - } // end validation_rules; + } /** * Get the id of the original 1.X model that was used to generate this item on migration. @@ -130,14 +126,11 @@ class Broadcast extends Post_Base_Model { public function get_migrated_from_id() { if ($this->migrated_from_id === null) { - $this->migrated_from_id = $this->get_meta('migrated_from_id', 0); - - } // end if; + } return $this->migrated_from_id; - - } // end get_migrated_from_id; + } /** * Set the id of the original 1.X model that was used to generate this item on migration. @@ -151,8 +144,7 @@ class Broadcast extends Post_Base_Model { $this->meta['migrated_from_id'] = $migrated_from_id; $this->migrated_from_id = $this->meta['migrated_from_id']; - - } // end set_migrated_from_id; + } /** * Get name of the broadcast @@ -163,8 +155,7 @@ class Broadcast extends Post_Base_Model { public function get_name() { return $this->get_title(); - - } // end get_name; + } /** * Get title of the broadcast @@ -175,8 +166,7 @@ class Broadcast extends Post_Base_Model { public function get_title() { return $this->title; - - } // end get_title; + } /** * Get notice type @@ -187,14 +177,11 @@ class Broadcast extends Post_Base_Model { public function get_notice_type() { if ($this->notice_type === null) { - $this->notice_type = $this->get_meta('notice_type', 'success'); - - } // end if; + } return $this->notice_type; - - } // end get_notice_type; + } /** * Get the message targets. @@ -205,8 +192,7 @@ class Broadcast extends Post_Base_Model { public function get_message_targets() { return $this->get_meta('message_targets'); - - } // end get_message_targets; + } /** * Set the message product and/or customer targets. @@ -219,8 +205,7 @@ class Broadcast extends Post_Base_Model { public function set_message_targets($message_targets) { $this->meta['message_targets'] = $message_targets; - - } // end set_message_targets; + } /** * Set the type of the notice. @@ -236,8 +221,7 @@ class Broadcast extends Post_Base_Model { $this->meta['notice_type'] = $notice_type; $this->notice_type = $this->meta['notice_type']; - - } // end set_notice_type; + } /** * Set title using the name parameter. @@ -250,8 +234,7 @@ class Broadcast extends Post_Base_Model { public function set_name($name) { $this->set_title($name); - - } // end set_name; + } /** * Adds checks to prevent saving the model with the wrong type. @@ -263,15 +246,12 @@ class Broadcast extends Post_Base_Model { */ public function set_type($type) { - if (!in_array($type, $this->allowed_types, true)) { - + if ( ! in_array($type, $this->allowed_types, true)) { $type = 'broadcast_notice'; - - } // end if; + } $this->type = $type; - - } // end set_type; + } /** * * Adds checks to prevent saving the model with the wrong status. @@ -283,14 +263,10 @@ class Broadcast extends Post_Base_Model { */ public function set_status($status) { - if (!in_array($status, $this->allowed_status, true)) { - + if ( ! in_array($status, $this->allowed_status, true)) { $status = 'publish'; - - } // end if; + } $this->status = $status; - - } // end set_status; - -} // end class Broadcast; + } +} diff --git a/inc/models/class-checkout-form.php b/inc/models/class-checkout-form.php index 8be1a51..b4a6498 100644 --- a/inc/models/class-checkout-form.php +++ b/inc/models/class-checkout-form.php @@ -9,8 +9,8 @@ namespace WP_Ultimo\Models; -use \WP_Ultimo\Models\Base_Model; -use \Arrch\Arrch as Array_Search; +use WP_Ultimo\Models\Base_Model; +use Arrch\Arrch as Array_Search; // Exit if accessed directly defined('ABSPATH') || exit; @@ -23,15 +23,15 @@ defined('ABSPATH') || exit; class Checkout_Form extends Base_Model { /** - * @var array|array - */ + * @var array|array + */ public $meta; /** - * The name of the checkout form. - * - * @since 2.0.0 - * @var string - */ + * The name of the checkout form. + * + * @since 2.0.0 + * @var string + */ protected $name; /** @@ -139,8 +139,7 @@ class Checkout_Form extends Base_Model { 'conversion_snippets' => 'nullable|default:', 'template' => 'in:blank,single-step,multi-step', ); - - } // end validation_rules; + } /** * Get the object type associated with this event. @@ -151,8 +150,7 @@ class Checkout_Form extends Base_Model { public function get_slug() { return $this->slug; - - } // end get_slug; + } /** * Set the checkout form slug @@ -165,8 +163,7 @@ class Checkout_Form extends Base_Model { public function set_slug($slug) { $this->slug = $slug; - - } // end set_slug; + } /** * Get the name of the checkout form. @@ -177,8 +174,7 @@ class Checkout_Form extends Base_Model { public function get_name() { return $this->name; - - } // end get_name; + } /** * Set the name of the checkout form. @@ -190,8 +186,7 @@ class Checkout_Form extends Base_Model { public function set_name($name) { $this->name = $name; - - } // end set_name; + } /** * Get is this checkout form active? @@ -202,8 +197,7 @@ class Checkout_Form extends Base_Model { public function is_active() { return (bool) $this->active; - - } // end is_active; + } /** * Set is this checkout form active? @@ -215,8 +209,7 @@ class Checkout_Form extends Base_Model { public function set_active($active) { $this->active = (bool) $active; - - } // end set_active; + } /** * Get custom CSS code. @@ -227,8 +220,7 @@ class Checkout_Form extends Base_Model { public function get_custom_css() { return $this->custom_css; - - } // end get_custom_css; + } /** * Set custom CSS code. @@ -240,8 +232,7 @@ class Checkout_Form extends Base_Model { public function set_custom_css($custom_css) { $this->custom_css = $custom_css; - - } // end set_custom_css; + } /** * Get settings of the event. @@ -252,20 +243,15 @@ class Checkout_Form extends Base_Model { public function get_settings() { if (empty($this->settings)) { - return array(); - - } // end if; + } if (is_string($this->settings)) { - $this->settings = maybe_unserialize($this->settings); - - } // end if; + } return $this->settings; - - } // end get_settings; + } /** * Set settings of the checkout form. @@ -279,62 +265,55 @@ class Checkout_Form extends Base_Model { if (is_string($settings)) { // @phpstan-ignore-line try { - $settings = maybe_unserialize(stripslashes($settings)); - } catch (\Throwable $exception) { // Silence is golden. - } - - } // end if; + } $this->settings = $settings; - - } // end set_settings; - /** - * Returns a specific step by the step name. - * - * @since 2.0.0 - * - * @param string $step_name Name of the step. E.g. 'account'. - * @param bool $to_show If we want the steps to show in a form. - * @return mixed[]|false - */ - public function get_step($step_name, $to_show = false) { + } + /** + * Returns a specific step by the step name. + * + * @since 2.0.0 + * + * @param string $step_name Name of the step. E.g. 'account'. + * @param bool $to_show If we want the steps to show in a form. + * @return mixed[]|false + */ + public function get_step($step_name, $to_show = false) { $settings = $to_show ? $this->get_steps_to_show() : $this->get_settings(); $step_key = array_search($step_name, array_column($settings, 'id'), true); - $step = $step_key !== false ? $settings[$step_key] : false; + $step = $step_key !== false ? $settings[ $step_key ] : false; if ($step) { - - $step = wp_parse_args($step, array( - 'logged' => 'always', - 'fields' => array(), - )); - - } // end if; + $step = wp_parse_args( + $step, + array( + 'logged' => 'always', + 'fields' => array(), + ) + ); + } return $step; - - } // end get_step; - /** - * Returns the steps to show in current form - * - * @since 2.0.19 - * @return mixed[]|false - */ - public function get_steps_to_show() { + } + /** + * Returns the steps to show in current form + * + * @since 2.0.19 + * @return mixed[]|false + */ + public function get_steps_to_show() { if ($this->steps_to_show) { - return $this->steps_to_show; - - } // end if; + } $steps = $this->get_settings(); @@ -345,7 +324,7 @@ class Checkout_Form extends Base_Model { $non_data_fields = array( 'submit_button', 'period_selection', - 'steps' + 'steps', ); $hidden_fields = array( @@ -355,80 +334,62 @@ class Checkout_Form extends Base_Model { $final_data_fields = array(); foreach ($steps as $key => $step) { - $logged = wu_get_isset($step, 'logged', 'always'); $show = $logged === 'always'; - if ($logged === 'guests_only' && !$user_exists) { - + if ($logged === 'guests_only' && ! $user_exists) { $show = true; - } elseif ($logged === 'logged_only' && $user_exists) { - $show = true; + } - } // end if; - - if (!$show) { - + if ( ! $show) { continue; + } - } // end if; + $data_fields = array_filter($step['fields'], fn($field) => ! in_array($field['type'], $non_data_fields, true)); - $data_fields = array_filter($step['fields'], fn($field) => !in_array($field['type'], $non_data_fields, true)); - - $not_hidden_fields = array_filter($data_fields, fn($field) => !in_array($field['type'], $hidden_fields, true) && !wu_should_hide_form_field($field)); + $not_hidden_fields = array_filter($data_fields, fn($field) => ! in_array($field['type'], $hidden_fields, true) && ! wu_should_hide_form_field($field)); if (empty($not_hidden_fields)) { - $final_data_fields = array_merge($final_data_fields, $data_fields); - } else { - $final_steps[] = $step; + } + } - } // end if; - - } // end foreach; - - if (!empty($final_steps) && !empty($final_data_fields)) { - + if ( ! empty($final_steps) && ! empty($final_data_fields)) { $key = array_key_last($final_steps); - $final_steps[$key]['fields'] = array_merge($final_data_fields, $final_steps[$key]['fields']); - - } // end if; + $final_steps[ $key ]['fields'] = array_merge($final_data_fields, $final_steps[ $key ]['fields']); + } $this->steps_to_show = $final_steps; return $final_steps; - - } // end get_steps_to_show; - /** - * Returns a specific field by the step name and field name. - * - * @since 2.0.0 - * - * @param string $step_name Name of the step. E.g. 'account'. - * @param string $field_name Name of the field. E.g. 'username'. - * @return mixed[]|false - */ - public function get_field($step_name, $field_name) { + } + /** + * Returns a specific field by the step name and field name. + * + * @since 2.0.0 + * + * @param string $step_name Name of the step. E.g. 'account'. + * @param string $field_name Name of the field. E.g. 'username'. + * @return mixed[]|false + */ + public function get_field($step_name, $field_name) { $step = $this->get_step($step_name); - if (!is_array($step)) { - + if ( ! is_array($step)) { return false; - - } // end if; + } $field_key = array_search($field_name, array_column($step['fields'], 'id'), true); - return $field_key !== false ? $step['fields'][$field_key] : false; - - } // end get_field; + return $field_key !== false ? $step['fields'][ $field_key ] : false; + } /** * Returns all the fields from all steps. @@ -440,23 +401,18 @@ class Checkout_Form extends Base_Model { $settings = $this->get_settings(); - if (!is_array($settings)) { - + if ( ! is_array($settings)) { return array(); - - } // end if; + } $fields = array_column($settings, 'fields'); if (empty($fields)) { - return array(); - - } // end if; + } return call_user_func_array('array_merge', $fields); - - } // end get_all_fields; + } /** * Get all fields of a given type. @@ -472,13 +428,15 @@ class Checkout_Form extends Base_Model { $types = (array) $type; - return Array_Search::find($all_fields, array( - 'where' => array( - array('type', $types), - ), - )); - - } // end get_all_fields_by_type; + return Array_Search::find( + $all_fields, + array( + 'where' => array( + array('type', $types), + ), + ) + ); + } /** * Get fields that are meta-related. @@ -494,14 +452,16 @@ class Checkout_Form extends Base_Model { $types = apply_filters('wu_checkout_form_meta_fields_list', array('text', 'select', 'color', 'color_picker', 'textarea', 'checkbox'), $this); - return Array_Search::find($all_fields, array( - 'where' => array( - array('type', $types), - array('save_as', $meta_type), - ), - )); - - } // end get_all_meta_fields; + return Array_Search::find( + $all_fields, + array( + 'where' => array( + array('type', $types), + array('save_as', $meta_type), + ), + ) + ); + } /** * Returns the number of steps in this form. @@ -514,8 +474,7 @@ class Checkout_Form extends Base_Model { $steps = $this->get_settings(); return is_array($steps) ? count($steps) : 0; - - } // end get_step_count; + } /** * Returns the number of fields on this form. @@ -528,8 +487,7 @@ class Checkout_Form extends Base_Model { $fields = $this->get_all_fields(); return is_array($fields) ? count($fields) : 0; - - } // end get_field_count; + } /** * Returns the shortcode that needs to be placed to embed this form. * @@ -538,8 +496,7 @@ class Checkout_Form extends Base_Model { public function get_shortcode(): string { return sprintf('[wu_checkout slug="%s"]', $this->get_slug()); - - } // end get_shortcode; + } /** * Sets an template for blank. @@ -554,20 +511,15 @@ class Checkout_Form extends Base_Model { $fields = array(); if ($template === 'multi-step') { - $fields = $this->get_multi_step_template(); $this->set_settings($fields); - } elseif ($template === 'single-step') { - $fields = $this->get_single_step_template(); - - } // end if; + } $this->set_settings($fields); - - } // end use_template; + } /** * Get the contents of the single step template. @@ -577,13 +529,13 @@ class Checkout_Form extends Base_Model { */ private function get_single_step_template() { - $steps = array ( - array ( + $steps = array( + array( 'id' => 'checkout', 'name' => __('Checkout', 'wp-ultimo'), 'desc' => '', - 'fields' => array ( - array ( + 'fields' => array( + array( 'step' => 'checkout', 'name' => __('Plans', 'wp-ultimo'), 'type' => 'pricing_table', @@ -592,7 +544,7 @@ class Checkout_Form extends Base_Model { 'pricing_table_products' => implode(',', wu_get_plans(array('fields' => 'ids'))), 'pricing_table_template' => 'list', ), - array ( + array( 'step' => 'checkout', 'name' => __('Email', 'wp-ultimo'), 'type' => 'email', @@ -601,7 +553,7 @@ class Checkout_Form extends Base_Model { 'placeholder' => '', 'tooltip' => '', ), - array ( + array( 'step' => 'checkout', 'name' => __('Username', 'wp-ultimo'), 'type' => 'username', @@ -611,7 +563,7 @@ class Checkout_Form extends Base_Model { 'tooltip' => '', 'auto_generate' => false, ), - array ( + array( 'step' => 'checkout', 'name' => __('Password', 'wp-ultimo'), 'type' => 'password', @@ -622,7 +574,7 @@ class Checkout_Form extends Base_Model { 'password_strength_meter' => '1', 'password_confirm_field' => '1', ), - array ( + array( 'step' => 'checkout', 'name' => __('Site Title', 'wp-ultimo'), 'type' => 'site_title', @@ -632,7 +584,7 @@ class Checkout_Form extends Base_Model { 'tooltip' => '', 'auto_generate' => false, ), - array ( + array( 'step' => 'checkout', 'name' => __('Site URL', 'wp-ultimo'), 'type' => 'site_url', @@ -643,7 +595,7 @@ class Checkout_Form extends Base_Model { 'auto_generate' => false, 'display_url_preview' => true, ), - array ( + array( 'step' => 'checkout', 'name' => __('Your Order', 'wp-ultimo'), 'type' => 'order_summary', @@ -651,13 +603,13 @@ class Checkout_Form extends Base_Model { 'order_summary_template' => 'clean', 'table_columns' => 'simple', ), - array ( + array( 'step' => 'checkout', 'name' => __('Payment Method', 'wp-ultimo'), 'type' => 'payment', 'id' => 'payment', ), - array ( + array( 'step' => 'checkout', 'name' => __('Billing Address', 'wp-ultimo'), 'type' => 'billing_address', @@ -665,7 +617,7 @@ class Checkout_Form extends Base_Model { 'required' => true, 'zip_and_country' => '1', ), - array ( + array( 'step' => 'checkout', 'name' => __('Checkout', 'wp-ultimo'), 'type' => 'submit_button', @@ -676,8 +628,7 @@ class Checkout_Form extends Base_Model { ); return apply_filters('wu_checkout_form_single_step_template', $steps); - - } // end get_single_step_template; + } /** * Get the contents of the multi step template. @@ -687,13 +638,13 @@ class Checkout_Form extends Base_Model { */ private function get_multi_step_template() { - $steps = array ( + $steps = array( array( 'id' => 'checkout', 'name' => __('Checkout', 'wp-ultimo'), 'desc' => '', 'fields' => array( - array ( + array( 'step' => 'checkout', 'name' => 'Plans', 'type' => 'pricing_table', @@ -702,7 +653,7 @@ class Checkout_Form extends Base_Model { 'pricing_table_products' => implode(',', wu_get_plans(array('fields' => 'ids'))), 'pricing_table_template' => 'list', ), - array ( + array( 'step' => 'checkout', 'name' => __('Next Step', 'wp-ultimo'), 'type' => 'submit_button', @@ -710,12 +661,12 @@ class Checkout_Form extends Base_Model { ), ), ), - array ( + array( 'id' => 'site', 'name' => __('Site Info', 'wp-ultimo'), 'desc' => '', - 'fields' => array ( - array ( + 'fields' => array( + array( 'step' => 'checkout', 'name' => __('Site Title', 'wp-ultimo'), 'type' => 'site_title', @@ -725,7 +676,7 @@ class Checkout_Form extends Base_Model { 'tooltip' => '', 'auto_generate' => false, ), - array ( + array( 'step' => 'checkout', 'name' => __('Site URL', 'wp-ultimo'), 'type' => 'site_url', @@ -736,7 +687,7 @@ class Checkout_Form extends Base_Model { 'auto_generate' => false, 'display_url_preview' => true, ), - array ( + array( 'step' => 'site', 'name' => __('Next Step', 'wp-ultimo'), 'type' => 'submit_button', @@ -744,13 +695,13 @@ class Checkout_Form extends Base_Model { ), ), ), - array ( + array( 'id' => 'user', 'name' => __('User Info', 'wp-ultimo'), 'logged' => 'guests_only', 'desc' => '', - 'fields' => array ( - array ( + 'fields' => array( + array( 'step' => 'checkout', 'name' => __('Email', 'wp-ultimo'), 'type' => 'email', @@ -759,7 +710,7 @@ class Checkout_Form extends Base_Model { 'placeholder' => '', 'tooltip' => '', ), - array ( + array( 'step' => 'checkout', 'name' => __('Username', 'wp-ultimo'), 'type' => 'username', @@ -769,7 +720,7 @@ class Checkout_Form extends Base_Model { 'tooltip' => '', 'auto_generate' => false, ), - array ( + array( 'step' => 'checkout', 'name' => __('Password', 'wp-ultimo'), 'type' => 'password', @@ -780,7 +731,7 @@ class Checkout_Form extends Base_Model { 'password_strength_meter' => '1', 'password_confirm_field' => '1', ), - array ( + array( 'step' => 'user', 'name' => __('Next Step', 'wp-ultimo'), 'type' => 'submit_button', @@ -788,12 +739,12 @@ class Checkout_Form extends Base_Model { ), ), ), - array ( + array( 'id' => 'payment', 'name' => __('Payment', 'wp-ultimo'), 'desc' => '', - 'fields' => array ( - array ( + 'fields' => array( + array( 'step' => 'checkout', 'name' => __('Your Order', 'wp-ultimo'), 'type' => 'order_summary', @@ -801,13 +752,13 @@ class Checkout_Form extends Base_Model { 'order_summary_template' => 'clean', 'table_columns' => 'simple', ), - array ( + array( 'step' => 'checkout', 'name' => __('Payment Method', 'wp-ultimo'), 'type' => 'payment', 'id' => 'payment', ), - array ( + array( 'step' => 'checkout', 'name' => __('Billing Address', 'wp-ultimo'), 'type' => 'billing_address', @@ -815,7 +766,7 @@ class Checkout_Form extends Base_Model { 'required' => true, 'zip_and_country' => '1', ), - array ( + array( 'step' => 'checkout', 'name' => __('Checkout', 'wp-ultimo'), 'type' => 'submit_button', @@ -826,8 +777,7 @@ class Checkout_Form extends Base_Model { ); return apply_filters('wu_checkout_form_multi_step_template', $steps); - - } // end get_multi_step_template; + } /** * Converts the steps from classic WP Multisite WaaS 1.X to the 2.0 format. @@ -848,29 +798,25 @@ class Checkout_Form extends Base_Model { $old_template_list = wu_get_isset($old_settings, 'templates', array()); if (empty($old_template_list)) { - $exclude_steps[] = 'template'; - - } // end if; + } $new_format = array(); foreach ($steps as $step_id => $step) { - if (in_array($step_id, $exclude_steps, true)) { - continue; - - } // end if; + } /** * Deal with special cases. */ if ($step_id === 'plan') { - - $products_list = wu_get_plans(array( - 'fields' => 'ids', - )); + $products_list = wu_get_plans( + array( + 'fields' => 'ids', + ) + ); /* * Calculate the period selector @@ -896,21 +842,16 @@ class Checkout_Form extends Base_Model { ); foreach ($period_options as $period_option_key => $period_option) { - $has_period_option = wu_get_isset($old_settings, $period_option_key, true); if ($has_period_option) { - $available_periods[] = $period_option; - - } // end if; - - } // end foreach; + } + } $step['fields'] = array(); if ($available_periods && count($available_periods) > 1) { - $step['fields']['period_selection'] = array( 'type' => 'period_selection', 'id' => 'period_selection', @@ -918,8 +859,7 @@ class Checkout_Form extends Base_Model { 'period_options_header' => '', 'period_options' => $available_periods, ); - - } // end if; + } $step['fields']['pricing_table'] = array( 'name' => __('Pricing Tables', 'wp-ultimo'), @@ -928,27 +868,23 @@ class Checkout_Form extends Base_Model { 'pricing_table_template' => 'legacy', 'pricing_table_products' => implode(',', $products_list), ); - - } // end if; + } /** * Deal with special cases. */ if ($step_id === 'template' && wu_get_isset($old_settings, 'allow_template', true)) { - $templates = array(); foreach (wu_get_site_templates() as $site) { - $templates[] = $site->get_id(); - - } // end foreach; + } $old_template_list = is_array($old_template_list) ? $old_template_list : array(); $template_list = array_flip($old_template_list); - $template_list = !empty($template_list) ? $template_list : $templates; + $template_list = ! empty($template_list) ? $template_list : $templates; $step['fields'] = array( 'template_selection' => array( @@ -959,8 +895,7 @@ class Checkout_Form extends Base_Model { 'template_selection_sites' => implode(',', $template_list), ), ); - - } // end if; + } /** * Remove unnecessary callbacks @@ -976,24 +911,20 @@ class Checkout_Form extends Base_Model { $fields_to_skip = array( 'user_pass_conf', 'url_preview', - 'site_url' // Despite the name, this is the Honeypot field. + 'site_url', // Despite the name, this is the Honeypot field. ); foreach ($step['fields'] as $field_id => $field) { - if (in_array($field_id, $fields_to_skip, true)) { - - unset($step['fields'][$field_id]); + unset($step['fields'][ $field_id ]); continue; - - } // end if; + } /** * Format specific fields. */ switch ($field_id) { - case 'user_name': $field['type'] = 'username'; $field['id'] = 'username'; @@ -1035,26 +966,21 @@ class Checkout_Form extends Base_Model { $field['id'] = 'submit_button'; if ($step_id === 'account') { - $field['name'] = __('Continue to the Next Step', 'wp-ultimo'); - - } // end if; + } break; - - } // end switch; + } $field['id'] = $field_id; $new_fields[] = $field; - - } // end foreach; + } $step['fields'] = $new_fields; $new_format[] = $step; - - } // end foreach; + } /** * Add Checkout step @@ -1097,8 +1023,7 @@ class Checkout_Form extends Base_Model { ); return $new_format; - - } // end convert_steps_to_v2; + } /** * Checks if this signup has limitations on countries. @@ -1108,9 +1033,8 @@ class Checkout_Form extends Base_Model { */ public function has_country_lock() { - return !empty($this->get_allowed_countries()); - - } // end has_country_lock; + return ! empty($this->get_allowed_countries()); + } /** * Get countries allowed on this checkout. @@ -1121,14 +1045,11 @@ class Checkout_Form extends Base_Model { public function get_allowed_countries() { if (is_string($this->allowed_countries)) { - $this->allowed_countries = maybe_unserialize(stripslashes($this->allowed_countries)); - - } // end if; + } return maybe_unserialize($this->allowed_countries); - - } // end get_allowed_countries; + } /** * Set countries allowed on this checkout. @@ -1140,8 +1061,7 @@ class Checkout_Form extends Base_Model { public function set_allowed_countries($allowed_countries) { $this->allowed_countries = $allowed_countries; - - } // end set_allowed_countries; + } /** * Checks if this checkout form has a custom thank you page. @@ -1154,8 +1074,7 @@ class Checkout_Form extends Base_Model { $page_id = $this->get_thank_you_page_id(); return $page_id && get_post($page_id); - - } // end has_thank_you_page; + } /** * Get custom thank you page, if set. @@ -1166,14 +1085,11 @@ class Checkout_Form extends Base_Model { public function get_thank_you_page_id() { if ($this->thank_you_page_id === null) { - $this->thank_you_page_id = $this->get_meta('wu_thank_you_page_id', ''); - - } // end if; + } return $this->thank_you_page_id; - - } // end get_thank_you_page_id; + } /** * Set custom thank you page, if set. @@ -1187,8 +1103,7 @@ class Checkout_Form extends Base_Model { $this->meta['wu_thank_you_page_id'] = $thank_you_page_id; $this->thank_you_page_id = $thank_you_page_id; - - } // end set_thank_you_page_id; + } /** * Get Snippets to run on thank you page. @@ -1199,14 +1114,11 @@ class Checkout_Form extends Base_Model { public function get_conversion_snippets() { if ($this->conversion_snippets === null) { - $this->conversion_snippets = $this->get_meta('wu_conversion_snippets', ''); - - } // end if; + } return $this->conversion_snippets; - - } // end get_conversion_snippets; + } /** * Set snippets to run on thank you page. @@ -1220,8 +1132,7 @@ class Checkout_Form extends Base_Model { $this->meta['wu_conversion_snippets'] = $conversion_snippets; $this->conversion_snippets = $conversion_snippets; - - } // end set_conversion_snippets; + } /** * Save (create or update) the model on the database. @@ -1241,14 +1152,11 @@ class Checkout_Form extends Base_Model { ); if ($this->template && in_array($this->template, $step_types, true)) { - $this->use_template($this->template); - - } // end if; + } return parent::save(); - - } // end save; + } /** * Get can be either 'blank', 'single-step' or 'multi-step'. @@ -1259,8 +1167,7 @@ class Checkout_Form extends Base_Model { public function get_template() { return $this->template; - - } // end get_template; + } /** * Set the template mode. THis is mostly used on CLI. @@ -1273,8 +1180,7 @@ class Checkout_Form extends Base_Model { public function set_template($template) { $this->template = $template; - - } // end set_template; + } /** * Custom fields to allow customer to finish a payment intent. @@ -1286,26 +1192,20 @@ class Checkout_Form extends Base_Model { $payment = wu_get_payment_by_hash(wu_request('payment')); - if (!$payment && wu_request('payment_id')) { - + if ( ! $payment && wu_request('payment_id')) { $payment = wu_get_payment(wu_request('payment_id')); + } - } // end if; - - if (!$payment && current_user_can('manage_options')) { - + if ( ! $payment && current_user_can('manage_options')) { $payment = wu_mock_payment(); + } - } // end if; - - if (!$payment) { - + if ( ! $payment) { return array(); - - } // end if; + } $fields = array( - array ( + array( 'step' => 'checkout', 'name' => __('Your Order', 'wp-ultimo'), 'type' => 'order_summary', @@ -1313,13 +1213,13 @@ class Checkout_Form extends Base_Model { 'order_summary_template' => 'clean', 'table_columns' => 'simple', ), - array ( + array( 'step' => 'checkout', 'name' => __('Payment Method', 'wp-ultimo'), 'type' => 'payment', 'id' => 'payment', ), - array ( + array( 'step' => 'checkout', 'name' => __('Finish Payment', 'wp-ultimo'), 'type' => 'submit_button', @@ -1328,8 +1228,8 @@ class Checkout_Form extends Base_Model { ), ); - $steps = array ( - array ( + $steps = array( + array( 'id' => 'checkout', 'name' => __('Checkout', 'wp-ultimo'), 'desc' => '', @@ -1338,8 +1238,7 @@ class Checkout_Form extends Base_Model { ); return apply_filters('wu_checkout_form_finish_checkout_form_fields', $steps); - - } // end finish_checkout_form_fields; + } /** * Custom fields for back-end upgrade/downgrades and such. @@ -1351,23 +1250,17 @@ class Checkout_Form extends Base_Model { $membership = WP_Ultimo()->currents->get_membership(); - if (!$membership && wu_request('membership_id')) { - + if ( ! $membership && wu_request('membership_id')) { $membership = wu_get_membership(wu_request('membership_id')); + } - } // end if; - - if (!$membership && current_user_can('manage_options')) { - + if ( ! $membership && current_user_can('manage_options')) { $membership = wu_mock_membership(); + } - } // end if; - - if (!$membership) { - + if ( ! $membership) { return array(); - - } // end if; + } $fields = array(); @@ -1388,17 +1281,14 @@ class Checkout_Form extends Base_Model { ); if ($group) { - $search_arguments['product_group'] = $group; - } else { /* * If there isn't a group available * limit the return to 3. */ $search_arguments['number'] = 3; - - } // end if; + } $plans = wu_get_plans($search_arguments); @@ -1413,7 +1303,6 @@ class Checkout_Form extends Base_Model { * and witch selectors we need */ foreach ($products as $product) { - $days_in_cycle = wu_get_days_in_cycle($product->get_duration_unit(), $product->get_duration()); $label = sprintf( @@ -1423,7 +1312,7 @@ class Checkout_Form extends Base_Model { wu_get_translatable_string($product->get_duration() <= 1 ? $product->get_duration_unit() : $product->get_duration_unit() . 's') ); - $period_selection[$days_in_cycle] = array( + $period_selection[ $days_in_cycle ] = array( 'duration' => $product->get_duration(), 'duration_unit' => $product->get_duration_unit(), 'label' => $label, @@ -1432,10 +1321,8 @@ class Checkout_Form extends Base_Model { $variations = $product->get_price_variations(); if (empty($variations)) { - continue; - - } // end if; + } /** * We have different variations on same product @@ -1456,20 +1343,17 @@ class Checkout_Form extends Base_Model { wu_get_translatable_string($variation['duration'] <= 1 ? $variation['duration_unit'] : $variation['duration_unit'] . 's') ); - $period_selection[$days_in_cycle] = array( + $period_selection[ $days_in_cycle ] = array( 'duration' => $variation['duration'], 'duration_unit' => $variation['duration_unit'], 'label' => $label, ); - - } // end foreach; - - } // end foreach; + } + } ksort($period_selection); if ($should_use_period_selector) { - $fields[] = array( 'step' => 'checkout', 'name' => '', @@ -1478,8 +1362,7 @@ class Checkout_Form extends Base_Model { 'period_selection_template' => 'clean', 'period_options' => array_values($period_selection), ); - - } // end if; + } $fields[] = array( 'step' => 'checkout', @@ -1489,26 +1372,21 @@ class Checkout_Form extends Base_Model { 'required' => true, 'pricing_table_products' => implode(',', $plans), 'pricing_table_template' => 'list', - 'force_different_durations' => (int) !$should_use_period_selector, + 'force_different_durations' => (int) ! $should_use_period_selector, ); $available_addons = (array) $plan->get_available_addons(); foreach ($available_addons as $addon_id) { - - if (!$addon_id) { - + if ( ! $addon_id) { continue; - - } // end if; + } $addon = wu_get_product($addon_id); - if (!$addon) { - + if ( ! $addon) { continue; - - } // end if; + } $fields[] = array( 'id' => "order_bump_{$addon_id}", @@ -1517,13 +1395,11 @@ class Checkout_Form extends Base_Model { 'product' => $addon_id, 'display_product_image' => true, ); - - } // end foreach; - - } // end if; + } + } $end_fields = array( - array ( + array( 'step' => 'checkout', 'name' => __('Your Order', 'wp-ultimo'), 'type' => 'order_summary', @@ -1531,13 +1407,13 @@ class Checkout_Form extends Base_Model { 'order_summary_template' => 'clean', 'table_columns' => 'simple', ), - array ( + array( 'step' => 'checkout', 'name' => __('Payment Method', 'wp-ultimo'), 'type' => 'payment', 'id' => 'payment', ), - array ( + array( 'step' => 'checkout', 'name' => __('Complete Checkout', 'wp-ultimo'), 'type' => 'submit_button', @@ -1548,8 +1424,8 @@ class Checkout_Form extends Base_Model { $fields = array_merge($fields, $end_fields); - $steps = array ( - array ( + $steps = array( + array( 'id' => 'checkout', 'name' => __('Checkout', 'wp-ultimo'), 'desc' => '', @@ -1558,8 +1434,7 @@ class Checkout_Form extends Base_Model { ); return apply_filters('wu_checkout_form_membership_change_form_fields', $steps); - - } // end membership_change_form_fields; + } /** * Custom fields to add to the add new site screen. @@ -1571,11 +1446,9 @@ class Checkout_Form extends Base_Model { $membership = WP_Ultimo()->currents->get_membership(); - if (!$membership) { - + if ( ! $membership) { return array(); - - } // end if; + } /* * Adds the addons @@ -1587,7 +1460,6 @@ class Checkout_Form extends Base_Model { // As this limit is not membership based, we need to exclude from verification here if ($membership->get_limitations(true, true)->site_templates->is_enabled()) { - $template_selection_fields = array( array( 'step' => 'template', @@ -1612,8 +1484,7 @@ class Checkout_Form extends Base_Model { 'desc' => '', 'fields' => $template_selection_fields, ); - - } // end if; + } $final_fields = array( array( @@ -1661,7 +1532,7 @@ class Checkout_Form extends Base_Model { 'placeholder' => '', 'display_field_attachments' => false, 'type' => 'site_url', - 'enable_domain_selection' => !empty($domain_options), + 'enable_domain_selection' => ! empty($domain_options), 'available_domains' => implode(PHP_EOL, $domain_options), ); @@ -1682,7 +1553,5 @@ class Checkout_Form extends Base_Model { ); return apply_filters('wu_checkout_form_add_new_site_form_fields', $steps); - - } // end add_new_site_form_fields; - -} // end class Checkout_Form; + } +} diff --git a/inc/models/class-customer.php b/inc/models/class-customer.php index 6ca6773..24452e3 100644 --- a/inc/models/class-customer.php +++ b/inc/models/class-customer.php @@ -24,7 +24,8 @@ defined('ABSPATH') || exit; */ class Customer extends Base_Model { - use Traits\Billable, Traits\Notable; + use Traits\Billable; + use Traits\Notable; /** * User ID of the associated user. @@ -136,8 +137,7 @@ class Customer extends Base_Model { public function save() { return parent::save(); - - } // end save; + } /** * Set the validation rules for this particular model. @@ -164,8 +164,7 @@ class Customer extends Base_Model { 'extra_information' => 'default:', 'signup_form' => 'default:', ); - - } // end validation_rules; + } /** * Get user ID of the associated user. @@ -176,8 +175,7 @@ class Customer extends Base_Model { public function get_user_id() { return absint($this->user_id); - - } // end get_user_id; + } /** * Set user ID of the associated user. @@ -189,8 +187,7 @@ class Customer extends Base_Model { public function set_user_id($user_id) { $this->user_id = $user_id; - - } // end set_user_id; + } /** * Returns the user associated with this customer. @@ -201,8 +198,7 @@ class Customer extends Base_Model { public function get_user() { return get_user_by('id', $this->get_user_id()); - - } // end get_user; + } /** * Returns the customer's display name. @@ -215,14 +211,11 @@ class Customer extends Base_Model { $user = $this->get_user(); if (empty($user)) { - return __('User Deleted', 'wp-ultimo'); - - } // end if; + } return $user->display_name; - - } // end get_display_name; + } /** * Returns the default billing address. @@ -235,13 +228,14 @@ class Customer extends Base_Model { */ public function get_default_billing_address() { - return new \WP_Ultimo\Objects\Billing_Address(array( - 'company_name' => $this->get_display_name(), - 'billing_email' => $this->get_email_address(), - 'billing_country' => $this->get_meta('ip_country'), - )); - - } // end get_default_billing_address; + return new \WP_Ultimo\Objects\Billing_Address( + array( + 'company_name' => $this->get_display_name(), + 'billing_email' => $this->get_email_address(), + 'billing_country' => $this->get_meta('ip_country'), + ) + ); + } /** * Returns the customer country. @@ -255,15 +249,12 @@ class Customer extends Base_Model { $country = $billing_address->billing_country; - if (!$country) { - + if ( ! $country) { return $this->get_meta('ip_country'); - - } // end if; + } return $country; - - } // end get_country; + } /** * Returns the customer's username. @@ -276,14 +267,11 @@ class Customer extends Base_Model { $user = $this->get_user(); if (empty($user)) { - return __('none', 'wp-ultimo'); - - } // end if; + } return $user->user_login; - - } // end get_username; + } /** * Returns the customer's email address. @@ -296,14 +284,11 @@ class Customer extends Base_Model { $user = $this->get_user(); if (empty($user)) { - return __('none', 'wp-ultimo'); - - } // end if; + } return $user->user_email; - - } // end get_email_address; + } /** * Get date when the customer was created. @@ -315,8 +300,7 @@ class Customer extends Base_Model { public function get_date_registered($formatted = true) { return $this->date_registered; - - } // end get_date_registered; + } /** * Set date when the customer was created. @@ -328,8 +312,7 @@ class Customer extends Base_Model { public function set_date_registered($date_registered) { $this->date_registered = $date_registered; - - } // end set_date_registered; + } /** * Get email verification status - either `none`, `pending`, or `verified`. @@ -340,8 +323,7 @@ class Customer extends Base_Model { public function get_email_verification() { return $this->email_verification; - - } // end get_email_verification; + } /** * Set email verification status - either `none`, `pending`, or `verified`. @@ -353,8 +335,7 @@ class Customer extends Base_Model { public function set_email_verification($email_verification) { $this->email_verification = $email_verification; - - } // end set_email_verification; + } /** * Get date this customer last logged in. @@ -366,8 +347,7 @@ class Customer extends Base_Model { public function get_last_login($formatted = true) { return $this->last_login; - - } // end get_last_login; + } /** * Set date this customer last logged in. @@ -379,8 +359,7 @@ class Customer extends Base_Model { public function set_last_login($last_login) { $this->last_login = $last_login; - - } // end set_last_login; + } /** * Get whether or not the customer has trialed before. @@ -391,35 +370,30 @@ class Customer extends Base_Model { public function has_trialed() { if ((bool) $this->has_trialed) { - return true; - - } // end if; + } $this->has_trialed = $this->get_meta('wu_has_trialed'); - if (!$this->has_trialed) { - - $trial = wu_get_memberships(array( - 'customer_id' => $this->get_id(), - 'date_trial_end__not_in' => array(null, '0000-00-00 00:00:00'), - 'fields' => 'ids', - 'number' => 1, - )); - - if (!empty($trial)) { + if ( ! $this->has_trialed) { + $trial = wu_get_memberships( + array( + 'customer_id' => $this->get_id(), + 'date_trial_end__not_in' => array(null, '0000-00-00 00:00:00'), + 'fields' => 'ids', + 'number' => 1, + ) + ); + if ( ! empty($trial)) { $this->update_meta('wu_has_trialed', true); $this->has_trialed = true; - - } // end if; - - } // end if; + } + } return $this->has_trialed; - - } // end has_trialed; + } /** * Set whether or not the customer has trialed before. @@ -433,8 +407,7 @@ class Customer extends Base_Model { $this->meta['wu_has_trialed'] = $has_trialed; $this->has_trialed = $has_trialed; - - } // end set_has_trialed; + } /** * Get if this customer is a VIP customer or not. @@ -445,8 +418,7 @@ class Customer extends Base_Model { public function is_vip() { return (bool) $this->vip; - - } // end is_vip; + } /** * Set if this customer is a VIP customer or not. @@ -458,8 +430,7 @@ class Customer extends Base_Model { public function set_vip($vip) { $this->vip = $vip; - - } // end set_vip; + } /** * Get list of IP addresses used by this customer. @@ -470,20 +441,15 @@ class Customer extends Base_Model { public function get_ips() { if (empty($this->ips)) { - return array(); - - } // end if; + } if (is_string($this->ips)) { - $this->ips = maybe_unserialize($this->ips); - - } // end if; + } return $this->ips; - - } // end get_ips; + } /** * Returns the last IP address recorded for the customer. @@ -496,8 +462,7 @@ class Customer extends Base_Model { $ips = $this->get_ips(); return array_pop($ips); - - } // end get_last_ip; + } /** * Set list of IP addresses used by this customer. @@ -509,14 +474,11 @@ class Customer extends Base_Model { public function set_ips($ips) { if (is_string($ips)) { - $ips = maybe_unserialize(wp_unslash($ips)); - - } // end if; + } $this->ips = $ips; - - } // end set_ips; + } /** * Adds a new IP to the IP list. @@ -530,26 +492,21 @@ class Customer extends Base_Model { $ips = $this->get_ips(); - if (!is_array($ips)) { - + if ( ! is_array($ips)) { $ips = array(); - - } // end if; + } /* * IP already exists. */ if (in_array($ip, $ips, true)) { - return; - - } // end if; + } $ips[] = sanitize_text_field($ip); $this->set_ips($ips); - - } // end add_ip; + } /** * Updates the last login, as well as the ip and country if necessary. @@ -562,28 +519,25 @@ class Customer extends Base_Model { */ public function update_last_login($update_ip = true, $update_country_and_state = false) { - $this->attributes(array( - 'last_login' => wu_get_current_time('mysql', true), - )); + $this->attributes( + array( + 'last_login' => wu_get_current_time('mysql', true), + ) + ); $geolocation = $update_ip || $update_country_and_state ? \WP_Ultimo\Geolocation::geolocate_ip('', true) : false; if ($update_ip) { - $this->add_ip($geolocation['ip']); - - } // end if; + } if ($update_country_and_state) { - $this->update_meta('ip_country', $geolocation['country']); $this->update_meta('ip_state', $geolocation['state']); - - } // end if; + } return $this->save(); - - } // end update_last_login; + } /** * Get extra information. @@ -594,16 +548,13 @@ class Customer extends Base_Model { public function get_extra_information() { if ($this->extra_information === null) { - $extra_information = (array) $this->get_meta('wu_customer_extra_information'); $this->extra_information = array_filter($extra_information); - - } // end if; + } return $this->extra_information; - - } // end get_extra_information; + } /** * Set featured extra information. @@ -618,8 +569,7 @@ class Customer extends Base_Model { $this->extra_information = $extra_information; $this->meta['wu_customer_extra_information'] = $extra_information; - - } // end set_extra_information; + } /** * Returns the subscriptions attached to this customer. @@ -629,11 +579,12 @@ class Customer extends Base_Model { */ public function get_memberships() { - return Membership::query(array( - 'customer_id' => $this->get_id(), - )); - - } // end get_memberships; + return Membership::query( + array( + 'customer_id' => $this->get_id(), + ) + ); + } /** * Returns the sites attached to this customer. @@ -657,8 +608,7 @@ class Customer extends Base_Model { ); return Site::query($query_args); - - } // end get_sites; + } /** * Returns all pending sites associated with a customer. @@ -673,20 +623,15 @@ class Customer extends Base_Model { $memberships = $this->get_memberships(); foreach ($memberships as $membership) { - $pending_site = $membership->get_pending_site(); if ($pending_site) { - $pending_sites[] = $pending_site; - - } // end if; - - } // end foreach; + } + } return $pending_sites; - - } // end get_pending_sites; + } /** * The the primary site ID if available. @@ -703,17 +648,14 @@ class Customer extends Base_Model { $primary_site_id = get_user_option('primary_blog', $this->get_user_id()); - if (!$primary_site_id) { - + if ( ! $primary_site_id) { $sites = $this->get_sites(); $primary_site_id = $sites ? $sites[0]->get_id() : wu_get_main_site_id(); - - } // end if; + } return $primary_site_id; - - } // end get_primary_site_id; + } /** * Returns the payments attached to this customer. @@ -723,11 +665,12 @@ class Customer extends Base_Model { */ public function get_payments() { - return Payment::query(array( - 'customer_id' => $this->get_id(), - )); - - } // end get_payments; + return Payment::query( + array( + 'customer_id' => $this->get_id(), + ) + ); + } /** * By default, we just use the to_array method, but you can rewrite this. @@ -740,32 +683,33 @@ class Customer extends Base_Model { $user = get_userdata($this->get_user_id()); if (isset($this->_user)) { - $user = $this->_user; // Allows for injection, which is useful for mocking. unset($this->_user); - - } // end if; + } $search_result = $this->to_array(); if ($user) { - - $user->data->avatar = get_avatar($user->data->user_email, 40, 'identicon', '', array( - 'force_display' => true, - 'class' => 'wu-rounded-full wu-mr-3', - )); + $user->data->avatar = get_avatar( + $user->data->user_email, + 40, + 'identicon', + '', + array( + 'force_display' => true, + 'class' => 'wu-rounded-full wu-mr-3', + ) + ); $search_result = array_merge((array) $user->data, $search_result); - - } // end if; + } $search_result['billing_address_data'] = $this->get_billing_address()->to_array(); $search_result['billing_address'] = $this->get_billing_address()->to_string(); return $search_result; - - } // end to_search_results; + } /** * Get the customer type. @@ -776,8 +720,7 @@ class Customer extends Base_Model { public function get_type() { return $this->type; - - } // end get_type; + } /** * Get the customer type. @@ -790,8 +733,7 @@ class Customer extends Base_Model { public function set_type($type) { $this->type = $type; - - } // end set_type; + } /** * Gets the total grossed by the customer so far. @@ -806,19 +748,16 @@ class Customer extends Base_Model { static $sum; if ($sum === null) { - $sum = $wpdb->get_var( $wpdb->prepare( "SELECT SUM(total) FROM {$wpdb->base_prefix}wu_payments WHERE parent_id = 0 AND customer_id = %d", $this->get_id() ) ); - - } // end if; + } return $sum; - - } // end get_total_grossed; + } /** * Get if the customer is online or not. @@ -829,10 +768,8 @@ class Customer extends Base_Model { public function is_online() { if ($this->get_last_login() === '0000-00-00 00:00:00') { - return false; - - } // end if; + } $last_login_date = new \DateTime($this->get_last_login()); $now = new \DateTime('now'); @@ -843,8 +780,7 @@ class Customer extends Base_Model { $minutes_interval += $interval->i; return $minutes_interval <= apply_filters('wu_is_online_minutes_interval', 3) ? true : false; - - } // end is_online; + } /** * Saves a verification key. @@ -859,19 +795,17 @@ class Customer extends Base_Model { $hash = \WP_Ultimo\Helpers\Hash::encode($seed, 'verification-key'); return $this->update_meta('wu_verification_key', $hash); - - } // end generate_verification_key; - /** - * Returns the saved verification key. - * - * @since 2.0.0 - * @return string|bool - */ - public function get_verification_key() { + } + /** + * Returns the saved verification key. + * + * @since 2.0.0 + * @return string|bool + */ + public function get_verification_key() { return $this->get_meta('wu_verification_key', false); - - } // end get_verification_key; + } /** * Disabled the verification by setting the key to false. @@ -882,30 +816,29 @@ class Customer extends Base_Model { public function disable_verification_key() { return $this->update_meta('wu_verification_key', false); - - } // end disable_verification_key; - /** - * Returns the link of the email verification endpoint. - * - * @since 2.0.0 - * @return string|bool - */ - public function get_verification_url() { + } + /** + * Returns the link of the email verification endpoint. + * + * @since 2.0.0 + * @return string|bool + */ + public function get_verification_url() { $key = $this->get_verification_key(); - if (!$key) { - + if ( ! $key) { return get_site_url(wu_get_main_site_id()); + } - } // end if; - - return add_query_arg(array( - 'email-verification-key' => $key, - 'customer' => $this->get_hash(), - ), get_site_url(wu_get_main_site_id())); - - } // end get_verification_url; + return add_query_arg( + array( + 'email-verification-key' => $key, + 'customer' => $this->get_hash(), + ), + get_site_url(wu_get_main_site_id()) + ); + } /** * Send verification email. @@ -923,8 +856,7 @@ class Customer extends Base_Model { ); wu_do_event('confirm_email_address', $payload); - - } // end send_verification_email; + } /** * Get the form used to signup. @@ -935,8 +867,7 @@ class Customer extends Base_Model { public function get_signup_form() { return $this->signup_form; - - } // end get_signup_form; + } /** * Set the form used to signup. @@ -948,7 +879,5 @@ class Customer extends Base_Model { public function set_signup_form($signup_form) { $this->signup_form = $signup_form; - - } // end set_signup_form; - -} // end class Customer; + } +} diff --git a/inc/models/class-discount-code.php b/inc/models/class-discount-code.php index 1e5bbc1..7103459 100644 --- a/inc/models/class-discount-code.php +++ b/inc/models/class-discount-code.php @@ -185,8 +185,7 @@ class Discount_Code extends Base_Model { 'allowed_products' => 'array', 'limit_products' => 'default:0', ); - - } // end validation_rules; + } /** * Get name of the discount code. @@ -197,8 +196,7 @@ class Discount_Code extends Base_Model { public function get_name() { return $this->name; - - } // end get_name; + } /** * Set name of the discount code. @@ -210,8 +208,7 @@ class Discount_Code extends Base_Model { public function set_name($name) { $this->name = $name; - - } // end set_name; + } /** * Get code to redeem the discount code. @@ -222,8 +219,7 @@ class Discount_Code extends Base_Model { public function get_code() { return $this->code; - - } // end get_code; + } /** * Set code to redeem the discount code. @@ -235,8 +231,7 @@ class Discount_Code extends Base_Model { public function set_code($code) { $this->code = $code; - - } // end set_code; + } /** * Get text describing the coupon code. Useful for identifying it. @@ -247,8 +242,7 @@ class Discount_Code extends Base_Model { public function get_description() { return $this->description; - - } // end get_description; + } /** * Set text describing the coupon code. Useful for identifying it. @@ -260,8 +254,7 @@ class Discount_Code extends Base_Model { public function set_description($description) { $this->description = $description; - - } // end set_description; + } /** * Get number of times this discount was applied. @@ -272,8 +265,7 @@ class Discount_Code extends Base_Model { public function get_uses() { return (int) $this->uses; - - } // end get_uses; + } /** * Set number of times this discount was applied. @@ -285,8 +277,7 @@ class Discount_Code extends Base_Model { public function set_uses($uses) { $this->uses = (int) $uses; - - } // end set_uses; + } /** * Add uses to this discount code. @@ -300,8 +291,7 @@ class Discount_Code extends Base_Model { $use_count = (int) $this->get_uses(); $this->set_uses($use_count + (int) $uses); - - } // end add_use; + } /** * Get the number of times this discount can be used before becoming inactive. @@ -312,8 +302,7 @@ class Discount_Code extends Base_Model { public function get_max_uses() { return (int) $this->max_uses; - - } // end get_max_uses; + } /** * Set the number of times this discount can be used before becoming inactive. @@ -325,8 +314,7 @@ class Discount_Code extends Base_Model { public function set_max_uses($max_uses) { $this->max_uses = (int) $max_uses; - - } // end set_max_uses; + } /** * Checks if the given discount code has a number of max uses. @@ -337,8 +325,7 @@ class Discount_Code extends Base_Model { public function has_max_uses() { return $this->get_max_uses() > 0; - - } // end has_max_uses; + } /** * Get if we should apply this coupon to renewals as well. @@ -349,8 +336,7 @@ class Discount_Code extends Base_Model { public function should_apply_to_renewals() { return (bool) $this->apply_to_renewals; - - } // end should_apply_to_renewals; + } /** * Set if we should apply this coupon to renewals as well. @@ -362,8 +348,7 @@ class Discount_Code extends Base_Model { public function set_apply_to_renewals($apply_to_renewals) { $this->apply_to_renewals = (bool) $apply_to_renewals; - - } // end set_apply_to_renewals; + } /** * Get type of the discount. Can be a percentage or absolute. @@ -374,8 +359,7 @@ class Discount_Code extends Base_Model { public function get_type() { return $this->type; - - } // end get_type; + } /** * Set type of the discount. Can be a percentage or absolute. @@ -388,8 +372,7 @@ class Discount_Code extends Base_Model { public function set_type($type) { $this->type = $type; - - } // end set_type; + } /** * Get amount discounted in cents. @@ -400,8 +383,7 @@ class Discount_Code extends Base_Model { public function get_value() { return (float) $this->value; - - } // end get_value; + } /** * Set amount discounted in cents. @@ -413,8 +395,7 @@ class Discount_Code extends Base_Model { public function set_value($value) { $this->value = $value; - - } // end set_value; + } /** * Get type of the discount for the setup fee value. Can be a percentage or absolute. @@ -425,8 +406,7 @@ class Discount_Code extends Base_Model { public function get_setup_fee_type() { return $this->setup_fee_type; - - } // end get_setup_fee_type; + } /** * Set type of the discount for the setup fee value. Can be a percentage or absolute. @@ -439,8 +419,7 @@ class Discount_Code extends Base_Model { public function set_setup_fee_type($setup_fee_type) { $this->setup_fee_type = $setup_fee_type; - - } // end set_setup_fee_type; + } /** * Get amount discounted fpr setup fees in cents. @@ -451,8 +430,7 @@ class Discount_Code extends Base_Model { public function get_setup_fee_value() { return (float) $this->setup_fee_value; - - } // end get_setup_fee_value; + } /** * Set amount discounted for setup fees in cents. @@ -464,8 +442,7 @@ class Discount_Code extends Base_Model { public function set_setup_fee_value($setup_fee_value) { $this->setup_fee_value = $setup_fee_value; - - } // end set_setup_fee_value; + } /** * Get if this coupon code is active or not. @@ -476,8 +453,7 @@ class Discount_Code extends Base_Model { public function is_active() { return (bool) $this->active; - - } // end is_active; + } /** * Checks if a given coupon code is valid and can be applied. @@ -489,19 +465,15 @@ class Discount_Code extends Base_Model { public function is_valid($product = false) { if ($this->is_active() === false) { - return new \WP_Error('discount_code', __('This coupon code is not valid.', 'wp-ultimo')); - - } // end if; + } /* * Check for uses */ if ($this->has_max_uses() && $this->get_uses() >= $this->get_max_uses()) { - return new \WP_Error('discount_code', __('This discount code was already redeemed the maximum amount of times allowed.', 'wp-ultimo')); - - } // end if; + } /* * Fist, check date boundaries. @@ -512,62 +484,43 @@ class Discount_Code extends Base_Model { $now = wu_date(); if ($start_date) { - $start_date_instance = wu_date($start_date); if ($now < $start_date_instance) { - return new \WP_Error('discount_code', __('This coupon code is not valid.', 'wp-ultimo')); - return new \WP_Error( 'discount_code', __( 'The coupon code is not valid yet.', 'wp-ultimo' ) ); - - } // end if; - - } // end if; + return new \WP_Error('discount_code', __('The coupon code is not valid yet.', 'wp-ultimo')); + } + } if ($expiration_date) { - $expiration_date_instance = wu_date($expiration_date); if ($now > $expiration_date_instance) { - return new \WP_Error('discount_code', __('This coupon code is not valid.', 'wp-ultimo')); + } + } - } // end if; - - } // end if; - - if (!$this->get_limit_products()) { - + if ( ! $this->get_limit_products()) { return true; + } - } // end if; - - if (!empty($product)) { - + if ( ! empty($product)) { if (is_a($product, '\WP_Ultimo\Models\Product')) { - $product_id = $product->get_id(); - } elseif (is_numeric($product)) { - $product_id = $product; - - } // end if; + } $allowed = $this->get_limit_products() && in_array($product_id, $this->get_allowed_products()); // phpcs:ignore if ($allowed === false) { - return new \WP_Error('discount_code', __('This coupon code is not valid.', 'wp-ultimo')); - - } // end if; - - } // end if; + } + } return true; - - } // end is_valid; + } /** * Checks if this discount applies just for the first payment. @@ -578,8 +531,7 @@ class Discount_Code extends Base_Model { public function is_one_time() { return (bool) $this->should_apply_to_renewals(); - - } // end is_one_time; + } /** * Set if this coupon code is active or not. @@ -591,8 +543,7 @@ class Discount_Code extends Base_Model { public function set_active($active) { $this->active = (bool) $active; - - } // end set_active; + } /** * Get start date for the coupon code to be considered valid. @@ -602,15 +553,12 @@ class Discount_Code extends Base_Model { */ public function get_date_start() { - if (!wu_validate_date($this->date_start)) { - + if ( ! wu_validate_date($this->date_start)) { return ''; - - } // end if; + } return $this->date_start; - - } // end get_date_start; + } /** * Set start date for the coupon code to be considered valid. @@ -622,8 +570,7 @@ class Discount_Code extends Base_Model { public function set_date_start($date_start) { $this->date_start = $date_start; - - } // end set_date_start; + } /** * Get expiration date for the coupon code. @@ -633,15 +580,12 @@ class Discount_Code extends Base_Model { */ public function get_date_expiration() { - if (!wu_validate_date($this->date_expiration)) { - + if ( ! wu_validate_date($this->date_expiration)) { return ''; - - } // end if; + } return $this->date_expiration; - - } // end get_date_expiration; + } /** * Set expiration date for the coupon code. @@ -653,8 +597,7 @@ class Discount_Code extends Base_Model { public function set_date_expiration($date_expiration) { $this->date_expiration = $date_expiration; - - } // end set_date_expiration; + } /** * Get date when this discount code was created. @@ -665,8 +608,7 @@ class Discount_Code extends Base_Model { public function get_date_created() { return $this->date_created; - - } // end get_date_created; + } /** * Set date when this discount code was created. @@ -678,8 +620,7 @@ class Discount_Code extends Base_Model { public function set_date_created($date_created) { $this->date_created = $date_created; - - } // end set_date_created; + } /** * Returns a text describing the discount code values. * @@ -690,44 +631,35 @@ class Discount_Code extends Base_Model { $description = array(); if ($this->get_value() > 0) { - $value = wu_format_currency($this->get_value()); if ($this->get_type() === 'percentage') { - $value = $this->get_value() . '%'; - - } // end if; + } $description[] = sprintf( // translators: placeholder is the value off. Can be wither $X.XX or X% __('%1$s OFF on Subscriptions', 'wp-ultimo'), $value ); - - } // end if; + } if ($this->get_setup_fee_value() > 0) { - $setup_fee_value = wu_format_currency($this->get_setup_fee_value()); if ($this->get_setup_fee_type() === 'percentage') { - $setup_fee_value = $this->get_setup_fee_value() . '%'; - - } // end if; + } $description[] = sprintf( // translators: placeholder is the value off. Can be wither $X.XX or X% __('%1$s OFF on Setup Fees', 'wp-ultimo'), $setup_fee_value ); - - } // end if; + } return implode(' ' . __('and', 'wp-ultimo') . ' ', $description); - - } // end get_discount_description; + } /** * Transform the object into an assoc array. @@ -742,8 +674,7 @@ class Discount_Code extends Base_Model { $array['discount_description'] = $this->get_discount_description(); return $array; - - } // end to_array; + } /** * Save (create or update) the model on the database. @@ -756,23 +687,18 @@ class Discount_Code extends Base_Model { $results = parent::save(); - if (!is_wp_error($results) && has_action('wp_ultimo_coupon_after_save')) { - + if ( ! is_wp_error($results) && has_action('wp_ultimo_coupon_after_save')) { if (did_action('wp_ultimo_coupon_after_save')) { - return $results; - - } // end if; + } $compat_coupon = $this; do_action_deprecated('wp_ultimo_coupon_after_save', array($compat_coupon), '2.0.0', 'wu_discount_code_post_save'); - - } // end if; + } return $results; - - } // end save; + } /** * Get holds the list of allowed products. @@ -783,14 +709,11 @@ class Discount_Code extends Base_Model { public function get_allowed_products() { if ($this->allowed_products === null) { - $this->allowed_products = $this->get_meta('wu_allowed_products', array()); - - } // end if; + } return (array) $this->allowed_products; - - } // end get_allowed_products; + } /** * Set holds the list of allowed products. @@ -804,8 +727,7 @@ class Discount_Code extends Base_Model { $this->meta['wu_allowed_products'] = (array) $allowed_products; $this->allowed_products = $this->meta['wu_allowed_products']; - - } // end set_allowed_products; + } /** * Get if we should check for products or not. @@ -816,14 +738,11 @@ class Discount_Code extends Base_Model { public function get_limit_products() { if ($this->limit_products === null) { - $this->limit_products = $this->get_meta('wu_limit_products', false); - - } // end if; + } return (bool) $this->limit_products; - - } // end get_limit_products; + } /** * Set if we should check for products or not. @@ -837,7 +756,5 @@ class Discount_Code extends Base_Model { $this->meta['wu_limit_products'] = (bool) $limit_products; $this->limit_products = $this->meta['wu_limit_products']; - - } // end set_limit_products; - -} // end class Discount_Code; + } +} diff --git a/inc/models/class-domain.php b/inc/models/class-domain.php index f601d4f..8f40cff 100644 --- a/inc/models/class-domain.php +++ b/inc/models/class-domain.php @@ -126,8 +126,7 @@ class Domain extends Base_Model { 'secure' => 'default:0', 'primary_domain' => 'default:0', ); - - } // end validation_rules; + } /** * Returns the domain address mapped. @@ -138,8 +137,7 @@ class Domain extends Base_Model { public function get_domain() { return $this->domain; - - } // end get_domain; + } /** * Sets the domain of this model object; @@ -152,8 +150,7 @@ class Domain extends Base_Model { public function set_domain($domain) { $this->domain = strtolower($domain); - - } // end set_domain; + } /** * Gets the URL with schema and all. * @@ -166,8 +163,7 @@ class Domain extends Base_Model { $schema = $this->is_secure() ? 'https://' : 'http://'; return sprintf('%s%s/%s', $schema, $this->get_domain(), $path); - - } // end get_url; + } /** * Get the ID of the corresponding site. @@ -179,8 +175,7 @@ class Domain extends Base_Model { public function get_blog_id() { return (int) $this->blog_id; - - } // end get_blog_id; + } /** * Sets the blog_id of this model object; @@ -193,8 +188,7 @@ class Domain extends Base_Model { public function set_blog_id($blog_id) { $this->blog_id = $blog_id; - - } // end set_blog_id; + } /** * Get the ID of the corresponding site. @@ -205,15 +199,14 @@ class Domain extends Base_Model { public function get_site_id() { return $this->get_blog_id(); - - } // end get_site_id; - /** - * Get the site object for this particular mapping. - * - * @since 2.0.0 - * @return \WP_Site|\WP_Ultimo\Models\Site|false - */ - public function get_site() { + } + /** + * Get the site object for this particular mapping. + * + * @since 2.0.0 + * @return \WP_Site|\WP_Ultimo\Models\Site|false + */ + public function get_site() { /** * In a domain mapping environment, the user is not yet logged in. @@ -222,15 +215,12 @@ class Domain extends Base_Model { * * To bypass this limitation, we use the default WordPress function on those cases. */ - if (!function_exists('current_user_can')) { - + if ( ! function_exists('current_user_can')) { return \WP_Site::get_instance($this->get_blog_id()); - - } // end if; + } return wu_get_site($this->get_blog_id()); - - } // end get_site; + } /** * Check if this particular mapping is active. @@ -241,14 +231,11 @@ class Domain extends Base_Model { public function is_active() { if ($this->has_inactive_stage()) { - return false; - - } // end if; + } return (bool) $this->active; - - } // end is_active; + } /** * Sets the active state of this model object; @@ -261,8 +248,7 @@ class Domain extends Base_Model { public function set_active($active) { $this->active = $active; - - } // end set_active; + } /** * Check if this is a primary domain. @@ -273,8 +259,7 @@ class Domain extends Base_Model { public function is_primary_domain() { return (bool) $this->primary_domain; - - } // end is_primary_domain; + } /** * Sets the primary_domain state of this model object; @@ -287,8 +272,7 @@ class Domain extends Base_Model { public function set_primary_domain($primary_domain) { $this->primary_domain = $primary_domain; - - } // end set_primary_domain; + } /** * Check if we should use this domain securely (via HTTPS). @@ -299,8 +283,7 @@ class Domain extends Base_Model { public function is_secure() { return (bool) $this->secure; - - } // end is_secure; + } /** * Sets the secure state of this model object; @@ -313,8 +296,7 @@ class Domain extends Base_Model { public function set_secure($secure) { $this->secure = $secure; - - } // end set_secure; + } /** * Get the stage in which this domain is in at the moment. @@ -327,8 +309,7 @@ class Domain extends Base_Model { public function get_stage() { return $this->stage; - - } // end get_stage; + } /** * Sets the stage of this model object; @@ -341,8 +322,7 @@ class Domain extends Base_Model { public function set_stage($stage) { $this->stage = $stage; - - } // end set_stage; + } /** * Check if this domain is on a inactive stage. * @@ -351,8 +331,7 @@ class Domain extends Base_Model { public function has_inactive_stage(): bool { return in_array($this->get_stage(), self::INACTIVE_STAGES, true); - - } // end has_inactive_stage; + } /** * Returns the Label for a given stage level. @@ -365,8 +344,7 @@ class Domain extends Base_Model { $type = new Domain_Stage($this->get_stage()); return $type->get_label(); - - } // end get_stage_label; + } /** * Gets the classes for a given stage level. @@ -379,8 +357,7 @@ class Domain extends Base_Model { $type = new Domain_Stage($this->get_stage()); return $type->get_classes(); - - } // end get_stage_class; + } /** * Get date when this was created. @@ -391,8 +368,7 @@ class Domain extends Base_Model { public function get_date_created() { return $this->date_created; - - } // end get_date_created; + } /** * Set date when this was created. @@ -404,8 +380,7 @@ class Domain extends Base_Model { public function set_date_created($date_created) { $this->date_created = $date_created; - - } // end set_date_created; + } /** * Check if the domain is correctly set-up in terms of DNS resolution. @@ -426,16 +401,12 @@ class Domain extends Base_Model { $domains_and_ips = array_column($results, 'data'); if (in_array($current_site->domain, $domains_and_ips, true)) { - return true; - - } // end if; + } if (in_array($network_ip_address, $domains_and_ips, true)) { - return true; - - } // end if; + } $result = false; @@ -451,8 +422,7 @@ class Domain extends Base_Model { $result = apply_filters('wu_domain_has_correct_dns', $result, $this, $domains_and_ips); return $result; - - } // end has_correct_dns; + } /** * Checks if the current domain has a valid SSL certificate that covers it. @@ -463,8 +433,7 @@ class Domain extends Base_Model { public function has_valid_ssl_certificate() { return Helper::has_valid_ssl_certificate($this->get_domain()); - - } // end has_valid_ssl_certificate; + } /** * Save (create or update) the model on the database. @@ -485,11 +454,8 @@ class Domain extends Base_Model { $results = parent::save(); if (is_wp_error($results) === false) { - if ($new_domain) { - if (has_action('mercator.mapping.created')) { - $deprecated_args = array( $this, ); @@ -503,13 +469,8 @@ class Domain extends Base_Model { * @return void. */ do_action_deprecated('mercator.mapping.created', $deprecated_args, '2.0.0', 'wu_domain_post_save'); - - } // end if; - - } else { - - if (has_action('mercator.mapping.updated')) { - + } + } elseif (has_action('mercator.mapping.updated')) { $deprecated_args = array( $this, $before_changes, @@ -524,10 +485,7 @@ class Domain extends Base_Model { * @return void. */ do_action_deprecated('mercator.mapping.updated', $deprecated_args, '2.0.0', 'wu_domain_post_save'); - - } // end if; - - } // end if; + } /* * Resets cache. @@ -536,24 +494,21 @@ class Domain extends Base_Model { * after a change is made. */ wp_cache_flush(); - - } // end if; + } return $results; - - } // end save; - /** - * Delete the model from the database. - * - * @since 2.0.0 - * @return \WP_Error|bool - */ - public function delete() { + } + /** + * Delete the model from the database. + * + * @since 2.0.0 + * @return \WP_Error|bool + */ + public function delete() { $results = parent::delete(); if (is_wp_error($results) === false && has_action('mercator.mapping.deleted')) { - $deprecated_args = array( $this, ); @@ -566,8 +521,7 @@ class Domain extends Base_Model { * @return void. */ do_action_deprecated('mercator.mapping.deleted', $deprecated_args, '2.0.0', 'wu_domain_post_delete'); - - } // end if; + } /* * Delete log file. @@ -577,8 +531,7 @@ class Domain extends Base_Model { wu_log_add("domain-{$this->get_domain()}", __('Domain deleted and logs cleared...', 'wp-ultimo')); return $results; - - } // end delete; + } /** * Get mapping by site ID @@ -594,16 +547,12 @@ class Domain extends Base_Model { // Allow passing a site object in if (is_object($site) && isset($site->blog_id)) { - $site = $site->blog_id; + } - } // end if; - - if (!is_numeric($site)) { - + if ( ! is_numeric($site)) { return new \WP_Error('wu_domain_mapping_invalid_id'); - - } // end if; + } $site = absint($site); @@ -611,16 +560,12 @@ class Domain extends Base_Model { $mappings = wp_cache_get('id:' . $site, 'domain_mapping'); if ($mappings === 'none') { - return false; + } - } // end if; - - if (!empty($mappings)) { - + if ( ! empty($mappings)) { return static::to_instances($mappings); - - } // end if; + } // Cache missed, fetch from DB // Suppress errors in case the table doesn't exist @@ -632,19 +577,16 @@ class Domain extends Base_Model { $wpdb->suppress_errors($suppress); - if (!$mappings) { - + if ( ! $mappings) { wp_cache_set('id:' . $site, 'none', 'domain_mapping'); return false; - - } // end if; + } wp_cache_set('id:' . $site, $mappings, 'domain_mapping'); return static::to_instances($mappings); - - } // end get_by_site; + } /** * Gets mappings by domain names @@ -666,28 +608,21 @@ class Domain extends Base_Model { $not_exists = 0; foreach ($domains as $domain) { - $data = wp_cache_get('domain:' . $domain, 'domain_mappings'); - if (!empty($data) && $data !== 'notexists') { - + if ( ! empty($data) && $data !== 'notexists') { return new static($data); - } elseif ($data === 'notexists') { - - $not_exists++; - - } // end if; - - } // end foreach; + ++$not_exists; + } + } if ($not_exists === count($domains)) { // Every domain we checked was found in the cache, but doesn't exist // so skip the query return null; - - } // end if; + } $placeholders = array_fill(0, count($domains), '%s'); @@ -709,19 +644,14 @@ class Domain extends Base_Model { // Cache that it doesn't exist foreach ($domains as $domain) { - wp_cache_set('domain:' . $domain, 'notexists', 'domain_mappings'); - - } // end foreach; + } return null; - - } // end if; + } wp_cache_set('domain:' . $mapping->domain, $mapping, 'domain_mappings'); return new static($mapping); - - } // end get_by_domain; - -} // end class Domain; + } +} diff --git a/inc/models/class-email.php b/inc/models/class-email.php index 02aa270..4d01f14 100644 --- a/inc/models/class-email.php +++ b/inc/models/class-email.php @@ -160,8 +160,7 @@ class Email extends Post_Base_Model { 'active' => 'default:1', 'legacy' => 'boolean|default:0', ); - - } // end validation_rules; + } /** * Get event of the email @@ -172,14 +171,11 @@ class Email extends Post_Base_Model { public function get_event() { if ($this->event === null) { - $this->event = $this->get_meta('wu_system_email_event'); - - } // end if; + } return $this->event; - - } // end get_event; + } /** * Get title of the email @@ -190,8 +186,7 @@ class Email extends Post_Base_Model { public function get_title() { return $this->title; - - } // end get_title; + } /** * Get title of the email using get_name @@ -202,8 +197,7 @@ class Email extends Post_Base_Model { public function get_name() { return $this->title; - - } // end get_name; + } /** * Get style of the email * @@ -215,10 +209,8 @@ class Email extends Post_Base_Model { $this->style = $this->get_meta('wu_style', 'html'); if ($this->style === 'use_default') { - $this->style = wu_get_setting('email_template_type', 'html'); - - } // end if; + } /* * Do an extra check for old installs @@ -226,14 +218,11 @@ class Email extends Post_Base_Model { * properly installed. */ if (empty($this->style)) { - $this->style = 'html'; - - } // end if; + } return $this->style; - - } // end get_style; + } /** * Set the style. @@ -249,8 +238,7 @@ class Email extends Post_Base_Model { $this->style = $style; $this->meta['wu_style'] = $this->style; - - } // end set_style; + } /** * Get if the email has a schedule. @@ -261,14 +249,11 @@ class Email extends Post_Base_Model { public function has_schedule() { if ($this->schedule === null) { - $this->schedule = $this->get_meta('wu_schedule', false); - - } // end if; + } return $this->schedule; - - } // end has_schedule; + } /** * Set the email schedule. @@ -282,8 +267,7 @@ class Email extends Post_Base_Model { $this->schedule = $schedule; $this->meta['wu_schedule'] = $schedule; - - } // end set_schedule; + } /** * Set the email schedule. @@ -294,8 +278,7 @@ class Email extends Post_Base_Model { public function get_schedule_type() { return $this->get_meta('system_email_schedule_type', 'days'); - - } // end get_schedule_type; + } /** * Get schedule send in days of the email @@ -306,8 +289,7 @@ class Email extends Post_Base_Model { public function get_send_days() { return $this->get_meta('system_email_send_days', 0); - - } // end get_send_days; + } /** * Get schedule send in hours of the email. @@ -318,8 +300,7 @@ class Email extends Post_Base_Model { public function get_send_hours() { return $this->get_meta('system_email_send_hours', '12:00'); - - } // end get_send_hours; + } /** * Returns a timestamp in the future when this email should be sent. @@ -331,29 +312,22 @@ class Email extends Post_Base_Model { $when_to_send = 0; - if (!$this->has_schedule()) { - + if ( ! $this->has_schedule()) { return $when_to_send; - - } // end if; + } if ($this->get_schedule_type() === 'hours') { - $send_time = explode(':', $this->get_send_hours()); $when_to_send = strtotime('+' . $send_time[0] . ' hours ' . $send_time[1] . ' minutes'); - - } // end if; + } if ($this->get_schedule_type() === 'days') { - $when_to_send = strtotime('+' . $this->get_send_days() . ' days'); - - } // end if; + } return $when_to_send; - - } // end get_when_to_send; + } /** * Get email slug. @@ -364,8 +338,7 @@ class Email extends Post_Base_Model { public function get_slug() { return $this->slug; - - } // end get_slug; + } /** * Get the custom sender option. @@ -376,8 +349,7 @@ class Email extends Post_Base_Model { public function get_custom_sender() { return $this->get_meta('system_email_custom_sender'); - - } // end get_custom_sender; + } /** * Get the custom sender name. @@ -388,8 +360,7 @@ class Email extends Post_Base_Model { public function get_custom_sender_name() { return $this->get_meta('system_email_custom_sender_name'); - - } // end get_custom_sender_name; + } /** * Get the custom sender email. @@ -400,8 +371,7 @@ class Email extends Post_Base_Model { public function get_custom_sender_email() { return $this->get_meta('system_email_custom_sender_email'); - - } // end get_custom_sender_email; + } /** * Adds checks to prevent saving the model with the wrong type. @@ -413,15 +383,12 @@ class Email extends Post_Base_Model { */ public function set_type($type) { - if (!in_array($type, $this->allowed_types, true)) { - + if ( ! in_array($type, $this->allowed_types, true)) { $type = 'system_email'; - - } // end if; + } $this->type = $type; - - } // end set_type; + } /** * Set the email event. @@ -436,8 +403,7 @@ class Email extends Post_Base_Model { $this->event = $event; $this->meta['wu_system_email_event'] = $event; - - } // end set_event; + } /** * Set if the email is schedule. @@ -450,8 +416,7 @@ class Email extends Post_Base_Model { public function set_email_schedule($email_schedule) { $this->meta['system_email_schedule'] = $email_schedule; - - } // end set_email_schedule; + } /** * Set the schedule date in hours. @@ -464,8 +429,7 @@ class Email extends Post_Base_Model { public function set_send_hours($send_hours) { $this->meta['system_email_send_hours'] = $send_hours; - - } // end set_send_hours; + } /** * Set the schedule date in days. @@ -478,8 +442,7 @@ class Email extends Post_Base_Model { public function set_send_days($send_days) { $this->meta['system_email_send_days'] = $send_days; - - } // end set_send_days; + } /** * Set the schedule type. @@ -493,8 +456,7 @@ class Email extends Post_Base_Model { public function set_schedule_type($schedule_type) { $this->meta['system_email_schedule_type'] = $schedule_type; - - } // end set_schedule_type; + } /** * Set title using the name parameter. @@ -507,8 +469,7 @@ class Email extends Post_Base_Model { public function set_name($name) { $this->set_title($name); - - } // end set_name; + } /** * Set the slug. @@ -521,8 +482,7 @@ class Email extends Post_Base_Model { public function set_slug($slug) { $this->slug = $slug; - - } // end set_slug; + } /** * Set the custom sender. @@ -535,8 +495,7 @@ class Email extends Post_Base_Model { public function set_custom_sender($custom_sender) { $this->meta['system_email_custom_sender'] = $custom_sender; - - } // end set_custom_sender; + } /** * Set the custom sender name. @@ -549,8 +508,7 @@ class Email extends Post_Base_Model { public function set_custom_sender_name($custom_sender_name) { $this->meta['system_email_custom_sender_name'] = $custom_sender_name; - - } // end set_custom_sender_name; + } /** * Set the custom sender email. @@ -563,8 +521,7 @@ class Email extends Post_Base_Model { public function set_custom_sender_email($custom_sender_email) { $this->meta['system_email_custom_sender_email'] = $custom_sender_email; - - } // end set_custom_sender_email; + } /** * Get if we should send this to a customer or to the network admin. @@ -575,14 +532,11 @@ class Email extends Post_Base_Model { public function get_target() { if ($this->target === null) { - $this->target = $this->get_meta('wu_target', 'admin'); - - } // end if; + } return $this->target; - - } // end get_target; + } /** * Set if we should send this to a customer or to the network admin. @@ -597,8 +551,7 @@ class Email extends Post_Base_Model { $this->target = $target; $this->meta['wu_target'] = $target; - - } // end set_target; + } /** * Gets the list of targets for an email. @@ -615,24 +568,17 @@ class Email extends Post_Base_Model { $target_type = $this->get_target(); if ($target_type === 'admin') { - $target_list = self::get_super_admin_targets(); - } elseif ($target_type === 'customer') { - - if (!wu_get_isset($payload, 'customer_id')) { - + if ( ! wu_get_isset($payload, 'customer_id')) { return array(); - - } // end if; + } $customer = wu_get_customer($payload['customer_id']); - if (!$customer) { - + if ( ! $customer) { return array(); - - } // end if; + } $target_list[] = array( 'name' => $customer->get_display_name(), @@ -643,18 +589,14 @@ class Email extends Post_Base_Model { * Maybe ad super admins as well. */ if ($this->get_send_copy_to_admin()) { - $admin_targets = self::get_super_admin_targets(); $target_list = array_merge($target_list, $admin_targets); - - } // end if; - - } // end if; + } + } return $target_list; - - } // end get_target_list; + } /** * Returns the list of super admin targets. @@ -669,23 +611,18 @@ class Email extends Post_Base_Model { $super_admins = get_super_admins(); foreach ($super_admins as $super_admin) { - $user = get_user_by('login', $super_admin); if ($user) { - $target_list[] = array( 'name' => $user->display_name, 'email' => $user->user_email, ); - - } // end if; - - } // end foreach; + } + } return $target_list; - - } // end get_super_admin_targets; + } /** * Get if we should send a copy of the email to the admin. @@ -696,14 +633,11 @@ class Email extends Post_Base_Model { public function get_send_copy_to_admin() { if ($this->send_copy_to_admin === null) { - $this->send_copy_to_admin = $this->get_meta('wu_send_copy_to_admin', false); - - } // end if; + } return $this->send_copy_to_admin; - - } // end get_send_copy_to_admin; + } /** * Set if we should send a copy of the email to the admin. @@ -717,8 +651,7 @@ class Email extends Post_Base_Model { $this->send_copy_to_admin = $send_copy_to_admin; $this->meta['wu_send_copy_to_admin'] = $send_copy_to_admin; - - } // end set_send_copy_to_admin; + } /** * Get the active status of an email. @@ -729,14 +662,11 @@ class Email extends Post_Base_Model { public function is_active() { if ($this->active === null) { - $this->active = $this->get_meta('wu_active', true); - - } // end if; + } return $this->active; - - } // end is_active; + } /** * Set the active status of an email. @@ -750,8 +680,7 @@ class Email extends Post_Base_Model { $this->active = $active; $this->meta['wu_active'] = $active; - - } // end set_active; + } /** * Get whether or not this is a legacy email. @@ -762,14 +691,11 @@ class Email extends Post_Base_Model { public function is_legacy() { if ($this->legacy === null) { - $this->legacy = $this->get_meta('wu_legacy', false); - - } // end if; + } return $this->legacy; - - } // end is_legacy; + } /** * Set whether or not this is a legacy email. @@ -783,7 +709,5 @@ class Email extends Post_Base_Model { $this->legacy = $legacy; $this->meta['wu_legacy'] = $legacy; - - } // end set_legacy; - -} // end class Email; + } +} diff --git a/inc/models/class-event.php b/inc/models/class-event.php index 8ad14dd..e8a8f7f 100644 --- a/inc/models/class-event.php +++ b/inc/models/class-event.php @@ -128,10 +128,9 @@ class Event extends Base_Model { 'object_id' => 'integer|default:0', 'author_id' => 'integer|default:0', 'slug' => 'required|alpha_dash', - 'initiator' => 'required|in:system,manual' + 'initiator' => 'required|in:system,manual', ); - - } // end validation_rules; + } /** * Get severity of the problem.. @@ -142,8 +141,7 @@ class Event extends Base_Model { public function get_severity() { return (int) $this->severity; - - } // end get_severity; + } /** * Returns the Label for a given severity level. @@ -154,16 +152,15 @@ class Event extends Base_Model { public function get_severity_label() { $labels = array( - Event::SEVERITY_SUCCESS => __('Success', 'wp-ultimo'), - Event::SEVERITY_NEUTRAL => __('Neutral', 'wp-ultimo'), - Event::SEVERITY_INFO => __('Info', 'wp-ultimo'), - Event::SEVERITY_WARNING => __('Warning', 'wp-ultimo'), - Event::SEVERITY_FATAL => __('Fatal', 'wp-ultimo'), + self::SEVERITY_SUCCESS => __('Success', 'wp-ultimo'), + self::SEVERITY_NEUTRAL => __('Neutral', 'wp-ultimo'), + self::SEVERITY_INFO => __('Info', 'wp-ultimo'), + self::SEVERITY_WARNING => __('Warning', 'wp-ultimo'), + self::SEVERITY_FATAL => __('Fatal', 'wp-ultimo'), ); - return isset($labels[$this->get_severity()]) ? $labels[$this->get_severity()] : __('Note', 'wp-ultimo'); - - } // end get_severity_label; + return isset($labels[ $this->get_severity() ]) ? $labels[ $this->get_severity() ] : __('Note', 'wp-ultimo'); + } /** * Gets the classes for a given severity level. @@ -174,16 +171,15 @@ class Event extends Base_Model { public function get_severity_class() { $classes = array( - Event::SEVERITY_SUCCESS => 'wu-bg-green-200 wu-text-green-700', - Event::SEVERITY_NEUTRAL => 'wu-bg-gray-200 wu-text-gray-700', - Event::SEVERITY_INFO => 'wu-bg-blue-200 wu-text-blue-700', - Event::SEVERITY_WARNING => 'wu-bg-yellow-200 wu-text-yellow-700', - Event::SEVERITY_FATAL => 'wu-bg-red-200 wu-text-red-700', + self::SEVERITY_SUCCESS => 'wu-bg-green-200 wu-text-green-700', + self::SEVERITY_NEUTRAL => 'wu-bg-gray-200 wu-text-gray-700', + self::SEVERITY_INFO => 'wu-bg-blue-200 wu-text-blue-700', + self::SEVERITY_WARNING => 'wu-bg-yellow-200 wu-text-yellow-700', + self::SEVERITY_FATAL => 'wu-bg-red-200 wu-text-red-700', ); - return isset($classes[$this->get_severity()]) ? $classes[$this->get_severity()] : ''; - - } // end get_severity_class; + return isset($classes[ $this->get_severity() ]) ? $classes[ $this->get_severity() ] : ''; + } /** * Set severity of the problem.. @@ -195,8 +191,7 @@ class Event extends Base_Model { public function set_severity($severity) { $this->severity = $severity; - - } // end set_severity; + } /** * Get date when the event was created.. @@ -207,8 +202,7 @@ class Event extends Base_Model { public function get_date_created() { return $this->date_created; - - } // end get_date_created; + } /** * Set date when the event was created.. @@ -220,8 +214,7 @@ class Event extends Base_Model { public function set_date_created($date_created) { $this->date_created = $date_created; - - } // end set_date_created; + } /** * Get payload of the event.. @@ -234,8 +227,7 @@ class Event extends Base_Model { $payload = (array) maybe_unserialize(wp_unslash($this->payload)); return $payload; - - } // end get_payload; + } /** * Set payload of the event.. @@ -247,8 +239,7 @@ class Event extends Base_Model { public function set_payload($payload) { $this->payload = $payload; - - } // end set_payload; + } /** * Get message for the event. @@ -261,8 +252,7 @@ class Event extends Base_Model { $message = self::get_default_system_messages($this->slug); return $this->interpolate_message($message, $this->get_payload()); - - } // end get_message; + } /** * Interpolates the value of a message and its placeholders with the contents of the payload. * @@ -278,16 +268,12 @@ class Event extends Base_Model { $interpolation_keys = array(); foreach ($payload as $key => &$value) { - $interpolation_keys[] = "{{{$key}}}"; if (is_array($value)) { - $value = implode(' → ', wu_array_flatten($value)); - - } // end if; - - } // end foreach; + } + } $interpolation = array_combine($interpolation_keys, $payload); @@ -298,8 +284,7 @@ class Event extends Base_Model { $interpolation['{{object_id}}'] = $this->object_id; return strtr($message, $interpolation); - - } // end interpolate_message; + } /** * Returns the default system messages for events. @@ -319,8 +304,7 @@ class Event extends Base_Model { $default_messages = apply_filters('wu_get_default_system_messages', $default_messages); return wu_get_isset($default_messages, $slug, __('No Message', 'wp-ultimo')); - - } // end get_default_system_messages; + } /** @@ -332,8 +316,7 @@ class Event extends Base_Model { public function get_initiator() { return $this->initiator; - - } // end get_initiator; + } /** * Set by people (admins, customers), saved as 'manual'. @@ -346,8 +329,7 @@ class Event extends Base_Model { public function set_initiator($initiator) { $this->initiator = $initiator; - - } // end set_initiator; + } /** * Get the author of the action, saved as the user_id. @@ -358,8 +340,7 @@ class Event extends Base_Model { public function get_author_id() { return $this->author_id; - - } // end get_author_id; + } /** * Returns the user associated with this author. @@ -370,18 +351,13 @@ class Event extends Base_Model { public function get_author_user() { if ($this->author_id) { - $user = get_user_by('id', $this->author_id); if ($user) { - return $user; - - } // end if; - - } // end if; - - } // end get_author_user; + } + } + } /** * Returns the authors' display name. @@ -394,12 +370,9 @@ class Event extends Base_Model { $user = $this->get_author_user(); if ($user) { - return $user->display_name; - - } // end if; - - } // end get_author_display_name; + } + } /** * Returns the authors' email address. @@ -412,12 +385,9 @@ class Event extends Base_Model { $user = $this->get_author_user(); if ($user) { - return $user->user_email; - - } // end if; - - } // end get_author_email_address; + } + } /** * Set the author of the action, saved as the user_id. @@ -429,8 +399,7 @@ class Event extends Base_Model { public function set_author_id($author_id) { $this->author_id = $author_id; - - } // end set_author_id; + } /** * Get the object of this event. @@ -445,109 +414,91 @@ class Event extends Base_Model { $function_name = "wu_get_{$object_type}"; if (function_exists($function_name)) { - return $function_name($this->get_object_id()); - - } // end if; + } return false; - - } // end get_object; - /** - * Polyfill for the get_object method. - * - * @since 2.0.0 - * @return false|object - */ - public function get_membership() { + } + /** + * Polyfill for the get_object method. + * + * @since 2.0.0 + * @return false|object + */ + public function get_membership() { $object_type = $this->get_object_type(); if ($object_type !== 'membership') { - return false; - - } // end if; + } return $this->get_object(); - - } // end get_membership; - /** - * Polyfill for the get_object method. - * - * @since 2.0.0 - * @return false|object - */ - public function get_product() { + } + /** + * Polyfill for the get_object method. + * + * @since 2.0.0 + * @return false|object + */ + public function get_product() { $object_type = $this->get_object_type(); if ($object_type !== 'product') { - return false; - - } // end if; + } return $this->get_object(); - - } // end get_product; - /** - * Polyfill for the get_object method. - * - * @since 2.0.0 - * @return false|object - */ - public function get_site() { + } + /** + * Polyfill for the get_object method. + * + * @since 2.0.0 + * @return false|object + */ + public function get_site() { $object_type = $this->get_object_type(); if ($object_type !== 'site') { - return false; - - } // end if; + } return $this->get_object(); - - } // end get_site; - /** - * Polyfill for the get_object method. - * - * @since 2.0.0 - * @return false|object - */ - public function get_customer() { + } + /** + * Polyfill for the get_object method. + * + * @since 2.0.0 + * @return false|object + */ + public function get_customer() { $object_type = $this->get_object_type(); if ($object_type !== 'customer') { - return false; - - } // end if; + } return $this->get_object(); - - } // end get_customer; - /** - * Polyfill for the get_object method. - * - * @since 2.0.0 - * @return false|object - */ - public function get_payment() { + } + /** + * Polyfill for the get_object method. + * + * @since 2.0.0 + * @return false|object + */ + public function get_payment() { $object_type = $this->get_object_type(); if ($object_type !== 'payment') { - return false; - - } // end if; + } return $this->get_object(); - - } // end get_payment; + } /** * Get the object type associated with this event. @@ -558,8 +509,7 @@ class Event extends Base_Model { public function get_object_type() { return $this->object_type; - - } // end get_object_type; + } /** * Set the object type associated with this event. @@ -571,8 +521,7 @@ class Event extends Base_Model { public function set_object_type($object_type) { $this->object_type = $object_type; - - } // end set_object_type; + } /** * Get the object type associated with this event. @@ -583,8 +532,7 @@ class Event extends Base_Model { public function get_slug() { return $this->slug; - - } // end get_slug; + } /** * Set the object type associated with this event. @@ -596,8 +544,7 @@ class Event extends Base_Model { public function set_slug($slug) { $this->slug = $slug; - - } // end set_slug; + } /** * Get iD of the related objects.. @@ -608,8 +555,7 @@ class Event extends Base_Model { public function get_object_id() { return $this->object_id; - - } // end get_object_id; + } /** * Set iD of the related objects. @@ -621,8 +567,7 @@ class Event extends Base_Model { public function set_object_id($object_id) { $this->object_id = $object_id; - - } // end set_object_id; + } /** * Transform the object into an assoc array. @@ -645,27 +590,25 @@ class Event extends Base_Model { $array['author'] = array(); if ($this->get_initiator() === 'manual') { - $user = get_user_by('ID', $this->get_author_id()); if ($user) { - $array['author'] = (array) $user->data; unset($array['author']['user_pass']); unset($array['author']['user_activation_key']); - $array['author']['avatar'] = get_avatar_url($this->get_author_id(), array( - 'default' => 'identicon', - )); - - } // end if; - - } // end if; + $array['author']['avatar'] = get_avatar_url( + $this->get_author_id(), + array( + 'default' => 'identicon', + ) + ); + } + } return $array; - - } // end to_array; + } /** * Override to clear event count. @@ -675,16 +618,12 @@ class Event extends Base_Model { */ public function save() { - if (!$this->exists() && function_exists('get_current_user_id')) { - + if ( ! $this->exists() && function_exists('get_current_user_id')) { $user_id = get_current_user_id(); delete_site_transient("wu_{$user_id}_unseen_events_count"); - - } // end if; + } return parent::save(); - - } // end save; - -} // end class Event; + } +} diff --git a/inc/models/class-membership.php b/inc/models/class-membership.php index a10485e..181f85f 100644 --- a/inc/models/class-membership.php +++ b/inc/models/class-membership.php @@ -9,11 +9,11 @@ namespace WP_Ultimo\Models; -use \WP_Ultimo\Models\Base_Model; -use \WP_Ultimo\Models\Product; -use \WP_Ultimo\Models\Site; -use \WP_Ultimo\Database\Memberships\Membership_Status; -use \WP_Ultimo\Checkout\Cart; +use WP_Ultimo\Models\Base_Model; +use WP_Ultimo\Models\Product; +use WP_Ultimo\Models\Site; +use WP_Ultimo\Database\Memberships\Membership_Status; +use WP_Ultimo\Checkout\Cart; // Exit if accessed directly defined('ABSPATH') || exit; @@ -25,7 +25,10 @@ defined('ABSPATH') || exit; */ class Membership extends Base_Model { - use Traits\Limitable, Traits\Billable, Traits\Notable, \WP_Ultimo\Traits\WP_Ultimo_Subscription_Deprecated; + use Traits\Limitable; + use Traits\Billable; + use Traits\Notable; + use \WP_Ultimo\Traits\WP_Ultimo_Subscription_Deprecated; /** * ID of the customer attached to this membership. @@ -327,12 +330,9 @@ class Membership extends Base_Model { ); if (did_action('plugins_loaded')) { - $this->_compiled_product_list = $this->get_all_products(); - - } // end if; - - } // end __construct; + } + } /** * Set the validation rules for this particular model. @@ -372,8 +372,7 @@ class Membership extends Base_Model { 'disabled' => 'default:0', 'recurring' => 'default:0', ); - - } // end validation_rules; + } /** * Gets the customer object associated with this membership. @@ -385,8 +384,7 @@ class Membership extends Base_Model { public function get_customer() { return wu_get_customer($this->get_customer_id()); - - } // end get_customer; + } /** * Get the value of customer_id. @@ -397,8 +395,7 @@ class Membership extends Base_Model { public function get_customer_id() { return absint($this->customer_id); - - } // end get_customer_id; + } /** * Set the value of customer_id. @@ -410,8 +407,7 @@ class Membership extends Base_Model { public function set_customer_id($customer_id) { $this->customer_id = absint($customer_id); - - } // end set_customer_id; + } /** * Checks if a given customer should have access to this site options. @@ -424,24 +420,19 @@ class Membership extends Base_Model { public function is_customer_allowed($customer_id = false) { if (current_user_can('manage_network')) { - return true; + } - } // end if; - - if (!$customer_id) { - + if ( ! $customer_id) { $customer = WP_Ultimo()->currents->get_customer(); $customer_id = $customer ? $customer->get_id() : 0; - - } // end if; + } $allowed = absint($customer_id) === absint($this->get_customer_id()); return apply_filters('wu_membership_is_customer_allowed', $allowed, $customer_id, $this); - - } // end is_customer_allowed; + } /** * Get the value of user_id. @@ -452,8 +443,7 @@ class Membership extends Base_Model { public function get_user_id() { return $this->user_id; - - } // end get_user_id; + } /** * Set the value of user_id. @@ -465,8 +455,7 @@ class Membership extends Base_Model { public function set_user_id($user_id) { $this->user_id = absint($user_id); - - } // end set_user_id; + } /** * Get the value of plan_id. @@ -477,8 +466,7 @@ class Membership extends Base_Model { public function get_plan_id() { return (int) $this->plan_id; - - } // end get_plan_id; + } /** * Returns the plan that created this membership. @@ -492,16 +480,13 @@ class Membership extends Base_Model { // Get the correct ariation if exists if ($plan && ($plan->get_duration() !== $this->get_duration() || $plan->get_duration_unit() !== $this->get_duration_unit())) { - $variation = $plan->get_as_variation($this->get_duration(), $this->get_duration_unit()); $plan = ($variation ? $variation : null) ?? $plan; - - } // end if; + } return $plan; - - } // end get_plan; + } /** * Set plan associated with the membership. @@ -513,8 +498,7 @@ class Membership extends Base_Model { public function set_plan_id($plan_id) { $this->plan_id = absint($plan_id); - - } // end set_plan_id; + } /** * Checks if this membership has a plan. @@ -524,9 +508,8 @@ class Membership extends Base_Model { */ public function has_plan() { - return !empty($this->get_plan()); - - } // end has_plan; + return ! empty($this->get_plan()); + } /** * Get additional product objects. @@ -539,8 +522,7 @@ class Membership extends Base_Model { $addons = array_map('wu_get_product', $this->get_addon_ids()); return array_filter($addons); - - } // end get_addons; + } /** * Checks if the given membership has addon products. @@ -550,9 +532,8 @@ class Membership extends Base_Model { */ public function has_addons() { - return !empty($this->get_addons()); - - } // end has_addons; + return ! empty($this->get_addons()); + } /** * Gets a list of product ids for addons. * @@ -561,8 +542,7 @@ class Membership extends Base_Model { public function get_addon_ids(): array { return array_map('absint', array_keys((array) $this->addon_products)); - - } // end get_addon_ids; + } /** * Adds an an addon product from this membership. @@ -577,23 +557,16 @@ class Membership extends Base_Model { $has_product = wu_get_isset($this->addon_products, $product_id); - if ($has_product && $this->addon_products[$product_id] >= 0) { - - $this->addon_products[$product_id] = $this->addon_products[$product_id] + $quantity; - + if ($has_product && $this->addon_products[ $product_id ] >= 0) { + $this->addon_products[ $product_id ] = $this->addon_products[ $product_id ] + $quantity; } else { + $this->addon_products[ $product_id ] = $quantity; + } - $this->addon_products[$product_id] = $quantity; - - } // end if; - - if ($this->addon_products[$product_id] <= 0) { - - unset($this->addon_products[$product_id]); - - } // end if; - - } // end add_product; + if ($this->addon_products[ $product_id ] <= 0) { + unset($this->addon_products[ $product_id ]); + } + } /** * Removes a product from the membership. @@ -608,19 +581,14 @@ class Membership extends Base_Model { $has_product = wu_get_isset($this->addon_products, $product_id); - if ($has_product && $this->addon_products[$product_id] >= 0) { + if ($has_product && $this->addon_products[ $product_id ] >= 0) { + $this->addon_products[ $product_id ] = $this->addon_products[ $product_id ] - $quantity; + } - $this->addon_products[$product_id] = $this->addon_products[$product_id] - $quantity; - - } // end if; - - if ($this->addon_products[$product_id] <= 0) { - - unset($this->addon_products[$product_id]); - - } // end if; - - } // end remove_product; + if ($this->addon_products[ $product_id ] <= 0) { + unset($this->addon_products[ $product_id ]); + } + } /** * Get additional products. Services and Packages. @@ -635,25 +603,20 @@ class Membership extends Base_Model { $this->addon_products = is_array($this->addon_products) ? $this->addon_products : array(); foreach ($this->addon_products as $product_id => $quantity) { - $product = wu_get_product($product_id); - if (!$product) { - + if ( ! $product) { continue; - - } // end if; + } $products[] = array( 'quantity' => $quantity, 'product' => $product, ); - - } // end foreach; + } return $products; - - } // end get_addon_products; + } /** * Returns a list with all products, including the plan. @@ -671,8 +634,7 @@ class Membership extends Base_Model { ); return array_merge($products, $this->get_addon_products()); - - } // end get_all_products; + } /** * Set additional products. Services and Packages. @@ -684,8 +646,7 @@ class Membership extends Base_Model { public function set_addon_products($addon_products) { $this->addon_products = maybe_unserialize($addon_products); - - } // end set_addon_products; + } /** * Changes the membership products and totals. @@ -707,11 +668,9 @@ class Membership extends Base_Model { */ public function swap($order) { - if (!is_a($order, Cart::class)) { - + if ( ! is_a($order, Cart::class)) { return new \WP_Error('invalid-date', __('Swap Cart is invalid.', 'wp-ultimo')); - - } // end if; + } // clear the current addons. $this->addon_products = array(); @@ -723,17 +682,14 @@ class Membership extends Base_Model { * as product ID. */ foreach ($order->get_line_items() as $line_item) { - $product = $line_item->get_product(); /** * We only care about products. */ if (empty($product)) { - continue; - - } // end if; + } /* * Checks if this is a plan. @@ -742,20 +698,17 @@ class Membership extends Base_Model { * plan id. */ if ($product->get_type() === 'plan') { - $this->set_plan_id($product->get_id()); continue; - - } // end if; + } /* * For other products, * we add them as addons. */ $this->add_product($product->get_id(), $line_item->get_quantity()); - - } // end foreach; + } /* * Finally, we have a couple of other parameters to set. @@ -771,36 +724,29 @@ class Membership extends Base_Model { * Returns self for chaining. */ return $this; - - } // end swap; - /** - * Schedule a swap for the membership. - * - * @since 2.0.0 - * - * @param Cart $order The cart representing the change. - * @param string|boolean $schedule_date The date to schedule the change for. - * @return int|\WP_Error - */ - public function schedule_swap($order, $schedule_date = false) { + } + /** + * Schedule a swap for the membership. + * + * @since 2.0.0 + * + * @param Cart $order The cart representing the change. + * @param string|boolean $schedule_date The date to schedule the change for. + * @return int|\WP_Error + */ + public function schedule_swap($order, $schedule_date = false) { if (empty($schedule_date)) { - $schedule_date = $this->get_date_expiration(); + } - } // end if; - - if (!wu_validate_date($schedule_date)) { - + if ( ! wu_validate_date($schedule_date)) { return new \WP_Error('invalid-date', __('Schedule date is invalid.', 'wp-ultimo')); + } - } // end if; - - if (!is_a($order, Cart::class)) { - + if ( ! is_a($order, Cart::class)) { return new \WP_Error('invalid-date', __('Swap Cart is invalid.', 'wp-ultimo')); - - } // end if; + } $date_instance = wu_date($schedule_date); @@ -813,18 +759,26 @@ class Membership extends Base_Model { /* * Remove the previous swaps. */ - wu_unschedule_action('wu_async_membership_swap', array( - 'membership_id' => $this->get_id(), - ), 'membership'); + wu_unschedule_action( + 'wu_async_membership_swap', + array( + 'membership_id' => $this->get_id(), + ), + 'membership' + ); /* * Schedule the swap. */ - return wu_schedule_single_action($date_instance->format('U'), 'wu_async_membership_swap', array( - 'membership_id' => $this->get_id(), - ), 'membership'); - - } // end schedule_swap; + return wu_schedule_single_action( + $date_instance->format('U'), + 'wu_async_membership_swap', + array( + 'membership_id' => $this->get_id(), + ), + 'membership' + ); + } /** * Returns the scheduled swap, if any. @@ -837,21 +791,18 @@ class Membership extends Base_Model { $order = $this->get_meta('wu_swap_order'); $scheduled_date = $this->get_meta('wu_swap_scheduled_date'); - if (!$scheduled_date || !$order) { - + if ( ! $scheduled_date || ! $order) { $this->delete_meta('wu_swap_order'); $this->delete_meta('wu_swap_scheduled_date'); return false; - - } // end if; + } return (object) array( 'order' => $order, 'scheduled_date' => $scheduled_date, ); - - } // end get_scheduled_swap; + } /** * Removes a schedule swap. @@ -866,8 +817,7 @@ class Membership extends Base_Model { $this->delete_meta('wu_swap_scheduled_date'); do_action('wu_membership_delete_scheduled_swap', $this); - - } // end delete_scheduled_swap; + } /** * Returns the amount recurring in a human-friendly way. @@ -885,8 +835,7 @@ class Membership extends Base_Model { ); return $description; - - } // end get_recurring_description; + } /** * Returns the times billed in a human-friendly way. * @@ -901,12 +850,10 @@ class Membership extends Base_Model { // translators: the place holder is the number of times the membership was billed. $description = __('%1$s / until cancelled', 'wp-ultimo'); - - } // end if; + } return sprintf($description, $this->get_times_billed(), $this->get_billing_cycles()); - - } // end get_times_billed_description; + } /** * Returns the membership price structure in a way human can understand it. * @@ -917,7 +864,6 @@ class Membership extends Base_Model { $pricing = array(); if ($this->is_recurring()) { - $duration = $this->get_duration(); $message = sprintf( @@ -930,8 +876,7 @@ class Membership extends Base_Model { $pricing['subscription'] = $message; - if (!$this->is_forever_recurring()) { - + if ( ! $this->is_forever_recurring()) { $billing_cycles_message = sprintf( // translators: %s is the number of billing cycles. _n('for %s cycle', 'for %s cycles', $this->get_billing_cycles(), 'wp-ultimo'), @@ -939,28 +884,21 @@ class Membership extends Base_Model { ); $pricing['subscription'] .= ' ' . $billing_cycles_message; - - } // end if; - + } } else { - $pricing['subscription'] = sprintf( // translators: %1$s is the formatted price of the product __('%1$s one time payment', 'wp-ultimo'), wu_format_currency($this->get_initial_amount(), $this->get_currency()) ); - - } // end if; + } if ($this->is_free()) { - $pricing['subscription'] = __('Free!', 'wp-ultimo'); - - } // end if; + } return implode(' + ', $pricing); - - } // end get_price_description; + } /** * Get the value of currency. @@ -972,8 +910,7 @@ class Membership extends Base_Model { // return $this->currency; For now, multi-currency is not yet supported. return wu_get_setting('currency_symbol', 'USD'); - - } // end get_currency; + } /** * Set the value of currency. @@ -985,8 +922,7 @@ class Membership extends Base_Model { public function set_currency($currency) { $this->currency = $currency; - - } // end set_currency; + } /** * Get time interval between charges. @@ -996,8 +932,7 @@ class Membership extends Base_Model { public function get_duration() { return absint($this->duration); - - } // end get_duration; + } /** * Set time interval between charges. @@ -1007,8 +942,7 @@ class Membership extends Base_Model { public function set_duration($duration) { $this->duration = absint($duration); - - } // end set_duration; + } /** * Get time interval unit between charges. @@ -1018,8 +952,7 @@ class Membership extends Base_Model { public function get_duration_unit() { return $this->duration_unit; - - } // end get_duration_unit; + } /** * Set time interval unit between charges. @@ -1029,8 +962,7 @@ class Membership extends Base_Model { public function set_duration_unit($duration_unit) { $this->duration_unit = $duration_unit; - - } // end set_duration_unit; + } /** * Get the product amount. @@ -1040,8 +972,7 @@ class Membership extends Base_Model { public function get_amount() { return $this->amount; - - } // end get_amount; + } /** * Get normalized amount. This is used to calculate MRR> @@ -1054,18 +985,15 @@ class Membership extends Base_Model { $amount = $this->get_amount(); if ($this->is_recurring()) { - return $amount; - - } // end if; + } $duration = $this->get_duration(); $normalized_duration_unit = wu_convert_duration_unit_to_month($this->get_duration_unit()); return $amount / $duration * $normalized_duration_unit; - - } // end get_normalized_amount; + } /** * Set the product amount. @@ -1075,8 +1003,7 @@ class Membership extends Base_Model { public function set_amount($amount) { $this->amount = wu_to_float($amount); - - } // end set_amount; + } /** * Get the product setup fee. @@ -1086,8 +1013,7 @@ class Membership extends Base_Model { public function get_initial_amount() { return $this->initial_amount; - - } // end get_initial_amount; + } /** * Set the product setup fee. @@ -1097,8 +1023,7 @@ class Membership extends Base_Model { public function set_initial_amount($initial_amount) { $this->initial_amount = wu_to_float($initial_amount); - - } // end set_initial_amount; + } /** * Get the value of date_created. @@ -1109,8 +1034,7 @@ class Membership extends Base_Model { public function get_date_created() { return $this->date_created; - - } // end get_date_created; + } /** * Set the value of date_created. @@ -1122,8 +1046,7 @@ class Membership extends Base_Model { public function set_date_created($date_created) { $this->date_created = $date_created; - - } // end set_date_created; + } /** * Get the value of date_activated. @@ -1134,8 +1057,7 @@ class Membership extends Base_Model { public function get_date_activated() { return $this->date_activated; - - } // end get_date_activated; + } /** * Set the value of date_activated. @@ -1147,8 +1069,7 @@ class Membership extends Base_Model { public function set_date_activated($date_activated) { $this->date_activated = $date_activated; - - } // end set_date_activated; + } /** * Get the value of date_trial_end. @@ -1159,8 +1080,7 @@ class Membership extends Base_Model { public function get_date_trial_end() { return $this->date_trial_end; - - } // end get_date_trial_end; + } /** * Set the value of date_trial_end. @@ -1172,8 +1092,7 @@ class Membership extends Base_Model { public function set_date_trial_end($date_trial_end) { $this->date_trial_end = $date_trial_end; - - } // end set_date_trial_end; + } /** * Get the value of date_renewed. @@ -1184,8 +1103,7 @@ class Membership extends Base_Model { public function get_date_renewed() { return $this->date_renewed; - - } // end get_date_renewed; + } /** * Set the value of date_renewed. @@ -1197,8 +1115,7 @@ class Membership extends Base_Model { public function set_date_renewed($date_renewed) { $this->date_renewed = $date_renewed; - - } // end set_date_renewed; + } /** * Get the value of date_cancellation. @@ -1209,8 +1126,7 @@ class Membership extends Base_Model { public function get_date_cancellation() { return $this->date_cancellation; - - } // end get_date_cancellation; + } /** * Set the value of date_cancellation. @@ -1222,8 +1138,7 @@ class Membership extends Base_Model { public function set_date_cancellation($date_cancellation) { $this->date_cancellation = $date_cancellation; - - } // end set_date_cancellation; + } /** * Get the cancellation reason @@ -1234,20 +1149,15 @@ class Membership extends Base_Model { public function get_cancellation_reason() { if ($this->get_status() !== Membership_Status::CANCELLED) { - return ''; - - } // end if;)) + })) if ($this->cancellation_reason === null) { - $this->cancellation_reason = $this->get_meta('cancellation_reason'); - - } // end if; + } return (string) $this->cancellation_reason; - - } // end get_cancellation_reason; + } /** * Set the reason to cancel the membership. @@ -1260,8 +1170,7 @@ class Membership extends Base_Model { $this->meta['cancellation_reason'] = $reason; $this->cancellation_reason = $reason; - - } // end set_cancellation_reason; + } /** * Get the value of date_expiration. @@ -1272,8 +1181,7 @@ class Membership extends Base_Model { public function get_date_expiration() { return $this->date_expiration; - - } // end get_date_expiration; + } /** * Set the value of date_expiration. @@ -1285,8 +1193,7 @@ class Membership extends Base_Model { public function set_date_expiration($date_expiration) { $this->date_expiration = $date_expiration; - - } // end set_date_expiration; + } /** * Calculate a new expiration date. @@ -1303,72 +1210,52 @@ class Membership extends Base_Model { $expiration = $this->get_date_expiration(); $expiration_timestamp = 0; - if (!$this->is_recurring()) { - + if ( ! $this->is_recurring()) { return null; - - } // end if; + } if (wu_validate_date($expiration)) { - $expiration_timestamp = wu_date($expiration)->format('U'); - - } // end if; + } // Determine what date to use as the start for the new expiration calculation if (!$from_today && $expiration_timestamp > wu_get_current_time('timestamp', true)) { // phpcs:ignore $base_timestamp = $expiration_timestamp; - } else { - $base_timestamp = wu_get_current_time('timestamp', true); // phpcs:ignore - - } // end if; + } if ($this->get_duration() > 0) { - if (false && $this->trial_duration > 0 && $trial) { - $expire_timestamp = strtotime('+' . $this->get_trial_duration() . ' ' . $this->trial_duration_unit . ' 23:59:59', $base_timestamp); - } else { - $expire_timestamp = strtotime('+' . $this->get_duration() . ' ' . $this->get_duration_unit() . ' 23:59:59', $base_timestamp); - - } // end if; + } $extension_days = array('29', '30', '31'); if (in_array(gmdate('j', $expire_timestamp), $extension_days, true) && 'month' === $this->get_duration_unit()) { - $month = gmdate('n', $expire_timestamp); if ($month < 12) { - $month += 1; $year = gmdate('Y', $expire_timestamp); - } else { - $month = 1; - $year = gmdate('Y', $expire_timestamp ) + 1; - - } // end if; + $year = gmdate('Y', $expire_timestamp) + 1; + } $expire_timestamp = mktime(0, 0, 0, $month, 1, $year); - - } // end if; + } $expiration = gmdate('Y-m-d 23:59:59', $expire_timestamp); - } else { - $expiration = null; // tag as lifetime. - } // end if; + } /** * Filters the calculated expiration date. @@ -1382,8 +1269,7 @@ class Membership extends Base_Model { $expiration = apply_filters('wu_membership_calculated_date_expiration', $expiration, $this->get_id(), $this); return $expiration; - - } // end calculate_expiration; + } /** * Get the value of date_payment_plan_completed. @@ -1394,8 +1280,7 @@ class Membership extends Base_Model { public function get_date_payment_plan_completed() { return $this->date_payment_plan_completed; - - } // end get_date_payment_plan_completed; + } /** * Set the value of date_payment_plan_completed. @@ -1407,8 +1292,7 @@ class Membership extends Base_Model { public function set_date_payment_plan_completed($date_payment_plan_completed) { $this->date_payment_plan_completed = $date_payment_plan_completed; - - } // end set_date_payment_plan_completed; + } /** * Get the value of auto_renew. @@ -1419,8 +1303,7 @@ class Membership extends Base_Model { public function should_auto_renew() { return (bool) $this->auto_renew; - - } // end should_auto_renew; + } /** * Deprecated: get_auto_renew @@ -1433,8 +1316,7 @@ class Membership extends Base_Model { _deprecated_function(__METHOD__, '2.0.0', 'should_auto_renew()'); return $this->should_auto_renew(); - - } // end get_auto_renew; + } /** * Set the value of auto_renew. @@ -1446,53 +1328,45 @@ class Membership extends Base_Model { public function set_auto_renew($auto_renew) { $this->auto_renew = (bool) $auto_renew; - - } // end set_auto_renew; - /** - * Get the discount code applied if exist. - * - * @since 2.0.20 - * @return \WP_Ultimo\Models\Discount_Code|false - */ - public function get_discount_code() { + } + /** + * Get the discount code applied if exist. + * + * @since 2.0.20 + * @return \WP_Ultimo\Models\Discount_Code|false + */ + public function get_discount_code() { if ($this->discount_code === null) { - $this->discount_code = $this->get_meta('discount_code'); - - } // end if; + } // Get discount code from original payment for compatibility - if (empty($this->discount_code) && !$this->get_meta('verified_payment_discount')) { - - $original_payment = wu_get_payments(array( - 'number' => 1, - 'membership_id' => $this->get_id(), - 'orderby' => 'id', - 'order' => 'ASC', - )); + if (empty($this->discount_code) && ! $this->get_meta('verified_payment_discount')) { + $original_payment = wu_get_payments( + array( + 'number' => 1, + 'membership_id' => $this->get_id(), + 'orderby' => 'id', + 'order' => 'ASC', + ) + ); if (isset($original_payment[0])) { - $original_cart = $original_payment[0]->get_meta('wu_original_cart'); $this->discount_code = $original_cart ? $original_cart->get_discount_code() : false; if ($this->discount_code) { - $this->update_meta('discount_code', $this->discount_code); - - } // end if; - - } // end if; + } + } $this->update_meta('verified_payment_discount', true); - - } // end if; + } return $this->discount_code; - - } // end get_discount_code; + } /** * Set the value of discount_code. @@ -1504,26 +1378,21 @@ class Membership extends Base_Model { public function set_discount_code($discount_code) { if (is_a($discount_code, '\WP_Ultimo\Models\Discount_Code')) { - $this->meta['discount_code'] = $discount_code; $this->discount_code = $discount_code; return; - - } // end if; + } $discount_code = wu_get_discount_code_by_code($discount_code); - if (!$discount_code) { - + if ( ! $discount_code) { return; - - } // end if; + } $this->meta['discount_code'] = $discount_code; $this->discount_code = $discount_code; - - } // end set_discount_code; + } /** * Get the value of times_billed. @@ -1534,8 +1403,7 @@ class Membership extends Base_Model { public function get_times_billed() { return (int) $this->times_billed; - - } // end get_times_billed; + } /** * Set the value of times_billed. @@ -1547,8 +1415,7 @@ class Membership extends Base_Model { public function set_times_billed($times_billed) { $this->times_billed = $times_billed; - - } // end set_times_billed; + } /** * Increments times billed. @@ -1565,8 +1432,7 @@ class Membership extends Base_Model { $this->set_times_billed(($times_billed + $number)); return $this; - - } // end add_to_times_billed; + } /** * Get the value of billing_cycles. @@ -1577,8 +1443,7 @@ class Membership extends Base_Model { public function get_billing_cycles() { return $this->billing_cycles; - - } // end get_billing_cycles; + } /** * Checks if this product recurs forever. @@ -1589,8 +1454,7 @@ class Membership extends Base_Model { public function is_forever_recurring() { return empty($this->get_billing_cycles()); - - } // end is_forever_recurring; + } /** * Checks if we are on the max renewals. @@ -1600,18 +1464,15 @@ class Membership extends Base_Model { */ public function at_maximum_renewals() { - if (!$this->is_forever_recurring()) { - + if ( ! $this->is_forever_recurring()) { return false; - - } // end if; + } $times_billed = $this->get_times_billed() - 1; // Subtract 1 to exclude initial payment. $renew_times = $this->get_billing_cycles(); return $times_billed >= $renew_times; - - } // end at_maximum_renewals; + } /** * Set the value of billing_cycles. @@ -1623,8 +1484,7 @@ class Membership extends Base_Model { public function set_billing_cycles($billing_cycles) { $this->billing_cycles = $billing_cycles; - - } // end set_billing_cycles; + } /** * Returns the default billing address. @@ -1642,14 +1502,11 @@ class Membership extends Base_Model { $customer = $this->get_customer(); if ($customer) { - return $customer->get_billing_address(); - - } // end if; + } return $billing_address; - - } // end get_default_billing_address; + } /** * Checks if the current membership has a active status. @@ -1667,8 +1524,7 @@ class Membership extends Base_Model { $active = in_array($this->status, $active_statuses, true); return apply_filters('wu_membership_is_active', $active, $this); - - } // end is_active; + } /** * Get the value of status. @@ -1679,8 +1535,7 @@ class Membership extends Base_Model { public function get_status() { return $this->status; - - } // end get_status; + } /** * Set the value of status. @@ -1693,8 +1548,7 @@ class Membership extends Base_Model { public function set_status($status) { $this->status = $status; - - } // end set_status; + } /** * Returns the Label for a given severity level. @@ -1707,8 +1561,7 @@ class Membership extends Base_Model { $status = new Membership_Status($this->get_status()); return $status->get_label(); - - } // end get_status_label; + } /** * Gets the classes for a given class. @@ -1721,8 +1574,7 @@ class Membership extends Base_Model { $status = new Membership_Status($this->get_status()); return $status->get_classes(); - - } // end get_status_class; + } /** * Get the value of gateway_customer_id. @@ -1733,8 +1585,7 @@ class Membership extends Base_Model { public function get_gateway_customer_id() { return $this->gateway_customer_id; - - } // end get_gateway_customer_id; + } /** * Set the value of gateway_customer_id. @@ -1746,8 +1597,7 @@ class Membership extends Base_Model { public function set_gateway_customer_id($gateway_customer_id) { $this->gateway_customer_id = $gateway_customer_id; - - } // end set_gateway_customer_id; + } /** * Get the value of gateway_subscription_id. @@ -1758,8 +1608,7 @@ class Membership extends Base_Model { public function get_gateway_subscription_id() { return $this->gateway_subscription_id; - - } // end get_gateway_subscription_id; + } /** * Set the value of gateway_subscription_id. @@ -1771,8 +1620,7 @@ class Membership extends Base_Model { public function set_gateway_subscription_id($gateway_subscription_id) { $this->gateway_subscription_id = $gateway_subscription_id; - - } // end set_gateway_subscription_id; + } /** * Get the value of gateway. @@ -1783,8 +1631,7 @@ class Membership extends Base_Model { public function get_gateway() { return $this->gateway; - - } // end get_gateway; + } /** * Set the value of gateway. @@ -1796,8 +1643,7 @@ class Membership extends Base_Model { public function set_gateway($gateway) { $this->gateway = $gateway; - - } // end set_gateway; + } /** * Get the value of signup_method. @@ -1808,8 +1654,7 @@ class Membership extends Base_Model { public function get_signup_method() { return $this->signup_method; - - } // end get_signup_method; + } /** * Set the value of signup_method. @@ -1821,8 +1666,7 @@ class Membership extends Base_Model { public function set_signup_method($signup_method) { $this->signup_method = $signup_method; - - } // end set_signup_method; + } /** * Get the value of upgraded_from. @@ -1833,8 +1677,7 @@ class Membership extends Base_Model { public function get_upgraded_from() { return $this->upgraded_from; - - } // end get_upgraded_from; + } /** * Set the value of upgraded_from. @@ -1846,8 +1689,7 @@ class Membership extends Base_Model { public function set_upgraded_from($upgraded_from) { $this->upgraded_from = $upgraded_from; - - } // end set_upgraded_from; + } /** * Get the value of date_modified. @@ -1858,8 +1700,7 @@ class Membership extends Base_Model { public function get_date_modified() { return $this->date_modified; - - } // end get_date_modified; + } /** * Set the value of date_modified. @@ -1871,8 +1712,7 @@ class Membership extends Base_Model { public function set_date_modified($date_modified) { $this->date_modified = $date_modified; - - } // end set_date_modified; + } /** * Get the value of disabled. @@ -1883,8 +1723,7 @@ class Membership extends Base_Model { public function is_disabled() { return (bool) $this->disabled; - - } // end is_disabled; + } /** * Set the value of disabled. @@ -1896,8 +1735,7 @@ class Membership extends Base_Model { public function set_disabled($disabled) { $this->disabled = (bool) $disabled; - - } // end set_disabled; + } /** * Returns a list of payments associated with this membership. @@ -1908,33 +1746,36 @@ class Membership extends Base_Model { */ public function get_payments($query = array()) { - $query = array_merge($query, array( - 'membership_id' => $this->get_id(), - )); + $query = array_merge( + $query, + array( + 'membership_id' => $this->get_id(), + ) + ); return wu_get_payments($query); + } + /** + * Returns the last pending payment for a membership. + * + * @since 2.0.0 + * @return \WP_Ultimo\Models\Payment|false + */ + public function get_last_pending_payment() { - } // end get_payments; - /** - * Returns the last pending payment for a membership. - * - * @since 2.0.0 - * @return \WP_Ultimo\Models\Payment|false - */ - public function get_last_pending_payment() { + $payments = wu_get_payments( + array( + 'membership_id' => $this->get_id(), + 'status' => 'pending', + 'number' => 1, + 'orderby' => 'id', + 'order' => 'DESC', + 'gateway_payment_id' => '', + ) + ); - $payments = wu_get_payments(array( - 'membership_id' => $this->get_id(), - 'status' => 'pending', - 'number' => 1, - 'orderby' => 'id', - 'order' => 'DESC', - 'gateway_payment_id' => '', - )); - - return !empty($payments) ? array_pop($payments) : false; - - } // end get_last_pending_payment; + return ! empty($payments) ? array_pop($payments) : false; + } /** * Returns the published sites attached to this membership. @@ -1944,18 +1785,19 @@ class Membership extends Base_Model { */ public function get_published_sites() { - $sites = Site::query(array( - 'meta_query' => array( - 'customer_id' => array( - 'key' => 'wu_membership_id', - 'value' => $this->get_id(), + $sites = Site::query( + array( + 'meta_query' => array( + 'customer_id' => array( + 'key' => 'wu_membership_id', + 'value' => $this->get_id(), + ), ), - ), - )); + ) + ); return $sites; - - } // end get_published_sites; + } /** * Returns the sites attached to this membership. @@ -1966,28 +1808,27 @@ class Membership extends Base_Model { */ public function get_sites($include_pending = true) { - $sites = Site::query(array( - 'meta_query' => array( - 'customer_id' => array( - 'key' => 'wu_membership_id', - 'value' => $this->get_id(), + $sites = Site::query( + array( + 'meta_query' => array( + 'customer_id' => array( + 'key' => 'wu_membership_id', + 'value' => $this->get_id(), + ), ), - ), - )); + ) + ); $pending_site = $include_pending ? $this->get_pending_site() : false; if ($pending_site) { - $pending_site->set_type('pending'); $sites[] = $pending_site; - - } // end if; + } return $sites; - - } // end get_sites; + } /** * Adds a pending site to the membership meta data. @@ -2001,19 +1842,21 @@ class Membership extends Base_Model { global $current_site; - $site_info = wp_parse_args($site_info, array( - 'title' => '', - 'domain' => $current_site->domain, - 'path' => '', - 'transient' => array(), - 'is_publishing' => false, - )); + $site_info = wp_parse_args( + $site_info, + array( + 'title' => '', + 'domain' => $current_site->domain, + 'path' => '', + 'transient' => array(), + 'is_publishing' => false, + ) + ); $site = new \WP_Ultimo\Models\Site($site_info); return (bool) $this->update_meta('pending_site', $site); - - } // end create_pending_site; + } /** * Updates a pending site to the membership meta data. @@ -2026,19 +1869,17 @@ class Membership extends Base_Model { public function update_pending_site($site) { return $this->update_meta('pending_site', $site); - - } // end update_pending_site; - /** - * Returns the pending site, if any. - * - * @since 2.0.0 - * @return \WP_Ultimo\Models\Site|false - */ - public function get_pending_site() { + } + /** + * Returns the pending site, if any. + * + * @since 2.0.0 + * @return \WP_Ultimo\Models\Site|false + */ + public function get_pending_site() { return $this->get_meta('pending_site'); - - } // end get_pending_site; + } /** * Published a pending site, but via job queue. @@ -2051,12 +1892,10 @@ class Membership extends Base_Model { * If the force sync setting is on, fallback to the sync version. */ if ((bool) wu_get_setting('force_publish_sites_sync', false)) { - $this->publish_pending_site(); return; - - } // end if; + } // We first try to generate the site through request to start earlier as possible. $rest_path = add_query_arg( @@ -2065,29 +1904,32 @@ class Membership extends Base_Model { '_ajax_nonce' => wp_create_nonce('wu_publish_pending_site'), 'membership_id' => $this->get_id(), ), - admin_url( 'admin-ajax.php' ) + admin_url('admin-ajax.php') ); - if ( function_exists( 'fastcgi_finish_request' ) && version_compare( phpversion(), '7.0.16', '>=' ) ) { + if ( function_exists('fastcgi_finish_request') && version_compare(phpversion(), '7.0.16', '>=') ) { // The server supports fastcgi, so we use this to guaranty that the function started before abort connection - wp_remote_request( $rest_path, array( - 'sslverify' => false, - )); - + wp_remote_request( + $rest_path, + array( + 'sslverify' => false, + ) + ); } elseif (ignore_user_abort(true) !== ignore_user_abort(false)) { // We do not have fastcgi but can make the request continue without listening - wp_remote_request( $rest_path, array( - 'sslverify' => false, - 'blocking' => false, - )); - - } // end if; + wp_remote_request( + $rest_path, + array( + 'sslverify' => false, + 'blocking' => false, + ) + ); + } wu_enqueue_async_action('wu_async_publish_pending_site', array('membership_id' => $this->get_id()), 'membership'); - - } // end publish_pending_site_async; + } /** * Publishes a pending site. @@ -2103,19 +1945,15 @@ class Membership extends Base_Model { $pending_site = $this->get_pending_site(); - if (!$pending_site) { - + if ( ! $pending_site) { return true; - - } // end if; + } $is_publishing = $pending_site->is_publishing(); if ($is_publishing) { - return true; - - } // end if; + } $pending_site->set_publishing(true); @@ -2126,7 +1964,6 @@ class Membership extends Base_Model { $saved = $pending_site->save(); if (is_wp_error($saved)) { - if ($saved->get_error_code() === 'site_taken') { /* * If the site is already taken, we just delete the pending site. @@ -2136,12 +1973,10 @@ class Membership extends Base_Model { $this->delete_pending_site(); return true; - - } // end if; + } return $saved; - - } // end if; + } $this->delete_pending_site(); @@ -2151,8 +1986,7 @@ class Membership extends Base_Model { do_action('wu_pending_site_published', $pending_site, $this); return true; - - } // end publish_pending_site; + } /** * Removes a pending site of a membership. @@ -2163,8 +1997,7 @@ class Membership extends Base_Model { public function delete_pending_site() { return $this->delete_meta('pending_site'); - - } // end delete_pending_site; + } /** * Get is this product recurring? @@ -2175,8 +2008,7 @@ class Membership extends Base_Model { public function is_recurring() { return (bool) $this->recurring && (float) $this->get_amount() > 0; - - } // end is_recurring; + } /** * Checks if this is a lifetime membership. @@ -2186,9 +2018,8 @@ class Membership extends Base_Model { */ public function is_lifetime() { - return !$this->is_recurring() && (empty($this->get_date_expiration()) || $this->get_date_expiration() === '0000-00-00 00:00:00'); - - } // end is_lifetime; + return ! $this->is_recurring() && (empty($this->get_date_expiration()) || $this->get_date_expiration() === '0000-00-00 00:00:00'); + } /** * Checks if this plan is free or not. @@ -2199,8 +2030,7 @@ class Membership extends Base_Model { public function is_free() { return $this->is_recurring() === false && empty($this->get_initial_amount()); - - } // end is_free; + } /** * Set is this product recurring? @@ -2212,8 +2042,7 @@ class Membership extends Base_Model { public function set_recurring($recurring) { $this->recurring = (bool) $recurring; - - } // end set_recurring; + } /** * Gets the total grossed by the membership so far. @@ -2228,19 +2057,16 @@ class Membership extends Base_Model { static $sum; if ($sum === null) { - $sum = $wpdb->get_var( $wpdb->prepare( "SELECT SUM(total) FROM {$wpdb->base_prefix}wu_payments WHERE parent_id = 0 AND membership_id = %d", $this->get_id() ) ); - - } // end if; + } return $sum; - - } // end get_total_grossed; + } /** * By default, we just use the to_array method, but you can rewrite this. @@ -2257,20 +2083,17 @@ class Membership extends Base_Model { $search_result['display_name'] = ''; if ($this->get_customer()) { - $search_result['customer'] = $this->get_customer()->to_search_results(); $search_result['display_name'] = $search_result['customer']['display_name']; - - } // end if; + } $search_result['formatted_price'] = $this->get_price_description(); $search_result['reference_code'] = $this->get_hash(); return $search_result; - - } // end to_search_results; + } /** * Renews the membership by updating status and expiration date. @@ -2293,23 +2116,18 @@ class Membership extends Base_Model { wu_log_add("membership-{$id}", sprintf('Starting membership renewal for membership #%d. Membership Level ID: %d; Current Expiration Date: %s', $id, $plan_id, $this->get_date_expiration())); if (empty($plan_id)) { - return false; - - } // end if; + } // Bail if this has a payment plan and it's completed - prevents renewals from running after the fact. - if (!$this->is_forever_recurring() && $this->at_maximum_renewals()) { - + if ( ! $this->is_forever_recurring() && $this->at_maximum_renewals()) { return false; - - } // end if; + } $plan = wu_get_product($plan_id); - if (!$expiration) { - - $expiration = $this->calculate_expiration(!$this->is_recurring()); + if ( ! $expiration) { + $expiration = $this->calculate_expiration(! $this->is_recurring()); /** * Filters the calculated expiration date to be set after the renewal. @@ -2322,8 +2140,7 @@ class Membership extends Base_Model { * @since 2.0.0 */ $expiration = apply_filters('wu_membership_renewal_expiration_date', $expiration, $plan, $this->get_id(), $this); - - } // end if; + } /** * Triggers before the membership renewal. @@ -2338,29 +2155,23 @@ class Membership extends Base_Model { $this->set_date_expiration($expiration); - if (!empty($status)) { - + if ( ! empty($status)) { $this->set_status($status); - - } // end if; + } $this->set_auto_renew($auto_renew); $this->set_date_renewed(wu_get_current_time('mysql')); // Current time. if ($this->get_user_id()) { - delete_user_meta($this->get_user_id(), 'wu_expired_email_sent'); - - } // end if; + } $status = $this->save(); if (is_wp_error($status)) { - return $status; - - } // end if; + } /** * Triggers after the membership renewal. @@ -2376,8 +2187,7 @@ class Membership extends Base_Model { wu_log_add("membership-{$id}", sprintf('Completed membership renewal for membership #%d. Membership Level ID: %d; New Expiration Date: %s; New Status: %s', $id, $plan_id, $expiration, $this->get_status())); return true; - - } // end renew; + } /** * Changes the membership status to "cancelled". @@ -2392,10 +2202,9 @@ class Membership extends Base_Model { public function cancel($reason = '') { if ($this->get_status() === Membership_Status::CANCELLED) { - return; // Already cancelled - } // end if; + } /** * Triggers before the membership is cancelled. @@ -2412,11 +2221,9 @@ class Membership extends Base_Model { $this->set_date_cancellation(wu_get_current_time('mysql')); - if (!empty($reason)) { - + if ( ! empty($reason)) { $this->set_cancellation_reason($reason); - - } // end if; + } $this->save(); @@ -2431,8 +2238,7 @@ class Membership extends Base_Model { * @since 2.0 */ do_action('wu_membership_post_cancel', $this->get_id(), $this); - - } // end cancel; + } /** * Returns the number of days still left in the cycle. @@ -2444,20 +2250,16 @@ class Membership extends Base_Model { /* * If this is a lifetime membership, we have unlimited days. Large number. */ - if (!$this->is_recurring()) { - + if ( ! $this->is_recurring()) { return 10000; - - } // end if; + } /* * We need to have a valid expiration date. */ - if (empty($this->get_date_expiration()) || !wu_validate_date($this->get_date_expiration())) { - + if (empty($this->get_date_expiration()) || ! wu_validate_date($this->get_date_expiration())) { return 0; - - } // end if; + } /* * Otherwise, we need to check based on the @@ -2472,14 +2274,11 @@ class Membership extends Base_Model { * There's nothing to pro-rate in that case. */ if ($today > $expiration_date) { - return 0; - - } // end if; + } return floor($today->diff($expiration_date)->days); - - } // end get_remaining_days_in_cycle; + } /** * List of limitations that need to be merged. @@ -2506,28 +2305,21 @@ class Membership extends Base_Model { $product_ids = array_merge($this->get_addon_ids(), $product_ids); foreach ($product_ids as $product_id) { - $amount = 1; - if (is_array($this->addon_products) && isset($this->addon_products[$product_id])) { - - $amount = $this->addon_products[$product_id]; - - } // end if; + if (is_array($this->addon_products) && isset($this->addon_products[ $product_id ])) { + $amount = $this->addon_products[ $product_id ]; + } $limitation = \WP_Ultimo\Objects\Limitations::early_get_limitations('product', $product_id); for ($i = 0; $i < $amount; $i++) { - $limitations_to_merge[] = $limitation; - - } // end for; - - } // end foreach; + } + } return $limitations_to_merge; - - } // end limitations_to_merge; + } /** * Checks if the membership has product changes. @@ -2538,27 +2330,22 @@ class Membership extends Base_Model { protected function has_product_changes() { if (empty($this->_compiled_product_list)) { - return false; - - } // end if; + } $old_products = $this->_compiled_product_list; $new_products = $this->get_all_products(); if (count($old_products) !== count($new_products)) { - return true; - - } // end if; + } $compiled_old = array_map(fn($product) => $product['product']->get_id() . '|' . $product['quantity'], $old_products); $compiled_new = array_map(fn($product) => $product['product']->get_id() . '|' . $product['quantity'], $new_products); return array_diff($compiled_old, $compiled_new) || array_diff($compiled_new, $compiled_old); - - } // end has_product_changes; + } /** * Checks if the membership has gateway changes. @@ -2577,20 +2364,15 @@ class Membership extends Base_Model { ); foreach ($this->_gateway_info as $key => $value) { - - if ($value !== $current_gateway[$key]) { - + if ($value !== $current_gateway[ $key ]) { $has_change = true; break; - - } // end if; - - } // end foreach; + } + } return $has_change; - - } // end has_gateway_changes; + } /** * Get the number of remaining sites available to this membership. @@ -2604,17 +2386,14 @@ class Membership extends Base_Model { $limit = $this->get_limitations()->sites->get_limit(); - if (!$this->get_limitations()->sites->is_enabled()) { - + if ( ! $this->get_limitations()->sites->is_enabled()) { return PHP_INT_MAX; - - } // end if; + } $limit = $limit === '' ? 1 : $limit; return $limit - count($this->get_sites()); - - } // end get_remaining_sites; + } /** * Checks if the current membership has remaining sites available. @@ -2625,8 +2404,7 @@ class Membership extends Base_Model { public function has_remaining_sites() { return $this->get_remaining_sites() >= 1; - - } // end has_remaining_sites; + } /** * Checks if the current membership is current trialing. @@ -2637,8 +2415,7 @@ class Membership extends Base_Model { public function is_trialing() { return $this->get_date_trial_end() > gmdate('Y-m-d 23:59:59'); - - } // end is_trialing; + } /** * Save (create or update) the model on the database. * @@ -2647,23 +2424,21 @@ class Membership extends Base_Model { public function save() { // Set trial status if needed - if ($this->get_status() === Membership_Status::PENDING && $this->is_trialing() && !$this->get_last_pending_payment()) { - - if (!wu_get_setting('enable_email_verification', true) || $this->get_customer()->get_email_verification() !== 'pending') { - + if ($this->get_status() === Membership_Status::PENDING && $this->is_trialing() && ! $this->get_last_pending_payment()) { + if ( ! wu_get_setting('enable_email_verification', true) || $this->get_customer()->get_email_verification() !== 'pending') { $this->set_status(Membership_Status::TRIALING); - - } // end if; - - } // end if; + } + } if ($this->has_product_changes()) { - - wu_enqueue_async_action('wu_async_after_membership_update_products', array( - 'membership_id' => $this->get_id(), - ), 'membership'); - - } // end if; + wu_enqueue_async_action( + 'wu_async_after_membership_update_products', + array( + 'membership_id' => $this->get_id(), + ), + 'membership' + ); + } // If membership is cancelled, we need to cancel the subscription on the gateway. if ($this->get_status() === Membership_Status::CANCELLED) { @@ -2675,8 +2450,7 @@ class Membership extends Base_Model { $this->set_gateway_customer_id(''); $this->set_gateway_subscription_id(''); $this->set_auto_renew(false); - - } // end if; + } if ($this->has_gateway_changes() && $this->_gateway_info['gateway']) { /** @@ -2687,21 +2461,17 @@ class Membership extends Base_Model { $gateway = wu_get_gateway($this->_gateway_info['gateway']); if ($gateway) { - $membership_old = clone $this; $membership_old->set_gateway($this->_gateway_info['gateway']); $membership_old->set_gateway_customer_id($this->_gateway_info['gateway_customer_id']); $membership_old->set_gateway_subscription_id($this->_gateway_info['gateway_subscription_id']); $gateway->process_cancellation($membership_old, $this->get_customer()); - - } // end if; - - } // end if; + } + } // Run it for existing memberships without gateway changes only. - if ($this->get_id() && !$this->has_gateway_changes()) { - + if ($this->get_id() && ! $this->has_gateway_changes()) { $original = $this->_get_original(); $has_amount_change = (float) $this->get_amount() !== (float) wu_get_isset($original, 'amount'); @@ -2716,44 +2486,33 @@ class Membership extends Base_Model { $gateway = wu_get_gateway($this->get_gateway()); if ($gateway) { - $gateway_update = $gateway->process_membership_update($this, $this->get_customer()); if (is_wp_error($gateway_update)) { - return $gateway_update; - - } // end if; - - } // end if; - - } // end if; - - } // end if; + } + } + } + } return parent::save(); - - } // end save; - /** - * Delete the model from the database. - * - * Here we also need to cancel the subscription on the gateway. - * - * @since 2.1.2 - * @return \WP_Error|bool - */ - public function delete() { + } + /** + * Delete the model from the database. + * + * Here we also need to cancel the subscription on the gateway. + * + * @since 2.1.2 + * @return \WP_Error|bool + */ + public function delete() { $gateway = wu_get_gateway($this->get_gateway()); if ($gateway) { - $gateway->process_cancellation($this, $this->get_customer()); - - } // end if; + } return parent::delete(); - - } // end delete; - -} // end class Membership; + } +} diff --git a/inc/models/class-payment.php b/inc/models/class-payment.php index 747660c..af12888 100644 --- a/inc/models/class-payment.php +++ b/inc/models/class-payment.php @@ -9,12 +9,12 @@ namespace WP_Ultimo\Models; -use \WP_Ultimo\Models\Base_Model; -use \WP_Ultimo\Database\Payments\Payment_Status; -use \WP_Ultimo\Checkout\Line_Item; -use \WP_Ultimo\Models\Product; -use \WP_Ultimo\Models\Customer; -use \WP_Ultimo\Models\Membership; +use WP_Ultimo\Models\Base_Model; +use WP_Ultimo\Database\Payments\Payment_Status; +use WP_Ultimo\Checkout\Line_Item; +use WP_Ultimo\Models\Product; +use WP_Ultimo\Models\Customer; +use WP_Ultimo\Models\Membership; // Exit if accessed directly defined('ABSPATH') || exit; @@ -189,14 +189,11 @@ class Payment extends Base_Model { $method_key = str_replace('_formatted', '', $name); if (strpos($name, '_formatted') !== false && method_exists($this, $method_key)) { - return wu_format_currency($this->{"$method_key"}(), $this->get_currency()); - - } // end if; + } throw new \BadMethodCallException($name); - - } // end __call; + } /** * Set the validation rules for this particular model. @@ -233,8 +230,7 @@ class Payment extends Base_Model { 'invoice_number' => 'default:', 'cancel_membership_on_refund' => 'boolean|default:0', ); - - } // end validation_rules; + } /** * Gets the customer object associated with this payment. @@ -246,8 +242,7 @@ class Payment extends Base_Model { public function get_customer() { return wu_get_customer($this->get_customer_id()); - - } // end get_customer; + } /** * Get the value of customer_id. @@ -258,8 +253,7 @@ class Payment extends Base_Model { public function get_customer_id(): int { return absint($this->customer_id); - - } // end get_customer_id; + } /** * Set the value of customer_id. @@ -271,20 +265,18 @@ class Payment extends Base_Model { public function set_customer_id($customer_id) { $this->customer_id = absint($customer_id); - - } // end set_customer_id; - /** - * Gets the membership object associated with this payment. - * - * @todo Implement this. - * @since 2.0.0 - * @return \WP_Ultimo\Models\Membership|false - */ - public function get_membership() { + } + /** + * Gets the membership object associated with this payment. + * + * @todo Implement this. + * @since 2.0.0 + * @return \WP_Ultimo\Models\Membership|false + */ + public function get_membership() { return wu_get_membership($this->get_membership_id()); - - } // end get_membership; + } /** * Get membership ID. @@ -295,8 +287,7 @@ class Payment extends Base_Model { public function get_membership_id() { return $this->membership_id; - - } // end get_membership_id; + } /** * Set membership ID. @@ -308,8 +299,7 @@ class Payment extends Base_Model { public function set_membership_id($membership_id) { $this->membership_id = $membership_id; - - } // end set_membership_id; + } /** * Get parent payment ID. @@ -320,8 +310,7 @@ class Payment extends Base_Model { public function get_parent_id() { return $this->parent_id; - - } // end get_parent_id; + } /** * Set parent payment ID. @@ -333,8 +322,7 @@ class Payment extends Base_Model { public function set_parent_id($parent_id) { $this->parent_id = $parent_id; - - } // end set_parent_id; + } /** * Get currency for this payment. 3-letter currency code. @@ -346,8 +334,7 @@ class Payment extends Base_Model { // return $this->currency; For now, multi-currency is not yet supported. return wu_get_setting('currency_symbol', 'USD'); - - } // end get_currency; + } /** * Set currency for this payment. 3-letter currency code. @@ -359,8 +346,7 @@ class Payment extends Base_Model { public function set_currency($currency) { $this->currency = $currency; - - } // end set_currency; + } /** * Get value before taxes, discounts, fees and etc. @@ -371,8 +357,7 @@ class Payment extends Base_Model { public function get_subtotal(): float { return $this->subtotal; - - } // end get_subtotal; + } /** * Set value before taxes, discounts, fees and etc. @@ -384,8 +369,7 @@ class Payment extends Base_Model { public function set_subtotal($subtotal) { $this->subtotal = $subtotal; - - } // end set_subtotal; + } /** * Get refund total in this payment. @@ -396,8 +380,7 @@ class Payment extends Base_Model { public function get_refund_total(): float { return $this->refund_total; - - } // end get_refund_total; + } /** * Set refund total in this payment. @@ -409,8 +392,7 @@ class Payment extends Base_Model { public function set_refund_total($refund_total): void { $this->refund_total = $refund_total; - - } // end set_refund_total; + } /** * Get the amount, in currency, of the tax. @@ -421,8 +403,7 @@ class Payment extends Base_Model { public function get_tax_total(): float { return (float) $this->tax_total; - - } // end get_tax_total; + } /** * Set the amount, in currency, of the tax. @@ -434,8 +415,7 @@ class Payment extends Base_Model { public function set_tax_total($tax_total): void { $this->tax_total = $tax_total; - - } // end set_tax_total; + } /** * Get discount code used. @@ -446,8 +426,7 @@ class Payment extends Base_Model { public function get_discount_code() { return $this->discount_code; - - } // end get_discount_code; + } /** * Set discount code used. @@ -459,8 +438,7 @@ class Payment extends Base_Model { public function set_discount_code($discount_code) { $this->discount_code = $discount_code; - - } // end set_discount_code; + } /** * Get this takes into account fees, discounts, credits, etc. @@ -471,8 +449,7 @@ class Payment extends Base_Model { public function get_total(): float { return (float) $this->total; - - } // end get_total; + } /** * Set this takes into account fees, discounts, credits, etc. @@ -484,8 +461,7 @@ class Payment extends Base_Model { public function set_total($total) { $this->total = $total; - - } // end set_total; + } /** * Returns the Label for a given severity level. @@ -498,8 +474,7 @@ class Payment extends Base_Model { $status = new Payment_Status($this->get_status()); return $status->get_label(); - - } // end get_status_label; + } /** * Gets the classes for a given class. @@ -512,8 +487,7 @@ class Payment extends Base_Model { $status = new Payment_Status($this->get_status()); return $status->get_classes(); - - } // end get_status_class; + } /** * Get status of the status. @@ -524,8 +498,7 @@ class Payment extends Base_Model { public function get_status() { return $this->status; - - } // end get_status; + } /** * Set status of the status. @@ -538,8 +511,7 @@ class Payment extends Base_Model { public function set_status($status) { $this->status = $status; - - } // end set_status; + } /** * Get gateway used to process this payment. @@ -550,8 +522,7 @@ class Payment extends Base_Model { public function get_gateway() { return $this->gateway; - - } // end get_gateway; + } /** * Set gateway used to process this payment. @@ -563,8 +534,7 @@ class Payment extends Base_Model { public function set_gateway($gateway) { $this->gateway = $gateway; - - } // end set_gateway; + } /** * Returns the payment method used. Usually it is the public name of the gateway. @@ -576,25 +546,20 @@ class Payment extends Base_Model { $gateway = $this->get_gateway(); - if (!$gateway) { - + if ( ! $gateway) { return __('None', 'wp-ultimo'); - - } // end if; + } $gateway_class = wu_get_gateway($gateway); - if (!$gateway_class) { - + if ( ! $gateway_class) { return __('None', 'wp-ultimo'); - - } // end if; + } $title = $gateway_class->get_public_title(); return apply_filters("wu_gateway_{$gateway}_as_option_title", $title, $gateway_class); - - } // end get_payment_method; + } /** * Returns the product associated to this payment. @@ -605,8 +570,7 @@ class Payment extends Base_Model { public function get_product() { return wu_get_product($this->product_id); - - } // end get_product; + } /** * Checks if this payment has line items. @@ -618,9 +582,8 @@ class Payment extends Base_Model { */ public function has_line_items(): bool { - return !empty($this->get_line_items()); - - } // end has_line_items; + return ! empty($this->get_line_items()); + } /** * Returns the line items for this payment. @@ -634,16 +597,13 @@ class Payment extends Base_Model { public function get_line_items(): array { if ($this->line_items === null) { - $line_items = (array) $this->get_meta('wu_line_items'); $this->line_items = array_filter($line_items); - - } // end if; + } return (array) $this->line_items; - - } // end get_line_items; + } /** * Set the line items of this payment. @@ -660,8 +620,7 @@ class Payment extends Base_Model { $this->meta['wu_line_items'] = $line_items; $this->line_items = $line_items; - - } // end set_line_items; + } /** * Add a new line item. @@ -675,19 +634,16 @@ class Payment extends Base_Model { $line_items = $this->get_line_items(); - if (!is_a($line_item, self::class)) { - + if ( ! is_a($line_item, self::class)) { return; + } - } // end if; - - $line_items[$line_item->get_id()] = $line_item; + $line_items[ $line_item->get_id() ] = $line_item; $this->set_line_items($line_items); krsort($this->line_items); - - } // end add_line_item; + } /** * Returns an array containing the subtotal per tax rate. @@ -702,30 +658,23 @@ class Payment extends Base_Model { $tax_brackets = array(); foreach ($line_items as $line_item) { - $tax_bracket = $line_item->get_tax_rate(); - if (!$tax_bracket) { + if ( ! $tax_bracket) { + continue; + } + + if (isset($tax_brackets[ $tax_bracket ])) { + $tax_brackets[ $tax_bracket ] += $line_item->get_tax_total(); continue; + } - } // end if; - - if (isset($tax_brackets[$tax_bracket])) { - - $tax_brackets[$tax_bracket] += $line_item->get_tax_total(); - - continue; - - } // end if; - - $tax_brackets[$tax_bracket] = $line_item->get_tax_total(); - - } // end foreach; + $tax_brackets[ $tax_bracket ] = $line_item->get_tax_total(); + } return $tax_brackets; - - } // end get_tax_breakthrough; + } /** * Recalculate payment totals. @@ -748,7 +697,6 @@ class Payment extends Base_Model { $total = 0; foreach ($line_items as $line_item) { - $line_item->recalculate_totals(); $tax_total += $line_item->get_tax_total(); @@ -758,23 +706,21 @@ class Payment extends Base_Model { $total += $line_item->get_total(); if ($line_item->get_type() === 'refund') { - $refund_total += $line_item->get_subtotal(); + } + } - } // end if; - - } // end foreach; - - $this->attributes(array( - 'tax_total' => $tax_total, - 'subtotal' => $sub_total, - 'refund_total' => $refund_total, - 'total' => $total, - )); + $this->attributes( + array( + 'tax_total' => $tax_total, + 'subtotal' => $sub_total, + 'refund_total' => $refund_total, + 'total' => $total, + ) + ); return $this; - - } // end recalculate_totals; + } /** * Checks if this payment is payable still. @@ -784,14 +730,16 @@ class Payment extends Base_Model { */ public function is_payable(): bool { - $payable_statuses = apply_filters('wu_payment_payable_statuses', array( - Payment_Status::PENDING, - Payment_Status::FAILED, - )); + $payable_statuses = apply_filters( + 'wu_payment_payable_statuses', + array( + Payment_Status::PENDING, + Payment_Status::FAILED, + ) + ); return $this->get_total() > 0 && in_array($this->get_status(), $payable_statuses, true); - - } // end is_payable; + } /** * Returns the link to pay for this payment. @@ -801,19 +749,19 @@ class Payment extends Base_Model { */ public function get_payment_url() { - if (!$this->is_payable()) { - + if ( ! $this->is_payable()) { return false; - - } // end if; + } $slug = $this->get_hash(); - return add_query_arg(array( - 'payment' => $slug, - ), wu_get_registration_url()); - - } // end get_payment_url; + return add_query_arg( + array( + 'payment' => $slug, + ), + wu_get_registration_url() + ); + } /** * Get iD of the product of this payment. @@ -824,8 +772,7 @@ class Payment extends Base_Model { public function get_product_id() { return $this->product_id; - - } // end get_product_id; + } /** * Set iD of the product of this payment. @@ -837,8 +784,7 @@ class Payment extends Base_Model { public function set_product_id($product_id) { $this->product_id = $product_id; - - } // end set_product_id; + } /** * Generates the Invoice URL. @@ -855,8 +801,7 @@ class Payment extends Base_Model { ); return add_query_arg($url_atts, get_site_url(wu_get_main_site_id())); - - } // end get_invoice_url; + } /** * Get iD of the payment on the gateway, if it exists. @@ -867,8 +812,7 @@ class Payment extends Base_Model { public function get_gateway_payment_id() { return $this->gateway_payment_id; - - } // end get_gateway_payment_id; + } /** * Set iD of the payment on the gateway, if it exists. @@ -880,8 +824,7 @@ class Payment extends Base_Model { public function set_gateway_payment_id($gateway_payment_id) { $this->gateway_payment_id = $gateway_payment_id; - - } // end set_gateway_payment_id; + } /** * By default, we just use the to_array method, but you can rewrite this. @@ -900,8 +843,7 @@ class Payment extends Base_Model { $search_result['product_names'] = implode(', ', array_column($line_items, 'title')); return $search_result; - - } // end to_search_results; + } /** * Get the total value in discounts. @@ -912,8 +854,7 @@ class Payment extends Base_Model { public function get_discount_total() { return (float) $this->discount_total; - - } // end get_discount_total; + } /** * Set the total value in discounts. @@ -925,8 +866,7 @@ class Payment extends Base_Model { public function set_discount_total($discount_total) { $this->discount_total = (float) $discount_total; - - } // end set_discount_total; + } /** * Get the invoice number actually saved on the payment. @@ -937,14 +877,11 @@ class Payment extends Base_Model { public function get_saved_invoice_number() { if ($this->invoice_number === null) { - $this->invoice_number = $this->get_meta('wu_invoice_number', ''); - - } // end if; + } return $this->invoice_number; - - } // end get_saved_invoice_number; + } /** * Get sequential invoice number assigned to this payment. @@ -955,26 +892,20 @@ class Payment extends Base_Model { public function get_invoice_number() { if (wu_get_setting('invoice_numbering_scheme', 'reference_code') === 'reference_code') { - return $this->get_hash(); - - } // end if; + } $provisional = false; if ($this->invoice_number === null) { - $this->invoice_number = $this->get_meta('wu_invoice_number'); - - } // end if; + } if ($this->invoice_number === false) { - $provisional = true; $this->invoice_number = wu_get_setting('next_invoice_number'); - - } // end if; + } $prefix = wu_get_setting('invoice_prefix', ''); @@ -999,8 +930,7 @@ class Payment extends Base_Model { $prefix = str_replace($search, $replace, (string) $prefix); return sprintf('%s%s %s', $prefix, $this->invoice_number, $provisional ? __('(provisional)', 'wp-ultimo') : ''); - - } // end get_invoice_number; + } /** * Set sequential invoice number assigned to this payment. @@ -1014,8 +944,7 @@ class Payment extends Base_Model { $this->meta['wu_invoice_number'] = $invoice_number; $this->invoice_number = $invoice_number; - - } // end set_invoice_number; + } /** * Remove all non-recurring items from the payment. @@ -1031,22 +960,17 @@ class Payment extends Base_Model { $line_items = $this->get_line_items(); foreach ($line_items as $line_item_id => $line_item) { - - if (!$line_item->is_recurring()) { - - unset($line_items[$line_item_id]); - - } // end if; - - } // end foreach; + if ( ! $line_item->is_recurring()) { + unset($line_items[ $line_item_id ]); + } + } $this->set_line_items($line_items); $this->recalculate_totals(); return $this; - - } // end remove_non_recurring_items; + } /** * Get holds if we need to cancel the membership on refund.. @@ -1057,14 +981,11 @@ class Payment extends Base_Model { public function should_cancel_membership_on_refund() { if ($this->cancel_membership_on_refund === null) { - $this->cancel_membership_on_refund = $this->get_meta('wu_cancel_membership_on_refund', false); - - } // end if; + } return $this->cancel_membership_on_refund; - - } // end should_cancel_membership_on_refund; + } /** * Set holds if we need to cancel the membership on refund.. @@ -1078,8 +999,7 @@ class Payment extends Base_Model { $this->meta['wu_cancel_membership_on_refund'] = $cancel_membership_on_refund; $this->cancel_membership_on_refund = $cancel_membership_on_refund; - - } // end set_cancel_membership_on_refund; + } /** * Handles a payment refund. @@ -1108,10 +1028,8 @@ class Payment extends Base_Model { * refund the full amount. */ if (empty($amount)) { - $amount = $this->get_total(); - - } // end if; + } $amount = wu_to_float($amount); @@ -1119,10 +1037,8 @@ class Payment extends Base_Model { * Do the same for the behavior regarding memberships. */ if (is_null($should_cancel_membership_on_refund)) { - $should_cancel_membership_on_refund = $this->should_cancel_membership_on_refund(); - - } // end if; + } /* * First, deal with the status. @@ -1133,18 +1049,14 @@ class Payment extends Base_Model { * it is a partial refund. */ if ($amount >= $this->get_total()) { - $title = __('Full Refund', 'wp-ultimo'); $new_status = Payment_Status::REFUND; - } else { - $title = __('Partial Refund', 'wp-ultimo'); $new_status = Payment_Status::PARTIAL_REFUND; - - } // end if; + } $time = current_time('timestamp'); // phpcs:ignore @@ -1175,30 +1087,23 @@ class Payment extends Base_Model { $status = $this->save(); if (is_wp_error($status)) { - return $status; - - } // end if; + } /** * Updating the payment went well. * Let's deal with the membership, if needed. */ if ($should_cancel_membership_on_refund) { - $membership = $this->get_membership(); if ($membership) { - $membership->cancel(); - - } // end if; - - } // end if; + } + } return true; - - } // end refund; + } /** * Creates a copy of the given model adn resets it's id to a 'new' state. @@ -1215,7 +1120,5 @@ class Payment extends Base_Model { $new_payment->set_line_items($line_items); return $new_payment; - - } // end duplicate; - -} // end class Payment; + } +} diff --git a/inc/models/class-post-base-model.php b/inc/models/class-post-base-model.php index 2c35683..1b00797 100644 --- a/inc/models/class-post-base-model.php +++ b/inc/models/class-post-base-model.php @@ -104,8 +104,7 @@ class Post_Base_Model extends Base_Model { public function get_author_id() { return $this->author_id; - - } // end get_author_id; + } /** * Set author ID. @@ -115,8 +114,7 @@ class Post_Base_Model extends Base_Model { public function set_author_id($author_id) { $this->author_id = $author_id; - - } // end set_author_id; + } /** * Get post type. @@ -126,8 +124,7 @@ class Post_Base_Model extends Base_Model { public function get_type() { return $this->type; - - } // end get_type; + } /** * Set post type. @@ -137,8 +134,7 @@ class Post_Base_Model extends Base_Model { public function set_type($type) { $this->type = $type; - - } // end set_type; + } /** * Get post title. @@ -148,8 +144,7 @@ class Post_Base_Model extends Base_Model { public function get_title() { return $this->title; - - } // end get_title; + } /** * Set post title. @@ -159,8 +154,7 @@ class Post_Base_Model extends Base_Model { public function set_title($title) { $this->title = $title; - - } // end set_title; + } /** * Get post content. @@ -173,8 +167,7 @@ class Post_Base_Model extends Base_Model { * Also we need to add the paragraphs and line breaks back. */ return wpautop(stripslashes($this->content)); - - } // end get_content; + } /** * Set post content. @@ -184,8 +177,7 @@ class Post_Base_Model extends Base_Model { public function set_content($content) { $this->content = $content; - - } // end set_content; + } /** * Get post excerpt. @@ -195,8 +187,7 @@ class Post_Base_Model extends Base_Model { public function get_excerpt() { return $this->excerpt; - - } // end get_excerpt; + } /** * Set post excerpt. @@ -206,8 +197,7 @@ class Post_Base_Model extends Base_Model { public function set_excerpt($excerpt) { $this->excerpt = $excerpt; - - } // end set_excerpt; + } /** * Get post creation date. @@ -217,8 +207,7 @@ class Post_Base_Model extends Base_Model { public function get_date_created() { return $this->date_created; - - } // end get_date_created; + } /** * Set post creation date. @@ -228,8 +217,7 @@ class Post_Base_Model extends Base_Model { public function set_date_created($date_created) { $this->date_created = $date_created; - - } // end set_date_created; + } /** * Get post last modification date. @@ -239,8 +227,7 @@ class Post_Base_Model extends Base_Model { public function get_date_modified() { return $this->date_modified; - - } // end get_date_modified; + } /** * Set post last modification date. @@ -250,8 +237,7 @@ class Post_Base_Model extends Base_Model { public function set_date_modified($date_modified) { $this->date_modified = $date_modified; - - } // end set_date_modified; + } /** * Get the post list order. @@ -261,8 +247,7 @@ class Post_Base_Model extends Base_Model { public function get_list_order() { return $this->list_order; - - } // end get_list_order; + } /** * Set the post list order. @@ -272,8 +257,7 @@ class Post_Base_Model extends Base_Model { public function set_list_order($list_order) { $this->list_order = $list_order; - - } // end set_list_order; + } /** * Get the post status. @@ -283,8 +267,7 @@ class Post_Base_Model extends Base_Model { public function get_status() { return $this->status; - - } // end get_status; + } /** * Set the post status. @@ -294,8 +277,7 @@ class Post_Base_Model extends Base_Model { public function set_status($status) { $this->status = $status; - - } // end set_status; + } /** * Save (create or update) the model on the database, @@ -306,13 +288,11 @@ class Post_Base_Model extends Base_Model { */ public function save() { - if (!$this->author_id) { - + if ( ! $this->author_id) { $this->author_id = get_current_user_id(); + } - } // end if; - - if (!$this->status) { + if ( ! $this->status) { /** * Filters the object data before it is stored into the database. @@ -324,11 +304,8 @@ class Post_Base_Model extends Base_Model { * @param Base_Model $this The object instance. */ $this->status = apply_filters('wu_post_default_status', 'draft', $this->type, $this); - - } // end if; + } return parent::save(); - - } // end save; - -} // end class Post_Base_Model; + } +} diff --git a/inc/models/class-product.php b/inc/models/class-product.php index 5c3d1a2..e4744ed 100644 --- a/inc/models/class-product.php +++ b/inc/models/class-product.php @@ -12,8 +12,8 @@ namespace WP_Ultimo\Models; // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\Models\Base_Model; -use \WP_Ultimo\Database\Products\Product_Type; +use WP_Ultimo\Models\Base_Model; +use WP_Ultimo\Database\Products\Product_Type; /** * Product model class. Implements the Base Model. @@ -22,7 +22,8 @@ use \WP_Ultimo\Database\Products\Product_Type; */ class Product extends Base_Model { - use Traits\Limitable, \WP_Ultimo\Traits\WP_Ultimo_Plan_Deprecated; + use Traits\Limitable; + use \WP_Ultimo\Traits\WP_Ultimo_Plan_Deprecated; /** * The product name. @@ -323,8 +324,7 @@ class Product extends Base_Model { 'contact_us_link' => 'url:http,https', 'customer_role' => 'alpha_dash', ); - - } // end validation_rules; + } /** * Get featured image ID. @@ -335,14 +335,11 @@ class Product extends Base_Model { public function get_featured_image_id() { if ($this->featured_image_id === null) { - $this->featured_image_id = $this->get_meta('wu_featured_image_id'); - - } // end if; + } return $this->featured_image_id; - - } // end get_featured_image_id; + } /** * Get featured image url. @@ -360,8 +357,7 @@ class Product extends Base_Model { is_multisite() && restore_current_blog(); return $image_attributes ? $image_attributes[0] : ''; - - } // end get_featured_image; + } /** * Set featured image ID. @@ -375,8 +371,7 @@ class Product extends Base_Model { $this->meta['wu_featured_image_id'] = $image_id; $this->featured_image_id = $image_id; - - } // end set_featured_image_id; + } /** * Get the product slug. @@ -386,8 +381,7 @@ class Product extends Base_Model { public function get_slug() { return $this->slug; - - } // end get_slug; + } /** * Set the slug name. @@ -397,8 +391,7 @@ class Product extends Base_Model { public function set_slug($slug) { $this->slug = $slug; - - } // end set_slug; + } /** * Get the product name. @@ -408,8 +401,7 @@ class Product extends Base_Model { public function get_name() { return $this->name; - - } // end get_name; + } /** * Set the product name. @@ -419,8 +411,7 @@ class Product extends Base_Model { public function set_name($name) { $this->name = $name; - - } // end set_name; + } /** * Get the product description. @@ -430,8 +421,7 @@ class Product extends Base_Model { public function get_description() { return stripslashes($this->description); - - } // end get_description; + } /** * Set the product description. @@ -441,8 +431,7 @@ class Product extends Base_Model { public function set_description($description) { $this->description = $description; - - } // end set_description; + } /** * Get the value of currency. @@ -457,14 +446,11 @@ class Product extends Base_Model { $currency = wu_get_setting('currency_symbol', 'USD'); if ($should_use_saved_currency) { - $currency = $this->currency; - - } // end if; + } return $currency; - - } // end get_currency; + } /** * Set the value of currency. @@ -476,8 +462,7 @@ class Product extends Base_Model { public function set_currency($currency) { $this->currency = $currency; - - } // end set_currency; + } /** * Get can be one of 'free', 'paid', and 'contact_us'. @@ -488,8 +473,7 @@ class Product extends Base_Model { public function get_pricing_type() { return $this->pricing_type; - - } // end get_pricing_type; + } /** * Set pricing type can be one of 'free', 'paid', and 'contact_us'. @@ -504,14 +488,11 @@ class Product extends Base_Model { $this->pricing_type = $pricing_type; if ($pricing_type === 'free' || $pricing_type === 'contact_us') { - $this->set_amount(0); $this->set_recurring(false); - - } // end if; - - } // end set_pricing_type; + } + } /** * Checks if a given product offers a trial period. @@ -522,8 +503,7 @@ class Product extends Base_Model { public function has_trial() { return $this->get_trial_duration() > 0; - - } // end has_trial; + } /** * Get duration of the trial. @@ -534,8 +514,7 @@ class Product extends Base_Model { public function get_trial_duration() { return $this->trial_duration; - - } // end get_trial_duration; + } /** * Set duration of the trial. @@ -547,8 +526,7 @@ class Product extends Base_Model { public function set_trial_duration($trial_duration) { $this->trial_duration = $trial_duration; - - } // end set_trial_duration; + } /** * Get the trial duration unit. @@ -559,8 +537,7 @@ class Product extends Base_Model { public function get_trial_duration_unit() { return $this->trial_duration_unit; - - } // end get_trial_duration_unit; + } /** * Set the trial duration unit. @@ -573,8 +550,7 @@ class Product extends Base_Model { public function set_trial_duration_unit($trial_duration_unit) { $this->trial_duration_unit = $trial_duration_unit; - - } // end set_trial_duration_unit; + } /** * Get time interval between charges. @@ -584,8 +560,7 @@ class Product extends Base_Model { public function get_duration() { return absint($this->duration); - - } // end get_duration; + } /** * Set time interval between charges. @@ -595,8 +570,7 @@ class Product extends Base_Model { public function set_duration($duration) { $this->duration = $duration; - - } // end set_duration; + } /** * Get time interval unit between charges. @@ -606,8 +580,7 @@ class Product extends Base_Model { public function get_duration_unit() { return $this->duration_unit; - - } // end get_duration_unit; + } /** * Set time interval unit between charges. @@ -617,8 +590,7 @@ class Product extends Base_Model { public function set_duration_unit($duration_unit) { $this->duration_unit = $duration_unit; - - } // end set_duration_unit; + } /** * Get the product amount. @@ -628,20 +600,15 @@ class Product extends Base_Model { public function get_amount() { if ($this->get_pricing_type() === 'free') { - return 0; - - } // end if; + } if ($this->get_pricing_type() === 'contact_us') { - return 0; - - } // end if; + } return $this->amount; - - } // end get_amount; + } /** * Get the formatted price amount. @@ -653,20 +620,15 @@ class Product extends Base_Model { public function get_formatted_amount($key = 'amount') { if ($this->is_free()) { - return __('Free!', 'wp-ultimo'); - - } // end if; + } if ($this->get_pricing_type() === 'contact_us') { - return $this->get_contact_us_label() ? $this->get_contact_us_label() : __('Contact Us', 'wp-ultimo'); - - } // end if; + } return wu_format_currency($this->get_amount(), $this->get_currency()); - - } // end get_formatted_amount; + } /** * Set the product amount. @@ -676,8 +638,7 @@ class Product extends Base_Model { public function set_amount($amount) { $this->amount = wu_to_float($amount); - - } // end set_amount; + } /** * Get the product setup fee.. @@ -688,8 +649,7 @@ class Product extends Base_Model { public function get_setup_fee() { return $this->setup_fee; - - } // end get_setup_fee; + } /** * Set the product setup fee.. @@ -701,8 +661,7 @@ class Product extends Base_Model { public function set_setup_fee($setup_fee) { $this->setup_fee = wu_to_float($setup_fee); - - } // end set_setup_fee; + } /** * Checks if a given product haw a setup fee. @@ -713,8 +672,7 @@ class Product extends Base_Model { public function has_setup_fee() { return $this->get_setup_fee() > 0; - - } // end has_setup_fee; + } /** * Get the product initial amount @@ -724,8 +682,7 @@ class Product extends Base_Model { public function get_initial_amount() { return $this->get_amount() + $this->get_setup_fee(); - - } // end get_initial_amount; + } /** * Returns the product price structure in a way human can understand it. @@ -740,19 +697,14 @@ class Product extends Base_Model { $pricing = array(); if ($this->get_pricing_type() === 'contact_us') { - return __('Contact us', 'wp-ultimo'); - - } // end if; + } if ($this->is_free()) { - return __('Free!', 'wp-ultimo'); - - } // end if; + } if ($this->is_recurring()) { - $duration = $this->get_duration(); $message = sprintf( @@ -765,8 +717,7 @@ class Product extends Base_Model { $pricing['subscription'] = $message; - if (!$this->is_forever_recurring()) { - + if ( ! $this->is_forever_recurring()) { $billing_cycles_message = sprintf( // translators: %s is the number of billing cycles. _n('for %s cycle', 'for %s cycles', $this->get_billing_cycles(), 'wp-ultimo'), @@ -774,32 +725,25 @@ class Product extends Base_Model { ); $pricing['subscription'] .= ' ' . $billing_cycles_message; - - } // end if; - + } } else { - $pricing['subscription'] = sprintf( // translators: %1$s is the formatted price of the product __('%1$s one time payment', 'wp-ultimo'), wu_format_currency($this->get_amount(), $this->get_currency()) ); - - } // end if; + } if ($this->has_setup_fee() && $include_fees) { - $pricing['fee'] = sprintf( // translators: %1$s is the formatted price of the setup fee __('Setup Fee of %1$s', 'wp-ultimo'), wu_format_currency($this->get_setup_fee(), $this->get_currency()) ); - - } // end if; + } return implode(' + ', $pricing); - - } // end get_price_description; + } /** * Returns the amount recurring in a human-friendly way. @@ -810,16 +754,12 @@ class Product extends Base_Model { public function get_recurring_description() { if ($this->is_free() || $this->get_pricing_type() === 'contact_us') { - return '--'; + } - } // end if; - - if (!$this->is_recurring()) { - + if ( ! $this->is_recurring()) { return __('one-time payment', 'wp-ultimo'); - - } // end if; + } $description = sprintf( // translators: %1$s the duration, and %2$s the duration unit (day, week, month, etc) @@ -829,8 +769,7 @@ class Product extends Base_Model { ); return $description; - - } // end get_recurring_description; + } /** * Get the product list order. Useful when ordering products in a list. @@ -840,8 +779,7 @@ class Product extends Base_Model { public function get_list_order() { return $this->list_order; - - } // end get_list_order; + } /** * Set the product list order. Useful when ordering products in a list. @@ -851,8 +789,7 @@ class Product extends Base_Model { public function set_list_order($list_order) { $this->list_order = $list_order; - - } // end set_list_order; + } /** * Get is this product active?. @@ -863,8 +800,7 @@ class Product extends Base_Model { public function is_active() { return (bool) $this->active; - - } // end is_active; + } /** * Set is this product active? @@ -876,8 +812,7 @@ class Product extends Base_Model { public function set_active($active) { $this->active = (bool) $active; - - } // end set_active; + } /** * Get type of the product. @@ -887,8 +822,7 @@ class Product extends Base_Model { public function get_type() { return $this->type; - - } // end get_type; + } /** * Set type of the product. @@ -899,8 +833,7 @@ class Product extends Base_Model { public function set_type($type) { $this->type = $type; - - } // end set_type; + } /** * Returns the Label for a given type. @@ -913,8 +846,7 @@ class Product extends Base_Model { $type = new Product_Type($this->get_type()); return $type->get_label(); - - } // end get_type_label; + } /** * Gets the classes for a given class. @@ -927,8 +859,7 @@ class Product extends Base_Model { $type = new Product_Type($this->get_type()); return $type->get_classes(); - - } // end get_type_class; + } /** * Get product that this product relates to.. @@ -939,8 +870,7 @@ class Product extends Base_Model { public function get_parent_id() { return $this->parent_id; - - } // end get_parent_id; + } /** * Set product that this product relates to.. @@ -952,8 +882,7 @@ class Product extends Base_Model { public function set_parent_id($parent_id) { $this->parent_id = $parent_id; - - } // end set_parent_id; + } /** * Get is this product recurring? @@ -964,8 +893,7 @@ class Product extends Base_Model { public function is_recurring() { return (bool) $this->recurring && (float) $this->get_amount() > 0; - - } // end is_recurring; + } /** * Checks if this plan is free or not. @@ -976,8 +904,7 @@ class Product extends Base_Model { public function is_free() { return empty($this->get_amount()) && empty($this->get_initial_amount()); - - } // end is_free; + } /** * Set is this product recurring? @@ -989,8 +916,7 @@ class Product extends Base_Model { public function set_recurring($recurring) { $this->recurring = (bool) $recurring; - - } // end set_recurring; + } /** * Get the number of times we should charge this product. @@ -1001,8 +927,7 @@ class Product extends Base_Model { public function get_billing_cycles() { return (int) $this->billing_cycles; - - } // end get_billing_cycles; + } /** * Checks if this product recurs forever. @@ -1013,8 +938,7 @@ class Product extends Base_Model { public function is_forever_recurring() { return empty($this->get_billing_cycles()) || $this->get_billing_cycles() <= 0; - - } // end is_forever_recurring; + } /** * Set the number of times we should charge this product. @@ -1026,8 +950,7 @@ class Product extends Base_Model { public function set_billing_cycles($billing_cycles) { $this->billing_cycles = (int) $billing_cycles; - - } // end set_billing_cycles; + } /** * Get date when this was created.. @@ -1038,8 +961,7 @@ class Product extends Base_Model { public function get_date_created() { return $this->date_created; - - } // end get_date_created; + } /** * Set date when this was created.. @@ -1051,8 +973,7 @@ class Product extends Base_Model { public function set_date_created($date_created) { $this->date_created = $date_created; - - } // end set_date_created; + } /** * Get date when this was last modified.. @@ -1063,8 +984,7 @@ class Product extends Base_Model { public function get_date_modified() { return $this->date_modified; - - } // end get_date_modified; + } /** * Set date when this was last modified.. @@ -1076,8 +996,7 @@ class Product extends Base_Model { public function set_date_modified($date_modified) { $this->date_modified = $date_modified; - - } // end set_date_modified; + } /** * By default, we just use the to_array method, but you can rewrite this. @@ -1096,8 +1015,7 @@ class Product extends Base_Model { $search_result['image'] = $image ? sprintf('', esc_attr($image)) : ''; return $search_result; - - } // end to_search_results; + } // Secondary Info, to be saved as meta @@ -1112,8 +1030,7 @@ class Product extends Base_Model { $is_taxable = (bool) $this->get_meta('taxable', true); return apply_filters('wu_product_is_taxable', $is_taxable, $this); - - } // end is_taxable; + } /** * Sets the taxable status of the product. @@ -1128,8 +1045,7 @@ class Product extends Base_Model { $this->meta['taxable'] = (bool) $is_taxable; $this->taxable = $this->meta['taxable']; - - } // end set_taxable; + } /** * Returns the tax category to apply. @@ -1140,14 +1056,11 @@ class Product extends Base_Model { public function get_tax_category() { if ($this->tax_category === null) { - $this->tax_category = $this->get_meta('tax_category', 'default'); - - } // end if; + } return apply_filters('wu_product_tax_category', $this->tax_category, $this); - - } // end get_tax_category; + } /** * Sets the tax category to apply. @@ -1162,8 +1075,7 @@ class Product extends Base_Model { $this->meta['tax_category'] = $tax_category; $this->tax_category = $this->meta['tax_category']; - - } // end set_tax_category; + } /** * Get the contact us label. @@ -1174,14 +1086,11 @@ class Product extends Base_Model { public function get_contact_us_label() { if ($this->contact_us_label === null) { - $this->contact_us_label = $this->get_meta('wu_contact_us_label', ''); - - } // end if; + } return $this->contact_us_label; - - } // end get_contact_us_label; + } /** * Set the contact us label. @@ -1195,8 +1104,7 @@ class Product extends Base_Model { $this->meta['wu_contact_us_label'] = $contact_us_label; $this->contact_us_label = $this->meta['wu_contact_us_label']; - - } // end set_contact_us_label; + } /** * Get the contact us link. @@ -1207,14 +1115,11 @@ class Product extends Base_Model { public function get_contact_us_link() { if ($this->contact_us_link === null) { - $this->contact_us_link = $this->get_meta('wu_contact_us_link', ''); - - } // end if; + } return $this->contact_us_link; - - } // end get_contact_us_link; + } /** * Set the contact us link. @@ -1228,8 +1133,7 @@ class Product extends Base_Model { $this->meta['wu_contact_us_link'] = $contact_us_link; $this->contact_us_link = $this->meta['wu_contact_us_link']; - - } // end set_contact_us_link; + } /** * Get feature list for pricing tables.. @@ -1240,14 +1144,11 @@ class Product extends Base_Model { public function get_feature_list() { if ($this->feature_list === null) { - $this->feature_list = $this->get_meta('feature_list'); - - } // end if; + } return $this->feature_list; - - } // end get_feature_list; + } /** * Set feature list for pricing tables.. @@ -1261,8 +1162,7 @@ class Product extends Base_Model { $this->meta['feature_list'] = $feature_list; $this->feature_list = $this->meta['feature_list']; - - } // end set_feature_list; + } /** * Get the customer role to force customers to be on this plan. @@ -1273,14 +1173,11 @@ class Product extends Base_Model { public function get_customer_role() { if ($this->customer_role === null) { - $this->customer_role = $this->get_limitations()->customer_user_role->get_limit(); - - } // end if; + } return $this->customer_role; - - } // end get_customer_role; + } /** * Set the customer role to force customers to be on this plan. @@ -1290,7 +1187,7 @@ class Product extends Base_Model { * @param string $customer_role The customer role of this product. * @return void */ - public function set_customer_role($customer_role) {} // end set_customer_role; + public function set_customer_role($customer_role) {} /** * Returns the same product, but with price and duration info changed to @@ -1310,38 +1207,29 @@ class Product extends Base_Model { $duration_unit = $duration_unit ? $duration_unit : 'month'; if ($this->is_free()) { - return $this; - - } // end if; + } if ($duration !== $this->get_duration() || $duration_unit !== $this->get_duration_unit()) { - $price_variation = $this->get_price_variation($duration, $duration_unit); - - } // end if; + } if (absint($duration) === $this->get_duration() && $duration_unit === $this->get_duration_unit()) { - $price_variation = array( 'amount' => $this->get_amount(), ); - - } // end if; + } $price_variation = apply_filters('wu_get_as_variation_price_variation', $price_variation, $duration, $duration_unit, $this); if ($price_variation) { - $this->attributes((array) $price_variation); return $this; - - } // end if; + } return false; - - } // end get_as_variation; + } /** * Returns the price variations for this product. @@ -1352,22 +1240,21 @@ class Product extends Base_Model { public function get_price_variations() { if ($this->price_variations === null) { + $this->price_variations = array_map( + function ($price_variation) { + /** + * Ensure the amount is a float. + */ + $price_variation['amount'] = wu_to_float(wu_get_isset($price_variation, 'amount', 0)); - $this->price_variations = array_map(function($price_variation) { - /** - * Ensure the amount is a float. - */ - $price_variation['amount'] = wu_to_float(wu_get_isset($price_variation, 'amount', 0)); - - return $price_variation; - - }, $this->get_meta('price_variations', array())); - - } // end if; + return $price_variation; + }, + $this->get_meta('price_variations', array()) + ); + } return $this->price_variations; - - } // end get_price_variations; + } /** * Sets the new price variations. @@ -1379,19 +1266,20 @@ class Product extends Base_Model { public function set_price_variations(?array $price_variations) { // Ensure the amount is a float. - $price_variations = array_map(function($price_variation) { + $price_variations = array_map( + function ($price_variation) { - $price_variation['amount'] = wu_to_float(wu_get_isset($price_variation, 'amount', 0)); + $price_variation['amount'] = wu_to_float(wu_get_isset($price_variation, 'amount', 0)); - return $price_variation; - - }, $price_variations ?? array()); + return $price_variation; + }, + $price_variations ?? array() + ); $this->meta['price_variations'] = $price_variations; $this->price_variations = $this->meta['price_variations']; - - } // end set_price_variations; + } /** * Get a particular price variation. @@ -1408,35 +1296,26 @@ class Product extends Base_Model { $price_variations = $this->get_price_variations(); - if (!empty($price_variations)) { - + if ( ! empty($price_variations)) { if (absint($duration) === 12 && $duration_unit === 'month') { - $duration = 1; $duration_unit = 'year'; - - } // end if; + } foreach ($price_variations as $pv) { - if (absint($pv['duration']) === absint($duration) && $pv['duration_unit'] === $duration_unit) { - $pv['monthly_amount'] = $pv['amount'] / (wu_convert_duration_unit_to_month($duration_unit) * $pv['duration']); $price_variation = $pv; break; - - } // end if; - - } // end foreach; - - } // end if; + } + } + } return apply_filters('wu_product_get_price_variation', $price_variation, $duration, $duration_unit, $this); - - } // end get_price_variation; + } /** * Save (create or update) the model on the database. @@ -1448,36 +1327,27 @@ class Product extends Base_Model { public function save() { if (empty($this->slug) && $this->name) { - $this->set_slug(sanitize_title($this->name)); - - } // end if; + } if ($this->is_free() && $this->get_pricing_type() !== 'contact_us') { - $this->set_pricing_type('free'); - - } // end if; + } $results = parent::save(); - if (!is_wp_error($results) && has_action('save_post_wpultimo_plan')) { - + if ( ! is_wp_error($results) && has_action('save_post_wpultimo_plan')) { do_action_deprecated('save_post_wpultimo_plan', array($this->get_id()), '2.0.0'); + } - } // end if; - - if (!is_wp_error($results) && has_action('wu_save_plan')) { - + if ( ! is_wp_error($results) && has_action('wu_save_plan')) { $compat_plan = new \WU_Plan($this); do_action_deprecated('wu_save_plan', array($compat_plan), '2.0.0', 'wu_product_post_save'); - - } // end if; + } return $results; - - } // end save; + } /** * Creates a copy of the given model adn resets it's id to a 'new' state. @@ -1492,8 +1362,7 @@ class Product extends Base_Model { $new_product = parent::duplicate(); return $new_product; - - } // end duplicate; + } /** * Get available add-ons. @@ -1504,20 +1373,15 @@ class Product extends Base_Model { public function get_available_addons() { if ($this->available_addons === null) { - $this->available_addons = $this->get_meta('wu_available_addons', array()); if (is_string($this->available_addons)) { - $this->available_addons = explode(',', $this->available_addons); - - } // end if; - - } // end if; + } + } return $this->available_addons; - - } // end get_available_addons; + } /** * Set available add-ons. @@ -1531,8 +1395,7 @@ class Product extends Base_Model { $this->meta['wu_available_addons'] = $available_addons; $this->available_addons = $this->meta['wu_available_addons']; - - } // end set_available_addons; + } /** * Get the shareable link for this product, depending on the permalinks structure. @@ -1544,8 +1407,7 @@ class Product extends Base_Model { public function get_shareable_link($deprecated = false) { return wu_get_registration_url($this->get_slug()); - - } // end get_shareable_link; + } /** * Get available add-ons. @@ -1556,8 +1418,7 @@ class Product extends Base_Model { public function get_group() { return $this->product_group; - - } // end get_group; + } /** * Set the group of this product. @@ -1569,8 +1430,7 @@ class Product extends Base_Model { public function set_group($group) { $this->product_group = $group; - - } // end set_group; + } /** * Get if legacy options are available. @@ -1581,14 +1441,11 @@ class Product extends Base_Model { public function get_legacy_options() { if ($this->legacy_options === null) { - $this->legacy_options = $this->get_meta('legacy_options', false); - - } // end if; + } return $this->legacy_options; - - } // end get_legacy_options; + } /** * Set if legacy options are available. @@ -1602,8 +1459,7 @@ class Product extends Base_Model { $this->meta['legacy_options'] = $legacy_options; $this->legacy_options = $this->meta['legacy_options']; - - } // end set_legacy_options; + } /** * List of limitations that need to be merged. @@ -1622,7 +1478,5 @@ class Product extends Base_Model { public function limitations_to_merge() { return array(); - - } // end limitations_to_merge; - -} // end class Product; + } +} diff --git a/inc/models/class-site.php b/inc/models/class-site.php index c7128e6..928e883 100644 --- a/inc/models/class-site.php +++ b/inc/models/class-site.php @@ -10,10 +10,10 @@ namespace WP_Ultimo\Models; use Psr\Log\LogLevel; -use \WP_Ultimo\Models\Base_Model; -use \WP_Ultimo\Objects\Limitations; -use \WP_Ultimo\Database\Sites\Site_Type; -use \WP_Ultimo\UI\Template_Previewer; +use WP_Ultimo\Models\Base_Model; +use WP_Ultimo\Objects\Limitations; +use WP_Ultimo\Database\Sites\Site_Type; +use WP_Ultimo\UI\Template_Previewer; // Exit if accessed directly defined('ABSPATH') || exit; @@ -25,7 +25,9 @@ defined('ABSPATH') || exit; */ class Site extends Base_Model { - use Traits\Limitable, \WP_Ultimo\Traits\WP_Ultimo_Site_Deprecated, Traits\Notable; + use Traits\Limitable; + use \WP_Ultimo\Traits\WP_Ultimo_Site_Deprecated; + use Traits\Notable; /** DEFAULT WP_SITE COLUMNS */ @@ -198,11 +200,11 @@ class Site extends Base_Model { protected $template_id; /** - * Duplication arguments. - * - * @since 2.0.0 - * @var array - */ + * Duplication arguments. + * + * @since 2.0.0 + * @var array + */ private $duplication_arguments = array(); /** @@ -275,7 +277,7 @@ class Site extends Base_Model { $date = wu_get_current_time('mysql', true); - $site_types = new \WP_Ultimo\Database\Sites\Site_Type; + $site_types = new \WP_Ultimo\Database\Sites\Site_Type(); $site_types = implode(',', array_values($site_types->get_options())); @@ -303,8 +305,7 @@ class Site extends Base_Model { 'type' => "required|in:{$site_types}", 'signup_options' => 'default:', ); - - } // end validation_rules; + } /** * Get the visits for this particular sites. @@ -317,8 +318,7 @@ class Site extends Base_Model { $visits_manager = new \WP_Ultimo\Objects\Visits($this->get_id()); return $visits_manager->get_visit_total('first day of this month', 'last day of this month'); - - } // end get_visits_count; + } /** * Set the categories for the site. @@ -333,8 +333,7 @@ class Site extends Base_Model { $this->meta['wu_categories'] = $categories; $this->categories = $categories; - - } // end set_categories; + } /** * Get the list of categories. @@ -345,20 +344,15 @@ class Site extends Base_Model { public function get_categories() { if ($this->categories === null) { - $this->categories = $this->get_meta('wu_categories', array()); + } - } // end if; - - if (!is_array($this->categories)) { - + if ( ! is_array($this->categories)) { return array(); - - } // end if; + } return array_filter($this->categories); - - } // end get_categories; + } /** * Get featured image ID. @@ -369,14 +363,11 @@ class Site extends Base_Model { public function get_featured_image_id() { if ($this->featured_image_id === null) { - return $this->get_meta('wu_featured_image_id'); - - } // end if; + } return $this->featured_image_id; - - } // end get_featured_image_id; + } /** * Get featured image url. * @@ -387,10 +378,8 @@ class Site extends Base_Model { public function get_featured_image($size = 'wu-thumb-medium') { if ($this->get_type() === 'external') { - return wu_get_asset('wp-ultimo-screenshot.png'); - - } // end if; + } is_multisite() && switch_to_blog(wu_get_main_site_id()); @@ -401,14 +390,11 @@ class Site extends Base_Model { is_multisite() && restore_current_blog(); if ($image_attributes) { - return $image_attributes[0]; - - } // end if; + } return wu_get_asset('site-placeholder-image.png', 'img'); - - } // end get_featured_image; + } /** * Set featured image ID. @@ -422,8 +408,7 @@ class Site extends Base_Model { $this->meta['wu_featured_image_id'] = $image_id; $this->featured_image_id = $image_id; - - } // end set_featured_image_id; + } /** * Get the preview URL. @@ -434,8 +419,7 @@ class Site extends Base_Model { public function get_preview_url() { return Template_Previewer::get_instance()->get_preview_url($this->get_id()); - - } // end get_preview_url; + } /** * Get the preview URL attrs. * @@ -447,17 +431,14 @@ class Site extends Base_Model { $href = 'href="%s" target="_blank"'; - if (!$is_enabled) { - + if ( ! $is_enabled) { return sprintf($href, $this->get_active_site_url()); - - } // end if; + } $onclick = 'onclick="window.open(\'%s\')"'; return sprintf($onclick, add_query_arg('open', 1, $this->get_preview_url())); - - } // end get_preview_url_attrs; + } /** * Get blog ID. Should be accessed via id. @@ -468,8 +449,7 @@ class Site extends Base_Model { public function get_id() { return $this->get_blog_id(); - - } // end get_id; + } /** * Get blog ID. Should be accessed via id.. @@ -480,8 +460,7 @@ class Site extends Base_Model { public function get_blog_id() { return (int) $this->blog_id; - - } // end get_blog_id; + } /** * Set blog ID. Should be accessed via id.. @@ -493,8 +472,7 @@ class Site extends Base_Model { public function set_blog_id($blog_id) { $this->blog_id = $blog_id; - - } // end set_blog_id; + } /** * Get network ID for this site.. @@ -505,8 +483,7 @@ class Site extends Base_Model { public function get_site_id() { return $this->site_id; - - } // end get_site_id; + } /** * Set network ID for this site.. @@ -518,8 +495,7 @@ class Site extends Base_Model { public function set_site_id($site_id) { $this->site_id = $site_id; - - } // end set_site_id; + } /** * Get title of the site.. * @@ -528,8 +504,7 @@ class Site extends Base_Model { public function get_title(): string { return stripslashes($this->title); - - } // end get_title; + } /** * Set title of the site. @@ -542,8 +517,7 @@ class Site extends Base_Model { public function set_title($title) { $this->title = sanitize_text_field($title); - - } // end set_title; + } /** * Alias to get name. @@ -554,8 +528,7 @@ class Site extends Base_Model { public function get_name() { return $this->get_title(); - - } // end get_name; + } /** * Alias to set title. @@ -567,8 +540,7 @@ class Site extends Base_Model { public function set_name($title) { $this->set_title($title); - - } // end set_name; + } /** * Gets the site description. @@ -579,14 +551,11 @@ class Site extends Base_Model { public function get_description() { if ($this->description) { - return $this->description; - - } // end if; + } return get_blog_option($this->get_id(), 'blogdescription'); - - } // end get_description; + } /** * Sets the site description. @@ -600,8 +569,7 @@ class Site extends Base_Model { public function set_description($description) { $this->description = $description; - - } // end set_description; + } /** * Get domain name used by this site.. @@ -612,8 +580,7 @@ class Site extends Base_Model { public function get_domain() { return $this->domain; - - } // end get_domain; + } /** * Set domain name used by this site.. @@ -625,8 +592,7 @@ class Site extends Base_Model { public function set_domain($domain) { $this->domain = $domain; - - } // end set_domain; + } /** * Get path of the site. Used when in sub-directory mode.. * @@ -635,8 +601,7 @@ class Site extends Base_Model { public function get_path(): string { return trim($this->path, '/'); - - } // end get_path; + } /** * Set path of the site. Used when in sub-directory mode.. @@ -648,8 +613,7 @@ class Site extends Base_Model { public function set_path($path) { $this->path = $path; - - } // end set_path; + } /** * Get date when the site was registered.. @@ -660,8 +624,7 @@ class Site extends Base_Model { public function get_registered() { return $this->registered; - - } // end get_registered; + } /** * Proxy for a common API. @@ -672,8 +635,7 @@ class Site extends Base_Model { public function get_date_registered() { return $this->get_registered(); - - } // end get_date_registered; + } /** * Set date when the site was registered.. @@ -685,8 +647,7 @@ class Site extends Base_Model { public function set_registered($registered) { $this->registered = $registered; - - } // end set_registered; + } /** * Get date of the last update on this site. @@ -697,8 +658,7 @@ class Site extends Base_Model { public function get_last_updated() { return $this->last_updated; - - } // end get_last_updated; + } /** * Proxy to last_updated. @@ -709,8 +669,7 @@ class Site extends Base_Model { public function get_date_modified() { return $this->get_last_updated(); - - } // end get_date_modified; + } /** * Set date of the last update on this site.. @@ -722,8 +681,7 @@ class Site extends Base_Model { public function set_last_updated($last_updated) { $this->last_updated = $last_updated; - - } // end set_last_updated; + } /** * Get if the site is being published. @@ -734,8 +692,7 @@ class Site extends Base_Model { public function is_publishing() { return $this->is_publishing; - - } // end is_publishing; + } /** * Set if the site is being published. @@ -747,8 +704,7 @@ class Site extends Base_Model { public function set_publishing($publishing) { $this->is_publishing = $publishing; - - } // end set_publishing; + } /** * Get holds the ID of the customer that owns this site. @@ -759,14 +715,11 @@ class Site extends Base_Model { public function is_active() { if ($this->active === null) { - $this->active = $this->get_meta('wu_active', true); - - } // end if; + } return $this->active; - - } // end is_active; + } /** * Set holds the ID of the customer that owns this site.. @@ -780,8 +733,7 @@ class Site extends Base_Model { $this->meta['wu_active'] = $active; $this->active = $active; - - } // end set_active; + } /** * Get is this a public site?. @@ -792,8 +744,7 @@ class Site extends Base_Model { public function get_public() { return $this->public; - - } // end get_public; + } /** * Set is this a public site?. @@ -805,8 +756,7 @@ class Site extends Base_Model { public function set_public($public) { $this->public = $public; - - } // end set_public; + } /** * Get is this an archived site. @@ -817,8 +767,7 @@ class Site extends Base_Model { public function is_archived() { return $this->archived; - - } // end is_archived; + } /** * Set is this an archived site?. @@ -830,8 +779,7 @@ class Site extends Base_Model { public function set_archived($archived) { $this->archived = $archived; - - } // end set_archived; + } /** * Get is this a site with mature content. @@ -842,8 +790,7 @@ class Site extends Base_Model { public function is_mature() { return $this->mature; - - } // end is_mature; + } /** * Set is this a site with mature content?. @@ -855,8 +802,7 @@ class Site extends Base_Model { public function set_mature($mature) { $this->mature = $mature; - - } // end set_mature; + } /** * Get is this an spam site. @@ -867,8 +813,7 @@ class Site extends Base_Model { public function is_spam() { return $this->spam; - - } // end is_spam; + } /** * Set is this an spam site?. @@ -880,8 +825,7 @@ class Site extends Base_Model { public function set_spam($spam) { $this->spam = $spam; - - } // end set_spam; + } /** * Get is this site deleted. @@ -892,8 +836,7 @@ class Site extends Base_Model { public function is_deleted() { return $this->deleted; - - } // end is_deleted; + } /** * Set is this site deleted?. @@ -905,8 +848,7 @@ class Site extends Base_Model { public function set_deleted($deleted) { $this->deleted = $deleted; - - } // end set_deleted; + } /** * Get iD of the language being used on this site. @@ -917,8 +859,7 @@ class Site extends Base_Model { public function get_lang_id() { return $this->lang_id; - - } // end get_lang_id; + } /** * Set iD of the language being used on this site. @@ -930,8 +871,7 @@ class Site extends Base_Model { public function set_lang_id($lang_id) { $this->lang_id = $lang_id; - - } // end set_lang_id; + } /** * Get holds the ID of the customer that owns this site.. @@ -942,14 +882,11 @@ class Site extends Base_Model { public function get_customer_id() { if ($this->customer_id === null) { - $this->customer_id = $this->get_meta('wu_customer_id'); - - } // end if; + } return (int) $this->customer_id; - - } // end get_customer_id; + } /** * Set holds the ID of the customer that owns this site.. @@ -963,8 +900,7 @@ class Site extends Base_Model { $this->meta['wu_customer_id'] = $customer_id; $this->customer_id = $customer_id; - - } // end set_customer_id; + } /** * Gets the customer object associated with this membership. @@ -975,8 +911,7 @@ class Site extends Base_Model { public function get_customer() { return wu_get_customer($this->get_customer_id()); - - } // end get_customer; + } /** * Checks if a given customer should have access to this site options. @@ -989,24 +924,19 @@ class Site extends Base_Model { public function is_customer_allowed($customer_id = false) { if (current_user_can('manage_network')) { - return true; + } - } // end if; - - if (!$customer_id) { - + if ( ! $customer_id) { $customer = WP_Ultimo()->currents->get_customer(); $customer_id = $customer ? $customer->get_id() : 0; - - } // end if; + } $allowed = absint($customer_id) === absint($this->get_customer_id()); return apply_filters('wu_site_is_customer_allowed', $allowed, $customer_id, $this); - - } // end is_customer_allowed; + } /** * Get holds the ID of the membership associated with this site, if any.. @@ -1017,14 +947,11 @@ class Site extends Base_Model { public function get_membership_id() { if ($this->membership_id === null) { - $this->membership_id = $this->get_meta('wu_membership_id'); - - } // end if; + } return $this->membership_id; - - } // end get_membership_id; + } /** * Set holds the ID of the membership associated with this site, if any.. @@ -1038,8 +965,7 @@ class Site extends Base_Model { $this->meta['wu_membership_id'] = $membership_id; $this->membership_id = $membership_id; - - } // end set_membership_id; + } /** * Checks if this site has a membership. @@ -1049,9 +975,8 @@ class Site extends Base_Model { */ public function has_membership() { - return !empty($this->get_membership()); - - } // end has_membership; + return ! empty($this->get_membership()); + } /** * Checks if the site has a product. @@ -1062,8 +987,7 @@ class Site extends Base_Model { public function has_product() { return $this->has_membership() && $this->get_membership()->has_product(); - - } // end has_product; + } /** * Gets the membership object associated with this membership. @@ -1074,18 +998,14 @@ class Site extends Base_Model { public function get_membership() { if ($this->_membership !== null) { - return $this->_membership; - - } // end if; + } if (function_exists('wu_get_membership')) { - $this->_membership = wu_get_membership($this->get_membership_id()); return $this->_membership; - - } // end if; + } global $wpdb; @@ -1093,27 +1013,22 @@ class Site extends Base_Model { $membership_id = $this->get_membership_id(); - if (!$membership_id) { - + if ( ! $membership_id) { return false; - - } // end if; + } $query = $wpdb->prepare("SELECT * FROM {$table_name} WHERE id = %d LIMIT 1", $membership_id); // phpcs:ignore $results = $wpdb->get_row($query); // phpcs:ignore - if (!$results) { - + if ( ! $results) { return false; - - } // end if; + } $this->_membership = new \WP_Ultimo\Models\Membership($results); return $this->_membership; - - } // end get_membership; + } /** * Returns the plan that created this site. @@ -1124,31 +1039,25 @@ class Site extends Base_Model { public function get_plan() { if ($this->has_membership()) { - return $this->get_membership()->get_plan(); - - } // end if; + } return false; - - } // end get_plan; - /** - * Get template ID. - * - * @since 2.0.0 - * @return int|bool - */ - public function get_template_id() { + } + /** + * Get template ID. + * + * @since 2.0.0 + * @return int|bool + */ + public function get_template_id() { if ($this->template_id === null) { - $this->template_id = $this->get_meta('wu_template_id'); - - } // end if; + } return $this->template_id; - - } // end get_template_id; + } /** * Set the template ID. @@ -1162,8 +1071,7 @@ class Site extends Base_Model { $this->meta['wu_template_id'] = absint($template_id); $this->template_id = $template_id; - - } // end set_template_id; + } /** * Gets the site object associated with this membership. @@ -1174,8 +1082,7 @@ class Site extends Base_Model { public function get_template() { return wu_get_site($this->get_template_id()); - - } // end get_template; + } /** * Returns the default duplication arguments. @@ -1190,8 +1097,7 @@ class Site extends Base_Model { 'copy_files' => true, 'public' => true, ); - - } // end get_default_duplication_arguments; + } /** * Convert the Ultimo instance to a WP_Site. @@ -1202,8 +1108,7 @@ class Site extends Base_Model { public function to_wp_site() { return get_site($this->get_id()); - - } // end to_wp_site; + } /** * Get duplication arguments.. @@ -1216,8 +1121,7 @@ class Site extends Base_Model { $args = wp_parse_args($this->duplication_arguments, $this->get_default_duplication_arguments()); return $args; - - } // end get_duplication_arguments; + } /** * Set duplication arguments.. @@ -1229,8 +1133,7 @@ class Site extends Base_Model { public function set_duplication_arguments($duplication_arguments) { $this->duplication_arguments = $duplication_arguments; - - } // end set_duplication_arguments; + } /** * Get the site type of this particular site.. @@ -1241,22 +1144,17 @@ class Site extends Base_Model { public function get_type() { if ($this->get_id() && is_main_site($this->get_id())) { - return 'main'; - - } // end if; + } if ($this->type === null) { - $type = $this->get_meta('wu_type'); $this->type = $type ? $type : 'default'; - - } // end if; + } return $this->type; - - } // end get_type; + } /** * Set the site type of this particular site. @@ -1273,32 +1171,30 @@ class Site extends Base_Model { $this->meta['wu_type'] = $type; $this->type = $type; + } + /** + * Get the primary mapped domain for this site. + * + * @since 2.0.0 + * @return \WP_Ultimo\Models\Domain|false + */ + public function get_primary_mapped_domain() { - } // end set_type; - /** - * Get the primary mapped domain for this site. - * - * @since 2.0.0 - * @return \WP_Ultimo\Models\Domain|false - */ - public function get_primary_mapped_domain() { - - if (!function_exists('wu_get_domains')) { - + if ( ! function_exists('wu_get_domains')) { return false; + } - } // end if; - - $domains = wu_get_domains(array( - 'primary_domain' => true, - 'blog_id' => $this->get_id(), - 'stage__not_in' => \WP_Ultimo\Models\Domain::INACTIVE_STAGES, - 'number' => 1, - )); + $domains = wu_get_domains( + array( + 'primary_domain' => true, + 'blog_id' => $this->get_id(), + 'stage__not_in' => \WP_Ultimo\Models\Domain::INACTIVE_STAGES, + 'number' => 1, + ) + ); return empty($domains) ? false : $domains[0]; - - } // end get_primary_mapped_domain; + } /** * Returns the active site URL, which can be a mapped domain. @@ -1308,23 +1204,18 @@ class Site extends Base_Model { */ public function get_active_site_url() { - if (!$this->get_id()) { - + if ( ! $this->get_id()) { return $this->get_site_url(); - - } // end if; + } $domain = $this->get_primary_mapped_domain(); if ($domain) { - return $domain->get_url(); - - } // end if; + } return $this->get_site_url(); - - } // end get_active_site_url; + } /** * Returns the original URL for the blog. @@ -1340,8 +1231,7 @@ class Site extends Base_Model { $url = set_url_scheme(esc_url(sprintf($this->get_domain() . '/' . $this->get_path()))); return $url; - - } // end get_site_url; + } /** * Checks if this model was already saved to the database. @@ -1351,9 +1241,8 @@ class Site extends Base_Model { */ public function exists() { - return !empty($this->blog_id); - - } // end exists; + return ! empty($this->blog_id); + } /** * Override te constructor due to this being a native table. @@ -1367,31 +1256,24 @@ class Site extends Base_Model { parent::__construct($object); if (is_array($object)) { - $object = (object) $object; - - } // end if; + } $details = get_blog_details($this->get_blog_id()); if ($details && $this->title === null) { - $this->set_title($details->blogname); - - } // end if; + } /* * Quick fix for WP CLI, since it uses the --path arg to do other things. */ - if (!$this->path && is_object($object) && isset($object->site_path)) { - + if ( ! $this->path && is_object($object) && isset($object->site_path)) { $this->path = $object->site_path; - - } // end if; + } $object = (object) $object; - - } // end __construct; + } /** * Gets the form data saved at the time of the site creation. @@ -1402,14 +1284,11 @@ class Site extends Base_Model { public function get_transient() { if ($this->transient === null) { - $this->transient = $this->get_meta('wu_transient'); - - } // end if; + } return $this->transient; - - } // end get_transient; + } /** * Holds the form data at the time of registration. @@ -1423,8 +1302,7 @@ class Site extends Base_Model { $this->meta['wu_transient'] = $transient; $this->transient = $transient; - - } // end set_transient; + } /** * Get signup options for the site. @@ -1435,8 +1313,7 @@ class Site extends Base_Model { public function get_signup_options() { return is_array($this->signup_options) ? $this->signup_options : array(); - - } // end get_signup_options; + } /** * Set signup options for the site. @@ -1448,8 +1325,7 @@ class Site extends Base_Model { public function set_signup_options($signup_options) { $this->signup_options = $signup_options; - - } // end set_signup_options; + } /** * Get signup meta for the site. @@ -1460,8 +1336,7 @@ class Site extends Base_Model { public function get_signup_meta() { return is_array($this->signup_meta) ? $this->signup_meta : array(); - - } // end get_signup_meta; + } /** * Set signup meta for the site. @@ -1473,8 +1348,7 @@ class Site extends Base_Model { public function set_signup_meta($signup_meta) { $this->signup_meta = $signup_meta; - - } // end set_signup_meta; + } /** * Returns the Label for a given type. @@ -1487,8 +1361,7 @@ class Site extends Base_Model { $type = new Site_Type($this->get_type()); return $type->get_label(); - - } // end get_type_label; + } /** * Gets the classes for a given class. @@ -1501,8 +1374,7 @@ class Site extends Base_Model { $type = new Site_Type($this->get_type()); return $type->get_classes(); - - } // end get_type_class; + } /** * Adds magic methods to return options. @@ -1517,16 +1389,13 @@ class Site extends Base_Model { public function __call($name, $args) { if (strpos($name, 'get_option_') !== false) { - $option = str_replace('get_option_', '', $name); return get_blog_option($this->get_id(), $option, false); - - } // end if; + } throw new \BadMethodCallException(__CLASS__ . "::$name()"); - - } // end __call; + } /** * Checks if this is the primary site of the customer. @@ -1538,38 +1407,31 @@ class Site extends Base_Model { $customer = $this->get_customer(); - if (!$customer) { - + if ( ! $customer) { return false; - - } // end if; + } $user_id = $customer->get_user_id(); - if (!$user_id) { - + if ( ! $user_id) { return false; - - } // end if; + } $primary_site_id = get_user_option('primary_blog', $user_id); return absint($primary_site_id) === absint($this->get_id()); + } + /** + * Delete the model from the database. + * + * @since 2.0.0 + * @return \WP_Error|bool + */ + public function delete() { - } // end is_customer_primary_site; - /** - * Delete the model from the database. - * - * @since 2.0.0 - * @return \WP_Error|bool - */ - public function delete() { - - if (!$this->get_id()) { - + if ( ! $this->get_id()) { return new \WP_Error("wu_{$this->model}_delete_unsaved_item", __('Item not found.', 'wp-ultimo')); - - } // end if; + } /** * Fires after an object is stored into the database. @@ -1581,16 +1443,12 @@ class Site extends Base_Model { do_action("wu_{$this->model}_pre_delete", $this); // @phpstan-ignore-line try { - $result = (bool) wp_delete_site($this->get_id()); - } catch (\Throwable $e) { - $result = false; wu_log_add('fatal-error', $e->getMessage(), LogLevel::ERROR); - - } // end try; + } /** * Fires after an object is stored into the database. @@ -1605,8 +1463,7 @@ class Site extends Base_Model { wp_cache_flush(); return $result; - - } // end delete; + } /** * Replaces meta fields with the data collected during signup. @@ -1619,24 +1476,23 @@ class Site extends Base_Model { $transient = $this->get_transient(); if ($transient) { + add_filter( + 'wu_search_and_replace_on_duplication', + function ($replace_list, $from_site_id, $to_site_id) use ($transient) { - add_filter('wu_search_and_replace_on_duplication', function($replace_list, $from_site_id, $to_site_id) use ($transient) { + foreach ($transient as $transient_key => $transient_value) { + $key = sprintf('{{%s}}', $transient_key); - foreach ($transient as $transient_key => $transient_value) { + $replace_list[ $key ] = $transient_value; + } - $key = sprintf('{{%s}}', $transient_key); - - $replace_list[$key] = $transient_value; - - } // end foreach; - - return $replace_list; - - }, 9, 3); - - } // end if; - - } // end handles_existing_search_and_replace; + return $replace_list; + }, + 9, + 3 + ); + } + } /** * Save (create or update) the model on the database. @@ -1656,7 +1512,6 @@ class Site extends Base_Model { * like overload the form session with the meta data saved on the pending site. */ if (has_filter('wu_search_and_replace_on_duplication')) { - $transient = $this->get_transient(); $session = wu_get_session('signup'); @@ -1664,8 +1519,7 @@ class Site extends Base_Model { $session->set('form', $transient); $session->commit(); - - } // end if; + } $data = get_object_vars($this); @@ -1679,10 +1533,9 @@ class Site extends Base_Model { $saved = true; - $new = !$this->exists(); + $new = ! $this->exists(); if ($new) { - $network = get_network(); $domain = $this->get_domain() ? $this->get_domain() : $network->domain; @@ -1699,25 +1552,26 @@ class Site extends Base_Model { $email = wp_get_current_user() ? wp_get_current_user()->user_email : get_network_option(null, 'admin_email'); if ($customer) { - $user_id = $customer->get_user_id(); $email = $customer->get_email_address(); - - } // end if; + } /* * Decide if we need to duplicate this site, or create a new one. */ if ($this->get_template()) { - - $saved = \WP_Ultimo\Helpers\Site_Duplicator::duplicate_site($this->get_template_id(), $this->get_title(), array( - 'email' => $email, - 'path' => $this->get_path(), - 'domain' => $domain, - 'meta' => $this->get_signup_options(), - 'user_id' => $user_id ? $user_id : 0, - )); + $saved = \WP_Ultimo\Helpers\Site_Duplicator::duplicate_site( + $this->get_template_id(), + $this->get_title(), + array( + 'email' => $email, + 'path' => $this->get_path(), + 'domain' => $domain, + 'meta' => $this->get_signup_options(), + 'user_id' => $user_id ? $user_id : 0, + ) + ); if (is_wp_error($saved)) { @@ -1727,26 +1581,22 @@ class Site extends Base_Model { $saved = get_blog_id_from_url($domain, $this->get_path()); if ($saved === 0 || $saved === wu_get_main_site_id()) { - return $error; - - } // end if; - - } // end if; - + } + } } else { - $saved = wpmu_create_blog($domain, $this->get_path(), $this->get_title(), $user_id, $this->get_signup_options(), $network_id); if ($saved && $this->get_public()) { - $site_id = $saved; - wp_update_site($site_id, array( - 'public' => $this->get_public(), - )); - - } // end if; + wp_update_site( + $site_id, + array( + 'public' => $this->get_public(), + ) + ); + } /** * Fires after a site is created for the first time. @@ -1758,51 +1608,42 @@ class Site extends Base_Model { */ do_action('wu_site_created', $data, $this); // @phpstan-ignore-line - } // end if; - - if (!is_wp_error($saved) && wu_get_setting('enable_screenshot_generator', true)) { - - wu_enqueue_async_action('wu_async_take_screenshot', array( - 'site_id' => $saved, - ), 'site'); - - } // end if; + } + if ( ! is_wp_error($saved) && wu_get_setting('enable_screenshot_generator', true)) { + wu_enqueue_async_action( + 'wu_async_take_screenshot', + array( + 'site_id' => $saved, + ), + 'site' + ); + } } else { - $saved = wp_update_site($this->get_id(), $this->to_array()); - - } // end if; + } if (is_wp_error($saved)) { - return $saved; - - } // end if; + } $this->blog_id = $saved; switch_to_blog($this->blog_id); foreach ($this->get_signup_options() as $key => $value) { - update_option($key, $value); - - } // end foreach; + } restore_current_blog(); foreach ($this->get_signup_meta() as $key => $value) { - update_site_meta($saved, $key, $value); - - } // end foreach; + } foreach ($this->meta as $key => $value) { - update_site_meta($saved, $key, $value); - - } // end foreach; + } /** * Handles membership @@ -1810,12 +1651,10 @@ class Site extends Base_Model { $membership = $this->get_membership(); if ($membership) { - $customer_id = $membership->get_customer_id(); $this->set_customer_id($customer_id); - - } // end if; + } /** * Handles customers. @@ -1823,28 +1662,22 @@ class Site extends Base_Model { $customer = $this->get_customer(); if ($customer) { - $role = wu_get_setting('default_role', 'administrator'); if ($membership && $membership->has_limitations()) { - $role = $membership->get_limitations()->customer_user_role->get_limit(); - - } // end if; + } update_site_meta($this->get_id(), 'wu_customer_id', $customer->get_id()); $user_id = $customer->get_user_id(); add_user_to_blog($this->get_id(), $user_id, $role); - } elseif ($this->get_type() !== Site_Type::CUSTOMER_OWNED && $original_customer_id) { - $user_id = wu_get_customer($original_customer_id)->get_user_id(); remove_user_from_blog($user_id, $this->get_id()); - - } // end if; + } update_blog_option($this->get_id(), 'blogname', $this->get_name()); @@ -1875,14 +1708,11 @@ class Site extends Base_Model { do_action("wu_{$this->model}_post_save", $data, $this, $new); // @phpstan-ignore-line if (isset($session)) { - $session->destroy(); - - } // end if; + } return $saved; - - } // end save; + } /** * By default, we just use the to_array method, but you can rewrite this. @@ -1897,8 +1727,7 @@ class Site extends Base_Model { $search_result['siteurl'] = $this->get_active_site_url(); return $search_result; - - } // end to_search_results; + } /** * Returns a list of sites based on the type. @@ -1916,7 +1745,6 @@ class Site extends Base_Model { global $wpdb; if ($type === 'pending') { - $table_name = "{$wpdb->base_prefix}wu_membershipmeta"; $customer_id = (int) wu_get_isset($query_args, 'customer_id'); @@ -1924,41 +1752,40 @@ class Site extends Base_Model { $customer_id_query = ''; if ($customer_id) { - - $memberships = wu_get_memberships(array( - 'fields' => array('id'), - 'customer_id' => $customer_id, - )); + $memberships = wu_get_memberships( + array( + 'fields' => array('id'), + 'customer_id' => $customer_id, + ) + ); $memberships_str = ''; foreach ($memberships as $membership) { + $memberships_str = ! empty($memberships_str) ? $memberships_str . ', ' . $membership->id : $membership->id; + } - $memberships_str = !empty($memberships_str) ? $memberships_str . ', ' . $membership->id : $membership->id; - - } // end foreach; - - $customer_id_query = !empty($memberships_str) ? "AND wu_membership_id IN ($memberships_str)" : ''; - - } // end if; + $customer_id_query = ! empty($memberships_str) ? "AND wu_membership_id IN ($memberships_str)" : ''; + } $sql = "SELECT meta_value FROM {$table_name} WHERE meta_key = 'pending_site' $customer_id_query ORDER BY meta_id DESC"; // phpcs:ignore $results = array_column($wpdb->get_results($sql), 'meta_value'); // phpcs:ignore - $results = array_map(function($item) { + $results = array_map( + function ($item) { - $pending_site = unserialize($item); + $pending_site = unserialize($item); - $pending_site->set_type('pending'); + $pending_site->set_type('pending'); - return $pending_site; - - }, $results); + return $pending_site; + }, + $results + ); return $results; - - } // end if; + } $query = $query_args; @@ -1970,8 +1797,7 @@ class Site extends Base_Model { ); return static::query($query); - - } // end get_all_by_type; + } /** * Returns a list of sites of given categories @@ -1997,8 +1823,7 @@ class Site extends Base_Model { ); return static::query($query); - - } // end get_all_by_categories; + } /** * Get the list of all Site Template Categories. @@ -2014,31 +1839,26 @@ class Site extends Base_Model { $cache = wp_cache_get('site_categories', 'sites'); if (is_array($cache)) { - return $cache; - - } // end if; + } $final_array = array(); $query = "SELECT DISTINCT meta_value FROM {$wpdb->base_prefix}blogmeta WHERE meta_key = %s"; - if (!empty($sites)) { + if ( ! empty($sites)) { // Ensures that $sites is a indexed array $sites = array_values($sites); - if (is_a($sites[0], \WP_Ultimo\Models\Site::class)) { - + if (is_a($sites[0], self::class)) { $array_sites = json_decode(json_encode($sites), true); $sites = array_values(array_column($array_sites, 'blog_id')); - - } // end if; + } $query .= ' AND blog_id IN (' . implode(', ', $sites) . ')'; - - } // end if; + } $results = $wpdb->get_results($wpdb->prepare($query, 'wu_categories'), ARRAY_A); // phpcs:ignore @@ -2047,32 +1867,25 @@ class Site extends Base_Model { $all_arrays = array_map('maybe_unserialize', $all_arrays); if ($all_arrays) { - $filtered_array = array(); foreach ($all_arrays as $array) { - if (is_array($array)) { - $filtered_array = array_merge($filtered_array, $array); - - } // end if; - - } // end foreach; + } + } $all_arrays = array_filter($filtered_array); $all_arrays = array_unique($all_arrays); $final_array = array_combine($all_arrays, $all_arrays); - - } // end if; + } wp_cache_set('site_categories', $final_array, 'sites'); return $final_array; - - } // end get_all_categories; + } /** * List of limitations that need to be merged. @@ -2096,15 +1909,11 @@ class Site extends Base_Model { $membership = $this->get_membership(); if ($membership) { - $membership_limitations = $membership->get_limitations(); $limitations_to_merge[] = $membership_limitations; - - } // end if; + } return $limitations_to_merge; - - } // end limitations_to_merge; - -} // end class Site; + } +} diff --git a/inc/models/class-webhook.php b/inc/models/class-webhook.php index 30709e7..493b27d 100644 --- a/inc/models/class-webhook.php +++ b/inc/models/class-webhook.php @@ -121,10 +121,9 @@ class Webhook extends Base_Model { 'active' => 'default:1', 'hidden' => 'default:0', 'integration' => 'required|min:2', - 'date_last_failed' => 'default:' + 'date_last_failed' => 'default:', ); - - } // end validation_rules; + } /** * Get the value of name. @@ -134,8 +133,7 @@ class Webhook extends Base_Model { public function get_name() { return $this->name; - - } // end get_name; + } /** * Set the value of name. @@ -145,8 +143,7 @@ class Webhook extends Base_Model { public function set_name($name) { $this->name = $name; - - } // end set_name; + } /** * Get the value of webhook_url. @@ -156,8 +153,7 @@ class Webhook extends Base_Model { public function get_webhook_url() { return $this->webhook_url; - - } // end get_webhook_url; + } /** * Set the value of webhook_url. @@ -167,8 +163,7 @@ class Webhook extends Base_Model { public function set_webhook_url($webhook_url) { $this->webhook_url = $webhook_url; - - } // end set_webhook_url; + } /** * Get the value of event. @@ -178,8 +173,7 @@ class Webhook extends Base_Model { public function get_event() { return $this->event; - - } // end get_event; + } /** * Set the value of event. @@ -189,8 +183,7 @@ class Webhook extends Base_Model { public function set_event($event) { $this->event = $event; - - } // end set_event; + } /** * Get the value of event_count. @@ -200,8 +193,7 @@ class Webhook extends Base_Model { public function get_event_count() { return (int) $this->event_count; - - } // end get_event_count; + } /** * Set the value of event_count. @@ -211,8 +203,7 @@ class Webhook extends Base_Model { public function set_event_count($event_count) { $this->event_count = $event_count; - - } // end set_event_count; + } /** * Check if this particular mapping is active. @@ -223,8 +214,7 @@ class Webhook extends Base_Model { public function is_active() { return (bool) $this->active; - - } // end is_active; + } /** * Sets the active state of this model object; @@ -237,8 +227,7 @@ class Webhook extends Base_Model { public function set_active($active) { $this->active = (bool) wu_string_to_bool($active); - - } // end set_active; + } /** * Get is this webhook hidden? @@ -248,8 +237,7 @@ class Webhook extends Base_Model { public function is_hidden() { return (bool) $this->hidden; - - } // end is_hidden; + } /** * Set is this webhook hidden? @@ -259,8 +247,7 @@ class Webhook extends Base_Model { public function set_hidden($hidden) { $this->hidden = $hidden; - - } // end set_hidden; + } /** * Get integration name. @@ -270,8 +257,7 @@ class Webhook extends Base_Model { public function get_integration() { return $this->integration; - - } // end get_integration; + } /** * Get date when this was created.. @@ -282,8 +268,7 @@ class Webhook extends Base_Model { public function get_date_created() { return $this->date_created; - - } // end get_date_created; + } /** * Get date when this was created.. @@ -294,8 +279,7 @@ class Webhook extends Base_Model { public function get_date_last_failed() { return $this->date_last_failed; - - } // end get_date_last_failed; + } /** * Set date when this was created.. @@ -307,8 +291,7 @@ class Webhook extends Base_Model { public function set_date_created($date_created) { $this->date_created = $date_created; - - } // end set_date_created; + } /** * Set integration name. @@ -318,7 +301,5 @@ class Webhook extends Base_Model { public function set_integration($integration) { $this->integration = $integration; - - } // end set_integration; - -} // end class Webhook; + } +} diff --git a/inc/models/traits/trait-billable.php b/inc/models/traits/trait-billable.php index 52672e7..e0c6dab 100644 --- a/inc/models/traits/trait-billable.php +++ b/inc/models/traits/trait-billable.php @@ -9,7 +9,7 @@ namespace WP_Ultimo\Models\Traits; -use \WP_Ultimo\Objects\Billing_Address; +use WP_Ultimo\Objects\Billing_Address; /** * Singleton trait. @@ -44,16 +44,13 @@ trait Billable { public function get_billing_address() { if ($this->billing_address === null) { - $billing_address = $this->get_meta('wu_billing_address'); $this->billing_address = is_a($billing_address, '\WP_Ultimo\Objects\Billing_Address') ? $billing_address : $this->get_default_billing_address(); - - } // end if; + } return $this->billing_address; - - } // end get_billing_address; + } /** * Sets the billing address. @@ -66,15 +63,11 @@ trait Billable { public function set_billing_address($billing_address) { if (is_array($billing_address)) { - $billing_address = new Billing_Address($billing_address); - - } // end if; + } $this->meta['wu_billing_address'] = $billing_address; $this->billing_address = $billing_address; - - } // end set_billing_address; - -} // end trait Billable; + } +} diff --git a/inc/models/traits/trait-limitable.php b/inc/models/traits/trait-limitable.php index b038fa6..1078a0d 100644 --- a/inc/models/traits/trait-limitable.php +++ b/inc/models/traits/trait-limitable.php @@ -9,8 +9,8 @@ namespace WP_Ultimo\Models\Traits; -use \WP_Ultimo\Database\Sites\Site_Type; -use \WP_Ultimo\Objects\Limitations; +use WP_Ultimo\Database\Sites\Site_Type; +use WP_Ultimo\Objects\Limitations; /** * Singleton trait. @@ -54,10 +54,8 @@ trait Limitable { * This is because we don't want to limit sites other than the customer owned ones. */ if ($this->model === 'site' && $this->get_type() !== Site_Type::CUSTOMER_OWNED) { - return new Limitations(array()); - - } // end if; + } $cache_key = $waterfall ? '_composite_limitations_' : '_limitations_'; @@ -67,32 +65,23 @@ trait Limitable { $cached_version = wu_get_isset($this->_limitations, $cache_key); - if (!empty($cached_version)) { - + if ( ! empty($cached_version)) { return $cached_version; + } - } // end if; - - if (!is_array($this->meta)) { - + if ( ! is_array($this->meta)) { $this->meta = array(); - - } // end if; + } if (did_action('muplugins_loaded') === false) { - $modules_data = $this->get_meta('wu_limitations', array()); - } else { - $modules_data = Limitations::early_get_limitations($this->model, $this->get_id()); - - } // end if; + } $limitations = new Limitations(array()); if ($waterfall) { - $limitations = $limitations->merge(...$this->limitations_to_merge()); /** @@ -102,23 +91,17 @@ trait Limitable { * This will return only the parents permissions and is super useful for * comparisons. */ - if (!$skip_self) { - + if ( ! $skip_self) { $limitations = $limitations->merge(true, $modules_data); - - } // end if; - + } } else { - $limitations = $limitations->merge($modules_data); + } - } // end if; - - $this->_limitations[$cache_key] = $limitations; + $this->_limitations[ $cache_key ] = $limitations; return $limitations; - - } // end get_limitations; + } /** * Checks if this site has limitations or not. @@ -129,8 +112,7 @@ trait Limitable { public function has_limitations() { return $this->get_limitations()->has_limitations(); - - } // end has_limitations; + } /** * Checks if a particular module is being limited. @@ -143,8 +125,7 @@ trait Limitable { public function has_module_limitation($module) { return $this->get_limitations()->is_module_enabled($module); - - } // end has_module_limitation; + } /** * Returns all user role quotas. @@ -155,8 +136,7 @@ trait Limitable { public function get_user_role_quotas() { return $this->get_limitations()->get_user_role_quotas(); - - } // end get_user_role_quotas; + } /** * Proxy method to retrieve the allowed user roles. @@ -167,8 +147,7 @@ trait Limitable { public function get_allowed_user_roles() { return $this->get_limitations()->get_allowed_user_roles(); - - } // end get_allowed_user_roles; + } /** * Schedules plugins to be activated or deactivated based on the current limitations; @@ -181,50 +160,35 @@ trait Limitable { $sites = array(); if ($this->model === 'site') { - $sites[] = $this; - } elseif ($this->model === 'membership') { - $sites = $this->get_sites(); - - } // end if; + } foreach ($sites as $site_object) { - - if (!$site_object->get_id() || $site_object->get_type() !== Site_Type::CUSTOMER_OWNED) { - + if ( ! $site_object->get_id() || $site_object->get_type() !== Site_Type::CUSTOMER_OWNED) { continue; - - } // end if; + } $site_id = $site_object->get_id(); $limitations = $site_object->get_limitations(); - if (!$limitations->plugins->is_enabled()) { - + if ( ! $limitations->plugins->is_enabled()) { continue; - - } // end if; + } $plugins_to_deactivate = $limitations->plugins->get_by_type('force_inactive'); $plugins_to_activate = $limitations->plugins->get_by_type('force_active'); if ($plugins_to_deactivate) { - wu_async_deactivate_plugins($site_id, array_keys($plugins_to_deactivate)); - - } // end if; + } if ($plugins_to_activate) { - wu_async_activate_plugins($site_id, array_keys($plugins_to_activate)); - - } // end if; - - } // end foreach; - - } // end sync_plugins; + } + } + } /** * Makes sure we save limitations when we are supposed to. @@ -241,11 +205,9 @@ trait Limitable { /* * Only handle limitations if there are to handle in the first place. */ - if (!wu_request('modules')) { - + if ( ! wu_request('modules')) { return; - - } // end if; + } $object_limitations = $this->get_limitations(false); @@ -258,22 +220,16 @@ trait Limitable { $current_limitations = $this->get_limitations(true, true); foreach ($limitations as $limitation_id => $class_name) { - $module = wu_get_isset($saved_limitations, $limitation_id, array()); try { - if (is_string($module)) { - $module = json_decode($module, true); - - } // end if; - + } } catch (\Throwable $exception) { // Silence is golden. - - } // end try; + } $module['enabled'] = $object_limitations->{$limitation_id}->handle_enabled(); @@ -282,32 +238,23 @@ trait Limitable { $module = $object_limitations->{$limitation_id}->handle_others($module); if ($module) { - - $modules_to_save[$limitation_id] = $module; - - } // end if; - - } // end foreach; + $modules_to_save[ $limitation_id ] = $module; + } + } if ($this->model !== 'product') { /* * Set the new permissions, based on the diff. */ $limitations = wu_array_recursive_diff($modules_to_save, $current_limitations->to_array()); - } elseif ($this->model === 'product' && $this->get_type() !== 'plan') { - $limitations = wu_array_recursive_diff($modules_to_save, Limitations::get_empty()->to_array()); - } else { - $limitations = $modules_to_save; - - } // end if; + } $this->meta['wu_limitations'] = $limitations; - - } // end handle_limitations; + } /** * Returns the list of product slugs associated with this model. @@ -318,31 +265,22 @@ trait Limitable { public function get_applicable_product_slugs() { if ($this->model === 'product') { - return array($this->get_slug()); - - } // end if; + } $slugs = array(); if ($this->model === 'membership') { - $membership = $this; - } elseif ($this->model === 'site') { - $membership = $this->get_membership(); + } - } // end if; - - if (!empty($membership)) { - + if ( ! empty($membership)) { $slugs = array_column(array_map('wu_cast_model_to_array', array_column($membership->get_all_products(), 'product')), 'slug'); // WOW - } // end if; + } return $slugs; - - } // end get_applicable_product_slugs; - -} // end trait Limitable; + } +} diff --git a/inc/models/traits/trait-notable.php b/inc/models/traits/trait-notable.php index 2347b27..fb5af15 100644 --- a/inc/models/traits/trait-notable.php +++ b/inc/models/traits/trait-notable.php @@ -9,7 +9,7 @@ namespace WP_Ultimo\Models\Traits; -use \WP_Ultimo\Objects\Note; +use WP_Ultimo\Objects\Note; /** * Singleton trait. @@ -33,14 +33,11 @@ trait Notable { public function get_notes() { if ($this->notes === null) { - $this->notes = get_metadata($this->get_meta_data_table_name(), $this->get_id(), 'wu_note', false); - - } // end if; + } return $this->notes; - - } // end get_notes; + } /** * Adds a new note to this model. @@ -52,25 +49,20 @@ trait Notable { */ public function add_note($note) { - if (!is_a($note, 'Note')) { - + if ( ! is_a($note, 'Note')) { $note = new Note($note); - - } // end if; + } $status = $note->validate(); if (is_wp_error($status)) { - return $status; - - } // end if; + } $status = add_metadata($this->get_meta_data_table_name(), $this->get_id(), 'wu_note', $note, false); return $status; - - } // end add_note; + } /** * Remove all notes related to this model. @@ -83,8 +75,7 @@ trait Notable { $status = delete_metadata($this->get_meta_data_table_name(), $this->get_id(), 'wu_note', '', true); return $status; - - } // end clear_notes; + } /** * Remove one note related to this model. @@ -104,9 +95,7 @@ trait Notable { $mid = false; foreach ($notes as $note) { - if ($note->note_id && $note->note_id === $note_id) { - global $wpdb; $prefix = $wpdb->base_prefix; @@ -116,36 +105,27 @@ trait Notable { $column_name = "wu_{$model}_id"; if ($model === 'site') { - $table_name = "{$wpdb->base_prefix}blogmeta"; $column_name = 'blog_id'; - - } // end if; + } $mid = $wpdb->get_row($wpdb->prepare("SELECT meta_id FROM $table_name WHERE $column_name = %d AND meta_key = %s AND meta_value = %s", $this->get_id(), 'wu_note', maybe_serialize($note)), ARRAY_A); // phpcs:ignore + } + } - } // end if; - - } // end foreach; - - if (!$mid) { - + if ( ! $mid) { return false; - - } // end if; + } $status = delete_metadata_by_mid("wu_{$model}", $mid['meta_id']); if ($model === 'site') { - $status = delete_metadata_by_mid('blog', $mid['meta_id']); - - } // end if; + } return $status; - - } // end delete_note; + } /** * Returns the meta data meta table. @@ -160,12 +140,10 @@ trait Notable { $query_class = new $this->query_class(); // Maybe apply table prefix - $table = !empty($query_class->prefix) + $table = ! empty($query_class->prefix) ? "{$query_class->prefix}_{$query_class->item_name}" : $query_class->item_name; return $table; - - } // end get_meta_data_table_name; - -} // end trait Notable; + } +} diff --git a/inc/objects/class-billing-address.php b/inc/objects/class-billing-address.php index 23ee95e..afa9354 100644 --- a/inc/objects/class-billing-address.php +++ b/inc/objects/class-billing-address.php @@ -37,8 +37,7 @@ class Billing_Address { public function __construct($data = array()) { $this->attributes($data); - - } // end __construct; + } /** * Loops through allowed fields and loads them. @@ -53,16 +52,11 @@ class Billing_Address { $allowed_attributes = array_keys(self::fields()); foreach ($data as $key => $value) { - if (in_array($key, $allowed_attributes, true)) { - - $this->attributes[$key] = $value; - - } // end if; - - } // end foreach; - - } // end attributes; + $this->attributes[ $key ] = $value; + } + } + } /** * Checks if this billing address has any content at all. @@ -72,9 +66,8 @@ class Billing_Address { */ public function exists() { - return !empty(array_filter($this->attributes)); - - } // end exists; + return ! empty(array_filter($this->attributes)); + } /** * Checks if a parameter exists. @@ -87,8 +80,7 @@ class Billing_Address { public function __isset($name) { return wu_get_isset($this->attributes, $name, ''); - - } // end __isset; + } /** * Gets a billing address field. @@ -103,8 +95,7 @@ class Billing_Address { $value = wu_get_isset($this->attributes, $name, ''); return apply_filters("wu_billing_address_get_{$name}", $value, $this); - - } // end __get; + } /** * Sets a billing address field. @@ -118,9 +109,8 @@ class Billing_Address { $value = apply_filters("wu_billing_address_set_{$name}", $value, $this); - $this->attributes[$name] = $value; - - } // end __set; + $this->attributes[ $name ] = $value; + } /** * Returns the validation rules for the billing address fields. * @@ -133,8 +123,7 @@ class Billing_Address { $keys = array_keys(array_filter($fields, fn($item) => wu_get_isset($item, 'validation_rules'))); return array_combine($keys, array_column($fields, 'validation_rules')); - - } // end validation_rules; + } /** * Validates the fields following the validation rules. @@ -144,19 +133,16 @@ class Billing_Address { */ public function validate() { - $validator = new \WP_Ultimo\Helpers\Validator; + $validator = new \WP_Ultimo\Helpers\Validator(); $validator->validate($this->to_array(), $this->validation_rules()); if ($validator->fails()) { - return $validator->get_errors(); - - } // end if; + } return true; - - } // end validate; + } /** * Returns a key => value representation of the billing address. @@ -173,20 +159,15 @@ class Billing_Address { $fields = self::fields(); foreach ($fields as $field_key => $field) { - - if (!empty($this->{$field_key})) { - + if ( ! empty($this->{$field_key})) { $key = $labels ? $field['title'] : $field_key; - $address_array[$key] = $this->{$field_key}; - - } // end if; - - } // end foreach; + $address_array[ $key ] = $this->{$field_key}; + } + } return $address_array; - - } // end to_array; + } /** * Returns a string representation of the billing address. * @@ -204,8 +185,7 @@ class Billing_Address { public function to_string($delimiter = PHP_EOL): string { return implode($delimiter, $this->to_array()); - - } // end to_string; + } /** * Returns the field array with values added. @@ -219,14 +199,11 @@ class Billing_Address { $fields = self::fields($zip_only); foreach ($fields as $field_key => &$field) { - $field['value'] = $this->{$field_key}; - - } // end foreach; + } return $fields; - - } // end get_fields; + } /** * Billing Address field definitions. @@ -246,23 +223,17 @@ class Billing_Address { // Get allowed countries in form if ($checkout_form && $checkout_form->has_country_lock()) { - $allowed_countries = $checkout_form->get_allowed_countries(); // Allow the Select Country field $allowed_countries[] = ''; foreach ($countries as $country_code => $country) { - - if (!in_array($country_code, $allowed_countries, true)) { - - unset($countries[$country_code]); - - } // end if; - - } // end foreach; - - } // end if; + if ( ! in_array($country_code, $allowed_countries, true)) { + unset($countries[ $country_code ]); + } + } + } $fields['company_name'] = array( 'type' => 'text', @@ -329,13 +300,11 @@ class Billing_Address { $fields = wu_set_order_from_index($fields); // Adds missing order attributes if ($zip_only) { - $fields = array( 'billing_zip_code' => $fields['billing_zip_code'], 'billing_country' => $fields['billing_country'], ); - - } // end if; + } /** * Allow plugin developers to filter the billing address fields. @@ -343,7 +312,7 @@ class Billing_Address { * @since 2.0.0 * * @param array $fields Billing Address array. - * @param bool $zip_only If we only need zip and country. + * @param bool $zip_only If we only need zip and country. * @return array */ $fields = apply_filters('wu_billing_address_fields', $fields, $zip_only); @@ -351,8 +320,7 @@ class Billing_Address { uasort($fields, 'wu_sort_by_order'); return $fields; - - } // end fields; + } /** * Billing Address fields array for REST API. @@ -366,27 +334,21 @@ class Billing_Address { $fields_for_rest = array(); foreach (self::fields($zip_only) as $field_key => $field) { - $options = wu_get_isset($field, 'options', false); $enum = is_callable($options) ? call_user_func($options) : false; - $fields_for_rest[$field_key] = array( + $fields_for_rest[ $field_key ] = array( 'description' => wu_get_isset($field, 'title', false) . '. ' . wu_get_isset($field, 'default_placeholder', false), 'type' => 'string', 'required' => wu_get_isset($field, 'required', false), ); if ($enum) { - - $fields_for_rest[$field_key]['enum'] = array_keys($enum); - - } // end if; - - } // end foreach; + $fields_for_rest[ $field_key ]['enum'] = array_keys($enum); + } + } return $fields_for_rest; - - } // end fields_for_rest; - -} // end class Billing_Address; + } +} diff --git a/inc/objects/class-limitations.php b/inc/objects/class-limitations.php index 1565f55..8e6f6d2 100644 --- a/inc/objects/class-limitations.php +++ b/inc/objects/class-limitations.php @@ -68,8 +68,7 @@ class Limitations { public function __construct($modules_data = array()) { $this->build_modules($modules_data); - - } // end __construct; + } /** * Returns the module via magic getter. @@ -84,26 +83,21 @@ class Limitations { $module = wu_get_isset($this->modules, $name, false); if ($module === false) { - $repo = self::repository(); $class_name = wu_get_isset($repo, $name, false); if (class_exists($class_name)) { - $module = new $class_name(array()); - $this->modules[$name] = $module; + $this->modules[ $name ] = $module; return $module; - - } // end if; - - } // end if; + } + } return $module; - - } // end __get; + } /** * Prepare to serialization. @@ -115,8 +109,7 @@ class Limitations { public function __serialize() { // phpcs:ignore return $this->to_array(); - - } // end __serialize; + } /** * Handles un-serialization. @@ -130,8 +123,7 @@ class Limitations { public function __unserialize($modules_data) { // phpcs:ignore $this->build_modules($modules_data); - - } // end __unserialize; + } /** * Builds the module list based on the module data. @@ -144,48 +136,38 @@ class Limitations { public function build_modules($modules_data) { foreach ($modules_data as $type => $data) { - $module = self::build($data, $type); if ($module) { - - $this->modules[$type] = $module; - - } // end if; - - } // end foreach; + $this->modules[ $type ] = $module; + } + } return $this; - - } // end build_modules; - /** - * Build a module, based on the data. - * - * @since 2.0.0 - * - * @param string|array $data The module data. - * @param string $module_name The module_name. - * @return false|\WP_Ultimo\Limitations\Limit - */ - static public function build($data, $module_name) { + } + /** + * Build a module, based on the data. + * + * @since 2.0.0 + * + * @param string|array $data The module data. + * @param string $module_name The module_name. + * @return false|\WP_Ultimo\Limitations\Limit + */ + public static function build($data, $module_name) { $class = wu_get_isset(self::repository(), $module_name); if (class_exists($class)) { - if (is_string($data)) { - $data = json_decode($data, true); - } return new $class($data); - - } // end if; + } return false; - - } // end build; + } /** * Checks if a limitation model exists in this limitations. @@ -198,8 +180,7 @@ class Limitations { public function exists($module) { return wu_get_isset($this->modules, $module, false); - - } // end exists; + } /** * Checks if we have any limitation modules setup at all. @@ -212,18 +193,13 @@ class Limitations { $has_limitations = false; foreach ($this->modules as $module) { - if ($module->is_enabled()) { - return true; - - } // end if; - - } // end foreach; + } + } return $has_limitations; - - } // end has_limitations; + } /** * Checks if a particular module is enabled. @@ -238,8 +214,7 @@ class Limitations { $module = $this->{$module_name}; return $module ? $module->is_enabled() : false; - - } // end is_module_enabled; + } /** * Merges limitations from other entities. @@ -257,37 +232,29 @@ class Limitations { */ public function merge($override = false, ...$limitations) { - if (!is_bool($override)) { - + if ( ! is_bool($override)) { $limitations[] = $override; $override = false; - - } // end if; + } $results = $this->to_array(); foreach ($limitations as $limitation) { - - if (is_a($limitation, \WP_Ultimo\Objects\Limitations::class)) { // @phpstan-ignore-line + if (is_a($limitation, self::class)) { // @phpstan-ignore-line $limitation = $limitation->to_array(); + } - } // end if; - - if (!is_array($limitation)) { - + if ( ! is_array($limitation)) { continue; + } - } // end if; - - $this->merge_recursive($results, $limitation, !$override); - - } // end foreach; + $this->merge_recursive($results, $limitation, ! $override); + } return new self($results); - - } // end merge; + } /** * Merges a limitation array @@ -310,26 +277,20 @@ class Limitations { $force_enabled = in_array($current_id, $force_enabled_list, true); - if ($force_enabled && (!wu_get_isset($array1, 'enabled', true) || !wu_get_isset($array2, 'enabled', true))) { - + if ($force_enabled && (! wu_get_isset($array1, 'enabled', true) || ! wu_get_isset($array2, 'enabled', true))) { $array1['enabled'] = true; $array2['enabled'] = true; + } - } // end if; - - if (!wu_get_isset($array1, 'enabled', true)) { - + if ( ! wu_get_isset($array1, 'enabled', true)) { $array1 = array( 'enabled' => false, ); + } - } // end if; - - if (!wu_get_isset($array2, 'enabled', true) && $should_sum) { - + if ( ! wu_get_isset($array2, 'enabled', true) && $should_sum) { return; - - } // end if; + } foreach ($array2 as $key => &$value) { /** @@ -338,24 +299,19 @@ class Limitations { */ $value = is_object($value) ? get_object_vars($value) : $value; - if (isset($array1[$key])) { + if (isset($array1[ $key ])) { + $array1[ $key ] = is_object($array1[ $key ]) ? get_object_vars($array1[ $key ]) : $array1[ $key ]; + } - $array1[$key] = is_object($array1[$key]) ? get_object_vars($array1[$key]) : $array1[$key]; - - } // end if; - - if (is_array($value) && isset($array1[$key]) && is_array($array1[$key])) { - - $array1_id = wu_get_isset($array1[$key], 'id', $current_id); + if (is_array($value) && isset($array1[ $key ]) && is_array($array1[ $key ])) { + $array1_id = wu_get_isset($array1[ $key ], 'id', $current_id); $this->current_merge_id = wu_get_isset($value, 'id', $array1_id); - $this->merge_recursive($array1[$key], $value, $should_sum); + $this->merge_recursive($array1[ $key ], $value, $should_sum); $this->current_merge_id = $current_id; - } else { - $original_value = wu_get_isset($array1, $key); // If the value is 0 or '' it can be a unlimited value @@ -366,22 +322,16 @@ class Limitations { * We use values 0 or '' as unlimited in our limits */ continue; - - } elseif (isset($array1[$key]) && is_numeric($array1[$key]) && is_numeric($value) && $should_sum && !$is_unlimited) { - - $array1[$key] = ((int) $array1[$key]) + $value; - - } elseif ($key === 'visibility' && isset($array1[$key]) && $should_sum) { - + } elseif (isset($array1[ $key ]) && is_numeric($array1[ $key ]) && is_numeric($value) && $should_sum && ! $is_unlimited) { + $array1[ $key ] = ((int) $array1[ $key ]) + $value; + } elseif ($key === 'visibility' && isset($array1[ $key ]) && $should_sum) { $key_priority = array( 'hidden' => 0, 'visible' => 1, ); - $array1[$key] = $key_priority[$value] > $key_priority[$array1[$key]] ? $value : $array1[$key]; - - } elseif ($key === 'behavior' && isset($array1[$key]) && $should_sum) { - + $array1[ $key ] = $key_priority[ $value ] > $key_priority[ $array1[ $key ] ] ? $value : $array1[ $key ]; + } elseif ($key === 'behavior' && isset($array1[ $key ]) && $should_sum) { $key_priority_list = array( 'plugins' => array( 'default' => 10, @@ -402,24 +352,19 @@ class Limitations { ), ); - $key_priority = apply_filters("wu_limitation_{$current_id}_priority", $key_priority_list[$current_id]); - - $array1[$key] = $key_priority[$value] > $key_priority[$array1[$key]] ? $value : $array1[$key]; + $key_priority = apply_filters("wu_limitation_{$current_id}_priority", $key_priority_list[ $current_id ]); + $array1[ $key ] = $key_priority[ $value ] > $key_priority[ $array1[ $key ] ] ? $value : $array1[ $key ]; } else { // Avoid change true values - $array1[$key] = $original_value !== true || !$should_sum ? $value : true; + $array1[ $key ] = $original_value !== true || ! $should_sum ? $value : true; - $array1[$key] = $original_value !== true || !$should_sum ? $value : true; - - } // end if; - - } // end if; - - } // end foreach; - - } // end merge_recursive; + $array1[ $key ] = $original_value !== true || ! $should_sum ? $value : true; + } + } + } + } /** * Converts the limitations list to an array. * @@ -428,8 +373,7 @@ class Limitations { public function to_array(): array { return array_map(fn($module) => method_exists($module, 'to_array') ? $module->to_array() : (array) $module, $this->modules); - - } // end to_array; + } /** * Static method to return limitations in very early stages of the WordPress lifecycle. @@ -449,22 +393,18 @@ class Limitations { * for the native tables of blogs. */ if ($slug === 'site') { - $slug = 'blog'; $wu_prefix = ''; - - } // end if; + } $cache = static::$limitations_cache; $key = sprintf('%s-%s', $slug, $id); - if (isset($cache[$key])) { - - return $cache[$key]; - - } // end if; + if (isset($cache[ $key ])) { + return $cache[ $key ]; + } global $wpdb; @@ -476,20 +416,17 @@ class Limitations { $results = $wpdb->get_var($sql); // phpcs:ignore - if (!empty($results)) { - + if ( ! empty($results)) { $limitations = unserialize($results); - - } // end if; + } /* * Caches the results. */ - static::$limitations_cache[$key] = $limitations; + static::$limitations_cache[ $key ] = $limitations; return $limitations; - - } // end early_get_limitations; + } /** * Delete limitations. @@ -511,20 +448,17 @@ class Limitations { * so no need to use low-level sql calls. */ if ($slug === 'site') { - $wu_prefix = ''; $slug = 'blog'; - - } // end if; + } $table_name = "{$wpdb->base_prefix}{$wu_prefix}{$slug}meta"; $sql = $wpdb->prepare("DELETE FROM {$table_name} WHERE meta_key = 'wu_limitations' AND {$wu_prefix}{$slug}_id = %d LIMIT 1", $id); // phpcs:ignore $wpdb->get_var($sql); // phpcs:ignore - - } // end remove_limitations; + } /** * Returns an empty permission set, with modules. @@ -532,19 +466,16 @@ class Limitations { * @since 2.0.0 * @return self */ - static public function get_empty() { + public static function get_empty() { $limitations = new self(); foreach (array_keys(self::repository()) as $module_name) { - $limitations->{$module_name}; - - } // end foreach; + } return $limitations; - - } // end get_empty; + } /** * Repository of the limitation modules. @@ -554,7 +485,7 @@ class Limitations { * @since 2.0.0 * @return array */ - static public function repository() { + public static function repository() { $classes = array( 'post_types' => \WP_Ultimo\Limitations\Limit_Post_Types::class, @@ -570,7 +501,5 @@ class Limitations { ); return apply_filters('wu_limit_classes', $classes); - - } // end repository; - -} // end class Limitations; + } +} diff --git a/inc/objects/class-note.php b/inc/objects/class-note.php index f89179b..12ecafc 100644 --- a/inc/objects/class-note.php +++ b/inc/objects/class-note.php @@ -37,8 +37,7 @@ class Note { public function __construct($data = array()) { $this->attributes($data); - - } // end __construct; + } /** * Loops through allowed fields and loads them. @@ -53,18 +52,13 @@ class Note { $allowed_attributes = array_keys(self::fields()); foreach ($data as $key => $value) { - if (in_array($key, $allowed_attributes, true)) { - - $this->attributes[$key] = $value; - - } // end if; - - } // end foreach; + $this->attributes[ $key ] = $value; + } + } $this->attributes['date_created'] = wu_get_current_time('mysql', true); - - } // end attributes; + } /** * Checks if this note has any content at all. @@ -74,9 +68,8 @@ class Note { */ public function exists() { - return !empty(array_filter($this->attributes)); - - } // end exists; + return ! empty(array_filter($this->attributes)); + } /** * Checks if a parameter exists. @@ -89,8 +82,7 @@ class Note { public function __isset($name) { return wu_get_isset($this->attributes, $name, ''); - - } // end __isset; + } /** * Gets a note field. @@ -105,8 +97,7 @@ class Note { $value = wu_get_isset($this->attributes, $name, ''); return apply_filters("wu_note_get_{$name}", $value, $this); - - } // end __get; + } /** * Sets a note field. @@ -120,9 +111,8 @@ class Note { $value = apply_filters("wu_note_set_{$name}", $value, $this); - $this->attributes[$name] = $value; - - } // end __set; + $this->attributes[ $name ] = $value; + } /** * Returns the validation rules for new notes. @@ -133,8 +123,7 @@ class Note { protected function validation_rules() { return array(); - - } // end validation_rules; + } /** * Validates the fields following the validation rules. @@ -144,19 +133,16 @@ class Note { */ public function validate() { - $validator = new \WP_Ultimo\Helpers\Validator; + $validator = new \WP_Ultimo\Helpers\Validator(); $validator->validate($this->to_array(), $this->validation_rules()); if ($validator->fails()) { - return $validator->get_errors(); - - } // end if; + } return true; - - } // end validate; + } /** * Returns a key => value representation of the notes fields. @@ -173,20 +159,15 @@ class Note { $fields = self::fields(); foreach ($fields as $field_key => $field) { - - if (!empty($this->{$field_key})) { - + if ( ! empty($this->{$field_key})) { $key = $labels ? $field['title'] : $field_key; - $address_array[$key] = $this->{$field_key}; - - } // end if; - - } // end foreach; + $address_array[ $key ] = $this->{$field_key}; + } + } return $address_array; - - } // end to_array; + } /** * Returns the contents of the note. * @@ -197,8 +178,7 @@ class Note { public function to_string($delimiter = PHP_EOL): string { return implode($delimiter, $this->to_array()); - - } // end to_string; + } /** * Note field definitions. @@ -230,7 +210,5 @@ class Note { uasort($fields, 'wu_sort_by_order'); return $fields; - - } // end fields; - -} // end class Note; + } +} diff --git a/inc/objects/class-visits.php b/inc/objects/class-visits.php index 2e167b5..3509ae0 100644 --- a/inc/objects/class-visits.php +++ b/inc/objects/class-visits.php @@ -23,10 +23,10 @@ class Visits { * Key to save on the database. */ const KEY = 'wu_visits'; - /** - * @var int - */ - protected $site_id; + /** + * @var int + */ + protected $site_id; /** * Sets the current site to manage. @@ -35,10 +35,9 @@ class Visits { * * @param int $site_id The current site id. */ - public function __construct($site_id) - { - $this->site_id = $site_id; - } // end __construct; + public function __construct($site_id) { + $this->site_id = $site_id; + } /** * Returns the meta key to save visits. * @@ -49,8 +48,7 @@ class Visits { protected function get_meta_key($day): string { return sprintf('%s_%s', self::KEY, $day); - - } // end get_meta_key; + } /** * Adds visits to a site count. @@ -63,11 +61,9 @@ class Visits { */ public function add_visit($count = 1, $day = false) { - if (!$day) { - + if ( ! $day) { $day = gmdate('Ymd'); - - } // end if; + } $key = $this->get_meta_key($day); @@ -76,8 +72,7 @@ class Visits { $new_value = $current_value + $count; return update_site_meta($this->site_id, $key, $new_value); - - } // end add_visit; + } /** * Returns an array of the dates and counts by day. @@ -92,29 +87,27 @@ class Visits { global $wpdb; - if (!$start_date) { - + if ( ! $start_date) { $start_date = wu_get_current_time('mysql', true); + } - } // end if; - - if (!$end_date) { - + if ( ! $end_date) { $end_date = wu_get_current_time('mysql', true); + } - } // end if; - - $query = $wpdb->prepare(" + $query = $wpdb->prepare( + " SELECT meta_value as count, str_to_date(meta_key, 'wu_visits_%%Y%%m%%d') as day, blog_id as site_id FROM {$wpdb->base_prefix}blogmeta WHERE blog_id = %d - ", $this->site_id); + ", + $this->site_id + ); $query .= $wpdb->prepare(" AND str_to_date(meta_key, 'wu_visits_%%Y%%m%%d') BETWEEN %s AND %s", gmdate('Y-m-d', strtotime($start_date)), gmdate('Y-m-d', strtotime($end_date))); return $wpdb->get_results($query); // phpcs:ignore - - } // end get_visits; + } /** * The total visits for the current site. @@ -129,29 +122,27 @@ class Visits { global $wpdb; - if (!$start_date) { - + if ( ! $start_date) { $start_date = wu_get_current_time('mysql', true); + } - } // end if; - - if (!$end_date) { - + if ( ! $end_date) { $end_date = wu_get_current_time('mysql', true); + } - } // end if; - - $query = $wpdb->prepare(" + $query = $wpdb->prepare( + " SELECT SUM(meta_value) as count FROM {$wpdb->base_prefix}blogmeta WHERE blog_id = %d - ", $this->site_id); + ", + $this->site_id + ); $query .= $wpdb->prepare(" AND str_to_date(meta_key, 'wu_visits_%%Y%%m%%d') BETWEEN %s AND %s", gmdate('Y-m-d', strtotime($start_date)), gmdate('Y-m-d', strtotime($end_date))); return (int) $wpdb->get_var($query); // phpcs:ignore - - } // end get_visit_total; + } /** * Get sites by visit count. @@ -167,17 +158,13 @@ class Visits { global $wpdb; - if (!$start_date) { - + if ( ! $start_date) { $start_date = wu_get_current_time('mysql', true); + } - } // end if; - - if (!$end_date) { - + if ( ! $end_date) { $end_date = wu_get_current_time('mysql', true); - - } // end if; + } $sub_query = " SELECT SUM(meta_value) as count, blog_id @@ -200,7 +187,5 @@ class Visits { // phpcs:enable return $wpdb->get_results($query); // phpcs:ignore - - } // end get_sites_by_visit_count; - -} // end class Visits; + } +} diff --git a/inc/site-templates/class-template-placeholders.php b/inc/site-templates/class-template-placeholders.php index 9107498..0ac5a7a 100644 --- a/inc/site-templates/class-template-placeholders.php +++ b/inc/site-templates/class-template-placeholders.php @@ -74,8 +74,7 @@ class Template_Placeholders { add_filter('the_content', array($this, 'placeholder_replacer')); add_filter('the_title', array($this, 'placeholder_replacer')); - - } // end init; + } /** * Loads the placeholders to keep them "cached". @@ -85,9 +84,12 @@ class Template_Placeholders { */ protected function load_placeholders() { - $placeholders = wu_get_option('template_placeholders', array( - 'placeholders' => array(), - )); + $placeholders = wu_get_option( + 'template_placeholders', + array( + 'placeholders' => array(), + ) + ); $this->placeholders_as_saved = $placeholders; @@ -109,8 +111,7 @@ class Template_Placeholders { $this->placeholder_keys = array_filter($this->placeholder_keys); $this->placeholder_values = array_filter($this->placeholder_values); $this->placeholders = array_filter($this->placeholders); - - } // end load_placeholders; + } /** * Adds curly braces to the placeholders. @@ -123,8 +124,7 @@ class Template_Placeholders { protected function add_curly_braces($tag) { return "{{{$tag}}}"; - - } // end add_curly_braces; + } /** * Replace the contents with the placeholders. * @@ -135,8 +135,7 @@ class Template_Placeholders { public function placeholder_replacer($content): string { return str_replace($this->placeholder_keys, $this->placeholder_values, $content); - - } // end placeholder_replacer; + } /** * Serve placeholders via ajax. @@ -147,8 +146,7 @@ class Template_Placeholders { public function serve_placeholders_via_ajax() { wp_send_json_success($this->placeholders_as_saved); - - } // end serve_placeholders_via_ajax; + } /** * Save the placeholders. @@ -158,29 +156,33 @@ class Template_Placeholders { */ public function save_placeholders() { - if (!check_ajax_referer('wu_edit_placeholders_editing')) { - - wp_send_json(array( - 'code' => 'not-enough-permissions', - 'message' => __('You don\'t have permission to alter placeholders.', 'wp-ultimo') - )); - - } // end if; + if ( ! check_ajax_referer('wu_edit_placeholders_editing')) { + wp_send_json( + array( + 'code' => 'not-enough-permissions', + 'message' => __('You don\'t have permission to alter placeholders.', 'wp-ultimo'), + ) + ); + } $data = json_decode(file_get_contents('php://input'), true); $placeholders = isset($data['placeholders']) ? $data['placeholders'] : array(); - wu_save_option('template_placeholders', array( - 'placeholders' => $placeholders, - )); + wu_save_option( + 'template_placeholders', + array( + 'placeholders' => $placeholders, + ) + ); - wp_send_json(array( - 'code' => 'success', - 'message' => __('Placeholders successfully updated!', 'wp-ultimo'), - )); - - } // end save_placeholders; + wp_send_json( + array( + 'code' => 'success', + 'message' => __('Placeholders successfully updated!', 'wp-ultimo'), + ) + ); + } /** * Adds the template placeholders admin page. @@ -190,8 +192,6 @@ class Template_Placeholders { */ public function add_template_placeholders_admin_page() { - new \WP_Ultimo\Admin_Pages\Placeholders_Admin_Page; - - } // end add_template_placeholders_admin_page; - -} // end class Template_Placeholders; + new \WP_Ultimo\Admin_Pages\Placeholders_Admin_Page(); + } +} diff --git a/inc/sso/auth-functions.php b/inc/sso/auth-functions.php index f2b1fbd..8a4c501 100644 --- a/inc/sso/auth-functions.php +++ b/inc/sso/auth-functions.php @@ -16,7 +16,7 @@ * @subpackage SSO */ -use \Delight\Cookie\Cookie; +use Delight\Cookie\Cookie; // phpcs:disable @@ -177,7 +177,7 @@ if ( !function_exists( 'auth_redirect' ) ) : return; - } // end if; + } $secure = ( is_ssl() || force_ssl_admin() ); diff --git a/inc/sso/class-sso-broker.php b/inc/sso/class-sso-broker.php index 6fe4237..5d19a03 100644 --- a/inc/sso/class-sso-broker.php +++ b/inc/sso/class-sso-broker.php @@ -12,10 +12,7 @@ namespace WP_Ultimo\SSO; -// Exit if accessed directly -defined('ABSPATH') || exit; - -use \Jasny\SSO\Broker\Broker; +use Jasny\SSO\Broker\Broker; /** * The SSO Broker implementation. @@ -25,37 +22,31 @@ use \Jasny\SSO\Broker\Broker; class SSO_Broker extends Broker { /** - * Checks if the current SSO call is a must-redirect call. - * - * @since 2.0.11 - * @return boolean - */ - public function is_must_redirect_call() { - + * Checks if the current SSO call is a must-redirect call. + * + * @since 2.0.11 + * @return boolean + */ + public function is_must_redirect_call(): bool { return $this->getVerificationCode() === 'must-redirect'; - - } // end is_must_redirect_call; + } /** * Get URL to attach session at SSO server. * * @param array $params The params to be passed. */ - public function getAttachUrl(array $params = array()) : string { // phpcs:ignore + public function getAttachUrl(array $params = array()): string { if ($this->getToken() === null) { - $this->generateToken(); - - } // end if; + } $data = array( 'broker' => $this->broker, 'token' => $this->getToken(), - 'checksum' => $this->generateChecksum('attach') + 'checksum' => $this->generateChecksum('attach'), ); return add_query_arg($data + $params, $this->url); - - } // end getAttachUrl; - -} // end class SSO_Broker; + } +} diff --git a/inc/sso/class-sso-session-handler.php b/inc/sso/class-sso-session-handler.php index a22e7f7..2b6c04d 100644 --- a/inc/sso/class-sso-session-handler.php +++ b/inc/sso/class-sso-session-handler.php @@ -14,9 +14,9 @@ namespace WP_Ultimo\SSO; -use \Jasny\SSO\Server\SessionInterface; -use \Jasny\SSO\ServerException; -use \WP_Ultimo\SSO\Exception\SSO_Session_Exception; +use Jasny\SSO\Server\SessionInterface; +use Jasny\SSO\ServerException; +use WP_Ultimo\SSO\Exception\SSO_Session_Exception; // Exit if accessed directly defined('ABSPATH') || exit; @@ -44,20 +44,16 @@ class SSO_Session_Handler implements SessionInterface { * @param \WP_Ultimo\SSO\SSO|null $sso_manager The sso manager. */ public function __construct(\WP_Ultimo\SSO\SSO $sso_manager = null) { - $this->sso_manager = $sso_manager; - - } // end __construct; + } /** * Returns the session id. * * @since 2.0.11 */ public function getId(): string { // phpcs:ignore - return $this->sso_manager->input('broker'); - - } // end getId; + } /** * Start a new session. * @@ -70,17 +66,14 @@ class SSO_Session_Handler implements SessionInterface { $site_hash = $this->sso_manager->input('broker'); - if (!get_current_user_id()) { - + if ( ! get_current_user_id()) { throw new SSO_Session_Exception('User not logged in.', 401); - - } // end if; + } $id = $this->sso_manager->decode($site_hash, $this->sso_manager->salt()); set_site_transient("sso-{$site_hash}-{$id}", get_current_user_id(), 180); - - } // end start; + } /** * Resume an existing session. * @@ -98,12 +91,9 @@ class SSO_Session_Handler implements SessionInterface { $user_id = get_site_transient("sso-{$id}-{$decoded_id}"); if ($user_id) { - $this->sso_manager->set_target_user_id($user_id); - - } // end if; - - } // end resume; + } + } /** * Check if a session is active. (status PHP_SESSION_ACTIVE). * @@ -112,9 +102,6 @@ class SSO_Session_Handler implements SessionInterface { * @since 2.0.11 */ public function isActive(): bool { // phpcs:ignore - return false; - - } // end isActive; - -} // end class SSO_Session_Handler; + } +} diff --git a/inc/sso/class-sso.php b/inc/sso/class-sso.php index 6518ed4..480899c 100644 --- a/inc/sso/class-sso.php +++ b/inc/sso/class-sso.php @@ -15,17 +15,15 @@ namespace WP_Ultimo\SSO; -use \WP_Ultimo\Helpers\Hash; -use \Jasny\SSO\Server\Server; -use \Jasny\SSO\Server\ServerException; -use \Jasny\SSO\Server\BrokerException; -use \Jasny\SSO\Broker\NotAttachedException; -use \Nyholm\Psr7\Factory\Psr17Factory; -use \Symfony\Component\Cache\Adapter\FilesystemAdapter; -use \Symfony\Component\Cache\Psr16Cache; - -// Exit if accessed directly -defined('ABSPATH') || exit; +use Exception; +use WP_Ultimo\Helpers\Hash; +use Jasny\SSO\Server\Server; +use Jasny\SSO\Server\ServerException; +use Jasny\SSO\Server\BrokerException; +use Jasny\SSO\Broker\NotAttachedException; +use Nyholm\Psr7\Factory\Psr17Factory; +use Symfony\Component\Cache\Adapter\FilesystemAdapter; +use Symfony\Component\Cache\Psr16Cache; /** * Handles Sign-sign on. @@ -74,10 +72,8 @@ class SSO { * @return void */ public function init() { - $this->is_enabled() && $this->startup(); - - } // end init; + } /** * Returns the status of SSO. @@ -90,10 +86,8 @@ class SSO { $enabled = $this->get_setting('enable_sso', true); if (has_filter('mercator.sso.enabled')) { - $enabled = apply_filters_deprecated('mercator.sso.enabled', $enabled, '2.0.0', 'wu_sso_enabled'); - - } // end if; + } /** * Enable/disable cross-domain single-sign-on capability. @@ -106,8 +100,7 @@ class SSO { * @return bool If SSO is enabled or not. */ return apply_filters('wu_sso_enabled', $enabled); - - } // end is_enabled; + } /** * Encode a given string. @@ -119,10 +112,8 @@ class SSO { * @return string The hashed content. */ public function encode($content, $salt) { - return Hash::encode($content, $salt); - - } // end encode; + } /** * Decode a given string. @@ -134,10 +125,8 @@ class SSO { * @return string The original content. */ public function decode($hash, $salt) { - return Hash::decode($hash, $salt); - - } // end decode; + } /** * Get the current url. @@ -146,41 +135,33 @@ class SSO { * @return string */ public function get_current_url() { - return wu_get_current_url(); - - } // end get_current_url; + } /** * Returns the content of a key inside the $_REQUEST array. * - * @since 2.0.11 - * * @param string $key The key to retrieve. - * @param mixed $default The default content. + * @param mixed $default_content The default content. + * * @return mixed */ - public function input($key, $default = false) { - - return wu_request($key, $default); - - } // end input; + public function input($key, $default_content = false) { + return wu_request($key, $default_content); + } /** - * Returns the content of a array key, if it exists. + * Returns the content of an array key, if it exists. * - * @since 2.0.11 - * - * @param array $array The array to check. + * @param array $array_checked The array to check. * @param string $key The key to test and return. - * @param mixed $default The default content to return. + * @param mixed $default_value The default content to return. + * * @return mixed */ - public function get_isset($array, $key, $default = false) { - - return wu_get_isset($array, $key, $default); - - } // end get_isset; + public function get_isset($array_checked, $key, $default_value = false) { + return wu_get_isset($array_checked, $key, $default_value); + } /** * Get settings and preferences. @@ -188,14 +169,12 @@ class SSO { * @since 2.0.11 * * @param string $key The setting to retrieve. - * @param mixed $default The default value to return, if no setting is found. + * @param mixed $default_value The default value to return, if no setting is found. * @return mixed */ - public function get_setting($key, $default = false) { - - return wu_get_setting($key, $default); - - } // end get_setting; + public function get_setting($key, $default_value = false) { + return wu_get_setting($key, $default_value); + } /** * Startup the SSO hooks and filters. @@ -302,8 +281,7 @@ class SSO { * on init, so later functionality can also hook into it. */ add_action('init', array($this, 'loaded_on_init')); - - } // end startup; + } /** * Late loaded hook, triggered on init. @@ -312,10 +290,8 @@ class SSO { * @return void */ public function loaded_on_init() { - do_action('wu_sso_loaded_on_init', $this); - - } // end loaded_on_init; + } /** * Changes the default WordPress requirements for setting the logged in cookie @@ -327,10 +303,8 @@ class SSO { * @return boolean */ public function force_secure_login_cookie() { - return is_ssl(); - - } // end force_secure_login_cookie; + } /** * Bypasses the auth redirect on the wp-admin side of things. @@ -349,15 +323,12 @@ class SSO { $broker = $this->get_broker(); - if (!$broker) { - - } // end if; + if ( ! $broker) { + } if ($broker->is_must_redirect_call()) { - return false; - - } // end if; + } $sso_path = $this->get_url_path(); @@ -369,10 +340,8 @@ class SSO { * login redirect. */ if ($this->input($sso_path) && $this->input($sso_path) !== 'done') { - return true; - - } // end if; + } $should_skip_redirect = $this->get_isset($_COOKIE, 'wu_sso_denied', false); @@ -385,23 +354,24 @@ class SSO { * 2. If the user is logged in or not; * 3. If we should skip the redirect, based on previous attempts. */ - if (!wu_is_same_domain() && !is_user_logged_in() && !$should_skip_redirect) { - + if ( ! wu_is_same_domain() && ! is_user_logged_in() && ! $should_skip_redirect) { nocache_headers(); $test = get_admin_url(); - $redirect_after = $pagenow === 'index.php' ? '' : $this->get_current_url(); + $redirect_after = 'index.php' === $pagenow ? '' : $this->get_current_url(); - $redirect_url = add_query_arg(array( - $sso_path => 'login' - ), wp_login_url($redirect_after)); + $redirect_url = add_query_arg( + array( + $sso_path => 'login', + ), + wp_login_url($redirect_after) + ); wp_redirect($redirect_url); exit; - - } // end if; + } /** * Fix the redirect URL, just to be sure @@ -409,9 +379,12 @@ class SSO { * * @since 2.0.11 */ - $_SERVER['REQUEST_URI'] = str_replace('https://a.com/', '', remove_query_arg('sso', 'https://a.com/' . $_SERVER['REQUEST_URI'])); - - } // end handle_auth_redirect; + $_SERVER['REQUEST_URI'] = str_replace( + 'https://a.com/', + '', + remove_query_arg('sso', 'https://a.com/' . $_SERVER['REQUEST_URI']) + ); + } /** * Listens for SSO requests and route them to the correct handler. @@ -423,11 +396,9 @@ class SSO { $action = $this->get_sso_action(); - if (!$action) { - + if ( ! $action) { return; - - } // end if; + } header('Access-Control-Allow-Headers: Content-Type'); @@ -444,8 +415,7 @@ class SSO { do_action('wu_sso_handle', $action, $return_type, $this); do_action("wu_sso_handle_{$action}", $return_type, $this); - - } // end handle_requests; + } /** * Handles the SSO server side of the auth protocol. @@ -462,45 +432,36 @@ class SSO { $server = $this->get_server(); try { - $verification_code = $server->attach(); $error = null; - } catch (Exception\SSO_Session_Exception $e) { - if (is_ssl()) { - $verification_code = null; $error = array( 'code' => $e->getCode(), 'message' => $e->getMessage(), ); - } else { - $verification_code = 'must-redirect'; - - } // end if; - + } } catch (\Throwable $th) { - $verification_code = null; $error = array( 'code' => $th->getCode(), 'message' => $th->getMessage(), ); + } - } // end try; - - if ($response_type === 'jsonp') { - - $data = json_encode($error ?? array( // phpcs:ignore - 'code' => 200, - 'verify' => $verification_code, - 'return_url' => $this->input('return_url', ''), - )); + if ('jsonp' === $response_type) { + $data = wp_json_encode( + $error ?? array( // phpcs:ignore + 'code' => 200, + 'verify' => $verification_code, + 'return_url' => $this->input('return_url', ''), + ) + ); $response_code = 200; // phpcs:ignore @@ -509,18 +470,14 @@ class SSO { status_header($response_code); exit; - } elseif ($response_type === 'redirect') { - $args = array( 'sso_verify' => $verification_code ? $verification_code : 'invalid', ); if (isset($error) && $error) { - $args['sso_error'] = $error['message']; - - } // end if; + } $return_url = remove_query_arg('sso_verify', $_GET['return_url']); @@ -529,10 +486,8 @@ class SSO { wp_redirect($url, 303, 'WP-Ultimo-SSO'); exit; - - } // end if; - - } // end handle_server; + } + } /** * Handles the broker side of the SSO protocol. @@ -545,16 +500,12 @@ class SSO { public function handle_broker($response_type = 'redirect') { if (is_main_site()) { - return; - - } // end if; + } if (is_user_logged_in()) { - return; - - } // end if; + } nocache_headers(); @@ -563,7 +514,6 @@ class SSO { $verify_code = $this->input('sso_verify'); if ($verify_code) { - $broker->verify($verify_code); $url = $this->input('return_url', $this->get_current_url()); @@ -573,43 +523,37 @@ class SSO { wp_redirect($redirect_url, 302, 'WP-Ultimo-SSO'); exit; + } - } // end if; - - // Attach through redirect if the client isn't attached yet. - if (!$broker->isAttached()) { - + // Attach through redirect if the client isn't attached yet. + if ( ! $broker->isAttached()) { $return_url = $this->get_current_url(); - if ($response_type === 'jsonp') { - - $attach_url = $broker->getAttachUrl(array( - '_jsonp' => '1', - )); - + if ( 'jsonp' === $response_type) { + $attach_url = $broker->getAttachUrl( + array( + '_jsonp' => '1', + ) + ); } else { - - $attach_url = $broker->getAttachUrl(array( - 'return_url' => $return_url, - )); - - } // end if; + $attach_url = $broker->getAttachUrl( + array( + 'return_url' => $return_url, + ) + ); + } wp_redirect($attach_url, 302, 'WP-Ultimo-SSO'); exit(); - - } // end if; + } if ($response_type === 'jsonp') { - echo '// Nothing to see here.'; exit; - - } // end if; - - } // end handle_broker; + } + } /** * Filters the list of allowed origins to add @@ -632,41 +576,38 @@ class SSO { $origin_url = wp_parse_url(get_http_origin()); - $sites = get_sites(array( - 'network_id' => get_current_network_id(), - 'domain' => $this->get_isset($origin_url, 'host', 'invalid'), - )); + $sites = get_sites( + array( + 'network_id' => get_current_network_id(), + 'domain' => $this->get_isset($origin_url, 'host', 'invalid'), + ) + ); if ($sites) { - $additional_domains[] = sprintf('http://%s', $this->get_isset($origin_url, 'host', 'invalid')); $additional_domains[] = sprintf('https://%s', $this->get_isset($origin_url, 'host', 'invalid')); - - } // end if; + } $site = get_site_by_path($this->get_isset($origin_url, 'host', 'invalid'), $this->get_isset($origin_url, 'path', '/')); if ($site) { - - $domains = wu_get_domains(array( - 'active' => true, - 'blog_id' => $site->blog_id, - 'stage__not_in' => \WP_Ultimo\Models\Domain::INACTIVE_STAGES, - 'fields' => 'domain', - )); + $domains = wu_get_domains( + array( + 'active' => true, + 'blog_id' => $site->blog_id, + 'stage__not_in' => \WP_Ultimo\Models\Domain::INACTIVE_STAGES, + 'fields' => 'domain', + ) + ); foreach ($domains as $domain) { - $additional_domains[] = "http://{$domain}"; $additional_domains[] = "https://{$domain}"; - - } // end foreach; - - } // end if; + } + } return array_merge($allowed_origins, $additional_domains); - - } // end add_additional_origins; + } /** * Determines the current user based on the Bearer token received. @@ -682,16 +623,13 @@ class SSO { $sso_path = $this->get_url_path(); - if (!$this->input($sso_path) || $this->input($sso_path) !== 'done') { - + if ( ! $this->input($sso_path) || $this->input($sso_path) !== 'done') { return $current_user_id; - - } // end if; + } $broker = $this->get_broker(); try { - $bearer = $broker->getBearerToken(); $server_request = $this->build_server_request('GET', $this->get_current_url())->withHeader('Authorization', "Bearer $bearer"); @@ -699,23 +637,16 @@ class SSO { $this->get_server()->startBrokerSession($server_request); if ($this->get_target_user_id()) { - wp_set_auth_cookie($this->get_target_user_id(), true); - if ($pagenow === 'wp-login.php') { - + if ('wp-login.php' === $pagenow) { wp_redirect(wu_request('redirect_to', get_admin_url())); - exit; - - } // end if; + } return $this->get_target_user_id(); - - } // end if; - + } } catch (\Throwable $exception) { - /** * We don't need to handle the exceptions here * as we mostly just want to ignore this and move @@ -726,12 +657,9 @@ class SSO { * @throws BrokerException * @throws NotAttachedException */ - - } // end try; - + } return $current_user_id; - - } // end determine_current_user; + } /** * Convert a user determined by a bearer into a cookie-based auth. @@ -744,16 +672,13 @@ class SSO { $broker = $this->get_broker(); if (is_user_logged_in() && $broker && $broker->isAttached()) { - $broker->clearToken(); $id = $this->decode($broker->getBrokerId(), $this->salt()); delete_site_transient(sprintf('sso-%s-%s', $broker->getBrokerId(), $id)); - - } // end if; - - } // end convert_bearer_into_auth_cookies; + } + } /** * Add the SSO tags to the removable query args. @@ -768,8 +693,7 @@ class SSO { $removable_query_args[] = $this->get_url_path(); return $removable_query_args; - - } // end add_sso_removable_query_args; + } /** * Adds the front-end script to trigger SSO flows @@ -780,32 +704,22 @@ class SSO { */ public function enqueue_script() { - global $pagenow; - if (is_main_site()) { - return; - - } // end if; + } if ($this->get_setting('restrict_sso_to_login_pages', false)) { - if (wu_is_login_page() === false) { - return; - - } // end if; - - } // end if; + } + } /* * The visitor is actively trying to logout. Let them do it! */ if ($this->input('action', 'nothing') === 'logout' || $this->input('loggedout')) { - return; - - } // end if; + } wp_register_script('wu-detect-incognito', wu_get_asset('detectincognito.js', 'js/lib'), false, wu_get_version()); @@ -834,8 +748,7 @@ class SSO { wp_localize_script('wu-sso', 'wu_sso_config', $options); wp_enqueue_script('wu-sso'); - - } // end enqueue_script; + } /** * Gets the strategy to be used by default. @@ -853,18 +766,13 @@ class SSO { $env = 'development'; if (function_exists('wp_get_environment_type')) { - $env = wp_get_environment_type(); - } else { - $env = defined('WP_DEBUG') && WP_DEBUG ? 'development' : 'production'; + } - } // end if; - - return apply_filters('wu_sso_get_strategy', $env === 'development' ? 'redirect' : 'ajax', $env, $this); - - } // end get_strategy; + return apply_filters('wu_sso_get_strategy', 'development' === $env ? 'redirect' : 'ajax', $env, $this); + } /** * Gets the final return URL. @@ -881,10 +789,8 @@ class SSO { $query_values = array(); if (isset($parsed_url['query'])) { - parse_str($parsed_url['query'], $query_values); - - } // end if; + } $sso_path = $this->get_url_path(); @@ -902,17 +808,14 @@ class SSO { ); if (isset($query_values['redirect_to'])) { - - $args['redirect_to'] = urlencode($query_values['redirect_to']); - - } // end if; + $args['redirect_to'] = rawurlencode($query_values['redirect_to']); + } // We should use the login URL to avoid cache issues. $login_url = wp_login_url(wu_get_isset($query_values, 'redirect_to', implode('/', $fragments))); return add_query_arg($args, $login_url); - - } // end get_final_return_url; + } /** * Get the return type we need to use. @@ -931,8 +834,7 @@ class SSO { $received_type = $this->input('return_type', 'redirect'); return in_array($received_type, $allowed_return_types, true) ? $received_type : 'redirect'; - - } // end get_return_type; + } /** * Parses the request and gets the SSO action to perform. @@ -954,27 +856,19 @@ class SSO { $action = $this->get_isset($m, 0, ''); - if (!$action) { - + if ( ! $action) { $action = $this->input($sso_path, 'done') !== 'done' ? $sso_path : ''; - - } // end if; - - if (!$action) { - + } + if ( ! $action) { $action = $this->input("$sso_path-grant", 'done') !== 'done' ? "$sso_path-grant" : ''; + } - } // end if; - - if (!$action) { - + if ( ! $action) { $action = $this->input("{$sso_path}_verify", '') !== '' ? $sso_path : ''; - - } // end if; + } return $action; - - } // end get_sso_action; + } /** * Returns the salt to be used on the hashing functions. @@ -983,10 +877,8 @@ class SSO { * @return string */ public function salt() { - return apply_filters('wu_sso_salt', wp_salt(), $this); - - } // end salt; + } /** * Returns a PSR16-compatible cache implementation. @@ -996,18 +888,15 @@ class SSO { */ public function cache() { - if ($this->cache === null) { - + if (null === $this->cache) { // the PSR-6 cache object that you want to use $psr6_cache = new FilesystemAdapter(); $this->cache = new Psr16Cache($psr6_cache); - - } // end if; + } return apply_filters('wu_sso_cache', $this->cache, $this); - - } // end cache; + } /** * Creates a PSR7 Server Request object. @@ -1024,8 +913,7 @@ class SSO { $request = $psr7_server_request_builder->createServerRequest('GET', $url); return apply_filters('wu_sso_server_request', $request, $url, $this); - - } // end build_server_request; + } /** * Returns a PSR3 logger interface that we can use to log SSO results. @@ -1035,13 +923,10 @@ class SSO { */ public function logger() { - if ($this->logger === null) { - + if (null === $this->logger) { return apply_filters('wu_sso_logger', $this->logger, $this); - - } // end if; - - } // end logger; + } + } /** * Creates a secret based on the date of registration of a sub-site. @@ -1050,24 +935,20 @@ class SSO { * * @param string $date The date to use. * @return string The hashed secret. + * @throws Exception\SSO_Exception Failure. */ public function calculate_secret_from_date($date) { $tz = new \DateTimeZone('GMT'); try { - $int_version = (int) \DateTime::createFromFormat('Y-m-d H:i:s', $date, $tz)->format('mdisY'); - } catch (\Throwable $exception) { - throw new Exception\SSO_Exception(__('SSO secret creation failed.', 'wp-ultimo'), 500); - - } // end try; + } return wp_hash($int_version); - - } // end calculate_secret_from_date; + } /** * Returns the server object to be used on the SSO protocol. @@ -1082,8 +963,7 @@ class SSO { $server = (new Server(array($this, 'get_broker_by_id'), $this->cache()))->withSession($session_handler); return apply_filters('wu_sso_get_server', $server, $this); - - } // end get_server; + } /** * Gets a sub-site based on the broker id passed. @@ -1101,11 +981,9 @@ class SSO { $site = get_site($site_id ? $site_id : 'non-existent'); - if (!$site) { - + if ( ! $site) { return null; - - } // end if; + } $main_domain = wp_parse_url(get_home_url($site_id), PHP_URL_HOST); @@ -1115,10 +993,8 @@ class SSO { ); if (is_subdomain_install()) { - $domain_list[] = $site->domain; - - } // end if; + } $domain_list = apply_filters('wu_sso_site_allowed_domains', $domain_list, $site_id, $site, $this); @@ -1126,8 +1002,7 @@ class SSO { 'secret' => $this->calculate_secret_from_date($site->registered), 'domains' => $domain_list, ); - - } // end get_broker_by_id; + } /** * Returns a broker instance. @@ -1148,8 +1023,7 @@ class SSO { $this->broker = new SSO_Broker($home_sso_url, $broker_id, $secret); return apply_filters('wu_sso_get_broker', $this->broker, $this); - - } // end get_broker; + } /** * Set the target user after the bearer is passed. @@ -1160,10 +1034,8 @@ class SSO { * @return void */ public function set_target_user_id($target_user_id) { - $this->target_user_id = $target_user_id; - - } // end set_target_user_id; + } /** * Returns the target user id. @@ -1172,10 +1044,8 @@ class SSO { * @return int */ public function get_target_user_id() { - return $this->target_user_id; - - } // end get_target_user_id; + } /** * Get the url path for SSO. * @@ -1194,14 +1064,11 @@ class SSO { ); if ($action) { - $fragments[] = $action; - - } // end if; + } return implode('-', $fragments); - - } // end get_url_path; + } /** * Helper function to generate a sso url. @@ -1213,13 +1080,11 @@ class SSO { */ public static function with_sso($url) { - $sso = SSO::get_instance(); + $sso = self::get_instance(); if ($sso->is_enabled() === false) { - return $url; - - } // end if; + } $sso_path = $sso->get_url_path(); @@ -1228,7 +1093,5 @@ class SSO { ); return add_query_arg($sso_params, $url); - - } // end with_sso; - -} // end class SSO; + } +} diff --git a/inc/sso/exception/class-sso-exception.php b/inc/sso/exception/class-sso-exception.php index e522819..e00933e 100644 --- a/inc/sso/exception/class-sso-exception.php +++ b/inc/sso/exception/class-sso-exception.php @@ -17,4 +17,4 @@ defined('ABSPATH') || exit; * * @since 2.0.11 */ -class SSO_Exception extends \RuntimeException {} // end class SSO_Exception; +class SSO_Exception extends \RuntimeException {} diff --git a/inc/sso/exception/class-sso-session-exception.php b/inc/sso/exception/class-sso-session-exception.php index 6aaa350..f339127 100644 --- a/inc/sso/exception/class-sso-session-exception.php +++ b/inc/sso/exception/class-sso-session-exception.php @@ -17,4 +17,4 @@ defined('ABSPATH') || exit; * * @since 2.0.11 */ -class SSO_Session_Exception extends \RuntimeException {} // end class SSO_Session_Exception; +class SSO_Session_Exception extends \RuntimeException {} diff --git a/inc/tax/class-dashboard-taxes-tab.php b/inc/tax/class-dashboard-taxes-tab.php index 48a1bef..7fe4527 100644 --- a/inc/tax/class-dashboard-taxes-tab.php +++ b/inc/tax/class-dashboard-taxes-tab.php @@ -36,8 +36,7 @@ class Dashboard_Taxes_Tab { add_filter('wu_dashboard_filter_bar', array($this, 'add_tab')); add_action('wu_dashboard_taxes_widgets', array($this, 'register_widgets'), 10, 3); - - } // end __construct; + } /** * Checks if tax support is enabled or not. @@ -48,8 +47,7 @@ class Dashboard_Taxes_Tab { protected function is_enabled() { return wu_get_setting('enable_taxes'); - - } // end is_enabled; + } /** * Add_tab to dashboard @@ -68,8 +66,7 @@ class Dashboard_Taxes_Tab { ); return $dashboard_filters; - - } // end add_tab; + } /** * Renders the disabled message, if taxes are not enabled. @@ -79,16 +76,20 @@ class Dashboard_Taxes_Tab { */ public function disabled_message() { - echo wu_render_empty_state(array( - 'message' => __('You do not have tax support enabled yet...'), - 'sub_message' => __('If you need to collect taxes, you\'ll be glad to hear that WP Multisite WaaS offers tax support!'), - 'link_label' => __('Enable Tax Support', 'wp-ultimo'), - 'link_url' => wu_network_admin_url('wp-ultimo-settings', array( - 'tab' => 'taxes', - )), - )); - - } // end disabled_message; + echo wu_render_empty_state( + array( + 'message' => __('You do not have tax support enabled yet...'), + 'sub_message' => __('If you need to collect taxes, you\'ll be glad to hear that WP Multisite WaaS offers tax support!'), + 'link_label' => __('Enable Tax Support', 'wp-ultimo'), + 'link_url' => wu_network_admin_url( + 'wp-ultimo-settings', + array( + 'tab' => 'taxes', + ) + ), + ) + ); + } /** * Adds a back link to the taxes without tax. @@ -109,8 +110,7 @@ class Dashboard_Taxes_Tab { ); return array_merge($back_link, $links); - - } // end add_back_link; + } /** * Register_widgets @@ -134,8 +134,7 @@ class Dashboard_Taxes_Tab { /* * Displays an empty page with the option to activate tax support. */ - if (!$this->is_enabled()) { - + if ( ! $this->is_enabled()) { add_filter('wu_dashboard_display_filter', '__return_false'); add_filter('wu_dashboard_display_widgets', '__return_false'); @@ -145,8 +144,7 @@ class Dashboard_Taxes_Tab { add_filter('wu_page_get_title_links', array($this, 'add_back_link')); return; - - } // end if; + } $this->dashboard_page = $dashboard_page; @@ -157,8 +155,7 @@ class Dashboard_Taxes_Tab { add_meta_box('wp-ultimo-taxes-by-day', __('Taxes by Day', 'wp-ultimo'), array($this, 'output_widget_taxes_by_day'), $screen->id, 'side', 'high'); $this->register_scripts(); - - } // end register_widgets; + } /** * Registers the necessary scripts to handle the tax graph. @@ -181,7 +178,7 @@ class Dashboard_Taxes_Tab { 'september' => array(), 'october' => array(), 'november' => array(), - 'december' => array() + 'december' => array(), ); $data = wu_calculate_taxes_by_month(); @@ -189,38 +186,39 @@ class Dashboard_Taxes_Tab { $index = 1; foreach ($payments_per_month as &$month) { + $month = $data[ $index ]; - $month = $data[$index]; - - $index++; - - } // end foreach; + ++$index; + } $month_list = array(); $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)); } wp_register_script('wu-tax-stats', wu_get_asset('tax-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-tax-stats', 'wu_tax_statistics_vars', array( - 'data' => $payments_per_month, - 'start_date' => date_i18n('Y-m-d', strtotime((string) wu_request('start_date', '-1 month'))), - 'end_date' => date_i18n('Y-m-d', strtotime((string) wu_request('end_date', 'tomorrow'))), - 'today' => date_i18n('Y-m-d', strtotime('tomorrow')), - 'month_list' => $month_list, - 'i18n' => array( - 'net_profit_label' => __('Net Profit', 'wp-ultimo'), - 'taxes_label' => __('Taxes Collected', 'wp-ultimo'), + wp_localize_script( + 'wu-tax-stats', + 'wu_tax_statistics_vars', + array( + 'data' => $payments_per_month, + 'start_date' => date_i18n('Y-m-d', strtotime((string) wu_request('start_date', '-1 month'))), + 'end_date' => date_i18n('Y-m-d', strtotime((string) wu_request('end_date', 'tomorrow'))), + 'today' => date_i18n('Y-m-d', strtotime('tomorrow')), + 'month_list' => $month_list, + 'i18n' => array( + 'net_profit_label' => __('Net Profit', 'wp-ultimo'), + 'taxes_label' => __('Taxes Collected', 'wp-ultimo'), + ), ) - )); + ); wp_enqueue_script('wu-tax-stats'); - - } // end register_scripts; + } /** * Renders the tax graph. @@ -231,8 +229,7 @@ class Dashboard_Taxes_Tab { public function output_widget_taxes() { wu_get_template('dashboard-statistics/widget-tax-graph'); - - } // end output_widget_taxes; + } /** * Renders the taxes by rate widget. @@ -244,12 +241,14 @@ class Dashboard_Taxes_Tab { $taxes_by_rate = wu_calculate_taxes_by_rate($this->dashboard_page->start_date, $this->dashboard_page->end_date); - wu_get_template('dashboard-statistics/widget-tax-by-code', array( - 'taxes_by_rate' => $taxes_by_rate, - 'page' => $this->dashboard_page, - )); - - } // end output_widget_taxes_by_rate; + wu_get_template( + 'dashboard-statistics/widget-tax-by-code', + array( + 'taxes_by_rate' => $taxes_by_rate, + 'page' => $this->dashboard_page, + ) + ); + } /** * Renders the taxes by date widget. @@ -261,11 +260,12 @@ class Dashboard_Taxes_Tab { $taxes_by_day = wu_calculate_taxes_by_day($this->dashboard_page->start_date, $this->dashboard_page->end_date); - wu_get_template('dashboard-statistics/widget-tax-by-day', array( - 'taxes_by_day' => $taxes_by_day, - 'page' => $this->dashboard_page, - )); - - } // end output_widget_taxes_by_day; - -} // end class Dashboard_Taxes_Tab; + wu_get_template( + 'dashboard-statistics/widget-tax-by-day', + array( + 'taxes_by_day' => $taxes_by_day, + 'page' => $this->dashboard_page, + ) + ); + } +} diff --git a/inc/tax/class-tax.php b/inc/tax/class-tax.php index 94028f2..c934c12 100644 --- a/inc/tax/class-tax.php +++ b/inc/tax/class-tax.php @@ -33,65 +33,62 @@ class Tax { add_action('wu_page_wp-ultimo-settings_load', array($this, 'add_sidebar_widget')); if ($this->is_enabled()) { - add_action('wp_ultimo_admin_pages', array($this, 'add_admin_page')); add_action('wp_ajax_wu_get_tax_rates', array($this, 'serve_taxes_rates_via_ajax')); add_action('wp_ajax_wu_save_tax_rates', array($this, 'save_taxes_rates')); - add_action('wu_before_search_models', function() { + add_action( + 'wu_before_search_models', + function () { - $model = wu_request('model', 'state'); + $model = wu_request('model', 'state'); - $country = wu_request('country', 'not-present'); + $country = wu_request('country', 'not-present'); - if ($country === 'not-present') { + if ($country === 'not-present') { + return; + } - return; + if ($model === 'state') { + $results = wu_get_country_states($country, 'slug', 'name'); + } elseif ($model === 'city') { + $states = explode(',', (string) wu_request('state', '')); - } // end if; + $results = wu_get_country_cities($country, $states, 'slug', 'name'); + } - if ($model === 'state') { + $query = wu_request( + 'query', + array( + 'search' => 'searching....', + ) + ); - $results = wu_get_country_states($country, 'slug', 'name'); + $s = trim((string) wu_get_isset($query, 'search', 'searching...'), '*'); - } elseif ($model === 'city') { + $filtered = array(); - $states = explode(',', (string) wu_request('state', '')); + if ( ! empty($s)) { + $filtered = \Arrch\Arrch::find( + $results, + array( + 'sort_key' => 'name', + 'where' => array( + array(array('slug', 'name'), '~', $s), + ), + ) + ); + } - $results = wu_get_country_cities($country, $states, 'slug', 'name'); + wp_send_json(array_values($filtered)); - } // end if; - - $query = wu_request('query', array( - 'search' => 'searching....', - )); - - $s = trim((string) wu_get_isset($query, 'search', 'searching...'), '*'); - - $filtered = array(); - - if (!empty($s)) { - - $filtered = \Arrch\Arrch::find($results, array( - 'sort_key' => 'name', - 'where' => array( - array(array('slug', 'name'), '~', $s), - ), - )); - - } // end if; - - wp_send_json(array_values($filtered)); - - exit; - - }); - - } // end if; - - } // end init; + exit; + } + ); + } + } /** * Register tax settings. @@ -101,31 +98,41 @@ class Tax { */ public function add_settings() { - wu_register_settings_section('taxes', array( - 'title' => __('Taxes', 'wp-ultimo'), - 'desc' => __('Taxes', 'wp-ultimo'), - 'icon' => 'dashicons-wu-percent', - 'order' => 55, - )); + wu_register_settings_section( + 'taxes', + array( + 'title' => __('Taxes', 'wp-ultimo'), + 'desc' => __('Taxes', 'wp-ultimo'), + 'icon' => 'dashicons-wu-percent', + 'order' => 55, + ) + ); - wu_register_settings_field('taxes', 'enable_taxes', array( - 'title' => __('Enable Taxes', 'wp-ultimo'), - 'desc' => __('Enable this option to be able to collect sales taxes on your network payments.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - )); + wu_register_settings_field( + 'taxes', + 'enable_taxes', + array( + 'title' => __('Enable Taxes', 'wp-ultimo'), + 'desc' => __('Enable this option to be able to collect sales taxes on your network payments.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + ) + ); - wu_register_settings_field('taxes', 'inclusive_tax', array( - 'title' => __('Inclusive Tax', 'wp-ultimo'), - 'desc' => __('Enable this option if your prices include taxes. In that case, WP Multisite WaaS will calculate the included tax instead of adding taxes to the price.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 0, - 'require' => array( - 'enable_taxes' => 1, - ), - )); - - } // end add_settings; + wu_register_settings_field( + 'taxes', + 'inclusive_tax', + array( + 'title' => __('Inclusive Tax', 'wp-ultimo'), + 'desc' => __('Enable this option if your prices include taxes. In that case, WP Multisite WaaS will calculate the included tax instead of adding taxes to the price.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 0, + 'require' => array( + 'enable_taxes' => 1, + ), + ) + ); + } /** * Adds the sidebar widget. @@ -135,12 +142,14 @@ class Tax { */ public function add_sidebar_widget() { - wu_register_settings_side_panel('taxes', array( - 'title' => __('Tax Rates', 'wp-ultimo'), - 'render' => array($this, 'render_taxes_side_panel'), - )); - - } // end add_sidebar_widget; + wu_register_settings_side_panel( + 'taxes', + array( + 'title' => __('Tax Rates', 'wp-ultimo'), + 'render' => array($this, 'render_taxes_side_panel'), + ) + ); + } /** * Checks if this functionality is available and should be loaded. @@ -153,8 +162,7 @@ class Tax { $is_enabled = wu_get_setting('enable_taxes', false); return apply_filters('wu_enable_taxes', $is_enabled); - - } // end is_enabled; + } /** * Adds the Tax Rate edit admin screen. @@ -164,9 +172,8 @@ class Tax { */ public function add_admin_page() { - new \WP_Ultimo\Admin_Pages\Tax_Rates_Admin_Page; - - } // end add_admin_page; + new \WP_Ultimo\Admin_Pages\Tax_Rates_Admin_Page(); + } /** * Returns the Tax Rate Types available in the platform; Filterable @@ -176,11 +183,13 @@ class Tax { */ public function get_tax_rate_types() { - return apply_filters('wu_get_tax_rate_types', array( - 'regular' => __('Regular', 'wp-ultimo') - )); - - } // end get_tax_rate_types; + return apply_filters( + 'wu_get_tax_rate_types', + array( + 'regular' => __('Regular', 'wp-ultimo'), + ) + ); + } /** * Returns the default elements of a tax rate. @@ -204,8 +213,7 @@ class Tax { ); return apply_filters('wu_get_tax_rate_defaults', $defaults); - - } // end get_tax_rate_defaults; + } /** * Returns the registered tax rates. @@ -217,44 +225,43 @@ class Tax { */ public function get_tax_rates($fetch_state_options = false) { - $tax_rates_categories = wu_get_option('tax_rates', array( - 'default' => array( - 'name' => __('Default', 'wp-ultimo'), - 'rates' => array(), - ), - )); + $tax_rates_categories = wu_get_option( + 'tax_rates', + array( + 'default' => array( + 'name' => __('Default', 'wp-ultimo'), + 'rates' => array(), + ), + ) + ); - if (!isset($tax_rates_categories['default'])) { + if ( ! isset($tax_rates_categories['default'])) { /** * We need to make sure the default category is always present. */ $default = array_shift($tax_rates_categories); $tax_rates_categories = array_merge(array('default' => $default), $tax_rates_categories); - - } // end if; + } foreach ($tax_rates_categories as &$tax_rate_category) { + $tax_rate_category['rates'] = array_map( + function ($rate) use ($fetch_state_options) { - $tax_rate_category['rates'] = array_map(function($rate) use ($fetch_state_options) { + if ($fetch_state_options) { + $rate['state_options'] = wu_get_country_states($rate['country'], 'slug', 'name'); + } - if ($fetch_state_options) { + $rate['tax_rate'] = is_numeric($rate['tax_rate']) ? $rate['tax_rate'] : 0; - $rate['state_options'] = wu_get_country_states($rate['country'], 'slug', 'name'); - - } // end if; - - $rate['tax_rate'] = is_numeric($rate['tax_rate']) ? $rate['tax_rate'] : 0; - - return wp_parse_args($rate, $this->get_tax_rate_defaults()); - - }, $tax_rate_category['rates']); - - } // end foreach; + return wp_parse_args($rate, $this->get_tax_rate_defaults()); + }, + $tax_rate_category['rates'] + ); + } return apply_filters('wu_get_tax_rates', $tax_rates_categories, $fetch_state_options); - - } // end get_tax_rates; + } /** * Retrieves the tax rates to serve via ajax. @@ -267,14 +274,11 @@ class Tax { $tax_rates = array(); if (current_user_can('read_tax_rates')) { - $tax_rates = $this->get_tax_rates(true); - - } // end if; + } wp_send_json_success((object) $tax_rates); - - } // end serve_taxes_rates_via_ajax; + } /** * Handles the saving of new tax rates. @@ -284,61 +288,60 @@ class Tax { */ public function save_taxes_rates() { - if (!check_ajax_referer('wu_tax_editing')) { - - wp_send_json(array( - 'code' => 'not-enough-permissions', - 'message' => __('You don\'t have permission to alter tax rates', 'wp-ultimo') - )); - - } // end if; + if ( ! check_ajax_referer('wu_tax_editing')) { + wp_send_json( + array( + 'code' => 'not-enough-permissions', + 'message' => __('You don\'t have permission to alter tax rates', 'wp-ultimo'), + ) + ); + } $data = json_decode(file_get_contents('php://input'), true); $tax_rates = isset($data['tax_rates']) ? $data['tax_rates'] : false; - if (!$tax_rates) { - - wp_send_json(array( - 'code' => 'tax-rates-not-found', - 'message' => __('No tax rates present in the request', 'wp-ultimo') - )); - - } // end if; + if ( ! $tax_rates) { + wp_send_json( + array( + 'code' => 'tax-rates-not-found', + 'message' => __('No tax rates present in the request', 'wp-ultimo'), + ) + ); + } $treated_tax_rates = array(); foreach ($tax_rates as $tax_rate_slug => $tax_rate) { - - if (!isset($tax_rate['rates'])) { - + if ( ! isset($tax_rate['rates'])) { continue; + } - } // end if; + $tax_rate['rates'] = array_map( + function ($item) { - $tax_rate['rates'] = array_map(function($item) { + unset($item['selected']); - unset($item['selected']); + unset($item['state_options']); - unset($item['state_options']); + return $item; + }, + $tax_rate['rates'] + ); - return $item; - - }, $tax_rate['rates']); - - $treated_tax_rates[strtolower(sanitize_title($tax_rate_slug))] = $tax_rate; - - } // end foreach; + $treated_tax_rates[ strtolower(sanitize_title($tax_rate_slug)) ] = $tax_rate; + } wu_save_option('tax_rates', $treated_tax_rates); - wp_send_json(array( - 'code' => 'success', - 'message' => __('Tax Rates successfully updated!', 'wp-ultimo'), - 'tax_category' => strtolower(sanitize_title(wu_get_isset($data, 'tax_category', 'default'))), - )); - - } // end save_taxes_rates; + wp_send_json( + array( + 'code' => 'success', + 'message' => __('Tax Rates successfully updated!', 'wp-ultimo'), + 'tax_category' => strtolower(sanitize_title(wu_get_isset($data, 'tax_category', 'default'))), + ) + ); + } /** * Render the tax side panel. @@ -409,7 +412,5 @@ class Tax { }); init(); - - } // end if; + } return static::$instance; - - } // end get_instance; + } /** * Runs only once, at the first instantiation of the Singleton. @@ -49,8 +46,7 @@ trait Singleton { public function init() { $this->has_parents() && method_exists(get_parent_class($this), 'init') && parent::init(); - - } // end init; + } /** * Check if the current class has parents. @@ -61,7 +57,5 @@ trait Singleton { public function has_parents() { return (bool) class_parents($this); - - } // end has_parents; - -} // end trait Singleton; + } +} diff --git a/inc/traits/trait-wp-ultimo-coupon-deprecated.php b/inc/traits/trait-wp-ultimo-coupon-deprecated.php index 0203537..070133d 100644 --- a/inc/traits/trait-wp-ultimo-coupon-deprecated.php +++ b/inc/traits/trait-wp-ultimo-coupon-deprecated.php @@ -31,9 +31,8 @@ trait WP_Ultimo_Coupon_Deprecated { */ _doing_it_wrong($key, __('Discount Code keys should not be set directly.', 'wp-ultimo'), '2.0.0'); - $this->meta["wpu_{$key}"] = $value; - - } // end __set; + $this->meta[ "wpu_{$key}" ] = $value; + } /** * Magic getter to provide backwards compatibility for plans. @@ -51,8 +50,7 @@ trait WP_Ultimo_Coupon_Deprecated { switch ($key) { default: $value = $this->get_meta('wpu_' . $key, false, true); - - } // end switch; + } if ($value === null) { @@ -62,8 +60,7 @@ trait WP_Ultimo_Coupon_Deprecated { // throw new \Exception($message); return false; - - } // end if; + } /** * Let developers know that this is not going to be supported in the future. @@ -73,7 +70,5 @@ trait WP_Ultimo_Coupon_Deprecated { _doing_it_wrong($key, __('Discount Code keys should not be accessed directly', 'wp-ultimo'), '2.0.0'); return $value; - - } // end __get; - -} // end trait WP_Ultimo_Coupon_Deprecated; + } +} diff --git a/inc/traits/trait-wp-ultimo-deprecated.php b/inc/traits/trait-wp-ultimo-deprecated.php index 4d50ec5..2afa1d7 100644 --- a/inc/traits/trait-wp-ultimo-deprecated.php +++ b/inc/traits/trait-wp-ultimo-deprecated.php @@ -26,8 +26,7 @@ trait WP_Ultimo_Deprecated { _deprecated_function(__METHOD__, '2.0.0', 'wu_slugify($term)'); wu_slugify($term); - - } // end slugfy; + } /** * Deprecated: WP_Ultimo->add_page_to_branding() @@ -38,8 +37,7 @@ trait WP_Ultimo_Deprecated { public function add_page_to_branding() { _deprecated_function(__METHOD__, '2.0.0'); - - } // end add_page_to_branding; + } /** * Renders a view file from the view folder. @@ -56,8 +54,7 @@ trait WP_Ultimo_Deprecated { _deprecated_function(__METHOD__, '2.0.0', 'wu_get_template()'); wu_get_template($view, $vars); - - } // end render; + } /** * Returns the full path to the plugin folder @@ -73,8 +70,7 @@ trait WP_Ultimo_Deprecated { _deprecated_function(__METHOD__, '2.0.0', 'wu_path()'); return wu_path($dir); - - } // end path; + } /** * Deprecated: Add messages to be displayed as notices @@ -95,12 +91,9 @@ trait WP_Ultimo_Deprecated { $ultimo = WP_Ultimo(); if (isset($ultimo->notices) && $ultimo->notices) { - $ultimo->notices->add($message, $type, $panel); - - } // end if; - - } // end add_message; + } + } /** * Deprecated: This function is here to make sure that the plugin is network active @@ -116,8 +109,7 @@ trait WP_Ultimo_Deprecated { _deprecated_function(__METHOD__, '2.0.0', 'WP_Ultimo()->is_loaded()'); return WP_Ultimo()->is_loaded(); - - } // end check_before_run; + } /** * Deprecated: enqueue_select2. @@ -132,7 +124,5 @@ trait WP_Ultimo_Deprecated { wp_enqueue_style('wu-select2css', 'https://cdnjs.cloudflare.com/ajax/libs/select2/3.4.8/select2.css', false, '1.0', 'all'); wp_enqueue_script('wu-select2', 'https://cdnjs.cloudflare.com/ajax/libs/select2/3.4.8/select2.js', array('jquery'), '1.0', true); - - } // end enqueue_select2; - -} // end trait WP_Ultimo_Deprecated; + } +} diff --git a/inc/traits/trait-wp-ultimo-plan-deprecated.php b/inc/traits/trait-wp-ultimo-plan-deprecated.php index 793f2ae..3ead03d 100644 --- a/inc/traits/trait-wp-ultimo-plan-deprecated.php +++ b/inc/traits/trait-wp-ultimo-plan-deprecated.php @@ -36,44 +36,44 @@ trait WP_Ultimo_Plan_Deprecated { $value = null; switch ($key) { - case 'title': - $value = $this->get_name(); - break; - case 'id': - case 'ID': - $value = $this->get_id(); - break; - case 'free': - $value = $this->get_pricing_type() === 'free'; - break; - case 'price_1': - case 'price_3': - case 'price_12': - $value = 20; - break; - case 'top_deal': - $value = $this->is_featured_plan(); - break; - case 'feature_list': - $value = $this->get_feature_list(); - break; - case 'quotas': - $value = array( - // 'sites' => 300, - 'upload' => 1024 * 1024 * 1024, - 'visits' => 300, - ); - break; - case 'post': - $value = (object) array( - 'ID' => $this->get_id(), - 'post_title' => $this->get_name(), - ); - break; - default: - $value = $this->get_meta('wpu_' . $key, false, true); - break; - } // end switch; + case 'title': + $value = $this->get_name(); + break; + case 'id': + case 'ID': + $value = $this->get_id(); + break; + case 'free': + $value = $this->get_pricing_type() === 'free'; + break; + case 'price_1': + case 'price_3': + case 'price_12': + $value = 20; + break; + case 'top_deal': + $value = $this->is_featured_plan(); + break; + case 'feature_list': + $value = $this->get_feature_list(); + break; + case 'quotas': + $value = array( + // 'sites' => 300, + 'upload' => 1024 * 1024 * 1024, + 'visits' => 300, + ); + break; + case 'post': + $value = (object) array( + 'ID' => $this->get_id(), + 'post_title' => $this->get_name(), + ); + break; + default: + $value = $this->get_meta('wpu_' . $key, false, true); + break; + } /** * Let developers know that this is not going to be supported in the future. @@ -83,8 +83,7 @@ trait WP_Ultimo_Plan_Deprecated { _doing_it_wrong($key, __('Product keys should not be accessed directly', 'wp-ultimo'), '2.0.0'); return $value; - - } // end __get; + } /** * Get the featured status for this product. @@ -95,14 +94,11 @@ trait WP_Ultimo_Plan_Deprecated { public function is_featured_plan() { if ($this->featured_plan === null) { - $this->featured_plan = $this->get_meta('featured_plan', false); - - } // end if; + } return (bool) $this->featured_plan; - - } // end is_featured_plan; + } /** * Set the featured status for this product. @@ -114,8 +110,7 @@ trait WP_Ultimo_Plan_Deprecated { public function set_featured_plan($featured_plan) { $this->meta['featured_plan'] = $featured_plan; - - } // end set_featured_plan; + } /** * Deprecated: Checks if a given plan is a contact us plan. @@ -129,8 +124,7 @@ trait WP_Ultimo_Plan_Deprecated { _deprecated_function(__METHOD__, '2.0.0', 'get_pricing_type'); return $this->get_pricing_type() === 'contact_us'; - - } // end is_contact_us; + } /** * Get the pricing table lines to be displayed on the pricing tables @@ -147,20 +141,14 @@ trait WP_Ultimo_Plan_Deprecated { * @since 1.7.0 */ if ($this->should_display_quota_on_pricing_tables('setup_fee', true)) { - if ($this->get_pricing_type() === 'contact_us') { - $pricing_table_lines['wu_product_contact_us'] = __('Contact Us to know more', 'wp-ultimo'); - } else { - $pricing_table_lines['wu_product_setup_fee'] = $this->has_setup_fee() ? sprintf(__('Setup Fee: %s', 'wp-ultimo'), "" . wu_format_currency($this->get_setup_fee()) . '') : __('No Setup Fee', 'wp-ultimo'); - - } // end if; - - } // end if; + } + } /** * @@ -181,28 +169,25 @@ trait WP_Ultimo_Plan_Deprecated { if ($this->is_post_type_disabled($pt_slug)) { // Translators: used as "No Posts" where a post type is disabled - $pricing_table_lines['wu_product_limit_post_type_' . $pt_slug] = sprintf(__('No %s', 'wp-ultimo'), $post_type->labels->name); + $pricing_table_lines[ 'wu_product_limit_post_type_' . $pt_slug ] = sprintf(__('No %s', 'wp-ultimo'), $post_type->labels->name); continue; - - } // end if; + } /** * Get the values - * + * * @var integer|string */ - $is_unlimited = (int) $this->get_limitations()->post_types->{$pt_slug}->number === 0 || !$this->get_limitations()->post_types->is_enabled(); + $is_unlimited = (int) $this->get_limitations()->post_types->{$pt_slug}->number === 0 || ! $this->get_limitations()->post_types->is_enabled(); $value = $is_unlimited ? __('Unlimited', 'wp-ultimo') : $this->get_limitations()->post_types->{$pt_slug}->number; // Add Line $label = $value == 1 ? $post_type->labels->singular_name : $post_type->labels->name; - $pricing_table_lines['wu_product_limit_post_type_' . $pt_slug] = sprintf('%s %s', $value, $label); - - } // end if; - - } // end foreach; + $pricing_table_lines[ 'wu_product_limit_post_type_' . $pt_slug ] = sprintf('%s %s', $value, $label); + } + } /** * @@ -210,27 +195,23 @@ trait WP_Ultimo_Plan_Deprecated { * Gets the Disk Space and Sites to be displayed on the pricing table options */ if (wu_get_setting('enable_multiple_sites') && $this->should_display_quota_on_pricing_tables('sites')) { - - $is_unlimited = (int) $this->get_limitations()->sites->get_limit() === 0 || !$this->get_limitations()->sites->is_enabled(); + $is_unlimited = (int) $this->get_limitations()->sites->get_limit() === 0 || ! $this->get_limitations()->sites->is_enabled(); $value = $is_unlimited ? __('Unlimited', 'wp-ultimo') : $this->get_limitations()->sites->get_limit(); // Add Line $pricing_table_lines['wu_product_limit_sites'] = sprintf('%s %s', $value, _n('Site', 'Sites', $this->get_limitations()->sites->get_limit(), 'wp-ultimo')); - - } // end if; + } /** * Display DiskSpace */ if ($this->should_display_quota_on_pricing_tables('upload')) { - - $is_unlimited = (int) $this->get_limitations()->disk_space->get_limit() === 0 || !$this->get_limitations()->disk_space->is_enabled(); + $is_unlimited = (int) $this->get_limitations()->disk_space->get_limit() === 0 || ! $this->get_limitations()->disk_space->is_enabled(); $disk_space = $is_unlimited ? __('Unlimited', 'wp-ultimo') : size_format(absint($this->get_limitations()->disk_space->get_limit()) * 1024 * 1024); // Add Line - $pricing_table_lines['wu_product_limit_disk_space'] = !empty($disk_space) ? sprintf(__('%s Disk Space', 'wp-ultimo'), $disk_space) : false; - - } // end if; + $pricing_table_lines['wu_product_limit_disk_space'] = ! empty($disk_space) ? sprintf(__('%s Disk Space', 'wp-ultimo'), $disk_space) : false; + } /** * Visits @@ -238,14 +219,12 @@ trait WP_Ultimo_Plan_Deprecated { * @since 1.6.0 */ if ($this->should_display_quota_on_pricing_tables('visits')) { - - $is_unlimited = (int) $this->get_limitations()->visits->get_limit() === 0 || !$this->get_limitations()->visits->is_enabled(); + $is_unlimited = (int) $this->get_limitations()->visits->get_limit() === 0 || ! $this->get_limitations()->visits->is_enabled(); $value = $is_unlimited ? __('Unlimited', 'wp-ultimo') : number_format($this->get_limitations()->visits->get_limit()); // Add Line $pricing_table_lines['wu_product_limit_visits'] = sprintf('%s %s', $value, _n('Visit per month', 'Visits per month', $this->get_limitations()->visits->get_limit(), 'wp-ultimo')); - - } // end if; + } /** * Display Trial, if some @@ -254,12 +233,10 @@ trait WP_Ultimo_Plan_Deprecated { $trial_days_plan = $this->get_trial_duration(); if ($trial_days > 0 || $trial_days_plan) { - $trial_days = $trial_days_plan ? $trial_days_plan : $trial_days; - $pricing_table_lines['wu_product_trial'] = !$this->is_free() ? sprintf(__('%s day Free Trial', 'wp-ultimo'), $trial_days) : '-'; - - } // end if; + $pricing_table_lines['wu_product_trial'] = ! $this->is_free() ? sprintf(__('%s day Free Trial', 'wp-ultimo'), $trial_days) : '-'; + } /** * @@ -271,23 +248,18 @@ trait WP_Ultimo_Plan_Deprecated { $custom_features = explode('
    ', nl2br($this->get_feature_list())); foreach ($custom_features as $key => $custom_feature) { - if (trim($custom_feature) == '') { - continue; + } - } // end if; - - $pricing_table_lines['wu_product_feature_' . $key] = sprintf('%s', trim($custom_feature)); - - } // end foreach; + $pricing_table_lines[ 'wu_product_feature_' . $key ] = sprintf('%s', trim($custom_feature)); + } /** * Return Lines, filterable */ return apply_filters("wu_get_pricing_table_lines_$this->id", $pricing_table_lines, $this); - - } // end get_pricing_table_lines; + } /** * Deprecated: A quota to get. @@ -301,26 +273,17 @@ trait WP_Ultimo_Plan_Deprecated { public function get_quota($quota_name) { if ($quota_name === 'visits') { - $limit = (float) $this->get_limitations()->visits->get_limit(); - } elseif ($quota_name === 'disk_space') { - $limit = (float) $this->get_limitations()->disk_space->get_limit(); - } elseif ($quota_name === 'sites') { - $limit = (float) $this->get_limitations()->sites->get_limit(); - } else { - $limit = (float) $this->get_limitations()->post_types->{$quota_name}->number; - - } // end if; + } return $limit; - - } // end get_quota; + } /** * Returns wether or not we should display a given quota type in the Quotas and Limits widgets @@ -336,21 +299,16 @@ trait WP_Ultimo_Plan_Deprecated { */ $elements = array(); - if (!$elements) { - + if ( ! $elements) { return true; + } - } // end if; - - if (!isset( $elements[$quota_type] ) && $default) { - + if ( ! isset($elements[ $quota_type ]) && $default) { return true; + } - } // end if; - - return isset( $elements[$quota_type] ) && $elements[$quota_type]; - - } // end should_display_quota_on_pricing_tables; + return isset($elements[ $quota_type ]) && $elements[ $quota_type ]; + } /** * Checks if this plan allows unlimited extra users @@ -361,8 +319,7 @@ trait WP_Ultimo_Plan_Deprecated { public function should_allow_unlimited_extra_users() { return apply_filters('wu_plan_should_allow_unlimited_extra_users', (bool) $this->unlimited_extra_users, $this); - - } // end should_allow_unlimited_extra_users; + } /** * Returns wether or not we should display a given quota type in the Quotas and Limits widgets @@ -373,9 +330,8 @@ trait WP_Ultimo_Plan_Deprecated { */ public function is_post_type_disabled($post_type) { - return !$this->get_limitations()->post_types->{$post_type}->enabled; - - } // end is_post_type_disabled; + return ! $this->get_limitations()->post_types->{$post_type}->enabled; + } /** * Returns the post_type quotas @@ -387,14 +343,20 @@ trait WP_Ultimo_Plan_Deprecated { $quotas = $this->quotas; - return array_filter($quotas, fn($quota_name) => !in_array($quota_name, array( - 'sites', - 'attachment', - 'upload', - 'users', - 'visits', - ), true), ARRAY_FILTER_USE_KEY); - - } // end get_post_type_quotas; - -} // end trait WP_Ultimo_Plan_Deprecated; + return array_filter( + $quotas, + fn($quota_name) => ! in_array( + $quota_name, + array( + 'sites', + 'attachment', + 'upload', + 'users', + 'visits', + ), + true + ), + ARRAY_FILTER_USE_KEY + ); + } +} diff --git a/inc/traits/trait-wp-ultimo-settings-deprecated.php b/inc/traits/trait-wp-ultimo-settings-deprecated.php index d47dfa3..18e0d36 100644 --- a/inc/traits/trait-wp-ultimo-settings-deprecated.php +++ b/inc/traits/trait-wp-ultimo-settings-deprecated.php @@ -21,16 +21,13 @@ trait WP_Ultimo_Settings_Deprecated { * @return void */ public function handle_legacy_scripts() { - /* - * Mailchimp: Backwards compatibility. - */ + /* + * Mailchimp: Backwards compatibility. + */ if (wp_script_is('wu-mailchimp', 'registered')) { - wp_enqueue_script('wu-mailchimp'); - - } // end if; - - } // end handle_legacy_scripts; + } + } /** * Handle legacy hooks to support old versions of our add-ons. @@ -42,22 +39,19 @@ trait WP_Ultimo_Settings_Deprecated { $legacy_settings = array(); - /* - * Fetch Extra Sections - */ + /* + * Fetch Extra Sections + */ $sections = apply_filters_deprecated('wu_settings_sections', array(array()), '2.0.0', 'wu_register_settings_section()'); foreach ($sections as $section_key => $section) { - if ($section_key === 'activation') { - continue; // No activation stuff; - } // end if; + } $legacy_settings = array_merge($legacy_settings, $section['fields']); - - } // end foreach; + } $filters = array( 'wu_settings_section_general', @@ -71,34 +65,28 @@ trait WP_Ultimo_Settings_Deprecated { ); foreach ($filters as $filter) { - $message = __('Adding setting sections directly via filters is no longer supported.'); $legacy_settings = apply_filters_deprecated($filter, array($legacy_settings), '2.0.0', 'wu_register_settings_field()', $message); - - } // end foreach; + } if ($legacy_settings) { - - $this->add_section('other', array( - 'title' => __('Other', 'wp-ultimo'), - 'desc' => __('Other', 'wp-ultimo'), - )); + $this->add_section( + 'other', + array( + 'title' => __('Other', 'wp-ultimo'), + 'desc' => __('Other', 'wp-ultimo'), + ) + ); foreach ($legacy_settings as $setting_key => $setting) { - if (strpos((string) $setting_key, 'license_key_') !== false) { - continue; // Remove old license key fields - } // end if; + } $this->add_field('other', $setting_key, $setting); - - } // end foreach; - - } // end if; - - } // end handle_legacy_filters; - -} // end trait WP_Ultimo_Settings_Deprecated; + } + } + } +} diff --git a/inc/traits/trait-wp-ultimo-site-deprecated.php b/inc/traits/trait-wp-ultimo-site-deprecated.php index e5d457c..9c9a9b6 100644 --- a/inc/traits/trait-wp-ultimo-site-deprecated.php +++ b/inc/traits/trait-wp-ultimo-site-deprecated.php @@ -28,13 +28,11 @@ trait WP_Ultimo_Site_Deprecated { $value = null; switch ($key) { - case 'site_owner_id': $customer = $this->get_customer(); $value = $customer ? $customer->get_user_id() : false; break; - - } // end switch; + } /** * Let developers know that this is not going to be supported in the future. @@ -44,8 +42,7 @@ trait WP_Ultimo_Site_Deprecated { _doing_it_wrong($key, __('Product keys should not be accessed directly', 'wp-ultimo'), '2.0.0'); return $value; - - } // end __get; + } /** * Deprecated: get_subscription. @@ -59,7 +56,5 @@ trait WP_Ultimo_Site_Deprecated { _deprecated_function(__CLASS__, '2.0.0', '\WP_Ultimo\Models\Site::get_membership()'); return $this->get_membership(); - - } // end get_subscription; - -} // end trait WP_Ultimo_Site_Deprecated; + } +} diff --git a/inc/traits/trait-wp-ultimo-subscription-deprecated.php b/inc/traits/trait-wp-ultimo-subscription-deprecated.php index 11b9c5b..442db11 100644 --- a/inc/traits/trait-wp-ultimo-subscription-deprecated.php +++ b/inc/traits/trait-wp-ultimo-subscription-deprecated.php @@ -28,12 +28,10 @@ trait WP_Ultimo_Subscription_Deprecated { $value = null; switch ($key) { - case 'plan_id': $value = $this->get_plan_id(); break; - - } // end switch; + } /** * Let developers know that this is not going to be supported in the future. @@ -43,7 +41,5 @@ trait WP_Ultimo_Subscription_Deprecated { _doing_it_wrong($key, __('Membership keys should not be accessed directly', 'wp-ultimo'), '2.0.0'); return $value; - - } // end __get; - -} // end trait WP_Ultimo_Subscription_Deprecated; + } +} diff --git a/inc/ui/class-account-summary-element.php b/inc/ui/class-account-summary-element.php index f31e08c..e84e31e 100644 --- a/inc/ui/class-account-summary-element.php +++ b/inc/ui/class-account-summary-element.php @@ -9,7 +9,7 @@ namespace WP_Ultimo\UI; -use \WP_Ultimo\UI\Base_Element; +use WP_Ultimo\UI\Base_Element; // Exit if accessed directly defined('ABSPATH') || exit; @@ -89,14 +89,11 @@ class Account_Summary_Element extends Base_Element { public function get_icon($context = 'block') { if ($context === 'elementor') { - return 'eicon-call-to-action'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * The title of the UI element. @@ -111,8 +108,7 @@ class Account_Summary_Element extends Base_Element { public function get_title() { return __('Account Summary', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -128,8 +124,7 @@ class Account_Summary_Element extends Base_Element { public function get_description() { return __('Adds a account summary block to the page.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -167,8 +162,7 @@ class Account_Summary_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * The list of keywords for this element. @@ -195,8 +189,7 @@ class Account_Summary_Element extends Base_Element { 'Summary', 'WP Multisite WaaS', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -217,8 +210,7 @@ class Account_Summary_Element extends Base_Element { return array( 'title' => __('About this Site', 'wp-ultimo'), ); - - } // end defaults; + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -230,13 +222,11 @@ class Account_Summary_Element extends Base_Element { $this->site = WP_Ultimo()->currents->get_site(); - if (!$this->site || !$this->site->is_customer_allowed()) { - + if ( ! $this->site || ! $this->site->is_customer_allowed()) { $this->set_display(false); return; - - } // end if; + } $this->membership = $this->site->get_membership(); @@ -260,8 +250,7 @@ class Account_Summary_Element extends Base_Element { 'unlimited_space' => $unlimited_space, 'message' => $message, ); - - } // end setup; + } /** * Allows the setup in the context of previews. @@ -288,8 +277,7 @@ class Account_Summary_Element extends Base_Element { 'unlimited_space' => $unlimited_space, 'message' => $message, ); - - } // end setup_preview; + } /** * The content to be output on the screen. @@ -315,8 +303,7 @@ class Account_Summary_Element extends Base_Element { $atts['product'] = $this->product; return wu_get_template_contents('dashboard-widgets/account-summary', $atts); - - } // end output; + } /** * Returns the manage URL for sites, depending on the environment. @@ -331,7 +318,5 @@ class Account_Summary_Element extends Base_Element { $base_url = \WP_Ultimo\Current::get_manage_url($site_id, 'site'); return is_admin() ? add_query_arg('page', 'account', $base_url . '/admin.php') : $base_url; - - } // end get_manage_url; - -} // end class Account_Summary_Element; + } +} diff --git a/inc/ui/class-base-element.php b/inc/ui/class-base-element.php index 48bac4b..05215c9 100644 --- a/inc/ui/class-base-element.php +++ b/inc/ui/class-base-element.php @@ -9,7 +9,7 @@ namespace WP_Ultimo\UI; -use \WP_Ultimo\Database\Sites\Site_Type; +use WP_Ultimo\Database\Sites\Site_Type; // Exit if accessed directly defined('ABSPATH') || exit; @@ -113,7 +113,7 @@ abstract class Base_Element { * @param string $context One of the values: block, elementor or bb. * @return string */ - abstract public function get_icon($context = 'block'); // end get_icon; + abstract public function get_icon($context = 'block'); /** * The title of the UI element. @@ -157,7 +157,7 @@ abstract class Base_Element { * @since 2.0.0 * @return array */ - abstract public function fields(); // end fields; + abstract public function fields(); /** * The list of keywords for this element. @@ -176,7 +176,7 @@ abstract class Base_Element { * @since 2.0.0 * @return array */ - abstract public function keywords(); // end keywords; + abstract public function keywords(); /** * List of default parameters for the element. @@ -192,7 +192,7 @@ abstract class Base_Element { * @since 2.0.0 * @return array */ - abstract public function defaults(); // end defaults; + abstract public function defaults(); /** * The content to be output on the screen. @@ -207,7 +207,7 @@ abstract class Base_Element { * @param string|null $content The content inside the shortcode. * @return string */ - abstract public function output($atts, $content = null); // end output; + abstract public function output($atts, $content = null); // Boilerplate ----------------------------------- @@ -239,17 +239,14 @@ abstract class Base_Element { // Init should be the correct time to call this to avoid the deprecated notice from I18N. // But it doesn't work for some reason, fix later. -// add_action('init', function () { + // add_action('init', function () { do_action('wu_element_loaded', $this); -// } ); + // } ); if ($this->public) { - - Base_Element::register_public_element($this); - - } // end if; - - } // end init; + self::register_public_element($this); + } + } /** * Register a public element to further use. @@ -261,8 +258,7 @@ abstract class Base_Element { public static function register_public_element($element) { static::$public_elements[] = $element; - - } // end register_public_element; + } /** * Retrieves the public registered elements. @@ -273,8 +269,7 @@ abstract class Base_Element { public static function get_public_elements() { return static::$public_elements; - - } // end get_public_elements; + } /** * Sets blocks up for the block editor. @@ -290,10 +285,8 @@ abstract class Base_Element { $should_load = false; if ($block['blockName'] === $this->get_id()) { - $should_load = true; - - } // end if; + } /** * We might need to add additional blocks later. @@ -301,38 +294,30 @@ abstract class Base_Element { * @since 2.0.0 * @return array */ - $blocks_to_check = apply_filters('wu_element_block_types_to_check', array( - 'core/shortcode', - 'core/paragraph', - )); + $blocks_to_check = apply_filters( + 'wu_element_block_types_to_check', + array( + 'core/shortcode', + 'core/paragraph', + ) + ); if (in_array($block['blockName'], $blocks_to_check, true)) { - if ($this->contains_current_element($block['innerHTML'])) { - $should_load = true; - - } // end if; - - } // end if; + } + } if ($should_load) { - if ($this->is_preview()) { - $this->setup_preview(); - } else { - $this->setup(); - - } // end if; - - } // end if; + } + } return $short_circuit; - - } // end setup_for_block_editor; + } /** * Search for an element id on the list of metaboxes. @@ -352,11 +337,9 @@ abstract class Base_Element { /* * Bail if things don't look normal or in the right context. */ - if (!function_exists('get_current_screen')) { - + if ( ! function_exists('get_current_screen')) { return; - - } // end if; + } $screen = get_current_screen(); @@ -364,10 +347,8 @@ abstract class Base_Element { * First, check on cache, to avoid recalculating it time and time again. */ if (is_array(self::$metabox_cache)) { - return in_array($element_id, self::$metabox_cache, true); - - } // end if; + } $contains_metaboxes = wu_get_isset($wp_meta_boxes, $screen->id) || wu_get_isset($wp_meta_boxes, $pagenow); @@ -375,38 +356,27 @@ abstract class Base_Element { $found = false; - if (is_array($wp_meta_boxes) && $contains_metaboxes && is_array($wp_meta_boxes[$screen->id])) { - - foreach ($wp_meta_boxes[$screen->id] as $position => $priorities) { - + if (is_array($wp_meta_boxes) && $contains_metaboxes && is_array($wp_meta_boxes[ $screen->id ])) { + foreach ($wp_meta_boxes[ $screen->id ] as $position => $priorities) { foreach ($priorities as $priority => $metaboxes) { - foreach ($metaboxes as $metabox_id => $metabox) { - $elements_to_cache[] = $metabox_id; if ($metabox_id === $element_id) { - $found = true; - - } // end if; - - } // end foreach; - - } // end foreach; - - } // end foreach; + } + } + } + } /** * Set a local cache so we don't have to loop it all over again. */ self::$metabox_cache = $elements_to_cache; - - } // end if; + } return $found; - - } // end search_in_metaboxes; + } /** * Setup element on admin pages. @@ -417,22 +387,17 @@ abstract class Base_Element { public function setup_for_admin() { if ($this->loaded === true) { - return; - - } // end if; + } $element_id = "wp-ultimo-{$this->id}-element"; if (self::search_in_metaboxes($element_id)) { - $this->loaded = true; $this->setup(); - - } // end if; - - } // end setup_for_admin; + } + } /** * Maybe run setup, when the shortcode or block is found. @@ -446,26 +411,17 @@ abstract class Base_Element { global $post; if (is_admin() || empty($post)) { - return; - - } // end if; + } if ($this->contains_current_element($post->post_content, $post)) { - if ($this->is_preview()) { - $this->setup_preview(); - } else { - $this->setup(); - - } // end if; - - } // end if; - - } // end maybe_setup; + } + } + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -473,7 +429,7 @@ abstract class Base_Element { * @since 2.0.0 * @return void */ - public function setup() {} // end setup; + public function setup() {} /** * Allows the setup in the context of previews. @@ -481,7 +437,7 @@ abstract class Base_Element { * @since 2.0.0 * @return void */ - public function setup_preview() {} // end setup_preview; + public function setup_preview() {} /** * Checks content to see if the current element is present. @@ -503,10 +459,8 @@ abstract class Base_Element { * we can skip the entire check and return true. */ if (is_array($this->pre_loaded_attributes)) { - return true; - - } // end if; + } /* * First, check for default shortcodes @@ -515,14 +469,12 @@ abstract class Base_Element { $shortcode = $this->get_shortcode_id(); if (has_shortcode($content, $shortcode)) { - $this->pre_loaded_attributes = $this->maybe_extract_arguments($content, 'shortcode'); $this->actually_loaded = true; return true; - - } // end if; + } /* * Handle the Block Editor @@ -531,14 +483,12 @@ abstract class Base_Element { $block = $this->get_id(); if (has_block($block, $content)) { - $this->pre_loaded_attributes = $this->maybe_extract_arguments($content, 'block'); $this->actually_loaded = true; return true; - - } // end if; + } /* * Runs generic version so plugins can extend it. @@ -551,10 +501,8 @@ abstract class Base_Element { * Last option is to check for the post force setting. */ if ($post && get_post_meta($post->ID, '_wu_force_elements_loading', true)) { - $contains_element = true; - - } // end if; + } /** * Allow developers to change the results of the initial search. @@ -567,8 +515,7 @@ abstract class Base_Element { * @param self The current element. */ return apply_filters('wu_contains_element', $contains_element, $content, $this, $post); - - } // end contains_current_element; + } /** * Tries to extract element arguments depending on the element type. @@ -591,8 +538,7 @@ abstract class Base_Element { preg_match_all('/' . $shortcode_regex . '/', $content, $matches, PREG_SET_ORDER); - return !empty($matches) ? shortcode_parse_atts($matches[0][3]) : false; - + return ! empty($matches) ? shortcode_parse_atts($matches[0][3]) : false; } elseif ($type === 'block') { /** @@ -602,18 +548,13 @@ abstract class Base_Element { $block_content = parse_blocks($content); foreach ($block_content as $block) { - if ($block['blockName'] === $this->get_id()) { - return $block['attrs']; - - } // end if; - - } // end foreach; + } + } return false; - - } // end if; + } /** * Adds generic filter to allow developers @@ -624,8 +565,7 @@ abstract class Base_Element { * @return false|array */ return apply_filters('wu_element_maybe_extract_arguments', false, $content, $type, $this); - - } // end maybe_extract_arguments; + } /** * Adds custom CSS to the signup screen. @@ -637,11 +577,9 @@ abstract class Base_Element { global $post; - if (!is_a($post, '\WP_Post')) { - + if ( ! is_a($post, '\WP_Post')) { return; - - } // end if; + } $should_enqueue_scripts = apply_filters('wu_element_should_enqueue_scripts', false, $post, $this->get_shortcode_id()); @@ -656,10 +594,8 @@ abstract class Base_Element { * @since 2.0.0 */ do_action("wu_{$this->id}_scripts", $post, $this); - - } // end if; - - } // end enqueue_element_scripts; + } + } /** * Tries to parse the shortcode content on page load. @@ -677,15 +613,12 @@ abstract class Base_Element { */ public function get_pre_loaded_attribute($name, $default = false) { - if ($this->pre_loaded_attributes === false || !is_array($this->pre_loaded_attributes)) { - + if ($this->pre_loaded_attributes === false || ! is_array($this->pre_loaded_attributes)) { return false; - - } // end if; + } return wu_get_isset($this->pre_loaded_attributes, $name, $default); - - } // end get_pre_loaded_attribute; + } /** * Registers the shortcode. @@ -696,14 +629,11 @@ abstract class Base_Element { public function register_shortcode() { if (wu_get_current_site()->get_type() === Site_Type::CUSTOMER_OWNED && is_admin() === false) { - return; - - } // end if; + } add_shortcode($this->get_shortcode_id(), array($this, 'display')); - - } // end register_shortcode; + } /** * Registers the forms. @@ -715,22 +645,27 @@ abstract class Base_Element { /* * Add Generator Forms */ - wu_register_form("shortcode_{$this->id}", array( - 'render' => array($this, 'render_generator_modal'), - 'handler' => '__return_empty_string', - 'capability' => 'manage_network', - )); + wu_register_form( + "shortcode_{$this->id}", + array( + 'render' => array($this, 'render_generator_modal'), + 'handler' => '__return_empty_string', + 'capability' => 'manage_network', + ) + ); /* * Add Customize Forms */ - wu_register_form("customize_{$this->id}", array( - 'render' => array($this, 'render_customize_modal'), - 'handler' => array($this, 'handle_customize_modal'), - 'capability' => 'manage_network', - )); - - } // end register_form; + wu_register_form( + "customize_{$this->id}", + array( + 'render' => array($this, 'render_customize_modal'), + 'handler' => array($this, 'handle_customize_modal'), + 'capability' => 'manage_network', + ) + ); + } /** * Adds the modal to copy the shortcode for this particular element. @@ -747,14 +682,11 @@ abstract class Base_Element { $state = array(); foreach ($fields as $field_slug => &$field) { - if ($field['type'] === 'header' || $field['type'] === 'note') { - - unset($fields[$field_slug]); + unset($fields[ $field_slug ]); continue; - - } // end if; + } /* * Additional State. @@ -766,20 +698,16 @@ abstract class Base_Element { $additional_state = array(); if ($field['type'] === 'group') { - foreach ($field['fields'] as $sub_field_slug => &$sub_field) { - $sub_field['html_attr'] = array( 'v-model.lazy' => "attributes.{$sub_field_slug}", ); - $additional_state[$sub_field_slug] = wu_request($sub_field_slug, wu_get_isset($defaults, $sub_field_slug)); - - } // end foreach; + $additional_state[ $sub_field_slug ] = wu_request($sub_field_slug, wu_get_isset($defaults, $sub_field_slug)); + } continue; - - } // end if; + } /* * Set v-model @@ -791,28 +719,23 @@ abstract class Base_Element { $required = wu_get_isset($field, 'required'); if (wu_get_isset($field, 'required')) { - $shows = array(); foreach ($required as $key => $value) { - $value = is_string($value) ? "\"$value\"" : $value; $shows[] = "attributes.{$key} == $value"; - - } // end foreach; + } $field['wrapper_html_attr'] = array( 'v-show' => implode(' && ', $shows), ); - $state[$field_slug . '_shortcode_requires'] = $required; + $state[ $field_slug . '_shortcode_requires' ] = $required; + } - } // end if; - - $state[$field_slug] = wu_request($field_slug, wu_get_isset($defaults, $field_slug)); - - } // end foreach; + $state[ $field_slug ] = wu_request($field_slug, wu_get_isset($defaults, $field_slug)); + } $fields['shortcode_result'] = array( 'type' => 'note', @@ -832,27 +755,32 @@ abstract class Base_Element { ), ); - $form = new \WP_Ultimo\UI\Form($this->id, $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0 wu-w-full', - '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}_generator", - 'data-state' => wu_convert_to_state(array( - 'id' => $this->get_shortcode_id(), - 'defaults' => $defaults, - 'attributes' => $state, - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + $this->id, + $fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0 wu-w-full', + '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}_generator", + 'data-state' => wu_convert_to_state( + array( + 'id' => $this->get_shortcode_id(), + 'defaults' => $defaults, + 'attributes' => $state, + ) + ), + ), + ) + ); echo '
    '; $form->render(); echo '
    '; - - } // end render_generator_modal; + } /** * Adds the modal customize the widget block @@ -882,24 +810,18 @@ abstract class Base_Element { $state = array_merge($defaults, $saved_settings); foreach ($fields as $field_slug => &$field) { - if ($field['type'] === 'header') { - - unset($fields[$field_slug]); + unset($fields[ $field_slug ]); continue; - - } // end if; + } $value = wu_get_isset($saved_settings, $field_slug, null); if ($value !== null) { - $field['value'] = $value; - - } // end if; - - } // end foreach; + } + } $fields['save_line'] = array( 'type' => 'group', @@ -923,23 +845,26 @@ abstract class Base_Element { ), ); - $form = new \WP_Ultimo\UI\Form($this->id, $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}_customize", - 'data-state' => wu_convert_to_state($state), - ), - )); + $form = new \WP_Ultimo\UI\Form( + $this->id, + $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}_customize", + 'data-state' => wu_convert_to_state($state), + ), + ) + ); echo '
    '; $form->render(); echo '
    '; - - } // end render_customize_modal; + } /** * Saves the customization settings for a given widget. @@ -952,7 +877,6 @@ abstract class Base_Element { $settings = array(); if (wu_request('submit') !== 'restore') { - $fields = $this->fields(); $fields['hide'] = array( @@ -960,31 +884,27 @@ abstract class Base_Element { ); foreach ($fields as $field_slug => $field) { - $setting = wu_request($field_slug, false); if ($setting !== false || $field['type'] === 'toggle') { - - $settings[$field_slug] = $setting; - - } // end if; - - } // end foreach; - - } // end if; + $settings[ $field_slug ] = $setting; + } + } + } $this->save_widget_settings($settings); - wp_send_json_success(array( - 'send' => array( - 'scope' => 'window', - 'function_name' => 'wu_block_ui', - 'data' => '#wpcontent', - ), - 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), - )); - - } // end handle_customize_modal; + wp_send_json_success( + array( + 'send' => array( + 'scope' => 'window', + 'function_name' => 'wu_block_ui', + 'data' => '#wpcontent', + ), + 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), + ) + ); + } /** * Registers scripts and styles necessary to render this. @@ -995,8 +915,7 @@ abstract class Base_Element { public function register_default_scripts() { wp_enqueue_style('wu-admin'); - - } // end register_default_scripts; + } /** * Registers scripts and styles necessary to render this. @@ -1004,7 +923,7 @@ abstract class Base_Element { * @since 2.0.0 * @return void */ - public function register_scripts() {} // end register_scripts; + public function register_scripts() {} /** * Loads dependencies that might not be available at render time. @@ -1012,7 +931,7 @@ abstract class Base_Element { * @since 2.0.0 * @return void */ - public function dependencies() {} // end dependencies; + public function dependencies() {} /** * Returns the ID of this UI element. @@ -1023,8 +942,7 @@ abstract class Base_Element { public function get_id() { return sprintf('wp-ultimo/%s', $this->id); - - } // end get_id; + } /** * Returns the ID of this UI element. @@ -1035,8 +953,7 @@ abstract class Base_Element { public function get_shortcode_id() { return str_replace('-', '_', sprintf('wu_%s', $this->id)); - - } // end get_shortcode_id; + } /** * Treats the attributes before passing them down to the output method. @@ -1048,11 +965,10 @@ abstract class Base_Element { */ public function display($atts) { - if (!$this->should_display()) { - + if ( ! $this->should_display()) { return; // bail if the display was set to false. - } // end if; + } $this->dependencies(); @@ -1069,8 +985,7 @@ abstract class Base_Element { $atts['element'] = $this; return call_user_func(array($this, 'output'), $atts); - - } // end display; + } /** * Retrieves a cleaned up version of the content. @@ -1086,20 +1001,27 @@ abstract class Base_Element { $content = $this->display($atts); - $content = str_replace(array( - 'v-', - 'data-wu', - 'data-state', - ), 'inactive-', $content); + $content = str_replace( + array( + 'v-', + 'data-wu', + 'data-state', + ), + 'inactive-', + $content + ); - $content = str_replace(array( - '{{', - '}}', - ), '', $content); + $content = str_replace( + array( + '{{', + '}}', + ), + '', + $content + ); return $content; - - } // end display_template; + } /** * Checks if we need to display admin management attachments. @@ -1111,8 +1033,7 @@ abstract class Base_Element { public function should_display_customize_controls() { return apply_filters('wu_element_display_super_admin_notice', current_user_can('manage_network'), $this); - - } // end should_display_customize_controls; + } /** * Adds the element as a inline block, without the admin widget frame. @@ -1126,56 +1047,47 @@ abstract class Base_Element { */ public function as_inline_content($screen_id, $hook = 'admin_notices', $atts = array()) { - if (!function_exists('get_current_screen')) { - + if ( ! function_exists('get_current_screen')) { _doing_it_wrong(__METHOD__, __('An element can not be loaded as inline content unless the get_current_screen() function is already available.', 'wp-ultimo'), '2.0.0'); return; - - } // end if; + } $screen = get_current_screen(); - if (!$screen || $screen_id !== $screen->id) { - + if ( ! $screen || $screen_id !== $screen->id) { return; - - } // end if; + } /* * Run the setup in this case; */ $this->setup(); - if (!$this->should_display()) { - + if ( ! $this->should_display()) { return; // bail if the display was set to false. - } // end if; + } if (empty($atts)) { - $atts = $this->get_widget_settings(); - - } // end if; + } $control_classes = ''; if (wu_get_isset($atts, 'hide', $this->hidden_by_default)) { - - if (!$this->should_display_customize_controls()) { - + if ( ! $this->should_display_customize_controls()) { return; - - } // end if; + } $control_classes = 'wu-customize-mode wu-opacity-25'; + } - } // end if; + add_action( + $hook, + function () use ($atts, $control_classes) { - add_action($hook, function() use ($atts, $control_classes) { - - echo '
    '; + echo '
    '; echo '
    '; @@ -1185,13 +1097,12 @@ abstract class Base_Element { $this->super_admin_notice(); - echo '
    '; - - }); + echo '
    '; + } + ); do_action("wu_{$this->id}_scripts", null, $this); - - } // end as_inline_content; + } /** * Save the widget options. @@ -1206,8 +1117,7 @@ abstract class Base_Element { $key = wu_replace_dashes($this->id); wu_save_setting("widget_{$key}_settings", $settings); - - } // end save_widget_settings; + } /** * Retrieves the settings for a particular widget. @@ -1220,8 +1130,7 @@ abstract class Base_Element { $key = wu_replace_dashes($this->id); return wu_get_setting("widget_{$key}_settings", array()); - - } // end get_widget_settings; + } /** * Adds the element as a metabox. @@ -1237,36 +1146,29 @@ abstract class Base_Element { $this->setup(); - if (!$this->should_display()) { - + if ( ! $this->should_display()) { return; // bail if the display was set to false. - } // end if; + } if (empty($atts)) { - $atts = $this->get_widget_settings(); - - } // end if; + } $control_classes = ''; if (wu_get_isset($atts, 'hide')) { - - if (!$this->should_display_customize_controls()) { - + if ( ! $this->should_display_customize_controls()) { return; - - } // end if; + } $control_classes = 'wu-customize-mode wu-opacity-25'; - - } // end if; + } add_meta_box( "wp-ultimo-{$this->id}-element", $this->get_title(), - function() use ($atts, $control_classes) { + function () use ($atts, $control_classes) { echo '
    '; @@ -1275,7 +1177,6 @@ abstract class Base_Element { echo '
    '; $this->super_admin_notice(); - }, $screen_id, $position, @@ -1283,8 +1184,7 @@ abstract class Base_Element { ); do_action("wu_{$this->id}_scripts", null, $this); - - } // end as_metabox; + } /** * Adds note for super admins. @@ -1326,10 +1226,8 @@ abstract class Base_Element { '; echo $html; - - } // end if; - - } // end super_admin_notice; + } + } /** * Checks if we are in a preview context. @@ -1342,14 +1240,11 @@ abstract class Base_Element { $is_preview = false; if (did_action('init')) { - $is_preview = wu_request('preview') && current_user_can('edit_posts'); - - } // end if; + } return apply_filters('wu_element_is_preview', false, $this); - - } // end is_preview; + } /** * Get controls whether or not the widget and element should display.. @@ -1360,8 +1255,7 @@ abstract class Base_Element { public function should_display() { return $this->display || $this->is_preview(); - - } // end should_display; + } /** * Set controls whether or not the widget and element should display.. @@ -1373,8 +1267,7 @@ abstract class Base_Element { public function set_display($display) { $this->display = $display; - - } // end set_display; + } /** * Checks if the current element was actually loaded. @@ -1385,7 +1278,5 @@ abstract class Base_Element { public function is_actually_loaded() { return $this->actually_loaded; - - } // end is_actually_loaded; - -} // end class Base_Element; + } +} diff --git a/inc/ui/class-billing-info-element.php b/inc/ui/class-billing-info-element.php index 7ce1954..0d7c25c 100644 --- a/inc/ui/class-billing-info-element.php +++ b/inc/ui/class-billing-info-element.php @@ -63,23 +63,20 @@ class Billing_Info_Element extends Base_Element { protected $site; /** - * The icon of the UI element. - * e.g. return fa fa-search - * - * @since 2.0.0 - * @param string $context One of the values: block, elementor or bb. - */ + * The icon of the UI element. + * e.g. return fa fa-search + * + * @since 2.0.0 + * @param string $context One of the values: block, elementor or bb. + */ public function get_icon($context = 'block'): string { if ($context === 'elementor') { - return 'eicon-info-circle-o'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * Overload the init to add site-related forms. @@ -91,13 +88,15 @@ class Billing_Info_Element extends Base_Element { parent::init(); - wu_register_form('update_billing_address', array( - 'render' => array($this, 'render_update_billing_address'), - 'handler' => array($this, 'handle_update_billing_address'), - 'capability' => 'exist', - )); - - } // end init; + wu_register_form( + 'update_billing_address', + array( + 'render' => array($this, 'render_update_billing_address'), + 'handler' => array($this, 'handle_update_billing_address'), + 'capability' => 'exist', + ) + ); + } /** * Loads the required scripts. @@ -108,8 +107,7 @@ class Billing_Info_Element extends Base_Element { public function register_scripts() { add_wubox(); - - } // end register_scripts; + } /** * The title of the UI element. @@ -124,8 +122,7 @@ class Billing_Info_Element extends Base_Element { public function get_title() { return __('Billing Information', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -141,8 +138,7 @@ class Billing_Info_Element extends Base_Element { public function get_description() { return __('Adds a checkout form block to the page.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -180,8 +176,7 @@ class Billing_Info_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * The list of keywords for this element. @@ -209,8 +204,7 @@ class Billing_Info_Element extends Base_Element { 'Form', 'Cart', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -231,8 +225,7 @@ class Billing_Info_Element extends Base_Element { return array( 'title' => __('Billing Address', 'wp-ultimo'), ); - - } // end defaults; + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -244,15 +237,12 @@ class Billing_Info_Element extends Base_Element { $this->membership = WP_Ultimo()->currents->get_membership(); - if (!$this->membership) { - + if ( ! $this->membership) { $this->set_display(false); return; - - } // end if; - - } // end setup; + } + } /** * Allows the setup in the context of previews. @@ -265,8 +255,7 @@ class Billing_Info_Element extends Base_Element { $this->site = wu_mock_site(); $this->membership = wu_mock_membership(); - - } // end setup_preview; + } /** * The content to be output on the screen. @@ -287,14 +276,16 @@ class Billing_Info_Element extends Base_Element { $atts['billing_address'] = $this->membership->get_billing_address(); - $atts['update_billing_address_link'] = wu_get_form_url('update_billing_address', array( - 'membership' => $this->membership->get_hash(), - 'width' => 500, - )); + $atts['update_billing_address_link'] = wu_get_form_url( + 'update_billing_address', + array( + 'membership' => $this->membership->get_hash(), + 'width' => 500, + ) + ); return wu_get_template_contents('dashboard-widgets/billing-info', $atts); - - } // end output; + } /** * Apply the placeholders to the fields. @@ -307,14 +298,11 @@ class Billing_Info_Element extends Base_Element { protected function apply_placeholders($fields) { foreach ($fields as &$field) { - $field['placeholder'] = $field['default_placeholder']; - - } // end foreach; + } return $fields; - - } // end apply_placeholders; + } /** * Renders the update billing address form. @@ -326,11 +314,9 @@ class Billing_Info_Element extends Base_Element { $membership = wu_get_membership_by_hash(wu_request('membership')); - if (!$membership) { - + if ( ! $membership) { return ''; - - } // end if; + } $billing_address = $membership->get_billing_address(); @@ -361,19 +347,22 @@ class Billing_Info_Element extends Base_Element { 'value' => wu_request('membership'), ); - $form = new \WP_Ultimo\UI\Form('edit_site', $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0 wu-grid-cols-2 wu-grid', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid wu-grid-col-span-2', - 'html_attr' => array( - 'data-wu-app' => 'edit_site', - 'data-state' => wu_convert_to_state(), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'edit_site', + $fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0 wu-grid-cols-2 wu-grid', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid wu-grid-col-span-2', + 'html_attr' => array( + 'data-wu-app' => 'edit_site', + 'data-state' => wu_convert_to_state(), + ), + ) + ); $form->render(); - - } // end render_update_billing_address; + } /** * Handles the password reset form. @@ -385,13 +374,11 @@ class Billing_Info_Element extends Base_Element { $membership = wu_get_membership_by_hash(wu_request('membership')); - if (!$membership) { - + if ( ! $membership) { $error = new \WP_Error('membership-dont-exist', __('Something went wrong.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } $billing_address = $membership->get_billing_address(); @@ -400,25 +387,21 @@ class Billing_Info_Element extends Base_Element { $valid_address = $billing_address->validate(); if (is_wp_error($valid_address)) { - wp_send_json_error($valid_address); - - } // end if; + } $membership->set_billing_address($billing_address); $saved = $membership->save(); if (is_wp_error($saved)) { - wp_send_json_error($saved); + } - } // end if; - - wp_send_json_success(array( - 'redirect_url' => add_query_arg('updated', (int) $saved, $_SERVER['HTTP_REFERER']), - )); - - } // end handle_update_billing_address; - -} // end class Billing_Info_Element; + wp_send_json_success( + array( + 'redirect_url' => add_query_arg('updated', (int) $saved, $_SERVER['HTTP_REFERER']), + ) + ); + } +} diff --git a/inc/ui/class-checkout-element.php b/inc/ui/class-checkout-element.php index cb2bc8e..83180f9 100644 --- a/inc/ui/class-checkout-element.php +++ b/inc/ui/class-checkout-element.php @@ -9,9 +9,9 @@ namespace WP_Ultimo\UI; -use \WP_Ultimo\UI\Base_Element; -use \ScssPhp\ScssPhp\Compiler; -use \WP_Ultimo\Database\Memberships\Membership_Status; +use WP_Ultimo\UI\Base_Element; +use ScssPhp\ScssPhp\Compiler; +use WP_Ultimo\Database\Memberships\Membership_Status; // Exit if accessed directly defined('ABSPATH') || exit; @@ -29,8 +29,8 @@ class Checkout_Element extends Base_Element { * The current signup. * * @since 2.2.0 - * @var Mocked_Signup - */ + * @var Mocked_Signup + */ protected $signup; /** @@ -81,23 +81,20 @@ class Checkout_Element extends Base_Element { protected $public = true; /** - * The icon of the UI element. - * e.g. return fa fa-search - * - * @since 2.0.0 - * @param string $context One of the values: block, elementor or bb. - */ + * The icon of the UI element. + * e.g. return fa fa-search + * + * @since 2.0.0 + * @param string $context One of the values: block, elementor or bb. + */ public function get_icon($context = 'block'): string { if ($context === 'elementor') { - return 'eicon-cart-medium'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * The title of the UI element. @@ -112,8 +109,7 @@ class Checkout_Element extends Base_Element { public function get_title() { return __('Checkout', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -129,8 +125,7 @@ class Checkout_Element extends Base_Element { public function get_description() { return __('Adds a checkout form block to the page.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -166,8 +161,7 @@ class Checkout_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * The list of keywords for this element. @@ -195,8 +189,7 @@ class Checkout_Element extends Base_Element { 'Form', 'Cart', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -220,8 +213,7 @@ class Checkout_Element extends Base_Element { 'display_title' => false, 'membership_limitations' => array(), ); - - } // end defaults; + } /** * Checks if we are on a thank you page. @@ -232,8 +224,7 @@ class Checkout_Element extends Base_Element { public function is_thank_you_page() { return is_user_logged_in() && wu_request('payment') && wu_request('status') === 'done'; - - } // end is_thank_you_page; + } /** * Triggers the setup event to allow the checkout class to hook in. @@ -244,16 +235,13 @@ class Checkout_Element extends Base_Element { public function setup() { if ($this->is_thank_you_page()) { - \WP_Ultimo\UI\Thank_You_Element::get_instance()->setup(); return; - - } // end if; + } do_action('wu_setup_checkout', $this); - - } // end setup; + } /** * Print the Custom CSS added on the checkout. @@ -272,16 +260,15 @@ class Checkout_Element extends Base_Element { $custom_css = $checkout_form->get_custom_css(); if ($custom_css) { - - $custom_css = $scss->compileString(".wu_checkout_form_{$slug} { + $custom_css = $scss->compileString( + ".wu_checkout_form_{$slug} { {$custom_css} - }")->getCss(); + }" + )->getCss(); - echo sprintf('', $custom_css); - - } // end if; - - } // end print_custom_css; + printf('', $custom_css); + } + } /** * Outputs thank you page. @@ -305,8 +292,7 @@ class Checkout_Element extends Base_Element { \WP_Ultimo\UI\Thank_You_Element::get_instance()->register_scripts(); return \WP_Ultimo\UI\Thank_You_Element::get_instance()->output($atts, $content); - - } // end output_thank_you; + } /** * Outputs the registration form. @@ -336,18 +322,15 @@ class Checkout_Element extends Base_Element { $bypass = apply_filters('wu_bypass_checkout_form', false, $atts); if ($bypass) { - return is_string($bypass) ? $bypass : ''; - - } // end if; + } if ($customer && $membership && $slug !== 'wu-finish-checkout') { - $published_sites = $membership->get_published_sites(); $pending_payment = $membership ? $membership->get_last_pending_payment() : false; - if ($pending_payment && !$membership->is_active() && $membership->get_status() !== Membership_Status::TRIALING) { + if ($pending_payment && ! $membership->is_active() && $membership->get_status() !== Membership_Status::TRIALING) { /** * We are talking about membership with a pending payment */ @@ -355,9 +338,12 @@ class Checkout_Element extends Base_Element { // Translators: Placeholder receives the customer display name $message = sprintf(__('Hi %s. You have a pending payment for your membership!', 'wp-ultimo'), $customer->get_display_name()); - $payment_url = add_query_arg(array( - 'payment' => $pending_payment->get_hash(), - ), wu_get_registration_url()); + $payment_url = add_query_arg( + array( + 'payment' => $pending_payment->get_hash(), + ), + wu_get_registration_url() + ); // Translators: The link to registration url with payment hash $message .= '
    ' . sprintf(__('Click here to pay.', 'wp-ultimo'), $payment_url); @@ -372,14 +358,13 @@ class Checkout_Element extends Base_Element { * @param WP_Ultimo\Models\Customer $customer The active customer in use. */ return apply_filters('wu_checkout_pending_payment_error_message', $message, $membership, $customer); - - } // end if; + } $membership_blocked_forms = array( - 'wu-add-new-site' + 'wu-add-new-site', ); - if (!$membership->is_active() && $membership->get_status() !== Membership_Status::TRIALING && in_array($atts['slug'], $membership_blocked_forms, true)) { + if ( ! $membership->is_active() && $membership->get_status() !== Membership_Status::TRIALING && in_array($atts['slug'], $membership_blocked_forms, true)) { // Translators: Placeholder receives the customer display name $message = sprintf(__('Hi %s. You cannot take action on your membership while it is not active!', 'wp-ultimo'), $customer->get_display_name()); @@ -390,15 +375,19 @@ class Checkout_Element extends Base_Element { */ wp_register_script('wu-thank-you', wu_get_asset('thank-you.js', 'js'), array(), wu_get_version()); - wp_localize_script('wu-thank-you', 'wu_thank_you', array( - 'ajaxurl' => admin_url('admin-ajax.php'), - 'resend_verification_email_nonce' => wp_create_nonce('wu_resend_verification_email_nonce'), - 'membership_hash' => $membership->get_hash(), - 'i18n' => array( - 'resending_verification_email' => __('Resending verification email...', 'wp-ultimo'), - 'email_sent' => __('Verification email sent!', 'wp-ultimo'), - ), - )); + wp_localize_script( + 'wu-thank-you', + 'wu_thank_you', + array( + 'ajaxurl' => admin_url('admin-ajax.php'), + 'resend_verification_email_nonce' => wp_create_nonce('wu_resend_verification_email_nonce'), + 'membership_hash' => $membership->get_hash(), + 'i18n' => array( + 'resending_verification_email' => __('Resending verification email...', 'wp-ultimo'), + 'email_sent' => __('Verification email sent!', 'wp-ultimo'), + ), + ) + ); wp_enqueue_script('wu-thank-you'); @@ -406,8 +395,7 @@ class Checkout_Element extends Base_Element { $message .= ''; $message .= sprintf('%s', __('Resend verification email', 'wp-ultimo')); $message .= ''; - - } // end if; + } /** * Allow developers to change the message if membership have a pending payment @@ -417,33 +405,32 @@ class Checkout_Element extends Base_Element { * @param WP_Ultimo\Models\Customer $customer The active customer in use. */ return apply_filters('wu_checkout_membership_status_error_message', $message, $membership, $customer); + } - } // end if; - - if (!wu_multiple_memberships_enabled() && $membership) { + if ( ! wu_multiple_memberships_enabled() && $membership) { /** * Allow developers to add new form slugs to bypass this behaviour. * * @param array $slugs a list of form slugs to bypass. */ - $allowed_forms = apply_filters('wu_get_membership_allowed_forms', array( - 'wu-checkout', - 'wu-add-new-site', - )); - - if (!in_array($slug, $allowed_forms, true) && !wu_request('payment')) { + $allowed_forms = apply_filters( + 'wu_get_membership_allowed_forms', + array( + 'wu-checkout', + 'wu-add-new-site', + ) + ); + if ( ! in_array($slug, $allowed_forms, true) && ! wu_request('payment')) { $message = sprintf('

    %s

    ', __('You already have a membership!', 'wp-ultimo')); if (isset($published_sites[0])) { - $account_link = get_admin_url($published_sites[0]->get_id(), 'admin.php?page=account'); $button_text = __('Go to my account', 'wp-ultimo'); $message .= "

    $button_text

    "; - - } // end if; + } /** * Allow developers to change the message about the limitation of a single membership for customer. @@ -452,13 +439,10 @@ class Checkout_Element extends Base_Element { * @param WP_Ultimo\Models\Customer $customer The active customer in use. */ return apply_filters('wu_checkout_single_membership_message', $message, $customer); - - } // end if; - - } // end if; + } + } if ($membership && $membership->get_customer_id() !== $customer->get_id()) { - $message = sprintf('

    %s

    ', __('You are not allowed to change this membership!', 'wp-ultimo')); /** @@ -469,8 +453,7 @@ class Checkout_Element extends Base_Element { * @param WP_Ultimo\Models\Customer $customer The active customer in use. */ return apply_filters('wu_checkout_customer_error_message', $message, $membership, $customer); - - } // end if; + } /** * Now we filter the current membership for each membership_limitations @@ -478,23 +461,19 @@ class Checkout_Element extends Base_Element { * a error message informing the user about and with buttons to allow * account upgrade and/or to buy a new membership. */ - if ($membership && !empty($atts['membership_limitations'])) { - + if ($membership && ! empty($atts['membership_limitations'])) { $limits = $membership->get_limitations(); foreach ($atts['membership_limitations'] as $limitation) { - - if (!method_exists($membership, "get_$limitation")) { - + if ( ! method_exists($membership, "get_$limitation")) { continue; - - } // end if; + } $current_limit = $limits->{$limitation}; $limit_max = $current_limit->is_enabled() ? $current_limit->get_limit() : PHP_INT_MAX; - $limit_max = !empty($limit_max) ? (int) $limit_max : 1; + $limit_max = ! empty($limit_max) ? (int) $limit_max : 1; $used_limit = $membership->{"get_$limitation"}(); @@ -508,16 +487,13 @@ class Checkout_Element extends Base_Element { $message .= ''; if (wu_multiple_memberships_enabled()) { - $register_page = wu_get_registration_url(); $button_text = __('Buy a new membership', 'wp-ultimo'); $message .= "$button_text"; - - } // end if; + } if ($limitation !== 'sites' || wu_get_setting('enable_multiple_sites')) { - $update_link = ''; $checkout_pages = \WP_Ultimo\Checkout\Checkout_Pages::get_instance(); @@ -525,30 +501,24 @@ class Checkout_Element extends Base_Element { $update_url = $checkout_pages->get_page_url('update'); if ($update_url) { - - $update_link = add_query_arg(array( - 'membership' => $membership->get_hash(), - ), $update_url); - + $update_link = add_query_arg( + array( + 'membership' => $membership->get_hash(), + ), + $update_url + ); } elseif (is_admin()) { - $update_link = admin_url('admin.php?page=wu-checkout&membership=' . $membership->get_hash()); - } elseif (isset($published_sites[0])) { - $update_link = get_admin_url($published_sites[0]->get_id(), 'admin.php?page=wu-checkout&membership=' . $membership->get_hash()); + } - } // end if; - - if (!empty($update_link)) { - + if ( ! empty($update_link)) { $button_text = __('Upgrade your account', 'wp-ultimo'); $message .= "$button_text"; - - } // end if; - - } // end if; + } + } $message .= ''; @@ -563,27 +533,18 @@ class Checkout_Element extends Base_Element { * @param WP_Ultimo\Models\Customer $customer The active customer in use. */ return apply_filters('wu_checkout_membership_limit_message', $message, $limitation, $limit_max, $used_limit, $membership, $customer); - - } // end if; - - } // end foreach; - - } // end if; - - } elseif (!$customer && $slug === 'wu-finish-checkout') { - + } + } + } + } elseif ( ! $customer && $slug === 'wu-finish-checkout') { if (is_user_logged_in()) { - $message = __('You need to be the account owner to complete this payment.', 'wp-ultimo'); - } else { - $message = __('You need to be logged in to complete a payment', 'wp-ultimo'); // Translators: The link to login url with redirect_to url $message .= '
    ' . sprintf(__('Click here sign in.', 'wp-ultimo'), wp_login_url(wu_get_current_url())); - - } // end if; + } $message = '

    ' . $message . '

    '; @@ -593,42 +554,33 @@ class Checkout_Element extends Base_Element { * @param string $message The HTML message to print in screen. */ return apply_filters('wu_checkout_payment_login_error_message', $message); - - } // end if; + } $checkout_form = wu_get_checkout_form_by_slug($slug); - if (!$checkout_form) { + if ( ! $checkout_form) { // translators: %s is the id of the form. e.g. main-form return sprintf(__('Checkout form %s not found.', 'wp-ultimo'), $slug); - - } // end if; + } if ($checkout_form->get_field_count() === 0) { // translators: %s is the id of the form. e.g. main-form return sprintf(__('Checkout form %s contains no fields.', 'wp-ultimo'), $slug); - } - if (!$checkout_form->is_active() || !wu_get_setting('enable_registration')) { - + if ( ! $checkout_form->is_active() || ! wu_get_setting('enable_registration')) { return sprintf('

    %s

    ', __('Registration is not available at this time.', 'wp-ultimo')); - - } // end if; + } if ($checkout_form->has_country_lock()) { - $geolocation = \WP_Ultimo\Geolocation::geolocate_ip('', true); - if (!in_array($geolocation['country'], $checkout_form->get_allowed_countries(), true)) { - + if ( ! in_array($geolocation['country'], $checkout_form->get_allowed_countries(), true)) { return sprintf('

    %s

    ', __('Registration is closed for your location.', 'wp-ultimo')); - - } // end if; - - } // end if; + } + } $checkout = \WP_Ultimo\Checkout\Checkout::get_instance(); @@ -640,10 +592,13 @@ class Checkout_Element extends Base_Element { $this->step = $step ? $step : current($this->steps); - $this->step = wp_parse_args($this->step, array( - 'classes' => '', - 'fields' => array(), - )); + $this->step = wp_parse_args( + $this->step, + array( + 'classes' => '', + 'fields' => array(), + ) + ); $this->step_name = $this->step['id'] ?? ''; @@ -656,11 +611,13 @@ class Checkout_Element extends Base_Element { $this->signup = $signup; - add_action('wp_print_footer_scripts', function() use ($checkout_form) { + add_action( + 'wp_print_footer_scripts', + function () use ($checkout_form) { - $this->print_custom_css($checkout_form); - - }); + $this->print_custom_css($checkout_form); + } + ); /* * Load the checkout class with the parameters @@ -690,16 +647,18 @@ class Checkout_Element extends Base_Element { $final_fields = apply_filters('wu_checkout_form_final_fields', $final_fields, $this); - return wu_get_template_contents('checkout/form', array( - 'step' => $this->step, - 'step_name' => $this->step_name, - 'checkout_form_name' => $atts['slug'], - 'errors' => $checkout->errors, - 'display_title' => $atts['display_title'], - 'final_fields' => $final_fields, - )); - - } // end output_form; + return wu_get_template_contents( + 'checkout/form', + array( + 'step' => $this->step, + 'step_name' => $this->step_name, + 'checkout_form_name' => $atts['slug'], + 'errors' => $checkout->errors, + 'display_title' => $atts['display_title'], + 'final_fields' => $final_fields, + ) + ); + } /** * Injects the auto-submittable field inline snippet. @@ -711,30 +670,31 @@ class Checkout_Element extends Base_Element { */ public function inject_inline_auto_submittable_field($auto_submittable_field) { - $callback = function() use ($auto_submittable_field) { + $callback = function () use ($auto_submittable_field) { - wp_add_inline_script('wu-checkout', sprintf(' + wp_add_inline_script( + 'wu-checkout', + sprintf( + ' /** * Set the auto-submittable field, if one exists. */ window.wu_auto_submittable_field = %s; - ', json_encode($auto_submittable_field)), 'after'); - + ', + json_encode($auto_submittable_field) + ), + 'after' + ); }; - if (wu_is_block_theme() && !is_admin()) { - + if (wu_is_block_theme() && ! is_admin()) { add_action('wu_checkout_scripts', $callback, 100); - } else { - call_user_func($callback); - - } // end if; - - } // end inject_inline_auto_submittable_field; + } + } /** * The content to be output on the screen. @@ -752,66 +712,57 @@ class Checkout_Element extends Base_Element { public function output($atts, $content = null) { if (wu_is_update_page()) { - $atts = array( 'slug' => apply_filters('wu_membership_update_form', 'wu-checkout'), 'step' => false, 'display_title' => false, ); - - } // end if; + } if (wu_is_new_site_page()) { - $atts = array( 'slug' => apply_filters('wu_membership_new_site_form', 'wu-add-new-site'), 'step' => false, 'display_title' => false, 'membership_limitations' => array('sites'), ); - - } // end if; + } if ($this->is_thank_you_page()) { - return $this->output_thank_you($atts, $content); - - } // end if; + } /** * Allow developers to add new update form slugs. * * @param array $slugs a list of form slugs to bypass. */ - $update_forms = apply_filters('wu_membership_update_forms', array( - 'wu-checkout', - )); - - if (!in_array($atts['slug'], $update_forms, true) && (wu_request('payment') || wu_request('payment_id'))) { + $update_forms = apply_filters( + 'wu_membership_update_forms', + array( + 'wu-checkout', + ) + ); + if ( ! in_array($atts['slug'], $update_forms, true) && (wu_request('payment') || wu_request('payment_id'))) { $atts = array( 'slug' => 'wu-finish-checkout', 'step' => false, 'display_title' => false, ); - - } // end if; + } if (wu_request('wu_form') && in_array(wu_request('wu_form'), $update_forms, true)) { - $atts = array( 'slug' => wu_request('wu_form'), 'step' => false, 'display_title' => false, ); - - } // end if; + } return $this->output_form($atts, $content); - - } // end output; - -} // end class Checkout_Element; + } +} /** * Replacement of the old WU_Signup class for templates. @@ -820,14 +771,14 @@ class Checkout_Element extends Base_Element { */ class Mocked_Signup { /** - * @var string - */ - public $step; - /** - * @var array - */ - public $steps; - /** + * @var string + */ + public $step; + /** + * @var array + */ + public $steps; + /** * Constructs the class. * * @since 2.0.0 @@ -835,11 +786,10 @@ class Mocked_Signup { * @param string $step Current step. * @param array $steps List of all steps. */ - public function __construct($step, $steps) - { - $this->step = $step; - $this->steps = $steps; - } // end __construct; + public function __construct($step, $steps) { + $this->step = $step; + $this->steps = $steps; + } /** * Get the value of steps. @@ -850,8 +800,7 @@ class Mocked_Signup { public function get_steps() { return $this->steps; - - } // end get_steps; + } /** * Deprecated: returns the prev step link. * @@ -860,7 +809,5 @@ class Mocked_Signup { public function get_prev_step_link(): string { return ''; - - } // end get_prev_step_link; - -} // end class Mocked_Signup; + } +} diff --git a/inc/ui/class-current-membership-element.php b/inc/ui/class-current-membership-element.php index ed1c1ef..c851ad1 100644 --- a/inc/ui/class-current-membership-element.php +++ b/inc/ui/class-current-membership-element.php @@ -9,8 +9,8 @@ namespace WP_Ultimo\UI; -use \WP_Ultimo\UI\Base_Element; -use \WP_Ultimo\Checkout\Cart; +use WP_Ultimo\UI\Base_Element; +use WP_Ultimo\Checkout\Cart; // Exit if accessed directly defined('ABSPATH') || exit; @@ -73,18 +73,23 @@ class Current_Membership_Element extends Base_Element { parent::init(); - wu_register_form('see_product_details', array( - 'render' => array($this, 'render_product_details'), - 'capability' => 'exist', - )); + wu_register_form( + 'see_product_details', + array( + 'render' => array($this, 'render_product_details'), + 'capability' => 'exist', + ) + ); - wu_register_form('edit_membership_product_modal', array( - 'render' => array($this, 'render_edit_membership_product_modal'), - 'handler' => array($this, 'handle_edit_membership_product_modal'), - 'capability' => 'exist', - )); - - } // end init; + wu_register_form( + 'edit_membership_product_modal', + array( + 'render' => array($this, 'render_edit_membership_product_modal'), + 'handler' => array($this, 'handle_edit_membership_product_modal'), + 'capability' => 'exist', + ) + ); + } /** * Loads the required scripts. @@ -95,8 +100,7 @@ class Current_Membership_Element extends Base_Element { public function register_scripts() { add_wubox(); - - } // end register_scripts; + } /** * The icon of the UI element. * e.g. return fa fa-search @@ -107,14 +111,11 @@ class Current_Membership_Element extends Base_Element { public function get_icon($context = 'block'): string { if ($context === 'elementor') { - return 'eicon-info-circle-o'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * The title of the UI element. @@ -129,8 +130,7 @@ class Current_Membership_Element extends Base_Element { public function get_title() { return __('Membership', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -146,8 +146,7 @@ class Current_Membership_Element extends Base_Element { public function get_description() { return __('Adds a checkout form block to the page.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -203,8 +202,7 @@ class Current_Membership_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * The list of keywords for this element. @@ -232,8 +230,7 @@ class Current_Membership_Element extends Base_Element { 'Form', 'Cart', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -256,8 +253,7 @@ class Current_Membership_Element extends Base_Element { 'display_images' => 1, 'columns' => 2, ); - - } // end defaults; + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -269,17 +265,14 @@ class Current_Membership_Element extends Base_Element { $this->membership = WP_Ultimo()->currents->get_membership(); - if (!$this->membership) { - + if ( ! $this->membership) { $this->set_display(false); return; - - } // end if; + } $this->plan = $this->membership ? $this->membership->get_plan() : false; - - } // end setup; + } /** * Allows the setup in the context of previews. @@ -292,8 +285,7 @@ class Current_Membership_Element extends Base_Element { $this->membership = wu_mock_membership(); $this->plan = wu_mock_product(); - - } // end setup_preview; + } /** * The content to be output on the screen. @@ -317,35 +309,33 @@ class Current_Membership_Element extends Base_Element { $atts['pending_change'] = false; if ($this->membership) { - $pending_swap_order = $this->membership->get_scheduled_swap(); $atts['pending_products'] = false; if ($pending_swap_order) { - $atts['pending_change'] = $pending_swap_order->order->get_cart_descriptor(); $atts['pending_change_date'] = wu_date($pending_swap_order->scheduled_date)->format(get_option('date_format')); $swap_membership = (clone $this->membership)->swap($pending_swap_order->order); - $pending_products = array_map(fn($product) => array( - 'id' => $product['product']->get_id(), - 'quantity' => $product['quantity'], - ), $swap_membership->get_all_products()); + $pending_products = array_map( + fn($product) => array( + 'id' => $product['product']->get_id(), + 'quantity' => $product['quantity'], + ), + $swap_membership->get_all_products() + ); // add the id as key $atts['pending_products'] = array_combine(array_column($pending_products, 'id'), $pending_products); - - } // end if; + } return wu_get_template_contents('dashboard-widgets/current-membership', $atts); - - } // end if; + } return ''; - - } // end output; + } /** * Renders the product details modal window. @@ -357,17 +347,14 @@ class Current_Membership_Element extends Base_Element { $product = wu_get_product_by_slug(wu_request('product')); - if (!$product) { - + if ( ! $product) { return; - - } // end if; + } $atts['product'] = $product; wu_get_template('dashboard-widgets/current-membership-product-details', $atts); - - } // end render_product_details; + } /** * Renders the add/edit line items form. @@ -381,30 +368,23 @@ class Current_Membership_Element extends Base_Element { $error = ''; - if (!$membership) { - + if ( ! $membership) { $error = __('Membership not selected.', 'wp-ultimo'); - - } // end if; + } $product = wu_get_product_by_slug(wu_request('product')); - if (!$product) { - + if ( ! $product) { $error = __('Product not selected.', 'wp-ultimo'); - - } // end if; + } $customer = wu_get_current_customer(); - if (empty($error) && !is_super_admin() && (!$customer || $customer->get_id() !== $membership->get_customer_id())) { - + if (empty($error) && ! is_super_admin() && (! $customer || $customer->get_id() !== $membership->get_customer_id())) { $error = __('You are not allowed to do this.', 'wp-ultimo'); + } - } // end if; - - if (!empty($error)) { - + if ( ! empty($error)) { $error_field = array( 'error_message' => array( 'type' => 'note', @@ -412,17 +392,20 @@ class Current_Membership_Element extends Base_Element { ), ); - $form = new \WP_Ultimo\UI\Form('cancel_payment_method', $error_field, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - )); + $form = new \WP_Ultimo\UI\Form( + 'cancel_payment_method', + $error_field, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + ) + ); $form->render(); return; - - } // end if; + } /** * If there is a scheduled swap, we need to swap the membership before @@ -431,20 +414,16 @@ class Current_Membership_Element extends Base_Element { $existing_swap = $membership->get_scheduled_swap(); if ($existing_swap) { - $membership = $membership->swap($existing_swap->order); - - } // end if; + } $gateway_message = false; - if (!empty($membership->get_gateway())) { - + if ( ! empty($membership->get_gateway())) { $gateway = wu_get_gateway($membership->get_gateway()); $gateway_message = $gateway ? $gateway->get_amount_update_message(true) : ''; - - } // end if; + } $existing_quantity = array_filter($membership->get_addon_products(), fn($item) => $item['product']->get_id() === $product->get_id())[0]['quantity']; @@ -499,27 +478,30 @@ class Current_Membership_Element extends Base_Element { ), ); - if (!$gateway_message) { - + if ( ! $gateway_message) { unset($fields['update_note']); + } - } // end if; - - $form = new \WP_Ultimo\UI\Form('edit_membership_product', $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - 'html_attr' => array( - 'data-wu-app' => 'edit_membership_product', - 'data-state' => wu_convert_to_state(array( - 'confirmed' => false, - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'edit_membership_product', + $fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + 'html_attr' => array( + 'data-wu-app' => 'edit_membership_product', + 'data-state' => wu_convert_to_state( + array( + 'confirmed' => false, + ) + ), + ), + ) + ); $form->render(); - - } // end render_edit_membership_product_modal; + } /** * Handles the membership product remove. @@ -529,43 +511,35 @@ class Current_Membership_Element extends Base_Element { */ public function handle_edit_membership_product_modal() { - if (!wu_request('confirm')) { - + if ( ! wu_request('confirm')) { $error = new \WP_Error('not-confirmed', __('Please confirm the cancellation.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } $membership = wu_get_membership_by_hash(wu_request('membership')); - if (!$membership) { - + if ( ! $membership) { $error = new \WP_Error('membership-not-found', __('Membership not found.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } $product = wu_get_product_by_slug(wu_request('product')); - if (!$product) { - + if ( ! $product) { $error = new \WP_Error('product-not-found', __('Product not found.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } $customer = wu_get_current_customer(); - if (!is_super_admin() && (!$customer || $customer->get_id() !== $membership->get_customer_id())) { - + if ( ! is_super_admin() && (! $customer || $customer->get_id() !== $membership->get_customer_id())) { $error = __('You are not allowed to do this.', 'wp-ultimo'); wp_send_json_error($error); - - } // end if; + } // Get the existing quantity by filtering the products array. $existing_quantity = array_filter($membership->get_addon_products(), fn($item) => $item['product']->get_id() === $product->get_id())[0]['quantity']; @@ -579,12 +553,10 @@ class Current_Membership_Element extends Base_Element { $existing_swap = $membership->get_scheduled_swap(); if ($existing_swap) { - $membership = $membership->swap($existing_swap->order); $existing_quantity = array_filter($membership->get_addon_products(), fn($item) => $item['product']->get_id() === $product->get_id())[0]['quantity']; - - } // end if; + } $quantity = (int) wu_request('quantity', 1); $quantity = $quantity > $existing_quantity ? $existing_quantity : $quantity; @@ -594,20 +566,16 @@ class Current_Membership_Element extends Base_Element { $value_to_remove = wu_get_membership_product_price($membership, $product->get_id(), $quantity); if (is_wp_error($value_to_remove)) { - wp_send_json_error($value_to_remove); - - } // end if; + } $plan_price = wu_get_membership_product_price($membership, $membership->get_plan()->get_id(), 1); // do not allow remove more than the plan price if ($plan_price < $value_to_remove) { - $value_to_remove = $membership->get_amount() - $plan_price; $value_to_remove = $value_to_remove < 0 ? 0 : $value_to_remove; - - } // end if; + } $membership->set_amount($membership->get_amount() - $value_to_remove); @@ -626,24 +594,20 @@ class Current_Membership_Element extends Base_Element { // Lets schedule this change as the customer already paid for this period. if (is_wp_error($schedule_swap)) { - wp_send_json_error($schedule_swap); - - } // end if; + } // Now we trigger the gateway update so the customer is charged for the new amount. $gateway = wu_get_gateway($membership->get_gateway()); if ($gateway) { - $gateway->process_membership_update($membership, $customer); + } - } // end if; - - wp_send_json_success(array( - 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), - )); - - } // end handle_edit_membership_product_modal; - -} // end class Current_Membership_Element; + wp_send_json_success( + array( + 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), + ) + ); + } +} diff --git a/inc/ui/class-current-site-element.php b/inc/ui/class-current-site-element.php index e3e4df2..f89aa94 100644 --- a/inc/ui/class-current-site-element.php +++ b/inc/ui/class-current-site-element.php @@ -63,23 +63,20 @@ class Current_Site_Element extends Base_Element { public $membership; /** - * The icon of the UI element. - * e.g. return fa fa-search - * - * @since 2.0.0 - * @param string $context One of the values: block, elementor or bb. - */ + * The icon of the UI element. + * e.g. return fa fa-search + * + * @since 2.0.0 + * @param string $context One of the values: block, elementor or bb. + */ public function get_icon($context = 'block'): string { if ($context === 'elementor') { - return 'eicon-info-circle-o'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * Overload the init to add site-related forms. @@ -91,13 +88,15 @@ class Current_Site_Element extends Base_Element { parent::init(); - wu_register_form('edit_site', array( - 'render' => array($this, 'render_edit_site'), - 'handler' => array($this, 'handle_edit_site'), - 'capability' => 'exist', - )); - - } // end init; + wu_register_form( + 'edit_site', + array( + 'render' => array($this, 'render_edit_site'), + 'handler' => array($this, 'handle_edit_site'), + 'capability' => 'exist', + ) + ); + } /** * The title of the UI element. @@ -112,8 +111,7 @@ class Current_Site_Element extends Base_Element { public function get_title() { return __('Site', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -129,8 +127,7 @@ class Current_Site_Element extends Base_Element { public function get_description() { return __('Adds a block to display the current site being managed.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -167,19 +164,19 @@ class Current_Site_Element extends Base_Element { 'value' => 1, ); - $pages = get_pages(array( - 'exclude' => array(get_the_ID()), - )); + $pages = get_pages( + array( + 'exclude' => array(get_the_ID()), + ) + ); $pages = $pages ? $pages : array(); $pages_list = array(0 => __('Current Page', 'wp-ultimo')); foreach ($pages as $page) { - - $pages_list[$page->ID] = $page->post_title; - - } // end foreach; + $pages_list[ $page->ID ] = $page->post_title; + } $fields['breadcrumbs_my_sites_page'] = array( 'type' => 'select', @@ -242,8 +239,7 @@ class Current_Site_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * The list of keywords for this element. @@ -271,8 +267,7 @@ class Current_Site_Element extends Base_Element { 'Form', 'Cart', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -299,8 +294,7 @@ class Current_Site_Element extends Base_Element { 'breadcrumbs_my_sites_page' => 0, 'show_admin_link' => 1, ); - - } // end defaults; + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -312,17 +306,14 @@ class Current_Site_Element extends Base_Element { $this->site = WP_Ultimo()->currents->get_site(); - if (!$this->site || !$this->site->is_customer_allowed()) { - + if ( ! $this->site || ! $this->site->is_customer_allowed()) { $this->set_display(false); return; - - } // end if; + } $this->membership = $this->site->get_membership(); - - } // end setup; + } /** * Allows the setup in the context of previews. @@ -335,8 +326,7 @@ class Current_Site_Element extends Base_Element { $this->site = wu_mock_site(); $this->membership = wu_mock_membership(); - - } // end setup_preview; + } /** * Loads the required scripts. @@ -347,8 +337,7 @@ class Current_Site_Element extends Base_Element { public function register_scripts() { add_wubox(); - - } // end register_scripts; + } /** * The content to be output on the screen. @@ -376,22 +365,23 @@ class Current_Site_Element extends Base_Element { 'label' => __('Edit Site', 'wp-ultimo'), 'icon_classes' => 'dashicons-wu-edit wu-align-text-bottom', 'classes' => 'wubox', - 'href' => wu_get_form_url('edit_site', array( - 'site' => $this->site->get_hash(), - )), + 'href' => wu_get_form_url( + 'edit_site', + array( + 'site' => $this->site->get_hash(), + ) + ), ), ); if ($atts['show_admin_link']) { - $actions['site_admin'] = array( 'label' => __('Admin Panel', 'wp-ultimo'), 'icon_classes' => 'dashicons-wu-grid wu-align-text-bottom', 'classes' => '', 'href' => get_admin_url($this->site->get_id()), ); - - } // end if; + } $atts['actions'] = apply_filters('wu_current_site_actions', $actions, $this->site); @@ -404,8 +394,7 @@ class Current_Site_Element extends Base_Element { $atts['my_sites_url'] = is_admin() ? admin_url('admin.php?page=sites') : $my_sites_url; return wu_get_template_contents('dashboard-widgets/current-site', $atts); - - } // end output; + } /** * Renders the edit site modal. @@ -417,11 +406,9 @@ class Current_Site_Element extends Base_Element { $site = wu_get_site_by_hash(wu_request('site')); - if (!$site) { - + if ( ! $site) { return ''; - - } // end if; + } $fields = array( 'site_title' => array( @@ -460,21 +447,26 @@ class Current_Site_Element extends Base_Element { $fields = apply_filters('wu_form_edit_site', $fields, $this); - $form = new \WP_Ultimo\UI\Form('edit_site', $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - 'html_attr' => array( - 'data-wu-app' => 'edit_site', - 'data-state' => wu_convert_to_state(array( - 'site_title' => $site->get_title(), - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'edit_site', + $fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + 'html_attr' => array( + 'data-wu-app' => 'edit_site', + 'data-state' => wu_convert_to_state( + array( + 'site_title' => $site->get_title(), + ) + ), + ), + ) + ); $form->render(); - - } // end render_edit_site; + } /** * Handles the password reset form. @@ -486,32 +478,28 @@ class Current_Site_Element extends Base_Element { $site = wu_get_site_by_hash(wu_request('site')); - if (!$site) { - + if ( ! $site) { $error = new \WP_Error('site-dont-exist', __('Something went wrong.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } $new_title = wu_request('site_title'); - if (!$new_title) { - + if ( ! $new_title) { $error = new \WP_Error('title_empty', __('Site title can not be empty.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } $status = update_blog_option($site->get_id(), 'blogname', $new_title); $status_desc = update_blog_option($site->get_id(), 'blogdescription', wu_request('site_description')); - wp_send_json_success(array( - 'redirect_url' => add_query_arg('updated', (int) $status, $_SERVER['HTTP_REFERER']), - )); - - } // end handle_edit_site; - -} // end class Current_Site_Element; + wp_send_json_success( + array( + 'redirect_url' => add_query_arg('updated', (int) $status, $_SERVER['HTTP_REFERER']), + ) + ); + } +} diff --git a/inc/ui/class-domain-mapping-element.php b/inc/ui/class-domain-mapping-element.php index 616945f..294807b 100644 --- a/inc/ui/class-domain-mapping-element.php +++ b/inc/ui/class-domain-mapping-element.php @@ -9,11 +9,11 @@ namespace WP_Ultimo\UI; -use \WP_Ultimo\UI\Base_Element; -use \WP_Ultimo\Models\Domain; -use \WP_Ultimo\Database\Domains\Domain_Stage; -use \WP_Ultimo\Models\Site; -use \WP_Ultimo\Models\Membership; +use WP_Ultimo\UI\Base_Element; +use WP_Ultimo\Models\Domain; +use WP_Ultimo\Database\Domains\Domain_Stage; +use WP_Ultimo\Models\Site; +use WP_Ultimo\Models\Membership; // Exit if accessed directly defined('ABSPATH') || exit; @@ -67,23 +67,20 @@ class Domain_Mapping_Element extends Base_Element { protected $membership; /** - * The icon of the UI element. - * e.g. return fa fa-search - * - * @since 2.0.0 - * @param string $context One of the values: block, elementor or bb. - */ + * The icon of the UI element. + * e.g. return fa fa-search + * + * @since 2.0.0 + * @param string $context One of the values: block, elementor or bb. + */ public function get_icon($context = 'block'): string { if ($context === 'elementor') { - return 'eicon-url'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * The title of the UI element. @@ -98,8 +95,7 @@ class Domain_Mapping_Element extends Base_Element { public function get_title() { return __('Domains', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -115,8 +111,7 @@ class Domain_Mapping_Element extends Base_Element { public function get_description() { return __('Adds the site\'s domains block.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -154,8 +149,7 @@ class Domain_Mapping_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * The list of keywords for this element. @@ -181,8 +175,7 @@ class Domain_Mapping_Element extends Base_Element { 'WP Multisite WaaS', 'Domain', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -203,8 +196,7 @@ class Domain_Mapping_Element extends Base_Element { return array( 'title' => __('Domains', 'wp-ultimo'), ); - - } // end defaults; + } /** * Initializes the singleton. @@ -217,32 +209,25 @@ class Domain_Mapping_Element extends Base_Element { parent::init(); if ($this->is_preview()) { - $this->site = wu_mock_site(); return; - - } // end if; + } $this->site = wu_get_current_site(); $maybe_limit_domain_mapping = true; if ($this->site->has_limitations()) { - $maybe_limit_domain_mapping = $this->site->get_limitations()->domain_mapping->is_enabled(); + } - } // end if; - - if (!$this->site || !wu_get_setting('enable_domain_mapping') || !wu_get_setting('custom_domains') || !$maybe_limit_domain_mapping) { - + if ( ! $this->site || ! wu_get_setting('enable_domain_mapping') || ! wu_get_setting('custom_domains') || ! $maybe_limit_domain_mapping) { $this->set_display(false); - - } // end if; + } add_action('plugins_loaded', array($this, 'register_forms')); - - } // end init; + } /** * Loads the required scripts. @@ -253,8 +238,7 @@ class Domain_Mapping_Element extends Base_Element { public function register_scripts() { add_wubox(); - - } // end register_scripts; + } /** * Register ajax forms used to add a new domain. @@ -266,25 +250,33 @@ class Domain_Mapping_Element extends Base_Element { /* * Add new Domain */ - wu_register_form('user_add_new_domain', array( - 'render' => array($this, 'render_user_add_new_domain_modal'), - 'handler' => array($this, 'handle_user_add_new_domain_modal'), - 'capability' => 'exist', - )); + wu_register_form( + 'user_add_new_domain', + array( + 'render' => array($this, 'render_user_add_new_domain_modal'), + 'handler' => array($this, 'handle_user_add_new_domain_modal'), + 'capability' => 'exist', + ) + ); - wu_register_form('user_make_domain_primary', array( - 'render' => array($this, 'render_user_make_domain_primary_modal'), - 'handler' => array($this, 'handle_user_make_domain_primary_modal'), - 'capability' => 'exist', - )); + wu_register_form( + 'user_make_domain_primary', + array( + 'render' => array($this, 'render_user_make_domain_primary_modal'), + 'handler' => array($this, 'handle_user_make_domain_primary_modal'), + 'capability' => 'exist', + ) + ); - wu_register_form('user_delete_domain_modal', array( - 'render' => array($this, 'render_user_delete_domain_modal'), - 'handler' => array($this, 'handle_user_delete_domain_modal'), - 'capability' => 'exist', - )); - - } // end register_forms; + wu_register_form( + 'user_delete_domain_modal', + array( + 'render' => array($this, 'render_user_delete_domain_modal'), + 'handler' => array($this, 'handle_user_delete_domain_modal'), + 'capability' => 'exist', + ) + ); + } /** * Renders the add new customer modal. @@ -313,7 +305,7 @@ class Domain_Mapping_Element extends Base_Element { 'display_value' => sprintf('
    %s
    ', wpautop($instructions)), 'wrapper_html_attr' => array( 'v-show' => '!ready', - 'v-cloak' => 1 + 'v-cloak' => 1, ), ), 'ready' => array( @@ -327,7 +319,7 @@ class Domain_Mapping_Element extends Base_Element { ), 'wrapper_html_attr' => array( 'v-show' => '!ready', - 'v-cloak' => 1 + 'v-cloak' => 1, ), ), 'current_site' => array( @@ -340,7 +332,7 @@ class Domain_Mapping_Element extends Base_Element { 'placeholder' => __('mydomain.com', 'wp-ultimo'), 'wrapper_html_attr' => array( 'v-show' => 'ready', - 'v-cloak' => 1 + 'v-cloak' => 1, ), ), 'primary_domain' => array( @@ -371,27 +363,32 @@ class Domain_Mapping_Element extends Base_Element { 'wrapper_classes' => 'wu-items-end', 'wrapper_html_attr' => array( 'v-show' => 'ready', - 'v-cloak' => 1 + 'v-cloak' => 1, ), ), ); - $form = new \WP_Ultimo\UI\Form('add_new_domain', $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - 'html_attr' => array( - 'data-wu-app' => 'add_new_domain', - 'data-state' => json_encode(array( - 'ready' => 0, - 'primary_domain' => false, - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'add_new_domain', + $fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + 'html_attr' => array( + 'data-wu-app' => 'add_new_domain', + 'data-state' => json_encode( + array( + 'ready' => 0, + 'primary_domain' => false, + ) + ), + ), + ) + ); $form->render(); - - } // end render_user_add_new_domain_modal; + } /** * Handles creation of a new customer. @@ -407,46 +404,44 @@ class Domain_Mapping_Element extends Base_Element { $current_site = wu_get_site($current_site_id); - if (!is_super_admin() && (!$current_site || $current_user_id !== $current_site->get_customer()->get_user_id())) { - + if ( ! is_super_admin() && (! $current_site || $current_user_id !== $current_site->get_customer()->get_user_id())) { wp_send_json_error( new \WP_Error('no-permissions', __('You do not have permissions to perform this action.', 'wp-ultimo')) ); exit; - - } // end if; + } /* * Tries to create the domain */ - $domain = wu_create_domain(array( - 'domain' => wu_request('domain'), - 'blog_id' => absint($current_site_id), - 'primary_domain' => (bool) wu_request('primary_domain'), - )); + $domain = wu_create_domain( + array( + 'domain' => wu_request('domain'), + 'blog_id' => absint($current_site_id), + 'primary_domain' => (bool) wu_request('primary_domain'), + ) + ); if (is_wp_error($domain)) { - wp_send_json_error($domain); - - } // end if; + } if (wu_request('primary_domain')) { - - $old_primary_domains = wu_get_domains(array( - 'primary_domain' => true, - 'blog_id' => $current_site_id, - 'id__not_in' => array($domain->get_id()), - 'fields' => 'ids', - )); + $old_primary_domains = wu_get_domains( + array( + 'primary_domain' => true, + 'blog_id' => $current_site_id, + 'id__not_in' => array($domain->get_id()), + 'fields' => 'ids', + ) + ); /* * Trigger async action to update the old primary domains. */ do_action_ref_array('wu_async_remove_old_primary_domains', array($old_primary_domains)); - - } // end if; + } wu_enqueue_async_action('wu_async_process_domain_stage', array('domain_id' => $domain->get_id()), 'domain'); @@ -455,13 +450,14 @@ class Domain_Mapping_Element extends Base_Element { */ do_action('wu_domain_created', $domain, $domain->get_site(), $domain->get_site()->get_membership()); - wp_send_json_success(array( - 'redirect_url' => wu_get_current_url(), - )); + wp_send_json_success( + array( + 'redirect_url' => wu_get_current_url(), + ) + ); exit; - - } // end handle_user_add_new_domain_modal; + } /** * Renders the domain delete action. @@ -497,21 +493,26 @@ class Domain_Mapping_Element extends Base_Element { ), ); - $form = new \WP_Ultimo\UI\Form('user_delete_domain_modal', $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - 'html_attr' => array( - 'data-wu-app' => 'user_delete_domain_modal', - 'data-state' => json_encode(array( - 'confirmed' => false, - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'user_delete_domain_modal', + $fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + 'html_attr' => array( + 'data-wu-app' => 'user_delete_domain_modal', + 'data-state' => json_encode( + array( + 'confirmed' => false, + ) + ), + ), + ) + ); $form->render(); - - } // end render_user_delete_domain_modal; + } /** * Handles deletion of the selected domain @@ -522,10 +523,8 @@ class Domain_Mapping_Element extends Base_Element { public function handle_user_delete_domain_modal() { if (wu_request('user_id')) { - $customer = wu_get_customer_by_user_id(wu_request('user_id')); - - } // end if; + } $current_site = wu_request('current_site'); @@ -534,16 +533,15 @@ class Domain_Mapping_Element extends Base_Element { $domain = new Domain($get_domain); if ($domain) { - $domain->delete(); + } - } // end if; - - wp_send_json_success(array( - 'redirect_url' => wu_get_current_url(), - )); - - } // end handle_user_delete_domain_modal; + wp_send_json_success( + array( + 'redirect_url' => wu_get_current_url(), + ) + ); + } /** * Renders the domain delete action. @@ -579,21 +577,26 @@ class Domain_Mapping_Element extends Base_Element { ), ); - $form = new \WP_Ultimo\UI\Form('user_delete_domain_modal', $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - 'html_attr' => array( - 'data-wu-app' => 'user_delete_domain_modal', - 'data-state' => json_encode(array( - 'confirmed' => false, - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'user_delete_domain_modal', + $fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + 'html_attr' => array( + 'data-wu-app' => 'user_delete_domain_modal', + 'data-state' => json_encode( + array( + 'confirmed' => false, + ) + ), + ), + ) + ); $form->render(); - - } // end render_user_make_domain_primary_modal; + } /** * Handles conversion to primary domain. @@ -610,38 +613,37 @@ class Domain_Mapping_Element extends Base_Element { $domain = wu_get_domain($domain_id); if ($domain) { - $domain->set_primary_domain(true); $status = $domain->save(); if (is_wp_error($status)) { - wp_send_json_error($status); + } - } // end if; - - $old_primary_domains = wu_get_domains(array( - 'primary_domain' => true, - 'blog_id' => $domain->get_blog_id(), - 'id__not_in' => array($domain->get_id()), - 'fields' => 'ids', - )); + $old_primary_domains = wu_get_domains( + array( + 'primary_domain' => true, + 'blog_id' => $domain->get_blog_id(), + 'id__not_in' => array($domain->get_id()), + 'fields' => 'ids', + ) + ); /* * Trigger async action to update the old primary domains. */ do_action_ref_array('wu_async_remove_old_primary_domains', array($old_primary_domains)); - wp_send_json_success(array( - 'redirect_url' => is_main_site() ? wu_get_current_url() : get_admin_url($current_site), - )); - - } // end if; + wp_send_json_success( + array( + 'redirect_url' => is_main_site() ? wu_get_current_url() : get_admin_url($current_site), + ) + ); + } wp_send_json_error(new \WP_Error('error', __('Something wrong happenned.', 'wp-ultimo'))); - - } // end handle_user_make_domain_primary_modal; + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -653,20 +655,17 @@ class Domain_Mapping_Element extends Base_Element { $this->site = WP_Ultimo()->currents->get_site(); - if (!$this->site || !$this->site->is_customer_allowed()) { - + if ( ! $this->site || ! $this->site->is_customer_allowed()) { $this->set_display(false); return; - - } // end if; + } // Ensure admin.php is loaded as we need wu_responsive_table_row function require_once wu_path('inc/functions/admin.php'); $this->membership = $this->site->get_membership(); - - } // end setup; + } /** * Allows the setup in the context of previews. @@ -679,8 +678,7 @@ class Domain_Mapping_Element extends Base_Element { $this->site = wu_mock_site(); $this->membership = wu_mock_membership(); - - } // end setup_preview; + } /** * The content to be output on the screen. @@ -699,16 +697,17 @@ class Domain_Mapping_Element extends Base_Element { $current_site = $this->site; - $all_domains = wu_get_domains(array( - 'blog_id' => $current_site->get_id(), - 'orderby' => 'primary_domain', - 'order' => 'DESC', - )); + $all_domains = wu_get_domains( + array( + 'blog_id' => $current_site->get_id(), + 'orderby' => 'primary_domain', + 'order' => 'DESC', + ) + ); $domains = array(); foreach ($all_domains as $key => $domain) { - $stage = new Domain_Stage($domain->get_stage()); $secure = 'dashicons-wu-lock-open'; @@ -716,12 +715,10 @@ class Domain_Mapping_Element extends Base_Element { $secure_message = __('Domain not secured with HTTPS', 'wp-ultimo'); if ($domain->is_secure()) { - $secure = 'dashicons-wu-lock wu-text-green-500'; $secure_message = __('Domain secured with HTTPS', 'wp-ultimo'); - - } // end if; + } $url_atts = array( 'current_site' => $current_site->get_id(), @@ -731,7 +728,7 @@ class Domain_Mapping_Element extends Base_Element { $delete_url = wu_get_form_url('user_delete_domain_modal', $url_atts); $primary_url = wu_get_form_url('user_make_domain_primary', $url_atts); - $domains[$key] = array( + $domains[ $key ] = array( 'id' => $domain->get_id(), 'domain_object' => $domain, 'domain' => $domain->get_domain(), @@ -742,9 +739,8 @@ class Domain_Mapping_Element extends Base_Element { 'secure_message' => $secure_message, 'delete_link' => $delete_url, 'primary_link' => $primary_url, - ); - - } // end foreach; + ); + } $url_atts = array( 'current_site' => $current_site->get_ID(), @@ -763,7 +759,5 @@ class Domain_Mapping_Element extends Base_Element { $atts = array_merge($other_atts, $atts); return wu_get_template_contents('dashboard-widgets/domain-mapping', $atts); - - } // end output; - -} // end class Domain_Mapping_Element; + } +} diff --git a/inc/ui/class-field.php b/inc/ui/class-field.php index a89676d..74067b3 100644 --- a/inc/ui/class-field.php +++ b/inc/ui/class-field.php @@ -46,8 +46,7 @@ class Field implements \JsonSerializable { public function __construct($id, $atts) { $this->set_attributes($id, $atts); - - } // end __construct; + } /** * Set and the attributes passed via the constructor. @@ -60,57 +59,59 @@ class Field implements \JsonSerializable { */ public function set_attributes($id, $atts) { - $this->atts = wp_parse_args($atts, array( - 'id' => $id, - 'type' => 'text', - 'icon' => 'dashicons-wu-cog', - 'action' => false, - 'form' => false, - 'title' => false, - 'img' => false, - 'desc' => false, - 'content' => false, - 'display_value' => false, - 'default_value' => false, - 'tooltip' => false, - 'args' => false, - 'sortable' => false, - 'placeholder' => false, - 'options' => false, - 'options_template' => false, - 'require' => false, - 'button' => false, - 'width' => false, - 'rules' => false, - 'min' => false, - 'max' => false, - 'allow_html' => false, - 'append' => false, - 'order' => false, - 'dummy' => false, - 'disabled' => false, - 'capability' => false, - 'edit' => false, - 'copy' => false, - 'validation' => false, - 'meter' => false, - 'href' => false, - 'raw' => false, - 'money' => false, - 'stacked' => false, // If the field is inside a restricted container - 'columns' => 1, - 'classes' => '', - 'wrapper_classes' => '', - 'html_attr' => array(), - 'wrapper_html_attr' => array(), - 'sub_fields' => array(), - 'prefix' => '', - 'suffix' => '', - 'prefix_html_attr' => array(), - 'suffix_html_attr' => array(), - )); - - } // end set_attributes; + $this->atts = wp_parse_args( + $atts, + array( + 'id' => $id, + 'type' => 'text', + 'icon' => 'dashicons-wu-cog', + 'action' => false, + 'form' => false, + 'title' => false, + 'img' => false, + 'desc' => false, + 'content' => false, + 'display_value' => false, + 'default_value' => false, + 'tooltip' => false, + 'args' => false, + 'sortable' => false, + 'placeholder' => false, + 'options' => false, + 'options_template' => false, + 'require' => false, + 'button' => false, + 'width' => false, + 'rules' => false, + 'min' => false, + 'max' => false, + 'allow_html' => false, + 'append' => false, + 'order' => false, + 'dummy' => false, + 'disabled' => false, + 'capability' => false, + 'edit' => false, + 'copy' => false, + 'validation' => false, + 'meter' => false, + 'href' => false, + 'raw' => false, + 'money' => false, + 'stacked' => false, // If the field is inside a restricted container + 'columns' => 1, + 'classes' => '', + 'wrapper_classes' => '', + 'html_attr' => array(), + 'wrapper_html_attr' => array(), + 'sub_fields' => array(), + 'prefix' => '', + 'suffix' => '', + 'prefix_html_attr' => array(), + 'suffix_html_attr' => array(), + ) + ); + } /** * Set a particular attribute. @@ -123,9 +124,8 @@ class Field implements \JsonSerializable { */ public function set_attribute($att, $value) { - $this->atts[$att] = $value; - - } // end set_attribute; + $this->atts[ $att ] = $value; + } /** * Returns the list of field attributes. @@ -136,8 +136,7 @@ class Field implements \JsonSerializable { public function get_attributes() { return $this->atts; - - } // end get_attributes; + } /** * Makes sure old fields remain compatible. @@ -168,33 +167,27 @@ class Field implements \JsonSerializable { ); if (array_key_exists($this->type, $aliases)) { - - $new_type_name = $aliases[$this->type]; + $new_type_name = $aliases[ $this->type ]; if (array_key_exists($this->type, $deprecated)) { // translators: The %1$s placeholder is the old type name, the second, the new type name. _doing_it_wrong('wu_add_field', sprintf(__('The field type "%1$s" is no longer supported, use "%2$s" instead.'), $this->type, $new_type_name), '2.0.0'); - - } // end if; + } /* * Back Compat for Select2 Fields */ if ($this->type === 'select2') { - $this->atts['html_attr']['data-selectize'] = 1; $this->atts['html_attr']['multiple'] = 1; - - } // end if; + } return $new_type_name; - - } // end if; + } return false; - - } // end get_compat_template_name; + } /** * Returns the template name for a field. @@ -214,8 +207,7 @@ class Field implements \JsonSerializable { $view_name = $compat_name ? $compat_name : $this->type; return str_replace('_', '-', (string) $view_name); - - } // end get_template_name; + } /** * Returns attributes as class properties. @@ -242,56 +234,41 @@ class Field implements \JsonSerializable { 'img', ); - $attr = isset($this->atts[$att]) ? $this->atts[$att] : false; + $attr = isset($this->atts[ $att ]) ? $this->atts[ $att ] : false; $allow_callable_prefix = is_string($attr) && strncmp($attr, 'wu_get_', strlen('wu_get_')) === 0 && is_callable($attr); $allow_callable_method = is_array($attr) && is_callable($attr); if (in_array($att, $allowed_callable, true) && ($allow_callable_prefix || $allow_callable_method || is_a($attr, \Closure::class))) { - $attr = call_user_func($attr, $this); - - } // end if; + } if ($att === 'wrapper_classes' && isset($this->atts['wrapper_html_attr']['v-show'])) { - $this->atts['wrapper_classes'] = $this->atts['wrapper_classes'] . ' wu-requires-other'; + } - } // end if; - - if ($att === 'type' && $this->atts[$att] === 'submit') { - + if ($att === 'type' && $this->atts[ $att ] === 'submit') { $this->atts['wrapper_classes'] = $this->atts['wrapper_classes'] . ' wu-submit-field'; + } - } // end if; - - if ($att === 'type' && $this->atts[$att] === 'tab-select') { - + if ($att === 'type' && $this->atts[ $att ] === 'tab-select') { $this->atts['wrapper_classes'] = $this->atts['wrapper_classes'] . ' wu-tab-field'; - - } // end if; + } if ($att === 'wrapper_classes' && is_a($this->form, '\\WP_Ultimo\\UI\\Form')) { - return $this->form->field_wrapper_classes . ' ' . $this->atts['wrapper_classes']; - - } // end if; + } if ($att === 'classes' && is_a($this->form, '\\WP_Ultimo\\UI\\Form')) { - return $this->form->field_classes . ' ' . $this->atts['classes']; - - } // end if; + } if ($att === 'title' && $attr === false && isset($this->atts['name'])) { - $attr = $this->atts['name']; - - } // end if; + } return $attr; - - } // end __get; + } /** * Returns the list of sanitization callbacks for each field type @@ -314,8 +291,7 @@ class Field implements \JsonSerializable { ); return apply_filters('wu_settings_fields_sanitization_rules', $rules); - - } // end sanitization_rules; + } /** * Returns the value of the setting represented by this field. @@ -326,8 +302,7 @@ class Field implements \JsonSerializable { public function get_value() { return $this->value; - - } // end get_value; + } /** * Sets the value of the settings represented by this field. @@ -344,15 +319,12 @@ class Field implements \JsonSerializable { $this->value = $value; - if (!$this->raw) { - + if ( ! $this->raw) { $this->sanitize(); - - } // end if; + } return $this; - - } // end set_value; + } /** * Runs the value of the field through the sanitization callback. @@ -364,45 +336,37 @@ class Field implements \JsonSerializable { $rules = $this->sanitization_rules(); - $sanitize_method = isset($rules[$this->type]) ? $rules[$this->type] : $rules['text']; + $sanitize_method = isset($rules[ $this->type ]) ? $rules[ $this->type ] : $rules['text']; if ($sanitize_method) { - $this->value = call_user_func($sanitize_method, $this->value); - - } // end if; - - } // end sanitize; - /** - * Sanitization callback for fields of type number. - * - * Checks if the new value set is between the min and max boundaries. - * - * @since 2.0.0 - * - * @param int|float $value Value of the settings being represented by this field. - * @return int|float - */ - protected function validate_number_field($value) { + } + } + /** + * Sanitization callback for fields of type number. + * + * Checks if the new value set is between the min and max boundaries. + * + * @since 2.0.0 + * + * @param int|float $value Value of the settings being represented by this field. + * @return int|float + */ + protected function validate_number_field($value) { /** * Check if the value respects the min/max values. */ if ($this->min && $value < $this->min) { - return $this->min; - - } // end if; + } if ($this->max && $value > $this->max) { - return $this->max; - - } // end if; + } return $value; - - } // end validate_number_field; + } /** * Cleans the value submitted via a textarea or wp_editor field for database insertion. @@ -415,14 +379,11 @@ class Field implements \JsonSerializable { protected function validate_textarea_field($value) { if ($this->allow_html) { - return stripslashes(wp_filter_post_kses(addslashes($value))); - - } // end if; + } return wp_strip_all_tags(stripslashes($value)); - - } // end validate_textarea_field; + } /** * Return HTML attributes for the field. @@ -433,43 +394,32 @@ class Field implements \JsonSerializable { public function get_html_attributes() { if (is_callable($this->atts['html_attr'])) { - $this->atts['html_attr'] = call_user_func($this->atts['html_attr']); - - } // end if; + } $attributes = $this->atts['html_attr']; unset($this->atts['html_attr']['class']); if ($this->type === 'number') { - if ($this->min !== false) { - $attributes['min'] = $this->min; - - } // end if; + } if ($this->max !== false) { - $attributes['max'] = $this->max; - - } // end if; - - } // end if; + } + } /* * Adds money formatting and masking */ if ($this->money !== false) { - $attributes['v-bind'] = 'money_settings'; - - } // end if; + } return wu_array_to_html_attrs($attributes); - - } // end get_html_attributes; + } /** * Return HTML attributes for the field. @@ -484,8 +434,7 @@ class Field implements \JsonSerializable { unset($this->atts['wrapper_html_attr']['class']); return wu_array_to_html_attrs($attributes); - - } // end get_wrapper_html_attributes; + } /** * Implements our on json_decode version of this object. Useful for use in vue.js @@ -497,7 +446,5 @@ class Field implements \JsonSerializable { public function jsonSerialize() { return $this->atts; - - } // end jsonSerialize; - -} // end class Field; + } +} diff --git a/inc/ui/class-form.php b/inc/ui/class-form.php index b81af97..8020af1 100644 --- a/inc/ui/class-form.php +++ b/inc/ui/class-form.php @@ -9,7 +9,7 @@ namespace WP_Ultimo\UI; -use \WP_Ultimo\UI\Field; +use WP_Ultimo\UI\Field; // Exit if accessed directly defined('ABSPATH') || exit; @@ -48,32 +48,37 @@ class Form implements \JsonSerializable { */ public function __construct($id, $fields, $atts = array()) { - $this->atts = apply_filters("wu_{$id}_form_atts", wp_parse_args($atts, array( - 'id' => $id, - 'method' => 'post', - 'before' => '', - 'after' => '', - 'action' => false, - 'title' => false, - 'wrap_in_form_tag' => false, - 'wrap_tag' => 'div', - 'classes' => false, - 'field_wrapper_classes' => false, - 'field_classes' => false, - 'views' => 'settings/fields', - 'variables' => array(), - 'step' => (object) array( - 'classes' => '', - 'element_id' => '', - ), - 'html_attr' => array( - 'class' => '', - ), - ))); + $this->atts = apply_filters( + "wu_{$id}_form_atts", + wp_parse_args( + $atts, + array( + 'id' => $id, + 'method' => 'post', + 'before' => '', + 'after' => '', + 'action' => false, + 'title' => false, + 'wrap_in_form_tag' => false, + 'wrap_tag' => 'div', + 'classes' => false, + 'field_wrapper_classes' => false, + 'field_classes' => false, + 'views' => 'settings/fields', + 'variables' => array(), + 'step' => (object) array( + 'classes' => '', + 'element_id' => '', + ), + 'html_attr' => array( + 'class' => '', + ), + ) + ) + ); $this->set_fields($fields); - - } // end __construct; + } /** * Returns attributes as class properties. @@ -90,17 +95,14 @@ class Form implements \JsonSerializable { 'after', ); - $attr = isset($this->atts[$att]) ? $this->atts[$att] : false; + $attr = isset($this->atts[ $att ]) ? $this->atts[ $att ] : false; if (in_array($att, $allowed_callable, true) && is_callable($attr)) { - $attr = call_user_func($attr, $this); - - } // end if; + } return $attr; - - } // end __get; + } /** * Returns the list of field attributes. @@ -111,8 +113,7 @@ class Form implements \JsonSerializable { public function get_attributes() { return $this->atts; - - } // end get_attributes; + } /** * Returns the list of fields used by the form. @@ -123,8 +124,7 @@ class Form implements \JsonSerializable { public function get_fields() { return (array) $this->fields; - - } // end get_fields; + } /** * Casts fields to \WP_Ultimo\UI\Fields and stores them on private list. @@ -148,14 +148,11 @@ class Form implements \JsonSerializable { $fields = apply_filters("wu_{$id}_form_fields", $fields); foreach ($fields as $field_slug => $field) { - $field['form'] = $this; - $this->fields[$field_slug] = new Field($field_slug, $field); - - } // end foreach; - - } // end set_fields; + $this->fields[ $field_slug ] = new Field($field_slug, $field); + } + } /** * Renders the form with its fields. @@ -165,42 +162,44 @@ class Form implements \JsonSerializable { */ public function render() { - $variables = array_merge($this->variables, array( - 'form_slug' => $this->id, - 'form' => $this, - 'step' => $this->step, - )); + $variables = array_merge( + $this->variables, + array( + 'form_slug' => $this->id, + 'form' => $this, + 'step' => $this->step, + ) + ); ob_start(); foreach ($this->get_fields() as $field_slug => $field) { - $template_name = $field->get_template_name(); if (wu_get_isset($field->wrapper_html_attr, 'id') === false) { - $new_wrapper_attributes = $field->wrapper_html_attr; $new_wrapper_attributes['id'] = "wrapper-field-$field_slug"; $field->set_attribute('wrapper_html_attr', $new_wrapper_attributes); + } - } // end if; - - wu_get_template("{$this->views}/field-{$template_name}", array( - 'field_slug' => $field_slug, - 'field' => $field, - ), "{$this->views}/field-text"); - - } // end foreach; + wu_get_template( + "{$this->views}/field-{$template_name}", + array( + 'field_slug' => $field_slug, + 'field' => $field, + ), + "{$this->views}/field-text" + ); + } $rendered_fields = ob_get_clean(); $variables['rendered_fields'] = $rendered_fields; wu_get_template("{$this->views}/form", $variables); - - } // end render; + } /** * Return HTML attributes for the field. @@ -215,24 +214,17 @@ class Form implements \JsonSerializable { unset($this->atts['html_attr']['class']); if ($this->type === 'number') { - if ($this->min !== false) { - $attributes['min'] = $this->min; - - } // end if; + } if ($this->max !== false) { - $attributes['max'] = $this->max; - - } // end if; - - } // end if; + } + } return wu_array_to_html_attrs($attributes); - - } // end get_html_attributes; + } /** * Implements our on json_decode version of this object. Useful for use in vue.js @@ -244,7 +236,5 @@ class Form implements \JsonSerializable { public function jsonSerialize() { return $this->atts; - - } // end jsonSerialize; - -} // end class Form; + } +} diff --git a/inc/ui/class-invoices-element.php b/inc/ui/class-invoices-element.php index 7005efb..2610aef 100644 --- a/inc/ui/class-invoices-element.php +++ b/inc/ui/class-invoices-element.php @@ -65,14 +65,11 @@ class Invoices_Element extends Base_Element { public function get_icon($context = 'block') { if ($context === 'elementor') { - return 'eicon-price-list'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * The title of the UI element. @@ -87,8 +84,7 @@ class Invoices_Element extends Base_Element { public function get_title() { return __('Invoices', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -104,8 +100,7 @@ class Invoices_Element extends Base_Element { public function get_description() { return __('Adds a checkout form block to the page.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -151,8 +146,7 @@ class Invoices_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * The list of keywords for this element. @@ -180,8 +174,7 @@ class Invoices_Element extends Base_Element { 'Form', 'Cart', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -203,8 +196,7 @@ class Invoices_Element extends Base_Element { 'title' => __('Invoices', 'wp-ultimo'), 'limit' => 0, ); - - } // end defaults; + } /** * Loads the required scripts. @@ -215,8 +207,7 @@ class Invoices_Element extends Base_Element { public function register_scripts() { wp_enqueue_script('wu-ajax-list-table'); - - } // end register_scripts; + } /** * Loads dependencies for the render. @@ -226,26 +217,19 @@ class Invoices_Element extends Base_Element { */ public function dependencies() { - if (!function_exists('convert_to_screen')) { - + if ( ! function_exists('convert_to_screen')) { require_once ABSPATH . 'wp-admin/includes/template.php'; + } - } // end if; - - if (!function_exists('get_column_headers')) { - + if ( ! function_exists('get_column_headers')) { require_once ABSPATH . 'wp-admin/includes/class-wp-screen.php'; require_once ABSPATH . 'wp-admin/includes/screen.php'; + } - } // end if; - - if (!function_exists('wu_responsive_table_row')) { - + if ( ! function_exists('wu_responsive_table_row')) { require wu_path('/inc/functions/admin.php'); - - } // end if; - - } // end dependencies; + } + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -257,15 +241,12 @@ class Invoices_Element extends Base_Element { $this->membership = WP_Ultimo()->currents->get_membership(); - if (!$this->membership) { - + if ( ! $this->membership) { $this->set_display(false); return; - - } // end if; - - } // end setup; + } + } /** * Allows the setup in the context of previews. @@ -276,8 +257,7 @@ class Invoices_Element extends Base_Element { public function setup_preview() { $this->membership = wu_mock_membership(); - - } // end setup_preview; + } /** * The content to be output on the screen. @@ -297,7 +277,5 @@ class Invoices_Element extends Base_Element { $atts['membership'] = $this->membership; return wu_get_template_contents('dashboard-widgets/invoices', $atts); - - } // end output; - -} // end class Invoices_Element; + } +} diff --git a/inc/ui/class-jumper.php b/inc/ui/class-jumper.php index 2c67861..ca2eb05 100644 --- a/inc/ui/class-jumper.php +++ b/inc/ui/class-jumper.php @@ -49,8 +49,7 @@ class Jumper { add_action('wp_ultimo_load', array($this, 'add_settings'), 20); add_action('init', array($this, 'load_jumper')); - - } // end __construct; + } /** * Checks if we should add the jumper or not. @@ -61,8 +60,7 @@ class Jumper { protected function is_jumper_enabled() { return apply_filters('wu_is_jumper_enabled', wu_get_setting('enable_jumper', true) && current_user_can('manage_network')); - - } // end is_jumper_enabled; + } /** * Adds the Jumper trigger to the admin top pages. @@ -74,12 +72,14 @@ class Jumper { */ public function add_jumper_trigger($page) { - wu_get_template('ui/jumper-trigger', array( - 'page' => $page, - 'jumper' => $this, - )); - - } // end add_jumper_trigger; + wu_get_template( + 'ui/jumper-trigger', + array( + 'page' => $page, + 'jumper' => $this, + ) + ); + } /** * Loads the necessary elements to display the Jumper. @@ -90,7 +90,6 @@ class Jumper { public function load_jumper() { if ($this->is_jumper_enabled() && is_admin()) { - add_action('wu_header_right', array($this, 'add_jumper_trigger')); add_action('admin_init', array($this, 'rebuild_menu')); @@ -108,10 +107,8 @@ class Jumper { add_filter('wu_link_list', array($this, 'add_wp_ultimo_extra_links')); add_filter('wu_link_list', array($this, 'add_user_custom_links')); - - } // end if; - - } // end load_jumper; + } + } /** * Clear the jumper menu cache on settings save @@ -127,12 +124,9 @@ class Jumper { public function clear_jump_cache_on_save($settings) { if (isset($settings['jumper_custom_links'])) { - delete_site_transient($this->transient_key); - - } // end if; - - } // end clear_jump_cache_on_save; + } + } /** * Rebuilds the jumper menu via a trigger URL. @@ -142,17 +136,14 @@ class Jumper { */ public function rebuild_menu() { - if (isset($_GET[$this->reset_slug]) && current_user_can('manage_network')) { - + if (isset($_GET[ $this->reset_slug ]) && current_user_can('manage_network')) { delete_site_transient($this->transient_key); wp_redirect(network_admin_url()); exit; - - } // end if; - - } // end rebuild_menu; + } + } /** * Retrieves the custom links added by the super admin @@ -169,22 +160,17 @@ class Jumper { $lines = explode(PHP_EOL, (string) $saved_links); foreach ($lines as $line) { - $link_elements = explode(':', $line, 2); if (count($link_elements) === 2) { - $title = trim($link_elements[1]); - $treated_lines[$title] = trim($link_elements[0]); - - } // end if; - - } // end foreach; + $treated_lines[ $title ] = trim($link_elements[0]); + } + } return $treated_lines; - - } // end get_user_custom_links; + } /** * Add the custom links to the Jumper menu @@ -198,15 +184,12 @@ class Jumper { $custom_links = $this->get_user_custom_links(); - if (!empty($custom_links)) { - - $links[__('Custom Links', 'wp-ultimo')] = $custom_links; - - } // end if; + if ( ! empty($custom_links)) { + $links[ __('Custom Links', 'wp-ultimo') ] = $custom_links; + } return $links; - - } // end add_user_custom_links; + } /** * Add WP Multisite WaaS settings links to the Jumper menu. @@ -219,7 +202,6 @@ class Jumper { public function add_wp_ultimo_extra_links($links) { if (isset($links['WP Ultimo'])) { - $settings_tabs = array( 'general' => __('General', 'wp-ultimo'), 'network' => __('Network Settings', 'wp-ultimo'), @@ -233,13 +215,11 @@ class Jumper { ); foreach ($settings_tabs as $tab => $tab_label) { - $url = network_admin_url('admin.php?page=wp-ultimo-settings&wu-tab=' . $tab); // translators: The placeholder represents the title of the Settings tab. - $links['WP Ultimo'][$url] = sprintf(__('Settings: %s', 'wp-ultimo'), $tab_label); - - } // end foreach; + $links['WP Ultimo'][ $url ] = sprintf(__('Settings: %s', 'wp-ultimo'), $tab_label); + } $links['WP Ultimo'][ network_admin_url('admin.php?page=wp-ultimo-settings&wu-tab=tools') ] = __('Settings: Webhooks', 'wp-ultimo'); @@ -248,19 +228,15 @@ class Jumper { /** * Adds Main Site Dashboard */ - if (isset($links[__('Sites')])) { - + if (isset($links[ __('Sites') ])) { $main_site_url = get_admin_url(get_current_site()->blog_id); - $links[__('Sites')][$main_site_url] = __('Main Site Dashboard', 'wp-ultimo'); - - } // end if; - - } // end if; + $links[ __('Sites') ][ $main_site_url ] = __('Main Site Dashboard', 'wp-ultimo'); + } + } return $links; - - } // end add_wp_ultimo_extra_links; + } /** * Get the trigger key defined by the user. * @@ -269,8 +245,7 @@ class Jumper { function get_defined_trigger_key(): string { return substr((string) wu_get_setting('jumper_key', 'g'), 0, 1); - - } // end get_defined_trigger_key; + } /** * Get the trigger key combination depending on the OS @@ -292,9 +267,8 @@ class Jumper { 'osx' => array('command', 'option', $trigger_key), ); - return isset($keys[$os]) ? $keys[$os] : $keys['win']; - - } // end get_keys; + return isset($keys[ $os ]) ? $keys[ $os ] : $keys['win']; + } /** * Changes the helper footer message about the Jumper and its trigger @@ -306,11 +280,9 @@ class Jumper { */ public function add_jumper_footer_message($text) { - if (!wu_get_setting('jumper_display_tip', true)) { - + if ( ! wu_get_setting('jumper_display_tip', true)) { return $text; - - } // end if; + } $os = stristr((string) $_SERVER['HTTP_USER_AGENT'], 'mac') ? 'osx' : 'win'; @@ -319,17 +291,14 @@ class Jumper { $html = ''; foreach ($keys as $key) { - $html .= '' . $key . '+'; - - } // end foreach; + } $html = trim($html, '+'); // translators: the %s placeholder is the key combination to trigger the Jumper. return '' . sprintf(__('Quick Tip: Use %s to jump between pages.', 'wp-ultimo'), $html) . '' . $text; - - } // end add_jumper_footer_message; + } /** * Enqueues the JavaScript files necessary to make the jumper work. @@ -343,19 +312,22 @@ class Jumper { wp_register_script('wu-jumper', wu_get_asset('jumper.js', 'js'), array('jquery', 'wu-selectize', 'wu-mousetrap', 'underscore'), wu_get_version(), true); - wp_localize_script('wu-jumper', 'wu_jumper_vars', array( - 'not_found_message' => __('Nothing found for', 'wp-ultimo'), - 'trigger_key' => $this->get_defined_trigger_key(), - 'network_base_url' => network_admin_url(), - 'ajaxurl' => wu_ajax_url(), - 'base_url' => get_admin_url(get_current_site()->blog_id), - )); + wp_localize_script( + 'wu-jumper', + 'wu_jumper_vars', + array( + 'not_found_message' => __('Nothing found for', 'wp-ultimo'), + 'trigger_key' => $this->get_defined_trigger_key(), + 'network_base_url' => network_admin_url(), + 'ajaxurl' => wu_ajax_url(), + 'base_url' => get_admin_url(get_current_site()->blog_id), + ) + ); wp_enqueue_script('wu-jumper'); wp_enqueue_style('wu-admin'); - - } // end enqueue_scripts; + } /** * Enqueues the CSS files necessary to make the jumper work. @@ -366,8 +338,7 @@ class Jumper { public function enqueue_styles() { wp_enqueue_style('wu-jumper', wu_get_asset('jumper.css', 'css'), array(), wu_get_version()); - - } // end enqueue_styles; + } /** * Outputs the actual HTML markup of the Jumper. @@ -377,11 +348,13 @@ class Jumper { */ public function output() { - wu_get_template('ui/jumper', array( - 'menu_groups' => $this->get_link_list(), - )); - - } // end output; + wu_get_template( + 'ui/jumper', + array( + 'menu_groups' => $this->get_link_list(), + ) + ); + } /** * Get the full page URL for admin pages. * @@ -394,8 +367,7 @@ class Jumper { $final_url = menu_page_url($url, false); return str_replace(admin_url(), network_admin_url(), $final_url); - - } // end get_menu_page_url; + } /** * Returns the URL of a jumper menu item @@ -411,20 +383,15 @@ class Jumper { public function get_target_url($url) { if (strpos($url, 'http') !== false) { - return $url; - - } // end if; + } if (strpos($url, '.php') !== false) { - return network_admin_url($url); - - } // end if; + } return $this->get_menu_page_url($url); - - } // end get_target_url; + } /** * Builds the list of links based on the $menu and $submenu globals. @@ -435,55 +402,50 @@ class Jumper { */ public function build_link_list() { - return Logger::track_time('jumper', __('Regenerating Jumper menu items', 'wp-ultimo'), function() { + return Logger::track_time( + 'jumper', + __('Regenerating Jumper menu items', 'wp-ultimo'), + function () { - global $menu, $submenu; + global $menu, $submenu; - // This variable is going to carry our options - $choices = array(); + // This variable is going to carry our options + $choices = array(); - // Prevent first run bug - if (!is_array($menu) || !is_array($submenu)) { + // Prevent first run bug + if ( ! is_array($menu) || ! is_array($submenu)) { + return array(); + } - return array(); + // Loop all submenus so que can get our final + foreach ($submenu as $menu_name => $submenu_items) { + $title = $this->search_recursive($menu_name, $menu); - } // end if; + $string = wu_get_isset($title, 0, ''); - // Loop all submenus so que can get our final - foreach ($submenu as $menu_name => $submenu_items) { + $title = preg_replace('/[0-9]+/', '', strip_tags($string)); - $title = $this->search_recursive($menu_name, $menu); + // If parent does not exists, skip + if ( ! empty($title) && is_array($submenu_items)) { - $string = wu_get_isset($title, 0, ''); + // We have to loop now each submenu + foreach ($submenu_items as $submenu_item) { + $url = $this->get_target_url($submenu_item[2]); - $title = preg_replace('/[0-9]+/', '', strip_tags($string)); + // Add to our choices the admin urls + $choices[ $title ][ $url ] = preg_replace('/[0-9]+/', '', strip_tags((string) $submenu_item[0])); + } + } + } - // If parent does not exists, skip - if (!empty($title) && is_array($submenu_items)) { + $choices = apply_filters('wu_link_list', $choices); - // We have to loop now each submenu - foreach ($submenu_items as $submenu_item) { + set_site_transient($this->transient_key, $choices, 10 * MINUTE_IN_SECONDS); - $url = $this->get_target_url($submenu_item[2]); - - // Add to our choices the admin urls - $choices[$title][$url] = preg_replace('/[0-9]+/', '', strip_tags((string) $submenu_item[0])); - - } // end foreach; - - } // end if; - - } // end foreach; - - $choices = apply_filters('wu_link_list', $choices); - - set_site_transient($this->transient_key, $choices, 10 * MINUTE_IN_SECONDS); - - return $choices; - - }); - - } // end build_link_list; + return $choices; + } + ); + } /** * Gets the cached menu list saved. @@ -496,8 +458,7 @@ class Jumper { $saved_menu = get_site_transient($this->transient_key); return $saved_menu ? $saved_menu : array(); - - } // end get_saved_menu; + } /** * Returns the link list. @@ -507,11 +468,10 @@ class Jumper { */ public function get_link_list() { - $should_rebuild_menu = !get_site_transient($this->transient_key); + $should_rebuild_menu = ! get_site_transient($this->transient_key); return $should_rebuild_menu && is_network_admin() ? $this->build_link_list() : $this->get_saved_menu(); - - } // end get_link_list; + } /** * Filter the WP Multisite WaaS settings to add Jumper options @@ -522,49 +482,67 @@ class Jumper { */ public function add_settings() { - wu_register_settings_section('tools', array( - 'title' => __('Tools', 'wp-ultimo'), - 'desc' => __('Tools', 'wp-ultimo'), - 'icon' => 'dashicons-wu-tools', - )); + wu_register_settings_section( + 'tools', + array( + 'title' => __('Tools', 'wp-ultimo'), + 'desc' => __('Tools', 'wp-ultimo'), + 'icon' => 'dashicons-wu-tools', + ) + ); - wu_register_settings_field('tools', 'tools_header', array( - 'title' => __('Jumper', 'wp-ultimo'), - 'desc' => __('Spotlight-like search bar that allows you to easily access everything on your network.', 'wp-ultimo'), - 'type' => 'header', - )); + wu_register_settings_field( + 'tools', + 'tools_header', + array( + 'title' => __('Jumper', 'wp-ultimo'), + 'desc' => __('Spotlight-like search bar that allows you to easily access everything on your network.', 'wp-ultimo'), + 'type' => 'header', + ) + ); - wu_register_settings_field('tools', 'enable_jumper', array( - 'title' => __('Enable Jumper', 'wp-ultimo'), - 'desc' => __('Turn this option on to make the Jumper available on your network.', 'wp-ultimo'), - 'type' => 'toggle', - 'default' => 1, - )); + wu_register_settings_field( + 'tools', + 'enable_jumper', + array( + 'title' => __('Enable Jumper', 'wp-ultimo'), + 'desc' => __('Turn this option on to make the Jumper available on your network.', 'wp-ultimo'), + 'type' => 'toggle', + 'default' => 1, + ) + ); - wu_register_settings_field('tools', 'jumper_key', array( - 'title' => __('Trigger Key', 'wp-ultimo'), - 'desc' => __('Change the keyboard key used in conjunction with ctrl + alt (or cmd + option), to trigger the Jumper box.', 'wp-ultimo'), - 'type' => 'text', - 'default' => 'g', - 'require' => array( - 'enable_jumper' => 1, - ), - )); + wu_register_settings_field( + 'tools', + 'jumper_key', + array( + 'title' => __('Trigger Key', 'wp-ultimo'), + 'desc' => __('Change the keyboard key used in conjunction with ctrl + alt (or cmd + option), to trigger the Jumper box.', 'wp-ultimo'), + 'type' => 'text', + 'default' => 'g', + 'require' => array( + 'enable_jumper' => 1, + ), + ) + ); - wu_register_settings_field('tools', 'jumper_custom_links', array( - 'title' => __('Custom Links', 'wp-ultimo'), - 'desc' => __('Use this textarea to add custom links to the Jumper. Add one per line, with the format "Title : url".', 'wp-ultimo'), - 'placeholder' => __('Tile of Custom Link : http://link.com', 'wp-ultimo'), - 'type' => 'textarea', - 'html_attr' => array( - 'rows' => 4, - ), - 'require' => array( - 'enable_jumper' => 1, - ), - )); - - } // end add_settings; + wu_register_settings_field( + 'tools', + 'jumper_custom_links', + array( + 'title' => __('Custom Links', 'wp-ultimo'), + 'desc' => __('Use this textarea to add custom links to the Jumper. Add one per line, with the format "Title : url".', 'wp-ultimo'), + 'placeholder' => __('Tile of Custom Link : http://link.com', 'wp-ultimo'), + 'type' => 'textarea', + 'html_attr' => array( + 'rows' => 4, + ), + 'require' => array( + 'enable_jumper' => 1, + ), + ) + ); + } /** * Helper function to recursively seach an array. @@ -578,19 +556,13 @@ class Jumper { public function search_recursive($needle, $haystack) { foreach ($haystack as $key => $value) { - $current_key = $key; if ($needle === $value || (is_array($value) && $this->search_recursive($needle, $value) !== false)) { - return $value; - - } // end if; - - } // end foreach; + } + } return false; - - } // end search_recursive; - -} // end class Jumper; + } +} diff --git a/inc/ui/class-limits-element.php b/inc/ui/class-limits-element.php index 540ddaf..7a9190a 100644 --- a/inc/ui/class-limits-element.php +++ b/inc/ui/class-limits-element.php @@ -9,7 +9,7 @@ namespace WP_Ultimo\UI; -use \WP_Ultimo\UI\Base_Element; +use WP_Ultimo\UI\Base_Element; // Exit if accessed directly defined('ABSPATH') || exit; @@ -55,23 +55,20 @@ class Limits_Element extends Base_Element { protected $site; /** - * The icon of the UI element. - * e.g. return fa fa-search - * - * @since 2.0.0 - * @param string $context One of the values: block, elementor or bb. - */ + * The icon of the UI element. + * e.g. return fa fa-search + * + * @since 2.0.0 + * @param string $context One of the values: block, elementor or bb. + */ public function get_icon($context = 'block'): string { if ($context === 'elementor') { - return 'eicon-skill-bar'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * The title of the UI element. @@ -86,8 +83,7 @@ class Limits_Element extends Base_Element { public function get_title() { return __('Limits & Quotas', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -103,8 +99,7 @@ class Limits_Element extends Base_Element { public function get_description() { return __('Adds a checkout form block to the page.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -152,8 +147,7 @@ class Limits_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * The list of keywords for this element. @@ -181,8 +175,7 @@ class Limits_Element extends Base_Element { 'Limits', 'Quotas', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -204,8 +197,7 @@ class Limits_Element extends Base_Element { 'columns' => 1, 'title' => __('Site Limits', 'wp-ultimo'), ); - - } // end defaults; + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -217,13 +209,10 @@ class Limits_Element extends Base_Element { $this->site = WP_Ultimo()->currents->get_site(); - if (!$this->site || !$this->site->is_customer_allowed()) { - + if ( ! $this->site || ! $this->site->is_customer_allowed()) { $this->set_display(false); - - } // end if; - - } // end setup; + } + } /** * Allows the setup in the context of previews. @@ -234,8 +223,7 @@ class Limits_Element extends Base_Element { public function setup_preview() { $this->site = wu_mock_site(); - - } // end setup_preview; + } /** * The content to be output on the screen. @@ -252,9 +240,12 @@ class Limits_Element extends Base_Element { */ public function output($atts, $content = null) { - $post_types = get_post_types(array( - 'public' => true, - ), 'objects'); + $post_types = get_post_types( + array( + 'public' => true, + ), + 'objects' + ); /* * Remove post types that where disabled or that are not available for display. @@ -278,7 +269,5 @@ class Limits_Element extends Base_Element { $atts['post_type_limits'] = $this->site->get_limitations()->post_types; return wu_get_template_contents('dashboard-widgets/limits-and-quotas', $atts); - - } // end output; - -} // end class Limits_Element; + } +} diff --git a/inc/ui/class-login-form-element.php b/inc/ui/class-login-form-element.php index 29579b0..2f98079 100644 --- a/inc/ui/class-login-form-element.php +++ b/inc/ui/class-login-form-element.php @@ -9,8 +9,8 @@ namespace WP_Ultimo\UI; -use \WP_Ultimo\UI\Base_Element; -use \WP_Ultimo\Checkout\Checkout_Pages; +use WP_Ultimo\UI\Base_Element; +use WP_Ultimo\Checkout\Checkout_Pages; // Exit if accessed directly defined('ABSPATH') || exit; @@ -67,27 +67,23 @@ class Login_Form_Element extends Base_Element { add_filter('login_redirect', array($this, 'handle_redirect'), -1, 3); parent::init(); - - } // end init; + } /** - * The icon of the UI element. - * e.g. return fa fa-search - * - * @since 2.0.0 - * @param string $context One of the values: block, elementor or bb. - */ + * The icon of the UI element. + * e.g. return fa fa-search + * + * @since 2.0.0 + * @param string $context One of the values: block, elementor or bb. + */ public function get_icon($context = 'block'): string { if ($context === 'elementor') { - return 'eicon-lock-user'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * The title of the UI element. @@ -102,8 +98,7 @@ class Login_Form_Element extends Base_Element { public function get_title() { return __('Login Form', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -119,8 +114,7 @@ class Login_Form_Element extends Base_Element { public function get_description() { return __('Adds a login form to the page.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -297,8 +291,7 @@ class Login_Form_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * Registers scripts and styles necessary to render this. @@ -309,8 +302,7 @@ class Login_Form_Element extends Base_Element { public function register_scripts() { wp_enqueue_style('wu-admin'); - - } // end register_scripts; + } /** * The list of keywords for this element. @@ -337,8 +329,7 @@ class Login_Form_Element extends Base_Element { 'Login', 'Reset Password', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -389,8 +380,7 @@ class Login_Form_Element extends Base_Element { 'value_username' => '', 'value_remember' => false, // Set 'value_remember' to true to default the "Remember me" checkbox to checked. ); - - } // end defaults; + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -403,13 +393,11 @@ class Login_Form_Element extends Base_Element { $this->logged = is_user_logged_in(); if ($this->is_reset_password_page()) { - $rp_path = '/'; $rp_cookie = 'wp-resetpass-' . COOKIEHASH; if (isset($_GET['key']) && isset($_GET['login'])) { - $value = sprintf('%s:%s', wp_unslash($_GET['login']), wp_unslash($_GET['key'])); setcookie($rp_cookie, $value, 0, $rp_path, (string) COOKIE_DOMAIN, is_ssl(), true); @@ -417,10 +405,8 @@ class Login_Form_Element extends Base_Element { wp_safe_redirect(remove_query_arg(array('key', 'login'))); exit; - - } // end if; - - } // end if; + } + } global $post; @@ -428,12 +414,9 @@ class Login_Form_Element extends Base_Element { * Handles maintenance mode on Elementor. */ if ($post && $post->ID === absint(wu_get_setting('default_login_page', 0))) { - add_filter('elementor/maintenance_mode/is_login_page', '__return_true'); - - } // end if; - - } // end setup; + } + } /** * Checks if we are in a lost password form page. @@ -444,8 +427,7 @@ class Login_Form_Element extends Base_Element { public function is_lost_password_page() { return wu_request('action') === 'lostpassword'; - - } // end is_lost_password_page; + } /** * Checks if we are in the email confirm instruction page of a reset password. @@ -456,8 +438,7 @@ class Login_Form_Element extends Base_Element { public function is_check_email_confirm() { return wu_request('checkemail') === 'confirm'; - - } // end is_check_email_confirm; + } /** * Checks if we are in a reset password page. @@ -468,8 +449,7 @@ class Login_Form_Element extends Base_Element { public function is_reset_password_page() { return wu_request('action') === 'rp' || wu_request('action') === 'resetpass'; - - } // end is_reset_password_page; + } /** * Checks if we are in the the password rest confirmation page. @@ -480,8 +460,7 @@ class Login_Form_Element extends Base_Element { public function is_reset_confirmation_page() { return wu_request('password-reset') === 'success'; - - } // end is_reset_confirmation_page; + } /** * Handle custom login redirection @@ -496,28 +475,22 @@ class Login_Form_Element extends Base_Element { public function handle_redirect($redirect_to, $requested_redirect_to, $user) { if (is_wp_error($user)) { - if (wu_request('wu_login_page_url')) { - $redirect_to = wu_request('wu_login_page_url'); $redirect_to = add_query_arg('error', $user->get_error_code(), $redirect_to); if ($user->get_error_code() === 'invalid_username') { - $redirect_to = add_query_arg('username', wu_request('log'), $redirect_to); - - } // end if; + } // In this case, WP will not redirect, so we need to do it here wp_redirect($redirect_to); exit; - - } // end if; + } return $redirect_to; - - } // end if; + } $redirect_type = wu_request('wu_login_form_redirect_type', 'default'); @@ -526,24 +499,18 @@ class Login_Form_Element extends Base_Element { // query_redirect is the default wp behaviour return $redirect_to; - } elseif ($redirect_type === 'customer_site') { - - $user_site = get_active_blog_for_user( $user->ID ); + $user_site = get_active_blog_for_user($user->ID); wp_redirect($user_site->siteurl . $requested_redirect_to); exit; - } elseif ($redirect_type === 'main_site') { - wp_redirect(network_site_url($requested_redirect_to)); exit; - - } // end if; + } return $redirect_to; - - } // end handle_redirect; + } /** * Allows the setup in the context of previews. @@ -554,8 +521,7 @@ class Login_Form_Element extends Base_Element { public function setup_preview() { $this->logged = false; - - } // end setup_preview; + } /** * Returns the logout URL for the "not you bar". @@ -568,8 +534,7 @@ class Login_Form_Element extends Base_Element { $redirect_to = wu_get_current_url(); return wp_logout_url($redirect_to); - - } // end get_logout_url; + } /** * The content to be output on the screen. @@ -595,7 +560,6 @@ class Login_Form_Element extends Base_Element { * login URL so the user can re-login with the new password. */ if ($this->is_reset_confirmation_page()) { - $fields = array( 'email-activation-instructions' => array( 'type' => 'note', @@ -603,13 +567,12 @@ class Login_Form_Element extends Base_Element { ), ); - /* - * Check if are in the email confirmation instructions page. - * - * If that's the case, we show the instructions. - */ + /* + * Check if are in the email confirmation instructions page. + * + * If that's the case, we show the instructions. + */ } elseif ($this->is_check_email_confirm()) { - $fields = array( 'email-activation-instructions' => array( 'type' => 'note', @@ -621,33 +584,26 @@ class Login_Form_Element extends Base_Element { ), ); - /* - * Check if we are in the set new password page. - * - * If that's the case, we show the new password fields - * so the user can set a new password. - */ + /* + * Check if we are in the set new password page. + * + * If that's the case, we show the new password fields + * so the user can set a new password. + */ } elseif ($this->is_reset_password_page()) { - $rp_cookie = 'wp-resetpass-' . COOKIEHASH; - if (isset($_COOKIE[$rp_cookie]) && 0 < strpos((string) $_COOKIE[$rp_cookie], ':')) { - - list($rp_login, $rp_key) = explode(':', wp_unslash($_COOKIE[$rp_cookie]), 2); + if (isset($_COOKIE[ $rp_cookie ]) && 0 < strpos((string) $_COOKIE[ $rp_cookie ], ':')) { + list($rp_login, $rp_key) = explode(':', wp_unslash($_COOKIE[ $rp_cookie ]), 2); $user = check_password_reset_key($rp_key, $rp_login); - if (isset($_POST['pass1']) && !hash_equals($rp_key, $_POST['rp_key'])) { - + if (isset($_POST['pass1']) && ! hash_equals($rp_key, $_POST['rp_key'])) { $user = false; - - } // end if; - + } } else { - $user = false; - - } // end if; + } $redirect_to = add_query_arg('password-reset', 'success', remove_query_arg(array('action', 'error'))); @@ -702,21 +658,18 @@ class Login_Form_Element extends Base_Element { ), ); - /* - * Checks if we are in the first reset password page, where the customer requests a reset. - * - * If that's the case, we show the username/email field, so the user can - * get an email with the reset link. - */ + /* + * Checks if we are in the first reset password page, where the customer requests a reset. + * + * If that's the case, we show the username/email field, so the user can + * get an email with the reset link. + */ } elseif ($this->is_lost_password_page()) { - $user_login = wu_request('user_login', ''); if ($user_login) { - $user_login = wp_unslash($user_login); - - } // end if; + } $redirect_to = add_query_arg('checkemail', 'confirm', remove_query_arg(array('action', 'error'))); @@ -752,9 +705,7 @@ class Login_Form_Element extends Base_Element { 'wrapper_classes' => 'wu-items-end wu-bg-none', ), ); - } else { - $view = 'dashboard-widgets/login-form'; $fields = array( @@ -773,14 +724,12 @@ class Login_Form_Element extends Base_Element { ); if ($atts['remember']) { - $fields['rememberme'] = array( 'type' => 'toggle', 'title' => $atts['label_remember'], 'desc' => $atts['desc_remember'], ); - - } // end if; + } $fields['redirect_to'] = array( 'type' => 'hidden', @@ -788,19 +737,13 @@ class Login_Form_Element extends Base_Element { ); if (isset($_GET['redirect_to'])) { - $atts['redirect_type'] = 'query_redirect'; $fields['redirect_to']['value'] = $_GET['redirect_to']; - } elseif ($atts['redirect_type'] === 'customer_site') { - $fields['redirect_to']['value'] = $atts['customer_redirect_path']; - } elseif ($atts['redirect_type'] === 'main_site') { - $fields['redirect_to']['value'] = $atts['main_redirect_path']; - - } // end if; + } $fields['wu_login_form_redirect_type'] = array( 'type' => 'hidden', @@ -821,8 +764,7 @@ class Login_Form_Element extends Base_Element { 'classes' => '', 'wrapper_classes' => 'wu-items-end wu-bg-none', ); - - } // end if; + } /* * Check for error messages @@ -831,7 +773,6 @@ class Login_Form_Element extends Base_Element { * at the top of the fields array, to display the errors. */ if (wu_request('error')) { - $username = wu_request('username', ''); $error_message_field = array( @@ -842,8 +783,7 @@ class Login_Form_Element extends Base_Element { ); $fields = array_merge($error_message_field, $fields); - - } // end if; + } $fields['wu_login_page_url'] = array( 'type' => 'hidden', @@ -855,23 +795,25 @@ class Login_Form_Element extends Base_Element { * * @since 2.0.0 */ - $form = new \WP_Ultimo\UI\Form($this->get_id(), $fields, array( - 'action' => esc_url(site_url('wp-login.php', 'login_post')), - 'wrap_in_form_tag' => true, - 'views' => 'admin-pages/fields', - 'classes' => 'wu-p-0 wu-m-0', - 'field_wrapper_classes' => 'wu-box-border wu-items-center wu-flex wu-justify-between wu-py-4 wu-m-0', - 'html_attr' => array( - 'class' => 'wu-w-full', - ), - )); + $form = new \WP_Ultimo\UI\Form( + $this->get_id(), + $fields, + array( + 'action' => esc_url(site_url('wp-login.php', 'login_post')), + 'wrap_in_form_tag' => true, + 'views' => 'admin-pages/fields', + 'classes' => 'wu-p-0 wu-m-0', + 'field_wrapper_classes' => 'wu-box-border wu-items-center wu-flex wu-justify-between wu-py-4 wu-m-0', + 'html_attr' => array( + 'class' => 'wu-w-full', + ), + ) + ); $atts['logged'] = $this->logged; $atts['login_url'] = $this->get_logout_url(); $atts['form'] = $form; return wu_get_template_contents($view, $atts); - - } // end output; - -} // end class Login_Form_Element; + } +} diff --git a/inc/ui/class-my-sites-element.php b/inc/ui/class-my-sites-element.php index 42cd0ef..1ef4372 100644 --- a/inc/ui/class-my-sites-element.php +++ b/inc/ui/class-my-sites-element.php @@ -74,14 +74,11 @@ class My_Sites_Element extends Base_Element { public function get_icon($context = 'block') { if ($context === 'elementor') { - return 'eicon-info-circle-o'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * The title of the UI element. @@ -96,8 +93,7 @@ class My_Sites_Element extends Base_Element { public function get_title() { return __('My Sites', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -113,8 +109,7 @@ class My_Sites_Element extends Base_Element { public function get_description() { return __('Adds a block to display the sites owned by the current customer.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -168,19 +163,19 @@ class My_Sites_Element extends Base_Element { ), ); - $pages = get_pages(array( - 'exclude' => array(get_the_ID()), - )); + $pages = get_pages( + array( + 'exclude' => array(get_the_ID()), + ) + ); $pages = $pages ? $pages : array(); $pages_list = array(0 => __('Current Page', 'wp-ultimo')); foreach ($pages as $page) { - - $pages_list[$page->ID] = $page->post_title; - - } // end foreach; + $pages_list[ $page->ID ] = $page->post_title; + } $fields['custom_manage_page'] = array( 'type' => 'select', @@ -213,8 +208,7 @@ class My_Sites_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * The list of keywords for this element. @@ -242,8 +236,7 @@ class My_Sites_Element extends Base_Element { 'Form', 'Cart', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -268,8 +261,7 @@ class My_Sites_Element extends Base_Element { 'custom_manage_page' => 0, 'site_show' => 'owned', ); - - } // end defaults; + } /** * Loads the necessary scripts and styles for this element. @@ -280,8 +272,7 @@ class My_Sites_Element extends Base_Element { public function register_scripts() { wp_enqueue_style('wu-admin'); - - } // end register_scripts; + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -293,17 +284,14 @@ class My_Sites_Element extends Base_Element { global $wpdb; - if (!is_user_logged_in() || WP_Ultimo()->currents->is_site_set_via_request()) { - + if ( ! is_user_logged_in() || WP_Ultimo()->currents->is_site_set_via_request()) { $this->set_display(false); return; - - } // end if; + } $this->customer = WP_Ultimo()->currents->get_customer(); - - } // end setup; + } /** * Allows the setup in the context of previews. @@ -319,8 +307,7 @@ class My_Sites_Element extends Base_Element { wu_mock_site(1), wu_mock_site(2), ); - - } // end setup_preview; + } /** * The content to be output on the screen. @@ -342,8 +329,7 @@ class My_Sites_Element extends Base_Element { $atts['sites'] = $this->get_sites(wu_get_isset($atts, 'site_show')); return wu_get_template_contents('dashboard-widgets/my-sites', $atts); - - } // end output; + } /** * Get sites to display on widget @@ -353,46 +339,42 @@ class My_Sites_Element extends Base_Element { */ protected function get_sites(?string $show = null): array { - if (!empty($this->sites)) { - + if ( ! empty($this->sites)) { return $this->sites; - } $this->sites = apply_filters('wp_ultimo_pre_my_sites_sites', array(), $show); - if (!empty($this->sites)) { - + if ( ! empty($this->sites)) { return $this->sites; - } - if (!empty($this->customer)) { - + if ( ! empty($this->customer)) { $pending_sites = \WP_Ultimo\Models\Site::get_all_by_type('pending', array('customer_id' => $this->customer->get_id())); $customer_sites = array_reduce( $this->customer->get_sites(), function ($customer_sites, $site) { - $customer_sites[$site->get_id()] = $site; + $customer_sites[ $site->get_id() ] = $site; return $customer_sites; } ); } if ($show === 'all') { - $wp_user_sites = get_blogs_of_user(get_current_user_id()); - $user_sites = array_reduce($wp_user_sites, function($user_sites, $wp_site) use ($customer_sites) { - if (!array_key_exists($wp_site->userblog_id, $customer_sites ?? array()) && $wp_site->userblog_id !== get_main_site_id()) { - $wu_site = wu_get_site($wp_site->userblog_id); - $wu_site->set_membership_id(0); - $user_sites[$wp_site->userblog_id] = $wu_site; + $user_sites = array_reduce( + $wp_user_sites, + function ($user_sites, $wp_site) use ($customer_sites) { + if ( ! array_key_exists($wp_site->userblog_id, $customer_sites ?? array()) && $wp_site->userblog_id !== get_main_site_id()) { + $wu_site = wu_get_site($wp_site->userblog_id); + $wu_site->set_membership_id(0); + $user_sites[ $wp_site->userblog_id ] = $wu_site; + } + return $user_sites; } - return $user_sites; - }); - + ); } $sites = array_merge( @@ -404,8 +386,7 @@ class My_Sites_Element extends Base_Element { $this->sites = apply_filters('wp_ultimo_after_my_sites_sites', $sites, $show); return $this->sites; - - } // end get_sites; + } /** @@ -421,28 +402,26 @@ class My_Sites_Element extends Base_Element { public function get_manage_url($site_id, $type = 'default', $custom_page_id = 0) { if ($type === 'wp_admin') { - return get_admin_url($site_id); - - } // end if; + } if ($type === 'custom_page') { - $custom_page = get_page_link($custom_page_id); $url_param = \WP_Ultimo\Current::param_key('site'); $site_hash = \WP_Ultimo\Helpers\Hash::encode($site_id, 'site'); - return add_query_arg(array( - $url_param => $site_hash, - ), $custom_page); - - } // end if; + return add_query_arg( + array( + $url_param => $site_hash, + ), + $custom_page + ); + } return \WP_Ultimo\Current::get_manage_url($site_id, 'site'); - - } // end get_manage_url; + } /** * Returns the new site URL for site creation. @@ -460,35 +439,31 @@ class My_Sites_Element extends Base_Element { $url = $checkout_pages->get_page_url('new_site'); if ($membership) { - if ($url) { - - return add_query_arg(array( - 'membership' => $membership->get_hash(), - ), $url); - - } // end if; + return add_query_arg( + array( + 'membership' => $membership->get_hash(), + ), + $url + ); + } if (is_main_site()) { - $sites = $membership->get_sites(false); - if (!empty($sites)) { - - return add_query_arg(array( - 'page' => 'add-new-site', - ), get_admin_url($sites[0]->get_id())); - - } // end if; + if ( ! empty($sites)) { + return add_query_arg( + array( + 'page' => 'add-new-site', + ), + get_admin_url($sites[0]->get_id()) + ); + } return ''; - - } // end if; - - } // end if; + } + } return admin_url('admin.php?page=add-new-site'); - - } // end get_new_site_url; - -} // end class My_Sites_Element; + } +} diff --git a/inc/ui/class-payment-methods-element.php b/inc/ui/class-payment-methods-element.php index d0796d5..a20ab75 100644 --- a/inc/ui/class-payment-methods-element.php +++ b/inc/ui/class-payment-methods-element.php @@ -49,14 +49,11 @@ class Payment_Methods_Element extends Base_Element { public function get_icon($context = 'block') { if ($context === 'elementor') { - return 'eicon-info-circle-o'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * The title of the UI element. @@ -71,8 +68,7 @@ class Payment_Methods_Element extends Base_Element { public function get_title() { return __('Payment Methods', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -88,8 +84,7 @@ class Payment_Methods_Element extends Base_Element { public function get_description() { return __('Adds a checkout form block to the page.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -135,8 +130,7 @@ class Payment_Methods_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * The list of keywords for this element. @@ -164,8 +158,7 @@ class Payment_Methods_Element extends Base_Element { 'Form', 'Cart', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -184,8 +177,7 @@ class Payment_Methods_Element extends Base_Element { public function defaults() { return array(); - - } // end defaults; + } /** * The content to be output on the screen. @@ -203,7 +195,5 @@ class Payment_Methods_Element extends Base_Element { public function output($atts, $content = null) { return 'lol'; - - } // end output; - -} // end class Payment_Methods_Element; + } +} diff --git a/inc/ui/class-simple-text-element.php b/inc/ui/class-simple-text-element.php index 150a966..ae63839 100644 --- a/inc/ui/class-simple-text-element.php +++ b/inc/ui/class-simple-text-element.php @@ -65,14 +65,11 @@ class Simple_Text_Element extends Base_Element { public function get_icon($context = 'block') { if ($context === 'elementor') { - return 'eicon-lock-user'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * The title of the UI element. @@ -87,8 +84,7 @@ class Simple_Text_Element extends Base_Element { public function get_title() { return __('Simple Text', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -104,8 +100,7 @@ class Simple_Text_Element extends Base_Element { public function get_description() { return __('Adds a simple text block to the page.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -142,12 +137,11 @@ class Simple_Text_Element extends Base_Element { 'tooltip' => '', 'html_attr' => array( 'rows' => 6, - ) + ), ); return $fields; - - } // end fields; + } /** * Registers scripts and styles necessary to render this. @@ -158,8 +152,7 @@ class Simple_Text_Element extends Base_Element { public function register_scripts() { wp_enqueue_style('wu-admin'); - - } // end register_scripts; + } /** * The list of keywords for this element. @@ -186,10 +179,9 @@ class Simple_Text_Element extends Base_Element { 'text', 'simple text', 'shortcode', - 'textarea' + 'textarea', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -210,8 +202,7 @@ class Simple_Text_Element extends Base_Element { return array( 'simple_text' => __('Text, HTML or shortcode.', 'wp-ultimo'), ); - - } // end defaults; + } /** * The content to be output on the screen. @@ -229,7 +220,5 @@ class Simple_Text_Element extends Base_Element { public function output($atts, $content = null) { return wu_get_template_contents('dashboard-widgets/simple-text', $atts); - - } // end output; - -} // end class Simple_Text_Element; + } +} diff --git a/inc/ui/class-site-actions-element.php b/inc/ui/class-site-actions-element.php index f5fa487..7cc0aa9 100644 --- a/inc/ui/class-site-actions-element.php +++ b/inc/ui/class-site-actions-element.php @@ -74,8 +74,7 @@ class Site_Actions_Element extends Base_Element { public function register_scripts() { add_wubox(); - - } // end register_scripts; + } /** * The icon of the UI element. * e.g. return fa fa-search @@ -86,14 +85,11 @@ class Site_Actions_Element extends Base_Element { public function get_icon($context = 'block'): string { if ($context === 'elementor') { - return 'eicon-info-circle-o'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * The title of the UI element. @@ -108,8 +104,7 @@ class Site_Actions_Element extends Base_Element { public function get_title() { return __('Actions', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -125,8 +120,7 @@ class Site_Actions_Element extends Base_Element { public function get_description() { return __('Adds a checkout form block to the page.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -179,19 +173,19 @@ class Site_Actions_Element extends Base_Element { 'value' => 1, ); - $pages = get_pages(array( - 'exclude' => array(get_the_ID()), - )); + $pages = get_pages( + array( + 'exclude' => array(get_the_ID()), + ) + ); $pages = $pages ? $pages : array(); $pages_list = array(0 => __('Default', 'wp-ultimo')); foreach ($pages as $page) { - - $pages_list[$page->ID] = $page->post_title; - - } // end foreach; + $pages_list[ $page->ID ] = $page->post_title; + } $fields['redirect_after_delete'] = array( 'type' => 'select', @@ -203,8 +197,7 @@ class Site_Actions_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * The list of keywords for this element. @@ -232,8 +225,7 @@ class Site_Actions_Element extends Base_Element { 'Form', 'Cart', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -257,8 +249,7 @@ class Site_Actions_Element extends Base_Element { 'show_change_payment_method' => 1, 'redirect_after_delete' => 0, ); - - } // end defaults; + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -270,23 +261,18 @@ class Site_Actions_Element extends Base_Element { $this->site = WP_Ultimo()->currents->get_site(); - if (!$this->site || !$this->site->is_customer_allowed()) { - + if ( ! $this->site || ! $this->site->is_customer_allowed()) { $this->site = false; - - } // end if; + } $this->membership = WP_Ultimo()->currents->get_membership(); - if (!$this->membership) { - + if ( ! $this->membership) { $this->set_display(false); return; - - } // end if; - - } // end setup; + } + } /** * Allows the setup in the context of previews. @@ -299,8 +285,7 @@ class Site_Actions_Element extends Base_Element { $this->site = wu_mock_site(); $this->membership = wu_mock_membership(); - - } // end setup_preview; + } /** * Overload the init to add site-related forms. @@ -313,8 +298,7 @@ class Site_Actions_Element extends Base_Element { parent::init(); $this->register_forms(); - - } // end init; + } /** * Register forms @@ -324,37 +308,51 @@ class Site_Actions_Element extends Base_Element { */ public function register_forms() { - wu_register_form('change_password', array( - 'render' => array($this, 'render_change_password'), - 'handler' => array($this, 'handle_change_password'), - 'capability' => 'exist', - )); + wu_register_form( + 'change_password', + array( + 'render' => array($this, 'render_change_password'), + 'handler' => array($this, 'handle_change_password'), + 'capability' => 'exist', + ) + ); - wu_register_form('delete_site', array( - 'render' => array($this, 'render_delete_site'), - 'handler' => array($this, 'handle_delete_site'), - 'capability' => 'exist', - )); + wu_register_form( + 'delete_site', + array( + 'render' => array($this, 'render_delete_site'), + 'handler' => array($this, 'handle_delete_site'), + 'capability' => 'exist', + ) + ); - wu_register_form('change_default_site', array( - 'render' => array($this, 'render_change_default_site'), - 'handler' => array($this, 'handle_change_default_site'), - 'capability' => 'exist', - )); + wu_register_form( + 'change_default_site', + array( + 'render' => array($this, 'render_change_default_site'), + 'handler' => array($this, 'handle_change_default_site'), + 'capability' => 'exist', + ) + ); - wu_register_form('cancel_payment_method', array( - 'render' => array($this, 'render_cancel_payment_method'), - 'handler' => array($this, 'handle_cancel_payment_method'), - 'capability' => 'exist', - )); + wu_register_form( + 'cancel_payment_method', + array( + 'render' => array($this, 'render_cancel_payment_method'), + 'handler' => array($this, 'handle_cancel_payment_method'), + 'capability' => 'exist', + ) + ); - wu_register_form('cancel_membership', array( - 'render' => array($this, 'render_cancel_membership'), - 'handler' => array($this, 'handle_cancel_membership'), - 'capability' => 'exist', - )); - - } // end register_forms; + wu_register_form( + 'cancel_membership', + array( + 'render' => array($this, 'render_cancel_membership'), + 'handler' => array($this, 'handle_cancel_membership'), + 'capability' => 'exist', + ) + ); + } /** * Returns the actions for the element. These can be filtered. @@ -372,58 +370,55 @@ class Site_Actions_Element extends Base_Element { $is_template_switching_enabled = wu_get_setting('allow_template_switching', true); if ($is_template_switching_enabled && $this->site) { - $actions['template_switching'] = array( 'label' => __('Change Site Template', 'wp-ultimo'), 'icon_classes' => 'dashicons-wu-edit wu-align-middle', - 'href' => add_query_arg(array( - 'page' => 'wu-template-switching', - ), get_admin_url($this->site->get_id())), + 'href' => add_query_arg( + array( + 'page' => 'wu-template-switching', + ), + get_admin_url($this->site->get_id()) + ), ); - - } // end if; + } if (count($all_blogs) > 1 && wu_get_isset($atts, 'show_change_default_site')) { - $actions['default_site'] = array( 'label' => __('Change Default Site', 'wp-ultimo'), 'icon_classes' => 'dashicons-wu-edit wu-align-middle', 'classes' => 'wubox', 'href' => wu_get_form_url('change_default_site'), ); - - } // end if; + } if (wu_get_isset($atts, 'show_change_password')) { - $actions['change_password'] = array( 'label' => __('Change Password', 'wp-ultimo'), 'icon_classes' => 'dashicons-wu-edit wu-align-middle', 'classes' => 'wubox', 'href' => wu_get_form_url('change_password'), ); - - } // end if; + } $payment_gateway = $this->membership ? $this->membership->get_gateway() : false; if (wu_get_isset($atts, 'show_change_payment_method') && $payment_gateway) { - $actions['cancel_payment_method'] = array( 'label' => __('Cancel Current Payment Method', 'wp-ultimo'), 'icon_classes' => 'dashicons-wu-edit wu-align-middle', 'classes' => 'wubox', - 'href' => wu_get_form_url('cancel_payment_method', array( - 'membership' => $this->membership->get_hash(), - 'redirect_url' => wu_get_current_url(), - )), + 'href' => wu_get_form_url( + 'cancel_payment_method', + array( + 'membership' => $this->membership->get_hash(), + 'redirect_url' => wu_get_current_url(), + ) + ), ); - - } // end if; + } return apply_filters('wu_element_get_site_actions', $actions, $atts, $this->site, $this->membership); - - } // end get_actions; + } /** * Returns the danger actions actions for the element. These can be filtered. @@ -437,40 +432,47 @@ class Site_Actions_Element extends Base_Element { $actions = array(); if ($this->site) { - - $actions = array_merge(array( - 'delete_site' => array( - 'label' => __('Delete Site', 'wp-ultimo'), - 'icon_classes' => 'dashicons-wu-edit wu-align-middle', - 'classes' => 'wubox wu-text-red-500', - 'href' => wu_get_form_url('delete_site', array( - 'site' => $this->site->get_hash(), - 'redirect_url' => !$atts['redirect_after_delete'] ? false : get_page_link($atts['redirect_after_delete']), - )), + $actions = array_merge( + array( + 'delete_site' => array( + 'label' => __('Delete Site', 'wp-ultimo'), + 'icon_classes' => 'dashicons-wu-edit wu-align-middle', + 'classes' => 'wubox wu-text-red-500', + 'href' => wu_get_form_url( + 'delete_site', + array( + 'site' => $this->site->get_hash(), + 'redirect_url' => ! $atts['redirect_after_delete'] ? false : get_page_link($atts['redirect_after_delete']), + ) + ), + ), ), - ), $actions); - - } // end if; + $actions + ); + } if ($this->membership && $this->membership->is_recurring() && $this->membership->get_status() !== Membership_Status::CANCELLED) { - - $actions = array_merge(array( - 'cancel_membership' => array( - 'label' => __('Cancel Membership', 'wp-ultimo'), - 'icon_classes' => 'dashicons-wu-edit wu-align-middle', - 'classes' => 'wubox wu-text-red-500', - 'href' => wu_get_form_url('cancel_membership', array( - 'membership' => $this->membership->get_hash(), - 'redirect_url' => wu_get_current_url(), - )), + $actions = array_merge( + array( + 'cancel_membership' => array( + 'label' => __('Cancel Membership', 'wp-ultimo'), + 'icon_classes' => 'dashicons-wu-edit wu-align-middle', + 'classes' => 'wubox wu-text-red-500', + 'href' => wu_get_form_url( + 'cancel_membership', + array( + 'membership' => $this->membership->get_hash(), + 'redirect_url' => wu_get_current_url(), + ) + ), + ), ), - ), $actions); - - } // end if; + $actions + ); + } return apply_filters('wu_element_get_danger_zone_site_actions', $actions); - - } // end get_danger_zone_actions; + } /** * Renders the delete site modal. @@ -484,22 +486,17 @@ class Site_Actions_Element extends Base_Element { $error = ''; - if (!$site) { - + if ( ! $site) { $error = __('Site not selected.', 'wp-ultimo'); - - } // end if; + } $customer = wu_get_current_customer(); - if (!$customer || $customer->get_id() !== $site->get_customer_id()) { - + if ( ! $customer || $customer->get_id() !== $site->get_customer_id()) { $error = __('You are not allowed to do this.', 'wp-ultimo'); + } - } // end if; - - if (!empty($error)) { - + if ( ! empty($error)) { $error_field = array( 'error_message' => array( 'type' => 'note', @@ -507,17 +504,20 @@ class Site_Actions_Element extends Base_Element { ), ); - $form = new \WP_Ultimo\UI\Form('change_password', $error_field, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - )); + $form = new \WP_Ultimo\UI\Form( + 'change_password', + $error_field, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + ) + ); $form->render(); return; - - } // end if; + } $fields = array( 'site' => array( @@ -549,21 +549,26 @@ class Site_Actions_Element extends Base_Element { ), ); - $form = new \WP_Ultimo\UI\Form('change_password', $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' => 'change_password', - 'data-state' => wu_convert_to_state(array( - 'confirmed' => false, - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'change_password', + $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' => 'change_password', + 'data-state' => wu_convert_to_state( + array( + 'confirmed' => false, + ) + ), + ), + ) + ); $form->render(); - - } // end render_delete_site; + } /** * Handles the delete site modal. @@ -578,55 +583,49 @@ class Site_Actions_Element extends Base_Element { $site = wu_get_site_by_hash(wu_request('site')); - if (!$site || !$site->is_customer_allowed()) { - + if ( ! $site || ! $site->is_customer_allowed()) { return new \WP_Error('error', __('An unexpected error happened.', 'wp-ultimo')); - - } // end if; + } $customer = wu_get_current_customer(); - if (!$customer || $customer->get_id() !== $site->get_customer_id()) { - + if ( ! $customer || $customer->get_id() !== $site->get_customer_id()) { return new \WP_Error('error', __('You are not allowed to do this.', 'wp-ultimo')); - - } // end if; + } $wpdb->query('START TRANSACTION'); try { - $saved = $site->delete(); if (is_wp_error($saved)) { - $wpdb->query('ROLLBACK'); return $saved; - - } // end if; - + } } catch (\Throwable $e) { - $wpdb->query('ROLLBACK'); return new \WP_Error('exception', $e->getMessage()); - - } // end try; + } $wpdb->query('COMMIT'); $redirect_url = wu_request('redirect_url'); - $redirect_url = add_query_arg(array( - 'site_deleted' => true, - ), wu_request('redirect_url') ?? user_admin_url()); + $redirect_url = add_query_arg( + array( + 'site_deleted' => true, + ), + wu_request('redirect_url') ?? user_admin_url() + ); - wp_send_json_success(array( - 'redirect_url' => $redirect_url, - )); - - } // end handle_delete_site; + wp_send_json_success( + array( + 'redirect_url' => $redirect_url, + ) + ); + } /** * Renders the change password modal. @@ -665,19 +664,22 @@ class Site_Actions_Element extends Base_Element { ), ); - $form = new \WP_Ultimo\UI\Form('change_password', $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' => 'change_password', - 'data-state' => wu_convert_to_state(), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'change_password', + $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' => 'change_password', + 'data-state' => wu_convert_to_state(), + ), + ) + ); $form->render(); - - } // end render_change_password; + } /** * Handles the password reset form. @@ -689,42 +691,34 @@ class Site_Actions_Element extends Base_Element { $user = wp_get_current_user(); - if (!$user) { - + if ( ! $user) { $error = new \WP_Error('user-dont-exist', __('Something went wrong.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } $current_password = wu_request('password'); - if (!wp_check_password($current_password, $user->user_pass, $user->ID)) { - + if ( ! wp_check_password($current_password, $user->user_pass, $user->ID)) { $error = new \WP_Error('wrong-password', __('Your current password is wrong.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } $new_password = wu_request('new_password'); $new_password_conf = wu_request('new_password_conf'); - if (!$new_password || strlen((string) $new_password) < 6) { - + if ( ! $new_password || strlen((string) $new_password) < 6) { $error = new \WP_Error('password-min-length', __('The new password must be at least 6 characters long.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } if ($new_password !== $new_password_conf) { - $error = new \WP_Error('passwords-dont-match', __('New passwords do not match.', 'wp-ultimo')); wp_send_json_error($error); - - } // end if; + } reset_password($user, $new_password); @@ -733,11 +727,12 @@ class Site_Actions_Element extends Base_Element { wp_set_current_user($user->ID); do_action('wp_login', $user->user_login, $user); // PHPCS:ignore - wp_send_json_success(array( - 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), - )); - - } // end handle_change_password; + wp_send_json_success( + array( + 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), + ) + ); + } /** * Renders the change current site modal. @@ -752,10 +747,8 @@ class Site_Actions_Element extends Base_Element { $option_blogs = array(); foreach ($all_blogs as $key => $blog) { - - $option_blogs[$blog->userblog_id] = get_home_url($blog->userblog_id); - - } // end foreach; + $option_blogs[ $blog->userblog_id ] = get_home_url($blog->userblog_id); + } $primary_blog = get_user_meta(get_current_user_id(), 'primary_blog', true); @@ -782,21 +775,26 @@ class Site_Actions_Element extends Base_Element { ), ); - $form = new \WP_Ultimo\UI\Form('change_default_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' => 'change_default_site', - 'data-state' => wu_convert_to_state(array( - 'new_primary_site' => $primary_blog - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'change_default_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' => 'change_default_site', + 'data-state' => wu_convert_to_state( + array( + 'new_primary_site' => $primary_blog, + ) + ), + ), + ) + ); $form->render(); - - } // end render_change_default_site; + } /** * Handles the change default site form. @@ -809,20 +807,19 @@ class Site_Actions_Element extends Base_Element { $new_primary_site = wu_request('new_primary_site'); if ($new_primary_site) { - update_user_meta(get_current_user_id(), 'primary_blog', $new_primary_site); - wp_send_json_success(array( - 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), - )); - - } // end if; + wp_send_json_success( + array( + 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']), + ) + ); + } $error = new \WP_Error('no-site-selected', __('You need to select a new primary site.', 'wp-ultimo')); wp_send_json_error($error); - - } // end handle_change_default_site; + } /** * Renders the cancel payment method modal. @@ -836,22 +833,17 @@ class Site_Actions_Element extends Base_Element { $error = ''; - if (!$membership) { - + if ( ! $membership) { $error = __('Membership not selected.', 'wp-ultimo'); - - } // end if; + } $customer = wu_get_current_customer(); - if (!is_super_admin() && (!$customer || $customer->get_id() !== $membership->get_customer_id())) { - + if ( ! is_super_admin() && (! $customer || $customer->get_id() !== $membership->get_customer_id())) { $error = __('You are not allowed to do this.', 'wp-ultimo'); + } - } // end if; - - if (!empty($error)) { - + if ( ! empty($error)) { $error_field = array( 'error_message' => array( 'type' => 'note', @@ -859,17 +851,20 @@ class Site_Actions_Element extends Base_Element { ), ); - $form = new \WP_Ultimo\UI\Form('cancel_payment_method', $error_field, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - )); + $form = new \WP_Ultimo\UI\Form( + 'cancel_payment_method', + $error_field, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + ) + ); $form->render(); return; - - } // end if; + } $fields = array( 'membership' => array( @@ -901,21 +896,26 @@ class Site_Actions_Element extends Base_Element { ), ); - $form = new \WP_Ultimo\UI\Form('cancel_payment_method', $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' => 'cancel_payment_method', - 'data-state' => wu_convert_to_state(array( - 'confirmed' => false, - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'cancel_payment_method', + $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' => 'cancel_payment_method', + 'data-state' => wu_convert_to_state( + array( + 'confirmed' => false, + ) + ), + ), + ) + ); $form->render(); - - } // end render_cancel_payment_method; + } /** * Handles the payment method cancellation. @@ -927,27 +927,23 @@ class Site_Actions_Element extends Base_Element { $membership = wu_get_membership_by_hash(wu_request('membership')); - if (!$membership) { - + if ( ! $membership) { $error = new \WP_Error('error', __('An unexpected error happened.', 'wp-ultimo')); wp_send_json_error($error); return; - - } // end if; + } $customer = wu_get_current_customer(); - if (!is_super_admin() && (!$customer || $customer->get_id() !== $membership->get_customer_id())) { - + if ( ! is_super_admin() && (! $customer || $customer->get_id() !== $membership->get_customer_id())) { $error = new \WP_Error('error', __('You are not allowed to do this.', 'wp-ultimo')); wp_send_json_error($error); return; - - } // end if; + } $membership->set_gateway(''); $membership->set_gateway_subscription_id(''); @@ -958,15 +954,19 @@ class Site_Actions_Element extends Base_Element { $redirect_url = wu_request('redirect_url'); - $redirect_url = add_query_arg(array( - 'payment_gateway_cancelled' => true, - ), $redirect_url ?? user_admin_url()); + $redirect_url = add_query_arg( + array( + 'payment_gateway_cancelled' => true, + ), + $redirect_url ?? user_admin_url() + ); - wp_send_json_success(array( - 'redirect_url' => $redirect_url, - )); - - } // end handle_cancel_payment_method; + wp_send_json_success( + array( + 'redirect_url' => $redirect_url, + ) + ); + } /** * Renders the cancel payment method modal. @@ -980,22 +980,17 @@ class Site_Actions_Element extends Base_Element { $error = ''; - if (!$membership) { - + if ( ! $membership) { $error = __('Membership not selected.', 'wp-ultimo'); - - } // end if; + } $customer = wu_get_current_customer(); - if (!is_super_admin() && (!$customer || $customer->get_id() !== $membership->get_customer_id())) { - + if ( ! is_super_admin() && (! $customer || $customer->get_id() !== $membership->get_customer_id())) { $error = __('You are not allowed to do this.', 'wp-ultimo'); + } - } // end if; - - if (!empty($error)) { - + if ( ! empty($error)) { $error_field = array( 'error_message' => array( 'type' => 'note', @@ -1003,17 +998,20 @@ class Site_Actions_Element extends Base_Element { ), ); - $form = new \WP_Ultimo\UI\Form('cancel_membership', $error_field, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - )); + $form = new \WP_Ultimo\UI\Form( + 'cancel_membership', + $error_field, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + ) + ); $form->render(); return; - - } // end if; + } $fields = array( 'membership' => array( @@ -1062,20 +1060,16 @@ class Site_Actions_Element extends Base_Element { $next_charge = false; if ($membership->is_recurring() && ($membership->is_active() || $membership->get_status() === Membership_Status::TRIALING)) { - $next_charge = strtotime($membership->get_date_expiration()); - - } // end if; + } if ($next_charge && $next_charge > time()) { - $fields['next_charge'] = array( 'type' => 'note', // translators: %s: Next charge date. 'desc' => sprintf(__('Your sites will stay working until %s.', 'wp-ultimo'), date_i18n(get_option('date_format'), $next_charge)), ); - - } // end if; + } $fields['submit_button'] = array( 'type' => 'submit', @@ -1089,22 +1083,27 @@ class Site_Actions_Element extends Base_Element { ), ); - $form = new \WP_Ultimo\UI\Form('cancel_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' => 'cancel_membership', - 'data-state' => wu_convert_to_state(array( - 'confirmation' => '', - 'cancellation_reason' => '', - )), - ), - )); + $form = new \WP_Ultimo\UI\Form( + 'cancel_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' => 'cancel_membership', + 'data-state' => wu_convert_to_state( + array( + 'confirmation' => '', + 'cancellation_reason' => '', + ) + ), + ), + ) + ); $form->render(); - - } // end render_cancel_membership; + } /** * Handles the payment method cancellation. @@ -1116,27 +1115,23 @@ class Site_Actions_Element extends Base_Element { $membership = wu_get_membership_by_hash(wu_request('membership')); - if (!$membership) { - + if ( ! $membership) { $error = new \WP_Error('error', __('An unexpected error happened.', 'wp-ultimo')); wp_send_json_error($error); return; - - } // end if; + } $customer = wu_get_current_customer(); - if (!is_super_admin() && (!$customer || $customer->get_id() !== $membership->get_customer_id())) { - + if ( ! is_super_admin() && (! $customer || $customer->get_id() !== $membership->get_customer_id())) { $error = new \WP_Error('error', __('You are not allowed to do this.', 'wp-ultimo')); wp_send_json_error($error); return; - - } // end if; + } $cancellation_options = array( 'unused' => __('I no longer need it', 'wp-ultimo'), @@ -1154,15 +1149,19 @@ class Site_Actions_Element extends Base_Element { $redirect_url = wu_request('redirect_url'); - $redirect_url = add_query_arg(array( - 'payment_gateway_cancelled' => true, - ), !empty($redirect_url) ? $redirect_url : user_admin_url()); + $redirect_url = add_query_arg( + array( + 'payment_gateway_cancelled' => true, + ), + ! empty($redirect_url) ? $redirect_url : user_admin_url() + ); - wp_send_json_success(array( - 'redirect_url' => $redirect_url, - )); - - } // end handle_cancel_membership; + wp_send_json_success( + array( + 'redirect_url' => $redirect_url, + ) + ); + } /** * The content to be output on the screen. @@ -1184,7 +1183,5 @@ class Site_Actions_Element extends Base_Element { $atts['danger_zone_actions'] = $this->get_danger_zone_actions($atts); return wu_get_template_contents('dashboard-widgets/site-actions', $atts); - - } // end output; - -} // end class Site_Actions_Element; + } +} diff --git a/inc/ui/class-site-maintenance-element.php b/inc/ui/class-site-maintenance-element.php index 645c088..fa3a330 100644 --- a/inc/ui/class-site-maintenance-element.php +++ b/inc/ui/class-site-maintenance-element.php @@ -55,12 +55,9 @@ class Site_Maintenance_Element extends Base_Element { public function init() { if (wu_get_setting('maintenance_mode')) { - parent::init(); - - } // end if; - - } // end init; + } + } /** * The icon of the UI element. @@ -73,14 +70,11 @@ class Site_Maintenance_Element extends Base_Element { public function get_icon($context = 'block') { if ($context === 'elementor') { - return 'eicon-lock-user'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * The title of the UI element. @@ -95,8 +89,7 @@ class Site_Maintenance_Element extends Base_Element { public function get_title() { return __('Site Maintenance', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -112,8 +105,7 @@ class Site_Maintenance_Element extends Base_Element { public function get_description() { return __('Adds the toggle control to turn maintenance mode on.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -158,8 +150,7 @@ class Site_Maintenance_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * The list of keywords for this element. @@ -186,8 +177,7 @@ class Site_Maintenance_Element extends Base_Element { 'Login', 'Reset Password', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -209,8 +199,7 @@ class Site_Maintenance_Element extends Base_Element { 'title' => __('Toggle Maintenance Mode', 'wp-ultimo'), 'desc' => __('Put your site on maintenance mode. When activated, the front-end will only be accessible to logged users.', 'wp-ultimo'), ); - - } // end defaults; + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -222,15 +211,12 @@ class Site_Maintenance_Element extends Base_Element { $this->site = WP_Ultimo()->currents->get_site(); - if (!$this->site || !$this->site->is_customer_allowed()) { - + if ( ! $this->site || ! $this->site->is_customer_allowed()) { $this->set_display(false); return; - - } // end if; - - } // end setup; + } + } /** * Allows the setup in the context of previews. @@ -241,8 +227,7 @@ class Site_Maintenance_Element extends Base_Element { public function setup_preview() { $this->site = wu_mock_site(); - - } // end setup_preview; + } /** * Registers scripts and styles necessary to render this. @@ -254,14 +239,17 @@ class Site_Maintenance_Element extends Base_Element { wp_register_script('wu-site-maintenance', wu_get_asset('site-maintenance.js', 'js'), array('jquery', 'wu-functions'), wu_get_version()); - wp_localize_script('wu-site-maintenance', 'wu_site_maintenance', array( - 'nonce' => wp_create_nonce('wu_toggle_maintenance_mode'), - 'ajaxurl' => wu_ajax_url(), - )); + wp_localize_script( + 'wu-site-maintenance', + 'wu_site_maintenance', + array( + 'nonce' => wp_create_nonce('wu_toggle_maintenance_mode'), + 'ajaxurl' => wu_ajax_url(), + ) + ); wp_enqueue_script('wu-site-maintenance'); - - } // end register_scripts; + } /** * The content to be output on the screen. @@ -296,17 +284,19 @@ class Site_Maintenance_Element extends Base_Element { * * @since 2.0.0 */ - $form = new \WP_Ultimo\UI\Form('maintenance-mode', $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-widget-list wu-striped wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0 wu-list-none wu-p-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - 'html_attr' => array(), - )); + $form = new \WP_Ultimo\UI\Form( + 'maintenance-mode', + $fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-widget-list wu-striped wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0 wu-list-none wu-p-0', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + 'html_attr' => array(), + ) + ); $atts['form'] = $form; return wu_get_template_contents('dashboard-widgets/site-maintenance', $atts); - - } // end output; - -} // end class Site_Maintenance_Element; + } +} diff --git a/inc/ui/class-template-previewer.php b/inc/ui/class-template-previewer.php index 71bd267..168d74d 100644 --- a/inc/ui/class-template-previewer.php +++ b/inc/ui/class-template-previewer.php @@ -45,8 +45,7 @@ class Template_Previewer { public function init() { add_action('wp_ultimo_load', array($this, 'hooks')); - - } // end init; + } /** * Hooks into WordPress to add the template preview. @@ -71,11 +70,9 @@ class Template_Previewer { add_action('send_headers', array($this, 'send_cross_origin_headers'), 1000); return; - - } // end if; + } if ($this->is_template_previewer()) { - add_action('init', array($this, 'template_previewer')); add_action('wp_enqueue_scripts', array($this, 'register_scripts')); @@ -89,10 +86,8 @@ class Template_Previewer { * @param self $template_previewer Instance of the current class. */ do_action('wu_template_previewer', $this); - - } // end if; - - } // end hooks; + } + } /** * Send the cross origin headers to allow iframes to be loaded. @@ -109,8 +104,7 @@ class Template_Previewer { send_origin_headers(); header_remove('X-Frame-Options'); - - } // end send_cross_origin_headers; + } /** * Register the necessary scripts. @@ -130,25 +124,34 @@ class Template_Previewer { wp_register_script('wu-template-previewer', wu_get_asset('template-previewer.js', 'js'), array(), wu_get_version()); - wp_localize_script('wu-template-previewer', 'wu_template_previewer', array( - 'domain' => str_replace('www.', '', (string) $current_site->domain), - 'current_template' => wu_request($this->get_preview_parameter(), false), - 'current_url' => wu_get_current_url(), - 'query_parameter' => $this->get_preview_parameter(), - )); + wp_localize_script( + 'wu-template-previewer', + 'wu_template_previewer', + array( + 'domain' => str_replace('www.', '', (string) $current_site->domain), + 'current_template' => wu_request($this->get_preview_parameter(), false), + 'current_url' => wu_get_current_url(), + 'query_parameter' => $this->get_preview_parameter(), + ) + ); wp_enqueue_script('wu-template-previewer'); wp_enqueue_style('wu-template-previewer', wu_get_asset('template-previewer.css', 'css'), array(), wu_get_version()); - wp_add_inline_style('wu-template-previewer', wu_get_template_contents('dynamic-styles/template-previewer', array( - 'bg_color' => $bg_color, - 'button_bg_color' => $button_bg_color, - ))); + wp_add_inline_style( + 'wu-template-previewer', + wu_get_template_contents( + 'dynamic-styles/template-previewer', + array( + 'bg_color' => $bg_color, + 'button_bg_color' => $button_bg_color, + ) + ) + ); wp_enqueue_style('dashicons'); - - } // end register_scripts; + } /** * Remove the unnecessary styles added by themes and other plugins. @@ -165,8 +168,7 @@ class Template_Previewer { 'wu-template-previewer', 'dashicons', ); - - } // end remove_unnecessary_styles; + } /** * Append preview parameter. @@ -189,20 +191,15 @@ class Template_Previewer { ); if (in_array($orig_scheme, $allowed_schemes, true) === false) { - return $url; - - } // end if; + } if (apply_filters('wu_append_preview_parameter', true, $this) === false) { - return $url; - - } // end if; + } return add_query_arg('wu-preview', 1, $url); - - } // end append_preview_parameter; + } /** * Returns the preview URL for the template previewer. @@ -219,14 +216,11 @@ class Template_Previewer { ); if (wu_request('open')) { - $args['open'] = 1; - - } // end if; + } return add_query_arg($args, home_url()); - - } // end get_preview_url; + } /** * Template Previewer code @@ -245,11 +239,9 @@ class Template_Previewer { /** * Check if this is a site template */ - if (!$selected_template || ($selected_template->get_type() !== Site_Type::SITE_TEMPLATE && !wu_request('customizer'))) { - + if ( ! $selected_template || ($selected_template->get_type() !== Site_Type::SITE_TEMPLATE && ! wu_request('customizer'))) { wp_die(__('This template is not available', 'wp-ultimo')); - - } // end if; + } $categories = array(); @@ -262,15 +254,14 @@ class Template_Previewer { 'tp' => $this, ); - $products_ids = isset($_COOKIE['wu_selected_products']) ? explode( ',', (string) $_COOKIE['wu_selected_products']) : array(); + $products_ids = isset($_COOKIE['wu_selected_products']) ? explode(',', (string) $_COOKIE['wu_selected_products']) : array(); $products = array_map('wu_get_product', $products_ids); // clear array $products = array_filter($products); - if (!empty($products)) { - + if ( ! empty($products)) { $limits = new \WP_Ultimo\Objects\Limitations(); list($plan, $additional_products) = wu_segregate_products($products); @@ -278,13 +269,10 @@ class Template_Previewer { $products = array_merge(array($plan), $additional_products); foreach ($products as $product) { - $limits = $limits->merge($product->get_limitations()); - - } // end foreach; + } if ($limits->site_templates->get_mode() !== 'default') { - $site_ids = $limits->site_templates->get_available_site_templates(); $render_parameters['templates'] = array_map('wu_get_site', $site_ids); @@ -293,8 +281,7 @@ class Template_Previewer { * Check if the current site is a member of * the list of available templates */ - if (!in_array($selected_template->get_id(), $site_ids, true)) { - + if ( ! in_array($selected_template->get_id(), $site_ids, true)) { $redirect_to = wu_get_current_url(); $redirect_to = add_query_arg($this->get_preview_parameter(), current($site_ids), $redirect_to); @@ -302,18 +289,13 @@ class Template_Previewer { wp_redirect($redirect_to); exit; + } + } + } - } // end if; - - } // end if; - - } // end if; - - if (!isset($render_parameters['templates'])) { - + if ( ! isset($render_parameters['templates'])) { $render_parameters['templates'] = wu_get_site_templates(); - - } // end if; + } $render_parameters['templates'] = array_filter((array) $render_parameters['templates'], fn($site) => $site->is_active()); @@ -322,8 +304,7 @@ class Template_Previewer { wu_get_template('ui/template-previewer', $render_parameters); exit; - - } // end template_previewer; + } /** * Returns the preview parameter, so admins can change it. @@ -336,8 +317,7 @@ class Template_Previewer { $slug = $this->get_setting('preview_url_parameter', 'template-preview'); return apply_filters('wu_get_template_preview_slug', $slug); - - } // end get_preview_parameter; + } /** * Checks if this is a template previewer window. @@ -350,8 +330,7 @@ class Template_Previewer { $slug = $this->get_preview_parameter(); return wu_request($slug); - - } // end is_template_previewer; + } /** * Check if the frame is a preview. @@ -361,9 +340,8 @@ class Template_Previewer { */ public function is_preview() { - return !empty(wu_request('wu-preview')); - - } // end is_preview; + return ! empty(wu_request('wu-preview')); + } /** * Returns the settings. @@ -375,7 +353,7 @@ class Template_Previewer { // Fix to issue on wp_get_attachment_url() inside core. // @todo report it. - $initial_pagenow = $GLOBALS['pagenow'] ?? ''; + $initial_pagenow = $GLOBALS['pagenow'] ?? ''; $GLOBALS['pagenow'] = ''; $default_settings = array( @@ -390,7 +368,7 @@ class Template_Previewer { 'enabled' => true, ); - $saved_settings = wu_get_option(Template_Previewer::KEY, array()); + $saved_settings = wu_get_option(self::KEY, array()); $default_settings = array_merge($default_settings, $saved_settings); @@ -398,10 +376,8 @@ class Template_Previewer { // Ensure that templates key does not change with request if (isset($server_request['templates'])) { - unset($server_request['templates']); - - } // end if; + } $parsed_args = wp_parse_args($server_request, $default_settings); @@ -410,8 +386,7 @@ class Template_Previewer { $GLOBALS['pagenow'] = $initial_pagenow; return $parsed_args; - - } // end get_settings; + } /** * Gets a particular setting. @@ -425,8 +400,7 @@ class Template_Previewer { public function get_setting($setting, $default = false) { return wu_get_isset($this->get_settings(), $setting, $default); - - } // end get_setting; + } /** * Save settings. @@ -441,21 +415,15 @@ class Template_Previewer { $settings = $this->get_settings(); foreach ($settings as $setting => $value) { - if ($setting === 'logo_url') { - $settings['logo_url'] = wu_get_network_logo(); continue; + } - } // end if; + $settings[ $setting ] = wu_get_isset($settings_to_save, $setting, false); + } - $settings[$setting] = wu_get_isset($settings_to_save, $setting, false); - - } // end foreach; - - return wu_save_option(Template_Previewer::KEY, $settings); - - } // end save_settings; - -} // end class Template_Previewer; + return wu_save_option(self::KEY, $settings); + } +} diff --git a/inc/ui/class-template-switching-element.php b/inc/ui/class-template-switching-element.php index 8eb0548..2c53699 100644 --- a/inc/ui/class-template-switching-element.php +++ b/inc/ui/class-template-switching-element.php @@ -9,8 +9,8 @@ namespace WP_Ultimo\UI; -use \WP_Ultimo\UI\Base_Element; -use \WP_Ultimo\Managers\Field_Templates_Manager; +use WP_Ultimo\UI\Base_Element; +use WP_Ultimo\Managers\Field_Templates_Manager; // Exit if accessed directly defined('ABSPATH') || exit; @@ -59,23 +59,20 @@ class Template_Switching_Element extends Base_Element { protected $products; /** - * The icon of the UI element. - * e.g. return fa fa-search - * - * @since 2.0.0 - * @param string $context One of the values: block, elementor or bb. - */ + * The icon of the UI element. + * e.g. return fa fa-search + * + * @since 2.0.0 + * @param string $context One of the values: block, elementor or bb. + */ public function get_icon($context = 'block'): string { if ($context === 'elementor') { - return 'eicon-cart-medium'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * The title of the UI element. @@ -86,8 +83,7 @@ class Template_Switching_Element extends Base_Element { public function get_title() { return __('Template Switching', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -98,8 +94,7 @@ class Template_Switching_Element extends Base_Element { public function get_description() { return __('Adds the template switching form to this page.', 'wp-ultimo'); - - } // end get_description; + } /** * Initializes the singleton. @@ -112,8 +107,7 @@ class Template_Switching_Element extends Base_Element { add_action('wu_ajax_wu_switch_template', array($this, 'switch_template')); parent::init(); - - } // end init; + } /** * Register element scripts. @@ -126,13 +120,16 @@ class Template_Switching_Element extends Base_Element { wp_register_script('wu-template-switching', wu_get_asset('template-switching.js', 'js'), array('jquery', 'wu-vue-apps', 'wu-selectizer', 'wp-hooks', 'wu-cookie-helpers')); - wp_localize_script('wu-template-switching', 'wu_template_switching_params', array( - 'ajaxurl' => wu_ajax_url(), - )); + wp_localize_script( + 'wu-template-switching', + 'wu_template_switching_params', + array( + 'ajaxurl' => wu_ajax_url(), + ) + ); wp_enqueue_script('wu-template-switching'); - - } // end register_scripts; + } /** * The list of fields to be added to Gutenberg. @@ -177,8 +174,7 @@ class Template_Switching_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * The list of keywords for this element. @@ -195,8 +191,7 @@ class Template_Switching_Element extends Base_Element { 'Template', 'Template Switching', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -206,17 +201,18 @@ class Template_Switching_Element extends Base_Element { */ public function defaults() { - $site_template_ids = wu_get_site_templates(array( - 'fields' => 'ids', - )); + $site_template_ids = wu_get_site_templates( + array( + 'fields' => 'ids', + ) + ); return array( 'slug' => 'template-switching', 'template_selection_template' => 'clean', 'template_selection_sites' => implode(',', $site_template_ids), ); - - } // end defaults; + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -228,13 +224,11 @@ class Template_Switching_Element extends Base_Element { $this->site = wu_get_current_site(); - if (!$this->site || !$this->site->is_customer_allowed()) { - + if ( ! $this->site || ! $this->site->is_customer_allowed()) { $this->set_display(false); return; - - } // end if; + } $this->membership = $this->site->get_membership(); @@ -243,22 +237,15 @@ class Template_Switching_Element extends Base_Element { $all_membership_products = array(); if ($this->membership) { - $all_membership_products = $this->membership->get_all_products(); if (is_array($all_membership_products) && $all_membership_products) { - foreach ($all_membership_products as $product) { - $this->products[] = $product['product']->get_id(); - - } // end foreach; - - } // end if; - - } // end if; - - } // end setup; + } + } + } + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -270,8 +257,7 @@ class Template_Switching_Element extends Base_Element { public function setup_preview() { $this->site = wu_mock_site(); - - } // end setup_preview; + } /** * Ajax action to change the template for a given site. @@ -282,19 +268,15 @@ class Template_Switching_Element extends Base_Element { */ public function switch_template() { - if (!$this->site) { - + if ( ! $this->site) { $this->site = wu_get_current_site(); - - } // end if; + } $template_id = wu_request('template_id', ''); - if (!$template_id) { - + if ( ! $template_id) { return new \WP_Error('template_id_required', __('You need to provide a valid template to duplicate.', 'wp-ultimo')); - - } // end if; + } $switch = \WP_Ultimo\Helpers\Site_Duplicator::override_site($template_id, $this->site->get_id()); @@ -308,16 +290,18 @@ class Template_Switching_Element extends Base_Element { do_action('wu_after_switch_template', $this->site->get_id()); if ($switch) { - - wp_send_json_success(array( - 'redirect_url' => add_query_arg(array( - 'updated' => 1, - ), $_SERVER['HTTP_REFERER']), - )); - - } // end if; - - } // end switch_template; + wp_send_json_success( + array( + 'redirect_url' => add_query_arg( + array( + 'updated' => 1, + ), + $_SERVER['HTTP_REFERER'] + ), + ) + ); + } + } /** * The content to be output on the screen. @@ -335,18 +319,15 @@ class Template_Switching_Element extends Base_Element { public function output($atts, $content = null) { if ($this->site) { - $filter_template_limits = new \WP_Ultimo\Limits\Site_Template_Limits(); $atts['products'] = $this->products; $template_selection_field = $filter_template_limits->maybe_filter_template_selection_options($atts); - if (!isset($template_selection_field['sites'])) { - + if ( ! isset($template_selection_field['sites'])) { $template_selection_field['sites'] = array(); - - } // end if; + } $atts['template_selection_sites'] = implode(',', $template_selection_field['sites']); @@ -400,7 +381,7 @@ class Template_Switching_Element extends Base_Element { 'wrapper_classes' => '', 'value' => 0, 'html_attr' => array( - 'v-model' => 'confirm_switch' + 'v-model' => 'confirm_switch', ), 'wrapper_html_attr' => array( 'v-show' => 'template_id != 0 && template_id != original_template_id', @@ -416,7 +397,7 @@ class Template_Switching_Element extends Base_Element { 'wrapper_html_attr' => array( 'v-cloak' => 1, 'v-show' => 'confirm_switch', - 'v-on:click.prevent' => 'ready = true' + 'v-on:click.prevent' => 'ready = true', ), ); @@ -430,23 +411,25 @@ class Template_Switching_Element extends Base_Element { $section_slug = 'wu-template-switching-form'; - $form = new Form($section_slug, $checkout_fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-striped wu-widget-inset', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-py-5 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid' - )); + $form = new Form( + $section_slug, + $checkout_fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-striped wu-widget-inset', + 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-py-5 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', + ) + ); ob_start(); $form->render(); return ob_get_clean(); - - } // end if; + } return ''; - - } // end output; + } /** * Returns the list of available pricing table templates. @@ -459,7 +442,5 @@ class Template_Switching_Element extends Base_Element { $available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('template_selection'); return $available_templates; - - } // end get_template_selection_templates; - -} // end class Template_Switching_Element; + } +} diff --git a/inc/ui/class-thank-you-element.php b/inc/ui/class-thank-you-element.php index b88e1ec..101748f 100644 --- a/inc/ui/class-thank-you-element.php +++ b/inc/ui/class-thank-you-element.php @@ -63,23 +63,20 @@ class Thank_You_Element extends Base_Element { protected $customer; /** - * The icon of the UI element. - * e.g. return fa fa-search - * - * @since 2.0.0 - * @param string $context One of the values: block, elementor or bb. - */ + * The icon of the UI element. + * e.g. return fa fa-search + * + * @since 2.0.0 + * @param string $context One of the values: block, elementor or bb. + */ public function get_icon($context = 'block'): string { if ($context === 'elementor') { - return 'eicon-info-circle-o'; - - } // end if; + } return 'fa fa-search'; - - } // end get_icon; + } /** * Overload the init to add site-related forms. @@ -90,8 +87,7 @@ class Thank_You_Element extends Base_Element { public function init() { parent::init(); - - } // end init; + } /** * Replace the register page title with the Thank you title. @@ -106,8 +102,7 @@ class Thank_You_Element extends Base_Element { $title_parts['title'] = $this->get_title(); return $title_parts; - - } // end replace_page_title; + } /** * Maybe clear the title at the content level. @@ -123,14 +118,11 @@ class Thank_You_Element extends Base_Element { global $post; if ($post && $post->ID === $id) { - return ''; - - } // end if; + } return $title; - - } // end maybe_replace_page_title; + } /** * Register additional scripts for the thank you page. @@ -145,22 +137,25 @@ class Thank_You_Element extends Base_Element { wp_register_script('wu-thank-you', wu_get_asset('thank-you.js', 'js'), array(), wu_get_version()); - wp_localize_script('wu-thank-you', 'wu_thank_you', array( - 'creating' => $is_publishing, - 'has_pending_site' => $has_pending_site, - 'next_queue' => wu_get_next_queue_run(), - 'ajaxurl' => admin_url('admin-ajax.php'), - 'resend_verification_email_nonce' => wp_create_nonce('wu_resend_verification_email_nonce'), - 'membership_hash' => $this->membership ? $this->membership->get_hash() : false, - 'i18n' => array( - 'resending_verification_email' => __('Resending verification email...', 'wp-ultimo'), - 'email_sent' => __('Verification email sent!', 'wp-ultimo'), - ), - )); + wp_localize_script( + 'wu-thank-you', + 'wu_thank_you', + array( + 'creating' => $is_publishing, + 'has_pending_site' => $has_pending_site, + 'next_queue' => wu_get_next_queue_run(), + 'ajaxurl' => admin_url('admin-ajax.php'), + 'resend_verification_email_nonce' => wp_create_nonce('wu_resend_verification_email_nonce'), + 'membership_hash' => $this->membership ? $this->membership->get_hash() : false, + 'i18n' => array( + 'resending_verification_email' => __('Resending verification email...', 'wp-ultimo'), + 'email_sent' => __('Verification email sent!', 'wp-ultimo'), + ), + ) + ); wp_enqueue_script('wu-thank-you'); - - } // end register_scripts; + } /** * The title of the UI element. @@ -175,8 +170,7 @@ class Thank_You_Element extends Base_Element { public function get_title() { return __('Thank You', 'wp-ultimo'); - - } // end get_title; + } /** * The description of the UI element. @@ -192,8 +186,7 @@ class Thank_You_Element extends Base_Element { public function get_description() { return __('Adds a checkout form block to the page.', 'wp-ultimo'); - - } // end get_description; + } /** * The list of fields to be added to Gutenberg. @@ -272,8 +265,7 @@ class Thank_You_Element extends Base_Element { ); return $fields; - - } // end fields; + } /** * The list of keywords for this element. @@ -301,8 +293,7 @@ class Thank_You_Element extends Base_Element { 'Form', 'Cart', ); - - } // end keywords; + } /** * List of default parameters for the element. @@ -327,8 +318,7 @@ class Thank_You_Element extends Base_Element { 'thank_you_message_pending' => __('Thank you for your order! We are waiting on the payment processor to confirm your payment, which can take up to 5 minutes. We will notify you via email when your site is ready.', 'wp-ultimo'), 'no_sites_message' => __('No sites found', 'wp-ultimo'), ); - - } // end defaults; + } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. @@ -340,31 +330,26 @@ class Thank_You_Element extends Base_Element { $this->payment = wu_get_payment_by_hash(wu_request('payment')); - if (!$this->payment) { - + if ( ! $this->payment) { $this->set_display(false); return; - - } // end if; + } $this->membership = $this->payment->get_membership(); - if (!$this->membership || !$this->membership->is_customer_allowed()) { - + if ( ! $this->membership || ! $this->membership->is_customer_allowed()) { $this->set_display(false); return; - - } // end if; + } $this->customer = $this->membership->get_customer(); add_filter('document_title_parts', array($this, 'replace_page_title')); add_filter('the_title', array($this, 'maybe_replace_page_title'), 10, 2); - - } // end setup; + } /** * Allows the setup in the context of previews. @@ -379,8 +364,7 @@ class Thank_You_Element extends Base_Element { $this->membership = wu_mock_membership(); $this->customer = wu_mock_customer(); - - } // end setup_preview; + } /** * The content to be output on the screen. @@ -410,45 +394,42 @@ class Thank_You_Element extends Base_Element { */ $conversion_snippets = $atts['checkout_form']->get_conversion_snippets(); - if (!empty($conversion_snippets)) { - + if ( ! empty($conversion_snippets)) { $product_ids = array(); foreach ($this->payment->get_line_items() as $line_item) { - if ($line_item->get_product_id()) { - $product_ids[] = (string) $line_item->get_product_id(); + } + } - } // end if; - - } // end foreach; - - $conversion_placeholders = apply_filters( 'wu_conversion_placeholders', array( - 'CUSTOMER_ID' => $this->customer->get_id(), - 'CUSTOMER_EMAIL' => $this->customer->get_email_address(), - 'MEMBERSHIP_DURATION' => $this->membership->get_recurring_description(), - 'MEMBERSHIP_PLAN' => $this->membership->get_plan_id(), - 'MEMBERSHIP_AMOUNT' => $this->membership->get_amount(), - 'ORDER_ID' => $this->payment->get_hash(), - 'ORDER_CURRENCY' => $this->payment->get_currency(), - 'ORDER_PRODUCTS' => array_values($product_ids), - 'ORDER_AMOUNT' => $this->payment->get_total(), - )); + $conversion_placeholders = apply_filters( + 'wu_conversion_placeholders', + array( + 'CUSTOMER_ID' => $this->customer->get_id(), + 'CUSTOMER_EMAIL' => $this->customer->get_email_address(), + 'MEMBERSHIP_DURATION' => $this->membership->get_recurring_description(), + 'MEMBERSHIP_PLAN' => $this->membership->get_plan_id(), + 'MEMBERSHIP_AMOUNT' => $this->membership->get_amount(), + 'ORDER_ID' => $this->payment->get_hash(), + 'ORDER_CURRENCY' => $this->payment->get_currency(), + 'ORDER_PRODUCTS' => array_values($product_ids), + 'ORDER_AMOUNT' => $this->payment->get_total(), + ) + ); foreach ($conversion_placeholders as $placeholder => $value) { - $conversion_snippets = preg_replace('/\%\%\s?' . $placeholder . '\s?\%\%/', json_encode($value), (string) $conversion_snippets); + } - } // end foreach; + add_action( + 'wp_print_footer_scripts', + function () use ($conversion_snippets) { - add_action('wp_print_footer_scripts', function() use ($conversion_snippets) { - - echo $conversion_snippets; - - }); - - } // end if; + echo $conversion_snippets; + } + ); + } /* * Account for the 'className' Gutenberg attribute. @@ -456,7 +437,5 @@ class Thank_You_Element extends Base_Element { $atts['className'] = trim('wu-' . $this->id . ' ' . wu_get_isset($atts, 'className', '')); return wu_get_template_contents('dashboard-widgets/thank-you', $atts); - - } // end output; - -} // end class Thank_You_Element; + } +} diff --git a/inc/ui/class-toolbox.php b/inc/ui/class-toolbox.php index 252dfc1..450afc6 100644 --- a/inc/ui/class-toolbox.php +++ b/inc/ui/class-toolbox.php @@ -29,8 +29,7 @@ class Toolbox { public function __construct() { add_action('init', array($this, 'load_toolbox')); - - } // end __construct; + } /** * Checks if we should add the toolbox or not. @@ -42,17 +41,14 @@ class Toolbox { $can_see_toolbox = current_user_can('manage_network'); - if (class_exists('\user_switching') && !$can_see_toolbox) { - + if (class_exists('\user_switching') && ! $can_see_toolbox) { $old_user = \user_switching::get_old_user(); $can_see_toolbox = user_can($old_user, 'manage_network'); + } - } // end if; - - return apply_filters('wu_is_toolbox_enabled', wu_get_setting('enable_jumper', true) && $can_see_toolbox && !is_network_admin()); - - } // end is_toolbox_enabled; + return apply_filters('wu_is_toolbox_enabled', wu_get_setting('enable_jumper', true) && $can_see_toolbox && ! is_network_admin()); + } /** * Loads the necessary elements to display the Toolbox. @@ -63,16 +59,13 @@ class Toolbox { public function load_toolbox() { if ($this->is_toolbox_enabled()) { - add_action('wp_footer', array($this, 'output')); add_action('admin_footer', array($this, 'output')); add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); - - } // end if; - - } // end load_toolbox; + } + } /** * Adds the admin styles to make sure the tooltip renders. @@ -83,8 +76,7 @@ class Toolbox { public function enqueue_styles() { wp_enqueue_style('wu-admin'); - - } // end enqueue_styles; + } /** * Outputs the actual HTML markup of the Toolbox. @@ -96,13 +88,14 @@ class Toolbox { $current_site = wu_get_current_site(); - wu_get_template('ui/toolbox', array( - 'toolbox' => $this, - 'current_site' => $current_site, - 'customer' => $current_site ? $current_site->get_customer() : false, - 'membership' => $current_site ? $current_site->get_membership() : false, - )); - - } // end output; - -} // end class Toolbox; + wu_get_template( + 'ui/toolbox', + array( + 'toolbox' => $this, + 'current_site' => $current_site, + 'customer' => $current_site ? $current_site->get_customer() : false, + 'membership' => $current_site ? $current_site->get_membership() : false, + ) + ); + } +} diff --git a/inc/ui/class-tours.php b/inc/ui/class-tours.php index 9a45a0d..2bf067a 100644 --- a/inc/ui/class-tours.php +++ b/inc/ui/class-tours.php @@ -41,8 +41,7 @@ class Tours { add_action('admin_enqueue_scripts', array($this, 'register_scripts')); add_action('in_admin_footer', array($this, 'enqueue_scripts')); - - } // end __construct; + } /** * Mark the tour as finished for a particular user. @@ -57,16 +56,13 @@ class Tours { $id = wu_request('tour_id'); if ($id) { - set_user_setting("wu_tour_$id", true); wp_send_json_success(); - - } // end if; + } wp_send_json_error(); - - } // end mark_as_finished; + } /** * Register the necessary scripts. @@ -79,8 +75,7 @@ class Tours { WP_Ultimo()->scripts->register_script('wu-shepherd', wu_get_asset('lib/shepherd.js', 'js'), array()); WP_Ultimo()->scripts->register_script('wu-tours', wu_get_asset('tours.js', 'js'), array('wu-shepherd', 'underscore')); - - } // end register_scripts; + } /** * Enqueues the scripts, if we need to. @@ -91,23 +86,24 @@ class Tours { public function enqueue_scripts() { if ($this->has_tours()) { - wp_localize_script('wu-tours', 'wu_tours', $this->tours); - wp_localize_script('wu-tours', 'wu_tours_vars', array( - 'ajaxurl' => wu_ajax_url(), - 'nonce' => wp_create_nonce('wu_tour_finished'), - 'i18n' => array( - 'next' => __('Next', 'wp-ultimo'), - 'finish' => __('Close', 'wp-ultimo') - ), - )); + wp_localize_script( + 'wu-tours', + 'wu_tours_vars', + array( + 'ajaxurl' => wu_ajax_url(), + 'nonce' => wp_create_nonce('wu_tour_finished'), + 'i18n' => array( + 'next' => __('Next', 'wp-ultimo'), + 'finish' => __('Close', 'wp-ultimo'), + ), + ) + ); wp_enqueue_script('wu-tours'); - - } // end if; - - } // end enqueue_scripts; + } + } /** * Checks if we have registered tours. @@ -117,9 +113,8 @@ class Tours { */ public function has_tours() { - return !empty($this->tours); - - } // end has_tours; + return ! empty($this->tours); + } /** * Register a new tour. @@ -136,41 +131,33 @@ class Tours { public function create_tour($id, $steps = array(), $once = true) { if (did_action('in_admin_header')) { - return; + } - } // end if; + add_action( + 'in_admin_header', + function () use ($id, $steps, $once) { - add_action('in_admin_header', function() use ($id, $steps, $once) { + $force_hide = wu_get_setting('hide_tours', false); - $force_hide = wu_get_setting('hide_tours', false); + if ($force_hide) { + return; + } - if ($force_hide) { + $finished = (bool) get_user_setting("wu_tour_$id", false); - return; + $finished = apply_filters('wu_tour_finished', $finished, $id, get_current_user_id()); - } // end if; + if ( ! $finished || ! $once) { + foreach ($steps as &$step) { + $step['text'] = is_array($step['text']) ? implode('

    ', $step['text']) : $step['text']; - $finished = (bool) get_user_setting("wu_tour_$id", false); + $step['text'] = sprintf('

    %s

    ', $step['text']); + } - $finished = apply_filters('wu_tour_finished', $finished, $id, get_current_user_id()); - - if (!$finished || !$once) { - - foreach ($steps as &$step) { - - $step['text'] = is_array($step['text']) ? implode('

    ', $step['text']) : $step['text']; - - $step['text'] = sprintf('

    %s

    ', $step['text']); - - } // end foreach; - - $this->tours[$id] = $steps; - - } // end if; - - }); - - } // end create_tour; - -} // end class Tours; + $this->tours[ $id ] = $steps; + } + } + ); + } +} diff --git a/inc/updater/plugin-update-checker.php b/inc/updater/plugin-update-checker.php index 609acd3..4dff2eb 100644 --- a/inc/updater/plugin-update-checker.php +++ b/inc/updater/plugin-update-checker.php @@ -11,7 +11,7 @@ // Exit if accessed directly defined('ABSPATH') || exit; -if (!class_exists('PluginUpdateChecker_2_0')) { +if ( ! class_exists('PluginUpdateChecker_2_0')) { /** * Deprecated: PluginUpdateChecker_2_0 @@ -26,13 +26,12 @@ if (!class_exists('PluginUpdateChecker_2_0')) { * @deprecated 2.0.0 * @return void */ - public function enable_update_checker() {} // end enable_update_checker; + public function enable_update_checker() {} + } - } // end class PluginUpdateChecker_2_0; +} -} // end if; - -if (!class_exists('PucFactory')) { +if ( ! class_exists('PucFactory')) { /** * Deprecated: PucFactory @@ -47,8 +46,7 @@ if (!class_exists('PucFactory')) { * @deprecated 2.0.0 * @return void */ - public static function buildUpdateChecker() {} // end buildUpdateChecker; + public static function buildUpdateChecker() {} + } - } // end class PucFactory; - -} // end if; +} diff --git a/sunrise.php b/sunrise.php index 88cdeb1..74e4ce6 100644 --- a/sunrise.php +++ b/sunrise.php @@ -13,7 +13,7 @@ * * This tells WordPress that it should load our sunrise file before plugins get loaded and * the request is processed. We use this great power to handle domain mapping logic and more. - * + * * @since 2.0.0.5 Adds a network admin notice warning that sunrise is still active when Ultimo is deactivated. * @since 2.0.0.5 Change return statement to a continue statement to prevent an early exit from the file. * @@ -25,7 +25,7 @@ defined('ABSPATH') || exit; -define('WP_ULTIMO_SUNRISE_VERSION', '2.0.0.8'); +const WP_ULTIMO_SUNRISE_VERSION = '2.0.0.8'; $wu_sunrise = defined('WP_PLUGIN_DIR') ? WP_PLUGIN_DIR . '/wp-multisite-waas/inc/class-sunrise.php' @@ -38,49 +38,40 @@ $wu_mu_sunrise = defined('WPMU_PLUGIN_DIR') /** * We search for the sunrise class file * in the plugins and mu-plugins folders. - * + * * @since 2.0.0.3 Sunrise Version. */ -$possible_sunrises = array( - $wu_sunrise, - $wu_mu_sunrise, -); -foreach ($possible_sunrises as $sunrise) { +foreach (array($wu_sunrise, $wu_mu_sunrise) as $wu_sunrise_file) { + if (file_exists($wu_sunrise_file)) { + if ($wu_sunrise_file === $wu_mu_sunrise) { - if (file_exists($sunrise)) { - - if ($sunrise === $wu_mu_sunrise) { - - /** - * Use a particular function that is defined - * after mu-plugins are loaded but before regular plugins - * to check if we are being loaded in a must-use context. - */ + /** + * Use a particular function that is defined + * after mu-plugins are loaded but before regular plugins + * to check if we are being loaded in a must-use context. + */ define('WP_ULTIMO_IS_MUST_USE', true); + } - } // end if; - - require_once $sunrise; + require_once $wu_sunrise_file; + + define('WP_ULTIMO_SUNRISE_FILE', $wu_sunrise_file); - define('WP_ULTIMO_SUNRISE_FILE', $sunrise); - WP_Ultimo\Sunrise::init(); add_action('network_admin_notices', 'wu_remove_sunrise_warning', 0); break; // Exit the loop. - - } // end if; - -} // end if; - + } +} +unset($wu_sunrise_file); /** * Include Mercator. - * + * * This is here purely for backwards compatibility reasons. * The file included here is a dumb file in version 2.0.7+. - * + * * @since 2.0.7 */ $wu_mercator = defined('WP_PLUGIN_DIR') @@ -88,10 +79,8 @@ $wu_mercator = defined('WP_PLUGIN_DIR') : WP_CONTENT_DIR . '/plugins/wp-multisite-waas/inc/mercator/mercator.php'; if (file_exists($wu_mercator)) { - require $wu_mercator; - -} // end if; +} /** * Adds a warning when WP Multisite WaaS is not present but the sunrise file is. @@ -99,22 +88,19 @@ if (file_exists($wu_mercator)) { * @since 2.0.0 * @return void */ -function wu_remove_sunrise_warning() { - +function wu_remove_sunrise_warning() { + if (function_exists('WP_Ultimo') === false) { - ?> - + ?>

    WP Multisite WaaS is deactivated, yet its sunrise.php file is still being loaded. If you have no intentions of continuing to use WP Multisite WaaS and this was not a temporary deactivation, we recommend removing the define('SUNRISE', true); line from your wp-config.php file. Keeping WP Multisite WaaS sunrise.php file active without WP Multisite WaaS can lead to unexpected behaviors and it is not advised.

    - getMockBuilder( Dashboard_Admin_Page::class ) - ->disableOriginalConstructor() - ->setMethods( [ 'output' ] ) - ->getMock(); + $dashboard_admin_page = $this->getMockBuilder(Dashboard_Admin_Page::class) + ->disableOriginalConstructor() + ->setMethods(array('output')) + ->getMock(); // Fake dates for testing $dashboard_admin_page->start_date = '2023-01-01'; @@ -24,22 +24,21 @@ class Dashboard_Admin_Page_Test extends WP_UnitTestCase { $dashboard_admin_page->register_scripts(); // Assert scripts are registered - $this->assertTrue( wp_script_is( 'wu-apex-charts', 'registered' ) ); - $this->assertTrue( wp_script_is( 'wu-vue-apex-charts', 'registered' ) ); - $this->assertTrue( wp_script_is( 'wu-dashboard-stats', 'registered' ) ); + $this->assertTrue(wp_script_is('wu-apex-charts', 'registered')); + $this->assertTrue(wp_script_is('wu-vue-apex-charts', 'registered')); + $this->assertTrue(wp_script_is('wu-dashboard-stats', 'registered')); // Assert styles are registered - $this->assertTrue( wp_style_is( 'wu-apex-charts', 'registered' ) ); + $this->assertTrue(wp_style_is('wu-apex-charts', 'registered')); // Assert scripts are enqueued - $this->assertTrue( wp_script_is( 'wu-dashboard-stats', 'enqueued' ) ); + $this->assertTrue(wp_script_is('wu-dashboard-stats', 'enqueued')); // Verify localized script data is correct - $localized_vars = wp_scripts()->get_data( 'wu-dashboard-stats', 'data' ); - echo( $localized_vars ); - $this->assertStringContainsString( '"month_list":["Jan ', $localized_vars ); - $this->assertStringContainsString( '"today":"', $localized_vars ); // Check that today is included - $this->assertStringContainsString( '"new_mrr":"New MRR"', $localized_vars ); + $localized_vars = wp_scripts()->get_data('wu-dashboard-stats', 'data'); + echo($localized_vars); + $this->assertStringContainsString('"month_list":["Jan ', $localized_vars); + $this->assertStringContainsString('"today":"', $localized_vars); // Check that today is included + $this->assertStringContainsString('"new_mrr":"New MRR"', $localized_vars); } - -} \ No newline at end of file +} diff --git a/tests/Admin_Pages/Membership_Edit_Admin_Page_Test.php b/tests/Admin_Pages/Membership_Edit_Admin_Page_Test.php index 2fb1108..0caaf43 100644 --- a/tests/Admin_Pages/Membership_Edit_Admin_Page_Test.php +++ b/tests/Admin_Pages/Membership_Edit_Admin_Page_Test.php @@ -30,11 +30,11 @@ class Membership_Edit_Admin_Page_Test extends WP_UnitTestCase { parent::setUp(); $faker = new Faker(); $faker->generate_fake_memberships(); - $this->swap_time = strtotime( '+100 days' ); + $this->swap_time = strtotime('+100 days'); - $this->membership = current( $faker->get_fake_data_generated( 'memberships' ) ); - $cart = new Cart( array() ); - $this->membership->schedule_swap( $cart, gmdate( 'Y-m-d H:i:s', $this->swap_time ) ); + $this->membership = current($faker->get_fake_data_generated('memberships')); + $cart = new Cart(array()); + $this->membership->schedule_swap($cart, gmdate('Y-m-d H:i:s', $this->swap_time)); // Mock Membership_Edit_Admin_Page with dependencies and methods. $this->membership_edit_admin_page = new Membership_Edit_Admin_Page(); } @@ -48,16 +48,16 @@ class Membership_Edit_Admin_Page_Test extends WP_UnitTestCase { $this->membership_edit_admin_page->page_loaded(); $membership = $this->membership_edit_admin_page->get_object(); - $this->assertInstanceOf( Membership::class, $membership ); - $this->assertEquals( $membership->get_id(), $this->membership->get_id() ); - $this->assertTrue( $this->membership_edit_admin_page->edit ); + $this->assertInstanceOf(Membership::class, $membership); + $this->assertEquals($membership->get_id(), $this->membership->get_id()); + $this->assertTrue($this->membership_edit_admin_page->edit); - $notices = \WP_Ultimo()->notices->get_notices( 'network-admin' ); - $this->assertNotEmpty( $notices ); - $notice = array_shift( $notices ); - $this->assertEquals( 'warning', $notice['type'] ); - $this->assertFalse( $notice['dismissible_key'] ); - $this->assertNotEmpty( $notice['actions'] ); - $this->assertStringContainsString( gmdate( get_option( 'date_format' ), $this->swap_time ), $notice['message'] ); + $notices = \WP_Ultimo()->notices->get_notices('network-admin'); + $this->assertNotEmpty($notices); + $notice = array_shift($notices); + $this->assertEquals('warning', $notice['type']); + $this->assertFalse($notice['dismissible_key']); + $this->assertNotEmpty($notice['actions']); + $this->assertStringContainsString(gmdate(get_option('date_format'), $this->swap_time), $notice['message']); } } diff --git a/tests/Gateway_Functions_Test.php b/tests/Gateway_Functions_Test.php index a348610..baacab9 100644 --- a/tests/Gateway_Functions_Test.php +++ b/tests/Gateway_Functions_Test.php @@ -8,19 +8,18 @@ use WP_Ultimo\Managers\Gateway_Manager; class Gateway_Functions_Test extends \WP_UnitTestCase { public function test_wu_get_gateway_returns_false_for_invalid_id() { - $invalid_gateway_id = 'non_existent_gateway'; + $invalid_gateway_id = 'non_existent_gateway'; - $result = wu_get_gateway($invalid_gateway_id); + $result = wu_get_gateway($invalid_gateway_id); - $this->assertFalse($result); + $this->assertFalse($result); } public function test_wu_get_gateway_returns_instance_for_valid_id() { - $valid_gateway_id = 'manual'; + $valid_gateway_id = 'manual'; - $gateway = wu_get_gateway($valid_gateway_id); + $gateway = wu_get_gateway($valid_gateway_id); - $this->assertInstanceOf(Manual_Gateway::class, $gateway); + $this->assertInstanceOf(Manual_Gateway::class, $gateway); } - } diff --git a/tests/WP_Ultimo/Date_Functions_Test.php b/tests/WP_Ultimo/Date_Functions_Test.php index dcdf0cd..4ca50cf 100644 --- a/tests/WP_Ultimo/Date_Functions_Test.php +++ b/tests/WP_Ultimo/Date_Functions_Test.php @@ -4,8 +4,8 @@ namespace WP_Ultimo; class Date_Functions_Test extends \WP_UnitTestCase { public function test_wu_get_days_ago() { - $days = wu_get_days_ago( '2024-01-01 00:00:00', '2024-01-31 00:00:00' ); + $days = wu_get_days_ago('2024-01-01 00:00:00', '2024-01-31 00:00:00'); - $this->assertEquals( -30, $days ); + $this->assertEquals(-30, $days); } } diff --git a/tests/WP_Ultimo/Models/Discount_Code_Test.php b/tests/WP_Ultimo/Models/Discount_Code_Test.php index c8a3eba..4c6bf93 100644 --- a/tests/WP_Ultimo/Models/Discount_Code_Test.php +++ b/tests/WP_Ultimo/Models/Discount_Code_Test.php @@ -12,11 +12,11 @@ class Discount_Code_Test extends WP_UnitTestCase { */ public function test_is_valid_active_discount_code() { $discount_code = new Discount_Code(); - $discount_code->set_active( true ); + $discount_code->set_active(true); $result = $discount_code->is_valid(); - $this->assertTrue( $result ); + $this->assertTrue($result); } /** @@ -24,13 +24,13 @@ class Discount_Code_Test extends WP_UnitTestCase { */ public function test_is_valid_inactive_discount_code() { $discount_code = new Discount_Code(); - $discount_code->set_active( false ); + $discount_code->set_active(false); $result = $discount_code->is_valid(); - $this->assertInstanceOf( WP_Error::class, $result ); - $this->assertEquals( 'discount_code', $result->get_error_code() ); - $this->assertEquals( 'This coupon code is not valid.', $result->get_error_message() ); + $this->assertInstanceOf(WP_Error::class, $result); + $this->assertEquals('discount_code', $result->get_error_code()); + $this->assertEquals('This coupon code is not valid.', $result->get_error_message()); } /** @@ -38,16 +38,18 @@ class Discount_Code_Test extends WP_UnitTestCase { */ public function test_is_valid_max_uses_exceeded() { $discount_code = new Discount_Code(); - $discount_code->set_active( true ); - $discount_code->set_max_uses( 5 ); - $discount_code->set_uses( 5 ); + $discount_code->set_active(true); + $discount_code->set_max_uses(5); + $discount_code->set_uses(5); $result = $discount_code->is_valid(); - $this->assertInstanceOf( WP_Error::class, $result ); - $this->assertEquals( 'discount_code', $result->get_error_code() ); - $this->assertEquals( 'This discount code was already redeemed the maximum amount of times allowed.', - $result->get_error_message() ); + $this->assertInstanceOf(WP_Error::class, $result); + $this->assertEquals('discount_code', $result->get_error_code()); + $this->assertEquals( + 'This discount code was already redeemed the maximum amount of times allowed.', + $result->get_error_message() + ); } /** @@ -55,14 +57,14 @@ class Discount_Code_Test extends WP_UnitTestCase { */ public function test_is_valid_before_start_date() { $discount_code = new Discount_Code(); - $discount_code->set_active( true ); - $discount_code->set_date_start( date( 'Y-m-d H:i:s', strtotime( '+1 day' ) ) ); + $discount_code->set_active(true); + $discount_code->set_date_start(date('Y-m-d H:i:s', strtotime('+1 day'))); $result = $discount_code->is_valid(); - $this->assertInstanceOf( WP_Error::class, $result ); - $this->assertEquals( 'discount_code', $result->get_error_code() ); - $this->assertEquals( 'This coupon code is not valid.', $result->get_error_message() ); + $this->assertInstanceOf(WP_Error::class, $result); + $this->assertEquals('discount_code', $result->get_error_code()); + $this->assertEquals('This coupon code is not valid.', $result->get_error_message()); } /** @@ -70,14 +72,14 @@ class Discount_Code_Test extends WP_UnitTestCase { */ public function test_is_valid_after_expiration_date() { $discount_code = new Discount_Code(); - $discount_code->set_active( true ); - $discount_code->set_date_expiration( date( 'Y-m-d H:i:s', strtotime( '-1 day' ) ) ); + $discount_code->set_active(true); + $discount_code->set_date_expiration(date('Y-m-d H:i:s', strtotime('-1 day'))); $result = $discount_code->is_valid(); - $this->assertInstanceOf( WP_Error::class, $result ); - $this->assertEquals( 'discount_code', $result->get_error_code() ); - $this->assertEquals( 'This coupon code is not valid.', $result->get_error_message() ); + $this->assertInstanceOf(WP_Error::class, $result); + $this->assertEquals('discount_code', $result->get_error_code()); + $this->assertEquals('This coupon code is not valid.', $result->get_error_message()); } /** @@ -86,13 +88,13 @@ class Discount_Code_Test extends WP_UnitTestCase { public function test_is_valid_for_allowed_product() { $product_id = 123; $discount_code = new Discount_Code(); - $discount_code->set_active( true ); - $discount_code->set_limit_products( true ); - $discount_code->set_allowed_products( [ $product_id ] ); + $discount_code->set_active(true); + $discount_code->set_limit_products(true); + $discount_code->set_allowed_products(array($product_id)); - $result = $discount_code->is_valid( $product_id ); + $result = $discount_code->is_valid($product_id); - $this->assertTrue( $result ); + $this->assertTrue($result); } /** @@ -102,15 +104,15 @@ class Discount_Code_Test extends WP_UnitTestCase { $allowed_product_id = 123; $disallowed_product_id = 456; $discount_code = new Discount_Code(); - $discount_code->set_active( true ); - $discount_code->set_limit_products( true ); - $discount_code->set_allowed_products( [ $allowed_product_id ] ); + $discount_code->set_active(true); + $discount_code->set_limit_products(true); + $discount_code->set_allowed_products(array($allowed_product_id)); - $result = $discount_code->is_valid( $disallowed_product_id ); + $result = $discount_code->is_valid($disallowed_product_id); - $this->assertInstanceOf( WP_Error::class, $result ); - $this->assertEquals( 'discount_code', $result->get_error_code() ); - $this->assertEquals( 'This coupon code is not valid.', $result->get_error_message() ); + $this->assertInstanceOf(WP_Error::class, $result); + $this->assertEquals('discount_code', $result->get_error_code()); + $this->assertEquals('This coupon code is not valid.', $result->get_error_message()); } /** @@ -118,11 +120,11 @@ class Discount_Code_Test extends WP_UnitTestCase { */ public function test_is_valid_no_product_limits() { $discount_code = new Discount_Code(); - $discount_code->set_active( true ); - $discount_code->set_limit_products( false ); + $discount_code->set_active(true); + $discount_code->set_limit_products(false); $result = $discount_code->is_valid(); - $this->assertTrue( $result ); + $this->assertTrue($result); } -} \ No newline at end of file +} diff --git a/tests/WP_Ultimo/Models/Domain_Test.php b/tests/WP_Ultimo/Models/Domain_Test.php index 17be507..312fa9f 100644 --- a/tests/WP_Ultimo/Models/Domain_Test.php +++ b/tests/WP_Ultimo/Models/Domain_Test.php @@ -12,10 +12,10 @@ class Domain_Test extends WP_UnitTestCase { public function test_has_valid_ssl_certificate_with_valid_certificate() { // Mocking a domain with a valid SSL certificate. $domain = new Domain(); - $domain->set_domain( 'dogs.4thelols.uk' ); + $domain->set_domain('dogs.4thelols.uk'); // Assert that it returns true for a valid SSL certificate. - $this->assertTrue( $domain->has_valid_ssl_certificate() ); + $this->assertTrue($domain->has_valid_ssl_certificate()); } /** @@ -24,10 +24,10 @@ class Domain_Test extends WP_UnitTestCase { public function test_has_valid_ssl_certificate_with_invalid_certificate() { // Mocking a domain with an invalid SSL certificate. $domain = new Domain(); - $domain->set_domain( 'eeeeeeeeeeeeeeeeauauexample.com' ); + $domain->set_domain('eeeeeeeeeeeeeeeeauauexample.com'); // Assert that it returns false for an invalid SSL certificate. - $this->assertFalse( $domain->has_valid_ssl_certificate() ); + $this->assertFalse($domain->has_valid_ssl_certificate()); } /** @@ -36,9 +36,9 @@ class Domain_Test extends WP_UnitTestCase { public function test_has_valid_ssl_certificate_with_empty_domain() { // Mocking a domain with an empty value. $domain = new Domain(); - $domain->set_domain( '' ); + $domain->set_domain(''); // Assert that it returns false for an empty domain. - $this->assertFalse( $domain->has_valid_ssl_certificate() ); + $this->assertFalse($domain->has_valid_ssl_certificate()); } -} \ No newline at end of file +} diff --git a/tests/WP_Ultimo/Models/Membership_Test.php b/tests/WP_Ultimo/Models/Membership_Test.php index 03bb2a2..7ffcb42 100644 --- a/tests/WP_Ultimo/Models/Membership_Test.php +++ b/tests/WP_Ultimo/Models/Membership_Test.php @@ -26,7 +26,7 @@ class Membership_Test extends \WP_UnitTestCase { $this->membership = new Membership(); // Set a default customer ID. - $this->membership->set_customer_id( 123 ); + $this->membership->set_customer_id(123); } /** @@ -34,23 +34,23 @@ class Membership_Test extends \WP_UnitTestCase { */ public function test_is_customer_allowed() { // Admins with 'manage_network' capability should always return true. - $admin_user_id = $this->factory()->user->create( array( 'role' => 'administrator' ) ); - grant_super_admin( $admin_user_id ); - wp_set_current_user( $admin_user_id ); - $this->assertTrue( $this->membership->is_customer_allowed(), 'Failed asserting that admin is allowed.' ); + $admin_user_id = $this->factory()->user->create(array('role' => 'administrator')); + grant_super_admin($admin_user_id); + wp_set_current_user($admin_user_id); + $this->assertTrue($this->membership->is_customer_allowed(), 'Failed asserting that admin is allowed.'); // Regular customers are allowed if IDs match. $customer_id = 123; $this->assertTrue( - $this->membership->is_customer_allowed( $customer_id ), + $this->membership->is_customer_allowed($customer_id), 'Failed asserting that customer with matching ID is allowed.' ); // Regular customers are denied if IDs do not match. $wrong_customer_id = 456; - wp_set_current_user( $wrong_customer_id ); + wp_set_current_user($wrong_customer_id); $this->assertFalse( - $this->membership->is_customer_allowed( $wrong_customer_id ), + $this->membership->is_customer_allowed($wrong_customer_id), 'Failed asserting that customer with non-matching ID is denied.' ); } @@ -64,14 +64,14 @@ class Membership_Test extends \WP_UnitTestCase { $faker = new Faker(); $faker->generate_fake_products(); /** @var Product $product */ - $product = $faker->get_fake_data_generated( 'products' )[0]; + $product = $faker->get_fake_data_generated('products')[0]; $product_id = $product->get_id(); - $this->membership->add_product( $product_id, $quantity ); + $this->membership->add_product($product_id, $quantity); // Verify that the product is added with the correct quantity. $addon_products = $this->membership->get_addon_ids(); - $this->assertContains( $product_id, $addon_products, 'Failed asserting that product ID was added.' ); + $this->assertContains($product_id, $addon_products, 'Failed asserting that product ID was added.'); $this->assertEquals( $quantity, $this->membership->get_addon_products()[0]['quantity'], @@ -80,7 +80,7 @@ class Membership_Test extends \WP_UnitTestCase { // Add more of the same product and check the updated quantity. $additional_quantity = 3; - $this->membership->add_product( $product_id, $additional_quantity ); + $this->membership->add_product($product_id, $additional_quantity); $this->assertEquals( $quantity + $additional_quantity, @@ -98,14 +98,14 @@ class Membership_Test extends \WP_UnitTestCase { $faker = new Faker(); $faker->generate_fake_products(); /** @var Product $product */ - $product = $faker->get_fake_data_generated( 'products' )[0]; + $product = $faker->get_fake_data_generated('products')[0]; $product_id = $product->get_id(); - $this->membership->add_product( $product_id, $quantity ); + $this->membership->add_product($product_id, $quantity); // Remove some of the product's quantity. $remove_quantity = 3; - $this->membership->remove_product( $product_id, $remove_quantity ); + $this->membership->remove_product($product_id, $remove_quantity); // Verify the updated quantity. $this->assertEquals( @@ -115,18 +115,18 @@ class Membership_Test extends \WP_UnitTestCase { ); // Remove the remaining quantity and verify it is removed. - $this->membership->remove_product( $product_id, $quantity ); + $this->membership->remove_product($product_id, $quantity); $addon_products = $this->membership->get_addon_ids(); - $this->assertNotContains( $product_id, $addon_products, 'Failed asserting that the product was removed.' ); + $this->assertNotContains($product_id, $addon_products, 'Failed asserting that the product was removed.'); } /** * Test get_remaining_days_in_cycle() method. */ public function test_get_remaining_days_in_cycle() { - $this->membership->set_amount( 12.99 ); + $this->membership->set_amount(12.99); // Case 1: Non-recurring membership should return 10000. - $this->membership->set_recurring( false ); + $this->membership->set_recurring(false); $this->assertEquals( 10000, $this->membership->get_remaining_days_in_cycle(), @@ -134,8 +134,8 @@ class Membership_Test extends \WP_UnitTestCase { ); // Case 2: Invalid expiration date should return 0. - $this->membership->set_recurring( true ); - $this->membership->set_date_expiration( 'invalid-date' ); // Setting an invalid date. + $this->membership->set_recurring(true); + $this->membership->set_date_expiration('invalid-date'); // Setting an invalid date. $this->assertEquals( 0, $this->membership->get_remaining_days_in_cycle(), @@ -143,7 +143,7 @@ class Membership_Test extends \WP_UnitTestCase { ); // Case 3: No expiration date should return 0. - $this->membership->set_date_expiration( '' ); + $this->membership->set_date_expiration(''); $this->assertEquals( 0, $this->membership->get_remaining_days_in_cycle(), @@ -151,9 +151,9 @@ class Membership_Test extends \WP_UnitTestCase { ); // Case 4: Expiration date is in the future and remaining days are calculated properly. - $today = new \DateTime( 'now', new \DateTimeZone( 'UTC' ) ); - $today->add( new \DateInterval( 'P10D' ) ); - $this->membership->set_date_expiration( $today->format( 'Y-m-d H:i:s' ) ); + $today = new \DateTime('now', new \DateTimeZone('UTC')); + $today->add(new \DateInterval('P10D')); + $this->membership->set_date_expiration($today->format('Y-m-d H:i:s')); $remaining_days = $this->membership->get_remaining_days_in_cycle(); $this->assertEquals( 10, @@ -162,7 +162,7 @@ class Membership_Test extends \WP_UnitTestCase { ); // Case 5: Expiration date is in the past, should return 0. - $this->membership->set_date_expiration( date( 'Y-m-d H:i:s', strtotime( '-5 days' ) ) ); + $this->membership->set_date_expiration(date('Y-m-d H:i:s', strtotime('-5 days'))); $remaining_days = $this->membership->get_remaining_days_in_cycle(); $this->assertEquals( 0, diff --git a/tests/WP_Ultimo/Tax/Dashboard_Taxes_Tab_Test.php b/tests/WP_Ultimo/Tax/Dashboard_Taxes_Tab_Test.php index 0f031ca..5e53202 100644 --- a/tests/WP_Ultimo/Tax/Dashboard_Taxes_Tab_Test.php +++ b/tests/WP_Ultimo/Tax/Dashboard_Taxes_Tab_Test.php @@ -11,24 +11,24 @@ class Dashboard_Taxes_Tab_Test extends WP_UnitTestCase { */ public function test_register_scripts_registers_scripts() { // Create a mock instance of Dashboard_Admin_Page and call the register_scripts method. - $dashboard_admin_page = $this->getMockBuilder( Dashboard_Taxes_Tab::class ) + $dashboard_admin_page = $this->getMockBuilder(Dashboard_Taxes_Tab::class) ->disableOriginalConstructor() - ->setMethods( array( 'output' ) ) + ->setMethods(array('output')) ->getMock(); // Execute register_scripts method. $dashboard_admin_page->register_scripts(); // Assert scripts are registered. - $this->assertTrue( wp_script_is( 'wu-tax-stats', 'registered' ) ); + $this->assertTrue(wp_script_is('wu-tax-stats', 'registered')); // Assert scripts are enqueued. - $this->assertTrue( wp_script_is( 'wu-tax-stats', 'enqueued' ) ); + $this->assertTrue(wp_script_is('wu-tax-stats', 'enqueued')); // Verify localized script data is correct. - $localized_vars = wp_scripts()->get_data( 'wu-tax-stats', 'data' ); - $this->assertStringContainsString( '"month_list":["Jan ', $localized_vars ); - $this->assertStringContainsString( '"today":"', $localized_vars ); // Check that today is included. - $this->assertStringContainsString( '"net_profit_label":"Net Profit"', $localized_vars ); + $localized_vars = wp_scripts()->get_data('wu-tax-stats', 'data'); + $this->assertStringContainsString('"month_list":["Jan ', $localized_vars); + $this->assertStringContainsString('"today":"', $localized_vars); // Check that today is included. + $this->assertStringContainsString('"net_profit_label":"Net Profit"', $localized_vars); } } diff --git a/tests/WP_Ultimo_Test.php b/tests/WP_Ultimo_Test.php index 83020dc..505c210 100644 --- a/tests/WP_Ultimo_Test.php +++ b/tests/WP_Ultimo_Test.php @@ -2,22 +2,22 @@ namespace WP_Ultimo; class WP_Ultimo_Test extends \WP_UnitTestCase { - /** - * Test if all helper functions are loaded correctly. - * - * This test case creates an instance of the WP_Ultimo class and calls the load_public_apis method. - * It then asserts that the helper functions wu_to_float, wu_replace_dashes, and wu_get_initials are - * correctly loaded. Additional assertions can be added for other helper functions. - * - * @return void - */ - public function testLoadAllHelperFunctionsCorrectly() { - // Assert that all helper functions are loaded correctly. - // This is all done in the bootstrap. - $this->assertTrue(function_exists('wu_to_float')); - $this->assertTrue(function_exists('wu_replace_dashes')); - $this->assertTrue(function_exists('wu_get_initials')); - } + /** + * Test if all helper functions are loaded correctly. + * + * This test case creates an instance of the WP_Ultimo class and calls the load_public_apis method. + * It then asserts that the helper functions wu_to_float, wu_replace_dashes, and wu_get_initials are + * correctly loaded. Additional assertions can be added for other helper functions. + * + * @return void + */ + public function testLoadAllHelperFunctionsCorrectly() { + // Assert that all helper functions are loaded correctly. + // This is all done in the bootstrap. + $this->assertTrue(function_exists('wu_to_float')); + $this->assertTrue(function_exists('wu_replace_dashes')); + $this->assertTrue(function_exists('wu_get_initials')); + } public function testLoaded() { $wpUltimo = \WP_Ultimo(); @@ -27,8 +27,8 @@ class WP_Ultimo_Test extends \WP_UnitTestCase { public function testPublicProperties() { $wpUltimo = \WP_Ultimo(); - $this->assertTrue($wpUltimo->settings instanceof Settings); - $this->assertTrue($wpUltimo->helper instanceof Helper); + $this->assertTrue($wpUltimo->settings instanceof Settings); + $this->assertTrue($wpUltimo->helper instanceof Helper); $this->assertTrue($wpUltimo->notices instanceof Admin_Notices); $this->assertTrue($wpUltimo->scripts instanceof Scripts); $this->assertTrue($wpUltimo->currents instanceof Current); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5a63625..4d4578a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -5,21 +5,21 @@ * @package Wp_Multisite_Waas */ -$_tests_dir = getenv( 'WP_TESTS_DIR' ); +$_tests_dir = getenv('WP_TESTS_DIR'); require 'vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; if ( ! $_tests_dir ) { - $_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib'; + $_tests_dir = rtrim(sys_get_temp_dir(), '/\\') . '/wordpress-tests-lib'; } // Forward custom PHPUnit Polyfills configuration to PHPUnit bootstrap file. -$_phpunit_polyfills_path = getenv( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ); +$_phpunit_polyfills_path = getenv('WP_TESTS_PHPUNIT_POLYFILLS_PATH'); if ( false !== $_phpunit_polyfills_path ) { - define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', $_phpunit_polyfills_path ); + define('WP_TESTS_PHPUNIT_POLYFILLS_PATH', $_phpunit_polyfills_path); } -if ( ! file_exists( "{$_tests_dir}/includes/functions.php" ) ) { +if ( ! file_exists("{$_tests_dir}/includes/functions.php") ) { echo "Could not find {$_tests_dir}/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - exit( 1 ); + exit(1); } // Give access to tests_add_filter() function. @@ -29,10 +29,10 @@ require_once "{$_tests_dir}/includes/functions.php"; * Manually load the plugin being tested. */ function _manually_load_plugin() { - require dirname( dirname( __FILE__ ) ) . '/wp-multisite-waas.php'; + require dirname(__DIR__) . '/wp-multisite-waas.php'; } -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); +tests_add_filter('muplugins_loaded', '_manually_load_plugin'); // Start up the WP testing environment. require "{$_tests_dir}/includes/bootstrap.php"; diff --git a/uninstall.php b/uninstall.php index 0e8b6f9..b74d157 100644 --- a/uninstall.php +++ b/uninstall.php @@ -6,10 +6,8 @@ * @since 2.0.0 */ -if (!defined('WP_UNINSTALL_PLUGIN')) { - +if ( ! defined('WP_UNINSTALL_PLUGIN')) { exit; - } // end if; global $wpdb; @@ -30,7 +28,6 @@ $wu_settings_uninstall_wipe_tables = isset($wu_settings['uninstall_wipe_tables'] * Let's do it. */ if ($wu_settings_uninstall_wipe_tables) { - $wu_tables = array( 'customers', 'customermeta', @@ -46,13 +43,12 @@ if ($wu_settings_uninstall_wipe_tables) { 'posts', 'productmeta', 'products', - 'webhooks' + 'webhooks', ); $wu_prefix_table = "{$wpdb->prefix}wu_"; foreach ($wu_tables as $wu_table) { - $wu_table_name = $wu_prefix_table . $wu_table; $wu_table_version = "wpdb_wu_{$wu_table}_version"; @@ -60,7 +56,6 @@ if ($wu_settings_uninstall_wipe_tables) { $wpdb->query("DROP TABLE IF EXISTS $wu_table_name"); // phpcs:ignore delete_network_option(null, $wu_table_version); - } // end foreach; /* @@ -72,5 +67,4 @@ if ($wu_settings_uninstall_wipe_tables) { delete_network_option(null, 'wu_default_email_template'); delete_network_option(null, 'wu_default_system_emails_created'); delete_network_option(null, 'wu_default_invoice_template'); - } // end if; diff --git a/views/about.php b/views/about.php index 02dfde8..066a6b8 100644 --- a/views/about.php +++ b/views/about.php @@ -21,185 +21,199 @@ - +
    -
    +
    -

    - A new release strategy -

    +

    + A new release strategy +

    -

    - Here's Erasmo:
    - WP Ultimo version 2.3.0 -

    +

    + Here's Erasmo:
    + WP Ultimo version 2.3.0 +

    -

    - Hi guys! -

    +

    + Hi guys! +

    -

    - With WP Ultimo 2.3.0 we start a new streamlined approach of releases, focusing on a central feature in minors and rolling out fixes as soon as they are ready in patches. Less time waiting and leaner versions. -

    -

    - This way we intend to avoid a significant gap in time between updates and an extensive scope of changes and fixes, all bundled into one massive release. -

    -

    - This version focuses on allowing custom meta fields for customers in the admin area. This tool lets you collect additional information from your users. The potential for automation and WP Ultimo customizations is now expanded, as these fields may help tailor and streamline your operations. -

    -

    - We also added a bunch of improvements and fixes that go from more translated strings for Spanish, Brazilian Portuguese, and French, to better PHP 8.2 compatibility, to webhook triggering. -

    -
    - - Gilberto Gil -
    -

    - This version is called Erasmo in honor of the Brazilian singer and songwriter - - Erasmo Carlos - - , who left us in 2022, at the age of 81. -

    -

    - Erasmo was one of the faces of Jovem Guarda, a Brazilian musical TV show aired during the 1960’s. The show was highly influenced by American rock’n roll and the British Invasion of rock bands of that decade. -

    -

    - Erasmo's songs are about love, friendship, ecology, and many other subjects distributed along more than two dozen albums. Here, you can listen to one of his classic songs - Minha fama de mau. - If you’re feeling more romantic, go for this version of - Do fundo do meu coração, - with Adriana Calcanhoto. And don’t forget to check out this - awesome playlist. -

    -

    - As always, let me know if you have any questions. -

    -

    - Yours truly, -

    +

    + With WP Ultimo 2.3.0 we start a new streamlined approach of releases, focusing on a central feature in minors and rolling out fixes as soon as they are ready in patches. Less time waiting and leaner versions. +

    +

    + This way we intend to avoid a significant gap in time between updates and an extensive scope of changes and fixes, all bundled into one massive release. +

    +

    + This version focuses on allowing custom meta fields for customers in the admin area. This tool lets you collect additional information from your users. The potential for automation and WP Ultimo customizations is now expanded, as these fields may help tailor and streamline your operations. +

    +

    + We also added a bunch of improvements and fixes that go from more translated strings for Spanish, Brazilian Portuguese, and French, to better PHP 8.2 compatibility, to webhook triggering. +

    +
    + + Gilberto Gil +
    +

    + This version is called Erasmo in honor of the Brazilian singer and songwriter + + Erasmo Carlos + + , who left us in 2022, at the age of 81. +

    +

    + Erasmo was one of the faces of Jovem Guarda, a Brazilian musical TV show aired during the 1960’s. The show was highly influenced by American rock’n roll and the British Invasion of rock bands of that decade. +

    +

    + Erasmo's songs are about love, friendship, ecology, and many other subjects distributed along more than two dozen albums. Here, you can listen to one of his classic songs + Minha fama de mau. + If you’re feeling more romantic, go for this version of + Do fundo do meu coração, + with Adriana Calcanhoto. And don’t forget to check out this + awesome playlist. +

    +

    + As always, let me know if you have any questions. +

    +

    + Yours truly, +

    -

    +

    - 'wu-rounded-full', - ]); ?> + 'wu-rounded-full', + ) + ); + ?> - Arindo Duque - Founder and CEO of NextPress, the makers of WP Ultimo -

    + Arindo Duque + Founder and CEO of NextPress, the makers of WP Ultimo +

    -
    +
    -
    +
    -
    +
    - [ - 'email' => 'arindo@wpultimo.com', - 'signature' => 'arindo.png', - 'name' => 'Arindo Duque', - 'position' => 'Founder and CEO', - ], - 'allyson' => [ - 'email' => 'allyson@wpultimo.com', - 'signature' => '', - 'name' => 'Allyson Souza', - 'position' => 'Developer', - ], - 'anyssa' => [ - 'email' => 'anyssa@wpultimo.com', - 'signature' => '', - 'name' => 'Anyssa Ferreira', - 'position' => 'Designer', - ], - 'gustavo' => [ - 'email' => 'gustavo@wpultimo.com', - 'signature' => '', - 'name' => 'Gustavo Modesto', - 'position' => 'Developer', - ], - 'juliana' => [ - 'email' => 'juliana@wpultimo.com', - 'signature' => '', - 'name' => 'Juliana Dias Gomes', - 'position' => 'Do-it-all', - ], - 'lucas-carvalho' => [ - 'email' => 'lucas@wpultimo.com', - 'signature' => '', - 'name' => 'Lucas Carvalho', - 'position' => 'Developer', - ], - 'yan' => [ - 'email' => 'yan@wpultimo.com', - 'signature' => '', - 'name' => 'Yan Kairalla', - 'position' => 'Developer', - ], - ]; + $key_people = array( + 'arindo' => array( + 'email' => 'arindo@wpultimo.com', + 'signature' => 'arindo.png', + 'name' => 'Arindo Duque', + 'position' => 'Founder and CEO', + ), + 'allyson' => array( + 'email' => 'allyson@wpultimo.com', + 'signature' => '', + 'name' => 'Allyson Souza', + 'position' => 'Developer', + ), + 'anyssa' => array( + 'email' => 'anyssa@wpultimo.com', + 'signature' => '', + 'name' => 'Anyssa Ferreira', + 'position' => 'Designer', + ), + 'gustavo' => array( + 'email' => 'gustavo@wpultimo.com', + 'signature' => '', + 'name' => 'Gustavo Modesto', + 'position' => 'Developer', + ), + 'juliana' => array( + 'email' => 'juliana@wpultimo.com', + 'signature' => '', + 'name' => 'Juliana Dias Gomes', + 'position' => 'Do-it-all', + ), + 'lucas-carvalho' => array( + 'email' => 'lucas@wpultimo.com', + 'signature' => '', + 'name' => 'Lucas Carvalho', + 'position' => 'Developer', + ), + 'yan' => array( + 'email' => 'yan@wpultimo.com', + 'signature' => '', + 'name' => 'Yan Kairalla', + 'position' => 'Developer', + ), + ); -?> + ?> -
    +
    - + -
    +
    - 'wu-rounded-full', - ]); - ?> - - + 'wu-rounded-full', + ) + ); + ?> + + -
    +
    - + -
    +
    -
    +
    diff --git a/views/admin-notices.php b/views/admin-notices.php index 4d159b4..a3f18d1 100644 --- a/views/admin-notices.php +++ b/views/admin-notices.php @@ -11,41 +11,41 @@ foreach ($notices as $key => $notice) : ?>
    - ') !== false) : ?> - - - - + ') !== false) : ?> + + + +

    - + -
    +
    -
      +
        - + -
      • - -
      • +
      • + +
      • - + -
      +
    -
    +
    - + - '> + '> - + diff --git a/views/admin-pages/fields/field-code-editor.php b/views/admin-pages/fields/field-code-editor.php index d2bcb6e..1c4deed 100644 --- a/views/admin-pages/fields/field-code-editor.php +++ b/views/admin-pages/fields/field-code-editor.php @@ -7,34 +7,42 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - + - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-description', + array( + 'field' => $field, + ) + ); - ?> + ?> -
    +
  • diff --git a/views/admin-pages/fields/field-color-picker.php b/views/admin-pages/fields/field-color-picker.php index a3786fb..2fd1683 100644 --- a/views/admin-pages/fields/field-color-picker.php +++ b/views/admin-pages/fields/field-color-picker.php @@ -7,38 +7,46 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> -
    +
    - get_html_attributes(); ?>> + get_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-description', + array( + 'field' => $field, + ) + ); - ?> + ?> -
    +
  • diff --git a/views/admin-pages/fields/field-dashicon.php b/views/admin-pages/fields/field-dashicon.php index b1803dc..d403483 100644 --- a/views/admin-pages/fields/field-dashicon.php +++ b/views/admin-pages/fields/field-dashicon.php @@ -8,57 +8,65 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - - + - $category_array) : ?> + $category_array) : ?> - + - $option_value) : ?> + $option_value) : ?> - + - + - + - + - + - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-description', + array( + 'field' => $field, + ) + ); - ?> + ?> -
    +
  • diff --git a/views/admin-pages/fields/field-group.php b/views/admin-pages/fields/field-group.php index c8b03a2..c8c743e 100644 --- a/views/admin-pages/fields/field-group.php +++ b/views/admin-pages/fields/field-group.php @@ -7,47 +7,55 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - id, $field->fields, array( - 'views' => 'admin-pages/fields', - 'classes' => trim('wu-flex '.esc_attr($field->classes)), - 'field_wrapper_classes' => 'wu-bg-transparent', - )); + /** + * Instantiate the form for the order details. + * + * @since 2.0.0 + */ + $form = new \WP_Ultimo\UI\Form( + $field->id, + $field->fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => trim('wu-flex ' . esc_attr($field->classes)), + 'field_wrapper_classes' => 'wu-bg-transparent', + ) + ); - $form->render(); + $form->render(); - ?> + ?> - desc) : ?> + desc) : ?> -
    +
    - desc; ?> + desc; ?> -
    +
    -
    +
  • diff --git a/views/admin-pages/fields/field-header.php b/views/admin-pages/fields/field-header.php index 02bec0d..013c9a4 100644 --- a/views/admin-pages/fields/field-header.php +++ b/views/admin-pages/fields/field-header.php @@ -7,30 +7,30 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    -

    +

    - title; ?> + title; ?> - tooltip) : ?> + tooltip) : ?> - tooltip); ?> + tooltip); ?> - + -

    + - desc) : ?> + desc) : ?> -

    +

    - desc; ?> + desc; ?> -

    +

    - + -
    +
  • diff --git a/views/admin-pages/fields/field-hidden.php b/views/admin-pages/fields/field-hidden.php index 2d360af..2405237 100644 --- a/views/admin-pages/fields/field-hidden.php +++ b/views/admin-pages/fields/field-hidden.php @@ -7,6 +7,6 @@ ?>
  • - get_html_attributes(); ?>> + get_html_attributes(); ?>>
  • diff --git a/views/admin-pages/fields/field-html.php b/views/admin-pages/fields/field-html.php index 18e0513..da00473 100644 --- a/views/admin-pages/fields/field-html.php +++ b/views/admin-pages/fields/field-html.php @@ -7,35 +7,43 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - /** - * Adds the partial title template. - * @since 2.0.0 - */ - wu_get_template('admin-pages/fields/partials/field-description', array( - 'field' => $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-description', + array( + 'field' => $field, + ) + ); - ?> + ?> -
    +
    - content; ?> + content; ?> -
    +
    -
    +
  • diff --git a/views/admin-pages/fields/field-image.php b/views/admin-pages/fields/field-image.php index 22d5f77..8fc51a6 100644 --- a/views/admin-pages/fields/field-image.php +++ b/views/admin-pages/fields/field-image.php @@ -7,7 +7,7 @@ /** * Set the media query. - * + * * When the stacked option is present * and set to true, ignore the flex arrangement * and make elements stacked. @@ -15,96 +15,104 @@ $mq = $field->stacked ? 'ignore-' : ''; $content_wrapper_classes = $field->content_wrapper_classes - ? esc_attr(trim($field->content_wrapper_classes)) - : "wu-ml-0 {$mq}md:wu-ml-4 {$mq}md:wu-w-4/12 wu-mt-4 {$mq}md:wu-mt-0 lg:wu-mt-2"; + ? esc_attr(trim($field->content_wrapper_classes)) + : "wu-ml-0 {$mq}md:wu-ml-4 {$mq}md:wu-w-4/12 wu-mt-4 {$mq}md:wu-mt-0 lg:wu-mt-2"; ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    -
    - - md:wu-w-10/12"> + + $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> -
    - - md:wu-w-9/12"> + + $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-description', + array( + 'field' => $field, + ) + ); - ?> + ?> -
    +
    -
    +
    -
    - -
    +
    + +
    -
    +
    -
    - - +
    + + -
    +
    - -
    +
    - get_html_attributes(); ?> /> + get_html_attributes(); ?> /> - -
    +
    -
    +
    -
  • +
    diff --git a/views/admin-pages/fields/field-link.php b/views/admin-pages/fields/field-link.php index 209a289..437a180 100644 --- a/views/admin-pages/fields/field-link.php +++ b/views/admin-pages/fields/field-link.php @@ -7,38 +7,46 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - get_html_attributes(); ?>> + get_html_attributes(); ?>> - display_value; ?> + display_value; ?> - + - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-description', + array( + 'field' => $field, + ) + ); - ?> + ?> -
    +
  • diff --git a/views/admin-pages/fields/field-multiselect.php b/views/admin-pages/fields/field-multiselect.php index 83d45e8..f93546a 100644 --- a/views/admin-pages/fields/field-multiselect.php +++ b/views/admin-pages/fields/field-multiselect.php @@ -6,80 +6,88 @@ */ ?>
  • get_wrapper_html_attributes(); ?> + class="wrapper_classes)); ?>" + get_wrapper_html_attributes(); ?> > -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - /** - * Adds the partial title template. - * @since 2.0.0 - */ - wu_get_template('admin-pages/fields/partials/field-description', array( - 'field' => $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-description', + array( + 'field' => $field, + ) + ); - ?> + ?> -
      +
        - options as $value => $option) : ?> + options as $value => $option) : ?> -
      • +
      • -
        +
        - + - + - + - + - + - + - + - + - + - + - + -
        +
        - value, true)); ?> value="" id="id}_{$value}"); ?>" type="checkbox" name="id}[]"); ?>" class="wu-tgl wu-tgl-ios" get_html_attributes(); ?>> + value, true)); ?> value="" id="id}_{$value}"); ?>" type="checkbox" name="id}[]"); ?>" class="wu-tgl wu-tgl-ios" get_html_attributes(); ?>> - + -
        +
        -
        +
        -
        +
        -
      • + - + -
      +
    -
    +
  • diff --git a/views/admin-pages/fields/field-note.php b/views/admin-pages/fields/field-note.php index 18cb0dc..3468807 100644 --- a/views/admin-pages/fields/field-note.php +++ b/views/admin-pages/fields/field-note.php @@ -7,22 +7,26 @@ ?>
  • get_wrapper_html_attributes(); ?>> - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> -
    +
    - desc; ?> + desc; ?> -
    +
  • diff --git a/views/admin-pages/fields/field-repeater.php b/views/admin-pages/fields/field-repeater.php index a52955f..50d1905 100644 --- a/views/admin-pages/fields/field-repeater.php +++ b/views/admin-pages/fields/field-repeater.php @@ -4,138 +4,142 @@ * * @since 2.0.0 */ + ?> -title) : ?> +title ) : ?> -
  • get_wrapper_html_attributes(); ?>> +
  • get_wrapper_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array('field' => $field) + ); + ?> - ?> + $field, + ) + ); - /** - * Adds the partial title template. - * @since 2.0.0 - */ - wu_get_template('admin-pages/fields/partials/field-description', array( - 'field' => $field, - )); + ?> - ?> +
    -
    - -
  • + values && $field->value) { +if (! $field->values && $field->value) { + $_values = array(); + $columns = array_keys($field->value); + $values = $field->value; - $_values = array(); + foreach ($columns as $column) { + $count = count(array_pop($field->value)); + for ($i = 0; $i < $count; $i++ ) { + $_values[ $i ][ $column ] = $field->value[ $column ][ $i ]; + } + } - $columns = array_keys($field->value); + $field->values = $_values; +} - $values = $field->value; +$fields = array(); - foreach ($columns as $column) { +foreach ($field->fields as $key => $value) { + $fields[ $key . '[]' ] = $field->fields[ $key ]; +} - $count = count(array_pop($field->value)); +if (is_array($field->values)) { + $position = 0; + $field_len = count($field->values); + foreach ($field->values as $key => $value) { + $field_id = esc_attr($field->id); - for ($i = 0; $i < $count; $i++) { + $field_id .= $position !== $field_len - 1 ? $key : ''; + ++$position; + ?> +
  • get_wrapper_html_attributes(); ?>> +
    + $field_value) { + $fields[ $field_name . '[]' ]['value'] = $field_value; + } - $_values[$i][$column] = $field->value[$column][$i]; + (new \WP_Ultimo\UI\Form( + $field->id, + $fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-flex', + 'field_wrapper_classes' => 'wu-bg-transparent', + ) + ))->render(); + ?> +
    +
  • + +
  • get_wrapper_html_attributes(); ?>> - } // end if; +
    - } // end if; + id, + $fields, + array( + 'views' => 'admin-pages/fields', + 'classes' => 'wu-flex', + 'field_wrapper_classes' => 'wu-bg-transparent', + ) + ))->render(); - $field->values = $_values; + ?> - } // end if; +
    - $fields = array(); - - foreach ($field->fields as $key => $value) { - $fields[$key.'[]'] = $field->fields[$key]; - } - - if (is_array($field->values)) { - $position = 0; - $field_len = count($field->values); - foreach ($field->values as $key => $value) { - $field_id = esc_attr($field->id); - - $field_id .= $position !== $field_len - 1 ? $key : ''; - $position++; - ?> -
  • get_wrapper_html_attributes(); ?>> -
    - $field_value) { - $fields[$field_name.'[]']['value'] = $field_value; - } - - $form = new \WP_Ultimo\UI\Form($field->id, $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-flex', - 'field_wrapper_classes' => 'wu-bg-transparent', - )); - - $form->render(); - ?> -
    -
  • - -
  • get_wrapper_html_attributes(); ?>> - -
    - - id, $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-flex', - 'field_wrapper_classes' => 'wu-bg-transparent', - )); - - $form->render(); - - ?> - -
    - -
  • - +
  • get_wrapper_html_attributes(); ?>> - - - + + +
  • diff --git a/views/admin-pages/fields/field-select-icon.php b/views/admin-pages/fields/field-select-icon.php index ee93460..6b12ab3 100644 --- a/views/admin-pages/fields/field-select-icon.php +++ b/views/admin-pages/fields/field-select-icon.php @@ -7,69 +7,80 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - /** - * Adds the partial title template. - * @since 2.0.0 - */ - wu_get_template('admin-pages/fields/partials/field-description', array( - 'field' => $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-description', + array( + 'field' => $field, + ) + ); - ?> + ?> -
    +
    - options as $option_value => $option) : ?> + options as $option_value => $option) : ?> - '', - )); + /* + * Set the default keys. + */ + $option = wp_parse_args( + $option, + array( + 'tooltip' => '', + ) + ); - ?> + ?> -
    +
    - -
    +
    - + -
    +
    -
    +
  • diff --git a/views/admin-pages/fields/field-select.php b/views/admin-pages/fields/field-select.php index 383f2a2..db56e1e 100644 --- a/views/admin-pages/fields/field-select.php +++ b/views/admin-pages/fields/field-select.php @@ -7,52 +7,60 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - get_html_attributes(); ?> placeholder="placeholder; ?>"> - options as $option_value => $option_label) : ?> + options as $option_value => $option_label) : ?> - + - + - options_template) : ?> + options_template) : ?> - options_template; ?> + options_template; ?> - + - + - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-description', + array( + 'field' => $field, + ) + ); - ?> + ?> -
    +
  • diff --git a/views/admin-pages/fields/field-small-header.php b/views/admin-pages/fields/field-small-header.php index 356986e..10c76d4 100644 --- a/views/admin-pages/fields/field-small-header.php +++ b/views/admin-pages/fields/field-small-header.php @@ -7,26 +7,30 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - desc) : ?> + desc) : ?> - desc; ?> + desc; ?> - + -
    +
  • diff --git a/views/admin-pages/fields/field-submit.php b/views/admin-pages/fields/field-submit.php index 7a0b48b..04dbbb6 100644 --- a/views/admin-pages/fields/field-submit.php +++ b/views/admin-pages/fields/field-submit.php @@ -5,12 +5,12 @@ * @since 2.0.0 */ ?> -
  • get_wrapper_html_attributes(); ?>> +
  • get_wrapper_html_attributes(); ?>> - +
  • diff --git a/views/admin-pages/fields/field-tab-select.php b/views/admin-pages/fields/field-tab-select.php index 9ec136a..f976c3e 100644 --- a/views/admin-pages/fields/field-tab-select.php +++ b/views/admin-pages/fields/field-tab-select.php @@ -7,23 +7,23 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    - options as $option_value => $option_label) : ?> + options as $option_value => $option_label) : ?> - - + -
    +
  • diff --git a/views/admin-pages/fields/field-text-display.php b/views/admin-pages/fields/field-text-display.php index 42d90c4..abaf59d 100644 --- a/views/admin-pages/fields/field-text-display.php +++ b/views/admin-pages/fields/field-text-display.php @@ -7,76 +7,80 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - type === 'date' || $field->date === true) : ?> + type === 'date' || $field->date === true) : ?> - value)) { + if (wu_validate_date($field->value)) { + $date = $field->value; - $date = $field->value; + $time = strtotime(get_date_from_gmt($date)); - $time = strtotime(get_date_from_gmt($date)); - - $formatted_value = date_i18n(get_option('date_format'), $time); + $formatted_value = date_i18n(get_option('date_format'), $time); $placeholder = wu_get_current_time('timestamp') > $time ? __('%s ago', 'wp-ultimo') : __('In %s', 'wp-ultimo'); // phpcs:ignore - echo sprintf('
    %2$s', $formatted_value, sprintf($placeholder, human_time_diff($time, wu_get_current_time('timestamp'))), get_date_from_gmt($date)); + printf('
    %2$s', $formatted_value, sprintf($placeholder, human_time_diff($time, wu_get_current_time('timestamp'))), get_date_from_gmt($date)); + } else { + _e('None', 'wp-ultimo'); + } // end if; - } else { + ?> - _e('None', 'wp-ultimo'); + - } // end if; + - ?> + display_value; ?> - + copy) : ?> - + class="wu-no-underline wp-ui-text-highlight wu-copy" data-clipboard-action="copy" data-clipboard-target="#id; ?>_value"> - display_value; ?> + - copy) : ?> + - class="wu-no-underline wp-ui-text-highlight wu-copy" data-clipboard-action="copy" data-clipboard-target="#id; ?>_value"> + - + - + - + + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-description', + array( + 'field' => $field, + ) + ); - + ?> - $field, - )); - - ?> - -
    +
  • diff --git a/views/admin-pages/fields/field-text-edit.php b/views/admin-pages/fields/field-text-edit.php index 179066f..65c7ee9 100644 --- a/views/admin-pages/fields/field-text-edit.php +++ b/views/admin-pages/fields/field-text-edit.php @@ -7,112 +7,116 @@ ?>
  • -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - type === 'date' || $field->date === true) : ?> + type === 'date' || $field->date === true) : ?> - value)) { + if (wu_validate_date($field->value)) { + if ($field->display_value == false) { + echo __('No date', 'wp-ultimo'); + } else { + $date = $field->value; - if ($field->display_value == false) { + $time = strtotime(get_date_from_gmt($date)); - echo __('No date', 'wp-ultimo'); + $formatted_value = date_i18n(get_option('date_format'), $time); - } else { + $placeholder = wu_get_current_time('timestamp') > $time ? __('%s ago', 'wp-ultimo') : __('In %s', 'wp-ultimo'); // phpcs:ignore - $date = $field->value; + printf('
    %2$s', $formatted_value, sprintf($placeholder, human_time_diff($time, wu_get_current_time('timestamp'))), get_date_from_gmt($date)); + } // end if; + } else { + _e('None', 'wp-ultimo'); + } // end if; - $time = strtotime(get_date_from_gmt($date)); + ?> - $formatted_value = date_i18n(get_option('date_format'), $time); + - $placeholder = wu_get_current_time('timestamp') > $time ? __('%s ago', 'wp-ultimo') : __('In %s', 'wp-ultimo'); // phpcs:ignore + - echo sprintf('
    %2$s', $formatted_value, sprintf($placeholder, human_time_diff($time, wu_get_current_time('timestamp'))), get_date_from_gmt($date)); + display_value; ?> - } // end if; +
    - } else { + - _e('None', 'wp-ultimo'); +
    - } // end if; + edit) : ?> - ?> +
    + + + +
    - +
    - + display_value; ?> + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - + ?> - + get_html_attributes(); ?>> -
    + edit) : ?> + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-description', + array( + 'field' => $field, + ) + ); -
    - - - -
    + ?> -
    +
    - - /** - * Adds the partial title template. - * @since 2.0.0 - */ - wu_get_template('admin-pages/fields/partials/field-title', array( - 'field' => $field, - )); + copy) : ?> - ?> +
    + + + +
    - get_html_attributes(); ?>> - - $field, - )); - - ?> - -
    - - - - copy) : ?> - -
    - - - -
    - - +
  • diff --git a/views/admin-pages/fields/field-text.php b/views/admin-pages/fields/field-text.php index 12db55d..84d4bc9 100644 --- a/views/admin-pages/fields/field-text.php +++ b/views/admin-pages/fields/field-text.php @@ -7,70 +7,78 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - type === 'model') : ?> + type === 'model') : ?> -
    +
    -
    - get_html_attributes(); ?>> -
    +
    + get_html_attributes(); ?>> +
    - html_attr, 'data-base-link')) : ?> + html_attr, 'data-base-link')) : ?> - + - + -
    +
    - money) : ?> + money) : ?> - get_html_attributes(); ?>> + get_html_attributes(); ?>> - get_html_attributes(); ?> v-if="false"> + get_html_attributes(); ?> v-if="false"> - + - get_html_attributes(); ?>> + get_html_attributes(); ?>> - + - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-description', + array( + 'field' => $field, + ) + ); - ?> + ?> -
    +
  • diff --git a/views/admin-pages/fields/field-textarea.php b/views/admin-pages/fields/field-textarea.php index fdb0511..a6f929a 100644 --- a/views/admin-pages/fields/field-textarea.php +++ b/views/admin-pages/fields/field-textarea.php @@ -7,34 +7,42 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - + - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-description', + array( + 'field' => $field, + ) + ); - ?> + ?> -
    +
  • diff --git a/views/admin-pages/fields/field-toggle.php b/views/admin-pages/fields/field-toggle.php index eee737e..8870430 100644 --- a/views/admin-pages/fields/field-toggle.php +++ b/views/admin-pages/fields/field-toggle.php @@ -7,38 +7,42 @@ ?>
  • get_wrapper_html_attributes(); ?>> -
    +
    - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - desc) : ?> + desc) : ?> - desc; ?> + desc; ?> - + -
    +
    -
    +
    -
    +
    - value == 1); ?> id="wu-tg-id); ?>" type="checkbox" name="" get_html_attributes(); ?> /> + value == 1); ?> id="wu-tg-id); ?>" type="checkbox" name="" get_html_attributes(); ?> /> - + -
    +
    -
    +
  • diff --git a/views/admin-pages/fields/field-wp-editor.php b/views/admin-pages/fields/field-wp-editor.php index acb81a4..ad177ad 100644 --- a/views/admin-pages/fields/field-wp-editor.php +++ b/views/admin-pages/fields/field-wp-editor.php @@ -15,11 +15,15 @@ /** * Adds the partial title template. + * * @since 2.0.0 */ - wu_get_template('admin-pages/fields/partials/field-title', array( - 'field' => $field, - )); + wu_get_template( + 'admin-pages/fields/partials/field-title', + array( + 'field' => $field, + ) + ); ?> @@ -42,11 +46,15 @@ /** * Adds the partial title template. + * * @since 2.0.0 */ - wu_get_template('admin-pages/fields/partials/field-description', array( - 'field' => $field, - )); + wu_get_template( + 'admin-pages/fields/partials/field-description', + array( + 'field' => $field, + ) + ); ?> diff --git a/views/admin-pages/fields/form.php b/views/admin-pages/fields/form.php index 84ceaa8..062760a 100644 --- a/views/admin-pages/fields/form.php +++ b/views/admin-pages/fields/form.php @@ -7,35 +7,35 @@ ?>
    - before; ?> + before; ?> -
    +
    - wrap_in_form_tag) : ?> + wrap_in_form_tag) : ?> - get_html_attributes(); ?> - > + get_html_attributes(); ?> + > - + -
      get_html_attributes(); ?>> +
        get_html_attributes(); ?>> - + -
      +
    - wrap_in_form_tag) : ?> + wrap_in_form_tag) : ?> - + - + - after; ?> + after; ?> -
    +
    diff --git a/views/admin-pages/fields/partials/field-description.php b/views/admin-pages/fields/partials/field-description.php index 72fa3f2..dd4ad58 100644 --- a/views/admin-pages/fields/partials/field-description.php +++ b/views/admin-pages/fields/partials/field-description.php @@ -8,10 +8,10 @@ desc) : ?> -

    +

    - desc; ?> + desc; ?> -

    +

    diff --git a/views/admin-pages/fields/partials/field-title.php b/views/admin-pages/fields/partials/field-title.php index 96add0d..2d999c5 100644 --- a/views/admin-pages/fields/partials/field-title.php +++ b/views/admin-pages/fields/partials/field-title.php @@ -8,16 +8,16 @@ title && is_string($field->title)) : ?> - + - title; ?> + title; ?> - tooltip) : ?> + tooltip) : ?> - tooltip); ?> + tooltip); ?> - + - + diff --git a/views/base/centered.php b/views/base/centered.php index cba55d3..5acdc13 100644 --- a/views/base/centered.php +++ b/views/base/centered.php @@ -7,190 +7,189 @@ ?>
    -
    +
    -

    +

    - + - get_title_links() as $action_link) : + get_title_links() as $action_link) : + $action_classes = isset($action_link['classes']) ? $action_link['classes'] : ''; - $action_classes = isset($action_link['classes']) ? $action_link['classes'] : ''; + ?> - ?> + - + - + +   + - -   - + - + - + - + - + - +

    - + - +
    +

    +
    -
    -

    -
    + - +
    -
    + - + - +
    -
    +
    -
    +
    -
    +
    + id, 'left', null); + ?> +
    -
    - id, 'left', null); - ?> -
    +
    -
    + - +
    -
    +
    -
    +
    -
    +

    -

    + - +

    - +
    -
    +
    -
    +
    -
    + - +
    -
    +
    -
    +
    -
    +
    -
    + - + id, 'normal', null); - /** - * Print Advanced Metaboxes - * - * Allow plugin developers to add new metaboxes - * - * @since 1.8.2 - * @param object Object being edited right now - */ - do_meta_boxes($screen->id, 'normal', null); + ?> - ?> +
    -
    + - ?> +
    -
    +
    -
    +
    + - id, 'right', null); - /** - * Print Advanced Metaboxes - * - * Allow plugin developers to add new metaboxes - * - * @since 1.8.2 - * @param object Object being edited right now - */ - do_meta_boxes($screen->id, 'right', null); + ?> +
    - ?> -
    +
    -
    +
    -
    + - + - +
    -
    + - + - - -
    +
    diff --git a/views/base/checkout-forms/js-templates.php b/views/base/checkout-forms/js-templates.php index fb3e806..4705098 100644 --- a/views/base/checkout-forms/js-templates.php +++ b/views/base/checkout-forms/js-templates.php @@ -60,20 +60,20 @@ {{ field.name ? field.name : "" }} - - - + + - - - - + + + @@ -82,10 +82,17 @@ diff --git a/views/base/checkout-forms/steps.php b/views/base/checkout-forms/steps.php index 512895d..813a429 100644 --- a/views/base/checkout-forms/steps.php +++ b/views/base/checkout-forms/steps.php @@ -7,307 +7,335 @@ ?>
    - -
    - -
    - -
    - - - - - - - -
    - -
    - -
      - -
    • - - - - - -
    • + +
      + +
      + +
      + + + + + + + +
      + +
      + + + +
      + +
      + +
      + + + +
      + + + + +
      + +
      +

      + + {{ step.name }} + +

      +
      + +
      + + +
      + + + + + guests', 'wp-ultimo'); ?> + + + + logged-in users', 'wp-ultimo'); ?> + + +
      + + +
      + +
      + + + +
      + +
      + +
      + + - -
      - -
      - -
      - - - -
      - - - - -
      - -
      -

      - - {{ step.name }} - -

      -
      - -
      - - -
      - - + - - guests', 'wp-ultimo'); ?> - +
    • - - logged-in users', 'wp-ultimo'); ?> - - -
    • - - -
      - -
      - - - -
      - -
      - -
      - - -
    • +
    • - - - +
      - +
      -
    • + + + + +
      + +
      + + + + + + + + + +
      + + +
      + + + + + +
      + + + +
      + + + + + +
      + + + + +
      - - - - + -
    • +
      + -
    +
    + + +
    + -
    + +
    -
    +
    -
    +
    - - + - -
    + -
    + - - - +
    - - - +
    -
    + - -
    +
    - - - +
    -
    - +
    + - - -
    - - - -
    - - - - - - - - - -
    - -
    - -
    - - - - - - - -
    - -
    - - - -
    - -
    - -
    - - - + diff --git a/views/base/customers/grid-item.php b/views/base/customers/grid-item.php index b7f357a..3f5118e 100644 --- a/views/base/customers/grid-item.php +++ b/views/base/customers/grid-item.php @@ -7,130 +7,146 @@ ?>
    -
    +
    -
    -   -
    +
    +   +
    -
    - get_user_id(), 92, 'identicon', '', array('force_display' => true, 'class' => 'wu-rounded-full wu-border wu-border-solid wu-border-gray-300 wu-bg-white')); ?> -
    +
    + get_user_id(), + 92, + 'identicon', + '', + array( + 'force_display' => true, + 'class' => 'wu-rounded-full wu-border wu-border-solid wu-border-gray-300 wu-bg-white', + ) + ); + ?> +
    -
    -
    - get_display_name(); ?> - #get_id(); ?> -
    -
    - get_email_address()) : ?> - - get_email_address(); ?> - - - - -
    -
    - - is_vip() ? __('VIP Customer', 'wp-ultimo') : __('Regular Customer', 'wp-ultimo'); ?> - -
    -
    +
    +
    + get_display_name(); ?> + #get_id(); ?> +
    +
    + get_email_address()) : ?> + + get_email_address(); ?> + + + + +
    +
    + + is_vip() ? __('VIP Customer', 'wp-ultimo') : __('Regular Customer', 'wp-ultimo'); ?> + +
    +
    -
    +
    -
    - - - - - is_online()) { - echo ''.__('Online', 'wp-ultimo'); - } else { - if ( '0000-00-00 00:00:00' !== $item->get_last_login() ) { - echo human_time_diff( strtotime( $item->get_last_login() ), time() ).' '.__('ago', 'wp-ultimo'); - } else { - _e('Never logged in', 'wp-ultimo'); - } - } - ?> - -
    -
    - - - - - get_date_registered() ), time() ).' '.__('ago', 'wp-ultimo'); ?> - -
    +
    + + + + + is_online()) { + echo '' . __('Online', 'wp-ultimo'); + } elseif ( '0000-00-00 00:00:00' !== $item->get_last_login() ) { + echo human_time_diff(strtotime($item->get_last_login()), time()) . ' ' . __('ago', 'wp-ultimo'); + } else { + _e('Never logged in', 'wp-ultimo'); + } + ?> + +
    +
    + + + + + get_date_registered()), time()) . ' ' . __('ago', 'wp-ultimo'); ?> + +
    -
    - - - -
    - - get_memberships()); ?> - +
    + + + +
    + + get_memberships()); ?> + - get_memberships())) { - ?> - - - - + get_memberships())) { + ?> + + + + -
    -
    +
    +
    -
    - - - -
    +
    + + + +
    - check_user_switching_is_activated() ? '' : 'wubox'; + // Concatenate switch to url + $is_modal_switch_to = \WP_Ultimo\User_Switching::get_instance()->check_user_switching_is_activated() ? '' : 'wubox'; - $url_switch_to = sprintf('%s', __('Switch To', 'wp-ultimo'), $is_modal_switch_to, \WP_Ultimo\User_Switching::get_instance()->render($item->get_user_id()), __('Switch To', 'wp-ultimo')); + $url_switch_to = sprintf('%s', __('Switch To', 'wp-ultimo'), $is_modal_switch_to, \WP_Ultimo\User_Switching::get_instance()->render($item->get_user_id()), __('Switch To', 'wp-ultimo')); - $actions = array( - 'switch-to' => $item->get_user_id() !== get_current_user_id() ? $url_switch_to : __('None', 'wp-ultimo'), - ); + $actions = array( + 'switch-to' => $item->get_user_id() !== get_current_user_id() ? $url_switch_to : __('None', 'wp-ultimo'), + ); - echo implode("
    ", $actions); + echo implode('
    ', $actions); - ?> + ?> -
    -
    +
    +
    -
    +
    -
    +
    - + - - - -
    -
    + + + +
    +
    diff --git a/views/base/dash.php b/views/base/dash.php index d001ccd..6ab73ea 100644 --- a/views/base/dash.php +++ b/views/base/dash.php @@ -5,142 +5,141 @@ * @since 2.0.0 */ ?> -
    +
    -

    +

    - + - get_title_links() as $action_link) : + get_title_links() as $action_link) : + $action_classes = isset($action_link['classes']) ? $action_link['classes'] : ''; - $action_classes = isset($action_link['classes']) ? $action_link['classes'] : ''; + ?> - ?> + - + - + +   + - -   - + - + - + - + - + - +

    - +
    -
    + - + - +
    -
    +
    -
    + - +
    + id, 'full', null); + ?> +
    -
    - id, 'full', null); - ?> -
    +
    -
    + - +
    -
    + - +
    -
    +
    + id, 'normal', null); + ?> +
    -
    - id, 'normal', null); - ?> -
    +
    + id, 'side', null); + ?> +
    -
    - id, 'side', null); - ?> -
    +
    + id, 'column3', null); + ?> +
    -
    - id, 'column3', null); - ?> -
    +
    -
    +
    -
    + - + - +
    -
    + - - - +
    diff --git a/views/base/edit.php b/views/base/edit.php index 2919ba6..dce0e3d 100644 --- a/views/base/edit.php +++ b/views/base/edit.php @@ -5,245 +5,250 @@ * @since 2.0.0 */ ?> -
    +
    -

    +

    - edit ? $labels['edit_label'] : $labels['add_new_label']; ?> + edit ? $labels['edit_label'] : $labels['add_new_label']; ?> - get_title_links() as $action_link) : + get_title_links() as $action_link) : + $action_classes = isset($action_link['classes']) ? $action_link['classes'] : ''; - $action_classes = isset($action_link['classes']) ? $action_link['classes'] : ''; + $attrs = isset($action_link['attrs']) ? $action_link['attrs'] : ''; - $attrs = isset($action_link['attrs']) ? $action_link['attrs'] : ''; + ?> - ?> + > - > + - + +   + - -   - + - + - + - + - + - +

    - + - +
    +

    +
    -
    -

    -
    + - + - +
    +

    +
    -
    -

    -
    + - + - +
    -
    +
    - +
    -
    +
    -
    + has_title()) : ?> - has_title()) : ?> +
    -
    +
    -
    +
    -
    + - + - + + + - - - + - + - +
    -
    +
    + -
    - + has_editor()) : ?> - has_editor()) : ?> +
    -
    + - + get_content()) : ''; ?> + 500, + ) + ); + ?> - get_content()) : ''; ?> - 500, - )); ?> +
    -
    + - +
    + -
    - + - +
    -
    + id, 'side', $object); + ?> - id, 'side', $object); - ?> + id, 'side-bottom', $object); + ?> - id, 'side-bottom', $object); - ?> +
    -
    +
    -
    + id, 'normal', $object); - /** - * Print Normal Metaboxes - * - * Allow plugin developers to add new metaboxes - * - * @since 1.8.2 - * @param object Object being edited right now - */ - do_meta_boxes($screen->id, 'normal', $object); + /** + * Allow developers to add additional elements after the modals are printed. + * + * @since 2.0.0 + * @param object Object being edited right now + */ + do_action("wu_edit_{$screen->id}_after_normal", $object); - /** - * Allow developers to add additional elements after the modals are printed. - * - * @since 2.0.0 - * @param object Object being edited right now - */ - do_action("wu_edit_{$screen->id}_after_normal", $object); + /** + * Print Advanced Metaboxes + * + * Allow plugin developers to add new metaboxes + * + * @since 1.8.2 + * @param object Object being edited right now + */ + do_meta_boxes($screen->id, 'advanced', $object); + + ?> + +
    + - /** - * Print Advanced Metaboxes - * - * Allow plugin developers to add new metaboxes - * - * @since 1.8.2 - * @param object Object being edited right now - */ - do_meta_boxes($screen->id, 'advanced', $object); +
    + - ?> +
    -
    - + -
    - + -
    + object_id), sprintf('saving_%s', $page->object_id), false); ?> - + object_id), '_wpultimo_nonce'); ?> + + edit) : ?> + object_id), sprintf('deleting_%s', $page->object_id), false); ?> + + object_id), 'delete_wpultimo_nonce'); ?> + + + + + +
    + - + - object_id), sprintf('saving_%s', $page->object_id), false); ?> - - object_id), '_wpultimo_nonce'); ?> - - edit) : ?> - object_id), sprintf('deleting_%s', $page->object_id), false); ?> - - object_id), 'delete_wpultimo_nonce'); ?> - - - - - -
    - - - - - +
    diff --git a/views/base/edit/display-notes.php b/views/base/edit/display-notes.php index 012fd88..f40cc6d 100644 --- a/views/base/edit/display-notes.php +++ b/views/base/edit/display-notes.php @@ -8,12 +8,16 @@ - __("No notes yet.", 'wp-ultimo'), - 'sub_message' => __('Use the "Add new Note" to create the first one.', 'wp-ultimo'), - 'link_url' => false, - 'display_background_image' => false, - )); ?> + __('No notes yet.', 'wp-ultimo'), + 'sub_message' => __('Use the "Add new Note" to create the first one.', 'wp-ultimo'), + 'link_url' => false, + 'display_background_image' => false, + ) + ); + ?> @@ -33,7 +37,21 @@
    - author_id, 20, 'identicon', '', array('force_display' => true, 'class' => 'wu-rounded-full wu-mr-2'))); ?> display_name; ?> + author_id, + 20, + 'identicon', + '', + array( + 'force_display' => true, + 'class' => 'wu-rounded-full wu-mr-2', + ) + ) + ); + ?> + display_name; ?>
    @@ -47,12 +65,14 @@ - wu_request('id'), 'model' => $model, 'note_id' => $note->note_id, 'height' => 306, - ); ?> + ); + ?> diff --git a/views/base/edit/editor-customizer.php b/views/base/edit/editor-customizer.php index ec99bb3..671d4db 100644 --- a/views/base/edit/editor-customizer.php +++ b/views/base/edit/editor-customizer.php @@ -7,46 +7,46 @@ ?>
    -
    +
    -
    +
    - + - + - + -
    +
    -
    +
    -
    +
    -
    +
    -
    +
    -
    +
    - + - + - + -
    +
    -
    +
    -
    +
    -
    +
    - + -
    +
    -
    +
    diff --git a/views/base/edit/widget-list-table.php b/views/base/edit/widget-list-table.php index af34a9c..280cdc8 100644 --- a/views/base/edit/widget-list-table.php +++ b/views/base/edit/widget-list-table.php @@ -9,28 +9,28 @@ edit) : ?> -
    +
    - prepare_items(); ?> + prepare_items(); ?> - + - + - display(); ?> + display(); ?> - + -
    +
    -
    - - - - -
    +
    + + + + +
    diff --git a/views/base/edit/widget-save.php b/views/base/edit/widget-save.php index 4a25173..2791842 100644 --- a/views/base/edit/widget-save.php +++ b/views/base/edit/widget-save.php @@ -5,18 +5,18 @@ * @since 2.0.0 */ ?> - + -

    - -

    +

    + +

    - +
    diff --git a/views/base/edit/widget-tabs.php b/views/base/edit/widget-tabs.php index bae4222..35bc8ea 100644 --- a/views/base/edit/widget-tabs.php +++ b/views/base/edit/widget-tabs.php @@ -6,114 +6,114 @@ */ ?>
    + class="wu-m-0" + data-wu-app="" + data-state="" + > -
    +
    -
    +
    - -
    +
    -
    +
    -
    +
    - + - + - + -
    +
    - $section) : ?> + $section) : ?> -
    " - > +
    " + > -
    +
    - + -
    +
    -
    +
    - +
    diff --git a/views/base/empty-state.php b/views/base/empty-state.php index 36fe9cb..d4e7dd8 100644 --- a/views/base/empty-state.php +++ b/views/base/empty-state.php @@ -6,56 +6,56 @@ */ ?>
    " + class="wu-flex wu-justify-center wu-items-center wu-text-center wu-bg-contain wu-bg-no-repeat wu--mb-12 wu-pb-12" + style="background-image: url(); " > -
    +
    - + - + - + - + -
    +
    - + -
    +
    - - + -
    +
    - + -
    +
    - + -
    +
    diff --git a/views/base/filter.php b/views/base/filter.php index 8497465..71ca6f6 100644 --- a/views/base/filter.php +++ b/views/base/filter.php @@ -6,214 +6,214 @@ */ ?>
    - + - - + - + - + -
    - -
    +
    + +
    - + - + -
    + - + - + - + - + - + - + - view_switcher($table->current_mode); ?> + view_switcher($table->current_mode); ?> - + -
    +
    -
    +
    -
    +
    -
    +
    -
    +
    - - - + + + - + - - - - + + + + -
    +
    -
    +
    - - + - + -
    +
    -
    +
    - + - + - + -
    +
    -
    +
    - + -
    +
    -
    + +
    -
    + +
    -
    +
    -
    +
    -
    +
    diff --git a/views/base/grid.php b/views/base/grid.php index ae47173..e24ca96 100644 --- a/views/base/grid.php +++ b/views/base/grid.php @@ -7,11 +7,11 @@ ?> display_tablenav('top'); ?> -
    +
    -
    +
    - display_rows_or_placeholder(); ?> + display_rows_or_placeholder(); ?> -
    +
    diff --git a/views/base/list.php b/views/base/list.php index f786c46..b22baf2 100644 --- a/views/base/list.php +++ b/views/base/list.php @@ -5,113 +5,112 @@ * @since 2.0.0 */ ?> -
    +
    -

    +

    - get_title(); ?> + get_title(); ?> - get_title_links() as $action_link) : + get_title_links() as $action_link) : + $action_classes = isset($action_link['classes']) ? $action_link['classes'] : ''; - $action_classes = isset($action_link['classes']) ? $action_link['classes'] : ''; + ?> - ?> + - + - + +   + - -   - + - + - + - + - + - +

    - + +
    +

    get_labels()['deleted_message']; ?>

    +
    + - -
    -

    get_labels()['deleted_message']; ?>

    -
    - + - +
    -
    +
    -
    +
    -
    +
    -
    +
    -
    + prepare_items(); ?> - prepare_items(); ?> + filters(); ?> - filters(); ?> +
    - + - + display(); ?> - display(); ?> + - +
    + -
    - +
    + -
    - +
    + -
    - +
    -
    +
    + -
    - - - +
    diff --git a/views/base/products/grid-item.php b/views/base/products/grid-item.php index bb14666..94b0c3e 100644 --- a/views/base/products/grid-item.php +++ b/views/base/products/grid-item.php @@ -7,15 +7,15 @@ ?>
    -
    +
    -
    +
    get_featured_image('wu-thumb-medium'); if ($featured_image) { - ?> + ?> get_type_label(); ?>
    - + ?>
    @@ -35,39 +35,39 @@
    get_type_label(); ?>
    - -
    +
    -
    +
    -
    - get_name(); ?> - -
    +
    + get_name(); ?> + +
    -
    - get_price_description(); ?> -
    +
    + get_price_description(); ?> +
    -
    +
    -
    +
    -
    +
    - + - - - + + + -
    -
    +
    +
    diff --git a/views/base/responsive-table-row.php b/views/base/responsive-table-row.php index 72bc568..225349d 100644 --- a/views/base/responsive-table-row.php +++ b/views/base/responsive-table-row.php @@ -7,122 +7,136 @@ ?>
    -
    +
    - + -
    +
    - + -
    +
    - + -
    +
    -
    +
    - + - + - + - (#) + (#) - + - + -
    +
    - + -
    +
    -
    +
    -
    +
    -
    +
    - $item) : $w_classes = wu_get_isset($item, 'wrapper_classes', ''); ?> + $item) : + $w_classes = wu_get_isset($item, 'wrapper_classes', ''); + ?> - + - > + > - + - + - + - + - > + > - + - + - + - + - + -
    +
    -
    +
    - $item) : $w_classes = wu_get_isset($item, 'wrapper_classes', ''); ?> + $item) : + $w_classes = wu_get_isset($item, 'wrapper_classes', ''); + ?> - + - > + > - + - + - + - + - > + > - + - + - + - + - + -
    +
    -
    +
    -
    +
    - + - - + -
    +
    diff --git a/views/base/settings.php b/views/base/settings.php index 94e94e8..dfd4a12 100644 --- a/views/base/settings.php +++ b/views/base/settings.php @@ -5,307 +5,300 @@ * @since 2.0.0 */ ?> -
    +
    -

    +

    - get_title(); ?> + get_title(); ?> - get_title_links() as $action_link) : + get_title_links() as $action_link) : + $action_classes = isset($action_link['classes']) ? $action_link['classes'] : ''; - $action_classes = isset($action_link['classes']) ? $action_link['classes'] : ''; + ?> - ?> + - + - + +   + - -   - + - + - + - + - + - +

    - + - +
    +

    +
    -
    -

    -
    + - +
    -
    +
    - +
    -
    +
    -
    +
    -
    + - +
    -
    +
    -
    + +
    - - +
    - +
    - - +
    - + id, 'normal', false); + ?> - - +
    - +
    -
    +
    -
    + -
    +
    -
    +
    - id, 'normal', false); - ?> + -
    + -
    + -
    - - - -
    - -
    - - - - - - - - +
    @@ -323,7 +316,7 @@ settings_loader = wu_block_ui('#wp-ultimo-wizard-body'); */ function remove_block_ui() { - settings_loader.unblock(); + settings_loader.unblock(); } // end remove_block_ui; diff --git a/views/base/sites/grid-item.php b/views/base/sites/grid-item.php index 8bd92f9..92eeafd 100644 --- a/views/base/sites/grid-item.php +++ b/views/base/sites/grid-item.php @@ -7,78 +7,78 @@ ?>
    -
    +
    -
    +
    - + - + -
    - get_type_label(); ?> -
    +
    + get_type_label(); ?> +
    - + -
    +
    -
    +
    -
    - get_title(); ?> - get_id() ? '#'.$item->get_id() : ''; ?> -
    +
    + get_title(); ?> + get_id() ? '#' . $item->get_id() : ''; ?> +
    - + -
    +
    -
    +
    - get_type() !== 'main') : ?> + get_type() !== 'main') : ?> - get_type() === 'pending') : ?> + get_type() === 'pending') : ?> - + - - - + + + - + - + - - - + + + - + - + -   +   - - - + + + - + -
    -
    +
    +
    diff --git a/views/base/wizard.php b/views/base/wizard.php index 9c83584..8317d16 100644 --- a/views/base/wizard.php +++ b/views/base/wizard.php @@ -7,66 +7,66 @@ ?>
    -

    - -

    +

    + +

    - + -
    +
    - + -
    - - - - - -
    - -

    labels['deleted_message']; ?>

    - -
    +
    -
    + -
    +
    -
    +

    labels['deleted_message']; ?>

    - +
    - get_title(); ?> + - +
    - +
    - -
      +
      - - /** - * We need to set a couple of flags in here to control clickable navigation elements. - * This flag makes sure only steps the user already went through are clickable. - */ - $is_pre_current_section = true; + get_title(); ?> - ?> + - $section) : ?> + + + +
        + + + + $section) : ?> - + - -
      •  
      • + +
      •  
      • - + - -
      • + +
      • - - - - - + + + + + - + - - + - + -
      • - + + - + - + -
      - +
    + -
    +
    -
    +
    -
    + - id, 'normal', false); + /** + * Print Side Metaboxes + * + * Allow plugin developers to add new metaboxes + * + * @since 1.8.2 + * @param object Object being edited right now + */ + do_meta_boxes($screen->id, 'normal', false); - ?> + ?> - + - + - + -
    +
    -
    +
    - - - + + + - + - + - +
    diff --git a/views/broadcast/emails/base.php b/views/broadcast/emails/base.php index b380806..0628737 100644 --- a/views/broadcast/emails/base.php +++ b/views/broadcast/emails/base.php @@ -15,105 +15,104 @@ * @version 1.4.0 */ -if (!defined('ABSPATH')) { - - exit; // Exit if accessed directly +if ( ! defined('ABSPATH')) { + exit; // Exit if accessed directly } // end if; ?> - + - - - - - - <?php echo $subject; ?> - + + + + + + <?php echo $subject; ?> + - -
    - - - + + +
    - +
    + + + + diff --git a/views/broadcast/emails/plain.php b/views/broadcast/emails/plain.php index 99f3959..b442085 100644 --- a/views/broadcast/emails/plain.php +++ b/views/broadcast/emails/plain.php @@ -15,8 +15,8 @@ * @version 1.4.0 */ -if (!defined('ABSPATH')) { - exit; // Exit if accessed directly +if ( ! defined('ABSPATH')) { + exit; // Exit if accessed directly } ?> diff --git a/views/broadcast/widget-targets.php b/views/broadcast/widget-targets.php index feef29f..83feafc 100644 --- a/views/broadcast/widget-targets.php +++ b/views/broadcast/widget-targets.php @@ -7,64 +7,64 @@ ?> diff --git a/views/checkout/confirmation.php b/views/checkout/confirmation.php index 335ec70..e17eed1 100644 --- a/views/checkout/confirmation.php +++ b/views/checkout/confirmation.php @@ -7,26 +7,26 @@ ?>
    -

    Thank you for your membership to wphunt.org. Your Teste 2 membership is now active.

    +

    Thank you for your membership to wphunt.org. Your Teste 2 membership is now active.

    -

    Below are details about your membership account and a receipt for your initial membership invoice. A welcome email with a copy of your initial membership invoice has been sent to arindo@wpultimo.com.

    +

    Below are details about your membership account and a receipt for your initial membership invoice. A welcome email with a copy of your initial membership invoice has been sent to arindo@wpultimo.com.

    -

    Extra message

    +

    Extra message

    -

    +

    Invoice #DF232BD72B on May 2, 2020

    - Print + Print -
      +
      • Account: aanduque (arindo@wpultimo.com)
      • Membership Level: Teste 2
      -
      +
      -
      +
      Billing Address

      Quynn Mullins
      @@ -49,14 +49,14 @@

      -
      +
      -
      diff --git a/views/checkout/fields/field-checkbox-multi.php b/views/checkout/fields/field-checkbox-multi.php index 441596c..11c6426 100644 --- a/views/checkout/fields/field-checkbox-multi.php +++ b/views/checkout/fields/field-checkbox-multi.php @@ -7,40 +7,48 @@ ?>
      get_wrapper_html_attributes(); ?>> - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - options as $option_value => $option_name) : ?> + options as $option_value => $option_name) : ?> - - + - $field, - )); + /** + * Adds the partial error template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-errors', + array( + 'field' => $field, + ) + ); - ?> + ?>
      diff --git a/views/checkout/fields/field-checkbox.php b/views/checkout/fields/field-checkbox.php index 0f1b3a5..29a33c0 100644 --- a/views/checkout/fields/field-checkbox.php +++ b/views/checkout/fields/field-checkbox.php @@ -7,28 +7,32 @@ ?>
      get_wrapper_html_attributes(); ?>> - - $field, - )); + /** + * Adds the partial error template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-errors', + array( + 'field' => $field, + ) + ); - ?> + ?>
      diff --git a/views/checkout/fields/field-group.php b/views/checkout/fields/field-group.php index 8672f87..b4b582b 100644 --- a/views/checkout/fields/field-group.php +++ b/views/checkout/fields/field-group.php @@ -7,59 +7,70 @@ ?>
      get_wrapper_html_attributes(); ?>> - + - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - id, $field->fields, array( - 'views' => 'checkout/fields', - 'classes' => 'wu-flex wu-my-1', - 'field_wrapper_classes' => 'wu-bg-transparent', - 'wrap_tag' => 'span', - 'step' => (object) array( - 'classes' => '', - ), - )); + id, + $field->fields, + array( + 'views' => 'checkout/fields', + 'classes' => 'wu-flex wu-my-1', + 'field_wrapper_classes' => 'wu-bg-transparent', + 'wrap_tag' => 'span', + 'step' => (object) array( + 'classes' => '', + ), + ) + ); - $form->render(); + $form->render(); - /** - * Adds the partial error template. - * - * @since 2.0.0 - */ - wu_get_template('checkout/fields/partials/field-errors', array( - 'field' => $field, - )); + /** + * Adds the partial error template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-errors', + array( + 'field' => $field, + ) + ); - ?> + ?> - desc) : ?> + desc) : ?> - + - desc; ?> + desc; ?> - + - +
      diff --git a/views/checkout/fields/field-hidden.php b/views/checkout/fields/field-hidden.php index 1e32d69..3e0c3e2 100644 --- a/views/checkout/fields/field-hidden.php +++ b/views/checkout/fields/field-hidden.php @@ -8,15 +8,15 @@ value)) : ?> - value as $index => $value) : ?> + value as $index => $value) : ?> - get_html_attributes(); ?>> + get_html_attributes(); ?>> - + - get_html_attributes(); ?>> + get_html_attributes(); ?>> @@ -24,10 +24,14 @@ /** * Adds the partial error template. + * * @since 2.0.0 */ -wu_get_template('checkout/fields/partials/field-errors', array( - 'field' => $field, -)); +wu_get_template( + 'checkout/fields/partials/field-errors', + array( + 'field' => $field, + ) +); ?> diff --git a/views/checkout/fields/field-html.php b/views/checkout/fields/field-html.php index 28265ec..3aea589 100644 --- a/views/checkout/fields/field-html.php +++ b/views/checkout/fields/field-html.php @@ -8,46 +8,58 @@
      get_wrapper_html_attributes(); ?>> -
      +
      - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - /** - * Adds the partial description template. - * @since 2.0.0 - */ - wu_get_template('checkout/fields/partials/field-description', array( - 'field' => $field, - )); + /** + * Adds the partial description template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-description', + array( + 'field' => $field, + ) + ); - ?> + ?> -
      +
      - content; ?> + content; ?> -
      +
      - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-errors', + array( + 'field' => $field, + ) + ); - ?> + ?> -
      +
      diff --git a/views/checkout/fields/field-note.php b/views/checkout/fields/field-note.php index 0a336ea..d503edb 100644 --- a/views/checkout/fields/field-note.php +++ b/views/checkout/fields/field-note.php @@ -8,6 +8,6 @@
      get_wrapper_html_attributes(); ?>> - desc; ?> + desc; ?>
      diff --git a/views/checkout/fields/field-password.php b/views/checkout/fields/field-password.php index 8ff3f00..1b64841 100644 --- a/views/checkout/fields/field-password.php +++ b/views/checkout/fields/field-password.php @@ -7,49 +7,57 @@ ?>
      get_wrapper_html_attributes(); ?>> - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - get_html_attributes(); ?>> + get_html_attributes(); ?>> - meter) : ?> + meter) : ?> - + - + - + - + - + - + - $field, - )); + /** + * Adds the partial error template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-errors', + array( + 'field' => $field, + ) + ); - ?> + ?> - +
      diff --git a/views/checkout/fields/field-payment-methods.php b/views/checkout/fields/field-payment-methods.php index a2214a8..9d10bbd 100644 --- a/views/checkout/fields/field-payment-methods.php +++ b/views/checkout/fields/field-payment-methods.php @@ -10,70 +10,79 @@ $active_gateways = wu_get_active_gateway_as_options(); ?>
      get_wrapper_html_attributes(); ?>> - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - $option_name) : ?> + $option_name) : ?> - + - get_html_attributes(); ?> - > + get_html_attributes(); ?> + > - + - - + - + - $field, - )); + /** + * Adds the partial error template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-errors', + array( + 'field' => $field, + ) + ); - /** - * Load Gateway fields - * @since 2.0.0 - */ - do_action('wu_checkout_gateway_fields'); + /** + * Load Gateway fields + * + * @since 2.0.0 + */ + do_action('wu_checkout_gateway_fields'); - ?> + ?>
      diff --git a/views/checkout/fields/field-products.php b/views/checkout/fields/field-products.php index 452cb3c..8b5b98a 100644 --- a/views/checkout/fields/field-products.php +++ b/views/checkout/fields/field-products.php @@ -7,40 +7,48 @@ ?>
      get_wrapper_html_attributes(); ?>> - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - + - - + - $field, - )); + /** + * Adds the partial error template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-errors', + array( + 'field' => $field, + ) + ); - ?> + ?>
      diff --git a/views/checkout/fields/field-radio.php b/views/checkout/fields/field-radio.php index 35940b8..b10b139 100644 --- a/views/checkout/fields/field-radio.php +++ b/views/checkout/fields/field-radio.php @@ -7,40 +7,48 @@ ?>
      get_wrapper_html_attributes(); ?>> - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - options as $option_value => $option_name) : ?> + options as $option_value => $option_name) : ?> - - + - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-errors', + array( + 'field' => $field, + ) + ); - ?> + ?>
      diff --git a/views/checkout/fields/field-select.php b/views/checkout/fields/field-select.php index 4bba6d5..6bf61ce 100644 --- a/views/checkout/fields/field-select.php +++ b/views/checkout/fields/field-select.php @@ -7,61 +7,69 @@ ?>
      get_wrapper_html_attributes(); ?>> - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - get_html_attributes(); ?> + > - placeholder) : ?> + placeholder) : ?> - + - + - options as $key => $label) : ?> + options as $key => $label) : ?> - + - + - options_template) : ?> + options_template) : ?> - options_template; ?> + options_template; ?> - + - + - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-errors', + array( + 'field' => $field, + ) + ); - ?> + ?>
      diff --git a/views/checkout/fields/field-submit.php b/views/checkout/fields/field-submit.php index f04f159..4247d21 100644 --- a/views/checkout/fields/field-submit.php +++ b/views/checkout/fields/field-submit.php @@ -7,10 +7,10 @@ ?>
      get_wrapper_html_attributes(); ?>> - +
      diff --git a/views/checkout/fields/field-text.php b/views/checkout/fields/field-text.php index 1d86bad..d990c36 100644 --- a/views/checkout/fields/field-text.php +++ b/views/checkout/fields/field-text.php @@ -7,54 +7,62 @@ ?>
      get_wrapper_html_attributes(); ?>> - $field, - )); + /** + * Adds the partial title template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-title', + array( + 'field' => $field, + ) + ); - ?> + ?> - prefix) : ?> + prefix) : ?> -
      +
      -
      prefix_html_attr ?? array()); ?>> - prefix; ?> -
      +
      prefix_html_attr ?? array()); ?>> + prefix; ?> +
      - + - get_html_attributes(); ?>> + get_html_attributes(); ?>> - suffix) : ?> + suffix) : ?> -
      suffix_html_attr ?? array()); ?>> - suffix; ?> -
      +
      suffix_html_attr ?? array()); ?>> + suffix; ?> +
      - + - prefix || $field->suffix) : ?> + prefix || $field->suffix) : ?> -
      +
      - + - $field, - )); + /** + * Adds the partial error template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-errors', + array( + 'field' => $field, + ) + ); - ?> + ?>
      diff --git a/views/checkout/fields/field-toggle.php b/views/checkout/fields/field-toggle.php index 0f1b3a5..29a33c0 100644 --- a/views/checkout/fields/field-toggle.php +++ b/views/checkout/fields/field-toggle.php @@ -7,28 +7,32 @@ ?>
      get_wrapper_html_attributes(); ?>> - - $field, - )); + /** + * Adds the partial error template. + * + * @since 2.0.0 + */ + wu_get_template( + 'checkout/fields/partials/field-errors', + array( + 'field' => $field, + ) + ); - ?> + ?>
      diff --git a/views/checkout/fields/form.php b/views/checkout/fields/form.php index d12580e..d1f7111 100644 --- a/views/checkout/fields/form.php +++ b/views/checkout/fields/form.php @@ -7,28 +7,28 @@ ?> wrap_in_form_tag) : ?> -
      get_html_attributes(); ?>> + get_html_attributes(); ?>> - <wrap_tag; ?> class="classes ? $form->classes.' '.$step->classes.' wu-mt-2' : $step->classes.' wu-mt-2')); ?>" get_html_attributes(); ?>> + <wrap_tag; ?> class="classes ? $form->classes . ' ' . $step->classes . ' wu-mt-2' : $step->classes . ' wu-mt-2')); ?>" get_html_attributes(); ?>> - title) : ?> + title) : ?> -

      title; ?>

      +

      title; ?>

      - + - + wrap_in_form_tag) : ?> -
      + - wrap_tag; ?>> + wrap_tag; ?>> diff --git a/views/checkout/fields/partials/field-description.php b/views/checkout/fields/partials/field-description.php index 5e80603..45eb84e 100644 --- a/views/checkout/fields/partials/field-description.php +++ b/views/checkout/fields/partials/field-description.php @@ -8,6 +8,7 @@ desc) : ?> - desc; ?> + desc; ?> - + diff --git a/views/checkout/fields/partials/field-title.php b/views/checkout/fields/partials/field-title.php index 22862d7..196e61f 100644 --- a/views/checkout/fields/partials/field-title.php +++ b/views/checkout/fields/partials/field-title.php @@ -8,18 +8,18 @@ title) : ?> - diff --git a/views/checkout/form.php b/views/checkout/form.php index abc9de2..737229d 100644 --- a/views/checkout/form.php +++ b/views/checkout/form.php @@ -10,7 +10,7 @@ id="wu_form" method="post" class="wu_checkout_form_ wu-relative" - + > $display_title ? $step['name'] : '', - 'views' => 'checkout/fields', - 'classes' => wu_get_isset($step, 'classes', '').' wu-grid wu-grid-cols-2 wu-gap-4', - 'field_wrapper_classes' => 'wu-col-span-2', - 'html_attr' => array( - 'id' => wu_get_isset($step, 'element_id') ? wu_get_isset($step, 'element_id') : "wu-step-{$step_name}", - ), - 'variables' => array( - 'step' => (object) $step, - ), - )); + $form = new \WP_Ultimo\UI\Form( + "checkout-{$step_name}", + $final_fields, + array( + 'title' => $display_title ? $step['name'] : '', + 'views' => 'checkout/fields', + 'classes' => wu_get_isset($step, 'classes', '') . ' wu-grid wu-grid-cols-2 wu-gap-4', + 'field_wrapper_classes' => 'wu-col-span-2', + 'html_attr' => array( + 'id' => wu_get_isset($step, 'element_id') ? wu_get_isset($step, 'element_id') : "wu-step-{$step_name}", + ), + 'variables' => array( + 'step' => (object) $step, + ), + ) + ); /** * Render form fields. diff --git a/views/checkout/partials/pricing-table-list.php b/views/checkout/partials/pricing-table-list.php index 83feb6e..48ef492 100644 --- a/views/checkout/partials/pricing-table-list.php +++ b/views/checkout/partials/pricing-table-list.php @@ -1,12 +1,12 @@ -
      +
      - + -
      +
      - + -
      get_id()}"; ?> wu-bg-gray-100 wu-m-2 wu-px-4 wu-py-4 wu-border wu-border-solid wu-rounded wu-border-gray-400 wu-box-border wu-flex-1 wu-flex wu-flex-col wu-justify-end" - > +
      get_id()}"; ?> wu-bg-gray-100 wu-m-2 wu-px-4 wu-py-4 wu-border wu-border-solid wu-rounded wu-border-gray-400 wu-box-border wu-flex-1 wu-flex wu-flex-col wu-justify-end" + > -
      +
      - get_name(); ?> - get_price_description(false); ?> + get_name(); ?> + get_price_description(false); ?> -
      +
      -
      +
      -
        - get_pricing_table_lines() as $key => $line) : ?> +
          + get_pricing_table_lines() as $key => $line) : ?> -
        • +
        • - -
        + +
      -
      +
      -
      + +
      - + -
      +
      - +
      diff --git a/views/checkout/paypal/confirm.php b/views/checkout/paypal/confirm.php index 35f206d..246b248 100644 --- a/views/checkout/paypal/confirm.php +++ b/views/checkout/paypal/confirm.php @@ -10,72 +10,52 @@ $is_trial_setup = $membership->is_trialing() && empty($payment->get_total()); $notes = array(); if ($is_trial_setup) { - $desc = $membership->get_recurring_description(); - $date = wp_date(get_option('date_format'), strtotime( $membership->get_date_trial_end(), wu_get_current_time('timestamp', true))); + $date = wp_date(get_option('date_format'), strtotime($membership->get_date_trial_end(), wu_get_current_time('timestamp', true))); $notes[] = sprintf(__('Your trial period will end on %1$s.', 'wp-ultimo'), $date); - } // end if; $original_cart = $payment->get_meta('wu_original_cart'); -$should_auto_renew = !empty($original_cart) ? $original_cart->should_auto_renew() : false; +$should_auto_renew = ! empty($original_cart) ? $original_cart->should_auto_renew() : false; $recurring_total = $membership->get_amount(); if ($membership->is_recurring() && $should_auto_renew) { - $payment_total = $payment->get_total() ? $payment->get_total() : $membership->get_initial_amount(); $desc = $membership->get_recurring_description(); if ($recurring_total !== $payment_total) { - $recurring_total_format = wu_format_currency($recurring_total, $payment->get_currency()); if ($original_cart->get_cart_type() === 'downgrade') { $subtotal = wu_format_currency($payment->get_subtotal(), $payment->get_currency()); if ($is_trial_setup) { - $notes[] = sprintf(__('Your updated membership will start on $1$s, from that date you will be billed %2$s %3$s.', 'wp-ultimo'), $date, $subtotal, $desc); - } else { - - $date_renew = wp_date(get_option('date_format'), strtotime( $membership->get_date_expiration(), wu_get_current_time('timestamp', true))); + $date_renew = wp_date(get_option('date_format'), strtotime($membership->get_date_expiration(), wu_get_current_time('timestamp', true))); $notes[] = sprintf(__('Your updated membership will start on %1$s, from that date you will be billed %2$s %3$s.', 'wp-ultimo'), $date_renew, $subtotal, $desc); - } // end if; } elseif ($is_trial_setup) { - $initial_amount_format = wu_format_currency($membership->get_initial_amount(), $payment->get_currency()); $notes[] = sprintf(__('After the first payment of %1$s you will be billed %2$s %3$s.', 'wp-ultimo'), $initial_amount_format, $recurring_total_format, $desc); - } else { - $notes[] = sprintf(__('After this payment you will be billed %1$s %2$s.', 'wp-ultimo'), $recurring_total_format, $desc); - } // end if; - } else { - $recurring_total_format = wu_format_currency($recurring_total, $payment->get_currency()); if ($is_trial_setup) { - $notes[] = sprintf(__('From that date, you will be billed %1$s %2$s.', 'wp-ultimo'), $recurring_total_format, $desc); - } else { - $notes[] = sprintf(__('After this payment you will be billed %1$s.', 'wp-ultimo'), $desc); - } // end if; - } // end if; - } // end if; $note = implode(' ', $notes); @@ -90,7 +70,7 @@ $subtotal = 0;
      - +
      @@ -112,7 +92,7 @@ $subtotal = 0; get_line_items() as $line_item) : + foreach ($payment->get_line_items() as $line_item) : $subtotal += $line_item->get_subtotal(); ?> @@ -152,7 +132,7 @@ $subtotal = 0; - +
      diff --git a/views/checkout/register.php b/views/checkout/register.php index 1457a63..24369e2 100644 --- a/views/checkout/register.php +++ b/views/checkout/register.php @@ -1,24 +1,28 @@
      - __('Products', 'wp-ultimo'), - 'views' => 'checkout/fields', - )); + /** + * Instantiate the form for the order details. + * + * @since 2.0.0 + */ + $order_form = new \WP_Ultimo\UI\Form( + 'product-fields', + $product_fields, + array( + 'title' => __('Products', 'wp-ultimo'), + 'views' => 'checkout/fields', + ) + ); - /** - * Render form fields. - * - * @see /view/checkout/fields/ for the template files for each field type. - * @since 2.0.0 - */ - $order_form->render(); + /** + * Render form fields. + * + * @see /view/checkout/fields/ for the template files for each field type. + * @since 2.0.0 + */ + $order_form->render(); /** * Instantiate the form for the submit button and such. diff --git a/views/checkout/templates/order-bump/simple.php b/views/checkout/templates/order-bump/simple.php index 7517699..5ee7778 100644 --- a/views/checkout/templates/order-bump/simple.php +++ b/views/checkout/templates/order-bump/simple.php @@ -13,58 +13,59 @@ $product = wu_get_product($product['id']); $product_variation = $product->get_as_variation($duration, $duration_unit); if ($product_variation !== false) { - - $product = $product_variation; - + $product = $product_variation; } // end if; ?>
      -
      +
      - get_featured_image('thumbnail'); ?> + get_featured_image('thumbnail'); + ?> - + -
      - -
      +
      + +
      - + - + -
      - get_name() : $name; ?> +
      + get_name() : $name; ?> - get_description()) : ?> -
      -

      - get_description(); ?> -

      -
      - + get_description()) : ?> +
      +

      + get_description(); ?> +

      +
      + -
      -

      - get_price_description(); ?> -

      -
      -
      -
      +
      +

      + get_price_description(); ?> +

      +
      +
      +
      -
      - -
      -
      - - -
      +
      + +
      +
      + + +
      - +
      diff --git a/views/checkout/templates/order-summary/simple.php b/views/checkout/templates/order-summary/simple.php index 083a8e1..76e1724 100644 --- a/views/checkout/templates/order-summary/simple.php +++ b/views/checkout/templates/order-summary/simple.php @@ -7,264 +7,265 @@ ?>
      -
      +
      - + -
      +
      -
      +
      - +
      - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + -
      - - + + - - + + - - + + - - + + - - + + - - + +
      + - + -
      + - + - + - + - + - + - + - + - {{ line_item.title }} + {{ line_item.title }} - + - + - + - + - + - + - {{ wu_format_money(line_item.subtotal) }} / {{ line_item.recurring_description }} + {{ wu_format_money(line_item.subtotal) }} / {{ line_item.recurring_description }} - + - {{ wu_format_money(line_item.subtotal) }} + {{ wu_format_money(line_item.subtotal) }} - + - {{ wu_format_money(line_item.subtotal) }} / {{ line_item.recurring_description }} + {{ wu_format_money(line_item.subtotal) }} / {{ line_item.recurring_description }} - + - {{ wu_format_money(line_item.subtotal) }} + {{ wu_format_money(line_item.subtotal) }} - + - {{ wu_format_money(line_item.discount_total) }} + {{ wu_format_money(line_item.discount_total) }} - + - {{ wu_format_money(line_item.tax_total) }} + {{ wu_format_money(line_item.tax_total) }} - + - {{ line_item.tax_label }} {{ line_item.tax_rate }}% + {{ line_item.tax_label }} {{ line_item.tax_rate }}% - + - + - {{ wu_format_money(line_item.total) }} + {{ wu_format_money(line_item.total) }} -
      + - + - + - {{ wu_format_money(order.totals.total_discounts) }} + {{ wu_format_money(order.totals.total_discounts) }} -
      + - + - + - {{ wu_format_money(order.totals.total_taxes) }} + {{ wu_format_money(order.totals.total_taxes) }} -
      + - + - + - {{ wu_format_money(0) }} + {{ wu_format_money(0) }} - + - {{ wu_format_money(order.totals.total) }} + {{ wu_format_money(order.totals.total) }} -
      + - - - + + + - + - {{ wu_format_money(order.totals.total) }} + {{ wu_format_money(order.totals.total) }} -
      + - -
      +
      diff --git a/views/checkout/templates/period-selection/clean.php b/views/checkout/templates/period-selection/clean.php index 29bba1e..2fcaab3 100644 --- a/views/checkout/templates/period-selection/clean.php +++ b/views/checkout/templates/period-selection/clean.php @@ -21,18 +21,18 @@ defined('ABSPATH') || exit; ?>
        - $period_option) : ?> + $period_option) : ?> -
      • - - - -
      • +
      • + + + +
      • - +
      diff --git a/views/checkout/templates/period-selection/legacy.php b/views/checkout/templates/period-selection/legacy.php index 2172dfe..1407bd9 100644 --- a/views/checkout/templates/period-selection/legacy.php +++ b/views/checkout/templates/period-selection/legacy.php @@ -22,18 +22,18 @@ defined('ABSPATH') || exit;
      -
        +
          - $period_option) : ?> + $period_option) : ?> -
        • - - - -
        • +
        • + + + +
        • - + -
        +
      diff --git a/views/checkout/templates/pricing-table/legacy.php b/views/checkout/templates/pricing-table/legacy.php index 7b43086..72e2d80 100644 --- a/views/checkout/templates/pricing-table/legacy.php +++ b/views/checkout/templates/pricing-table/legacy.php @@ -15,31 +15,34 @@ $products_to_reduce = array_merge(array(false), $products); -$first_recurring_product = array_reduce($products_to_reduce, function($chosen_product, $product) { +$first_recurring_product = array_reduce( + $products_to_reduce, + function ($chosen_product, $product) { - if ($product && $product->is_recurring() && $chosen_product == false) { + if ($product && $product->is_recurring() && $chosen_product == false) { + $chosen_product = $product; + } // end if; - $chosen_product = $product; + return $chosen_product; + } +); - } // end if; +$legacy_mode = array_reduce( + $products_to_reduce, + function ($all_have_same_duration, $product) use ($first_recurring_product) { - return $chosen_product; + if ($product && $product->is_recurring()) { + $all_have_same_duration = $first_recurring_product->get_recurring_description() == $product->get_recurring_description(); + } // end if; -}); + return $all_have_same_duration; + } +); -$legacy_mode = array_reduce($products_to_reduce, function($all_have_same_duration, $product) use ($first_recurring_product) { - - if ($product && $product->is_recurring()) { - - $all_have_same_duration = $first_recurring_product->get_recurring_description() == $product->get_recurring_description(); - - } // end if; - - return $all_have_same_duration; - -}); - -wp_add_inline_script('wu-checkout', sprintf(' +wp_add_inline_script( + 'wu-checkout', + sprintf( + ' /** * Force different durations. @@ -48,11 +51,18 @@ wp_add_inline_script('wu-checkout', sprintf(' window.wu_legacy_mode = %s; -', json_encode($force_different_durations), json_encode($legacy_mode)), 'after'); +', + json_encode($force_different_durations), + json_encode($legacy_mode) + ), + 'after' +); if ($first_recurring_product !== null) { - - wp_add_inline_script('wu-checkout', sprintf(" + wp_add_inline_script( + 'wu-checkout', + sprintf( + " /** * Add durations if necessary. @@ -78,8 +88,12 @@ if ($first_recurring_product !== null) { }); - ", json_encode($first_recurring_product->get_duration()), json_encode($first_recurring_product->get_duration_unit())), 'after'); - + ", + json_encode($first_recurring_product->get_duration()), + json_encode($first_recurring_product->get_duration_unit()) + ), + 'after' + ); } ?> @@ -93,281 +107,267 @@ if ($first_recurring_product !== null) { -
      +
      -
      +
      - + -
      get_id()}"; ?> lift wu-plan plan-tier wu-flex-1 is_featured_plan() ? 'callout' : ''); ?> wu-flex wu-flex-col wu-justify-between" - v-show="wu_force_different_durations || (duration && wu_legacy_mode) || (( (!duration) || duration == get_duration(); ?> && duration_unit == 'get_duration_unit(); ?>' ) || get_pricing_type() !== 'paid'); ?>)" - > +
      get_id()}"; ?> lift wu-plan plan-tier wu-flex-1 is_featured_plan() ? 'callout' : ''); ?> wu-flex wu-flex-col wu-justify-between" + v-show="wu_force_different_durations || (duration && wu_legacy_mode) || (( (!duration) || duration == get_duration(); ?> && duration_unit == 'get_duration_unit(); ?>' ) || get_pricing_type() !== 'paid'); ?>)" + > -
      +
      - is_featured_plan()) : ?> + is_featured_plan()) : ?> -
      +
      - + ?> -
      + - + -

      +

      - get_name(); ?> + get_name(); ?> -

      + - get_pricing_type() === 'free') : + /** + * Case Free + */ + if ($product->get_pricing_type() === 'free') : - ?> + ?> - -
      + +
      - + - + - + -
      + - get_pricing_type() === 'contact_us') : + /** + * Case Free + */ + elseif ($product->get_pricing_type() === 'contact_us') : - ?> + ?> - -
      + +
      - + - + - + -
      + - + - -
      + +
      - + ?> - + - + - get_currency()); ?> + get_currency()); ?> - + - + - + - get_amount(); + $n = $product->get_amount(); - echo str_replace(wu_get_currency_symbol(), '', wu_format_currency($n)); + echo str_replace(wu_get_currency_symbol(), '', wu_format_currency($n)); - ?> + ?> - + - get_price_variation($freq, 'month'); - $price_variation = $product->get_price_variation($freq, 'month'); + if ( ! $price_variation) { + continue; + } // end if; - if (!$price_variation) { + ?> - continue; + - } // end if; + + $n = $price_variation ? $price_variation['monthly_amount'] : false; - + if ($n) { + echo str_replace(wu_get_currency_symbol(), '', wu_format_currency($n)); + } else { + echo '--'; + } // end if; - - $n = $price_variation ? $price_variation['monthly_amount'] : false; - - if ($n) { - - echo str_replace(wu_get_currency_symbol(), '', wu_format_currency($n)); - - } else { - - echo '--'; - - } // end if; - - ?> - - - - - - - - is_recurring() ? __('/mo', 'wp-ultimo') : ''; - - echo (!$symbol_left ? wu_get_currency_symbol() : '').' '.$symbol; - - ?> - - - - - - is_recurring() ? $product->get_recurring_description() : ''; - - echo (!$symbol_left ? wu_get_currency_symbol() : '').' '.$symbol; - - ?> - - - -
      - - - - -

      - - get_description(); ?> - -

      - -
      - -
      - - -
        - - __('every 3 months', 'wp-ultimo'), - 12 => __('yearly', 'wp-ultimo'), - ); - - foreach ($prices_total as $freq => $string) { - - $price_variation = $product->get_price_variation($freq, 'month'); - - if (!$price_variation || $product->get_pricing_type() == 'free' || $product->get_pricing_type() == 'contact_us') { - - echo "
      • -
      • "; - - } else { - - $text = sprintf(__('%1$s, billed %2$s', 'wp-ultimo'), wu_format_currency($price_variation['amount']), $string); - - $extra_check_for_annual = ''; - - if ($freq === 12) { - - $extra_check_for_annual = ' || (duration == "1" && duration_unit == "year")'; - - } // end if; - - echo "
      • $text
      • "; - - } // end if; - - } // end foreach; - - ?> - - get_pricing_table_lines() as $key => $line) : ?> - -
      • - - - -
      • - - - - - -
      • - -
      - - -
      + -
      - -
      + + + is_recurring() ? __('/mo', 'wp-ultimo') : ''; + + echo (! $symbol_left ? wu_get_currency_symbol() : '') . ' ' . $symbol; + + ?> + + + + + + is_recurring() ? $product->get_recurring_description() : ''; + + echo (! $symbol_left ? wu_get_currency_symbol() : '') . ' ' . $symbol; + + ?> + + + + + + + + +

      + + get_description(); ?> + +

      + +
      + +
      + + +
        + + __('every 3 months', 'wp-ultimo'), + 12 => __('yearly', 'wp-ultimo'), + ); + + foreach ($prices_total as $freq => $string) { + $price_variation = $product->get_price_variation($freq, 'month'); + + if ( ! $price_variation || $product->get_pricing_type() == 'free' || $product->get_pricing_type() == 'contact_us') { + echo "
      • -
      • "; + } else { + $text = sprintf(__('%1$s, billed %2$s', 'wp-ultimo'), wu_format_currency($price_variation['amount']), $string); + + $extra_check_for_annual = ''; + + if ($freq === 12) { + $extra_check_for_annual = ' || (duration == "1" && duration_unit == "year")'; + } // end if; + + echo "
      • $text
      • "; + } // end if; + } // end foreach; + + ?> + + get_pricing_table_lines() as $key => $line) : ?> + +
      • + + + +
      • + + + + + +
      • + +
      + + +
      + + + +
      + +
      diff --git a/views/checkout/templates/pricing-table/list.php b/views/checkout/templates/pricing-table/list.php index a7bb358..2df2350 100644 --- a/views/checkout/templates/pricing-table/list.php +++ b/views/checkout/templates/pricing-table/list.php @@ -9,63 +9,59 @@ * Deal with different pricing options */ foreach ($products as $index => &$_product) { + $_product = wu_get_product($_product['id']); - $_product = wu_get_product($_product['id']); + $product_variation = $_product->get_as_variation($duration, $duration_unit); - $product_variation = $_product->get_as_variation($duration, $duration_unit); - - if ($product_variation === false && !$force_different_durations) { - - unset($products[$index]); - - $_product = $product_variation; - - } // end if; + if ($product_variation === false && ! $force_different_durations) { + unset($products[ $index ]); + $_product = $product_variation; + } // end if; } // end foreach; ?>
      -
      +
      - + - - + -
      +
      diff --git a/views/checkout/templates/steps/clean.php b/views/checkout/templates/steps/clean.php index 54154f6..dbb72c4 100644 --- a/views/checkout/templates/steps/clean.php +++ b/views/checkout/templates/steps/clean.php @@ -15,48 +15,45 @@ * @version 1.4.0 */ -if (!defined('ABSPATH')) { - exit; // Exit if accessed directly +if ( ! defined('ABSPATH')) { + exit; // Exit if accessed directly } ?> diff --git a/views/checkout/templates/steps/legacy.php b/views/checkout/templates/steps/legacy.php index 1c31342..bd13c2f 100644 --- a/views/checkout/templates/steps/legacy.php +++ b/views/checkout/templates/steps/legacy.php @@ -15,42 +15,39 @@ * @version 1.4.0 */ -if (!defined('ABSPATH')) { - exit; // Exit if accessed directly +if ( ! defined('ABSPATH')) { + exit; // Exit if accessed directly } ?>
        - $step) : + $step) : + $step_key = $step['id']; - $step_key = $step['id']; + /** + * Class element of the Step Status Bar + * + * @var string + */ + $class = ''; - /** - * Class element of the Step Status Bar - * @var string - */ - $class = ''; + if ($step_key === $current_step) { + $class = 'active'; + } elseif (array_search($current_step, array_column($steps, 'id')) > array_search($step_key, array_column($steps, 'id'))) { + $class = 'done'; + } // end if; - if ($step_key === $current_step) { + ?> - $class = 'active'; +
      1. - } elseif (array_search($current_step, array_column($steps, 'id')) > array_search($step_key, array_column($steps, 'id'))) { + - $class = 'done'; +
      2. - } // end if; - - ?> - -
      3. - - - -
      4. - - +
      diff --git a/views/checkout/templates/steps/minimal.php b/views/checkout/templates/steps/minimal.php index b463000..7996d6c 100644 --- a/views/checkout/templates/steps/minimal.php +++ b/views/checkout/templates/steps/minimal.php @@ -15,46 +15,43 @@ * @version 1.4.0 */ -if (!defined('ABSPATH')) { - exit; // Exit if accessed directly +if ( ! defined('ABSPATH')) { + exit; // Exit if accessed directly } ?> diff --git a/views/checkout/templates/template-selection/clean.php b/views/checkout/templates/template-selection/clean.php index 6d57cb9..b45ceda 100644 --- a/views/checkout/templates/template-selection/clean.php +++ b/views/checkout/templates/template-selection/clean.php @@ -16,14 +16,13 @@ // Exit if accessed directly defined('ABSPATH') || exit; -if (isset($should_display) && !$should_display) { +if (isset($should_display) && ! $should_display) { - ?> -
      - +
      + -
        +
          -
        • - - - -
        • +
        • + + + +
        • - + -
        • - -
        • +
        • + +
        • - + - + - + -
        • - -
        • +
        • + +
        • - + - + -
        +
      -
      +
      - + - get_type() !== 'site_template' && !in_array($site_template->get_id(), $customer_sites, true)) { continue; } ?> + get_type() !== 'site_template' && ! in_array($site_template->get_id(), $customer_sites, true)) { + continue; } + ?> - get_type() === 'site_template'; ?> + get_type() === 'site_template'; ?> - get_categories(), !$is_template ? array($customer_sites_category) : array()); ?> + get_categories(), ! $is_template ? array($customer_sites_category) : array()); ?> - - + -
      +
      diff --git a/views/checkout/templates/template-selection/legacy.php b/views/checkout/templates/template-selection/legacy.php index dce601e..ab1b2fa 100644 --- a/views/checkout/templates/template-selection/legacy.php +++ b/views/checkout/templates/template-selection/legacy.php @@ -16,12 +16,10 @@ // Exit if accessed directly defined('ABSPATH') || exit; -if (!$should_display) { - - echo "
      "; - - return; +if ( ! $should_display) { + echo '
      '; + return; } // end if; $sites = array_map('wu_get_site', isset($sites) ? $sites : array()); @@ -37,7 +35,7 @@ $customer_sites = isset($customer_sites) ? array_map('intval', $customer_sites)
      @@ -48,217 +46,219 @@ $customer_sites = isset($customer_sites) ? array_map('intval', $customer_sites)
      -
      +
      - -

      +

      - + - + - + - + -

      + - + -
      +
      -
      +
      -

      +

      - - + - + - + - + - + - + - + - + -
      +
      - -
      +
      -
      +
      -
      +
      - + - get_type() !== 'site_template' && !in_array($site->get_id(), $customer_sites, true)) { continue; } ?> + get_type() !== 'site_template' && ! in_array($site->get_id(), $customer_sites, true)) { + continue; } + ?> - get_type() === 'site_template'; ?> + get_type() === 'site_template'; ?> - get_categories(), !$is_template ? array($customer_sites_category) : array()) ?> + get_categories(), ! $is_template ? array($customer_sites_category) : array()); ?> - - + + ++$i; + endforeach; -
      + ?> -
      +
      -

      +

      - - -

      +
      -
      +

      + + + +

      + +
      diff --git a/views/checkout/templates/template-selection/minimal.php b/views/checkout/templates/template-selection/minimal.php index 4978a06..b6897b9 100644 --- a/views/checkout/templates/template-selection/minimal.php +++ b/views/checkout/templates/template-selection/minimal.php @@ -18,10 +18,8 @@ // Exit if accessed directly defined('ABSPATH') || exit; -if (!$should_display) { - - return; - +if ( ! $should_display) { + return; } // end if; $sites = array_map('wu_get_site', isset($sites) ? $sites : array()); @@ -35,107 +33,110 @@ $customer_sites = isset($customer_sites) ? array_map('intval', $customer_sites) ?>
      -
        +
          -
        • - - - -
        • +
        • + + + +
        • - + -
        • - -
        • +
        • + +
        • - + - + - + -
        • - -
        • +
        • + +
        • - + - + -
        +
      -
      +
      - + - get_type() !== 'site_template' && !in_array($site_template->get_id(), $customer_sites, true)) { continue; } ?> + get_type() !== 'site_template' && ! in_array($site_template->get_id(), $customer_sites, true)) { + continue; } + ?> - get_type() === 'site_template'; ?> + get_type() === 'site_template'; ?> - get_categories(), !$is_template ? array($customer_sites_category) : array()); ?> + get_categories(), ! $is_template ? array($customer_sites_category) : array()); ?> -
      +
      - <?php echo $site_template->get_title(); ?> + <?php echo $site_template->get_title(); ?> -

      +

      - get_title(); ?> + get_title(); ?> -

      + -

      +

      - get_description(); ?> + get_description(); ?> -

      +

      - - -
      +
      - + -
      +
      diff --git a/views/customers/widget-avatar.php b/views/customers/widget-avatar.php index 0465c55..5b878ae 100644 --- a/views/customers/widget-avatar.php +++ b/views/customers/widget-avatar.php @@ -7,71 +7,86 @@ ?>
      -
      +
      -
      -   -
      +
      +   +
      -
      +
      - ID, 86, 'identicon', '', array( - 'force_display' => true, - 'class' => 'wu-rounded-full wu-border wu-border-solid wu-border-gray-300 wu-relative', - )); ?> + ID, + 86, + 'identicon', + '', + array( + 'force_display' => true, + 'class' => 'wu-rounded-full wu-border wu-border-solid wu-border-gray-300 wu-relative', + ) + ); + ?> -
      +
      -
      +
      -
      - display_name; ?> -
      +
      + display_name; ?> +
      - -
      +
      - ID !== get_current_user_id()) : ?> + ID !== get_current_user_id()) : ?> - - - + + + - + - + - + - + - + - + -
      +
      -
      +
      -
      +
      diff --git a/views/dashboard-statistics/filter.php b/views/dashboard-statistics/filter.php index 7c72e99..4b054da 100644 --- a/views/dashboard-statistics/filter.php +++ b/views/dashboard-statistics/filter.php @@ -7,58 +7,60 @@ ?>
      - - + -
      diff --git a/views/dashboard-statistics/widget-countries.php b/views/dashboard-statistics/widget-countries.php index 42cde6c..738d118 100644 --- a/views/dashboard-statistics/widget-countries.php +++ b/views/dashboard-statistics/widget-countries.php @@ -11,29 +11,29 @@ $count) { + $line = array( + wu_get_country_name($country_code), + $count, + ); - $line = array( - wu_get_country_name($country_code), - $count, - ); - - $data[] = $line; - + $data[] = $line; } // end foreach; -$page->render_csv_button(array( - 'headers' => $headers, - 'data' => $data, - 'slug' => $slug, -)); +$page->render_csv_button( + array( + 'headers' => $headers, + 'data' => $data, + 'slug' => $slug, + ) +); ?> @@ -41,77 +41,81 @@ $page->render_csv_button(array(
      - + -
      +
      - +
      - - - - - - + + + + + + - + - $count) : ?> + $count) : ?> - - - - + ?> + + + + - + ?> - $state_count) : $_state_count = $_state_count + $state_count; ?> + $state_count) : + $_state_count = $_state_count + $state_count; + ?> - - - - + + + + - + - = 0) : ?> + = 0) : ?> - - - - + + + + - + - + - + -
      - + + ', - strtolower($country_code), - wu_tooltip_text(wu_get_country_name($country_code)) - ); + printf( + '', + strtolower($country_code), + wu_tooltip_text(wu_get_country_name($country_code)) + ); - ?> - -
      |⟶
      |⟶
      |⟶
      |⟶
      + -
      +
      -
      +
      - + -
      +
      diff --git a/views/dashboard-statistics/widget-forms.php b/views/dashboard-statistics/widget-forms.php index 85dbbda..bf6029c 100644 --- a/views/dashboard-statistics/widget-forms.php +++ b/views/dashboard-statistics/widget-forms.php @@ -12,29 +12,29 @@ signup_form, + $form->count, + ); - $line = array( - $form->signup_form, - $form->count, - ); - - $data[] = $line; - + $data[] = $line; } // end foreach; -$page->render_csv_button(array( - 'headers' => $headers, - 'data' => $data, - 'slug' => $slug, -)); +$page->render_csv_button( + array( + 'headers' => $headers, + 'data' => $data, + 'slug' => $slug, + ) +); ?> @@ -42,47 +42,47 @@ $page->render_csv_button(array(
      - + -
      +
      - +
      - - - - - - + + + + + + - + - + - - - - + + + + - + - + -
      - signup_form; ?> - signup_form === 'by-admin') : ?> - - - count; ?>
      + signup_form; ?> + signup_form === 'by-admin') : ?> + + + count; ?>
      + -
      +
      -
      +
      - + -
      +
      diff --git a/views/dashboard-statistics/widget-most-visited-sites.php b/views/dashboard-statistics/widget-most-visited-sites.php index 38449bb..03352f2 100644 --- a/views/dashboard-statistics/widget-most-visited-sites.php +++ b/views/dashboard-statistics/widget-most-visited-sites.php @@ -20,8 +20,7 @@ $headers = array( ); foreach ($sites as $site_visits) { - - $site_line = $site_visits->site->get_title().' '.get_admin_url($site_visits->site->get_id()); + $site_line = $site_visits->site->get_title() . ' ' . get_admin_url($site_visits->site->get_id()); $line = array( $site_line, @@ -29,14 +28,15 @@ foreach ($sites as $site_visits) { ); $data[] = $line; - } // end foreach; -$page->render_csv_button(array( - 'headers' => $headers, - 'data' => $data, - 'slug' => $slug, -)); +$page->render_csv_button( + array( + 'headers' => $headers, + 'data' => $data, + 'slug' => $slug, + ) +); ?> @@ -44,66 +44,66 @@ $page->render_csv_button(array(
      - + -
      +
      - +
      - - - - - - + + + + + + - + - + - - + - - + + + + - + - + -
      - - site->get_title(); ?> - +
      + + site->get_title(); ?> + - - count, 'wp-ultimo'), $site_visits->count); ?> -
      + count, 'wp-ultimo'), $site_visits->count); ?> +
      + -
      +
      -
      +
      - + -
      +
      diff --git a/views/dashboard-statistics/widget-mrr-growth.php b/views/dashboard-statistics/widget-mrr-growth.php index cf23ccb..5f5b773 100644 --- a/views/dashboard-statistics/widget-mrr-growth.php +++ b/views/dashboard-statistics/widget-mrr-growth.php @@ -7,26 +7,26 @@ ?>
      -
      +
      - + - + - + -
      +
      -
      - - -
      +
      + + +
      diff --git a/views/dashboard-statistics/widget-new-accounts.php b/views/dashboard-statistics/widget-new-accounts.php index 3cebe15..e292e60 100644 --- a/views/dashboard-statistics/widget-new-accounts.php +++ b/views/dashboard-statistics/widget-new-accounts.php @@ -7,69 +7,69 @@ ?>
      -
        +
          -
        • +
        • -
          +
          - - - + + + -
          +
          -
          - -
          +
          + +
          -
        • + -
        +
      -
      +
      - +
      - - - - - - + + + + + + - + - + - + - - - - + + + + - + - + - - - + + + - + - + -
      - name; ?> - - count; ?> -
      + name; ?> + + count; ?> +
      - -
      + +
      + -
      +
      diff --git a/views/dashboard-statistics/widget-revenue.php b/views/dashboard-statistics/widget-revenue.php index 8de8cb1..f01ac0f 100644 --- a/views/dashboard-statistics/widget-revenue.php +++ b/views/dashboard-statistics/widget-revenue.php @@ -7,100 +7,100 @@ ?>
      -
        +
          -
        • > +
        • > -
          +
          - - - + + + -
          +
          -
          - -
          +
          + +
          -
        • + -
        • +
        • -
          +
          - - - + + + -
          +
          -
          - -
          +
          + +
          -
        • + -
        • +
        • -
          +
          - - - + + + -
          +
          -
          - -
          +
          + +
          -
        • + -
        +
      -
      +
      - +
      - - - - - - + + + + + + - + - + - + - - - - + + + + - + - + - - - + + + - + - + -
      - - - -
      + + + +
      - -
      + +
      + -
      +
      diff --git a/views/dashboard-statistics/widget-tax-by-code.php b/views/dashboard-statistics/widget-tax-by-code.php index 11171de..8893fde 100644 --- a/views/dashboard-statistics/widget-tax-by-code.php +++ b/views/dashboard-statistics/widget-tax-by-code.php @@ -7,88 +7,88 @@ ?>
      -
      +
      - render_csv_button( + array( + 'headers' => $headers, + 'data' => $data, + 'slug' => $slug, + ) + ); - } // end foreach; + ?> - $page->render_csv_button(array( - 'headers' => $headers, - 'data' => $data, - 'slug' => $slug - )); + - ?> + + + + + + + + -
      + - - - - - - - - + - + - + + + + + + - + - - - - - - + - + + + - + - - - + - +
      + + + % + + + + +
      - - - % - - - - -
      + +
      - -
      - - - - -
      +
      diff --git a/views/dashboard-statistics/widget-tax-by-day.php b/views/dashboard-statistics/widget-tax-by-day.php index 980dd3f..e8cbb60 100644 --- a/views/dashboard-statistics/widget-tax-by-day.php +++ b/views/dashboard-statistics/widget-tax-by-day.php @@ -7,12 +7,12 @@ ?>
      -
      +
      - $tax_line) { - $line = array( date_i18n(get_option('date_format'), strtotime($day)), $tax_line['order_count'], wu_format_currency($tax_line['total']), wu_format_currency($tax_line['tax_total']), - wu_format_currency($tax_line['net_profit']) + wu_format_currency($tax_line['net_profit']), ); - $data[] = $line; - + $data[] = $line; } // end foreach; - $page->render_csv_button(array( - 'headers' => $headers, - 'data' => $data, - 'slug' => $slug - )); + $page->render_csv_button( + array( + 'headers' => $headers, + 'data' => $data, + 'slug' => $slug, + ) + ); ?> - +
      - - - - - - - - - + + + + + + + + + - + - + - $tax_line) : ?> + $tax_line) : ?> - - - - - - - + + + + + + + - + - + - - - + + + - + - + -
      - - - - - - - - - -
      + + + + + + + + + +
      - -
      + +
      + -
      +
      diff --git a/views/dashboard-statistics/widget-tax-graph.php b/views/dashboard-statistics/widget-tax-graph.php index cf23ccb..5f5b773 100644 --- a/views/dashboard-statistics/widget-tax-graph.php +++ b/views/dashboard-statistics/widget-tax-graph.php @@ -7,26 +7,26 @@ ?>
      -
      +
      - + - + - + -
      +
      -
      - - -
      +
      + + +
      diff --git a/views/dashboard-statistics/widget-taxes.php b/views/dashboard-statistics/widget-taxes.php index cf23ccb..5f5b773 100644 --- a/views/dashboard-statistics/widget-taxes.php +++ b/views/dashboard-statistics/widget-taxes.php @@ -7,26 +7,26 @@ ?>
      -
      +
      - + - + - + -
      +
      -
      - - -
      +
      + + +
      diff --git a/views/dashboard-widgets/account-summary.php b/views/dashboard-widgets/account-summary.php index 14b38e3..ea7ea8e 100644 --- a/views/dashboard-widgets/account-summary.php +++ b/views/dashboard-widgets/account-summary.php @@ -7,119 +7,119 @@ ?>
      -
      +
      - -
      + +
      - + -

      +

      - + -

      + - + - + -
      + +
      - + -
      - +
      + -
        +
          - + -
        • +
        • -
          +
          - + - get_name(); ?> + get_name(); ?> - + -
          +
          -
          - - -
          +
          + + +
          -
        • + - + - + -
        • +
        • -
          +
          - - - + + + -
          +
          -
          - - -
          +
          + + +
          -
        • + - + -
        • +
        • -
          +
          - - + - + - + - - % - + + % + - + -
          +
          -
          - - -
          +
          + + +
          -
        • + -
        +
      diff --git a/views/dashboard-widgets/activity-stream.php b/views/dashboard-widgets/activity-stream.php index 639b0d4..6e863e7 100644 --- a/views/dashboard-widgets/activity-stream.php +++ b/views/dashboard-widgets/activity-stream.php @@ -7,181 +7,181 @@ ?>
      -
      + +
      + +
      +
      + + -
    + -
    +
    - + -
    +
    -
    + - + diff --git a/views/dashboard-widgets/billing-info.php b/views/dashboard-widgets/billing-info.php index 97e7c92..fe9e653 100644 --- a/views/dashboard-widgets/billing-info.php +++ b/views/dashboard-widgets/billing-info.php @@ -7,175 +7,175 @@ ?>
    -
    +
    - + -
    +
    - -
    + +
    - + -

    +

    - + -

    + - + -
    + +
    -
    - +
    + - exists()) : ?> + exists()) : ?> -
    +
    -
    +
    - here to add one.', 'wp-ultimo'), __('Update Billing Address', 'wp-ultimo'), $update_billing_address_link); ?> + here to add one.', 'wp-ultimo'), __('Update Billing Address', 'wp-ultimo'), $update_billing_address_link); ?> -
    +
    -
    +
    - + -
    +
    - to_array(true) as $label => $value) : ?> + to_array(true) as $label => $value) : ?> -
    +
    -
    -
    -
    +
    +
    +
    -
    -
    +
    +
    -
    -
    -
    +
    +
    +
    -
    +
    - + -
    +
    - + -
    +
    - + - is_recurring() && false) : ?> + is_recurring() && false) : ?> - + -
    +
    - -
    + +
    - + -

    +

    - + -

    + - + -
    + +
    -
    - +
    + -
    +
    -
    +
    -
    +
    -

    Visa

    +

    Visa

    -
    +
    - + -
    +
    -
    - Ending with 4242 -
    +
    + Ending with 4242 +
    -
    +
    -
    - Expires 12/20 -
    +
    + Expires 12/20 +
    - + -
    - Last updated on 22 Aug 2017 -
    +
    + Last updated on 22 Aug 2017 +
    -
    +
    -
    +
    -
    +
    -
    +
    -
    +
    -
    +
    -
    +
    - + - + -
    +
    diff --git a/views/dashboard-widgets/current-membership-product-details.php b/views/dashboard-widgets/current-membership-product-details.php index 65acf80..3c86cff 100644 --- a/views/dashboard-widgets/current-membership-product-details.php +++ b/views/dashboard-widgets/current-membership-product-details.php @@ -8,58 +8,58 @@
    get_id()}-head"; ?> wu-bg-gray-100 wu-p-4 wu-flex wu-items-center"> -
    +
    - get_name(); ?> + get_name(); ?> - get_price_description(); ?> + get_price_description(); ?> -
    +
    - get_featured_image()) : ?> + get_featured_image()) : ?> -
    +
    - <?php echo esc_attr($product->get_name()); ?> + <?php echo esc_attr($product->get_name()); ?> -
    +
    - +
    get_id()}-description"; ?> wu-p-4 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b wu-border-gray-300 wu-border-solid"> - get_description()) : ?> + get_description()) : ?> - + - + - + -

    get_description(); ?>

    +

    get_description(); ?>

    - + - + - + - + -
      +
        - get_pricing_table_lines() as $key => $line) : ?> + get_pricing_table_lines() as $key => $line) : ?> -
      • +
      • - + -
      +
    diff --git a/views/dashboard-widgets/current-membership.php b/views/dashboard-widgets/current-membership.php index 6269b08..e96b2b1 100644 --- a/views/dashboard-widgets/current-membership.php +++ b/views/dashboard-widgets/current-membership.php @@ -7,347 +7,365 @@ ?>
    -
    +
    - -
    + +
    - + -

    +

    - + -

    + - + - + -
    + +
    - + -
    - +
    + - + - + -
    +
    -
    +
    -
    +
    - get_featured_image()) : ?> + get_featured_image()) : ?> -
    +
    - <?php echo esc_attr($plan->get_name()); ?> + <?php echo esc_attr($plan->get_name()); ?> -
    +
    - + -
    +
    - + - get_name(); ?> + get_name(); ?> - get_hash(); ?> + get_hash(); ?> - + - + - get_price_description(); ?> + get_price_description(); ?> - + -
    +
    -
    +
    - + -
    +
    -
    +
    - %1\$s. Changing to %2\$s.", 'wp-ultimo'), $pending_change_date, $pending_change); ?> + %1\$s. Changing to %2\$s.", 'wp-ultimo'), $pending_change_date, $pending_change); ?> -
    +
    -
    +
    - + -
    +
    -
    +
    - + - + - + -
    +
    -
    +
    -
    - -
    +
    + +
    -
    +
    - + - get_status_label(); ?> + get_status_label(); ?> - + -
    +
    -
    +
    -
    +
    -
    - -
    +
    + +
    -
    - get_initial_amount(), $membership->get_currency()) ?> -
    +
    + get_initial_amount(), $membership->get_currency()); ?> +
    -
    +
    - is_recurring()) : ?> + is_recurring()) : ?> -
    +
    -
    - -
    +
    + +
    -
    - get_times_billed_description(); ?> -
    +
    + get_times_billed_description(); ?> +
    -
    +
    - + - is_lifetime()) : ?> + is_lifetime()) : ?> -
    +
    -
    - -
    +
    + +
    -
    - get_formatted_date('date_expiration'); ?> -
    +
    + get_formatted_date('date_expiration'); ?> +
    -
    +
    - + -
    +
    - + -
    +
    - -
    +
    -
    +
    - -
    + +
    -

    +

    - + -

    + -
    - +
    + - has_addons()) : ?> + has_addons()) : ?> - - + -
    - -
    +
    + +
    - + -
    +
    - is_recurring()) : ?> + is_recurring()) : ?> - -
    + +
    -
    +
    - - - + + + - + - - get_amount(), $membership->get_currency()) ?> - + + get_amount(), $membership->get_currency())); ?> + - - get_recurring_description(); ?> - + + get_recurring_description()); ?> + -
    +
    -
    - +
    + - + - + -
    +
    diff --git a/views/dashboard-widgets/current-site.php b/views/dashboard-widgets/current-site.php index 6547d64..19e2436 100644 --- a/views/dashboard-widgets/current-site.php +++ b/views/dashboard-widgets/current-site.php @@ -7,144 +7,144 @@ ?>
    -
    +
    - + -
    +
    -
    +
    - -
    +
    -
    +
    - + -
    +
    -
    +
    - + -
    +
    - <?php printf(esc_attr__('Site Image: %s', 'wp-ultimo'), $current_site->get_title()); ?> + <?php printf(esc_attr__('Site Image: %s', 'wp-ultimo'), $current_site->get_title()); ?> -
    +
    - + -
    +
    -
    +
    - + - get_title(); ?> + get_title(); ?> - + - + - get_active_site_url(); ?> + get_active_site_url(); ?> - + - + - + - get_description(); ?> + get_description(); ?> - + - + - - + -
    +
    -
    +
    -
    +
    -
    +
    -
    +
    diff --git a/views/dashboard-widgets/domain-mapping.php b/views/dashboard-widgets/domain-mapping.php index ce768a1..288f92e 100644 --- a/views/dashboard-widgets/domain-mapping.php +++ b/views/dashboard-widgets/domain-mapping.php @@ -7,127 +7,129 @@ ?>
    -
    +
    - -
    + +
    - + -

    +

    - + -

    + - + -
    + +
    -
    - +
    + -
    +
    - +
    - + - + - $domain) : $item = $domain['domain_object']; ?> + $domain) : + $item = $domain['domain_object']; + ?> - + - - $second_row_actions['remove'] = array( - 'wrapper_classes' => 'wu-text-red-500 wubox', - 'icon' => 'dashicons-wu-trash-2 wu-align-middle wu-mr-1', - 'label' => '', - 'value' => __('Delete', 'wp-ultimo'), - 'url' => $domain['delete_link'], - ); + - echo wu_responsive_table_row(array( - 'id' => false, - 'title' => strtolower($item->get_domain()), - 'url' => false, - 'status' => $status, - ), array( - 'primary' => array( - 'wrapper_classes' => $item->is_primary_domain() ? 'wu-text-blue-600' : '', - 'icon' => $item->is_primary_domain() ? 'dashicons-wu-filter_1 wu-align-text-bottom wu-mr-1' : 'dashicons-wu-plus-square wu-align-text-bottom wu-mr-1', - 'label' => '', - 'value' => $item->is_primary_domain() ? __('Primary', 'wp-ultimo').wu_tooltip(__('All other mapped domains will redirect to the primary domain.', 'wp-ultimo'), 'dashicons-editor-help wu-align-middle wu-ml-1') : __('Alias', 'wp-ultimo'), - ), - 'secure' => array( - 'wrapper_classes' => $item->is_secure() ? 'wu-text-green-500' : '', - 'icon' => $item->is_secure() ? 'dashicons-wu-lock1 wu-align-text-bottom wu-mr-1' : 'dashicons-wu-lock1 wu-align-text-bottom wu-mr-1', - 'label' => '', - 'value' => $item->is_secure() ? __('Secure (HTTPS)', 'wp-ultimo') : __('Not Secure (HTTP)', 'wp-ultimo'), - ), - ), - $second_row_actions); + - ?> + - +
    + +
    - + - + - +
    + - get_stage_label(); + $label = $item->get_stage_label(); - if (!$item->is_active()) { + if ( ! $item->is_active()) { + $label = sprintf('%s (%s)', $label, __('Inactive', 'wp-ultimo')); + } // end if; - $label = sprintf('%s (%s)', $label, __('Inactive', 'wp-ultimo')); + $class = $item->get_stage_class(); - } // end if; + $status = "{$label}"; - $class = $item->get_stage_class(); + $second_row_actions = array(); - $status = "{$label}"; + if ( ! $item->is_primary_domain()) { + $second_row_actions['make_primary'] = array( + 'wrapper_classes' => 'wubox', + 'icon' => 'dashicons-wu-edit1 wu-align-middle wu-mr-1', + 'label' => '', + 'url' => $domain['primary_link'], + 'value' => __('Make Primary', 'wp-ultimo'), + ); + } // end if; - $second_row_actions = array(); + $second_row_actions['remove'] = array( + 'wrapper_classes' => 'wu-text-red-500 wubox', + 'icon' => 'dashicons-wu-trash-2 wu-align-middle wu-mr-1', + 'label' => '', + 'value' => __('Delete', 'wp-ultimo'), + 'url' => $domain['delete_link'], + ); - if (!$item->is_primary_domain()) { + echo wu_responsive_table_row( + array( + 'id' => false, + 'title' => strtolower($item->get_domain()), + 'url' => false, + 'status' => $status, + ), + array( + 'primary' => array( + 'wrapper_classes' => $item->is_primary_domain() ? 'wu-text-blue-600' : '', + 'icon' => $item->is_primary_domain() ? 'dashicons-wu-filter_1 wu-align-text-bottom wu-mr-1' : 'dashicons-wu-plus-square wu-align-text-bottom wu-mr-1', + 'label' => '', + 'value' => $item->is_primary_domain() ? __('Primary', 'wp-ultimo') . wu_tooltip(__('All other mapped domains will redirect to the primary domain.', 'wp-ultimo'), 'dashicons-editor-help wu-align-middle wu-ml-1') : __('Alias', 'wp-ultimo'), + ), + 'secure' => array( + 'wrapper_classes' => $item->is_secure() ? 'wu-text-green-500' : '', + 'icon' => $item->is_secure() ? 'dashicons-wu-lock1 wu-align-text-bottom wu-mr-1' : 'dashicons-wu-lock1 wu-align-text-bottom wu-mr-1', + 'label' => '', + 'value' => $item->is_secure() ? __('Secure (HTTPS)', 'wp-ultimo') : __('Not Secure (HTTP)', 'wp-ultimo'), + ), + ), + $second_row_actions + ); - $second_row_actions['make_primary'] = array( - 'wrapper_classes' => 'wubox', - 'icon' => 'dashicons-wu-edit1 wu-align-middle wu-mr-1', - 'label' => '', - 'url' => $domain['primary_link'], - 'value' => __('Make Primary', 'wp-ultimo'), - ); + ?> - } // end if; +
    -
    - -
    +
    - - - - - - -
    - -
    +
    diff --git a/views/dashboard-widgets/first-steps.php b/views/dashboard-widgets/first-steps.php index 23f274c..04e598c 100644 --- a/views/dashboard-widgets/first-steps.php +++ b/views/dashboard-widgets/first-steps.php @@ -7,93 +7,96 @@ ?>
    -
    +
    -
    +
    - - - + + + - - - + + + -
    +
    -
    +
    - - - + + + -
    +
    -
    +
    -
      +
        - $step) : ?> + $step) : ?> -
      • +
      • -
        - - - -
        +
        + + + +
        -
        +
        - + - + - + - + - + - + - + -
        +
        -
        +
        -
         
        +
         
        - - - + + + -
        +
        -
      • + - + -
      +
    - + -
    +
    - + -
    +
    - +
    diff --git a/views/dashboard-widgets/invoices.php b/views/dashboard-widgets/invoices.php index 41b283b..cf06c7c 100644 --- a/views/dashboard-widgets/invoices.php +++ b/views/dashboard-widgets/invoices.php @@ -7,87 +7,97 @@ ?>
    -
    +
    - + - + -
    +
    -

    +

    - + -

    + -
    +
    - + - + - +
    - + - get_payments(array('number' => !empty($limit) ? $limit : null)) as $payment) : ?> + get_payments(array('number' => ! empty($limit) ? $limit : null)) as $payment) : ?> - - + + - + - - + + - + - + -
    + - + $download_link = sprintf( + ' - ', $payment->get_invoice_url(), esc_attr__('Download Invoice', 'wp-ultimo')); + ', + $payment->get_invoice_url(), + esc_attr__('Download Invoice', 'wp-ultimo') + ); - $payment_column = $payment->get_status() === 'pending' ? array( - 'pay_now' => array( - 'url' => add_query_arg(array('payment' => $payment->get_hash()), wu_get_registration_url()), - 'icon' => 'dashicons-wu-credit-card wu-align-middle wu-mr-1', - 'label' => __('Go to payment', 'wp-ultimo'), - 'value' => __('Pay Now', 'wp-ultimo'), - ), - ) : array(); + $payment_column = $payment->get_status() === 'pending' ? array( + 'pay_now' => array( + 'url' => add_query_arg(array('payment' => $payment->get_hash()), wu_get_registration_url()), + 'icon' => 'dashicons-wu-credit-card wu-align-middle wu-mr-1', + 'label' => __('Go to payment', 'wp-ultimo'), + 'value' => __('Pay Now', 'wp-ultimo'), + ), + ) : array(); - echo wu_responsive_table_row(array( - 'url' => false, - 'title' => $payment->get_invoice_number().$download_link, - 'status' => wu_format_currency($payment->get_total(), $payment->get_currency()), - ), array_merge(array( - 'status' => array( - 'url' => false, - 'icon' => wu_get_payment_icon_classes($payment->get_status()).' wu-mr-1', - 'value' => $payment->get_status_label(), - )), - $payment_column - ), array( - 'date_created' => array( - 'url' => false, - 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', - 'label' => '', - 'value' => $payment->get_formatted_date('date_created'), - ), - )); + echo wu_responsive_table_row( + array( + 'url' => false, + 'title' => $payment->get_invoice_number() . $download_link, + 'status' => wu_format_currency($payment->get_total(), $payment->get_currency()), + ), + array_merge( + array( + 'status' => array( + 'url' => false, + 'icon' => wu_get_payment_icon_classes($payment->get_status()) . ' wu-mr-1', + 'value' => $payment->get_status_label(), + ), + ), + $payment_column + ), + array( + 'date_created' => array( + 'url' => false, + 'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1', + 'label' => '', + 'value' => $payment->get_formatted_date('date_created'), + ), + ) + ); - ?> + ?> -
    + -
    +
    diff --git a/views/dashboard-widgets/limits-and-quotas.php b/views/dashboard-widgets/limits-and-quotas.php index 97e4234..29b147d 100644 --- a/views/dashboard-widgets/limits-and-quotas.php +++ b/views/dashboard-widgets/limits-and-quotas.php @@ -7,143 +7,138 @@ ?>
    -
    +
    - -
    + +
    - + -

    +

    - + -

    + - + -
    - +
    + -
      +
        - is_enabled()) : ?> + is_enabled()) : ?> - get_id()); ?> + get_id()); ?> - $post_type) : ?> + $post_type) : ?> - {$post_type_slug}->enabled) : + $post_count = $post_type_limits->get_post_count($post_type_slug); - } // end if; + // Calculate width + if (empty($post_type_limits->{$post_type_slug}->number)) { // unlimited posts. - if ($post_type_limits->{$post_type_slug}->enabled) : + $width = 5; + } else { + $width = ($post_count / $post_type_limits->{$post_type_slug}->number * 100); + } // end if; - $post_count = $post_type_limits->get_post_count($post_type_slug); + if ($width > 100) { + $width = 100; + } // end if; - // Calculate width - if (empty($post_type_limits->{$post_type_slug}->number)) { // unlimited posts. + ?> - $width = 5; +
      • - } else { + - $width = ($post_count / $post_type_limits->{$post_type_slug}->number * 100); + label; ?> - } // end if; + - if ($width > 100) { + - $width = 100; + - } // end if; + - ?> +
        -
      • + + / + {$post_type_slug}->number) ? __('Unlimited', 'wp-ultimo') : $post_type_limits->{$post_type_slug}->number; ?> - +
    - label; ?> + - + - + - + - + -
    + get_limitations()->visits->is_enabled()) : ?> - - / - {$post_type_slug}->number) ? __('Unlimited', 'wp-ultimo') : $post_type_limits->{$post_type_slug}->number; ?> + + $visit_limitations = $site->get_limitations()->visits; - + /* + * Get the visits count. + */ + $visits_count = (int) $site->get_visits_count(); - + /* + * Calculates the width of the bar + */ + $visits_width = empty($visit_limitations->get_limit()) ? 1 : $visits_count / $visit_limitations->get_limit() * 100; - + ?> - +
  • - +
    - get_limitations()->visits->is_enabled()) : ?> + - - $visit_limitations = $site->get_limitations()->visits; +
    - /* - * Get the visits count. - */ - $visits_count = (int) $site->get_visits_count(); + - /* - * Calculates the width of the bar - */ - $visits_width = empty($visit_limitations->get_limit()) ? 1 : $visits_count / $visit_limitations->get_limit() * 100; + - ?> + -
  • +
    -
    + + / + get_limit() == 0 ? __('Unlimited', 'wp-ultimo') : number_format((int) $visit_limitations->get_limit()); ?> - +
    - +
  • -
    + - + - - - - -
    - - - / - get_limit() == 0 ? __('Unlimited', 'wp-ultimo') : number_format((int) $visit_limitations->get_limit()); ?> - -
    - - - - - - - -
    +
    diff --git a/views/dashboard-widgets/login-additional-forms.php b/views/dashboard-widgets/login-additional-forms.php index 1416a72..2f7dbee 100644 --- a/views/dashboard-widgets/login-additional-forms.php +++ b/views/dashboard-widgets/login-additional-forms.php @@ -7,6 +7,6 @@ ?>
    - render(); ?> + render(); ?>
    diff --git a/views/dashboard-widgets/login-form.php b/views/dashboard-widgets/login-form.php index 30bdfd0..f2e06d3 100644 --- a/views/dashboard-widgets/login-form.php +++ b/views/dashboard-widgets/login-form.php @@ -7,61 +7,61 @@ ?>
    - + - + -
    +
    - Log in using your account.', 'wp-ultimo'), wp_get_current_user()->display_name, $login_url); + // translators: 1$s is the display name of the user currently logged in. + printf(__('Not %1$s? Log in using your account.', 'wp-ultimo'), wp_get_current_user()->display_name, $login_url); - ?> + ?> -
    +
    - + - + - -
    + +
    - + -

    +

    - + -

    + - + - + -
    + +
    - + -
    - +
    + - render(); ?> + render(); ?> - +
    diff --git a/views/dashboard-widgets/my-sites.php b/views/dashboard-widgets/my-sites.php index fb71527..7114272 100644 --- a/views/dashboard-widgets/my-sites.php +++ b/views/dashboard-widgets/my-sites.php @@ -10,9 +10,12 @@ $current_site = wu_get_current_site(); $add_new_url = wu_get_setting('enable_multiple_sites') ? $element->get_new_site_url() : wu_get_registration_url(); // Redirect back to this page after create the site -$add_new_url = add_query_arg(array( - 'redirect_url' => urlencode(wu_get_current_url()), -), $add_new_url); +$add_new_url = add_query_arg( + array( + 'redirect_url' => urlencode(wu_get_current_url()), + ), + $add_new_url +); $show_add_new = wu_get_setting('enable_multiple_sites') || wu_get_setting('enable_multiple_memberships'); @@ -21,166 +24,166 @@ $show_add_new = apply_filters('wp_ultimo_my_sites_show_add_new', $show_add_new); ?>
    -
    +
    -
    +
    -
    +
    - + -
    +
    -
    +
    -
    +
    - get_membership()) : ?> + get_membership()) : ?> - get_id()) : ?> + get_id()) : ?> - - get_membership()->get_status_label(); ?> - + + get_membership()->get_status_label(); ?> + - + - - - + + + - + - + - + - get_id() && $site->is_customer_primary_site()) : ?> + get_id() && $site->is_customer_primary_site()) : ?> - - - + + + - + - + -
    +
    - + - <?php printf(esc_attr__('Site Image: %s', 'wp-ultimo'), $site->get_title()); ?> + <?php printf(esc_attr__('Site Image: %s', 'wp-ultimo'), $site->get_title()); ?> - + -
     
    +
     
    - + -
    +
    -
    + +
    - get_id()): ?> + get_id()) : ?> -
      +
        - currents->get_site() && WP_Ultimo()->currents->get_site()->get_id() == $site->get_id()) : ?> + currents->get_site() && WP_Ultimo()->currents->get_site()->get_id() == $site->get_id()) : ?> -
      • - - - -
      • +
      • + + + +
      • - + -
      • - - - -
      • +
      • + + + +
      • - + -
      +
    - + -
    +
    - + - + - + - - - - + + + + - + - + -
    +
    -
    +
    -
    +
    diff --git a/views/dashboard-widgets/simple-text.php b/views/dashboard-widgets/simple-text.php index 2b16576..dfecbf5 100644 --- a/views/dashboard-widgets/simple-text.php +++ b/views/dashboard-widgets/simple-text.php @@ -8,16 +8,16 @@
    -
    +
    - -
    + +
    - + -
    - +
    + -
    +
    diff --git a/views/dashboard-widgets/site-actions.php b/views/dashboard-widgets/site-actions.php index fec482b..447c398 100644 --- a/views/dashboard-widgets/site-actions.php +++ b/views/dashboard-widgets/site-actions.php @@ -7,88 +7,93 @@ ?>
    -
    +
    - -
    + +
    - + -

    +

    - + -

    + - + -
    - +
    + - - + - -
    + +
    - + -

    +

    - + -

    + - + -
    - +
    + - - + -
    +
    diff --git a/views/dashboard-widgets/site-maintenance.php b/views/dashboard-widgets/site-maintenance.php index a4649d8..44a2b6c 100644 --- a/views/dashboard-widgets/site-maintenance.php +++ b/views/dashboard-widgets/site-maintenance.php @@ -7,17 +7,17 @@ ?>
    -
    +
    - render(); ?> + render(); ?> -
    +
    diff --git a/views/dashboard-widgets/summary.php b/views/dashboard-widgets/summary.php index 2e81cd5..fae23ed 100644 --- a/views/dashboard-widgets/summary.php +++ b/views/dashboard-widgets/summary.php @@ -7,56 +7,56 @@ ?>
    -
      +
        -
      • +
      • -
        +
        - - - + + + -
        +
        -
        - -
        +
        + +
        -
      • + -
      • > +
      • > -
        +
        - - - + + + -
        +
        -
        - -
        +
        + +
        -
      • + -
      • +
      • -
        +
        - - - + + + -
        +
        -
        - -
        +
        + +
        -
      • + -
      +
    diff --git a/views/dashboard-widgets/thank-you.php b/views/dashboard-widgets/thank-you.php index cfce058..c587537 100644 --- a/views/dashboard-widgets/thank-you.php +++ b/views/dashboard-widgets/thank-you.php @@ -7,461 +7,461 @@ ?>
    -
    +
    - get_status(), array('completed'))) : ?> + get_status(), array('completed'))) : ?> - -
    + +
    - -
    + +
    - + -

    +

    - + -

    + - + -
    - +
    + - -
    + +
    - + -
    - +
    + -
      +
        - -
      • + +
      • - + - + - + - + - get_hash(); ?> + get_hash(); ?> - + - get_date_created())); ?> + get_date_created())); ?> - + - + -
      • - + + - -
      • + +
      • - + - + - + - + - get_email_address(); ?> + get_email_address(); ?> - + -
      • - + + - -
      • + +
      • - + - + - + - + - get_total(), $payment->get_currency()); ?> + get_total(), $payment->get_currency()); ?> - + -
      • - + + -
      +
    -
    - +
    + - + - -
    + +
    - -
    + +
    - + -

    +

    - + -

    + - + -
    - +
    + - -
    + +
    - + -
    - +
    + -
      +
        - -
      • + +
      • - + - + - + - + - get_hash(); ?> + get_hash(); ?> - + -
      • - + + - -
      • + +
      • - + - + - + - + - get_date_created())); ?> + get_date_created())); ?> - + -
      • - + + - -
      • + +
      • - + - + - + - + - get_email_address(); ?> + get_email_address(); ?> - + -
      • - + + - -
      • + +
      • - + - + - + - + - get_total(), $payment->get_currency()); ?> + get_total(), $payment->get_currency()); ?> - + -
      • - + + -
      +
    -
    - +
    + - + - + - -
    + +
    - -
    + +
    - + -

    +

    - + -

    + - + -
    - +
    + - -
    + +
    - + -
    +
    - get_sites()) : ?> + get_sites()) : ?> - get_sites() as $site) : ?> + get_sites() as $site) : ?> -
    +
    -
    +
    - + -
    +
    -
    +
    -
    +
    - get_title()); ?> + get_title()); ?> - get_type() === 'pending') : ?> + get_type() === 'pending') : ?> - - get_type_label(); ?> - + + get_type_label(); ?> + - - {{ progress }}% - + + {{ progress }}% + - + - - - + + + - + -
    + -
    +
    - + - get_active_site_url(); ?> + get_active_site_url(); ?> - + -
    +
    -
    +
    -
    +
    - get_type() === 'pending') : ?> + get_type() === 'pending') : ?> - - - - -
    - - -
    + + + + +
    + + +
    - + - - - - + + + + - - - - + + + + - + -
    +
    -
    +
    - + - + -
    +
    - + -
    +
    - + -
    +
    -
    - +
    + -
    - +
    + - -
    + +
    - -
    + +
    - + -

    +

    - + -

    + - + -
    - +
    + - -
    + +
    - +
    - + - - - - + + + + - + - + - get_line_items() as $line_item) : ?> + get_line_items() as $line_item) : ?> - + - + - + - + - + - + - + - - - - + + + + - get_tax_breakthrough() as $rate => $total) : ?> + get_tax_breakthrough() as $rate => $total) : ?> - - - - + + + + - + - - - - + + + + - + -
    - get_title(); ?> - xget_quantity(); ?> - + get_title(); ?> + xget_quantity(); ?> + - get_subtotal(), $payment->get_currency()); ?> - + get_subtotal(), $payment->get_currency()); ?> +
    get_subtotal(), $payment->get_currency()); ?>
    get_subtotal(), $payment->get_currency()); ?>
    get_currency()); ?>
    get_currency()); ?>
    get_total(), $payment->get_currency()); ?>
    get_total(), $payment->get_currency()); ?>
    + -
    - +
    + -
    - +
    + - -
    + +
    - -
    + +
    - + -

    +

    - + -

    + - + -
    - +
    + - -
    + +
    - get_billing_address()->to_string('
    '); ?> + get_billing_address()->to_string('
    '); ?> -
    - +
    + -
    - +
    + -
    +
    diff --git a/views/domain/dns-table.php b/views/domain/dns-table.php index 454301b..eeb366a 100644 --- a/views/domain/dns-table.php +++ b/views/domain/dns-table.php @@ -7,76 +7,76 @@ ?>
    - +
    - - - - - - - - + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - + + + + - + -
    + - + -
    + -
    +
    -
    {{ dns.host }}{{ dns.type }}{{ dns.data }}{{ dns.ttl }}
    {{ dns.host }}{{ dns.type }}{{ dns.data }}{{ dns.ttl }}
    {{ dns.host }}{{ dns.type }}{{ dns.data }}{{ dns.ttl }}
    {{ dns.host }}{{ dns.type }}{{ dns.data }}{{ dns.ttl }}
    {{ dns.host }}{{ dns.type }}{{ dns.data }}{{ dns.ttl }}
    {{ dns.host }}{{ dns.type }}{{ dns.data }}{{ dns.ttl }}
    {{ results.network_ip }}
    {{ results.network_ip }}
    +
    @@ -84,48 +84,48 @@ (function($) { - wu_dns_table = new Vue({ - el: '#wu-dns-table', - data: { - error: null, - results: {}, - loading: true, - }, - updated() { - this.$nextTick(function() { + wu_dns_table = new Vue({ + el: '#wu-dns-table', + data: { + error: null, + results: {}, + loading: true, + }, + updated() { + this.$nextTick(function() { - window.wu_initialize_tooltip(); + window.wu_initialize_tooltip(); - }); - } - }) + }); + } + }) - $(document).ready(function() { + $(document).ready(function() { - $.ajax({ - url: ajaxurl, - data: { - action: 'wu_get_dns_records', - domain: 'get_domain()); ?>', - }, - success: function(data) { + $.ajax({ + url: ajaxurl, + data: { + action: 'wu_get_dns_records', + domain: 'get_domain()); ?>', + }, + success: function(data) { - Vue.set(wu_dns_table, 'loading', false); + Vue.set(wu_dns_table, 'loading', false); - if (data.success) { + if (data.success) { - Vue.set(wu_dns_table, 'results', data.data); + Vue.set(wu_dns_table, 'results', data.data); - } else { + } else { - Vue.set(wu_dns_table, 'error', data.data); + Vue.set(wu_dns_table, 'error', data.data); - } // end if; + } // end if; - }, - }) + }, + }) - }); + }); })(jQuery); diff --git a/views/domain/log.php b/views/domain/log.php index a10c5dc..8ecf05b 100644 --- a/views/domain/log.php +++ b/views/domain/log.php @@ -7,17 +7,17 @@ ?>
    -
    -    
    -  
    +
    +	
    +	
    - +
    @@ -25,52 +25,52 @@ (function($) { - $(document).ready(function() { + $(document).ready(function() { - const refresh_logs = function(callback) { + const refresh_logs = function(callback) { - $.ajax({ - url: ajaxurl, - method: 'GET', - data: { - action: 'wu_handle_view_logs', - file: 'domain-get_domain()); ?>.log', - return_ascii: 'no', - }, - success(response) { + $.ajax({ + url: ajaxurl, + method: 'GET', + data: { + action: 'wu_handle_view_logs', + file: 'domain-get_domain()); ?>.log', + return_ascii: 'no', + }, + success(response) { - $('#content').html(response.data.contents); + $('#content').html(response.data.contents); - if (typeof callback !== 'undefined') { + if (typeof callback !== 'undefined') { - callback(); + callback(); - } + } - }, - }); + }, + }); - } // end refresh_logs; + } // end refresh_logs; - refresh_logs(); + refresh_logs(); - setInterval(refresh_logs, 60000); + setInterval(refresh_logs, 60000); - $(document).on('click', '#refresh-logs', function(e) { + $(document).on('click', '#refresh-logs', function(e) { - const block_content = wu_block_ui('#content'); + const block_content = wu_block_ui('#content'); - e.preventDefault(); + e.preventDefault(); - refresh_logs(function() { + refresh_logs(function() { - block_content.unblock(); + block_content.unblock(); - }); + }); - }); + }); - }); + }); })(jQuery); diff --git a/views/dynamic-styles/template-previewer.php b/views/dynamic-styles/template-previewer.php index 970d0a7..719172b 100644 --- a/views/dynamic-styles/template-previewer.php +++ b/views/dynamic-styles/template-previewer.php @@ -6,7 +6,7 @@ */ ?> body #switcher { - background-color: #getHex(); ?>; + background-color: #getHex(); ?>; border-bottom: 5px solid isDark() ? '#f9f9f9' : '#333'; ?>; } @@ -15,7 +15,7 @@ body #switcher { } .responsive a { - color: isDark() ? '#fff' : '#444'; ?> + color: isDark() ? '#fff' : '#444'; ?> } .responsive a.active, .responsive a:hover { @@ -23,6 +23,6 @@ body #switcher { } .select-template a, .mobile-selector a { - background-color: #getHex(); ?>; - color: isDark() ? '#fff' : '#444'; ?>; + background-color: #getHex(); ?>; + color: isDark() ? '#fff' : '#444'; ?>; } diff --git a/views/emails/admin/domain-created.php b/views/emails/admin/domain-created.php index c31fbdf..54940be 100644 --- a/views/emails/admin/domain-created.php +++ b/views/emails/admin/domain-created.php @@ -12,126 +12,126 @@

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    - {{domain_domain}} -
    - {{domain_id}} -
    - {{domain_stage}} -
    - {{domain_active}} -
    - {{domain_primary}} -
    - {{domain_secure}} -
    - -
    + {{domain_domain}} +
    + {{domain_id}} +
    + {{domain_stage}} +
    + {{domain_active}} +
    + {{domain_primary}} +
    + {{domain_secure}} +
    + +

    - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + +
    - {{site_title}} -
    - {{site_id}} -
    - -
    - -
    - -
    + {{site_title}} +
    + {{site_id}} +
    + +
    + +
    + +

    - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + +
    - {{membership_description}} -
    - {{membership_initial_amount}} -
    - {{membership_id}} -
    - {{membership_reference_code}} -
    {{membership_date_expiration}}
    - -
    + {{membership_description}} +
    + {{membership_initial_amount}} +
    + {{membership_id}} +
    + {{membership_reference_code}} +
    {{membership_date_expiration}}
    + +
    diff --git a/views/emails/admin/payment-received.php b/views/emails/admin/payment-received.php index e1daeed..b5f3ca9 100644 --- a/views/emails/admin/payment-received.php +++ b/views/emails/admin/payment-received.php @@ -14,145 +14,145 @@

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    - {{payment_product_names}} -
    - {{payment_subtotal}} -
    - {{payment_tax_total}} -
    - {{payment_total}} -
    {{payment_gateway}}
    - {{payment_id}} -
    - {{payment_reference_code}} -
    {{payment_date_created}}
    - - - -
    Initial Payment
    - -
    + {{payment_product_names}} +
    + {{payment_subtotal}} +
    + {{payment_tax_total}} +
    + {{payment_total}} +
    {{payment_gateway}}
    + {{payment_id}} +
    + {{payment_reference_code}} +
    {{payment_date_created}}
    + + + +
    Initial Payment
    + +

    - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + +
    - {{membership_description}} -
    - {{membership_initial_amount}} -
    - {{membership_id}} -
    - {{membership_reference_code}} -
    {{membership_date_expiration}}
    - -
    + {{membership_description}} +
    + {{membership_initial_amount}} +
    + {{membership_id}} +
    + {{membership_reference_code}} +
    {{membership_date_expiration}}
    + +

    - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + +
    - {{customer_avatar}}
    - {{customer_name}} -
    - {{customer_user_email}} -
    - {{customer_id}} -
    {{customer_billing_address}}
    - -
    + {{customer_avatar}}
    + {{customer_name}} +
    + {{customer_user_email}} +
    + {{customer_id}} +
    {{customer_billing_address}}
    + +
    diff --git a/views/emails/admin/site-published.php b/views/emails/admin/site-published.php index 96d9d41..9eab9a2 100644 --- a/views/emails/admin/site-published.php +++ b/views/emails/admin/site-published.php @@ -12,114 +12,114 @@

    - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + +
    - {{site_title}} -
    - {{site_id}} -
    - -
    - -
    - -
    + {{site_title}} +
    + {{site_id}} +
    + +
    + +
    + +

    - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + +
    - {{membership_description}} -
    - {{membership_initial_amount}} -
    - {{membership_id}} -
    - {{membership_reference_code}} -
    {{membership_date_expiration}}
    - -
    + {{membership_description}} +
    + {{membership_initial_amount}} +
    + {{membership_id}} +
    + {{membership_reference_code}} +
    {{membership_date_expiration}}
    + +

    - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + +
    - {{customer_avatar}}
    - {{customer_name}} -
    - {{customer_user_email}} -
    - {{customer_id}} -
    {{customer_billing_address}}
    - -
    + {{customer_avatar}}
    + {{customer_name}} +
    + {{customer_user_email}} +
    + {{customer_id}} +
    {{customer_billing_address}}
    + +
    diff --git a/views/emails/customer/confirm-email-address.php b/views/emails/customer/confirm-email-address.php index 92af718..67feff0 100644 --- a/views/emails/customer/confirm-email-address.php +++ b/views/emails/customer/confirm-email-address.php @@ -12,7 +12,7 @@

    - -
    - {{verification_link}}'); ?> + +
    + {{verification_link}}'); ?>

    diff --git a/views/emails/customer/payment-received.php b/views/emails/customer/payment-received.php index 6f20c72..6052a75 100644 --- a/views/emails/customer/payment-received.php +++ b/views/emails/customer/payment-received.php @@ -14,46 +14,46 @@

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    - {{payment_product_names}} -
    - {{payment_subtotal}} -
    - {{payment_tax_total}} -
    - {{payment_total}} -
    {{payment_date_created}}
    - - - -
    Initial Payment
    + {{payment_product_names}} +
    + {{payment_subtotal}} +
    + {{payment_tax_total}} +
    + {{payment_total}} +
    {{payment_date_created}}
    + + + +
    Initial Payment
    diff --git a/views/emails/customer/renewal-payment-created.php b/views/emails/customer/renewal-payment-created.php index fc6acf3..f5c867e 100644 --- a/views/emails/customer/renewal-payment-created.php +++ b/views/emails/customer/renewal-payment-created.php @@ -14,34 +14,34 @@

    - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + +
    - {{payment_product_names}} -
    - {{payment_subtotal}} -
    - {{payment_tax_total}} -
    - {{payment_total}} -
    {{payment_date_created}}
    + {{payment_product_names}} +
    + {{payment_subtotal}} +
    + {{payment_tax_total}} +
    + {{payment_total}} +
    {{payment_date_created}}
    diff --git a/views/emails/customer/site-published.php b/views/emails/customer/site-published.php index 85e96c2..1ea84e1 100644 --- a/views/emails/customer/site-published.php +++ b/views/emails/customer/site-published.php @@ -12,24 +12,24 @@

    - - - - - - - - - - - - - - + + + + + + + + + + + + + +
    - {{site_title}} -
    - -
    - -
    + {{site_title}} +
    + +
    + +
    diff --git a/views/events/widget-initiator.php b/views/events/widget-initiator.php index e3d3435..a23d264 100644 --- a/views/events/widget-initiator.php +++ b/views/events/widget-initiator.php @@ -7,107 +7,111 @@ ?>
    -
    diff --git a/views/events/widget-message.php b/views/events/widget-message.php index 4bbc2f2..1f90c5d 100644 --- a/views/events/widget-message.php +++ b/views/events/widget-message.php @@ -7,15 +7,15 @@ ?>
      -
    • +
    • -

      +

      - - get_message(); ?> - + + get_message(); ?> + -
    • +
    diff --git a/views/events/widget-payload.php b/views/events/widget-payload.php index 7950324..548eac3 100644 --- a/views/events/widget-payload.php +++ b/views/events/widget-payload.php @@ -7,32 +7,32 @@ ?>
      -
    • +
    • -
      
      +	
      
       
      -  
    • + -
      +
      - + - + - + -
      +
    - + - - - + + +
    diff --git a/views/invoice/template.php b/views/invoice/template.php index 8a8fc05..8229f4d 100644 --- a/views/invoice/template.php +++ b/views/invoice/template.php @@ -10,290 +10,290 @@ $has_tax_included = false; ?>
    - - -
    - - - + - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - + + + + + + - is_payable()) : ?> + is_payable()) : ?> - - - + + + - - - + + + - -
    - + + + - + + +
    + + + + <?php echo get_network_option(null, 'site_name'); ?> + + + - - -
    + - + - + - + - <?php echo get_network_option(null, 'site_name'); ?> - - - -
    - get_invoice_number(); ?> -
    - get_date_created()))); ?>
    -
    -
    -
    +
    + get_invoice_number(); ?> +
    + get_date_created()))); ?>
    +
    +
    +
    - - - - + ?> + + + +
    - - + + + + + ?> + - - -
    + + - + ?> + -
    +
    - -
    - -
    - + +
    + - -
    -
    +
    - - + + - - + + - - + + - - + + - - + +
    - get_title(); ?> -
    - get_description(); ?> -
    + get_title(); ?> +
    + get_description(); ?> +
    - get_subtotal(), $payment->get_currency()); ?> - + get_subtotal(), $payment->get_currency()); ?> + - get_discount_total(), $payment->get_currency()); ?> - + get_discount_total(), $payment->get_currency()); ?> + - get_tax_total(), $payment->get_currency()); ?> -
    - get_tax_label(); ?> (get_tax_rate(); ?>%) - get_tax_inclusive()) : ?> - - * - -
    + get_tax_total(), $payment->get_currency()); ?> +
    + get_tax_label(); ?> (get_tax_rate(); ?>%) + get_tax_inclusive()) : ?> + + * + +
    - get_total(), $payment->get_currency()); ?> - + get_total(), $payment->get_currency()); ?> +
    - * - - get_total(), $payment->get_currency())); ?> -
    + * + + get_total(), $payment->get_currency())); ?> +
    - -
    + +
    - get_payment_method(); ?> -
    + get_payment_method(); ?> +
    + +
    diff --git a/views/legacy/signup/pricing-table/coupon-code.php b/views/legacy/signup/pricing-table/coupon-code.php index 5cffda8..73fb5f6 100644 --- a/views/legacy/signup/pricing-table/coupon-code.php +++ b/views/legacy/signup/pricing-table/coupon-code.php @@ -8,8 +8,6 @@ @@ -17,326 +15,326 @@ if (isset($_GET['coupon']) && wu_get_coupon($_GET['coupon']) !== false && isset(
    diff --git a/views/legacy/signup/pricing-table/frequency-selector.php b/views/legacy/signup/pricing-table/frequency-selector.php index 2699012..ed2ad98 100644 --- a/views/legacy/signup/pricing-table/frequency-selector.php +++ b/views/legacy/signup/pricing-table/frequency-selector.php @@ -15,8 +15,8 @@ * @version 1.0.0 */ -if (!defined('ABSPATH')) { - exit; // Exit if accessed directly +if ( ! defined('ABSPATH')) { + exit; // Exit if accessed directly } ?> @@ -25,29 +25,33 @@ if (!defined('ABSPATH')) {
      - __('Monthly', 'wp-ultimo'), - 3 => __('Quarterly', 'wp-ultimo'), - 12 => __('Yearly', 'wp-ultimo'), - ); + $prices = array( + 1 => __('Monthly', 'wp-ultimo'), + 3 => __('Quarterly', 'wp-ultimo'), + 12 => __('Yearly', 'wp-ultimo'), + ); - $first = true; + $first = true; - foreach ($prices as $type => $name) : + foreach ($prices as $type => $name) : + if ( ! wu_get_setting('enable_price_' . $type, true)) { + continue; + } - if (!wu_get_setting('enable_price_'.$type, true)) continue; + ?> - ?> +
    • + + + +
    • -
    • - - - -
    • - - +
    diff --git a/views/legacy/signup/pricing-table/no-plans.php b/views/legacy/signup/pricing-table/no-plans.php index 626afbc..ae31553 100644 --- a/views/legacy/signup/pricing-table/no-plans.php +++ b/views/legacy/signup/pricing-table/no-plans.php @@ -15,12 +15,12 @@ * @version 1.0.0 */ -if (!defined('ABSPATH')) { - exit; // Exit if accessed directly +if ( ! defined('ABSPATH')) { + exit; // Exit if accessed directly } ?>
    -


    +


    diff --git a/views/legacy/signup/pricing-table/plan.php b/views/legacy/signup/pricing-table/plan.php index c0a7d04..5631030 100644 --- a/views/legacy/signup/pricing-table/plan.php +++ b/views/legacy/signup/pricing-table/plan.php @@ -15,8 +15,8 @@ * @version 1.0.0 */ -if (!defined('ABSPATH')) { - exit; // Exit if accessed directly +if ( ! defined('ABSPATH')) { + exit; // Exit if accessed directly } ?> @@ -25,117 +25,119 @@ if (!defined('ABSPATH')) { /** * Set plan attributes + * * @var string */ $plan_attrs = ''; foreach (array(1, 3, 12) as $type) { - - $price = $plan->free ? __('Free!', 'wp-ultimo') : str_replace(wu_get_currency_symbol(), '', wu_format_currency( ( ( (float) $plan->{"price_".$type}) / $type))); - $plan_attrs .= " data-price-$type='$price'"; - + $price = $plan->free ? __('Free!', 'wp-ultimo') : str_replace(wu_get_currency_symbol(), '', wu_format_currency((((float) $plan->{'price_' . $type}) / $type))); + $plan_attrs .= " data-price-$type='$price'"; } // end foreach; -$plan_attrs = apply_filters("wu_pricing_table_plan", $plan_attrs, $plan); +$plan_attrs = apply_filters('wu_pricing_table_plan', $plan_attrs, $plan); ?>
    class="get_id()}"; ?> lift wu-plan plan-tier is_featured_plan() ? 'callout' : ''; ?> wu-col-sm- wu-col-xs-12"> - is_featured_plan()) : ?> + is_featured_plan()) : ?> -
    +
    - + -

    get_name(); ?>

    +

    get_name(); ?>

    - - is_free()) : ?> + + is_free()) : ?> -
    - -
    +
    + +
    - is_contact_us()) : ?> + is_contact_us()) : ?> -
    - -
    +
    + +
    - + -
    - - - price_1)); ?> - -
    +
    + + + + price_1)); ?> + +
    - - + + -

    get_description(); ?> 


    +

    get_description(); ?> 


    - -
      + +
        - __('every 3 months', 'wp-ultimo'), - 12 => __('yearly', 'wp-ultimo'), - ); + __('every 3 months', 'wp-ultimo'), + 12 => __('yearly', 'wp-ultimo'), + ); - foreach ($prices_total as $freq => $string) { - - $text = sprintf(__('%1$s, billed %2$s', 'wp-ultimo'), wu_format_currency($plan->{"price_$freq"}), $string); - - if ($plan->free || $plan->is_contact_us()) echo "
      • -
      • "; - - else echo "
      • $text
      • "; - - } // end foreach; + foreach ($prices_total as $freq => $string) { + $text = sprintf(__('%1$s, billed %2$s', 'wp-ultimo'), wu_format_currency($plan->{"price_$freq"}), $string); - /** - * Loop and Displays Pricing Table Lines - */ - foreach ($plan->get_pricing_table_lines() as $key => $line) : ?> + if ($plan->free || $plan->is_contact_us()) { + echo "
      • -
      • "; + } else { + echo "
      • $text
      • "; + } + } // end foreach; -
      • + /** + * Loop and Displays Pricing Table Lines + */ + foreach ($plan->get_pricing_table_lines() as $key => $line) : + ?> - +
      • - id == $plan->get_id() ? __('This is your current plan', 'wp-ultimo') : __('Select Plan', 'wp-ultimo'); - $button_label = apply_filters('wu_plan_select_button_label', $button_label, $plan, $current_plan); - ?> + - is_contact_us()) : ?> + id == $plan->get_id() ? __('This is your current plan', 'wp-ultimo') : __('Select Plan', 'wp-ultimo'); + $button_label = apply_filters('wu_plan_select_button_label', $button_label, $plan, $current_plan); + ?> -
      • - - get_contact_us_label(); ?> - -
      • + is_contact_us()) : ?> - +
      • + + get_contact_us_label(); ?> + +
      • -
      • - -
      • + - +
      • + +
      • -
      - + + +
    +
    diff --git a/views/legacy/signup/pricing-table/pricing-table.php b/views/legacy/signup/pricing-table/pricing-table.php index e5b51f0..526872f 100644 --- a/views/legacy/signup/pricing-table/pricing-table.php +++ b/views/legacy/signup/pricing-table/pricing-table.php @@ -15,8 +15,8 @@ * @version 1.0.0 */ -if (!defined('ABSPATH')) { - exit; // Exit if accessed directly +if ( ! defined('ABSPATH')) { + exit; // Exit if accessed directly } ?> @@ -34,20 +34,20 @@ $accent_color_2 = wu_color($accent_color->darken(4)); @@ -58,10 +58,8 @@ $accent_color_2 = wu_color($accent_color->darken(4)); /** * Display the frequency selector */ -if (!isset($is_shortcode) || !$is_shortcode || $atts['show_selector']) { - - wu_get_template('/legacy/signup/pricing-table/frequency-selector'); - +if ( ! isset($is_shortcode) || ! $is_shortcode || $atts['show_selector']) { + wu_get_template('/legacy/signup/pricing-table/frequency-selector'); } // end if; /** @@ -69,51 +67,51 @@ if (!isset($is_shortcode) || !$is_shortcode || $atts['show_selector']) { */ if (empty($plans)) { + wu_get_template('legacy/signup/pricing-table/no-plans'); +} else { + ?> - wu_get_template('legacy/signup/pricing-table/no-plans'); + -} else { ?> + + /** + * Required: Prints the essential fields necessary to this form to work properly + */ + $signup->form_fields($current_plan); - - /** - * Required: Prints the essential fields necessary to this form to work properly - */ - $signup->form_fields($current_plan); +
    - ?> + + /** + * Display the plan table + */ - $plan, + 'count' => $count, + 'columns' => $columns, + 'current_plan' => $current_plan, + ) + ); + } // end foreach; - $count = count($plans); - $columns = $count == 5 ? '2-4' : 12 / $count; + ?> - foreach ($plans as $plan) { +
    - wu_get_template('legacy/signup/pricing-table/plan', array( - 'plan' => $plan, - 'count' => $count, - 'columns' => $columns, - 'current_plan' => $current_plan, - )); +
    - } // end foreach; - - ?> - -
    - - - - + @@ -123,16 +121,16 @@ if (empty($plans)) { diff --git a/views/legacy/signup/signup-main.php b/views/legacy/signup/signup-main.php index 3a4b21f..0ae69ec 100644 --- a/views/legacy/signup/signup-main.php +++ b/views/legacy/signup/signup-main.php @@ -22,37 +22,31 @@ defined('ABSPATH') || exit; require_once ABSPATH . 'wp-admin/includes/class-wp-screen.php'; require_once ABSPATH . 'wp-admin/includes/screen.php'; -// Load the admin actions removed in wordpress 6.0 +// Load the admin actions removed in WordPress 6.0 $admin_actions = array( - 'admin_print_scripts' => array( - 'print_head_scripts' => 20 + 'admin_print_scripts' => array( + 'print_head_scripts' => 20, ), - 'admin_print_styles' => array( - 'print_admin_styles' => 20, + 'admin_print_styles' => array( + 'print_admin_styles' => 20, ), - 'admin_head' => array( - 'wp_color_scheme_settings' => 10, - 'wp_admin_canonical_url' => 10, - 'wp_site_icon' => 10, - 'wp_admin_viewport_meta' => 10, + 'admin_head' => array( + 'wp_color_scheme_settings' => 10, + 'wp_admin_canonical_url' => 10, + 'wp_site_icon' => 10, + 'wp_admin_viewport_meta' => 10, ), 'admin_print_footer_scripts' => array( - '_wp_footer_scripts' => 10, + '_wp_footer_scripts' => 10, ), ); foreach ($admin_actions as $action => $handlers) { - foreach ($handlers as $handler => $priority) { - - if (!has_action($action, $handler) && function_exists($handler)) { - + if ( ! has_action($action, $handler) && function_exists($handler)) { add_action($action, $handler, $priority); - } // end foreach; - } // end foreach; - } // end foreach; do_action('wu_checkout_scripts'); @@ -61,121 +55,124 @@ do_action('wu_checkout_scripts'); > - - - + + + - - <?php echo apply_filters('wu_signup_page_title', sprintf(__('%s - Signup', 'wp-ultimo'), get_bloginfo('Name'), get_bloginfo('Name'))); ?> - + + <?php echo apply_filters('wu_signup_page_title', sprintf(__('%s - Signup', 'wp-ultimo'), get_bloginfo('Name'), get_bloginfo('Name'))); ?> + - - - - - - + + + + + + - + - + - + - + -
    +
    - + ?> -
    +
    -

    - - - -

    +

    + + + +

    - + ?> -
    +
    -
    +
    - + -
    +
    -
    +
    - + ?> - $signup)); - ?> + $signup)); + ?> -
    +
    - $signup)); - ?> + $signup)); + ?> - + ?> -
    +
    - + - print_inline_script('wu-checkout', 'after', true); + $wp_scripts->print_inline_script('wu-checkout', 'after', true); - ?> + ?> - + - + diff --git a/views/legacy/signup/signup-nav-links.php b/views/legacy/signup/signup-nav-links.php index be8bae9..ad92d79 100644 --- a/views/legacy/signup/signup-nav-links.php +++ b/views/legacy/signup/signup-nav-links.php @@ -15,8 +15,8 @@ * @version 1.4.0 */ -if (!defined('ABSPATH')) { - exit; // Exit if accessed directly +if ( ! defined('ABSPATH')) { + exit; // Exit if accessed directly } ?> @@ -25,45 +25,50 @@ if (!defined('ABSPATH')) { /** * Get Navigational Links + * * @var array */ -$nav_links = apply_filters('wu_signup_form_nav_links', array( - home_url() => __('Return to Home', 'wp-ultimo') , - wp_login_url() => sprintf('%s', __('Log In', 'wp-ultimo')) -)); - -if (!isset($signup->step)) { - - return; +$nav_links = apply_filters( + 'wu_signup_form_nav_links', + array( + home_url() => __('Return to Home', 'wp-ultimo'), + wp_login_url() => sprintf('%s', __('Log In', 'wp-ultimo')), + ) +); +if ( ! isset($signup->step)) { + return; } // end if; ?> step != 'plan' && $signup->step != 'template') : ?> - +

    diff --git a/views/legacy/signup/signup-steps-navigation.php b/views/legacy/signup/signup-steps-navigation.php index 4708cd2..50fa543 100644 --- a/views/legacy/signup/signup-steps-navigation.php +++ b/views/legacy/signup/signup-steps-navigation.php @@ -15,14 +15,12 @@ * @version 1.4.0 */ -if (!defined('ABSPATH')) { - exit; // Exit if accessed directly +if ( ! defined('ABSPATH')) { + exit; // Exit if accessed directly } -if (!$signup) { - - return; - +if ( ! $signup) { + return; } // end if; ?> @@ -39,33 +37,30 @@ $percent = 100 / $count;
      - step) { + $class = 'active'; + } elseif (array_search($signup->step, array_keys($signup->steps)) > array_search($step_key, array_keys($signup->steps))) { + $class = 'done'; + } // end if; - if ($step_key === $signup->step) { + ?> - $class = 'active'; +
    1. - } elseif (array_search($signup->step, array_keys($signup->steps)) > array_search($step_key, array_keys($signup->steps))) { + - $class = 'done'; - - } // end if; - - ?> - -
    2. - - - -
    3. + @@ -73,14 +68,14 @@ $percent = 100 / $count; get_prev_step_link()) : ?> - diff --git a/views/legacy/signup/steps/step-default.php b/views/legacy/signup/steps/step-default.php index 5a3c88d..d7e69bb 100644 --- a/views/legacy/signup/steps/step-default.php +++ b/views/legacy/signup/steps/step-default.php @@ -1,6 +1,6 @@
      - + -
      + - $field) { + foreach ($fields as $field_slug => $field) { - /** - * Prints each of our fields using a helper function - */ - wu_print_signup_field($field_slug, $field, $results); + /** + * Prints each of our fields using a helper function + */ + wu_print_signup_field($field_slug, $field, $results); + } // end foreach; - } // end foreach; + ?> - ?> + step"); ?> - step"); ?> - -
      +
      diff --git a/views/legacy/signup/steps/step-domain-url-preview.php b/views/legacy/signup/steps/step-domain-url-preview.php index 5b15f8a..a89789f 100644 --- a/views/legacy/signup/steps/step-domain-url-preview.php +++ b/views/legacy/signup/steps/step-domain-url-preview.php @@ -15,32 +15,32 @@ * @version 1.0.0 */ -if (!defined('ABSPATH')) { - exit; // Exit if accessed directly +if ( ! defined('ABSPATH')) { + exit; // Exit if accessed directly } ?>
      -
      +
      - '; - // This is used on the yoursite.network.com during sign-up - $dynamic_part .= isset($signup->results['blogname']) ? $signup->results['blogname'] : __('yoursite', 'wp-ultimo'); - $dynamic_part .= ''; + '; + // This is used on the yoursite.network.com during sign-up + $dynamic_part .= isset($signup->results['blogname']) ? $signup->results['blogname'] : __('yoursite', 'wp-ultimo'); + $dynamic_part .= ''; - $site_url = preg_replace('#^https?://#', '', WU_Signup()->get_site_url_for_previewer()); - $site_url = str_replace('www.', '', $site_url); + $site_url = preg_replace('#^https?://#', '', WU_Signup()->get_site_url_for_previewer()); + $site_url = str_replace('www.', '', $site_url); - $template = is_subdomain_install() ? sprintf('%s.%s', $dynamic_part, $site_url) : sprintf('%s/%s', $site_url, $dynamic_part); + $template = is_subdomain_install() ? sprintf('%s.%s', $dynamic_part, $site_url) : sprintf('%s/%s', $site_url, $dynamic_part); - echo $template; + echo $template; - ?> + ?>
      diff --git a/views/legacy/signup/steps/step-plans.php b/views/legacy/signup/steps/step-plans.php index 9140700..cbe968a 100644 --- a/views/legacy/signup/steps/step-plans.php +++ b/views/legacy/signup/steps/step-plans.php @@ -15,25 +15,30 @@ * @version 1.0.0 */ -if (!defined('ABSPATH')) { - exit; // Exit if accessed directly +if ( ! defined('ABSPATH')) { + exit; // Exit if accessed directly } // Get all available plans -$plans = wu_get_products(array( - 'type' => 'plan', -)); +$plans = wu_get_products( + array( + 'type' => 'plan', + ) +); // Render the selector -wu_get_template('legacy/signup/pricing-table/pricing-table', array( - 'plans' => $plans, - 'signup' => $signup, - 'current_plan' => false, - 'is_shortcode' => false, - 'atts' => array( - 'primary_color' => '#00a1ff', // wu_get_setting('primary-color', '#00a1ff'), - 'accent_color' => '#78b336', // wu_get_setting('accent-color', '#78b336'), - 'default_pricing_option' => 1, // wu_get_setting('default_pricing_option', 1), - 'show_selector' => true, - ) -)); +wu_get_template( + 'legacy/signup/pricing-table/pricing-table', + array( + 'plans' => $plans, + 'signup' => $signup, + 'current_plan' => false, + 'is_shortcode' => false, + 'atts' => array( + 'primary_color' => '#00a1ff', // wu_get_setting('primary-color', '#00a1ff'), + 'accent_color' => '#78b336', // wu_get_setting('accent-color', '#78b336'), + 'default_pricing_option' => 1, // wu_get_setting('default_pricing_option', 1), + 'show_selector' => true, + ), + ) +); diff --git a/views/limitations/plugin-selector.php b/views/limitations/plugin-selector.php index 2f57bd8..2144c00 100644 --- a/views/limitations/plugin-selector.php +++ b/views/limitations/plugin-selector.php @@ -4,101 +4,101 @@
        - $plugin_data) : ?> + $plugin_data) : ?> -
      • +
      • -
        +
        -
        +
        -
        +
        -
        +
        -
        +
        - + - + - + - - - + + + - + - + - + - + - + -
        +
        -
        +
        - - - + + + - - - + + + -
        +
        -
        +
        -
        +
        -

        +

        - + -

        + - + -

        +

        - + -

        + - + -
        +
        -
        +
        -
        +
        - model !== 'product' && $object->get_limitations(false)->plugins->exists($plugin_path)) : ?> + model !== 'product' && $object->get_limitations(false)->plugins->exists($plugin_path)) : ?> -

        - -

        +

        + +

        - + -
        +
        -
      • + - +
      diff --git a/views/limitations/site-template-selector.php b/views/limitations/site-template-selector.php index 4611ab9..89ab309 100644 --- a/views/limitations/site-template-selector.php +++ b/views/limitations/site-template-selector.php @@ -4,96 +4,96 @@
        - + - get_id(); + $key_name = 'site_' . $site_template->get_id(); - $template_settings = $product->get_limitations()->site_templates->{$key_name}; + $template_settings = $product->get_limitations()->site_templates->{$key_name}; - ?> + ?> -
      • +
      • -
        +
        -
        +
        -
        +
        - + -
        +
        -
        +
        - + - get_title(); ?> + get_title(); ?> - + - + - get_description()), 40); ?> + get_description()), 40); ?> - + - + - get_categories() ? __('No categories', 'wp-ultimo') : implode(', ', $site_template->get_categories()); ?> + get_categories() ? __('No categories', 'wp-ultimo') : implode(', ', $site_template->get_categories()); ?> - + -
        +
        -
        +
        -

        +

        - + -

        + - + -
        +
        -
        +
        -
        +
        - get_id() == $product->get_limitations()->site_templates->get_pre_selected_site_template()); ?> - class="wu-tgl wu-tgl-ios" - value="pre_selected" - id="wu-tg-get_id()); ?>" - type="checkbox" - v-on:click="pre_selected_template = get_id()); ?>" - v-bind:checked="pre_selected_template == get_id()); ?>" - :name="pre_selected_template == get_id()); ?> ? 'modules[site_templates][limit][get_id()); ?>][behavior]' : ''" /> + get_id() == $product->get_limitations()->site_templates->get_pre_selected_site_template()); ?> + class="wu-tgl wu-tgl-ios" + value="pre_selected" + id="wu-tg-get_id()); ?>" + type="checkbox" + v-on:click="pre_selected_template = get_id()); ?>" + v-bind:checked="pre_selected_template == get_id()); ?>" + :name="pre_selected_template == get_id()); ?> ? 'modules[site_templates][limit][get_id()); ?>][behavior]' : ''" /> - + -
        +
        -
        +
        -
        +
        -
        +
        -
      • + - +
      diff --git a/views/limitations/theme-selector.php b/views/limitations/theme-selector.php index cd1894d..b409aeb 100644 --- a/views/limitations/theme-selector.php +++ b/views/limitations/theme-selector.php @@ -4,100 +4,98 @@
        - $theme_data) : ?> + $theme_data) : ?> - get_limitations()->themes->{$theme_path}; + $theme_settings = $object->get_limitations()->themes->{$theme_path}; - if ($theme_settings->behavior === 'force_active') { + if ($theme_settings->behavior === 'force_active') { + $section['state']['force_active_theme'] = $theme_path; + } // end if; - $section['state']['force_active_theme'] = $theme_path; + ?> - } // end if; +
      • - ?> +
        -
      • +
        -
        +
        -
        +
        -
        + -
        + - + - + - + - + - +
        -
        +
        -
        + + + -
        + + + - - - +
        - - - +
        -
        +
        -
        + -
        +

        - + -

        +

        - + - +

        - + -

        +

        - + - +
        - +
        -
        + model !== 'product' && $object->get_limitations(false)->themes->exists($theme_path)) : ?> -
        +

        + +

        - model !== 'product' && $object->get_limitations(false)->themes->exists($theme_path)) : ?> + -

        - -

        +
        - - - - -
      • + diff --git a/views/memberships/product-list.php b/views/memberships/product-list.php index 518fcc6..55d5995 100644 --- a/views/memberships/product-list.php +++ b/views/memberships/product-list.php @@ -7,21 +7,21 @@ ?>
        -
        +
        - -
        +
        diff --git a/views/payments/line-item-actions.php b/views/payments/line-item-actions.php index b2c5fb9..2f0a3f4 100644 --- a/views/payments/line-item-actions.php +++ b/views/payments/line-item-actions.php @@ -7,68 +7,68 @@ ?>
        -
        +
        - -
        +
        -
        +
        -
        +
        - + - + - + - + - get_refund_total(), $payment->get_currency()); ?> + get_refund_total(), $payment->get_currency()); ?> - + -
        +
        -
        +
        - + - + - + - + - get_total(), $payment->get_currency()); ?> + get_total(), $payment->get_currency()); ?> - + -
        +
        -
        +
        diff --git a/views/payments/tax-details.php b/views/payments/tax-details.php index 6953e4d..6c83c18 100644 --- a/views/payments/tax-details.php +++ b/views/payments/tax-details.php @@ -7,43 +7,43 @@ ?>
        - - +
        + - + - $tax_total) : ?> - - - - - + $tax_total) : ?> + + + + + - - - - - - + + + + + + - + - - - + + + - + - -
        %
        %
        get_tax_total()); ?>
        get_tax_total()); ?>
        - -
        + +
        + +
        diff --git a/views/settings/fields/field-ajax_button.php b/views/settings/fields/field-ajax_button.php index 2ed34c1..5a7908e 100644 --- a/views/settings/fields/field-ajax_button.php +++ b/views/settings/fields/field-ajax_button.php @@ -7,70 +7,70 @@ ?>
        -
        +
        -
        +
        - -
        +
        -
        +
        - + - desc) : ?> + desc) : ?> -

        +

        - desc; ?> + desc; ?> -

        +

        - + -
        +
        -
        +
        - +
        diff --git a/views/settings/fields/field-checkbox.php b/views/settings/fields/field-checkbox.php index a19ab70..f3b7193 100644 --- a/views/settings/fields/field-checkbox.php +++ b/views/settings/fields/field-checkbox.php @@ -7,44 +7,44 @@ ?>
        -
        +
        -
        +
        - -
        +
        -
        +
        - - desc) : ?> + desc) : ?> -

        +

        - desc; ?> + desc; ?> -

        +

        - + -
        +
        -
        +
        - +
        diff --git a/views/settings/fields/field-color.php b/views/settings/fields/field-color.php index 5988070..f5e28b8 100644 --- a/views/settings/fields/field-color.php +++ b/views/settings/fields/field-color.php @@ -7,45 +7,45 @@ ?>
        -
        +
        -
        +
        - -
        +
        -
        +
        - + - desc) : ?> + desc) : ?> -

        +

        - desc; ?> + desc; ?> -

        +

        - + -
        +
        -
        +
        - +
        diff --git a/views/settings/fields/field-heading.php b/views/settings/fields/field-heading.php index 3278cec..d2d0c75 100644 --- a/views/settings/fields/field-heading.php +++ b/views/settings/fields/field-heading.php @@ -6,6 +6,6 @@ */ ?>
        -

        title; ?>

        -

        desc; ?>

        +

        title; ?>

        +

        desc; ?>

        diff --git a/views/settings/fields/field-heading_collapsible.php b/views/settings/fields/field-heading_collapsible.php index 8c4e353..c6ef6b7 100644 --- a/views/settings/fields/field-heading_collapsible.php +++ b/views/settings/fields/field-heading_collapsible.php @@ -5,6 +5,6 @@ * @since 2.0.0 */ ?> -
        - +
        +
        diff --git a/views/settings/fields/field-image.php b/views/settings/fields/field-image.php index 0d6a62f..e60373b 100644 --- a/views/settings/fields/field-image.php +++ b/views/settings/fields/field-image.php @@ -18,43 +18,46 @@ wp_enqueue_script('wu-field-button-upload', WP_Ultimo()->get_asset("wu-field-ima ?> - + - '; - printf( - $image, - $field_slug.'-preview', - $image_url, - get_bloginfo('name'), - $field['width'].'px' - ); + if ( $image_url ) { + $image = '%s'; + printf( + $image, + $field_slug . '-preview', + $image_url, + get_bloginfo('name'), + $field['width'] . 'px' + ); + } + ?> - } ?> +
        -
        + + + - - - + + + - - - + +

        + +

        - -

        - -

        + - - - + diff --git a/views/settings/fields/field-multi_checkbox.php b/views/settings/fields/field-multi_checkbox.php index a869d72..90133b0 100644 --- a/views/settings/fields/field-multi_checkbox.php +++ b/views/settings/fields/field-multi_checkbox.php @@ -6,89 +6,82 @@ */ ?> - - + + - &$value) { + if ( ! isset($field['options'][ $key ])) { + unset($_settings[ $key ]); - // If sortable, merge settings and list of items - if (isset($field['sortable']) && $field['sortable'] && $settings) { + continue; + } // end if; - $_settings = $settings; + $value = $field['options'][ $key ]; + } // end foreach; - foreach ($_settings as $key => &$value) { + $field['options'] = $_settings + $field['options']; + } // end if; - if (!isset($field['options'][$key])) { + ?> - unset($_settings[$key]); +
        - continue; + $field_name) : - } // end if; + // Check this setting + $this_settings = isset($settings[ $field_value ]) ? $settings[ $field_value ] : false; - $value = $field['options'][$key]; + ?> - } // end foreach; +
        - $field['options'] = $_settings + $field['options']; + - } // end if; +
        - ?> + -
        +
        - $field_name) : + - // Check this setting - $this_settings = isset($settings[$field_value]) ? $settings[$field_value] : false; +
        - ?> + -
        +

        + +

        - + -
        - - - -
        - - - -
        - - - -

        - -

        - - - - - + + diff --git a/views/settings/fields/field-note.php b/views/settings/fields/field-note.php index d68af03..308332b 100644 --- a/views/settings/fields/field-note.php +++ b/views/settings/fields/field-note.php @@ -7,38 +7,38 @@ ?>
        -
        +
        - title) : ?> + title) : ?> -
        +
        - -
        +
        - + -
        +
        - desc) : ?> + desc) : ?> -

        +

        - desc; ?> + desc; ?> -

        +

        - + -
        +
        -
        +
        - +
        diff --git a/views/settings/fields/field-select.php b/views/settings/fields/field-select.php index 1371b5a..c144e10 100644 --- a/views/settings/fields/field-select.php +++ b/views/settings/fields/field-select.php @@ -7,48 +7,48 @@ ?>
        -
        +
        -
        +
        - -
        +
        -
        +
        - - options as $value => $option) : ?> + options as $value => $option) : ?> - + - + - + - desc) : ?> + desc) : ?> -

        +

        - desc; ?> + desc; ?> -

        +

        - + -
        +
        -
        +
        - +
        diff --git a/views/settings/fields/field-select2.php b/views/settings/fields/field-select2.php index 83ad2e2..dddf2e1 100644 --- a/views/settings/fields/field-select2.php +++ b/views/settings/fields/field-select2.php @@ -18,22 +18,22 @@ $placeholder = isset($field['placeholder']) ? $field['placeholder'] : ''; ?> - - + + - - $option) : ?> - - + $option) : ?> + + - + - -

        - -

        - + +

        + +

        + - + diff --git a/views/settings/fields/field-text.php b/views/settings/fields/field-text.php index 79fe95e..e628219 100644 --- a/views/settings/fields/field-text.php +++ b/views/settings/fields/field-text.php @@ -7,42 +7,42 @@ ?>
        -
        +
        -
        +
        - -
        +
        -
        +
        - html_attr ? $field->get_html_attributes() : ''; ?> disabled ? 'disabled="disabled"' : ''; ?> name="id); ?>" type="type); ?>" id="id); ?>" class="regular-text" value="id); ?>" placeholder="placeholder ? $field->placeholder : ''; ?>"> + html_attr ? $field->get_html_attributes() : ''; ?> disabled ? 'disabled="disabled"' : ''; ?> name="id); ?>" type="type); ?>" id="id); ?>" class="regular-text" value="id); ?>" placeholder="placeholder ? $field->placeholder : ''; ?>"> - append) && !empty($field->append)) : ?> + append) && ! empty($field->append)) : ?> - append; ?> + append; ?> - + - desc) : ?> + desc) : ?> -

        +

        - desc; ?> + desc; ?> -

        +

        - + -
        +
        -
        +
        - +
        diff --git a/views/settings/fields/field-textarea.php b/views/settings/fields/field-textarea.php index 888613d..d6301cc 100644 --- a/views/settings/fields/field-textarea.php +++ b/views/settings/fields/field-textarea.php @@ -7,36 +7,36 @@ ?>
        -
        +
        -
        +
        - -
        +
        -
        +
        - + - desc) : ?> + desc) : ?> -

        +

        - desc; ?> + desc; ?> -

        +

        - + -
        +
        -
        +
        - +
        diff --git a/views/settings/fields/field-wp_editor.php b/views/settings/fields/field-wp_editor.php index 8d1c516..87475d8 100644 --- a/views/settings/fields/field-wp_editor.php +++ b/views/settings/fields/field-wp_editor.php @@ -7,40 +7,40 @@ ?>
        -
        +
        -
        +
        - -
        +
        -
        +
        -
        +
        - id), $field->id, $field->args); ?> + id), $field->id, $field->args); ?> -
        +
        - desc) : ?> + desc) : ?> -

        +

        - desc; ?> + desc; ?> -

        +

        - + -
        +
        -
        +
        - +
        diff --git a/views/shortcodes/shortcodes.php b/views/shortcodes/shortcodes.php index 87d20b9..4717271 100644 --- a/views/shortcodes/shortcodes.php +++ b/views/shortcodes/shortcodes.php @@ -6,81 +6,81 @@ */ ?> -
        +
        -

        +

        -
        -
        -
        +
        +
        +
        - + -
        -
        -
        +
        +
        +
        -
        - - - - -
        -

        - [] -

        -

        - -

        -
        -
        +
        + + + + +
        +

        + [] +

        +

        + +

        +
        +
        -
        - - - - - - - - $value) { ?> - - - - - - - -
        - - - - - - - -
        - - - - - - - -
        -
        +
        + + + + + + + + $value) { ?> + + + + + + + +
        + + + + + + + +
        + + + + + + + +
        +
        -
        -
        -
        +
        +
        +
        - + -
        -
        -
        +
        +
        +
        diff --git a/views/sites/edit-placeholders.php b/views/sites/edit-placeholders.php index fec2749..a0561f1 100644 --- a/views/sites/edit-placeholders.php +++ b/views/sites/edit-placeholders.php @@ -5,260 +5,268 @@ * @since 2.0.0 */ ?> -
        +
        -

        +

        - + -

        + -

        +

        -
        +
        -
        +
        -
        + -
        +
        -
        +
        - + - {{data.placeholders.length}} + {{data.placeholders.length}} - + -
        +
        -
        -
        +
        +
        - +
        - + - + - + - $label) : ?> + $label) : ?> - + - + - + - + - + - + - + - + - + - + - + - + - + - $label) : ?> + $label) : ?> - + - + - + - + - + - + - + - $label) : ?> + $label) : ?> - + - + - + - + -
        + - + - + - - - + +
        + -
        +
        - + -
        +
        -
        + -
        +
        - + -
        +
        -
        + - - + - + - + /** + * Switch for some of the fields + */ + switch ($key) : + case 'compound': + ?> - + - + - + - + - + - + - + - + - + - + - + - + -
        + - - + - + - + -
        -
        + +
        -
        +
        -
        +
        - + - + -
        +
        -
        +
        - + ?> -
        +
        -
        +
        - - - + + + - - - + + + - - {{saveMessage}} - + + {{saveMessage}} + - -
        + +
        -
        +
        - + -
        +
        -
        + - + -
        + -
        +
        diff --git a/views/system-info/system-info.php b/views/system-info/system-info.php index 7bbf0e1..9fc82c3 100644 --- a/views/system-info/system-info.php +++ b/views/system-info/system-info.php @@ -8,63 +8,63 @@ -
        +
        -

        +

        - + + - + - + -   +   - + - + -
        -
        -
        +
        +
        +
        - id, 'normal', ''); ?> + id, 'normal', ''); ?> -
        -
        -
        +
        +
        +
        diff --git a/views/taxes/list.php b/views/taxes/list.php index 2088327..f068d73 100644 --- a/views/taxes/list.php +++ b/views/taxes/list.php @@ -7,180 +7,180 @@ ?>
        -

        +

        - + -

        + - + - + - + - + -
        +
        -
        +
        -
        +
        -
        +
        -
        +
        - + - + - + -
        +
        -
        +
        - + - + -
        +
        -
        +
        - + - + - + -   +   - + -
        +
        -
        +
        -
        +
        - + - {{data[tax_category].rates.length}} + {{data[tax_category].rates.length}} - + -
        +
        -
        +
        -
        +
        - +
        - + - + - + - $label) : ?> + $label) : ?> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - $label) : ?> + $label) : ?> - + - + - + - + - + - + - + - $label) : ?> + $label) : ?> - + - + - + - + -
        + - + - + - + -
        + -
        +
        - + -
        +
        -
        + -
        +
        - + -
        +
        -
        + - - + - + - + - + - $tax_rate_type_label) : ?> - + - + - + - + - $country_name) : ?> - + - + - + - + - + - + - + - + -
        +
        - + -
        +
        - + - + - + - + -
        + - - + - + -
        + -
        +
        -
        +
        -
        +
        - + - + -
        +
        -
        +
        - + ?> -
        +
        -
        +
        - - - + + + - - - + + + - - {{saveMessage}} - + + {{saveMessage}} + - + -
        +
        -
        +
        -
        +
        -
        + - + -
        + -
        +
        diff --git a/views/ui/branding/footer.php b/views/ui/branding/footer.php index 9a68371..ae1e98d 100644 --- a/views/ui/branding/footer.php +++ b/views/ui/branding/footer.php @@ -8,50 +8,50 @@ diff --git a/views/ui/branding/header.php b/views/ui/branding/header.php index b864368..d970bb3 100644 --- a/views/ui/branding/header.php +++ b/views/ui/branding/header.php @@ -7,67 +7,67 @@ ?>
        -
        +
        - + -
        +
        - is_loaded()) : ?> + is_loaded()) : ?> -
        +
        - + ?> -
        +
        - + -
        +
        -
        +
        -
        +
        - is_loaded()) : ?> + is_loaded()) : ?> - + ?> - - - - - - - - - - + + + + + + + + + + - + -
        +
        diff --git a/views/ui/container-toggle.php b/views/ui/container-toggle.php index 8e752b4..3335f36 100644 --- a/views/ui/container-toggle.php +++ b/views/ui/container-toggle.php @@ -6,56 +6,56 @@ */ ?> - - ' href="#" class="wu-tooltip wu-inline-block wu-py-1 wu-pl-2 md:wu-pr-3 wu-uppercase wu-text-gray-600 wu-no-underline"> + + ' href="#" class="wu-tooltip wu-inline-block wu-py-1 wu-pl-2 md:wu-pr-3 wu-uppercase wu-text-gray-600 wu-no-underline"> - - - - + + + + - - - - + + + + - - + + diff --git a/views/ui/jumper-trigger.php b/views/ui/jumper-trigger.php index 521a327..79be78a 100644 --- a/views/ui/jumper-trigger.php +++ b/views/ui/jumper-trigger.php @@ -6,12 +6,12 @@ */ ?> - - ' href="#" class="wu-tooltip wu-inline-block wu-py-1 wu-pl-2 md:wu-pr-3 wu-uppercase wu-text-gray-600 wu-no-underline"> - - - - - - + + ' href="#" class="wu-tooltip wu-inline-block wu-py-1 wu-pl-2 md:wu-pr-3 wu-uppercase wu-text-gray-600 wu-no-underline"> + + + + + + diff --git a/views/ui/jumper.php b/views/ui/jumper.php index c598001..b50e22e 100644 --- a/views/ui/jumper.php +++ b/views/ui/jumper.php @@ -10,95 +10,95 @@ ?> diff --git a/views/ui/selectize-templates.php b/views/ui/selectize-templates.php index d1c2783..003dec0 100644 --- a/views/ui/selectize-templates.php +++ b/views/ui/selectize-templates.php @@ -8,23 +8,23 @@ @@ -32,23 +32,23 @@ @@ -56,25 +56,25 @@ @@ -82,23 +82,23 @@ @@ -106,19 +106,19 @@ @@ -126,23 +126,23 @@ @@ -150,23 +150,23 @@ @@ -174,17 +174,17 @@ @@ -192,17 +192,17 @@ @@ -210,17 +210,17 @@ @@ -228,17 +228,17 @@ @@ -246,15 +246,15 @@ @@ -262,17 +262,17 @@ @@ -280,17 +280,17 @@ @@ -298,23 +298,23 @@ @@ -322,23 +322,22 @@ diff --git a/views/ui/template-previewer.php b/views/ui/template-previewer.php index 5558a90..0db40db 100644 --- a/views/ui/template-previewer.php +++ b/views/ui/template-previewer.php @@ -15,8 +15,7 @@ * @version 1.0.0 */ -if (!defined('ABSPATH')) { - +if ( ! defined('ABSPATH')) { exit; // Exit if accessed directly } // end if; @@ -29,190 +28,198 @@ do_action('wu_template_previewer_before'); ?> > - + - + - + - + - + -
        +
        -
        +
        - - - + -
        +
        - + - + - + - + - + -
        +
        - + -
        +
        - + - - + - + -
        +
        - + -
        +
        - + - + - + - + - + -
        +
        - + - + - + - + -
        +
        -
        +
        -
        +
        - + -
        +
        -
        +
        -
        +
        - + - + - + diff --git a/views/ui/toolbox.php b/views/ui/toolbox.php index e31d9ee..d3b9f55 100644 --- a/views/ui/toolbox.php +++ b/views/ui/toolbox.php @@ -11,111 +11,111 @@ diff --git a/views/wizards/host-integrations/activation.php b/views/wizards/host-integrations/activation.php index 1e630b4..400dd0a 100644 --- a/views/wizards/host-integrations/activation.php +++ b/views/wizards/host-integrations/activation.php @@ -6,104 +6,104 @@ */ ?>

        - get_title()); ?> + get_title()); ?>

        - get_description(); ?> + get_description(); ?>

        -
        +
        -
        - -
        +
        + +
        -
        +
        -
        - -
        +
        + +
        -
        +
        -
        +
        - - - + + + -
          +
            - + -
          • - - -
          • +
          • + + +
          • - + -
          -
        +
      + - + -
      +
      - - not:', 'wp-ultimo'); ?> - + + not:', 'wp-ultimo'); ?> + -
        +
          - + -
        • - - -
        • +
        • + + +
        • - + -
        +
      -
      +
      - +
      - + - + - is_enabled()) : ?> + is_enabled()) : ?> - - - + + + - + - + -   +   - is_enabled()) : ?> - - - - + is_enabled()) : ?> + + + + - +
      diff --git a/views/wizards/host-integrations/cloudflare-instructions.php b/views/wizards/host-integrations/cloudflare-instructions.php index bcc92b5..82f4f13 100644 --- a/views/wizards/host-integrations/cloudflare-instructions.php +++ b/views/wizards/host-integrations/cloudflare-instructions.php @@ -10,25 +10,25 @@

      - +

      -
      - this tutorial to create the wildcard entry and deactivate this integration entirely.', 'wp-ultimo'), 'https://support.cloudflare.com/hc/en-us/articles/200169356-How-do-I-use-WordPress-Multi-Site-WPMU-With-Cloudflare'); ?> +
      + this tutorial to create the wildcard entry and deactivate this integration entirely.', 'wp-ultimo'), 'https://support.cloudflare.com/hc/en-us/articles/200169356-How-do-I-use-WordPress-Multi-Site-WPMU-With-Cloudflare'); ?>

      - +

      - +

      - +

      @@ -36,34 +36,34 @@

      - +

      - +

      - +

      - +

      - +

      diff --git a/views/wizards/host-integrations/cloudways-instructions.php b/views/wizards/host-integrations/cloudways-instructions.php index 9a1abf3..9fb5d0a 100644 --- a/views/wizards/host-integrations/cloudways-instructions.php +++ b/views/wizards/host-integrations/cloudways-instructions.php @@ -6,30 +6,30 @@ */ ?>
      -

      Step 1: Getting a Cloudways API Key

      -

      Follow the steps 1 and 2 of the official Cloudways tutorial to obtain an API key for your account (Read the tutorial). Copy the API Key as we will need it in the following steps.

      -

      Step 2: Get the Server ID

      -

      The next piece of information we will need is the server ID of the server hosting your WordPress install on Cloudways. To discover the server ID, visit the Server Management screen of the server. The server ID will be present on the URL of that page after the “/server/” portion of it.

      -
      - -
      -

      The URL takes the form of https://platform.cloudways.com/server/SERVER_ID_HERE/access_detail

      -

      Step 3: Get the App ID

      -

      We’ll need to do a similar thing to obtain the App ID for your WordPress installation. Go to Application Management screen of your WordPress app and the App ID will be present on the URL, after the “/apps/” portion of it.

      -
      - -
      -

      The same thing happens here: the URL takes the form of https://platform.cloudways.com/apps/YOUR_APP_ID_HERE/access_detail

      +

      Step 1: Getting a Cloudways API Key

      +

      Follow the steps 1 and 2 of the official Cloudways tutorial to obtain an API key for your account (Read the tutorial). Copy the API Key as we will need it in the following steps.

      +

      Step 2: Get the Server ID

      +

      The next piece of information we will need is the server ID of the server hosting your WordPress install on Cloudways. To discover the server ID, visit the Server Management screen of the server. The server ID will be present on the URL of that page after the “/server/” portion of it.

      +
      + +
      +

      The URL takes the form of https://platform.cloudways.com/server/SERVER_ID_HERE/access_detail

      +

      Step 3: Get the App ID

      +

      We’ll need to do a similar thing to obtain the App ID for your WordPress installation. Go to Application Management screen of your WordPress app and the App ID will be present on the URL, after the “/apps/” portion of it.

      +
      + +
      +

      The same thing happens here: the URL takes the form of https://platform.cloudways.com/apps/YOUR_APP_ID_HERE/access_detail

      -

      Additional Step – Extra Domains

      -

      The Cloudways API is a bit strange in that it doesn’t offer a way to add or remove just one domain, only a way to update the whole domain list. That means that WP Multisite WaaS will replace all domains you might have there with the list of mapped domains of the network every time a new domain is added.

      -

      If there are domains you want to keep on the list, use the WU_CLOUDWAYS_EXTRA_DOMAINS as demonstrated below, with a comma-separated list of the domains you wanna keep (this is useful if you need a wildcard setting, for example, that needs to be on that list at all times).

      -
      define('WU_CLOUDWAYS_EXTRA_DOMAINS', '*.yourdomain.com,extradomain1.com,extradomain2.com');
      -

      Here’s how it should look on your wp-config.php (fake values used below):

      -
      - -
      -

      You’re all set!

      -

      Now, every time a new domain is mapped in the network (via the Aliases tab by the network admin or via the custom domain meta-box on the user’s Account page) will be added to the Cloudways platform automatically.

      -

      The same is true for domain removals. Every time a domain is deleted from the network, that change will be communicated to your Cloudways account instantly!

      +

      Additional Step – Extra Domains

      +

      The Cloudways API is a bit strange in that it doesn’t offer a way to add or remove just one domain, only a way to update the whole domain list. That means that WP Multisite WaaS will replace all domains you might have there with the list of mapped domains of the network every time a new domain is added.

      +

      If there are domains you want to keep on the list, use the WU_CLOUDWAYS_EXTRA_DOMAINS as demonstrated below, with a comma-separated list of the domains you wanna keep (this is useful if you need a wildcard setting, for example, that needs to be on that list at all times).

      +
      define('WU_CLOUDWAYS_EXTRA_DOMAINS', '*.yourdomain.com,extradomain1.com,extradomain2.com');
      +

      Here’s how it should look on your wp-config.php (fake values used below):

      +
      + +
      +

      You’re all set!

      +

      Now, every time a new domain is mapped in the network (via the Aliases tab by the network admin or via the custom domain meta-box on the user’s Account page) will be added to the Cloudways platform automatically.

      +

      The same is true for domain removals. Every time a domain is deleted from the network, that change will be communicated to your Cloudways account instantly!

      diff --git a/views/wizards/host-integrations/configuration-results.php b/views/wizards/host-integrations/configuration-results.php index fe9e489..f6dfb1b 100644 --- a/views/wizards/host-integrations/configuration-results.php +++ b/views/wizards/host-integrations/configuration-results.php @@ -6,50 +6,50 @@ */ ?>

      - +

      - +

      - is_enabled()) : ?> + is_enabled()) : ?> -
    4. - - - - -
    5. +
    6. + + + + +
    7. - + -
    8. - /* That\'s all, stop editing! Happy publishing. */', 'wp-ultimo') ; ?> -
    9. +
    10. + /* That\'s all, stop editing! Happy publishing. */', 'wp-ultimo'); ?> +
    11. -

      +

      -
      get_constants_string($post); ?>
      +
      get_constants_string($post); ?>
      - +
      - + - + - + - +
      diff --git a/views/wizards/host-integrations/configuration.php b/views/wizards/host-integrations/configuration.php index c8fb8e2..a82f371 100644 --- a/views/wizards/host-integrations/configuration.php +++ b/views/wizards/host-integrations/configuration.php @@ -6,47 +6,47 @@ */ ?>

      - +

      - +

      - render(); + /** + * Renders the form. + */ + $form->render(); - ?> + ?>
      - - - + + + - + - + - + - +
      diff --git a/views/wizards/host-integrations/gridpane-instructions.php b/views/wizards/host-integrations/gridpane-instructions.php index 58e84b3..a32ca4b 100644 --- a/views/wizards/host-integrations/gridpane-instructions.php +++ b/views/wizards/host-integrations/gridpane-instructions.php @@ -10,23 +10,23 @@

      !

      - . . + . .

      - +

      - . + .

      - +

      - ! + !

      diff --git a/views/wizards/host-integrations/ready.php b/views/wizards/host-integrations/ready.php index ed0219e..2a5e058 100644 --- a/views/wizards/host-integrations/ready.php +++ b/views/wizards/host-integrations/ready.php @@ -7,28 +7,28 @@ ?>
      -
      - -

      - -

      -

      - get_title()); ?> -

      -
      +
      + +

      + +

      +

      + get_title()); ?> +

      +
      - + - - - + + + - +
      diff --git a/views/wizards/host-integrations/runcloud-instructions.php b/views/wizards/host-integrations/runcloud-instructions.php index b3b0dda..b5b0b95 100644 --- a/views/wizards/host-integrations/runcloud-instructions.php +++ b/views/wizards/host-integrations/runcloud-instructions.php @@ -10,20 +10,20 @@

      - , . + , .

      - +

      - . + .

      - +

      @@ -31,21 +31,21 @@

      .

      - +

      , . , .

      - +

      -

      - +

      +

      .

      - +

      .

      diff --git a/views/wizards/host-integrations/serverpilot-instructions.php b/views/wizards/host-integrations/serverpilot-instructions.php index 0a68e19..2a4c8b4 100644 --- a/views/wizards/host-integrations/serverpilot-instructions.php +++ b/views/wizards/host-integrations/serverpilot-instructions.php @@ -6,24 +6,24 @@ */ ?>
      -

      Step 1: Getting the API Key and the Client ID

      -

      In Your ServerPilot admin panel, first go to the Account Settings page and navigate to the API link, there you can get the API Key and Client ID (if the API Key field is empty, click the New API Key button). Paste those values somewhere as we'll need them in a later step.

      -
      - -
      +

      Step 1: Getting the API Key and the Client ID

      +

      In Your ServerPilot admin panel, first go to the Account Settings page and navigate to the API link, there you can get the API Key and Client ID (if the API Key field is empty, click the New API Key button). Paste those values somewhere as we'll need them in a later step.

      +
      + +
      -

      Step 2: Getting the App ID

      -

      Next, we’ll need to get the App ID for your WordPress site. To find that ID, navigate to your app’s manage page:

      -
      - -
      -

      Then, take a look at the URL at the top of your browser. The APP ID is the portion between the app/ and the /settings segments of the URL.

      +

      Step 2: Getting the App ID

      +

      Next, we’ll need to get the App ID for your WordPress site. To find that ID, navigate to your app’s manage page:

      +
      + +
      +

      Then, take a look at the URL at the top of your browser. The APP ID is the portion between the app/ and the /settings segments of the URL.

      -
      - -
      +
      + +
      -

      After this you can proceed to the next integration step where you can paste these values in the related fields.

      +

      After this you can proceed to the next integration step where you can paste these values in the related fields.

      diff --git a/views/wizards/host-integrations/test.php b/views/wizards/host-integrations/test.php index ce08650..e3d8f72 100644 --- a/views/wizards/host-integrations/test.php +++ b/views/wizards/host-integrations/test.php @@ -8,113 +8,113 @@

      - get_title()); ?> + get_title()); ?>

      -
      - - - - -
      +
      + + + + +
      -
      - - - - -
      +
      + + + + +
      -
      - - - - -
      +
      + + + + +
      -
      +
      -
      +
      -

      +

      -
        -
      1. - Configuration step - if available - and make sure you entered all the necessary information correctly;', 'wp-ultimo'); ?> -
      2. -
      3. - /* That\'s all, stop editing! Happy publishing. */)', 'wp-ultimo'); ?>); -
      4. -
      5. - -
      6. -
      +
        +
      1. + Configuration step - if available - and make sure you entered all the necessary information correctly;', 'wp-ultimo'); ?> +
      2. +
      3. + /* That\'s all, stop editing! Happy publishing. */)', 'wp-ultimo'); ?>); +
      4. +
      5. + +
      6. +
      -
      +
      - -
      + + - +
      + -
      - render_submit_box(); - ?> -
      +
      + render_submit_box(); + ?> +
      diff --git a/views/wizards/setup/alert.php b/views/wizards/setup/alert.php index 359537d..85287c0 100644 --- a/views/wizards/setup/alert.php +++ b/views/wizards/setup/alert.php @@ -7,36 +7,36 @@ ?>
      -
      +
      - + -

      - -

      +

      + +

      -

      - -

      +

      + +

      -

      - -

      +

      + +

      -
      +
      - + - + - +
      diff --git a/views/wizards/setup/default.php b/views/wizards/setup/default.php index ee06cb9..64bdb90 100644 --- a/views/wizards/setup/default.php +++ b/views/wizards/setup/default.php @@ -6,53 +6,53 @@ */ ?>

      - +

      -

      - -

      +

      + +

      - +
      - + - - - + + + - + -
      +
      - + - - - + + + - + - + - + - + -
      +
      diff --git a/views/wizards/setup/installation_steps.php b/views/wizards/setup/installation_steps.php index f4a93e8..d087f60 100644 --- a/views/wizards/setup/installation_steps.php +++ b/views/wizards/setup/installation_steps.php @@ -6,62 +6,62 @@ */ ?>
      - - - - - - - - - - - - $default) : ?> +
      + + + + + + + + + + + $default) : ?> - - - > + + + > - - - + + + - + - - - - - + + + + + - + - + - -
      - - - - + + + + - - - - - + + + + + - - - - - -
      - -
      + + + + + +
      + +
      + +
      diff --git a/views/wizards/setup/ready.php b/views/wizards/setup/ready.php index 318d16c..0b615ec 100644 --- a/views/wizards/setup/ready.php +++ b/views/wizards/setup/ready.php @@ -7,49 +7,49 @@ ?>
      -
      +
      - + -

      - customer->first) ? $page->customer->first : __('my friend', 'wp-ultimo'))); ?> -

      +

      + customer->first) ? $page->customer->first : __('my friend', 'wp-ultimo'))); ?> +

      -

      - Arindo Duque and NextPress.', 'wp-ultimo'); ?> -

      +

      + Arindo Duque and NextPress.', 'wp-ultimo'); ?> +

      -

      - GitHub', 'wp-ultimo');?> -

      +

      + GitHub', 'wp-ultimo'); ?> +

      -

      - The Support Page to find an expert who can assist in setting up WP Multisite WaaS or custom development.', 'wp-ultimo');?> -

      +

      + The Support Page to find an expert who can assist in setting up WP Multisite WaaS or custom development.', 'wp-ultimo'); ?> +

      -

      - -

      +

      + +

      -

      - +

      + -

      +

      -
      +
      - + - - - + + + - +
      diff --git a/views/wizards/setup/requirements_table.php b/views/wizards/setup/requirements_table.php index 7b32818..86346e9 100644 --- a/views/wizards/setup/requirements_table.php +++ b/views/wizards/setup/requirements_table.php @@ -7,89 +7,89 @@ ?>
      -
      - -
      +
      + +
      -
      - - - - - - - - - - - - - - - - - + + + +
      - - ' : ''; ?> +
      + + + + + + + + + + + + + + + + + - - - -
      + + ' : ''; ?> - + - - - - + + + + - -
      -
      -
      + +
      +
      +
      -
      - -
      +
      + +
      -
      - - - - - - - - - - - - + + + +
      - - ' : ''; ?> +
      + + + + + + + + + + + + - - - -
      + + ' : ''; ?> - + - - - - + + + + - -
      -
      -
      + +
      +
      +
      - + -
      - Read More links on each item to see what steps you need to take to bring your environment up to the WP Multisite WaaS current requirements.', 'wp-ultimo'); ?> -
      +
      + Read More links on each item to see what steps you need to take to bring your environment up to the WP Multisite WaaS current requirements.', 'wp-ultimo'); ?> +
      - +
      diff --git a/views/wizards/setup/support_terms.php b/views/wizards/setup/support_terms.php index e6bc09a..5e338cd 100644 --- a/views/wizards/setup/support_terms.php +++ b/views/wizards/setup/support_terms.php @@ -6,38 +6,38 @@ */ ?>
      -

      support@wpultimo.com and includes:', 'wp-ultimo'); ?>

      +

      support@wpultimo.com and includes:', 'wp-ultimo'); ?>

      -
        -
      • - - -
      • -
      • - - -
      • -
      • - - -
      • -
      +
        +
      • + + +
      • +
      • + + +
      • +
      • + + +
      • +
      -

      DOES NOT Include:', 'wp-ultimo'); ?>

      +

      DOES NOT Include:', 'wp-ultimo'); ?>

      -
        -
      • - - -
      • -
      • - - -
      • -
      • - - -
      • -
      +
        +
      • + + +
      • +
      • + + +
      • +
      • + + +
      • +
      diff --git a/wp-multisite-waas.php b/wp-multisite-waas.php index a2f903f..009ee5a 100644 --- a/wp-multisite-waas.php +++ b/wp-multisite-waas.php @@ -38,10 +38,10 @@ defined('ABSPATH') || exit; if ( defined('WP_SANDBOX_SCRAPING') && WP_SANDBOX_SCRAPING ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; - if ( is_plugin_active( 'wp-ultimo/wp-ultimo.php' ) ) { + if ( is_plugin_active('wp-ultimo/wp-ultimo.php') ) { // old plugin still installed and active with the old name and path // and the user is trying to activate this plugin. So deactivate and return. - deactivate_plugins( 'wp-ultimo/wp-ultimo.php', true, true); + deactivate_plugins('wp-ultimo/wp-ultimo.php', true, true); if ( file_exists(WP_CONTENT_DIR . '/sunrise.php')) { // We must override the old sunrise file or more name conflicts will occur. @@ -51,7 +51,7 @@ if ( defined('WP_SANDBOX_SCRAPING') && WP_SANDBOX_SCRAPING ) { } } -if (!defined('WP_ULTIMO_PLUGIN_FILE')) { +if ( ! defined('WP_ULTIMO_PLUGIN_FILE')) { define('WP_ULTIMO_PLUGIN_FILE', __FILE__); } @@ -82,9 +82,7 @@ if ( ! function_exists('WP_Ultimo')) { * @since 2.0.0 */ function WP_Ultimo() { // phpcs:ignore - return WP_Ultimo::get_instance(); - } // end WP_Ultimo; } // Initialize and set to global for back-compat