Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 4 |
CRAP | n/a |
0 / 0 |
|
| wpcom_is_block_editor_screen | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
12 | |||
| wpcom_is_homepage_title_hidden | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| wpcom_add_hide_homepage_title_class_if_needed | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| wpcom_enqueue_hide_homepage_title_assets | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Allow homepage title to be edited even when hidden Lighter color to signify not visible from front page |
| 4 | * |
| 5 | * @package automattic/jetpack-mu-wpcom |
| 6 | */ |
| 7 | |
| 8 | use Automattic\Jetpack\Jetpack_Mu_Wpcom; |
| 9 | |
| 10 | /** |
| 11 | * Can be used to determine if the current screen is the block editor. |
| 12 | * |
| 13 | * @return bool True if the current screen is a block editor screen. False otherwise. |
| 14 | */ |
| 15 | function wpcom_is_block_editor_screen() { |
| 16 | return is_callable( 'get_current_screen' ) && get_current_screen() && get_current_screen()->is_block_editor(); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Detects if the current page is the homepage post editor, and if the homepage |
| 21 | * title is hidden. |
| 22 | * |
| 23 | * @return bool True if the homepage title features should be used. (See above.) |
| 24 | */ |
| 25 | function wpcom_is_homepage_title_hidden() { |
| 26 | global $post; |
| 27 | |
| 28 | // Handle the case where we are not rendering a post. |
| 29 | if ( ! isset( $post ) ) { |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | $hide_homepage_title = (bool) get_theme_mod( 'hide_front_page_title', false ); |
| 34 | $is_homepage = ( (int) get_option( 'page_on_front' ) === $post->ID ); |
| 35 | return (bool) wpcom_is_block_editor_screen() && $hide_homepage_title && $is_homepage; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Adds custom classes to the admin body classes. |
| 40 | * |
| 41 | * @param string $classes Classes for the body element. |
| 42 | * @return string |
| 43 | */ |
| 44 | function wpcom_add_hide_homepage_title_class_if_needed( $classes ) { |
| 45 | if ( wpcom_is_homepage_title_hidden() ) { |
| 46 | $classes .= ' hide-homepage-title '; |
| 47 | } |
| 48 | |
| 49 | return $classes; |
| 50 | } |
| 51 | add_filter( 'admin_body_class', 'wpcom_add_hide_homepage_title_class_if_needed' ); |
| 52 | |
| 53 | /** |
| 54 | * Enqueue assets |
| 55 | */ |
| 56 | function wpcom_enqueue_hide_homepage_title_assets() { |
| 57 | if ( ! wpcom_is_homepage_title_hidden() ) { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | wp_enqueue_style( |
| 62 | 'wpcom-hide-homepage-title', |
| 63 | plugins_url( 'hide-homepage-title.css', __FILE__ ), |
| 64 | array(), |
| 65 | Jetpack_Mu_Wpcom::PACKAGE_VERSION |
| 66 | ); |
| 67 | } |
| 68 | add_action( 'admin_enqueue_scripts', 'wpcom_enqueue_hide_homepage_title_assets' ); |