-
Notifications
You must be signed in to change notification settings - Fork 100
/
general-template.php
162 lines (150 loc) · 4.28 KB
/
general-template.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* General template tags that can go anywhere in a template.
*
* Code in this file would be added/amended to wp-includes/general-template.php in core.
*
* @package PWA
* @subpackage Template
* @since 0.2.0
*/
/**
* Load header template.
*
* Includes the header template for a theme or if a name is specified then a
* specialised header will be included.
*
* For the parameter, if the file is called "header-special.php" then specify
* "special".
*
* @since 0.2
* @see get_header() This is a clone of the core function but replaces `locate_template()` with `pwa_locate_template()`.
* @link https://core.trac.wordpress.org/ticket/13239 The reason why this patched function is needed.
*
* @param string $name The name of the specialised header.
*/
function pwa_get_header( $name = null ) {
/**
* Fires before the header template file is loaded.
*
* @since 2.1.0
* @since 2.8.0 $name parameter added.
*
* @param string|null $name Name of the specific header file to use. null for the default header.
*/
do_action( 'get_header', $name );
$templates = array();
$name = (string) $name;
if ( '' !== $name ) {
$templates[] = "header-{$name}.php";
}
$templates[] = 'header.php';
// Begin core patch.
pwa_locate_template( $templates, true );
// End core patch.
}
/**
* Load footer template.
*
* Includes the footer template for a theme or if a name is specified then a
* specialised footer will be included.
*
* For the parameter, if the file is called "footer-special.php" then specify
* "special".
*
* @since 0.2
* @see get_footer() This is a clone of the core function but replaces `locate_template()` with `pwa_locate_template()`.
* @link https://core.trac.wordpress.org/ticket/13239 The reason why this patched function is needed.
*
* @param string $name The name of the specialised footer.
*/
function pwa_get_footer( $name = null ) {
/**
* Fires before the footer template file is loaded.
*
* @since 2.1.0
* @since 2.8.0 $name parameter added.
*
* @param string|null $name Name of the specific footer file to use. null for the default footer.
*/
do_action( 'get_footer', $name );
$templates = array();
$name = (string) $name;
if ( '' !== $name ) {
$templates[] = "footer-{$name}.php";
}
$templates[] = 'footer.php';
// Begin core patch.
pwa_locate_template( $templates, true );
// End core patch.
}
/**
* Filter wp_robots to prevent the error template from being indexed.
*
* @since 0.7
*
* @param array $robots Robots.
* @return array Robots.
*/
function wp_filter_robots_for_error_template( $robots ) {
if ( is_offline() || is_500() ) {
$robots['noindex'] = true;
}
return $robots;
}
/**
* Add no-robots meta tag to error template.
*
* @deprecated Only relevant to WordPress < 5.6.
* @todo Is this right? Should we add_action when we find out that the filter is present?
* @see wp_no_robots()
* @since 0.2
*/
function wp_add_error_template_no_robots() {
if ( is_offline() || is_500() ) {
wp_no_robots();
}
}
/**
* Ensure current user is unset when serving an error page (either offline or server error).
*
* This is important so that what the service worker initially precaches for the user when first accessing the site
* will persist even after they have authenticated.
*
* @since 0.5
*/
function wp_unauthenticate_error_template_requests() {
if ( is_offline() || is_500() ) {
wp_set_current_user( 0 );
}
}
/**
* Filter the document title for the offline/500 error template.
*
* In core merge, this would amend `wp_get_document_title()`.
*
* @see wp_get_document_title()
* @since 2.0
*
* @param array $parts {
* The document title parts.
*
* @type string $title Title of the viewed page.
* @type string $page Optional. Page number if paginated.
* @type string $tagline Optional. Site description when on home page.
* @type string $site Optional. Site title when not on home page.
* }
* @return array $title Filtered title.
*/
function pwa_filter_document_title_parts( $parts ) {
if ( ! empty( $parts['title'] ) ) {
return $parts;
}
if ( is_offline() ) {
$parts['title'] = __( 'Offline', 'pwa' );
} elseif ( is_500() ) {
$parts['title'] = __( 'Internal Server Error', 'pwa' );
}
return $parts;
}
add_filter( 'document_title_parts', 'pwa_filter_document_title_parts' );