Group HG plugins under a shared branded admin menu
This commit is contained in:
1 parent
9e9133c93e
commit
0cad18c757
7 files changed
+81
-6
No files matched your search
+1
-1
@@ -31,7 +31,7 @@ function hgcf_workflow_card($flow,$index,$languages,$template=false) {
|
||||
</div></details>
|
||||
<?php
|
||||
}
|
||||
add_action('admin_enqueue_scripts',function($hook){if($hook!=='toplevel_page_hg-contactform')return;wp_enqueue_style('hgcf-admin',plugins_url('assets/admin.css',HGCF_FILE),[],HGCF_VERSION);wp_enqueue_script('hgcf-admin',plugins_url('assets/admin.js',HGCF_FILE),[],HGCF_VERSION,true);});
|
||||
add_action('admin_enqueue_scripts',function($hook){if($hook!==HG_Plugin_Admin::hook('hg-contactform'))return;wp_enqueue_style('hgcf-admin',plugins_url('assets/admin.css',HGCF_FILE),[],HGCF_VERSION);wp_enqueue_script('hgcf-admin',plugins_url('assets/admin.js',HGCF_FILE),[],HGCF_VERSION,true);});
|
||||
function hgcf_admin_info() {
|
||||
$manifest=json_decode(file_get_contents(__DIR__.'/vendor/altcha/versions.json'),true);
|
||||
$version=fn($key)=>is_string($manifest[$key]['version']??null)?$manifest[$key]['version']:'Niet beschikbaar';
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* HG admin navigation, bundled identically in each standalone HG plugin.
|
||||
* Shared component version: 1.0.0. Update both copies together.
|
||||
*/
|
||||
if (!defined('ABSPATH')) exit;
|
||||
if (!class_exists('HG_Plugin_Admin', false)) {
|
||||
|
||||
final class HG_Plugin_Admin {
|
||||
private static array $plugins = [];
|
||||
private static array $hooks = [];
|
||||
|
||||
public static function register(array $plugin): void {
|
||||
self::$plugins[$plugin['slug']] = $plugin;
|
||||
}
|
||||
|
||||
public static function hook(string $slug): string {
|
||||
return self::$hooks[$slug] ?? '';
|
||||
}
|
||||
|
||||
public static function menu(): void {
|
||||
if (!self::$plugins) return;
|
||||
add_menu_page('HG Plugins', 'HG Plugins', 'manage_options', 'hg-plugins', [self::class, 'overview'], 'dashicons-screenoptions', 58);
|
||||
add_submenu_page('hg-plugins', 'HG Plugins', 'Overzicht', 'manage_options', 'hg-plugins', [self::class, 'overview']);
|
||||
uasort(self::$plugins, fn($a, $b) => strcasecmp($a['label'], $b['label']));
|
||||
foreach (self::$plugins as $slug => $plugin) {
|
||||
self::$hooks[$slug] = (string) add_submenu_page('hg-plugins', $plugin['title'], $plugin['label'], 'manage_options', $slug, $plugin['callback']);
|
||||
}
|
||||
}
|
||||
|
||||
public static function styles(): void {
|
||||
if (!self::$plugins || !current_user_can('manage_options')) return;
|
||||
wp_enqueue_style('hg-admin-menu', plugins_url('../assets/hg-admin-menu.css', __FILE__), [], '1.0.0');
|
||||
}
|
||||
|
||||
public static function overview(): void {
|
||||
if (!current_user_can('manage_options')) wp_die('Geen toegang.', '', ['response' => 403]);
|
||||
?>
|
||||
<div class="wrap hg-suite">
|
||||
<header class="hg-suite-header"><span class="hg-suite-mark" aria-hidden="true">HG</span><div><h1>HG Plugins</h1><p>De Hippogrief-modules op deze website.</p></div></header>
|
||||
<div class="hg-suite-grid">
|
||||
<?php foreach (self::$plugins as $slug => $plugin): ?>
|
||||
<section class="hg-suite-card"><span class="hg-suite-version">Versie <?php echo esc_html($plugin['version']); ?></span><h2><?php echo esc_html($plugin['title']); ?></h2><p><?php echo esc_html($plugin['description']); ?></p><a class="button button-primary" href="<?php echo esc_url(add_query_arg('page', $slug, admin_url('admin.php'))); ?>">Beheren</a></section>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
add_action('admin_menu', [HG_Plugin_Admin::class, 'menu'], 20);
|
||||
add_action('admin_enqueue_scripts', [HG_Plugin_Admin::class, 'styles']);
|
||||
}
|
||||
@@ -102,6 +102,6 @@ function hgcf_sanitize_settings($input) {
|
||||
$out['schema_version']=2;
|
||||
return $out;
|
||||
}
|
||||
add_action('admin_menu',function(){add_menu_page('HG Contactformulier','Contactformulier','manage_options','hg-contactform','hgcf_admin_page','dashicons-email-alt',58);});
|
||||
HG_Plugin_Admin::register(['slug'=>'hg-contactform','title'=>'HG Contactformulier','label'=>'Contactformulier','callback'=>'hgcf_admin_page','version'=>HGCF_VERSION,'description'=>'Contactformulieren, workflows en e-mailinstellingen beheren.']);
|
||||
add_action('admin_init',function(){register_setting('hgcf','hgcf_settings',['type'=>'array','sanitize_callback'=>'hgcf_sanitize_settings']);});
|
||||
require_once __DIR__.'/admin.php';
|
||||
Reference in new issue
Block a user