Skip to content

Commit

Permalink
MU WPCOM: Port hide-homepage-title feature from ETK (#38190)
Browse files Browse the repository at this point in the history
* MU WPCOM: Port hide-homepage-title feature from ETK

* changelog
  • Loading branch information
arthur791004 authored Jul 5, 2024
1 parent 018d353 commit e4f0926
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

MU WPCOM: Port the hide-homepage-title feature from ETK
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body.hide-homepage-title .editor-post-title {
opacity: 0.4;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Allow homepage title to be edited even when hidden Lighter color to signify not visible from front page
*
* @package automattic/jetpack-mu-wpcom
*/

use Automattic\Jetpack\Jetpack_Mu_Wpcom;

define( 'MU_WPCOM_HOMEPAGE_TITLE_HIDDEN', true );

/**
* Can be used to determine if the current screen is the block editor.
*
* @return bool True if the current screen is a block editor screen. False otherwise.
*/
function wpcom_is_block_editor_screen() {
return is_callable( 'get_current_screen' ) && get_current_screen() && get_current_screen()->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' );

0 comments on commit e4f0926

Please sign in to comment.