First draft

This commit is contained in:
2025-12-02 10:06:37 +00:00
parent 6d76533d1f
commit 801c24885b
11 changed files with 498 additions and 165 deletions

View File

@@ -15,26 +15,51 @@
* Feel free to remove this file if you don't intend to use the 1984/HostingSupport1984
* user interface additions.
*/
class HostingSupport1984UI {
class HostingSupport1984UI
{
const VIEWS_DIR = './views/';
/**
* Construct a new HostingSupport1984UI object
* Build a new HostingSupport1984UI object
*/
public function __construct() {
public function __construct()
{
// Add the 1984 Support Information dashboard widget.
add_action(
'wp_dashboard_setup',
array( $this, 'add_dashboard_widget' )
array($this,
'add_dashboard_widget')
);
// Enqueue the admin JS and CSS.
add_action(
'admin_enqueue_scripts',
array( $this, 'enqueue_admin_scripts' )
array($this,
'enqueue_admin_scripts')
);
}
/**
* 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');
}
/**
* Render a view
*
@@ -43,12 +68,13 @@ class HostingSupport1984UI {
*
* @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 ) {
public function render_view(string $view_file, bool $admin_only = true): bool
{
if (
true === $admin_only && current_user_can( 'manage_options' ) ||
true === $admin_only && current_user_can('manage_options') ||
false === $admin_only
) {
require self::view_path( $view_file );
require self::view_path($view_file);
return true;
}
return false;
@@ -57,44 +83,20 @@ class HostingSupport1984UI {
/**
* Get full file path for a view
*
* @param String $view_file The view file name.
* @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' );
private function view_path(string $view_file)
{
return plugin_dir_path(__FILE__) . self::VIEWS_DIR . $view_file;
}
/**
* Enqueue the 1984 wp-admin scripts
*/
public function enqueue_admin_scripts() {
public function enqueue_admin_scripts()
{
wp_enqueue_script(
'1984-hosting-support-admin',
plugins_url(
@@ -116,6 +118,16 @@ class HostingSupport1984UI {
false
);
}
/**
* Check if the user can see the 1984 admin panel
*
* @return bool [type] [description]
*/
private function current_user_can_view_admin_panel(): bool
{
return (true === current_user_can('manage_options'));
}
}
$hosting_support_1984_ui = new HostingSupport1984UI();