added settings page sceleton

This commit is contained in:
ruru4143 2024-07-17 16:17:54 +02:00 committed by Benjamin Linus Witzerstorfer
parent 8ef7cefeeb
commit d0e63fc859
6 changed files with 161 additions and 1 deletions

View file

@ -0,0 +1,110 @@
<?php
/**
* Class responsible for Event Plugin related admin notices.
*
* Notices for guiding to proper configuration of ActivityPub with event plugins.
*
* @package Activitypub_Event_Extensions
* @since 1.0.0
*/
namespace Activitypub_Event_Extensions\Admin;
use Activitypub_Event_Extensions\Setup;
/**
* Class responsible for Event Plugin related admin notices.
*
* Notices for guiding to proper configuration of ActivityPub with event plugins.
*
* @since 1.0.0
*/
class Settings_Page {
/*
* TODO:
* - [ ] create settings page
* - [ ] skeleton
* - [ ] Autoloader
* - [ ] Common settings?
* - [ ] Hook points
* - [ ] let transformers hook settings into the page
* - [ ] provide setting-type-classes for hooks
* - [ ] True/False
* - [ ] Number
* - [ ] advanced for mapping
*/
const static = 'Activitypub_Event_Extensions\Admin\Settings_Page';
/**
* Warning if the plugin is Active and the ActivityPub plugin is not.
*/
public static function admin_menu() {
\add_options_page(
'Activitypub Event Extension',
'Activitypub Events',
'manage_options',
'activitypub-events',
array( self::static, 'settings_page' )
);
}
public static function settings_page() {
if ( empty( $_GET['tab'] ) ) {
$tab = 'general';
} else {
$tab = sanitize_key( $_GET['tab'] );
}
/*
submenu_options = {
tab => {name => ''
active => true|false}
}
*/
// todo generate this somehow
// maybe with filters, similar as with the settings
$submenu_options = array(
'general' => array(
'name' => 'General',
'active' => false
),
'events_manager' => array(
'name' => 'Events Manager',
'active' => false,
),
'gatherpress' => array(
'name' => 'Gatherpress',
'active' => false,
),
'the_events_calendar' => array(
'name' => 'The Events Calendar',
'active' => false,
),
'vsel' => array(
'name' => 'VS Event',
'active' => false,
),
);
$submenu_options[$tab]['active'] = true;
switch ( $tab ) {
case 'general':
\load_template( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . 'templates/settings-general.php' , true, $submenu_options );
break;
default:
\load_template( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . 'templates/settings-extractor.php', true, $submenu_options );
break;
}
}
}

View file

@ -13,7 +13,7 @@ namespace Activitypub_Event_Extensions;
use Activitypub_Event_Extensions\Admin\Event_Plugin_Admin_Notices; use Activitypub_Event_Extensions\Admin\Event_Plugin_Admin_Notices;
use Activitypub_Event_Extensions\Admin\General_Admin_Notices; use Activitypub_Event_Extensions\Admin\General_Admin_Notices;
use Activitypub_Event_Extensions\Admin\Settings_Page;
// Exit if accessed directly. // Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
@ -141,6 +141,9 @@ class Setup {
return; return;
} }
add_action( 'admin_menu', array( Settings_Page::static, 'admin_menu' ) );
add_filter( 'plugin_action_links_Activitypub_Event_Extensions', array( Settings_Page::static, 'settings_links' ) );
add_filter( 'activitypub_transformer', array( $this, 'register_activitypub_event_transformer' ), 10, 3 ); add_filter( 'activitypub_transformer', array( $this, 'register_activitypub_event_transformer' ), 10, 3 );
} }

View file

@ -0,0 +1,21 @@
<!-- TODO css classes?
currently reusing activitypub classes which is kinda nice, because it has a consistent theme then, but also it cloud break if activitypub changes something
-->
<div class="activitypub-settings-header">
<div class="activitypub-settings-title-section">
<h1><?php \esc_html_e( 'Activitypub Events Plugin', 'activitypub-events' ); ?></h1>
</div>
<nav class="activitypub-settings-tabs-wrapper" aria-label="<?php \esc_attr_e( 'Secondary menu', 'activitypub-events' ); ?>">
<!-- todo loop through settings pages of Extractors -->
<?php foreach ( $args as $slug => $plugin ) { ?>
<a href="<?php echo \esc_url_raw( admin_url( 'options-general.php?page=activitypub-events&tab=' . $slug ) ); ?>" class="activitypub-settings-tab <?php echo \esc_attr( $plugin['active'] ? 'active' : '' ); ?>">
<?php \esc_html_e( $plugin['name'], 'activitypub-events' ); ?> <!-- Todo better name handling -->
</a>
<?php } ?>
</nav>
</div>
<hr class="wp-header-end">

View file

@ -0,0 +1,13 @@
<?php
// Is this check necessary? it's already enforced by admin_menu()
// it's "recommended" by https://developer.wordpress.org/plugins/administration-menus/sub-menus/
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
\load_template(
__DIR__ . '/admin-header.php',
true,
$args
);
?>

View file

@ -0,0 +1,13 @@
<?php
// Is this check necessary? it's already enforced by admin_menu()
// it's "recommended" by https://developer.wordpress.org/plugins/administration-menus/sub-menus/
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
\load_template(
__DIR__ . '/admin-header.php',
true,
$args
);
?>