diff --git a/projects/packages/jetpack-mu-wpcom/changelog/add-auto-open-upload-theme b/projects/packages/jetpack-mu-wpcom/changelog/add-auto-open-upload-theme new file mode 100644 index 0000000000000..a2cc66580f2bc --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/add-auto-open-upload-theme @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Auto open Upload Theme dialog if query parameter is present diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/wpcom-themes.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/wpcom-themes.php index d8d25b497f141..6d6ede007345a 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/wpcom-themes.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/wpcom-themes.php @@ -70,3 +70,22 @@ function wpcom_themes_add_theme_showcase_menu() { ); } add_action( 'admin_menu', 'wpcom_themes_add_theme_showcase_menu' ); + +/** + * Automatically opens the "Upload Theme" dialog on the theme installation page based on a 'wpcom-upload' query parameter. + */ +function wpcom_auto_open_upload_theme() { + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( isset( $_GET['wpcom-upload'] ) && $_GET['wpcom-upload'] === '1' ) { + if ( ! current_user_can( 'install_themes' ) ) { + return; + } + add_filter( + 'admin_body_class', + function ( $classes ) { + return $classes . ' show-upload-view '; + } + ); + } +} +add_action( 'load-theme-install.php', 'wpcom_auto_open_upload_theme' );