forked from Tetrakern/fictioneer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.php
134 lines (109 loc) · 3.7 KB
/
header.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* Template Part: Header
*
* Starts the document. The HTML root <html> is used to store default settings and
* configuration classes since it is the only node available at the beginning.
* This is necessary for the light/dark switch and site settings to work without
* causing color flickering or layout shifts.
*
* @package WordPress
* @subpackage Fictioneer
* @since 3.0
* @see wp_head()
* @see wp_body_open()
* @see fictioneer_output_head_meta()
* @see fictioneer_output_head_critical_scripts()
*
* @internal $args Array of arguments passed to the template.
*/
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
global $fictioneer_render_start_time;
$fictioneer_render_start_time = microtime( true );
}
// IDs
global $post;
$page_id = get_queried_object_id();
$post_id = $post ? $post->ID : null;
$story_id = null;
if ( $page_id != $post_id ) {
$post_id = $page_id;
}
if ( is_archive() || is_search() || is_404() || FICTIONEER_MU_REGISTRATION ) {
$post_id = null;
}
// Prevent indexing if required
if ( ( $args['no_index'] ?? 0 ) || FICTIONEER_MU_REGISTRATION ) {
add_filter( 'wp_robots', 'wp_robots_no_robots' );
}
// Setup
$story_id = null;
$post_type = $post_id ? $post->post_type : null;
$header_image_source = 'default';
$header_image_url = get_header_image();
// If this is a content page...
if ( $post_id ) {
// Type?
switch ( $post_type ) {
case 'fcn_story':
$story_id = $post_id;
break;
case 'fcn_chapter':
$story_id = fictioneer_get_chapter_story_id( get_the_ID() );
break;
}
// Custom header image?
if ( get_post_meta( $post_id, 'fictioneer_custom_header_image', true ) ) {
$header_image_url = get_post_meta( $post_id, 'fictioneer_custom_header_image', true );
$header_image_url = wp_get_attachment_image_url( $header_image_url, 'full' );
$header_image_source = 'post';
} elseif ( ! empty( $story_id ) && get_post_meta( $story_id, 'fictioneer_custom_header_image', true ) ) {
$header_image_url = get_post_meta( $story_id, 'fictioneer_custom_header_image', true );
$header_image_url = wp_get_attachment_image_url( $header_image_url, 'full' );
$header_image_source = 'story';
}
}
// Filter header image
if ( ! empty( $post_id ) && $header_image_url ) {
$header_image_url = apply_filters( 'fictioneer_filter_header_image', $header_image_url, $post_id );
}
// Action arguments
$action_args = array(
'post_id' => $post_id,
'post_type' => $post_type,
'story_id' => $story_id,
'header_image_url' => $header_image_url,
'header_image_source' => $header_image_source,
'header_args' => $args ?? []
);
// Body attributes
$body_attributes = array(
'data-post-id' => ( $post_id ?: -1 )
);
if ( $story_id ) {
$body_attributes['data-story-id'] = $story_id;
}
$body_attributes = apply_filters( 'fictioneer_filter_body_attributes', $body_attributes, $action_args );
unset( $body_attributes['class'] ); // Prevent mistakes
$body_attributes = array_map(
function ( $key, $value ) { return $key . '="' . esc_attr( $value ) . '"'; },
array_keys( $body_attributes ),
$body_attributes
);
?>
<!doctype html>
<html <?php language_attributes(); ?> <?php fictioneer_root_attributes(); ?>>
<head><?php wp_head(); ?></head>
<body <?php body_class( 'site-bg scrolled-to-top' ); echo implode( ' ', $body_attributes ); ?>>
<?php
// WP Default action
wp_body_open();
// Includes mobile menu
do_action( 'fictioneer_body', $action_args );
?>
<div id="notifications" class="notifications"></div>
<div id="site" class="site background-texture">
<?php
// Includes header background, navigation bar, and site header (with title, logo, etc.)
do_action( 'fictioneer_site', $action_args );
?>