-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MU WPCOM: Port hide-homepage-title feature from ETK (#38190)
* MU WPCOM: Port hide-homepage-title feature from ETK * changelog
- Loading branch information
1 parent
018d353
commit e4f0926
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/packages/jetpack-mu-wpcom/changelog/mu-wpcom-hide-homepage-title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
projects/packages/jetpack-mu-wpcom/src/features/hide-homepage-title/hide-homepage-title.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body.hide-homepage-title .editor-post-title { | ||
opacity: 0.4; | ||
} |
70 changes: 70 additions & 0 deletions
70
projects/packages/jetpack-mu-wpcom/src/features/hide-homepage-title/hide-homepage-title.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); |