From 1840d79e7d6539828a2079da617ffc550725a666 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Wed, 26 Mar 2025 16:18:30 +0100 Subject: [PATCH 1/5] Fix: Set proper default, to show Welcome screen by default --- includes/class-activitypub.php | 22 ++++++++++++++++++++++ includes/wp-admin/class-settings.php | 18 +++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index e2c460448..b58584799 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -49,6 +49,7 @@ public static function init() { \add_action( 'updated_postmeta', array( self::class, 'updated_postmeta' ), 10, 4 ); \add_action( 'added_post_meta', array( self::class, 'updated_postmeta' ), 10, 4 ); + \add_action( 'default_user_metadata', array( self::class, 'default_user_metadata' ), 10, 3 ); \add_filter( 'pre_option_activitypub_actor_mode', array( self::class, 'pre_get_option' ) ); \add_action( 'init', array( self::class, 'register_user_meta' ), 11 ); @@ -816,4 +817,25 @@ public static function register_user_meta() { ) ); } + + /** + * Add default value to user meta. + * + * @param mixed $value The value to check. + * @param int $object_id The object ID. + * @param string $meta_key The meta key. + * + * @return mixed The value. + */ + public static function default_user_metadata( $value, $object_id, $meta_key ) { + if ( 'activitypub_show_welcome_tab' !== $meta_key ) { + return $value; + } + + if ( ! $value ) { + return '1'; + } + + return $value; + } } diff --git a/includes/wp-admin/class-settings.php b/includes/wp-admin/class-settings.php index 7b7ae5436..319a0ca14 100644 --- a/includes/wp-admin/class-settings.php +++ b/includes/wp-admin/class-settings.php @@ -23,6 +23,7 @@ public static function init() { \add_action( 'admin_init', array( self::class, 'register_settings' ), 11 ); \add_action( 'admin_menu', array( self::class, 'add_settings_page' ) ); + \add_action( 'admin_init', array( self::class, 'handle_welcome_query_arg' ), 12 ); \add_filter( 'screen_settings', array( self::class, 'add_screen_option' ), 10, 2 ); \add_filter( 'screen_options_show_submit', array( self::class, 'screen_options_show_submit' ), 10, 2 ); } @@ -442,6 +443,18 @@ public static function add_settings_help_tab() { ); } + /** + * Handle 'welcome' query arg. + */ + public static function handle_welcome_query_arg() { + if ( isset( $_GET['welcome'] ) ) { + $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1; + \update_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', $welcome_checked ); + \wp_redirect( \admin_url( 'admin.php?page=activitypub&tab=settings' ) ); + exit; + } + } + /** * Add screen option. * @@ -455,11 +468,6 @@ public static function add_screen_option( $screen_settings, $screen ) { return $screen_settings; } - if ( isset( $_GET['welcome'] ) ) { - $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1; - \update_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', $welcome_checked ); - } - if ( isset( $_POST['activitypub_show_welcome_tab'] ) && isset( $_POST['screenoptionnonce'] ) ) { $nonce = \sanitize_text_field( \wp_unslash( $_POST['screenoptionnonce'] ) ); $welcome = \sanitize_text_field( \wp_unslash( $_POST['activitypub_show_welcome_tab'] ) ); From 24d3c4223cf9cdaa00073c0a3ee02dac6e740d4f Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Wed, 26 Mar 2025 16:26:23 +0100 Subject: [PATCH 2/5] fix phpcs --- includes/wp-admin/class-settings.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/wp-admin/class-settings.php b/includes/wp-admin/class-settings.php index 319a0ca14..9c76550d6 100644 --- a/includes/wp-admin/class-settings.php +++ b/includes/wp-admin/class-settings.php @@ -447,10 +447,12 @@ public static function add_settings_help_tab() { * Handle 'welcome' query arg. */ public static function handle_welcome_query_arg() { + // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['welcome'] ) ) { - $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1; + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $welcome_checked = empty( \sanitize_text_field( \wp_unslash( $_GET['welcome'] ) ) ) ? 0 : 1; \update_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', $welcome_checked ); - \wp_redirect( \admin_url( 'admin.php?page=activitypub&tab=settings' ) ); + \wp_safe_redirect( \admin_url( 'admin.php?page=activitypub&tab=settings' ) ); exit; } } From 541b7a7034ba5ea586d53cf8fcdbf97911ac8ba5 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Wed, 26 Mar 2025 17:58:26 +0100 Subject: [PATCH 3/5] class-settings.php aktualisieren Co-authored-by: Konstantin Obenland --- includes/wp-admin/class-settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wp-admin/class-settings.php b/includes/wp-admin/class-settings.php index 9c76550d6..8f64bd760 100644 --- a/includes/wp-admin/class-settings.php +++ b/includes/wp-admin/class-settings.php @@ -452,7 +452,7 @@ public static function handle_welcome_query_arg() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $welcome_checked = empty( \sanitize_text_field( \wp_unslash( $_GET['welcome'] ) ) ) ? 0 : 1; \update_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', $welcome_checked ); - \wp_safe_redirect( \admin_url( 'admin.php?page=activitypub&tab=settings' ) ); + \wp_safe_redirect( \admin_url( 'options-general.php?page=activitypub&tab=settings' ) ); exit; } } From df4f1dae7a688f233f936a6c2a5c803a33dc3f7c Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Wed, 26 Mar 2025 17:59:37 +0100 Subject: [PATCH 4/5] class-settings.php aktualisieren Co-authored-by: Konstantin Obenland --- includes/wp-admin/class-settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wp-admin/class-settings.php b/includes/wp-admin/class-settings.php index 8f64bd760..19d5885f5 100644 --- a/includes/wp-admin/class-settings.php +++ b/includes/wp-admin/class-settings.php @@ -23,7 +23,7 @@ public static function init() { \add_action( 'admin_init', array( self::class, 'register_settings' ), 11 ); \add_action( 'admin_menu', array( self::class, 'add_settings_page' ) ); - \add_action( 'admin_init', array( self::class, 'handle_welcome_query_arg' ), 12 ); + \add_action( 'load-settings_page_activitypub', array( self::class, 'handle_welcome_query_arg' ) ); \add_filter( 'screen_settings', array( self::class, 'add_screen_option' ), 10, 2 ); \add_filter( 'screen_options_show_submit', array( self::class, 'screen_options_show_submit' ), 10, 2 ); } From 8ab0874b007efd451b092134d0cc0ffde9512ab4 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Wed, 26 Mar 2025 18:13:15 +0100 Subject: [PATCH 5/5] use user-meta --- includes/class-activitypub.php | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index b58584799..052286758 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -49,7 +49,6 @@ public static function init() { \add_action( 'updated_postmeta', array( self::class, 'updated_postmeta' ), 10, 4 ); \add_action( 'added_post_meta', array( self::class, 'updated_postmeta' ), 10, 4 ); - \add_action( 'default_user_metadata', array( self::class, 'default_user_metadata' ), 10, 3 ); \add_filter( 'pre_option_activitypub_actor_mode', array( self::class, 'pre_get_option' ) ); \add_action( 'init', array( self::class, 'register_user_meta' ), 11 ); @@ -816,26 +815,17 @@ public static function register_user_meta() { 'sanitize_callback' => 'absint', ) ); - } - - /** - * Add default value to user meta. - * - * @param mixed $value The value to check. - * @param int $object_id The object ID. - * @param string $meta_key The meta key. - * - * @return mixed The value. - */ - public static function default_user_metadata( $value, $object_id, $meta_key ) { - if ( 'activitypub_show_welcome_tab' !== $meta_key ) { - return $value; - } - - if ( ! $value ) { - return '1'; - } - return $value; + \register_meta( + 'user', + 'activitypub_show_welcome_tab', + array( + 'type' => 'integer', + 'description' => 'Whether to show the welcome tab.', + 'single' => true, + 'default' => 1, + 'sanitize_callback' => 'absint', + ) + ); } }