use tab instead of different settings pages

This commit is contained in:
Matthias Pfefferle 2022-12-06 10:58:32 +01:00
parent 62c99c87a3
commit 2a8cd2a54f
3 changed files with 24 additions and 26 deletions

View file

@ -1,4 +1,4 @@
.settings_page_activitypub-settings .notice-info {
.settings_page_activitypub .notice {
max-width: 800px;
margin: 0 auto;
}
@ -18,8 +18,7 @@
padding-top: 8px;
}
.settings_page_activitypub #wpcontent,
.settings_page_activitypub-settings #wpcontent {
.settings_page_activitypub #wpcontent {
padding-left: 0;
}

View file

@ -21,25 +21,15 @@ class Admin {
* Add admin menu entry
*/
public static function admin_menu() {
$settings_page = \add_submenu_page(
null,
'ActivityPub Settings',
'ActivityPub',
'manage_options',
'activitypub-settings',
array( '\Activitypub\Admin', 'settings_page' )
);
$welcome_page = \add_options_page(
$settings_page = \add_options_page(
'Welcome',
'ActivityPub',
'manage_options',
'activitypub',
array( '\Activitypub\Admin', 'welcome_page' )
array( '\Activitypub\Admin', 'settings_page' )
);
\add_action( 'load-' . $settings_page, array( '\Activitypub\Admin', 'add_settings_help_tab' ) );
\add_action( 'load-' . $welcome_page, array( '\Activitypub\Admin', 'add_settings_help_tab' ) );
$followers_list_page = \add_users_page( \__( 'Followers', 'activitypub' ), \__( 'Followers (Fediverse)', 'activitypub' ), 'read', 'activitypub-followers-list', array( '\Activitypub\Admin', 'followers_list_page' ) );
@ -50,18 +40,27 @@ class Admin {
* Load settings page
*/
public static function settings_page() {
\load_template( \dirname( __FILE__ ) . '/../templates/settings.php' );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( empty( $_GET['tab'] ) ) {
$tab = 'welcome';
} else {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$tab = sanitize_key( $_GET['tab'] );
}
/**
* Load welcome page
*/
public static function welcome_page() {
switch ( $tab ) {
case 'settings':
\load_template( \dirname( __FILE__ ) . '/../templates/settings.php' );
break;
case 'welcome':
default:
wp_enqueue_script( 'plugin-install' );
add_thickbox();
wp_enqueue_script( 'updates' );
\load_template( \dirname( __FILE__ ) . '/../templates/welcome.php' );
break;
}
}
/**

View file

@ -8,7 +8,7 @@
<?php \esc_html_e( 'Welcome', 'activitypub' ); ?>
</a>
<a href="<?php echo \esc_url_raw( admin_url( 'options-general.php?page=activitypub-settings' ) ); ?>" class="activitypub-settings-tab <?php echo \esc_attr( $args['settings'] ); ?>">
<a href="<?php echo \esc_url_raw( admin_url( 'options-general.php?page=activitypub&tab=settings' ) ); ?>" class="activitypub-settings-tab <?php echo \esc_attr( $args['settings'] ); ?>">
<?php \esc_html_e( 'Settings', 'activitypub' ); ?>
</a>
</nav>