Skip to content

Commit 01ca034

Browse files
pfefferleobenland
andauthored
Onboarding: Allow skipping the welcome page (#1504)
* Onboarding: Allow skipping the welcome page * if $tab is unknown, fall back to to default * phpcs fixes * Do it welcome screen style * Show screen settings * fix phpcs * Fix PHPCS and save settings * use old text * Add changelog * fix typo * Update includes/wp-admin/class-settings.php Co-authored-by: Konstantin Obenland <obenland@gmx.de> * Update includes/wp-admin/class-settings.php Co-authored-by: Konstantin Obenland <obenland@gmx.de> * Update assets/css/activitypub-admin.css Co-authored-by: Konstantin Obenland <obenland@gmx.de> * Update includes/wp-admin/class-welcome-fields.php Co-authored-by: Konstantin Obenland <obenland@gmx.de> * make screen_options_show_submit a function * store get_user_meta in a var * globalize some missing functions * fix phpcs --------- Co-authored-by: Konstantin Obenland <obenland@gmx.de>
1 parent 3d11153 commit 01ca034

File tree

4 files changed

+128
-17
lines changed

4 files changed

+128
-17
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
The option to show/hide the "Welcome Page".

assets/css/activitypub-admin.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.activitypub-settings {
22
max-width: 800px;
33
margin: 0 auto;
4+
position: relative;
45
}
56

67
.settings_page_activitypub .notice {
@@ -220,3 +221,23 @@ input.blog-user-identifier {
220221
.like .dashboard-comment-wrap .comment-author {
221222
margin-block: 0;
222223
}
224+
225+
.activitypub-settings .welcome-tab-close {
226+
position: absolute;
227+
top: 0px;
228+
right: 0px;
229+
font-size: 13px;
230+
padding: 0 5px 0 20px;
231+
text-decoration: none;
232+
z-index: 1;
233+
}
234+
235+
.activitypub-settings .welcome-tab-close::before {
236+
position: absolute;
237+
top: 0px;
238+
left: 0;
239+
transition: all .1s ease-in-out;
240+
font: normal 16px/20px dashicons;
241+
content: '\f335';
242+
font-size: 20px;
243+
}

includes/wp-admin/class-settings.php

Lines changed: 102 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class Settings {
2222
public static function init() {
2323
\add_action( 'admin_init', array( self::class, 'register_settings' ), 11 );
2424
\add_action( 'admin_menu', array( self::class, 'add_settings_page' ) );
25+
26+
\add_filter( 'screen_settings', array( self::class, 'add_screen_option' ), 10, 2 );
27+
\add_filter( 'screen_options_show_submit', array( self::class, 'screen_options_show_submit' ), 10, 2 );
2528
}
2629

2730
/**
@@ -232,19 +235,30 @@ public static function register_settings() {
232235
* Load settings page.
233236
*/
234237
public static function settings_page() {
238+
$show_welcome_tab = \get_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', true );
239+
$default_tab = $show_welcome_tab ? 'welcome' : 'settings';
235240
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
236-
$tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'welcome';
241+
$tab = isset( $_GET['tab'] ) ? \sanitize_key( $_GET['tab'] ) : $default_tab;
242+
243+
// Redirect welcome tab to settings if skipped.
244+
if ( 'welcome' === $tab && ! $show_welcome_tab ) {
245+
$tab = 'settings';
246+
}
247+
248+
$settings_tabs = array();
237249

238-
$settings_tabs = array(
239-
'welcome' => array(
250+
if ( $show_welcome_tab ) {
251+
$settings_tabs['welcome'] = array(
240252
'label' => __( 'Welcome', 'activitypub' ),
241253
'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/welcome.php',
242-
),
243-
'settings' => array(
244-
'label' => __( 'Settings', 'activitypub' ),
245-
'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/settings.php',
246-
),
254+
);
255+
}
256+
257+
$settings_tabs['settings'] = array(
258+
'label' => __( 'Settings', 'activitypub' ),
259+
'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/settings.php',
247260
);
261+
248262
if ( ! is_user_disabled( Actors::BLOG_USER_ID ) ) {
249263
$settings_tabs['blog-profile'] = array(
250264
'label' => __( 'Blog Profile', 'activitypub' ),
@@ -266,18 +280,28 @@ public static function settings_page() {
266280

267281
switch ( $tab ) {
268282
case 'blog-profile':
269-
wp_enqueue_media();
270-
wp_enqueue_script( 'activitypub-header-image' );
283+
\wp_enqueue_media();
284+
\wp_enqueue_script( 'activitypub-header-image' );
271285
break;
272286
case 'welcome':
273-
wp_enqueue_script( 'plugin-install' );
274-
add_thickbox();
275-
wp_enqueue_script( 'updates' );
287+
\wp_enqueue_script( 'plugin-install' );
288+
\add_thickbox();
289+
\wp_enqueue_script( 'updates' );
276290
break;
277291
}
278292

279-
$labels = wp_list_pluck( $settings_tabs, 'label' );
280-
$args = array_fill_keys( array_keys( $labels ), '' );
293+
if ( ! isset( $settings_tabs[ $tab ] ) ) {
294+
$tab = $default_tab;
295+
}
296+
297+
// Only show tabs if there are more than one.
298+
if ( \count( $settings_tabs ) <= 1 ) {
299+
$labels = array();
300+
} else {
301+
$labels = \wp_list_pluck( $settings_tabs, 'label' );
302+
}
303+
304+
$args = \array_fill_keys( \array_keys( $labels ), '' );
281305
$args[ $tab ] = 'active';
282306
$args['tabs'] = $labels;
283307

@@ -297,8 +321,8 @@ public static function add_settings_help_tab() {
297321
),
298322
);
299323

300-
if ( ! is_user_disabled( get_current_user_id() ) ) {
301-
$webfinger = Actors::get_by_id( get_current_user_id() )->get_webfinger();
324+
if ( ! is_user_disabled( \get_current_user_id() ) ) {
325+
$webfinger = Actors::get_by_id( \get_current_user_id() )->get_webfinger();
302326
} else {
303327
$webfinger = ( new Blog() )->get_webfinger();
304328
}
@@ -417,4 +441,65 @@ public static function add_settings_help_tab() {
417441
'<p>' . \__( '<a href="https://github.com/automattic/wordpress-activitypub/issues">Report an issue</a>', 'activitypub' ) . '</p>'
418442
);
419443
}
444+
445+
/**
446+
* Add screen option.
447+
*
448+
* @param string $screen_settings The screen settings.
449+
* @param object $screen The screen object.
450+
*
451+
* @return string The screen settings.
452+
*/
453+
public static function add_screen_option( $screen_settings, $screen ) {
454+
if ( 'settings_page_activitypub' !== $screen->id ) {
455+
return $screen_settings;
456+
}
457+
458+
if ( isset( $_GET['welcome'] ) ) {
459+
$welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
460+
\update_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', $welcome_checked );
461+
}
462+
463+
if ( isset( $_POST['activitypub_show_welcome_tab'] ) && isset( $_POST['screenoptionnonce'] ) ) {
464+
$nonce = \sanitize_text_field( \wp_unslash( $_POST['screenoptionnonce'] ) );
465+
$welcome = \sanitize_text_field( \wp_unslash( $_POST['activitypub_show_welcome_tab'] ) );
466+
// Verify screen options nonce.
467+
if ( \wp_verify_nonce( $nonce, 'screen-options-nonce' ) ) {
468+
$welcome_checked = empty( $welcome ) ? 0 : 1;
469+
\update_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', $welcome_checked );
470+
}
471+
}
472+
473+
$screen_settings = '<fieldset>
474+
<legend class="screen-layout">' . \esc_html__( 'Settings Pages', 'activitypub' ) . '</legend>
475+
<p>
476+
' . \__( 'Some settings pages can be shown or hidden by using the checkboxes.', 'activitypub' ) . '
477+
</p>
478+
<div class="metabox-prefs-container">
479+
<label for="activitypub_show_welcome_tab">
480+
<input name="activitypub_show_welcome_tab" type="hidden" value="0" />
481+
<input name="activitypub_show_welcome_tab" type="checkbox" id="activitypub_show_welcome_tab" value="1" ' . \checked( 1, \get_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', true ), false ) . ' />
482+
' . \__( 'Welcome Page', 'activitypub' ) . '
483+
</label>
484+
</div>
485+
</fieldset>';
486+
487+
return $screen_settings;
488+
}
489+
490+
/**
491+
* Show the submit button on the screen options page.
492+
*
493+
* @param bool $show_submit Whether to show the submit button.
494+
* @param object $screen The screen object.
495+
*
496+
* @return bool Whether to show the submit button.
497+
*/
498+
public static function screen_options_show_submit( $show_submit, $screen ) {
499+
if ( 'settings_page_activitypub' !== $screen->id ) {
500+
return $show_submit;
501+
}
502+
503+
return true;
504+
}
420505
}

includes/wp-admin/class-welcome-fields.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public static function register_welcome_fields() {
8383
*/
8484
public static function render_welcome_intro_section() {
8585
?>
86+
<a class="welcome-tab-close" href="<?php echo \esc_url( \admin_url( 'options-general.php?page=activitypub&welcome=0' ) ); ?>" aria-label="<?php \esc_attr_e( 'Dismiss the welcome page', 'activitypub' ); ?>"><?php \esc_html_e( 'Dismiss Welcome Page', 'activitypub' ); ?></a>
8687
<p><?php echo wp_kses( \__( 'Enter the fediverse with <strong>ActivityPub</strong>, broadcasting your blog to a wider audience. Attract followers, deliver updates, and receive comments from a diverse user base on <strong>Mastodon</strong>, <strong>Friendica</strong>, <strong>Pleroma</strong>, <strong>Pixelfed</strong>, and all <strong>ActivityPub</strong>-compliant platforms.', 'activitypub' ), array( 'strong' => array() ) ); ?></p>
8788
<?php
8889
}

0 commit comments

Comments
 (0)