122 lines
2.9 KiB
PHP
122 lines
2.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 1984 Hosting Support UI class
|
|
*
|
|
* @package HostingSupport1984
|
|
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html GNU General Public License v2.0
|
|
*
|
|
* This is where we add the "1984 Hosting Support" widget to the wp-admin
|
|
* dashboard.
|
|
*
|
|
* We also plan to use this file to add more widgets and views to the wp-admin
|
|
* interface for support and configuration options.
|
|
*
|
|
* Feel free to remove this file if you don't intend to use the 1984/HostingSupport1984
|
|
* user interface additions.
|
|
*/
|
|
class HostingSupport1984UI {
|
|
const VIEWS_DIR = './views/';
|
|
|
|
/**
|
|
* Construct a new HostingSupport1984UI object
|
|
*/
|
|
public function __construct() {
|
|
// Add the 1984 Support Information dashboard widget.
|
|
add_action(
|
|
'wp_dashboard_setup',
|
|
array( $this, 'add_dashboard_widget' )
|
|
);
|
|
|
|
// Enqueue the admin JS and CSS.
|
|
add_action(
|
|
'admin_enqueue_scripts',
|
|
array( $this, 'enqueue_admin_scripts' )
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Render a view
|
|
*
|
|
* @param String $view_file The filename of the view to render.
|
|
* @param Boolean $admin_only Only display the view to users with the manage_options capability.
|
|
*
|
|
* @return Boolean True if the user has access to the view. False if not.
|
|
*/
|
|
public function render_view( string $view_file, bool $admin_only = true ) {
|
|
if (
|
|
true === $admin_only && current_user_can( 'manage_options' ) ||
|
|
false === $admin_only
|
|
) {
|
|
require self::view_path( $view_file );
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Get full file path for a view
|
|
*
|
|
* @param String $view_file The view file name.
|
|
* @return String The path.
|
|
*/
|
|
private function view_path( $view_file ) {
|
|
return plugin_dir_path( __FILE__ ) . self::VIEWS_DIR . $view_file;
|
|
}
|
|
|
|
/**
|
|
* Check if the user can see the 1984 admin panel
|
|
*
|
|
* @return [type] [description]
|
|
*/
|
|
private function current_user_can_view_admin_panel() {
|
|
return ( true === current_user_can( 'manage_options' ) );
|
|
}
|
|
|
|
/**
|
|
* Add the 1984 Hosting dashboard widget.
|
|
*/
|
|
public function add_dashboard_widget() {
|
|
wp_add_dashboard_widget(
|
|
'1984_hosting_support_widget',
|
|
__( '1984 Hosting Support', 'hostingsupport1984' ),
|
|
array( $this, 'render_dashboard_widget' )
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Render the 1984 Hosting dashboard widget.
|
|
*/
|
|
public function render_dashboard_widget() {
|
|
$this->render_view( 'support-dashboard-widget.php' );
|
|
}
|
|
|
|
/**
|
|
* Enqueue the 1984 wp-admin scripts
|
|
*/
|
|
public function enqueue_admin_scripts() {
|
|
wp_enqueue_script(
|
|
'1984-hosting-support-admin',
|
|
plugins_url(
|
|
'js/1984-hosting-support.js',
|
|
__FILE__
|
|
),
|
|
array(),
|
|
HostingSupport1984::HOSTING_SUPPORT_VERSION,
|
|
true
|
|
);
|
|
wp_enqueue_style(
|
|
'1984-hosting-support-admin',
|
|
plugins_url(
|
|
'style/1984-hosting-support.css',
|
|
__FILE__
|
|
),
|
|
array(),
|
|
HostingSupport1984::HOSTING_SUPPORT_VERSION,
|
|
false
|
|
);
|
|
}
|
|
}
|
|
|
|
$hosting_support_1984_ui = new HostingSupport1984UI();
|