This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #199 from devuri/feat_adds-admin-page-packagist_pl…
…ugins_list feat: adds plugins list admin page
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Urisoft\App\Core\Settings; | ||
|
||
/** | ||
* Custom Admin Page class for WordPress. | ||
*/ | ||
class AdminSettingsPage | ||
{ | ||
/** | ||
* @var string $settings_page The name of the setting. | ||
*/ | ||
private $settings_page; | ||
|
||
/** | ||
* @var string $content_callback The content of the settings page. | ||
*/ | ||
private $content_callback; | ||
|
||
/** | ||
* @var bool $is_submenu Whether the page should be a submenu. | ||
*/ | ||
private $is_submenu; | ||
|
||
/** | ||
* AdminSettingsPage constructor. | ||
* | ||
* @param string $settings_page The name of the setting. | ||
* @param callback $page_content_callback The content callback of the settings page. | ||
* @param bool $is_submenu Whether the page should be a submenu. | ||
*/ | ||
public function __construct( string $settings_page, $page_content_callback = null, bool $is_submenu = true ) | ||
{ | ||
$this->settings_page = $settings_page; | ||
$this->content_callback = $page_content_callback ?? 'no_callback_defined'; | ||
$this->is_submenu = $is_submenu; | ||
|
||
add_action( 'admin_menu', [ $this, 'register_settings_page' ] ); | ||
} | ||
|
||
/** | ||
* Registers the custom settings page in the WordPress admin menu. | ||
*/ | ||
public function register_settings_page(): void | ||
{ | ||
if ( $this->is_submenu ) { | ||
add_submenu_page( | ||
'options-general.php', | ||
$this->settings_page . ' admin', | ||
$this->settings_page, | ||
'manage_options', | ||
sanitize_title( $this->settings_page ), | ||
$this->content_callback | ||
); | ||
|
||
return; | ||
} | ||
|
||
add_options_page( | ||
$this->settings_page . ' admin', | ||
$this->settings_page, | ||
'manage_options', | ||
sanitize_title( $this->settings_page ), | ||
$this->content_callback | ||
); | ||
} | ||
} |