class-global-theme-compatibility.php
1 year ago
class-hfe-default-compat.php
1 year ago
hfe-footer.php
5 years ago
hfe-header.php
4 years ago
class-global-theme-compatibility.php
105 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Support all themes. |
| 4 | * |
| 5 | * @package header-footer-elementor |
| 6 | */ |
| 7 | |
| 8 | namespace HFE\Themes; |
| 9 | |
| 10 | /** |
| 11 | * Global theme compatibility. |
| 12 | */ |
| 13 | class Global_Theme_Compatibility { |
| 14 | |
| 15 | /** |
| 16 | * Initiator |
| 17 | */ |
| 18 | public function __construct() { |
| 19 | add_action( 'wp', [ $this, 'hooks' ] ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Run all the Actions / Filters. |
| 24 | * |
| 25 | * @return void |
| 26 | */ |
| 27 | // phpcs:ignore |
| 28 | public function hooks(): void { |
| 29 | if ( hfe_header_enabled() ) { |
| 30 | // Replace header.php. |
| 31 | add_action( 'get_header', [ $this, 'option_override_header' ] ); |
| 32 | |
| 33 | add_action( 'wp_body_open', [ 'Header_Footer_Elementor', 'get_header_content' ] ); |
| 34 | add_action( 'hfe_fallback_header', [ 'Header_Footer_Elementor', 'get_header_content' ] ); |
| 35 | } |
| 36 | |
| 37 | if ( hfe_is_before_footer_enabled() ) { |
| 38 | add_action( 'wp_footer', [ 'Header_Footer_Elementor', 'get_before_footer_content' ], 20 ); |
| 39 | } |
| 40 | |
| 41 | if ( hfe_footer_enabled() ) { |
| 42 | add_action( 'wp_footer', [ 'Header_Footer_Elementor', 'get_footer_content' ], 50 ); |
| 43 | } |
| 44 | |
| 45 | if ( hfe_header_enabled() || hfe_footer_enabled() ) { |
| 46 | add_action( 'wp_enqueue_scripts', [ $this, 'force_fullwidth' ] ); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Force full width CSS for the header. |
| 52 | * |
| 53 | * @since 1.2.0 |
| 54 | * |
| 55 | * // phpcs:ignore |
| 56 | * @return void |
| 57 | */ |
| 58 | // phpcs:ignore |
| 59 | public function force_fullwidth(): void { |
| 60 | $css = ' |
| 61 | .force-stretched-header { |
| 62 | width: 100vw; |
| 63 | position: relative; |
| 64 | margin-left: -50vw; |
| 65 | left: 50%; |
| 66 | }'; |
| 67 | |
| 68 | if ( true === hfe_header_enabled() ) { |
| 69 | $css .= 'header#masthead { |
| 70 | display: none; |
| 71 | }'; |
| 72 | } |
| 73 | |
| 74 | if ( true === hfe_footer_enabled() ) { |
| 75 | $css .= 'footer#colophon { |
| 76 | display: none; |
| 77 | }'; |
| 78 | } |
| 79 | |
| 80 | wp_add_inline_style( 'hfe-style', $css ); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Function overriding the header in the wp_body_open way. |
| 85 | * |
| 86 | * @since 1.2.0 |
| 87 | * |
| 88 | * // phpcs:ignore |
| 89 | * @return void |
| 90 | */ |
| 91 | // phpcs:ignore |
| 92 | public function option_override_header(): void { |
| 93 | $templates = []; |
| 94 | $templates[] = 'header.php'; |
| 95 | locate_template( $templates, true ); |
| 96 | |
| 97 | if ( ! did_action( 'wp_body_open' ) ) { |
| 98 | echo '<div class="force-stretched-header">'; |
| 99 | do_action( 'hfe_fallback_header' ); |
| 100 | echo '</div>'; |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | new Global_Theme_Compatibility(); |
| 105 |