From ebbd3926242b6a2f540c8a5465d1efb94decfd34 Mon Sep 17 00:00:00 2001 From: Dusty Reagan Date: Fri, 23 Aug 2024 10:26:58 -0500 Subject: [PATCH] Auto open "Upload Theme" dialog when wpcom-upload=1 param exists (#39045) * Add auto open upload theme dialog * Dont use click event add CSS class to body instead * changelog --- .../changelog/add-auto-open-upload-theme | 4 ++++ .../features/wpcom-themes/wpcom-themes.php | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/add-auto-open-upload-theme 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' );