Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #199 from devuri/feat_adds-admin-page-packagist_pl…
Browse files Browse the repository at this point in the history
…ugins_list

feat: adds plugins list admin page
  • Loading branch information
devuri authored Nov 2, 2023
2 parents a9e836a + c929c9d commit 6bff3a0
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/App/Core/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace Urisoft\App\Core;

use Urisoft\App\Core\Settings\AdminSettingsPage;

class Plugin
{
protected $env_menu_id;
Expand Down Expand Up @@ -123,6 +125,20 @@ function ( $actions, $plugin_file, $plugin_data, $context ) {
);

$this->add_core_app_events();

// Add some special admin pages.
new AdminSettingsPage(
'Composer plugins',
function (): void {
?><div class="wrap">
<h2>Composer Plugins List</h2>
<?php
dump( app_packagist_plugins_list() );
?>
</div>
<?php
}
);
}

public static function init(): self
Expand Down
67 changes: 67 additions & 0 deletions src/App/Core/Settings/AdminSettingsPage.php
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
);
}
}

0 comments on commit 6bff3a0

Please sign in to comment.