Change to WordPress format

This commit is contained in:
2025-12-02 14:36:52 +00:00
parent bf71c6c8a0
commit b485445dfc
3 changed files with 130 additions and 119 deletions

View File

@@ -15,49 +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/';
/**
* 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()
{
public function add_dashboard_widget() {
wp_add_dashboard_widget(
'1984_hosting_support_widget',
__('1984 Hosting Support', 'hostingsupport1984'),
array($this,
'render_dashboard_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');
public function render_dashboard_widget() {
$this->render_view( 'support-dashboard-widget.php' );
}
/**
@@ -68,15 +70,16 @@ 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): bool
{
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;
}
@@ -87,16 +90,14 @@ class HostingSupport1984UI
*
* @return String The path.
*/
private function view_path(string $view_file): string
{
return plugin_dir_path(__FILE__) . self::VIEWS_DIR . $view_file;
private function view_path( string $view_file ): string {
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(
@@ -124,9 +125,8 @@ class HostingSupport1984UI
*
* @return bool [type] [description]
*/
private function current_user_can_view_admin_panel(): bool
{
return (true === current_user_can('manage_options'));
private function current_user_can_view_admin_panel(): bool {
return ( true === current_user_can( 'manage_options' ) );
}
}