diff --git a/projects/packages/jetpack-mu-wpcom/changelog/mu-wpcom-hide-homepage-title b/projects/packages/jetpack-mu-wpcom/changelog/mu-wpcom-hide-homepage-title new file mode 100644 index 0000000000000..52a11a8fb73eb --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/mu-wpcom-hide-homepage-title @@ -0,0 +1,4 @@ +Significance: patch +Type: added + +MU WPCOM: Port the hide-homepage-title feature from ETK diff --git a/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php b/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php index 2d7d5addcf6ac..ea0902f82a205 100644 --- a/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php +++ b/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php @@ -94,6 +94,7 @@ public static function load_features() { if ( ! class_exists( 'A8C\FSE\Help_Center' ) ) { require_once __DIR__ . '/features/help-center/class-help-center.php'; } + require_once __DIR__ . '/features/hide-homepage-title/hide-homepage-title.php'; require_once __DIR__ . '/features/import-customizations/import-customizations.php'; require_once __DIR__ . '/features/marketplace-products-updater/class-marketplace-products-updater.php'; require_once __DIR__ . '/features/media/heif-support.php'; diff --git a/projects/packages/jetpack-mu-wpcom/src/features/hide-homepage-title/hide-homepage-title.css b/projects/packages/jetpack-mu-wpcom/src/features/hide-homepage-title/hide-homepage-title.css new file mode 100644 index 0000000000000..cad2f55204561 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/src/features/hide-homepage-title/hide-homepage-title.css @@ -0,0 +1,3 @@ +body.hide-homepage-title .editor-post-title { + opacity: 0.4; +} diff --git a/projects/packages/jetpack-mu-wpcom/src/features/hide-homepage-title/hide-homepage-title.php b/projects/packages/jetpack-mu-wpcom/src/features/hide-homepage-title/hide-homepage-title.php new file mode 100644 index 0000000000000..4b165e7b6756b --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/src/features/hide-homepage-title/hide-homepage-title.php @@ -0,0 +1,70 @@ +is_block_editor(); +} + +/** + * Detects if the current page is the homepage post editor, and if the homepage + * title is hidden. + * + * @return bool True if the homepage title features should be used. (See above.) + */ +function wpcom_is_homepage_title_hidden() { + global $post; + + // Handle the case where we are not rendering a post. + if ( ! isset( $post ) ) { + return false; + } + + $hide_homepage_title = (bool) get_theme_mod( 'hide_front_page_title', false ); + $is_homepage = ( (int) get_option( 'page_on_front' ) === $post->ID ); + return (bool) wpcom_is_block_editor_screen() && $hide_homepage_title && $is_homepage; +} + +/** + * Adds custom classes to the admin body classes. + * + * @param string $classes Classes for the body element. + * @return string + */ +function wpcom_add_hide_homepage_title_class_if_needed( $classes ) { + if ( wpcom_is_homepage_title_hidden() ) { + $classes .= ' hide-homepage-title '; + } + + return $classes; +} +add_filter( 'admin_body_class', 'wpcom_add_hide_homepage_title_class_if_needed' ); + +/** + * Enqueue assets + */ +function wpcom_enqueue_hide_homepage_title_assets() { + if ( ! wpcom_is_homepage_title_hidden() ) { + return; + } + + wp_enqueue_style( + 'wpcom-hide-homepage-title', + plugins_url( 'hide-homepage-title.css', __FILE__ ), + array(), + Jetpack_Mu_Wpcom::PACKAGE_VERSION + ); +} +add_action( 'admin_enqueue_scripts', 'wpcom_enqueue_hide_homepage_title_assets' );