Initial Commit
This commit is contained in:
254
inc/admin-pages/customer-panel/class-account-admin-page.php
Normal file
254
inc/admin-pages/customer-panel/class-account-admin-page.php
Normal file
@ -0,0 +1,254 @@
|
||||
<?php
|
||||
/**
|
||||
* WP Ultimo My_Account Admin Page.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Admin_Pages
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Admin_Pages\Customer_Panel;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Admin_Page;
|
||||
|
||||
/**
|
||||
* WP Ultimo My_Account Admin Page.
|
||||
*/
|
||||
class Account_Admin_Page extends Base_Customer_Facing_Admin_Page {
|
||||
|
||||
/**
|
||||
* Holds the ID for this page, this is also used as the page slug.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id = 'account';
|
||||
|
||||
/**
|
||||
* Menu position. This is only used for top-level menus
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var integer
|
||||
*/
|
||||
protected $position = 101_010_101;
|
||||
|
||||
/**
|
||||
* Dashicon to be used on the menu item. This is only used on top-level menus
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var string
|
||||
*/
|
||||
protected $menu_icon = 'dashicons-wu-email';
|
||||
|
||||
/**
|
||||
* If this number is greater than 0, a badge with the number will be displayed alongside the menu title
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var integer
|
||||
*/
|
||||
protected $badge_count = 0;
|
||||
|
||||
/**
|
||||
* Should we hide admin notices on this page?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $hide_admin_notices = true;
|
||||
|
||||
/**
|
||||
* Holds the admin panels where this page should be displayed, as well as which capability to require.
|
||||
*
|
||||
* To add a page to the regular admin (wp-admin/), use: 'admin_menu' => 'capability_here'
|
||||
* To add a page to the network admin (wp-admin/network), use: 'network_admin_menu' => 'capability_here'
|
||||
* To add a page to the user (wp-admin/user) admin, use: 'user_admin_menu' => 'capability_here'
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $supported_panels = array(
|
||||
'admin_menu' => 'exist',
|
||||
'user_admin_menu' => 'exist',
|
||||
);
|
||||
|
||||
/**
|
||||
* The current site instance.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var \WP_Ultimo\Models\Site
|
||||
*/
|
||||
protected $current_site;
|
||||
|
||||
/**
|
||||
* The current membership instance.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var \WP_Ultimo\Models\Membership
|
||||
*/
|
||||
protected $current_membership;
|
||||
|
||||
/**
|
||||
* Checks if we need to add this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->current_site = wu_get_current_site();
|
||||
|
||||
$this->current_membership = $this->current_site->get_membership();
|
||||
|
||||
$this->register_page_settings();
|
||||
|
||||
if ($this->current_site->get_type() === 'customer_owned') {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Loads the current site and membership.
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
public function page_loaded() {
|
||||
|
||||
$this->current_site = wu_get_current_site();
|
||||
|
||||
$this->current_membership = $this->current_site->get_membership();
|
||||
|
||||
$this->add_notices();
|
||||
|
||||
} // end page_loaded;
|
||||
|
||||
/**
|
||||
* Adds notices after a membership is changed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function add_notices() {
|
||||
|
||||
$nonce = wu_request('nonce');
|
||||
|
||||
$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.
|
||||
*
|
||||
* @see https://codex.wordpress.org/Plugin_API/Action_Reference/load-(page)
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
public function hooks() {} // end hooks;
|
||||
|
||||
/**
|
||||
* Allow child classes to add screen options; Useful for pages that have list tables.
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
public function screen_options() {} // end screen_options;
|
||||
|
||||
/**
|
||||
* Allow child classes to register widgets, if they need them.
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
public function register_widgets() {
|
||||
|
||||
\WP_Ultimo\UI\Current_Membership_Element::get_instance()->as_metabox(get_current_screen()->id);
|
||||
|
||||
\WP_Ultimo\UI\Billing_Info_Element::get_instance()->as_metabox(get_current_screen()->id, 'side');
|
||||
|
||||
\WP_Ultimo\UI\Invoices_Element::get_instance()->as_metabox(get_current_screen()->id, 'side');
|
||||
|
||||
\WP_Ultimo\UI\Site_Actions_Element::get_instance()->as_metabox(get_current_screen()->id, 'side');
|
||||
|
||||
\WP_Ultimo\UI\Account_Summary_Element::get_instance()->as_metabox(get_current_screen()->id);
|
||||
|
||||
\WP_Ultimo\UI\Limits_Element::get_instance()->as_metabox(get_current_screen()->id);
|
||||
|
||||
\WP_Ultimo\UI\Domain_Mapping_Element::get_instance()->as_metabox(get_current_screen()->id, 'side');
|
||||
|
||||
\WP_Ultimo\UI\Login_Form_Element::get_instance()->as_inline_content(get_current_screen()->id, 'wu_dash_before_metaboxes');
|
||||
|
||||
\WP_Ultimo\UI\Simple_Text_Element::get_instance()->as_inline_content(get_current_screen()->id, 'wu_dash_before_metaboxes');
|
||||
|
||||
\WP_Ultimo\UI\Current_Site_Element::get_instance()->as_inline_content(get_current_screen()->id, 'wu_dash_before_metaboxes', array('show_admin_link' => false));
|
||||
|
||||
} // end register_widgets;
|
||||
|
||||
/**
|
||||
* Returns the title of the page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string Title of the page.
|
||||
*/
|
||||
public function get_title() {
|
||||
|
||||
return __('Account', 'wp-ultimo');
|
||||
|
||||
} // end get_title;
|
||||
|
||||
/**
|
||||
* Returns the title of menu for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string Menu label of the 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.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string False to use the title menu or string with sub-menu title.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
public function output() {
|
||||
/*
|
||||
* 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;
|
259
inc/admin-pages/customer-panel/class-add-new-site-admin-page.php
Normal file
259
inc/admin-pages/customer-panel/class-add-new-site-admin-page.php
Normal file
@ -0,0 +1,259 @@
|
||||
<?php
|
||||
/**
|
||||
* WP Ultimo Add New Site Admin Page.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Admin_Pages
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Admin_Pages\Customer_Panel;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Admin_Page;
|
||||
|
||||
/**
|
||||
* WP Ultimo Add New Site 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
|
||||
*/
|
||||
protected $id = 'add-new-site';
|
||||
|
||||
/**
|
||||
* Is this a top-level menu or a submenu?
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'submenu';
|
||||
|
||||
/**
|
||||
* Allows us to highlight another menu page, if this page has no parent page at all.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $highlight_menu_slug = 'sites';
|
||||
|
||||
/**
|
||||
* Menu position. This is only used for top-level menus
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var integer
|
||||
*/
|
||||
protected $position = 101_010_101;
|
||||
|
||||
/**
|
||||
* Dashicon to be used on the menu item. This is only used on top-level menus
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var string
|
||||
*/
|
||||
protected $menu_icon = 'dashicons-wu-browser';
|
||||
|
||||
/**
|
||||
* If this number is greater than 0, a badge with the number will be displayed alongside the menu title
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var integer
|
||||
*/
|
||||
protected $badge_count = 0;
|
||||
|
||||
/**
|
||||
* Should we hide admin notices on this page?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $hide_admin_notices = true;
|
||||
|
||||
/**
|
||||
* Holds the admin panels where this page should be displayed, as well as which capability to require.
|
||||
*
|
||||
* To add a page to the regular admin (wp-admin/), use: 'admin_menu' => 'capability_here'
|
||||
* To add a page to the network admin (wp-admin/network), use: 'network_admin_menu' => 'capability_here'
|
||||
* To add a page to the user (wp-admin/user) admin, use: 'user_admin_menu' => 'capability_here'
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $supported_panels = array(
|
||||
'admin_menu' => 'exist',
|
||||
'user_admin_menu' => 'exist',
|
||||
);
|
||||
|
||||
/**
|
||||
* The current customer instance.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var \WP_Ultimo\Models\Customer
|
||||
*/
|
||||
protected $customer;
|
||||
|
||||
/**
|
||||
* The current site instance.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @var \WP_Ultimo\Models\Site
|
||||
*/
|
||||
protected $current_site;
|
||||
|
||||
/**
|
||||
* The current membership instance.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @var \WP_Ultimo\Models\Membership|false
|
||||
*/
|
||||
protected $current_membership;
|
||||
|
||||
/**
|
||||
* Checks if we need to add this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->current_site = wu_get_current_site();
|
||||
|
||||
$this->current_membership = $this->current_site->get_membership();
|
||||
|
||||
$this->register_page_settings();
|
||||
|
||||
if ($this->current_site->get_type() === 'customer_owned') {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Loads the current site and membership.
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @see https://codex.wordpress.org/Plugin_API/Action_Reference/load-(page)
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
public function hooks() {} // end hooks;
|
||||
|
||||
/**
|
||||
* Force the screen options so our customize options show up.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* Allow child classes to add screen options; Useful for pages that have list tables.
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
public function screen_options() {} // end screen_options;
|
||||
|
||||
/**
|
||||
* Allow child classes to register widgets, if they need them.
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
public function register_widgets() {
|
||||
|
||||
\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;
|
||||
|
||||
/**
|
||||
* Returns the title of the page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string Title of the page.
|
||||
*/
|
||||
public function get_title() {
|
||||
|
||||
return __('Add New Site', 'wp-ultimo');
|
||||
|
||||
} // end get_title;
|
||||
|
||||
/**
|
||||
* Returns the title of menu for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string Menu label of the 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.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string False to use the title menu or string with sub-menu title.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
public function output() {
|
||||
/*
|
||||
* 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;
|
191
inc/admin-pages/customer-panel/class-checkout-admin-page.php
Normal file
191
inc/admin-pages/customer-panel/class-checkout-admin-page.php
Normal file
@ -0,0 +1,191 @@
|
||||
<?php
|
||||
/**
|
||||
* WP Ultimo Customer Checkout Admin Page.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Admin_Pages
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Admin_Pages\Customer_Panel;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* WP Ultimo Dashboard Admin Page.
|
||||
*/
|
||||
class Checkout_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Admin_Page {
|
||||
|
||||
/**
|
||||
* Holds the ID for this page, this is also used as the page slug.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id = 'wu-checkout';
|
||||
|
||||
/**
|
||||
* Is this a top-level menu or a submenu?
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'submenu';
|
||||
|
||||
/**
|
||||
* Is this a top-level menu or a submenu?
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var string
|
||||
*/
|
||||
protected $parent = 'none';
|
||||
|
||||
/**
|
||||
* This page has no parent, so we need to highlight another sub-menu.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $highlight_menu_slug = 'account';
|
||||
|
||||
/**
|
||||
* If this number is greater than 0, a badge with the number will be displayed alongside the menu title
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var integer
|
||||
*/
|
||||
protected $badge_count = 0;
|
||||
|
||||
/**
|
||||
* Holds the admin panels where this page should be displayed, as well as which capability to require.
|
||||
*
|
||||
* To add a page to the regular admin (wp-admin/), use: 'admin_menu' => 'capability_here'
|
||||
* To add a page to the network admin (wp-admin/network), use: 'network_admin_menu' => 'capability_here'
|
||||
* To add a page to the user (wp-admin/user) admin, use: 'user_admin_menu' => 'capability_here'
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $supported_panels = array(
|
||||
'user_admin_menu' => 'read',
|
||||
'admin_menu' => 'read',
|
||||
);
|
||||
|
||||
/**
|
||||
* Should we hide admin notices on this page?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $hide_admin_notices = true;
|
||||
|
||||
/**
|
||||
* Should we force the admin menu into a folded state?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $fold_menu = true;
|
||||
|
||||
/**
|
||||
* Returns the title of the page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string Title of the page.
|
||||
*/
|
||||
public function get_title() {
|
||||
|
||||
return sprintf(__('Checkout', 'wp-ultimo'));
|
||||
|
||||
} // end get_title;
|
||||
|
||||
/**
|
||||
* Returns the title of menu for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string Menu label of the page.
|
||||
*/
|
||||
public function get_menu_title() {
|
||||
|
||||
return __('Checkout', 'wp-ultimo');
|
||||
|
||||
} // end get_menu_title;
|
||||
|
||||
/**
|
||||
* Registers the necessary scripts.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function register_scripts() {
|
||||
|
||||
do_action('wu_checkout_scripts', null, null);
|
||||
|
||||
} // end register_scripts;
|
||||
|
||||
/**
|
||||
* Overrides the page loaded method.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function page_loaded() {
|
||||
|
||||
do_action('wu_setup_checkout', null);
|
||||
|
||||
parent::page_loaded();
|
||||
|
||||
} // end page_loaded;
|
||||
|
||||
/**
|
||||
* Returns the sections for this Wizard.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
|
||||
$sections = array(
|
||||
'plan' => array(
|
||||
'title' => __('Change Membership', 'wp-ultimo'),
|
||||
'view' => array($this, 'display_checkout_form'),
|
||||
),
|
||||
);
|
||||
|
||||
return $sections;
|
||||
|
||||
} // end get_sections;
|
||||
|
||||
/**
|
||||
* Displays the content of the activation section.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function output() {
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Allow child classes to register widgets, if they need them.
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
public function register_widgets() {
|
||||
|
||||
\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;
|
290
inc/admin-pages/customer-panel/class-my-sites-admin-page.php
Normal file
290
inc/admin-pages/customer-panel/class-my-sites-admin-page.php
Normal file
@ -0,0 +1,290 @@
|
||||
<?php
|
||||
/**
|
||||
* WP Ultimo My Sites Admin Page.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Admin_Pages
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Admin_Pages\Customer_Panel;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Admin_Page;
|
||||
|
||||
/**
|
||||
* WP Ultimo My Sites 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
|
||||
*/
|
||||
protected $id = 'sites';
|
||||
|
||||
/**
|
||||
* Menu position. This is only used for top-level menus
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var integer
|
||||
*/
|
||||
protected $position = 101_010_101;
|
||||
|
||||
/**
|
||||
* Dashicon to be used on the menu item. This is only used on top-level menus
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var string
|
||||
*/
|
||||
protected $menu_icon = 'dashicons-wu-browser';
|
||||
|
||||
/**
|
||||
* If this number is greater than 0, a badge with the number will be displayed alongside the menu title
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var integer
|
||||
*/
|
||||
protected $badge_count = 0;
|
||||
|
||||
/**
|
||||
* Should we hide admin notices on this page?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $hide_admin_notices = true;
|
||||
|
||||
/**
|
||||
* Holds the admin panels where this page should be displayed, as well as which capability to require.
|
||||
*
|
||||
* To add a page to the regular admin (wp-admin/), use: 'admin_menu' => 'capability_here'
|
||||
* To add a page to the network admin (wp-admin/network), use: 'network_admin_menu' => 'capability_here'
|
||||
* To add a page to the user (wp-admin/user) admin, use: 'user_admin_menu' => 'capability_here'
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $supported_panels = array(
|
||||
'admin_menu' => 'exist',
|
||||
'user_admin_menu' => 'exist',
|
||||
);
|
||||
|
||||
/**
|
||||
* The current customer instance.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var \WP_Ultimo\Models\Customer
|
||||
*/
|
||||
protected $customer;
|
||||
|
||||
/**
|
||||
* The current site instance.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @var \WP_Ultimo\Models\Site
|
||||
*/
|
||||
public $current_site;
|
||||
|
||||
/**
|
||||
* The current membership instance.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @var \WP_Ultimo\Models\Membership|false
|
||||
*/
|
||||
public $current_membership;
|
||||
|
||||
/**
|
||||
* Checks if we need to add this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->current_site = wu_get_current_site();
|
||||
|
||||
$this->current_membership = $this->current_site->get_membership();
|
||||
|
||||
$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'));
|
||||
|
||||
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.
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @see https://codex.wordpress.org/Plugin_API/Action_Reference/load-(page)
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
public function hooks() {} // end hooks;
|
||||
|
||||
/**
|
||||
* Remove the default my sites link.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function unset_default_my_sites_menu() {
|
||||
|
||||
global $submenu;
|
||||
|
||||
unset($submenu['index.php'][5]);
|
||||
|
||||
} // end unset_default_my_sites_menu;
|
||||
|
||||
/**
|
||||
* Update the my sites link on the top-bar.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param object $wp_admin_bar The admin bar object.
|
||||
* @return void
|
||||
*/
|
||||
public function change_my_sites_link($wp_admin_bar) {
|
||||
|
||||
$my_sites = $wp_admin_bar->get_node('my-sites');
|
||||
|
||||
if (empty($my_sites)) {
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
|
||||
$args = array(
|
||||
'page' => 'sites',
|
||||
);
|
||||
|
||||
$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.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* Allow child classes to add screen options; Useful for pages that have list tables.
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
public function screen_options() {} // end screen_options;
|
||||
|
||||
/**
|
||||
* Allow child classes to register widgets, if they need them.
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
public function register_widgets() {
|
||||
|
||||
\WP_Ultimo\UI\Login_Form_Element::get_instance()->as_inline_content(get_current_screen()->id, 'wu_dash_before_metaboxes');
|
||||
|
||||
\WP_Ultimo\UI\Simple_Text_Element::get_instance()->as_inline_content(get_current_screen()->id, 'wu_dash_before_metaboxes');
|
||||
|
||||
\WP_Ultimo\UI\My_Sites_Element::get_instance()->as_inline_content(get_current_screen()->id, 'wu_dash_before_metaboxes');
|
||||
|
||||
} // end register_widgets;
|
||||
|
||||
/**
|
||||
* Returns the title of the page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string Title of the page.
|
||||
*/
|
||||
public function get_title() {
|
||||
|
||||
return __('My Sites', 'wp-ultimo');
|
||||
|
||||
} // end get_title;
|
||||
|
||||
/**
|
||||
* Returns the title of menu for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string Menu label of the 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.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string False to use the title menu or string with sub-menu title.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
public function output() {
|
||||
/*
|
||||
* 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;
|
@ -0,0 +1,181 @@
|
||||
<?php
|
||||
/**
|
||||
* WP Ultimo Switch Template Admin Page.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Admin_Pages
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Admin_Pages\Customer_Panel;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* WP Ultimo Switch Template Admin Page.
|
||||
*/
|
||||
class Template_Switching_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Admin_Page {
|
||||
|
||||
/**
|
||||
* Holds the ID for this page, this is also used as the page slug.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id = 'wu-template-switching';
|
||||
|
||||
/**
|
||||
* Is this a top-level menu or a submenu?
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'submenu';
|
||||
|
||||
/**
|
||||
* Is this a top-level menu or a submenu?
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var string
|
||||
*/
|
||||
protected $parent = 'none';
|
||||
|
||||
/**
|
||||
* This page has no parent, so we need to highlight another sub-menu.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $highlight_menu_slug = 'account';
|
||||
|
||||
/**
|
||||
* If this number is greater than 0, a badge with the number will be displayed alongside the menu title
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @var integer
|
||||
*/
|
||||
protected $badge_count = 0;
|
||||
|
||||
/**
|
||||
* Holds the admin panels where this page should be displayed, as well as which capability to require.
|
||||
*
|
||||
* To add a page to the regular admin (wp-admin/), use: 'admin_menu' => 'capability_here'
|
||||
* To add a page to the network admin (wp-admin/network), use: 'network_admin_menu' => 'capability_here'
|
||||
* To add a page to the user (wp-admin/user) admin, use: 'user_admin_menu' => 'capability_here'
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $supported_panels = array(
|
||||
'user_admin_menu' => 'read',
|
||||
'admin_menu' => 'read',
|
||||
);
|
||||
|
||||
/**
|
||||
* Should we hide admin notices on this page?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $hide_admin_notices = true;
|
||||
|
||||
/**
|
||||
* Should we force the admin menu into a folded state?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $fold_menu = true;
|
||||
|
||||
/**
|
||||
* If this customer facing page has menu settings.
|
||||
*
|
||||
* @since 2.0.9
|
||||
* @var boolean
|
||||
*/
|
||||
protected $menu_settings = false;
|
||||
|
||||
/**
|
||||
* Returns the title of the page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string Title of the page.
|
||||
*/
|
||||
public function get_title() {
|
||||
|
||||
return __('Switch Template', 'wp-ultimo');
|
||||
|
||||
} // end get_title;
|
||||
|
||||
/**
|
||||
* Returns the title of menu for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string Menu label of the page.
|
||||
*/
|
||||
public function get_menu_title() {
|
||||
|
||||
return __('Switch Template', 'wp-ultimo');
|
||||
|
||||
} // end get_menu_title;
|
||||
|
||||
/**
|
||||
* Registers the necessary scripts.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function register_scripts() {
|
||||
|
||||
do_action('wu_template_switching_admin_page_scripts', null, null);
|
||||
|
||||
} // end register_scripts;
|
||||
|
||||
/**
|
||||
* Overrides the page loaded method.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function page_loaded() {
|
||||
|
||||
do_action('wu_template_switching_admin_page', null);
|
||||
|
||||
parent::page_loaded();
|
||||
|
||||
} // end page_loaded;
|
||||
|
||||
/**
|
||||
* Displays the content of the activation section.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function output() {
|
||||
/*
|
||||
* 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')
|
||||
)
|
||||
));
|
||||
|
||||
} // end output;
|
||||
|
||||
/**
|
||||
* Allow child classes to register widgets, if they need them.
|
||||
*
|
||||
* @since 1.8.2
|
||||
* @return void
|
||||
*/
|
||||
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;
|
Reference in New Issue
Block a user