0
|
1 |
<?php
|
|
2 |
/**
|
|
3 |
* General template tags that can go anywhere in a template.
|
|
4 |
*
|
|
5 |
* @package WordPress
|
|
6 |
* @subpackage Template
|
|
7 |
*/
|
|
8 |
|
|
9 |
/**
|
|
10 |
* Load header template.
|
|
11 |
*
|
|
12 |
* Includes the header template for a theme or if a name is specified then a
|
|
13 |
* specialised header will be included.
|
|
14 |
*
|
|
15 |
* For the parameter, if the file is called "header-special.php" then specify
|
|
16 |
* "special".
|
|
17 |
*
|
|
18 |
* @since 1.5.0
|
|
19 |
*
|
|
20 |
* @param string $name The name of the specialised header.
|
|
21 |
*/
|
|
22 |
function get_header( $name = null ) {
|
5
|
23 |
/**
|
|
24 |
* Fires before the header template file is loaded.
|
|
25 |
*
|
|
26 |
* The hook allows a specific header template file to be used in place of the
|
|
27 |
* default header template file. If your file is called header-new.php,
|
|
28 |
* you would specify the filename in the hook as get_header( 'new' ).
|
|
29 |
*
|
|
30 |
* @since 2.1.0
|
|
31 |
* @since 2.8.0 $name parameter added.
|
|
32 |
*
|
|
33 |
* @param string $name Name of the specific header file to use.
|
|
34 |
*/
|
0
|
35 |
do_action( 'get_header', $name );
|
|
36 |
|
|
37 |
$templates = array();
|
|
38 |
$name = (string) $name;
|
|
39 |
if ( '' !== $name )
|
|
40 |
$templates[] = "header-{$name}.php";
|
|
41 |
|
|
42 |
$templates[] = 'header.php';
|
|
43 |
|
|
44 |
// Backward compat code will be removed in a future release
|
|
45 |
if ('' == locate_template($templates, true))
|
|
46 |
load_template( ABSPATH . WPINC . '/theme-compat/header.php');
|
|
47 |
}
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Load footer template.
|
|
51 |
*
|
|
52 |
* Includes the footer template for a theme or if a name is specified then a
|
|
53 |
* specialised footer will be included.
|
|
54 |
*
|
|
55 |
* For the parameter, if the file is called "footer-special.php" then specify
|
|
56 |
* "special".
|
|
57 |
*
|
|
58 |
* @since 1.5.0
|
|
59 |
*
|
|
60 |
* @param string $name The name of the specialised footer.
|
|
61 |
*/
|
|
62 |
function get_footer( $name = null ) {
|
5
|
63 |
/**
|
|
64 |
* Fires before the footer template file is loaded.
|
|
65 |
*
|
|
66 |
* The hook allows a specific footer template file to be used in place of the
|
|
67 |
* default footer template file. If your file is called footer-new.php,
|
|
68 |
* you would specify the filename in the hook as get_footer( 'new' ).
|
|
69 |
*
|
|
70 |
* @since 2.1.0
|
|
71 |
* @since 2.8.0 $name parameter added.
|
|
72 |
*
|
|
73 |
* @param string $name Name of the specific footer file to use.
|
|
74 |
*/
|
0
|
75 |
do_action( 'get_footer', $name );
|
|
76 |
|
|
77 |
$templates = array();
|
|
78 |
$name = (string) $name;
|
|
79 |
if ( '' !== $name )
|
|
80 |
$templates[] = "footer-{$name}.php";
|
|
81 |
|
|
82 |
$templates[] = 'footer.php';
|
|
83 |
|
|
84 |
// Backward compat code will be removed in a future release
|
|
85 |
if ('' == locate_template($templates, true))
|
|
86 |
load_template( ABSPATH . WPINC . '/theme-compat/footer.php');
|
|
87 |
}
|
|
88 |
|
|
89 |
/**
|
|
90 |
* Load sidebar template.
|
|
91 |
*
|
|
92 |
* Includes the sidebar template for a theme or if a name is specified then a
|
|
93 |
* specialised sidebar will be included.
|
|
94 |
*
|
|
95 |
* For the parameter, if the file is called "sidebar-special.php" then specify
|
|
96 |
* "special".
|
|
97 |
*
|
|
98 |
* @since 1.5.0
|
|
99 |
*
|
|
100 |
* @param string $name The name of the specialised sidebar.
|
|
101 |
*/
|
|
102 |
function get_sidebar( $name = null ) {
|
5
|
103 |
/**
|
|
104 |
* Fires before the sidebar template file is loaded.
|
|
105 |
*
|
|
106 |
* The hook allows a specific sidebar template file to be used in place of the
|
|
107 |
* default sidebar template file. If your file is called sidebar-new.php,
|
|
108 |
* you would specify the filename in the hook as get_sidebar( 'new' ).
|
|
109 |
*
|
|
110 |
* @since 2.2.0
|
|
111 |
* @since 2.8.0 $name parameter added.
|
|
112 |
*
|
|
113 |
* @param string $name Name of the specific sidebar file to use.
|
|
114 |
*/
|
0
|
115 |
do_action( 'get_sidebar', $name );
|
|
116 |
|
|
117 |
$templates = array();
|
|
118 |
$name = (string) $name;
|
|
119 |
if ( '' !== $name )
|
|
120 |
$templates[] = "sidebar-{$name}.php";
|
|
121 |
|
|
122 |
$templates[] = 'sidebar.php';
|
|
123 |
|
|
124 |
// Backward compat code will be removed in a future release
|
|
125 |
if ('' == locate_template($templates, true))
|
|
126 |
load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php');
|
|
127 |
}
|
|
128 |
|
|
129 |
/**
|
|
130 |
* Load a template part into a template
|
|
131 |
*
|
|
132 |
* Makes it easy for a theme to reuse sections of code in a easy to overload way
|
|
133 |
* for child themes.
|
|
134 |
*
|
|
135 |
* Includes the named template part for a theme or if a name is specified then a
|
|
136 |
* specialised part will be included. If the theme contains no {slug}.php file
|
|
137 |
* then no template will be included.
|
|
138 |
*
|
|
139 |
* The template is included using require, not require_once, so you may include the
|
|
140 |
* same template part multiple times.
|
|
141 |
*
|
|
142 |
* For the $name parameter, if the file is called "{slug}-special.php" then specify
|
|
143 |
* "special".
|
|
144 |
*
|
|
145 |
* @since 3.0.0
|
|
146 |
*
|
|
147 |
* @param string $slug The slug name for the generic template.
|
|
148 |
* @param string $name The name of the specialised template.
|
|
149 |
*/
|
|
150 |
function get_template_part( $slug, $name = null ) {
|
5
|
151 |
/**
|
|
152 |
* Fires before the specified template part file is loaded.
|
|
153 |
*
|
|
154 |
* The dynamic portion of the hook name, `$slug`, refers to the slug name
|
|
155 |
* for the generic template part.
|
|
156 |
*
|
|
157 |
* @since 3.0.0
|
|
158 |
*
|
|
159 |
* @param string $slug The slug name for the generic template.
|
|
160 |
* @param string $name The name of the specialized template.
|
|
161 |
*/
|
0
|
162 |
do_action( "get_template_part_{$slug}", $slug, $name );
|
|
163 |
|
|
164 |
$templates = array();
|
|
165 |
$name = (string) $name;
|
|
166 |
if ( '' !== $name )
|
|
167 |
$templates[] = "{$slug}-{$name}.php";
|
|
168 |
|
|
169 |
$templates[] = "{$slug}.php";
|
|
170 |
|
|
171 |
locate_template($templates, true, false);
|
|
172 |
}
|
|
173 |
|
|
174 |
/**
|
|
175 |
* Display search form.
|
|
176 |
*
|
|
177 |
* Will first attempt to locate the searchform.php file in either the child or
|
|
178 |
* the parent, then load it. If it doesn't exist, then the default search form
|
|
179 |
* will be displayed. The default search form is HTML, which will be displayed.
|
|
180 |
* There is a filter applied to the search form HTML in order to edit or replace
|
|
181 |
* it. The filter is 'get_search_form'.
|
|
182 |
*
|
|
183 |
* This function is primarily used by themes which want to hardcode the search
|
|
184 |
* form into the sidebar and also by the search widget in WordPress.
|
|
185 |
*
|
|
186 |
* There is also an action that is called whenever the function is run called,
|
|
187 |
* 'pre_get_search_form'. This can be useful for outputting JavaScript that the
|
|
188 |
* search relies on or various formatting that applies to the beginning of the
|
|
189 |
* search. To give a few examples of what it can be used for.
|
|
190 |
*
|
|
191 |
* @since 2.7.0
|
|
192 |
*
|
|
193 |
* @param boolean $echo Default to echo and not return the form.
|
|
194 |
* @return string|null String when retrieving, null when displaying or if searchform.php exists.
|
|
195 |
*/
|
|
196 |
function get_search_form( $echo = true ) {
|
5
|
197 |
/**
|
|
198 |
* Fires before the search form is retrieved, at the start of get_search_form().
|
|
199 |
*
|
|
200 |
* @since 2.7.0 as 'get_search_form' action.
|
|
201 |
* @since 3.6.0
|
|
202 |
*
|
|
203 |
* @link https://core.trac.wordpress.org/ticket/19321
|
|
204 |
*/
|
0
|
205 |
do_action( 'pre_get_search_form' );
|
|
206 |
|
|
207 |
$format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
|
5
|
208 |
|
|
209 |
/**
|
|
210 |
* Filter the HTML format of the search form.
|
|
211 |
*
|
|
212 |
* @since 3.6.0
|
|
213 |
*
|
|
214 |
* @param string $format The type of markup to use in the search form.
|
|
215 |
* Accepts 'html5', 'xhtml'.
|
|
216 |
*/
|
0
|
217 |
$format = apply_filters( 'search_form_format', $format );
|
|
218 |
|
|
219 |
$search_form_template = locate_template( 'searchform.php' );
|
|
220 |
if ( '' != $search_form_template ) {
|
|
221 |
ob_start();
|
|
222 |
require( $search_form_template );
|
|
223 |
$form = ob_get_clean();
|
|
224 |
} else {
|
|
225 |
if ( 'html5' == $format ) {
|
|
226 |
$form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
|
|
227 |
<label>
|
|
228 |
<span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
|
|
229 |
<input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search …', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" title="' . esc_attr_x( 'Search for:', 'label' ) . '" />
|
|
230 |
</label>
|
|
231 |
<input type="submit" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
|
|
232 |
</form>';
|
|
233 |
} else {
|
|
234 |
$form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
|
|
235 |
<div>
|
|
236 |
<label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
|
|
237 |
<input type="text" value="' . get_search_query() . '" name="s" id="s" />
|
|
238 |
<input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
|
|
239 |
</div>
|
|
240 |
</form>';
|
|
241 |
}
|
|
242 |
}
|
|
243 |
|
5
|
244 |
/**
|
|
245 |
* Filter the HTML output of the search form.
|
|
246 |
*
|
|
247 |
* @since 2.7.0
|
|
248 |
*
|
|
249 |
* @param string $form The search form HTML output.
|
|
250 |
*/
|
0
|
251 |
$result = apply_filters( 'get_search_form', $form );
|
5
|
252 |
|
0
|
253 |
if ( null === $result )
|
|
254 |
$result = $form;
|
|
255 |
|
|
256 |
if ( $echo )
|
|
257 |
echo $result;
|
|
258 |
else
|
|
259 |
return $result;
|
|
260 |
}
|
|
261 |
|
|
262 |
/**
|
|
263 |
* Display the Log In/Out link.
|
|
264 |
*
|
|
265 |
* Displays a link, which allows users to navigate to the Log In page to log in
|
|
266 |
* or log out depending on whether they are currently logged in.
|
|
267 |
*
|
|
268 |
* @since 1.5.0
|
|
269 |
*
|
|
270 |
* @param string $redirect Optional path to redirect to on login/logout.
|
|
271 |
* @param boolean $echo Default to echo and not return the link.
|
|
272 |
* @return string|null String when retrieving, null when displaying.
|
|
273 |
*/
|
|
274 |
function wp_loginout($redirect = '', $echo = true) {
|
|
275 |
if ( ! is_user_logged_in() )
|
|
276 |
$link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
|
|
277 |
else
|
|
278 |
$link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
|
|
279 |
|
5
|
280 |
if ( $echo ) {
|
|
281 |
/**
|
|
282 |
* Filter the HTML output for the Log In/Log Out link.
|
|
283 |
*
|
|
284 |
* @since 1.5.0
|
|
285 |
*
|
|
286 |
* @param string $link The HTML link content.
|
|
287 |
*/
|
|
288 |
echo apply_filters( 'loginout', $link );
|
|
289 |
} else {
|
|
290 |
/** This filter is documented in wp-includes/general-template.php */
|
|
291 |
return apply_filters( 'loginout', $link );
|
|
292 |
}
|
0
|
293 |
}
|
|
294 |
|
|
295 |
/**
|
|
296 |
* Returns the Log Out URL.
|
|
297 |
*
|
|
298 |
* Returns the URL that allows the user to log out of the site.
|
|
299 |
*
|
|
300 |
* @since 2.7.0
|
|
301 |
*
|
|
302 |
* @param string $redirect Path to redirect to on logout.
|
|
303 |
* @return string A log out URL.
|
|
304 |
*/
|
|
305 |
function wp_logout_url($redirect = '') {
|
|
306 |
$args = array( 'action' => 'logout' );
|
|
307 |
if ( !empty($redirect) ) {
|
|
308 |
$args['redirect_to'] = urlencode( $redirect );
|
|
309 |
}
|
|
310 |
|
|
311 |
$logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
|
|
312 |
$logout_url = wp_nonce_url( $logout_url, 'log-out' );
|
|
313 |
|
5
|
314 |
/**
|
|
315 |
* Filter the logout URL.
|
|
316 |
*
|
|
317 |
* @since 2.8.0
|
|
318 |
*
|
|
319 |
* @param string $logout_url The Log Out URL.
|
|
320 |
* @param string $redirect Path to redirect to on logout.
|
|
321 |
*/
|
|
322 |
return apply_filters( 'logout_url', $logout_url, $redirect );
|
0
|
323 |
}
|
|
324 |
|
|
325 |
/**
|
|
326 |
* Returns the Log In URL.
|
|
327 |
*
|
|
328 |
* Returns the URL that allows the user to log in to the site.
|
|
329 |
*
|
|
330 |
* @since 2.7.0
|
|
331 |
*
|
|
332 |
* @param string $redirect Path to redirect to on login.
|
|
333 |
* @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false.
|
|
334 |
* @return string A log in URL.
|
|
335 |
*/
|
|
336 |
function wp_login_url($redirect = '', $force_reauth = false) {
|
|
337 |
$login_url = site_url('wp-login.php', 'login');
|
|
338 |
|
|
339 |
if ( !empty($redirect) )
|
|
340 |
$login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
|
|
341 |
|
|
342 |
if ( $force_reauth )
|
|
343 |
$login_url = add_query_arg('reauth', '1', $login_url);
|
|
344 |
|
5
|
345 |
/**
|
|
346 |
* Filter the login URL.
|
|
347 |
*
|
|
348 |
* @since 2.8.0
|
|
349 |
* @since 4.2.0 The `$force_reauth` parameter was added.
|
|
350 |
*
|
|
351 |
* @param string $login_url The login URL.
|
|
352 |
* @param string $redirect The path to redirect to on login, if supplied.
|
|
353 |
* @param bool $force_reauth Whether to force reauthorization, even if a cookie is present.
|
|
354 |
*/
|
|
355 |
return apply_filters( 'login_url', $login_url, $redirect, $force_reauth );
|
0
|
356 |
}
|
|
357 |
|
|
358 |
/**
|
|
359 |
* Returns the user registration URL.
|
|
360 |
*
|
|
361 |
* Returns the URL that allows the user to register on the site.
|
|
362 |
*
|
|
363 |
* @since 3.6.0
|
|
364 |
*
|
5
|
365 |
* @return string User registration URL.
|
0
|
366 |
*/
|
|
367 |
function wp_registration_url() {
|
5
|
368 |
/**
|
|
369 |
* Filter the user registration URL.
|
|
370 |
*
|
|
371 |
* @since 3.6.0
|
|
372 |
*
|
|
373 |
* @param string $register The user registration URL.
|
|
374 |
*/
|
0
|
375 |
return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
|
|
376 |
}
|
|
377 |
|
|
378 |
/**
|
|
379 |
* Provides a simple login form for use anywhere within WordPress. By default, it echoes
|
|
380 |
* the HTML immediately. Pass array('echo'=>false) to return the string instead.
|
|
381 |
*
|
|
382 |
* @since 3.0.0
|
5
|
383 |
*
|
0
|
384 |
* @param array $args Configuration options to modify the form output.
|
|
385 |
* @return string|null String when retrieving, null when displaying.
|
|
386 |
*/
|
|
387 |
function wp_login_form( $args = array() ) {
|
|
388 |
$defaults = array(
|
|
389 |
'echo' => true,
|
|
390 |
'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // Default redirect is back to the current page
|
|
391 |
'form_id' => 'loginform',
|
|
392 |
'label_username' => __( 'Username' ),
|
|
393 |
'label_password' => __( 'Password' ),
|
|
394 |
'label_remember' => __( 'Remember Me' ),
|
|
395 |
'label_log_in' => __( 'Log In' ),
|
|
396 |
'id_username' => 'user_login',
|
|
397 |
'id_password' => 'user_pass',
|
|
398 |
'id_remember' => 'rememberme',
|
|
399 |
'id_submit' => 'wp-submit',
|
|
400 |
'remember' => true,
|
|
401 |
'value_username' => '',
|
|
402 |
'value_remember' => false, // Set this to true to default the "Remember me" checkbox to checked
|
|
403 |
);
|
5
|
404 |
|
|
405 |
/**
|
|
406 |
* Filter the default login form output arguments.
|
|
407 |
*
|
|
408 |
* @since 3.0.0
|
|
409 |
*
|
|
410 |
* @see wp_login_form()
|
|
411 |
*
|
|
412 |
* @param array $defaults An array of default login form arguments.
|
|
413 |
*/
|
0
|
414 |
$args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
|
|
415 |
|
5
|
416 |
/**
|
|
417 |
* Filter content to display at the top of the login form.
|
|
418 |
*
|
|
419 |
* The filter evaluates just following the opening form tag element.
|
|
420 |
*
|
|
421 |
* @since 3.0.0
|
|
422 |
*
|
|
423 |
* @param string $content Content to display. Default empty.
|
|
424 |
* @param array $args Array of login form arguments.
|
|
425 |
*/
|
|
426 |
$login_form_top = apply_filters( 'login_form_top', '', $args );
|
|
427 |
|
|
428 |
/**
|
|
429 |
* Filter content to display in the middle of the login form.
|
|
430 |
*
|
|
431 |
* The filter evaluates just following the location where the 'login-password'
|
|
432 |
* field is displayed.
|
|
433 |
*
|
|
434 |
* @since 3.0.0
|
|
435 |
*
|
|
436 |
* @param string $content Content to display. Default empty.
|
|
437 |
* @param array $args Array of login form arguments.
|
|
438 |
*/
|
|
439 |
$login_form_middle = apply_filters( 'login_form_middle', '', $args );
|
|
440 |
|
|
441 |
/**
|
|
442 |
* Filter content to display at the bottom of the login form.
|
|
443 |
*
|
|
444 |
* The filter evaluates just preceding the closing form tag element.
|
|
445 |
*
|
|
446 |
* @since 3.0.0
|
|
447 |
*
|
|
448 |
* @param string $content Content to display. Default empty.
|
|
449 |
* @param array $args Array of login form arguments.
|
|
450 |
*/
|
|
451 |
$login_form_bottom = apply_filters( 'login_form_bottom', '', $args );
|
|
452 |
|
0
|
453 |
$form = '
|
|
454 |
<form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post">
|
5
|
455 |
' . $login_form_top . '
|
0
|
456 |
<p class="login-username">
|
|
457 |
<label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
|
|
458 |
<input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" />
|
|
459 |
</p>
|
|
460 |
<p class="login-password">
|
|
461 |
<label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label>
|
|
462 |
<input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" />
|
|
463 |
</p>
|
5
|
464 |
' . $login_form_middle . '
|
0
|
465 |
' . ( $args['remember'] ? '<p class="login-remember"><label><input name="rememberme" type="checkbox" id="' . esc_attr( $args['id_remember'] ) . '" value="forever"' . ( $args['value_remember'] ? ' checked="checked"' : '' ) . ' /> ' . esc_html( $args['label_remember'] ) . '</label></p>' : '' ) . '
|
|
466 |
<p class="login-submit">
|
|
467 |
<input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" />
|
|
468 |
<input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" />
|
|
469 |
</p>
|
5
|
470 |
' . $login_form_bottom . '
|
0
|
471 |
</form>';
|
|
472 |
|
|
473 |
if ( $args['echo'] )
|
|
474 |
echo $form;
|
|
475 |
else
|
|
476 |
return $form;
|
|
477 |
}
|
|
478 |
|
|
479 |
/**
|
|
480 |
* Returns the Lost Password URL.
|
|
481 |
*
|
|
482 |
* Returns the URL that allows the user to retrieve the lost password
|
|
483 |
*
|
|
484 |
* @since 2.8.0
|
|
485 |
*
|
|
486 |
* @param string $redirect Path to redirect to on login.
|
|
487 |
* @return string Lost password URL.
|
|
488 |
*/
|
|
489 |
function wp_lostpassword_url( $redirect = '' ) {
|
|
490 |
$args = array( 'action' => 'lostpassword' );
|
|
491 |
if ( !empty($redirect) ) {
|
|
492 |
$args['redirect_to'] = $redirect;
|
|
493 |
}
|
|
494 |
|
|
495 |
$lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') );
|
5
|
496 |
|
|
497 |
/**
|
|
498 |
* Filter the Lost Password URL.
|
|
499 |
*
|
|
500 |
* @since 2.8.0
|
|
501 |
*
|
|
502 |
* @param string $lostpassword_url The lost password page URL.
|
|
503 |
* @param string $redirect The path to redirect to on login.
|
|
504 |
*/
|
0
|
505 |
return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
|
|
506 |
}
|
|
507 |
|
|
508 |
/**
|
|
509 |
* Display the Registration or Admin link.
|
|
510 |
*
|
|
511 |
* Display a link which allows the user to navigate to the registration page if
|
|
512 |
* not logged in and registration is enabled or to the dashboard if logged in.
|
|
513 |
*
|
|
514 |
* @since 1.5.0
|
|
515 |
*
|
5
|
516 |
* @param string $before Text to output before the link. Default `<li>`.
|
|
517 |
* @param string $after Text to output after the link. Default `</li>`.
|
0
|
518 |
* @param boolean $echo Default to echo and not return the link.
|
|
519 |
* @return string|null String when retrieving, null when displaying.
|
|
520 |
*/
|
|
521 |
function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
|
|
522 |
|
|
523 |
if ( ! is_user_logged_in() ) {
|
|
524 |
if ( get_option('users_can_register') )
|
|
525 |
$link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register') . '</a>' . $after;
|
|
526 |
else
|
|
527 |
$link = '';
|
|
528 |
} else {
|
|
529 |
$link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
|
|
530 |
}
|
|
531 |
|
5
|
532 |
/**
|
|
533 |
* Filter the HTML link to the Registration or Admin page.
|
|
534 |
*
|
|
535 |
* Users are sent to the admin page if logged-in, or the registration page
|
|
536 |
* if enabled and logged-out.
|
|
537 |
*
|
|
538 |
* @since 1.5.0
|
|
539 |
*
|
|
540 |
* @param string $link The HTML code for the link to the Registration or Admin page.
|
|
541 |
*/
|
|
542 |
$link = apply_filters( 'register', $link );
|
|
543 |
|
|
544 |
if ( $echo ) {
|
|
545 |
echo $link;
|
|
546 |
} else {
|
|
547 |
return $link;
|
|
548 |
}
|
0
|
549 |
}
|
|
550 |
|
|
551 |
/**
|
|
552 |
* Theme container function for the 'wp_meta' action.
|
|
553 |
*
|
|
554 |
* The 'wp_meta' action can have several purposes, depending on how you use it,
|
|
555 |
* but one purpose might have been to allow for theme switching.
|
|
556 |
*
|
|
557 |
* @since 1.5.0
|
5
|
558 |
*
|
|
559 |
* @link https://core.trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
|
0
|
560 |
*/
|
|
561 |
function wp_meta() {
|
5
|
562 |
/**
|
|
563 |
* Fires before displaying echoed content in the sidebar.
|
|
564 |
*
|
|
565 |
* @since 1.5.0
|
|
566 |
*/
|
|
567 |
do_action( 'wp_meta' );
|
0
|
568 |
}
|
|
569 |
|
|
570 |
/**
|
|
571 |
* Display information about the blog.
|
|
572 |
*
|
|
573 |
* @see get_bloginfo() For possible values for the parameter.
|
|
574 |
* @since 0.71
|
|
575 |
*
|
|
576 |
* @param string $show What to display.
|
|
577 |
*/
|
|
578 |
function bloginfo( $show='' ) {
|
|
579 |
echo get_bloginfo( $show, 'display' );
|
|
580 |
}
|
|
581 |
|
|
582 |
/**
|
|
583 |
* Retrieve information about the blog.
|
|
584 |
*
|
|
585 |
* Some show parameter values are deprecated and will be removed in future
|
5
|
586 |
* versions. These options will trigger the {@see _deprecated_argument()}
|
|
587 |
* function. The deprecated blog info options are listed in the function
|
|
588 |
* contents.
|
0
|
589 |
*
|
|
590 |
* The possible values for the 'show' parameter are listed below.
|
5
|
591 |
*
|
|
592 |
* 1. url - Blog URI to homepage.
|
|
593 |
* 2. wpurl - Blog URI path to WordPress.
|
|
594 |
* 3. description - Secondary title
|
0
|
595 |
*
|
|
596 |
* The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
|
|
597 |
* 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
|
|
598 |
* comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
|
|
599 |
* feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
|
|
600 |
*
|
|
601 |
* @since 0.71
|
|
602 |
*
|
|
603 |
* @param string $show Blog info to retrieve.
|
|
604 |
* @param string $filter How to filter what is retrieved.
|
|
605 |
* @return string Mostly string values, might be empty.
|
|
606 |
*/
|
|
607 |
function get_bloginfo( $show = '', $filter = 'raw' ) {
|
|
608 |
|
|
609 |
switch( $show ) {
|
|
610 |
case 'home' : // DEPRECATED
|
|
611 |
case 'siteurl' : // DEPRECATED
|
5
|
612 |
_deprecated_argument( __FUNCTION__, '2.2', sprintf(
|
|
613 |
/* translators: 1: 'siteurl'/'home' argument, 2: bloginfo() function name, 3: 'url' argument */
|
|
614 |
__( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s option instead.' ),
|
|
615 |
'<code>' . $show . '</code>',
|
|
616 |
'<code>bloginfo()</code>',
|
|
617 |
'<code>url</code>'
|
|
618 |
) );
|
0
|
619 |
case 'url' :
|
|
620 |
$output = home_url();
|
|
621 |
break;
|
|
622 |
case 'wpurl' :
|
|
623 |
$output = site_url();
|
|
624 |
break;
|
|
625 |
case 'description':
|
|
626 |
$output = get_option('blogdescription');
|
|
627 |
break;
|
|
628 |
case 'rdf_url':
|
|
629 |
$output = get_feed_link('rdf');
|
|
630 |
break;
|
|
631 |
case 'rss_url':
|
|
632 |
$output = get_feed_link('rss');
|
|
633 |
break;
|
|
634 |
case 'rss2_url':
|
|
635 |
$output = get_feed_link('rss2');
|
|
636 |
break;
|
|
637 |
case 'atom_url':
|
|
638 |
$output = get_feed_link('atom');
|
|
639 |
break;
|
|
640 |
case 'comments_atom_url':
|
|
641 |
$output = get_feed_link('comments_atom');
|
|
642 |
break;
|
|
643 |
case 'comments_rss2_url':
|
|
644 |
$output = get_feed_link('comments_rss2');
|
|
645 |
break;
|
|
646 |
case 'pingback_url':
|
|
647 |
$output = site_url( 'xmlrpc.php' );
|
|
648 |
break;
|
|
649 |
case 'stylesheet_url':
|
|
650 |
$output = get_stylesheet_uri();
|
|
651 |
break;
|
|
652 |
case 'stylesheet_directory':
|
|
653 |
$output = get_stylesheet_directory_uri();
|
|
654 |
break;
|
|
655 |
case 'template_directory':
|
|
656 |
case 'template_url':
|
|
657 |
$output = get_template_directory_uri();
|
|
658 |
break;
|
|
659 |
case 'admin_email':
|
|
660 |
$output = get_option('admin_email');
|
|
661 |
break;
|
|
662 |
case 'charset':
|
|
663 |
$output = get_option('blog_charset');
|
|
664 |
if ('' == $output) $output = 'UTF-8';
|
|
665 |
break;
|
|
666 |
case 'html_type' :
|
|
667 |
$output = get_option('html_type');
|
|
668 |
break;
|
|
669 |
case 'version':
|
|
670 |
global $wp_version;
|
|
671 |
$output = $wp_version;
|
|
672 |
break;
|
|
673 |
case 'language':
|
|
674 |
$output = get_locale();
|
|
675 |
$output = str_replace('_', '-', $output);
|
|
676 |
break;
|
|
677 |
case 'text_direction':
|
5
|
678 |
_deprecated_argument( __FUNCTION__, '2.2', sprintf(
|
|
679 |
/* translators: 1: 'text_direction' argument, 2: bloginfo() function name, 3: is_rtl() function name */
|
|
680 |
__( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s function instead.' ),
|
|
681 |
'<code>' . $show . '</code>',
|
|
682 |
'<code>bloginfo()</code>',
|
|
683 |
'<code>is_rtl()</code>'
|
|
684 |
) );
|
0
|
685 |
if ( function_exists( 'is_rtl' ) ) {
|
|
686 |
$output = is_rtl() ? 'rtl' : 'ltr';
|
|
687 |
} else {
|
|
688 |
$output = 'ltr';
|
|
689 |
}
|
|
690 |
break;
|
|
691 |
case 'name':
|
|
692 |
default:
|
|
693 |
$output = get_option('blogname');
|
|
694 |
break;
|
|
695 |
}
|
|
696 |
|
|
697 |
$url = true;
|
|
698 |
if (strpos($show, 'url') === false &&
|
|
699 |
strpos($show, 'directory') === false &&
|
|
700 |
strpos($show, 'home') === false)
|
|
701 |
$url = false;
|
|
702 |
|
|
703 |
if ( 'display' == $filter ) {
|
5
|
704 |
if ( $url ) {
|
|
705 |
/**
|
|
706 |
* Filter the URL returned by get_bloginfo().
|
|
707 |
*
|
|
708 |
* @since 2.0.5
|
|
709 |
*
|
|
710 |
* @param mixed $output The URL returned by bloginfo().
|
|
711 |
* @param mixed $show Type of information requested.
|
|
712 |
*/
|
|
713 |
$output = apply_filters( 'bloginfo_url', $output, $show );
|
|
714 |
} else {
|
|
715 |
/**
|
|
716 |
* Filter the site information returned by get_bloginfo().
|
|
717 |
*
|
|
718 |
* @since 0.71
|
|
719 |
*
|
|
720 |
* @param mixed $output The requested non-URL site information.
|
|
721 |
* @param mixed $show Type of information requested.
|
|
722 |
*/
|
|
723 |
$output = apply_filters( 'bloginfo', $output, $show );
|
|
724 |
}
|
0
|
725 |
}
|
|
726 |
|
|
727 |
return $output;
|
|
728 |
}
|
|
729 |
|
|
730 |
/**
|
5
|
731 |
* Display title tag with contents.
|
|
732 |
*
|
|
733 |
* @ignore
|
|
734 |
* @since 4.1.0
|
|
735 |
* @access private
|
|
736 |
*
|
|
737 |
* @see wp_title()
|
|
738 |
*/
|
|
739 |
function _wp_render_title_tag() {
|
|
740 |
if ( ! current_theme_supports( 'title-tag' ) ) {
|
|
741 |
return;
|
|
742 |
}
|
|
743 |
|
|
744 |
// This can only work internally on wp_head.
|
|
745 |
if ( ! did_action( 'wp_head' ) && ! doing_action( 'wp_head' ) ) {
|
|
746 |
return;
|
|
747 |
}
|
|
748 |
|
|
749 |
echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n";
|
|
750 |
}
|
|
751 |
|
|
752 |
/**
|
0
|
753 |
* Display or retrieve page title for all areas of blog.
|
|
754 |
*
|
|
755 |
* By default, the page title will display the separator before the page title,
|
|
756 |
* so that the blog title will be before the page title. This is not good for
|
|
757 |
* title display, since the blog title shows up on most tabs and not what is
|
|
758 |
* important, which is the page that the user is looking at.
|
|
759 |
*
|
|
760 |
* There are also SEO benefits to having the blog title after or to the 'right'
|
|
761 |
* or the page title. However, it is mostly common sense to have the blog title
|
|
762 |
* to the right with most browsers supporting tabs. You can achieve this by
|
|
763 |
* using the seplocation parameter and setting the value to 'right'. This change
|
|
764 |
* was introduced around 2.5.0, in case backwards compatibility of themes is
|
|
765 |
* important.
|
|
766 |
*
|
|
767 |
* @since 1.0.0
|
|
768 |
*
|
|
769 |
* @param string $sep Optional, default is '»'. How to separate the various items within the page title.
|
|
770 |
* @param bool $display Optional, default is true. Whether to display or retrieve title.
|
|
771 |
* @param string $seplocation Optional. Direction to display title, 'right'.
|
|
772 |
* @return string|null String on retrieve, null when displaying.
|
|
773 |
*/
|
|
774 |
function wp_title($sep = '»', $display = true, $seplocation = '') {
|
5
|
775 |
global $wp_locale, $page, $paged;
|
0
|
776 |
|
|
777 |
$m = get_query_var('m');
|
|
778 |
$year = get_query_var('year');
|
|
779 |
$monthnum = get_query_var('monthnum');
|
|
780 |
$day = get_query_var('day');
|
|
781 |
$search = get_query_var('s');
|
|
782 |
$title = '';
|
|
783 |
|
|
784 |
$t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
|
|
785 |
|
|
786 |
// If there is a post
|
|
787 |
if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
|
|
788 |
$title = single_post_title( '', false );
|
|
789 |
}
|
|
790 |
|
|
791 |
// If there's a post type archive
|
|
792 |
if ( is_post_type_archive() ) {
|
|
793 |
$post_type = get_query_var( 'post_type' );
|
|
794 |
if ( is_array( $post_type ) )
|
|
795 |
$post_type = reset( $post_type );
|
|
796 |
$post_type_object = get_post_type_object( $post_type );
|
|
797 |
if ( ! $post_type_object->has_archive )
|
|
798 |
$title = post_type_archive_title( '', false );
|
|
799 |
}
|
|
800 |
|
|
801 |
// If there's a category or tag
|
|
802 |
if ( is_category() || is_tag() ) {
|
|
803 |
$title = single_term_title( '', false );
|
|
804 |
}
|
|
805 |
|
|
806 |
// If there's a taxonomy
|
|
807 |
if ( is_tax() ) {
|
|
808 |
$term = get_queried_object();
|
|
809 |
if ( $term ) {
|
|
810 |
$tax = get_taxonomy( $term->taxonomy );
|
|
811 |
$title = single_term_title( $tax->labels->name . $t_sep, false );
|
|
812 |
}
|
|
813 |
}
|
|
814 |
|
|
815 |
// If there's an author
|
5
|
816 |
if ( is_author() && ! is_post_type_archive() ) {
|
0
|
817 |
$author = get_queried_object();
|
|
818 |
if ( $author )
|
|
819 |
$title = $author->display_name;
|
|
820 |
}
|
|
821 |
|
|
822 |
// Post type archives with has_archive should override terms.
|
|
823 |
if ( is_post_type_archive() && $post_type_object->has_archive )
|
|
824 |
$title = post_type_archive_title( '', false );
|
|
825 |
|
|
826 |
// If there's a month
|
|
827 |
if ( is_archive() && !empty($m) ) {
|
|
828 |
$my_year = substr($m, 0, 4);
|
|
829 |
$my_month = $wp_locale->get_month(substr($m, 4, 2));
|
|
830 |
$my_day = intval(substr($m, 6, 2));
|
|
831 |
$title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
|
|
832 |
}
|
|
833 |
|
|
834 |
// If there's a year
|
|
835 |
if ( is_archive() && !empty($year) ) {
|
|
836 |
$title = $year;
|
|
837 |
if ( !empty($monthnum) )
|
|
838 |
$title .= $t_sep . $wp_locale->get_month($monthnum);
|
|
839 |
if ( !empty($day) )
|
|
840 |
$title .= $t_sep . zeroise($day, 2);
|
|
841 |
}
|
|
842 |
|
|
843 |
// If it's a search
|
|
844 |
if ( is_search() ) {
|
|
845 |
/* translators: 1: separator, 2: search phrase */
|
|
846 |
$title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
|
|
847 |
}
|
|
848 |
|
|
849 |
// If it's a 404 page
|
|
850 |
if ( is_404() ) {
|
|
851 |
$title = __('Page not found');
|
|
852 |
}
|
|
853 |
|
|
854 |
$prefix = '';
|
|
855 |
if ( !empty($title) )
|
|
856 |
$prefix = " $sep ";
|
|
857 |
|
5
|
858 |
/**
|
|
859 |
* Filter the parts of the page title.
|
|
860 |
*
|
|
861 |
* @since 4.0.0
|
|
862 |
*
|
|
863 |
* @param array $title_array Parts of the page title.
|
|
864 |
*/
|
|
865 |
$title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
|
|
866 |
|
0
|
867 |
// Determines position of the separator and direction of the breadcrumb
|
|
868 |
if ( 'right' == $seplocation ) { // sep on right, so reverse the order
|
|
869 |
$title_array = array_reverse( $title_array );
|
|
870 |
$title = implode( " $sep ", $title_array ) . $prefix;
|
|
871 |
} else {
|
|
872 |
$title = $prefix . implode( " $sep ", $title_array );
|
|
873 |
}
|
|
874 |
|
5
|
875 |
if ( current_theme_supports( 'title-tag' ) && ! is_feed() ) {
|
|
876 |
$title .= get_bloginfo( 'name', 'display' );
|
|
877 |
|
|
878 |
$site_description = get_bloginfo( 'description', 'display' );
|
|
879 |
if ( $site_description && ( is_home() || is_front_page() ) ) {
|
|
880 |
$title .= " $sep $site_description";
|
|
881 |
}
|
|
882 |
|
|
883 |
if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
|
|
884 |
$title .= " $sep " . sprintf( __( 'Page %s' ), max( $paged, $page ) );
|
|
885 |
}
|
|
886 |
}
|
|
887 |
|
|
888 |
/**
|
|
889 |
* Filter the text of the page title.
|
|
890 |
*
|
|
891 |
* @since 2.0.0
|
|
892 |
*
|
|
893 |
* @param string $title Page title.
|
|
894 |
* @param string $sep Title separator.
|
|
895 |
* @param string $seplocation Location of the separator (left or right).
|
|
896 |
*/
|
|
897 |
$title = apply_filters( 'wp_title', $title, $sep, $seplocation );
|
0
|
898 |
|
|
899 |
// Send it out
|
|
900 |
if ( $display )
|
|
901 |
echo $title;
|
|
902 |
else
|
|
903 |
return $title;
|
|
904 |
|
|
905 |
}
|
|
906 |
|
|
907 |
/**
|
|
908 |
* Display or retrieve page title for post.
|
|
909 |
*
|
|
910 |
* This is optimized for single.php template file for displaying the post title.
|
|
911 |
*
|
|
912 |
* It does not support placing the separator after the title, but by leaving the
|
|
913 |
* prefix parameter empty, you can set the title separator manually. The prefix
|
|
914 |
* does not automatically place a space between the prefix, so if there should
|
|
915 |
* be a space, the parameter value will need to have it at the end.
|
|
916 |
*
|
|
917 |
* @since 0.71
|
|
918 |
*
|
|
919 |
* @param string $prefix Optional. What to display before the title.
|
|
920 |
* @param bool $display Optional, default is true. Whether to display or retrieve title.
|
|
921 |
* @return string|null Title when retrieving, null when displaying or failure.
|
|
922 |
*/
|
|
923 |
function single_post_title($prefix = '', $display = true) {
|
|
924 |
$_post = get_queried_object();
|
|
925 |
|
|
926 |
if ( !isset($_post->post_title) )
|
|
927 |
return;
|
|
928 |
|
5
|
929 |
/**
|
|
930 |
* Filter the page title for a single post.
|
|
931 |
*
|
|
932 |
* @since 0.71
|
|
933 |
*
|
|
934 |
* @param string $_post_title The single post page title.
|
|
935 |
* @param object $_post The current queried object as returned by get_queried_object().
|
|
936 |
*/
|
|
937 |
$title = apply_filters( 'single_post_title', $_post->post_title, $_post );
|
0
|
938 |
if ( $display )
|
|
939 |
echo $prefix . $title;
|
|
940 |
else
|
|
941 |
return $prefix . $title;
|
|
942 |
}
|
|
943 |
|
|
944 |
/**
|
|
945 |
* Display or retrieve title for a post type archive.
|
|
946 |
*
|
|
947 |
* This is optimized for archive.php and archive-{$post_type}.php template files
|
|
948 |
* for displaying the title of the post type.
|
|
949 |
*
|
|
950 |
* @since 3.1.0
|
|
951 |
*
|
|
952 |
* @param string $prefix Optional. What to display before the title.
|
|
953 |
* @param bool $display Optional, default is true. Whether to display or retrieve title.
|
|
954 |
* @return string|null Title when retrieving, null when displaying or failure.
|
|
955 |
*/
|
|
956 |
function post_type_archive_title( $prefix = '', $display = true ) {
|
|
957 |
if ( ! is_post_type_archive() )
|
|
958 |
return;
|
|
959 |
|
|
960 |
$post_type = get_query_var( 'post_type' );
|
|
961 |
if ( is_array( $post_type ) )
|
|
962 |
$post_type = reset( $post_type );
|
|
963 |
|
|
964 |
$post_type_obj = get_post_type_object( $post_type );
|
5
|
965 |
|
|
966 |
/**
|
|
967 |
* Filter the post type archive title.
|
|
968 |
*
|
|
969 |
* @since 3.1.0
|
|
970 |
*
|
|
971 |
* @param string $post_type_name Post type 'name' label.
|
|
972 |
* @param string $post_type Post type.
|
|
973 |
*/
|
|
974 |
$title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
|
0
|
975 |
|
|
976 |
if ( $display )
|
|
977 |
echo $prefix . $title;
|
|
978 |
else
|
|
979 |
return $prefix . $title;
|
|
980 |
}
|
|
981 |
|
|
982 |
/**
|
|
983 |
* Display or retrieve page title for category archive.
|
|
984 |
*
|
|
985 |
* This is useful for category template file or files, because it is optimized
|
|
986 |
* for category page title and with less overhead than {@link wp_title()}.
|
|
987 |
*
|
|
988 |
* It does not support placing the separator after the title, but by leaving the
|
|
989 |
* prefix parameter empty, you can set the title separator manually. The prefix
|
|
990 |
* does not automatically place a space between the prefix, so if there should
|
|
991 |
* be a space, the parameter value will need to have it at the end.
|
|
992 |
*
|
|
993 |
* @since 0.71
|
|
994 |
*
|
|
995 |
* @param string $prefix Optional. What to display before the title.
|
|
996 |
* @param bool $display Optional, default is true. Whether to display or retrieve title.
|
|
997 |
* @return string|null Title when retrieving, null when displaying or failure.
|
|
998 |
*/
|
|
999 |
function single_cat_title( $prefix = '', $display = true ) {
|
|
1000 |
return single_term_title( $prefix, $display );
|
|
1001 |
}
|
|
1002 |
|
|
1003 |
/**
|
|
1004 |
* Display or retrieve page title for tag post archive.
|
|
1005 |
*
|
|
1006 |
* Useful for tag template files for displaying the tag page title. It has less
|
|
1007 |
* overhead than {@link wp_title()}, because of its limited implementation.
|
|
1008 |
*
|
|
1009 |
* It does not support placing the separator after the title, but by leaving the
|
|
1010 |
* prefix parameter empty, you can set the title separator manually. The prefix
|
|
1011 |
* does not automatically place a space between the prefix, so if there should
|
|
1012 |
* be a space, the parameter value will need to have it at the end.
|
|
1013 |
*
|
|
1014 |
* @since 2.3.0
|
|
1015 |
*
|
|
1016 |
* @param string $prefix Optional. What to display before the title.
|
|
1017 |
* @param bool $display Optional, default is true. Whether to display or retrieve title.
|
|
1018 |
* @return string|null Title when retrieving, null when displaying or failure.
|
|
1019 |
*/
|
|
1020 |
function single_tag_title( $prefix = '', $display = true ) {
|
|
1021 |
return single_term_title( $prefix, $display );
|
|
1022 |
}
|
|
1023 |
|
|
1024 |
/**
|
|
1025 |
* Display or retrieve page title for taxonomy term archive.
|
|
1026 |
*
|
|
1027 |
* Useful for taxonomy term template files for displaying the taxonomy term page title.
|
|
1028 |
* It has less overhead than {@link wp_title()}, because of its limited implementation.
|
|
1029 |
*
|
|
1030 |
* It does not support placing the separator after the title, but by leaving the
|
|
1031 |
* prefix parameter empty, you can set the title separator manually. The prefix
|
|
1032 |
* does not automatically place a space between the prefix, so if there should
|
|
1033 |
* be a space, the parameter value will need to have it at the end.
|
|
1034 |
*
|
|
1035 |
* @since 3.1.0
|
|
1036 |
*
|
|
1037 |
* @param string $prefix Optional. What to display before the title.
|
|
1038 |
* @param bool $display Optional, default is true. Whether to display or retrieve title.
|
|
1039 |
* @return string|null Title when retrieving, null when displaying or failure.
|
|
1040 |
*/
|
|
1041 |
function single_term_title( $prefix = '', $display = true ) {
|
|
1042 |
$term = get_queried_object();
|
|
1043 |
|
|
1044 |
if ( !$term )
|
|
1045 |
return;
|
|
1046 |
|
5
|
1047 |
if ( is_category() ) {
|
|
1048 |
/**
|
|
1049 |
* Filter the category archive page title.
|
|
1050 |
*
|
|
1051 |
* @since 2.0.10
|
|
1052 |
*
|
|
1053 |
* @param string $term_name Category name for archive being displayed.
|
|
1054 |
*/
|
0
|
1055 |
$term_name = apply_filters( 'single_cat_title', $term->name );
|
5
|
1056 |
} elseif ( is_tag() ) {
|
|
1057 |
/**
|
|
1058 |
* Filter the tag archive page title.
|
|
1059 |
*
|
|
1060 |
* @since 2.3.0
|
|
1061 |
*
|
|
1062 |
* @param string $term_name Tag name for archive being displayed.
|
|
1063 |
*/
|
0
|
1064 |
$term_name = apply_filters( 'single_tag_title', $term->name );
|
5
|
1065 |
} elseif ( is_tax() ) {
|
|
1066 |
/**
|
|
1067 |
* Filter the custom taxonomy archive page title.
|
|
1068 |
*
|
|
1069 |
* @since 3.1.0
|
|
1070 |
*
|
|
1071 |
* @param string $term_name Term name for archive being displayed.
|
|
1072 |
*/
|
0
|
1073 |
$term_name = apply_filters( 'single_term_title', $term->name );
|
5
|
1074 |
} else {
|
0
|
1075 |
return;
|
5
|
1076 |
}
|
0
|
1077 |
|
|
1078 |
if ( empty( $term_name ) )
|
|
1079 |
return;
|
|
1080 |
|
|
1081 |
if ( $display )
|
|
1082 |
echo $prefix . $term_name;
|
|
1083 |
else
|
|
1084 |
return $prefix . $term_name;
|
|
1085 |
}
|
|
1086 |
|
|
1087 |
/**
|
|
1088 |
* Display or retrieve page title for post archive based on date.
|
|
1089 |
*
|
|
1090 |
* Useful for when the template only needs to display the month and year, if
|
|
1091 |
* either are available. Optimized for just this purpose, so if it is all that
|
|
1092 |
* is needed, should be better than {@link wp_title()}.
|
|
1093 |
*
|
|
1094 |
* It does not support placing the separator after the title, but by leaving the
|
|
1095 |
* prefix parameter empty, you can set the title separator manually. The prefix
|
|
1096 |
* does not automatically place a space between the prefix, so if there should
|
|
1097 |
* be a space, the parameter value will need to have it at the end.
|
|
1098 |
*
|
|
1099 |
* @since 0.71
|
|
1100 |
*
|
|
1101 |
* @param string $prefix Optional. What to display before the title.
|
|
1102 |
* @param bool $display Optional, default is true. Whether to display or retrieve title.
|
|
1103 |
* @return string|null Title when retrieving, null when displaying or failure.
|
|
1104 |
*/
|
|
1105 |
function single_month_title($prefix = '', $display = true ) {
|
|
1106 |
global $wp_locale;
|
|
1107 |
|
|
1108 |
$m = get_query_var('m');
|
|
1109 |
$year = get_query_var('year');
|
|
1110 |
$monthnum = get_query_var('monthnum');
|
|
1111 |
|
|
1112 |
if ( !empty($monthnum) && !empty($year) ) {
|
|
1113 |
$my_year = $year;
|
|
1114 |
$my_month = $wp_locale->get_month($monthnum);
|
|
1115 |
} elseif ( !empty($m) ) {
|
|
1116 |
$my_year = substr($m, 0, 4);
|
|
1117 |
$my_month = $wp_locale->get_month(substr($m, 4, 2));
|
|
1118 |
}
|
|
1119 |
|
|
1120 |
if ( empty($my_month) )
|
|
1121 |
return false;
|
|
1122 |
|
|
1123 |
$result = $prefix . $my_month . $prefix . $my_year;
|
|
1124 |
|
|
1125 |
if ( !$display )
|
|
1126 |
return $result;
|
|
1127 |
echo $result;
|
|
1128 |
}
|
|
1129 |
|
|
1130 |
/**
|
5
|
1131 |
* Display the archive title based on the queried object.
|
|
1132 |
*
|
|
1133 |
* @since 4.1.0
|
|
1134 |
*
|
|
1135 |
* @see get_the_archive_title()
|
|
1136 |
*
|
|
1137 |
* @param string $before Optional. Content to prepend to the title. Default empty.
|
|
1138 |
* @param string $after Optional. Content to append to the title. Default empty.
|
|
1139 |
*/
|
|
1140 |
function the_archive_title( $before = '', $after = '' ) {
|
|
1141 |
$title = get_the_archive_title();
|
|
1142 |
|
|
1143 |
if ( ! empty( $title ) ) {
|
|
1144 |
echo $before . $title . $after;
|
|
1145 |
}
|
|
1146 |
}
|
|
1147 |
|
|
1148 |
/**
|
|
1149 |
* Retrieve the archive title based on the queried object.
|
|
1150 |
*
|
|
1151 |
* @since 4.1.0
|
|
1152 |
*
|
|
1153 |
* @return string Archive title.
|
|
1154 |
*/
|
|
1155 |
function get_the_archive_title() {
|
|
1156 |
if ( is_category() ) {
|
|
1157 |
$title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) );
|
|
1158 |
} elseif ( is_tag() ) {
|
|
1159 |
$title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) );
|
|
1160 |
} elseif ( is_author() ) {
|
|
1161 |
$title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . get_the_author() . '</span>' );
|
|
1162 |
} elseif ( is_year() ) {
|
|
1163 |
$title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) );
|
|
1164 |
} elseif ( is_month() ) {
|
|
1165 |
$title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) );
|
|
1166 |
} elseif ( is_day() ) {
|
|
1167 |
$title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) );
|
|
1168 |
} elseif ( is_tax( 'post_format' ) ) {
|
|
1169 |
if ( is_tax( 'post_format', 'post-format-aside' ) ) {
|
|
1170 |
$title = _x( 'Asides', 'post format archive title' );
|
|
1171 |
} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
|
|
1172 |
$title = _x( 'Galleries', 'post format archive title' );
|
|
1173 |
} elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
|
|
1174 |
$title = _x( 'Images', 'post format archive title' );
|
|
1175 |
} elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
|
|
1176 |
$title = _x( 'Videos', 'post format archive title' );
|
|
1177 |
} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
|
|
1178 |
$title = _x( 'Quotes', 'post format archive title' );
|
|
1179 |
} elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
|
|
1180 |
$title = _x( 'Links', 'post format archive title' );
|
|
1181 |
} elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
|
|
1182 |
$title = _x( 'Statuses', 'post format archive title' );
|
|
1183 |
} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
|
|
1184 |
$title = _x( 'Audio', 'post format archive title' );
|
|
1185 |
} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
|
|
1186 |
$title = _x( 'Chats', 'post format archive title' );
|
|
1187 |
}
|
|
1188 |
} elseif ( is_post_type_archive() ) {
|
|
1189 |
$title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) );
|
|
1190 |
} elseif ( is_tax() ) {
|
|
1191 |
$tax = get_taxonomy( get_queried_object()->taxonomy );
|
|
1192 |
/* translators: 1: Taxonomy singular name, 2: Current taxonomy term */
|
|
1193 |
$title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) );
|
|
1194 |
} else {
|
|
1195 |
$title = __( 'Archives' );
|
|
1196 |
}
|
|
1197 |
|
|
1198 |
/**
|
|
1199 |
* Filter the archive title.
|
|
1200 |
*
|
|
1201 |
* @since 4.1.0
|
|
1202 |
*
|
|
1203 |
* @param string $title Archive title to be displayed.
|
|
1204 |
*/
|
|
1205 |
return apply_filters( 'get_the_archive_title', $title );
|
|
1206 |
}
|
|
1207 |
|
|
1208 |
/**
|
|
1209 |
* Display category, tag, or term description.
|
|
1210 |
*
|
|
1211 |
* @since 4.1.0
|
|
1212 |
*
|
|
1213 |
* @see get_the_archive_description()
|
|
1214 |
*
|
|
1215 |
* @param string $before Optional. Content to prepend to the description. Default empty.
|
|
1216 |
* @param string $after Optional. Content to append to the description. Default empty.
|
|
1217 |
*/
|
|
1218 |
function the_archive_description( $before = '', $after = '' ) {
|
|
1219 |
$description = get_the_archive_description();
|
|
1220 |
if ( $description ) {
|
|
1221 |
echo $before . $description . $after;
|
|
1222 |
}
|
|
1223 |
}
|
|
1224 |
|
|
1225 |
/**
|
|
1226 |
* Retrieve category, tag, or term description.
|
|
1227 |
*
|
|
1228 |
* @since 4.1.0
|
|
1229 |
*
|
|
1230 |
* @return string Archive description.
|
|
1231 |
*/
|
|
1232 |
function get_the_archive_description() {
|
|
1233 |
/**
|
|
1234 |
* Filter the archive description.
|
|
1235 |
*
|
|
1236 |
* @since 4.1.0
|
|
1237 |
*
|
|
1238 |
* @see term_description()
|
|
1239 |
*
|
|
1240 |
* @param string $description Archive description to be displayed.
|
|
1241 |
*/
|
|
1242 |
return apply_filters( 'get_the_archive_description', term_description() );
|
|
1243 |
}
|
|
1244 |
|
|
1245 |
/**
|
0
|
1246 |
* Retrieve archive link content based on predefined or custom code.
|
|
1247 |
*
|
|
1248 |
* The format can be one of four styles. The 'link' for head element, 'option'
|
|
1249 |
* for use in the select element, 'html' for use in list (either ol or ul HTML
|
|
1250 |
* elements). Custom content is also supported using the before and after
|
|
1251 |
* parameters.
|
|
1252 |
*
|
5
|
1253 |
* The 'link' format uses the `<link>` HTML element with the **archives**
|
0
|
1254 |
* relationship. The before and after parameters are not used. The text
|
|
1255 |
* parameter is used to describe the link.
|
|
1256 |
*
|
|
1257 |
* The 'option' format uses the option HTML element for use in select element.
|
|
1258 |
* The value is the url parameter and the before and after parameters are used
|
|
1259 |
* between the text description.
|
|
1260 |
*
|
|
1261 |
* The 'html' format, which is the default, uses the li HTML element for use in
|
|
1262 |
* the list HTML elements. The before parameter is before the link and the after
|
|
1263 |
* parameter is after the closing link.
|
|
1264 |
*
|
|
1265 |
* The custom format uses the before parameter before the link ('a' HTML
|
|
1266 |
* element) and the after parameter after the closing link tag. If the above
|
|
1267 |
* three values for the format are not used, then custom format is assumed.
|
|
1268 |
*
|
|
1269 |
* @since 1.0.0
|
|
1270 |
*
|
5
|
1271 |
* @todo Properly document optional arguments as such
|
|
1272 |
*
|
0
|
1273 |
* @param string $url URL to archive.
|
|
1274 |
* @param string $text Archive text description.
|
|
1275 |
* @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
|
|
1276 |
* @param string $before Optional.
|
|
1277 |
* @param string $after Optional.
|
|
1278 |
* @return string HTML link content for archive.
|
|
1279 |
*/
|
|
1280 |
function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
|
|
1281 |
$text = wptexturize($text);
|
|
1282 |
$url = esc_url($url);
|
|
1283 |
|
|
1284 |
if ('link' == $format)
|
|
1285 |
$link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
|
|
1286 |
elseif ('option' == $format)
|
|
1287 |
$link_html = "\t<option value='$url'>$before $text $after</option>\n";
|
|
1288 |
elseif ('html' == $format)
|
|
1289 |
$link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
|
|
1290 |
else // custom
|
|
1291 |
$link_html = "\t$before<a href='$url'>$text</a>$after\n";
|
|
1292 |
|
5
|
1293 |
/**
|
|
1294 |
* Filter the archive link content.
|
|
1295 |
*
|
|
1296 |
* @since 2.6.0
|
|
1297 |
*
|
|
1298 |
* @param string $link_html The archive HTML link content.
|
|
1299 |
*/
|
0
|
1300 |
$link_html = apply_filters( 'get_archives_link', $link_html );
|
|
1301 |
|
|
1302 |
return $link_html;
|
|
1303 |
}
|
|
1304 |
|
|
1305 |
/**
|
|
1306 |
* Display archive links based on type and format.
|
|
1307 |
*
|
|
1308 |
* @since 1.2.0
|
|
1309 |
*
|
5
|
1310 |
* @see get_archives_link()
|
|
1311 |
*
|
|
1312 |
* @param string|array $args {
|
|
1313 |
* Default archive links arguments. Optional.
|
|
1314 |
*
|
|
1315 |
* @type string $type Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly',
|
|
1316 |
* 'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha'
|
|
1317 |
* display the same archive link list as well as post titles instead
|
|
1318 |
* of displaying dates. The difference between the two is that 'alpha'
|
|
1319 |
* will order by post title and 'postbypost' will order by post date.
|
|
1320 |
* Default 'monthly'.
|
|
1321 |
* @type string|int $limit Number of links to limit the query to. Default empty (no limit).
|
|
1322 |
* @type string $format Format each link should take using the $before and $after args.
|
|
1323 |
* Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html'
|
|
1324 |
* (`<li>` tag), or a custom format, which generates a link anchor
|
|
1325 |
* with $before preceding and $after succeeding. Default 'html'.
|
|
1326 |
* @type string $before Markup to prepend to the beginning of each link. Default empty.
|
|
1327 |
* @type string $after Markup to append to the end of each link. Default empty.
|
|
1328 |
* @type bool $show_post_count Whether to display the post count alongside the link. Default false.
|
|
1329 |
* @type bool|int $echo Whether to echo or return the links list. Default 1|true to echo.
|
|
1330 |
* @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'.
|
|
1331 |
* Default 'DESC'.
|
|
1332 |
* }
|
0
|
1333 |
* @return string|null String when retrieving, null when displaying.
|
|
1334 |
*/
|
5
|
1335 |
function wp_get_archives( $args = '' ) {
|
0
|
1336 |
global $wpdb, $wp_locale;
|
|
1337 |
|
|
1338 |
$defaults = array(
|
|
1339 |
'type' => 'monthly', 'limit' => '',
|
|
1340 |
'format' => 'html', 'before' => '',
|
|
1341 |
'after' => '', 'show_post_count' => false,
|
|
1342 |
'echo' => 1, 'order' => 'DESC',
|
|
1343 |
);
|
|
1344 |
|
|
1345 |
$r = wp_parse_args( $args, $defaults );
|
|
1346 |
|
5
|
1347 |
if ( '' == $r['type'] ) {
|
|
1348 |
$r['type'] = 'monthly';
|
0
|
1349 |
}
|
|
1350 |
|
5
|
1351 |
if ( ! empty( $r['limit'] ) ) {
|
|
1352 |
$r['limit'] = absint( $r['limit'] );
|
|
1353 |
$r['limit'] = ' LIMIT ' . $r['limit'];
|
|
1354 |
}
|
|
1355 |
|
|
1356 |
$order = strtoupper( $r['order'] );
|
|
1357 |
if ( $order !== 'ASC' ) {
|
0
|
1358 |
$order = 'DESC';
|
5
|
1359 |
}
|
0
|
1360 |
|
|
1361 |
// this is what will separate dates on weekly archive links
|
|
1362 |
$archive_week_separator = '–';
|
|
1363 |
|
|
1364 |
// over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
|
|
1365 |
$archive_date_format_over_ride = 0;
|
|
1366 |
|
|
1367 |
// options for daily archive (only if you over-ride the general date format)
|
|
1368 |
$archive_day_date_format = 'Y/m/d';
|
|
1369 |
|
|
1370 |
// options for weekly archive (only if you over-ride the general date format)
|
|
1371 |
$archive_week_start_date_format = 'Y/m/d';
|
|
1372 |
$archive_week_end_date_format = 'Y/m/d';
|
|
1373 |
|
5
|
1374 |
if ( ! $archive_date_format_over_ride ) {
|
|
1375 |
$archive_day_date_format = get_option( 'date_format' );
|
|
1376 |
$archive_week_start_date_format = get_option( 'date_format' );
|
|
1377 |
$archive_week_end_date_format = get_option( 'date_format' );
|
0
|
1378 |
}
|
|
1379 |
|
5
|
1380 |
/**
|
|
1381 |
* Filter the SQL WHERE clause for retrieving archives.
|
|
1382 |
*
|
|
1383 |
* @since 2.2.0
|
|
1384 |
*
|
|
1385 |
* @param string $sql_where Portion of SQL query containing the WHERE clause.
|
|
1386 |
* @param array $r An array of default arguments.
|
|
1387 |
*/
|
0
|
1388 |
$where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
|
5
|
1389 |
|
|
1390 |
/**
|
|
1391 |
* Filter the SQL JOIN clause for retrieving archives.
|
|
1392 |
*
|
|
1393 |
* @since 2.2.0
|
|
1394 |
*
|
|
1395 |
* @param string $sql_join Portion of SQL query containing JOIN clause.
|
|
1396 |
* @param array $r An array of default arguments.
|
|
1397 |
*/
|
0
|
1398 |
$join = apply_filters( 'getarchives_join', '', $r );
|
|
1399 |
|
|
1400 |
$output = '';
|
|
1401 |
|
|
1402 |
$last_changed = wp_cache_get( 'last_changed', 'posts' );
|
|
1403 |
if ( ! $last_changed ) {
|
|
1404 |
$last_changed = microtime();
|
|
1405 |
wp_cache_set( 'last_changed', $last_changed, 'posts' );
|
|
1406 |
}
|
|
1407 |
|
5
|
1408 |
$limit = $r['limit'];
|
|
1409 |
|
|
1410 |
if ( 'monthly' == $r['type'] ) {
|
0
|
1411 |
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit";
|
|
1412 |
$key = md5( $query );
|
|
1413 |
$key = "wp_get_archives:$key:$last_changed";
|
|
1414 |
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
|
|
1415 |
$results = $wpdb->get_results( $query );
|
|
1416 |
wp_cache_set( $key, $results, 'posts' );
|
|
1417 |
}
|
|
1418 |
if ( $results ) {
|
5
|
1419 |
$after = $r['after'];
|
0
|
1420 |
foreach ( (array) $results as $result ) {
|
|
1421 |
$url = get_month_link( $result->year, $result->month );
|
|
1422 |
/* translators: 1: month name, 2: 4-digit year */
|
5
|
1423 |
$text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );
|
|
1424 |
if ( $r['show_post_count'] ) {
|
|
1425 |
$r['after'] = ' (' . $result->posts . ')' . $after;
|
|
1426 |
}
|
|
1427 |
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
|
0
|
1428 |
}
|
|
1429 |
}
|
5
|
1430 |
} elseif ( 'yearly' == $r['type'] ) {
|
0
|
1431 |
$query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
|
|
1432 |
$key = md5( $query );
|
|
1433 |
$key = "wp_get_archives:$key:$last_changed";
|
|
1434 |
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
|
|
1435 |
$results = $wpdb->get_results( $query );
|
|
1436 |
wp_cache_set( $key, $results, 'posts' );
|
|
1437 |
}
|
|
1438 |
if ( $results ) {
|
5
|
1439 |
$after = $r['after'];
|
0
|
1440 |
foreach ( (array) $results as $result) {
|
5
|
1441 |
$url = get_year_link( $result->year );
|
|
1442 |
$text = sprintf( '%d', $result->year );
|
|
1443 |
if ( $r['show_post_count'] ) {
|
|
1444 |
$r['after'] = ' (' . $result->posts . ')' . $after;
|
|
1445 |
}
|
|
1446 |
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
|
0
|
1447 |
}
|
|
1448 |
}
|
5
|
1449 |
} elseif ( 'daily' == $r['type'] ) {
|
0
|
1450 |
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
|
|
1451 |
$key = md5( $query );
|
|
1452 |
$key = "wp_get_archives:$key:$last_changed";
|
|
1453 |
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
|
|
1454 |
$results = $wpdb->get_results( $query );
|
|
1455 |
wp_cache_set( $key, $results, 'posts' );
|
|
1456 |
}
|
|
1457 |
if ( $results ) {
|
5
|
1458 |
$after = $r['after'];
|
0
|
1459 |
foreach ( (array) $results as $result ) {
|
5
|
1460 |
$url = get_day_link( $result->year, $result->month, $result->dayofmonth );
|
|
1461 |
$date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth );
|
|
1462 |
$text = mysql2date( $archive_day_date_format, $date );
|
|
1463 |
if ( $r['show_post_count'] ) {
|
|
1464 |
$r['after'] = ' (' . $result->posts . ')' . $after;
|
|
1465 |
}
|
|
1466 |
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
|
0
|
1467 |
}
|
|
1468 |
}
|
5
|
1469 |
} elseif ( 'weekly' == $r['type'] ) {
|
0
|
1470 |
$week = _wp_mysql_week( '`post_date`' );
|
|
1471 |
$query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
|
|
1472 |
$key = md5( $query );
|
|
1473 |
$key = "wp_get_archives:$key:$last_changed";
|
|
1474 |
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
|
|
1475 |
$results = $wpdb->get_results( $query );
|
|
1476 |
wp_cache_set( $key, $results, 'posts' );
|
|
1477 |
}
|
|
1478 |
$arc_w_last = '';
|
|
1479 |
if ( $results ) {
|
5
|
1480 |
$after = $r['after'];
|
|
1481 |
foreach ( (array) $results as $result ) {
|
|
1482 |
if ( $result->week != $arc_w_last ) {
|
|
1483 |
$arc_year = $result->yr;
|
|
1484 |
$arc_w_last = $result->week;
|
|
1485 |
$arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) );
|
|
1486 |
$arc_week_start = date_i18n( $archive_week_start_date_format, $arc_week['start'] );
|
|
1487 |
$arc_week_end = date_i18n( $archive_week_end_date_format, $arc_week['end'] );
|
|
1488 |
$url = sprintf( '%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $result->week );
|
|
1489 |
$text = $arc_week_start . $archive_week_separator . $arc_week_end;
|
|
1490 |
if ( $r['show_post_count'] ) {
|
|
1491 |
$r['after'] = ' (' . $result->posts . ')' . $after;
|
0
|
1492 |
}
|
5
|
1493 |
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
|
0
|
1494 |
}
|
5
|
1495 |
}
|
0
|
1496 |
}
|
5
|
1497 |
} elseif ( ( 'postbypost' == $r['type'] ) || ('alpha' == $r['type'] ) ) {
|
|
1498 |
$orderby = ( 'alpha' == $r['type'] ) ? 'post_title ASC ' : 'post_date DESC, ID DESC ';
|
0
|
1499 |
$query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
|
|
1500 |
$key = md5( $query );
|
|
1501 |
$key = "wp_get_archives:$key:$last_changed";
|
|
1502 |
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
|
|
1503 |
$results = $wpdb->get_results( $query );
|
|
1504 |
wp_cache_set( $key, $results, 'posts' );
|
|
1505 |
}
|
|
1506 |
if ( $results ) {
|
|
1507 |
foreach ( (array) $results as $result ) {
|
|
1508 |
if ( $result->post_date != '0000-00-00 00:00:00' ) {
|
5
|
1509 |
$url = get_permalink( $result );
|
0
|
1510 |
if ( $result->post_title ) {
|
|
1511 |
/** This filter is documented in wp-includes/post-template.php */
|
|
1512 |
$text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
|
|
1513 |
} else {
|
|
1514 |
$text = $result->ID;
|
|
1515 |
}
|
5
|
1516 |
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
|
0
|
1517 |
}
|
|
1518 |
}
|
|
1519 |
}
|
|
1520 |
}
|
5
|
1521 |
if ( $r['echo'] ) {
|
0
|
1522 |
echo $output;
|
5
|
1523 |
} else {
|
0
|
1524 |
return $output;
|
5
|
1525 |
}
|
0
|
1526 |
}
|
|
1527 |
|
|
1528 |
/**
|
|
1529 |
* Get number of days since the start of the week.
|
|
1530 |
*
|
|
1531 |
* @since 1.5.0
|
|
1532 |
*
|
|
1533 |
* @param int $num Number of day.
|
|
1534 |
* @return int Days since the start of the week.
|
|
1535 |
*/
|
|
1536 |
function calendar_week_mod($num) {
|
|
1537 |
$base = 7;
|
|
1538 |
return ($num - $base*floor($num/$base));
|
|
1539 |
}
|
|
1540 |
|
|
1541 |
/**
|
|
1542 |
* Display calendar with days that have posts as links.
|
|
1543 |
*
|
|
1544 |
* The calendar is cached, which will be retrieved, if it exists. If there are
|
|
1545 |
* no posts for the month, then it will not be displayed.
|
|
1546 |
*
|
|
1547 |
* @since 1.0.0
|
|
1548 |
*
|
|
1549 |
* @param bool $initial Optional, default is true. Use initial calendar names.
|
|
1550 |
* @param bool $echo Optional, default is true. Set to false for return.
|
|
1551 |
* @return string|null String when retrieving, null when displaying.
|
|
1552 |
*/
|
|
1553 |
function get_calendar($initial = true, $echo = true) {
|
|
1554 |
global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
|
|
1555 |
|
|
1556 |
$key = md5( $m . $monthnum . $year );
|
|
1557 |
if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
|
|
1558 |
if ( is_array($cache) && isset( $cache[ $key ] ) ) {
|
|
1559 |
if ( $echo ) {
|
5
|
1560 |
/** This filter is documented in wp-includes/general-template.php */
|
|
1561 |
echo apply_filters( 'get_calendar', $cache[$key] );
|
0
|
1562 |
return;
|
|
1563 |
} else {
|
5
|
1564 |
/** This filter is documented in wp-includes/general-template.php */
|
|
1565 |
return apply_filters( 'get_calendar', $cache[$key] );
|
0
|
1566 |
}
|
|
1567 |
}
|
|
1568 |
}
|
|
1569 |
|
|
1570 |
if ( !is_array($cache) )
|
|
1571 |
$cache = array();
|
|
1572 |
|
|
1573 |
// Quick check. If we have no posts at all, abort!
|
|
1574 |
if ( !$posts ) {
|
|
1575 |
$gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
|
|
1576 |
if ( !$gotsome ) {
|
|
1577 |
$cache[ $key ] = '';
|
|
1578 |
wp_cache_set( 'get_calendar', $cache, 'calendar' );
|
|
1579 |
return;
|
|
1580 |
}
|
|
1581 |
}
|
|
1582 |
|
|
1583 |
if ( isset($_GET['w']) )
|
|
1584 |
$w = ''.intval($_GET['w']);
|
|
1585 |
|
|
1586 |
// week_begins = 0 stands for Sunday
|
|
1587 |
$week_begins = intval(get_option('start_of_week'));
|
|
1588 |
|
|
1589 |
// Let's figure out when we are
|
|
1590 |
if ( !empty($monthnum) && !empty($year) ) {
|
|
1591 |
$thismonth = ''.zeroise(intval($monthnum), 2);
|
|
1592 |
$thisyear = ''.intval($year);
|
|
1593 |
} elseif ( !empty($w) ) {
|
|
1594 |
// We need to get the month from MySQL
|
|
1595 |
$thisyear = ''.intval(substr($m, 0, 4));
|
|
1596 |
$d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
|
|
1597 |
$thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
|
|
1598 |
} elseif ( !empty($m) ) {
|
|
1599 |
$thisyear = ''.intval(substr($m, 0, 4));
|
|
1600 |
if ( strlen($m) < 6 )
|
|
1601 |
$thismonth = '01';
|
|
1602 |
else
|
|
1603 |
$thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
|
|
1604 |
} else {
|
|
1605 |
$thisyear = gmdate('Y', current_time('timestamp'));
|
|
1606 |
$thismonth = gmdate('m', current_time('timestamp'));
|
|
1607 |
}
|
|
1608 |
|
|
1609 |
$unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
|
|
1610 |
$last_day = date('t', $unixmonth);
|
|
1611 |
|
|
1612 |
// Get the next and previous month and year with at least one post
|
|
1613 |
$previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
|
|
1614 |
FROM $wpdb->posts
|
|
1615 |
WHERE post_date < '$thisyear-$thismonth-01'
|
|
1616 |
AND post_type = 'post' AND post_status = 'publish'
|
|
1617 |
ORDER BY post_date DESC
|
|
1618 |
LIMIT 1");
|
|
1619 |
$next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
|
|
1620 |
FROM $wpdb->posts
|
|
1621 |
WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
|
|
1622 |
AND post_type = 'post' AND post_status = 'publish'
|
|
1623 |
ORDER BY post_date ASC
|
|
1624 |
LIMIT 1");
|
|
1625 |
|
|
1626 |
/* translators: Calendar caption: 1: month name, 2: 4-digit year */
|
|
1627 |
$calendar_caption = _x('%1$s %2$s', 'calendar caption');
|
|
1628 |
$calendar_output = '<table id="wp-calendar">
|
|
1629 |
<caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
|
|
1630 |
<thead>
|
|
1631 |
<tr>';
|
|
1632 |
|
|
1633 |
$myweek = array();
|
|
1634 |
|
|
1635 |
for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
|
|
1636 |
$myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
|
|
1637 |
}
|
|
1638 |
|
|
1639 |
foreach ( $myweek as $wd ) {
|
|
1640 |
$day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
|
|
1641 |
$wd = esc_attr($wd);
|
|
1642 |
$calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
|
|
1643 |
}
|
|
1644 |
|
|
1645 |
$calendar_output .= '
|
|
1646 |
</tr>
|
|
1647 |
</thead>
|
|
1648 |
|
|
1649 |
<tfoot>
|
|
1650 |
<tr>';
|
|
1651 |
|
|
1652 |
if ( $previous ) {
|
5
|
1653 |
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '">« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
|
0
|
1654 |
} else {
|
|
1655 |
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
|
|
1656 |
}
|
|
1657 |
|
|
1658 |
$calendar_output .= "\n\t\t".'<td class="pad"> </td>';
|
|
1659 |
|
|
1660 |
if ( $next ) {
|
5
|
1661 |
$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »</a></td>';
|
0
|
1662 |
} else {
|
|
1663 |
$calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
|
|
1664 |
}
|
|
1665 |
|
|
1666 |
$calendar_output .= '
|
|
1667 |
</tr>
|
|
1668 |
</tfoot>
|
|
1669 |
|
|
1670 |
<tbody>
|
|
1671 |
<tr>';
|
|
1672 |
|
5
|
1673 |
$daywithpost = array();
|
|
1674 |
|
0
|
1675 |
// Get days with posts
|
|
1676 |
$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
|
|
1677 |
FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
|
|
1678 |
AND post_type = 'post' AND post_status = 'publish'
|
|
1679 |
AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
|
|
1680 |
if ( $dayswithposts ) {
|
|
1681 |
foreach ( (array) $dayswithposts as $daywith ) {
|
|
1682 |
$daywithpost[] = $daywith[0];
|
|
1683 |
}
|
|
1684 |
}
|
|
1685 |
|
|
1686 |
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
|
|
1687 |
$ak_title_separator = "\n";
|
|
1688 |
else
|
|
1689 |
$ak_title_separator = ', ';
|
|
1690 |
|
|
1691 |
$ak_titles_for_day = array();
|
|
1692 |
$ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
|
|
1693 |
."FROM $wpdb->posts "
|
|
1694 |
."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
|
|
1695 |
."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
|
|
1696 |
."AND post_type = 'post' AND post_status = 'publish'"
|
|
1697 |
);
|
|
1698 |
if ( $ak_post_titles ) {
|
|
1699 |
foreach ( (array) $ak_post_titles as $ak_post_title ) {
|
|
1700 |
|
|
1701 |
/** This filter is documented in wp-includes/post-template.php */
|
|
1702 |
$post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
|
|
1703 |
|
|
1704 |
if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
|
|
1705 |
$ak_titles_for_day['day_'.$ak_post_title->dom] = '';
|
|
1706 |
if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
|
|
1707 |
$ak_titles_for_day["$ak_post_title->dom"] = $post_title;
|
|
1708 |
else
|
|
1709 |
$ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
|
|
1710 |
}
|
|
1711 |
}
|
|
1712 |
|
|
1713 |
// See how much we should pad in the beginning
|
|
1714 |
$pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
|
|
1715 |
if ( 0 != $pad )
|
|
1716 |
$calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad"> </td>';
|
|
1717 |
|
|
1718 |
$daysinmonth = intval(date('t', $unixmonth));
|
|
1719 |
for ( $day = 1; $day <= $daysinmonth; ++$day ) {
|
|
1720 |
if ( isset($newrow) && $newrow )
|
|
1721 |
$calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
|
|
1722 |
$newrow = false;
|
|
1723 |
|
|
1724 |
if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
|
|
1725 |
$calendar_output .= '<td id="today">';
|
|
1726 |
else
|
|
1727 |
$calendar_output .= '<td>';
|
|
1728 |
|
|
1729 |
if ( in_array($day, $daywithpost) ) // any posts today?
|
|
1730 |
$calendar_output .= '<a href="' . get_day_link( $thisyear, $thismonth, $day ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
|
|
1731 |
else
|
|
1732 |
$calendar_output .= $day;
|
|
1733 |
$calendar_output .= '</td>';
|
|
1734 |
|
|
1735 |
if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
|
|
1736 |
$newrow = true;
|
|
1737 |
}
|
|
1738 |
|
|
1739 |
$pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
|
|
1740 |
if ( $pad != 0 && $pad != 7 )
|
|
1741 |
$calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'"> </td>';
|
|
1742 |
|
|
1743 |
$calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
|
|
1744 |
|
|
1745 |
$cache[ $key ] = $calendar_output;
|
|
1746 |
wp_cache_set( 'get_calendar', $cache, 'calendar' );
|
|
1747 |
|
5
|
1748 |
if ( $echo ) {
|
|
1749 |
/**
|
|
1750 |
* Filter the HTML calendar output.
|
|
1751 |
*
|
|
1752 |
* @since 3.0.0
|
|
1753 |
*
|
|
1754 |
* @param string $calendar_output HTML output of the calendar.
|
|
1755 |
*/
|
|
1756 |
echo apply_filters( 'get_calendar', $calendar_output );
|
|
1757 |
} else {
|
|
1758 |
/** This filter is documented in wp-includes/general-template.php */
|
|
1759 |
return apply_filters( 'get_calendar', $calendar_output );
|
|
1760 |
}
|
0
|
1761 |
|
|
1762 |
}
|
|
1763 |
|
|
1764 |
/**
|
|
1765 |
* Purge the cached results of get_calendar.
|
|
1766 |
*
|
|
1767 |
* @see get_calendar
|
|
1768 |
* @since 2.1.0
|
|
1769 |
*/
|
|
1770 |
function delete_get_calendar_cache() {
|
|
1771 |
wp_cache_delete( 'get_calendar', 'calendar' );
|
|
1772 |
}
|
|
1773 |
|
|
1774 |
/**
|
|
1775 |
* Display all of the allowed tags in HTML format with attributes.
|
|
1776 |
*
|
|
1777 |
* This is useful for displaying in the comment area, which elements and
|
|
1778 |
* attributes are supported. As well as any plugins which want to display it.
|
|
1779 |
*
|
|
1780 |
* @since 1.0.1
|
|
1781 |
* @uses $allowedtags
|
|
1782 |
*
|
|
1783 |
* @return string HTML allowed tags entity encoded.
|
|
1784 |
*/
|
|
1785 |
function allowed_tags() {
|
|
1786 |
global $allowedtags;
|
|
1787 |
$allowed = '';
|
|
1788 |
foreach ( (array) $allowedtags as $tag => $attributes ) {
|
|
1789 |
$allowed .= '<'.$tag;
|
|
1790 |
if ( 0 < count($attributes) ) {
|
|
1791 |
foreach ( $attributes as $attribute => $limits ) {
|
|
1792 |
$allowed .= ' '.$attribute.'=""';
|
|
1793 |
}
|
|
1794 |
}
|
|
1795 |
$allowed .= '> ';
|
|
1796 |
}
|
|
1797 |
return htmlentities($allowed);
|
|
1798 |
}
|
|
1799 |
|
|
1800 |
/***** Date/Time tags *****/
|
|
1801 |
|
|
1802 |
/**
|
|
1803 |
* Outputs the date in iso8601 format for xml files.
|
|
1804 |
*
|
|
1805 |
* @since 1.0.0
|
|
1806 |
*/
|
|
1807 |
function the_date_xml() {
|
|
1808 |
echo mysql2date( 'Y-m-d', get_post()->post_date, false );
|
|
1809 |
}
|
|
1810 |
|
|
1811 |
/**
|
5
|
1812 |
* Display or Retrieve the date the current post was written (once per date)
|
0
|
1813 |
*
|
|
1814 |
* Will only output the date if the current post's date is different from the
|
|
1815 |
* previous one output.
|
|
1816 |
*
|
|
1817 |
* i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
|
|
1818 |
* function is called several times for each post.
|
|
1819 |
*
|
|
1820 |
* HTML output can be filtered with 'the_date'.
|
|
1821 |
* Date string output can be filtered with 'get_the_date'.
|
|
1822 |
*
|
|
1823 |
* @since 0.71
|
5
|
1824 |
*
|
0
|
1825 |
* @param string $d Optional. PHP date format defaults to the date_format option if not specified.
|
|
1826 |
* @param string $before Optional. Output before the date.
|
|
1827 |
* @param string $after Optional. Output after the date.
|
|
1828 |
* @param bool $echo Optional, default is display. Whether to echo the date or return it.
|
|
1829 |
* @return string|null Null if displaying, string if retrieving.
|
|
1830 |
*/
|
|
1831 |
function the_date( $d = '', $before = '', $after = '', $echo = true ) {
|
|
1832 |
global $currentday, $previousday;
|
5
|
1833 |
|
0
|
1834 |
if ( $currentday != $previousday ) {
|
5
|
1835 |
$the_date = $before . get_the_date( $d ) . $after;
|
0
|
1836 |
$previousday = $currentday;
|
|
1837 |
|
5
|
1838 |
/**
|
|
1839 |
* Filter the date a post was published for display.
|
|
1840 |
*
|
|
1841 |
* @since 0.71
|
|
1842 |
*
|
|
1843 |
* @param string $the_date The formatted date string.
|
|
1844 |
* @param string $d PHP date format. Defaults to 'date_format' option
|
|
1845 |
* if not specified.
|
|
1846 |
* @param string $before HTML output before the date.
|
|
1847 |
* @param string $after HTML output after the date.
|
|
1848 |
*/
|
|
1849 |
$the_date = apply_filters( 'the_date', $the_date, $d, $before, $after );
|
0
|
1850 |
|
|
1851 |
if ( $echo )
|
|
1852 |
echo $the_date;
|
|
1853 |
else
|
|
1854 |
return $the_date;
|
|
1855 |
}
|
|
1856 |
|
|
1857 |
return null;
|
|
1858 |
}
|
|
1859 |
|
|
1860 |
/**
|
5
|
1861 |
* Retrieve the date on which the post was written.
|
0
|
1862 |
*
|
|
1863 |
* Unlike the_date() this function will always return the date.
|
|
1864 |
* Modify output with 'get_the_date' filter.
|
|
1865 |
*
|
|
1866 |
* @since 3.0.0
|
|
1867 |
*
|
5
|
1868 |
* @param string $d Optional. PHP date format defaults to the date_format option if not specified.
|
|
1869 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
|
|
1870 |
* @return false|string Date the current post was written. False on failure.
|
0
|
1871 |
*/
|
5
|
1872 |
function get_the_date( $d = '', $post = null ) {
|
|
1873 |
$post = get_post( $post );
|
|
1874 |
|
|
1875 |
if ( ! $post ) {
|
|
1876 |
return false;
|
|
1877 |
}
|
0
|
1878 |
|
5
|
1879 |
if ( '' == $d ) {
|
|
1880 |
$the_date = mysql2date( get_option( 'date_format' ), $post->post_date );
|
|
1881 |
} else {
|
|
1882 |
$the_date = mysql2date( $d, $post->post_date );
|
|
1883 |
}
|
0
|
1884 |
|
5
|
1885 |
/**
|
|
1886 |
* Filter the date a post was published.
|
|
1887 |
*
|
|
1888 |
* @since 3.0.0
|
|
1889 |
*
|
|
1890 |
* @param string $the_date The formatted date.
|
|
1891 |
* @param string $d PHP date format. Defaults to 'date_format' option
|
|
1892 |
* if not specified.
|
|
1893 |
* @param int|WP_Post $post The post object or ID.
|
|
1894 |
*/
|
|
1895 |
return apply_filters( 'get_the_date', $the_date, $d, $post );
|
0
|
1896 |
}
|
|
1897 |
|
|
1898 |
/**
|
|
1899 |
* Display the date on which the post was last modified.
|
|
1900 |
*
|
|
1901 |
* @since 2.1.0
|
|
1902 |
*
|
|
1903 |
* @param string $d Optional. PHP date format defaults to the date_format option if not specified.
|
|
1904 |
* @param string $before Optional. Output before the date.
|
|
1905 |
* @param string $after Optional. Output after the date.
|
|
1906 |
* @param bool $echo Optional, default is display. Whether to echo the date or return it.
|
|
1907 |
* @return string|null Null if displaying, string if retrieving.
|
|
1908 |
*/
|
|
1909 |
function the_modified_date($d = '', $before='', $after='', $echo = true) {
|
|
1910 |
|
|
1911 |
$the_modified_date = $before . get_the_modified_date($d) . $after;
|
5
|
1912 |
|
|
1913 |
/**
|
|
1914 |
* Filter the date a post was last modified for display.
|
|
1915 |
*
|
|
1916 |
* @since 2.1.0
|
|
1917 |
*
|
|
1918 |
* @param string $the_modified_date The last modified date.
|
|
1919 |
* @param string $d PHP date format. Defaults to 'date_format' option
|
|
1920 |
* if not specified.
|
|
1921 |
* @param string $before HTML output before the date.
|
|
1922 |
* @param string $after HTML output after the date.
|
|
1923 |
*/
|
|
1924 |
$the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $d, $before, $after );
|
0
|
1925 |
|
|
1926 |
if ( $echo )
|
|
1927 |
echo $the_modified_date;
|
|
1928 |
else
|
|
1929 |
return $the_modified_date;
|
|
1930 |
|
|
1931 |
}
|
|
1932 |
|
|
1933 |
/**
|
|
1934 |
* Retrieve the date on which the post was last modified.
|
|
1935 |
*
|
|
1936 |
* @since 2.1.0
|
|
1937 |
*
|
|
1938 |
* @param string $d Optional. PHP date format. Defaults to the "date_format" option
|
|
1939 |
* @return string
|
|
1940 |
*/
|
|
1941 |
function get_the_modified_date($d = '') {
|
|
1942 |
if ( '' == $d )
|
|
1943 |
$the_time = get_post_modified_time(get_option('date_format'), null, null, true);
|
|
1944 |
else
|
|
1945 |
$the_time = get_post_modified_time($d, null, null, true);
|
5
|
1946 |
|
|
1947 |
/**
|
|
1948 |
* Filter the date a post was last modified.
|
|
1949 |
*
|
|
1950 |
* @since 2.1.0
|
|
1951 |
*
|
|
1952 |
* @param string $the_time The formatted date.
|
|
1953 |
* @param string $d PHP date format. Defaults to value specified in
|
|
1954 |
* 'date_format' option.
|
|
1955 |
*/
|
|
1956 |
return apply_filters( 'get_the_modified_date', $the_time, $d );
|
0
|
1957 |
}
|
|
1958 |
|
|
1959 |
/**
|
|
1960 |
* Display the time at which the post was written.
|
|
1961 |
*
|
|
1962 |
* @since 0.71
|
|
1963 |
*
|
|
1964 |
* @param string $d Either 'G', 'U', or php date format.
|
|
1965 |
*/
|
|
1966 |
function the_time( $d = '' ) {
|
5
|
1967 |
/**
|
|
1968 |
* Filter the time a post was written for display.
|
|
1969 |
*
|
|
1970 |
* @since 0.71
|
|
1971 |
*
|
|
1972 |
* @param string $get_the_time The formatted time.
|
|
1973 |
* @param string $d The time format. Accepts 'G', 'U',
|
|
1974 |
* or php date format.
|
|
1975 |
*/
|
|
1976 |
echo apply_filters( 'the_time', get_the_time( $d ), $d );
|
0
|
1977 |
}
|
|
1978 |
|
|
1979 |
/**
|
|
1980 |
* Retrieve the time at which the post was written.
|
|
1981 |
*
|
|
1982 |
* @since 1.5.0
|
|
1983 |
*
|
5
|
1984 |
* @param string $d Optional. Format to use for retrieving the time the post
|
|
1985 |
* was written. Either 'G', 'U', or php date format defaults
|
|
1986 |
* to the value specified in the time_format option. Default empty.
|
|
1987 |
* @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
|
|
1988 |
* @return false|string Formatted date string or Unix timestamp. False on failure.
|
0
|
1989 |
*/
|
|
1990 |
function get_the_time( $d = '', $post = null ) {
|
|
1991 |
$post = get_post($post);
|
|
1992 |
|
5
|
1993 |
if ( ! $post ) {
|
|
1994 |
return false;
|
|
1995 |
}
|
|
1996 |
|
0
|
1997 |
if ( '' == $d )
|
|
1998 |
$the_time = get_post_time(get_option('time_format'), false, $post, true);
|
|
1999 |
else
|
|
2000 |
$the_time = get_post_time($d, false, $post, true);
|
5
|
2001 |
|
|
2002 |
/**
|
|
2003 |
* Filter the time a post was written.
|
|
2004 |
*
|
|
2005 |
* @since 1.5.0
|
|
2006 |
*
|
|
2007 |
* @param string $the_time The formatted time.
|
|
2008 |
* @param string $d Format to use for retrieving the time the post was written.
|
|
2009 |
* Accepts 'G', 'U', or php date format value specified
|
|
2010 |
* in 'time_format' option. Default empty.
|
|
2011 |
* @param int|WP_Post $post WP_Post object or ID.
|
|
2012 |
*/
|
|
2013 |
return apply_filters( 'get_the_time', $the_time, $d, $post );
|
0
|
2014 |
}
|
|
2015 |
|
|
2016 |
/**
|
|
2017 |
* Retrieve the time at which the post was written.
|
|
2018 |
*
|
|
2019 |
* @since 2.0.0
|
|
2020 |
*
|
5
|
2021 |
* @param string $d Optional. Format to use for retrieving the time the post
|
|
2022 |
* was written. Either 'G', 'U', or php date format. Default 'U'.
|
|
2023 |
* @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
|
|
2024 |
* @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
|
|
2025 |
* @param bool $translate Whether to translate the time string. Default false.
|
|
2026 |
* @return false|string|int Formatted date string or Unix timestamp. False on failure.
|
0
|
2027 |
*/
|
5
|
2028 |
function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
|
0
|
2029 |
$post = get_post($post);
|
|
2030 |
|
5
|
2031 |
if ( ! $post ) {
|
|
2032 |
return false;
|
|
2033 |
}
|
|
2034 |
|
0
|
2035 |
if ( $gmt )
|
|
2036 |
$time = $post->post_date_gmt;
|
|
2037 |
else
|
|
2038 |
$time = $post->post_date;
|
|
2039 |
|
|
2040 |
$time = mysql2date($d, $time, $translate);
|
5
|
2041 |
|
|
2042 |
/**
|
|
2043 |
* Filter the localized time a post was written.
|
|
2044 |
*
|
|
2045 |
* @since 2.6.0
|
|
2046 |
*
|
|
2047 |
* @param string $time The formatted time.
|
|
2048 |
* @param string $d Format to use for retrieving the time the post was written.
|
|
2049 |
* Accepts 'G', 'U', or php date format. Default 'U'.
|
|
2050 |
* @param bool $gmt Whether to retrieve the GMT time. Default false.
|
|
2051 |
*/
|
|
2052 |
return apply_filters( 'get_post_time', $time, $d, $gmt );
|
0
|
2053 |
}
|
|
2054 |
|
|
2055 |
/**
|
|
2056 |
* Display the time at which the post was last modified.
|
|
2057 |
*
|
|
2058 |
* @since 2.0.0
|
|
2059 |
*
|
|
2060 |
* @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
|
|
2061 |
*/
|
|
2062 |
function the_modified_time($d = '') {
|
5
|
2063 |
/**
|
|
2064 |
* Filter the localized time a post was last modified, for display.
|
|
2065 |
*
|
|
2066 |
* @since 2.0.0
|
|
2067 |
*
|
|
2068 |
* @param string $get_the_modified_time The formatted time.
|
|
2069 |
* @param string $d The time format. Accepts 'G', 'U',
|
|
2070 |
* or php date format. Defaults to value
|
|
2071 |
* specified in 'time_format' option.
|
|
2072 |
*/
|
|
2073 |
echo apply_filters( 'the_modified_time', get_the_modified_time($d), $d );
|
0
|
2074 |
}
|
|
2075 |
|
|
2076 |
/**
|
|
2077 |
* Retrieve the time at which the post was last modified.
|
|
2078 |
*
|
|
2079 |
* @since 2.0.0
|
|
2080 |
*
|
|
2081 |
* @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
|
|
2082 |
* @return string
|
|
2083 |
*/
|
|
2084 |
function get_the_modified_time($d = '') {
|
|
2085 |
if ( '' == $d )
|
|
2086 |
$the_time = get_post_modified_time(get_option('time_format'), null, null, true);
|
|
2087 |
else
|
|
2088 |
$the_time = get_post_modified_time($d, null, null, true);
|
5
|
2089 |
|
|
2090 |
/**
|
|
2091 |
* Filter the localized time a post was last modified.
|
|
2092 |
*
|
|
2093 |
* @since 2.0.0
|
|
2094 |
*
|
|
2095 |
* @param string $the_time The formatted time.
|
|
2096 |
* @param string $d Format to use for retrieving the time the post was
|
|
2097 |
* written. Accepts 'G', 'U', or php date format. Defaults
|
|
2098 |
* to value specified in 'time_format' option.
|
|
2099 |
*/
|
|
2100 |
return apply_filters( 'get_the_modified_time', $the_time, $d );
|
0
|
2101 |
}
|
|
2102 |
|
|
2103 |
/**
|
|
2104 |
* Retrieve the time at which the post was last modified.
|
|
2105 |
*
|
|
2106 |
* @since 2.0.0
|
|
2107 |
*
|
5
|
2108 |
* @param string $d Optional. Format to use for retrieving the time the post
|
|
2109 |
* was modified. Either 'G', 'U', or php date format. Default 'U'.
|
|
2110 |
* @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
|
|
2111 |
* @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
|
|
2112 |
* @param bool $translate Whether to translate the time string. Default false.
|
|
2113 |
* @return false|string Formatted date string or Unix timestamp. False on failure.
|
0
|
2114 |
*/
|
|
2115 |
function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
|
|
2116 |
$post = get_post($post);
|
|
2117 |
|
5
|
2118 |
if ( ! $post ) {
|
|
2119 |
return false;
|
|
2120 |
}
|
|
2121 |
|
0
|
2122 |
if ( $gmt )
|
|
2123 |
$time = $post->post_modified_gmt;
|
|
2124 |
else
|
|
2125 |
$time = $post->post_modified;
|
|
2126 |
$time = mysql2date($d, $time, $translate);
|
|
2127 |
|
5
|
2128 |
/**
|
|
2129 |
* Filter the localized time a post was last modified.
|
|
2130 |
*
|
|
2131 |
* @since 2.8.0
|
|
2132 |
*
|
|
2133 |
* @param string $time The formatted time.
|
|
2134 |
* @param string $d The date format. Accepts 'G', 'U', or php date format. Default 'U'.
|
|
2135 |
* @param bool $gmt Whether to return the GMT time. Default false.
|
|
2136 |
*/
|
|
2137 |
return apply_filters( 'get_post_modified_time', $time, $d, $gmt );
|
0
|
2138 |
}
|
|
2139 |
|
|
2140 |
/**
|
|
2141 |
* Display the weekday on which the post was written.
|
|
2142 |
*
|
|
2143 |
* @since 0.71
|
|
2144 |
* @uses $wp_locale
|
|
2145 |
*/
|
|
2146 |
function the_weekday() {
|
|
2147 |
global $wp_locale;
|
|
2148 |
$the_weekday = $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
|
5
|
2149 |
|
|
2150 |
/**
|
|
2151 |
* Filter the weekday on which the post was written, for display.
|
|
2152 |
*
|
|
2153 |
* @since 0.71
|
|
2154 |
*
|
|
2155 |
* @param string $the_weekday
|
|
2156 |
*/
|
|
2157 |
$the_weekday = apply_filters( 'the_weekday', $the_weekday );
|
0
|
2158 |
echo $the_weekday;
|
|
2159 |
}
|
|
2160 |
|
|
2161 |
/**
|
|
2162 |
* Display the weekday on which the post was written.
|
|
2163 |
*
|
|
2164 |
* Will only output the weekday if the current post's weekday is different from
|
|
2165 |
* the previous one output.
|
|
2166 |
*
|
|
2167 |
* @since 0.71
|
|
2168 |
*
|
|
2169 |
* @param string $before Optional Output before the date.
|
|
2170 |
* @param string $after Optional Output after the date.
|
|
2171 |
*/
|
|
2172 |
function the_weekday_date($before='',$after='') {
|
|
2173 |
global $wp_locale, $currentday, $previousweekday;
|
|
2174 |
$the_weekday_date = '';
|
|
2175 |
if ( $currentday != $previousweekday ) {
|
|
2176 |
$the_weekday_date .= $before;
|
|
2177 |
$the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
|
|
2178 |
$the_weekday_date .= $after;
|
|
2179 |
$previousweekday = $currentday;
|
|
2180 |
}
|
5
|
2181 |
|
|
2182 |
/**
|
|
2183 |
* Filter the localized date on which the post was written, for display.
|
|
2184 |
*
|
|
2185 |
* @since 0.71
|
|
2186 |
*
|
|
2187 |
* @param string $the_weekday_date
|
|
2188 |
* @param string $before The HTML to output before the date.
|
|
2189 |
* @param string $after The HTML to output after the date.
|
|
2190 |
*/
|
|
2191 |
$the_weekday_date = apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after );
|
0
|
2192 |
echo $the_weekday_date;
|
|
2193 |
}
|
|
2194 |
|
|
2195 |
/**
|
|
2196 |
* Fire the wp_head action
|
|
2197 |
*
|
|
2198 |
* @since 1.2.0
|
|
2199 |
*/
|
|
2200 |
function wp_head() {
|
5
|
2201 |
/**
|
|
2202 |
* Print scripts or data in the head tag on the front end.
|
|
2203 |
*
|
|
2204 |
* @since 1.5.0
|
|
2205 |
*/
|
|
2206 |
do_action( 'wp_head' );
|
0
|
2207 |
}
|
|
2208 |
|
|
2209 |
/**
|
|
2210 |
* Fire the wp_footer action
|
|
2211 |
*
|
|
2212 |
* @since 1.5.1
|
|
2213 |
*/
|
|
2214 |
function wp_footer() {
|
5
|
2215 |
/**
|
|
2216 |
* Print scripts or data before the closing body tag on the front end.
|
|
2217 |
*
|
|
2218 |
* @since 1.5.1
|
|
2219 |
*/
|
|
2220 |
do_action( 'wp_footer' );
|
0
|
2221 |
}
|
|
2222 |
|
|
2223 |
/**
|
|
2224 |
* Display the links to the general feeds.
|
|
2225 |
*
|
|
2226 |
* @since 2.8.0
|
|
2227 |
*
|
|
2228 |
* @param array $args Optional arguments.
|
|
2229 |
*/
|
|
2230 |
function feed_links( $args = array() ) {
|
|
2231 |
if ( !current_theme_supports('automatic-feed-links') )
|
|
2232 |
return;
|
|
2233 |
|
|
2234 |
$defaults = array(
|
|
2235 |
/* translators: Separator between blog name and feed type in feed links */
|
|
2236 |
'separator' => _x('»', 'feed link'),
|
|
2237 |
/* translators: 1: blog title, 2: separator (raquo) */
|
|
2238 |
'feedtitle' => __('%1$s %2$s Feed'),
|
|
2239 |
/* translators: 1: blog title, 2: separator (raquo) */
|
|
2240 |
'comstitle' => __('%1$s %2$s Comments Feed'),
|
|
2241 |
);
|
|
2242 |
|
|
2243 |
$args = wp_parse_args( $args, $defaults );
|
|
2244 |
|
|
2245 |
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['feedtitle'], get_bloginfo('name'), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link() ) . "\" />\n";
|
|
2246 |
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link( 'comments_' . get_default_feed() ) ) . "\" />\n";
|
|
2247 |
}
|
|
2248 |
|
|
2249 |
/**
|
|
2250 |
* Display the links to the extra feeds such as category feeds.
|
|
2251 |
*
|
|
2252 |
* @since 2.8.0
|
|
2253 |
*
|
|
2254 |
* @param array $args Optional arguments.
|
|
2255 |
*/
|
|
2256 |
function feed_links_extra( $args = array() ) {
|
|
2257 |
$defaults = array(
|
|
2258 |
/* translators: Separator between blog name and feed type in feed links */
|
|
2259 |
'separator' => _x('»', 'feed link'),
|
|
2260 |
/* translators: 1: blog name, 2: separator(raquo), 3: post title */
|
|
2261 |
'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
|
|
2262 |
/* translators: 1: blog name, 2: separator(raquo), 3: category name */
|
|
2263 |
'cattitle' => __('%1$s %2$s %3$s Category Feed'),
|
|
2264 |
/* translators: 1: blog name, 2: separator(raquo), 3: tag name */
|
|
2265 |
'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
|
|
2266 |
/* translators: 1: blog name, 2: separator(raquo), 3: author name */
|
|
2267 |
'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
|
|
2268 |
/* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
|
|
2269 |
'searchtitle' => __('%1$s %2$s Search Results for “%3$s” Feed'),
|
|
2270 |
/* translators: 1: blog name, 2: separator(raquo), 3: post type name */
|
|
2271 |
'posttypetitle' => __('%1$s %2$s %3$s Feed'),
|
|
2272 |
);
|
|
2273 |
|
|
2274 |
$args = wp_parse_args( $args, $defaults );
|
|
2275 |
|
|
2276 |
if ( is_singular() ) {
|
|
2277 |
$id = 0;
|
|
2278 |
$post = get_post( $id );
|
|
2279 |
|
|
2280 |
if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
|
5
|
2281 |
$title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], the_title_attribute( array( 'echo' => false ) ) );
|
0
|
2282 |
$href = get_post_comments_feed_link( $post->ID );
|
|
2283 |
}
|
|
2284 |
} elseif ( is_post_type_archive() ) {
|
|
2285 |
$post_type = get_query_var( 'post_type' );
|
|
2286 |
if ( is_array( $post_type ) )
|
|
2287 |
$post_type = reset( $post_type );
|
|
2288 |
|
|
2289 |
$post_type_obj = get_post_type_object( $post_type );
|
|
2290 |
$title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name );
|
|
2291 |
$href = get_post_type_archive_feed_link( $post_type_obj->name );
|
|
2292 |
} elseif ( is_category() ) {
|
|
2293 |
$term = get_queried_object();
|
|
2294 |
|
|
2295 |
if ( $term ) {
|
|
2296 |
$title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name );
|
|
2297 |
$href = get_category_feed_link( $term->term_id );
|
|
2298 |
}
|
|
2299 |
} elseif ( is_tag() ) {
|
|
2300 |
$term = get_queried_object();
|
|
2301 |
|
|
2302 |
if ( $term ) {
|
|
2303 |
$title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name );
|
|
2304 |
$href = get_tag_feed_link( $term->term_id );
|
|
2305 |
}
|
|
2306 |
} elseif ( is_author() ) {
|
|
2307 |
$author_id = intval( get_query_var('author') );
|
|
2308 |
|
|
2309 |
$title = sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) );
|
|
2310 |
$href = get_author_feed_link( $author_id );
|
|
2311 |
} elseif ( is_search() ) {
|
|
2312 |
$title = sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) );
|
|
2313 |
$href = get_search_feed_link();
|
|
2314 |
} elseif ( is_post_type_archive() ) {
|
|
2315 |
$title = sprintf( $args['posttypetitle'], get_bloginfo('name'), $args['separator'], post_type_archive_title( '', false ) );
|
|
2316 |
$post_type_obj = get_queried_object();
|
|
2317 |
if ( $post_type_obj )
|
|
2318 |
$href = get_post_type_archive_feed_link( $post_type_obj->name );
|
|
2319 |
}
|
|
2320 |
|
|
2321 |
if ( isset($title) && isset($href) )
|
|
2322 |
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n";
|
|
2323 |
}
|
|
2324 |
|
|
2325 |
/**
|
|
2326 |
* Display the link to the Really Simple Discovery service endpoint.
|
|
2327 |
*
|
|
2328 |
* @link http://archipelago.phrasewise.com/rsd
|
|
2329 |
* @since 2.0.0
|
|
2330 |
*/
|
|
2331 |
function rsd_link() {
|
|
2332 |
echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
|
|
2333 |
}
|
|
2334 |
|
|
2335 |
/**
|
|
2336 |
* Display the link to the Windows Live Writer manifest file.
|
|
2337 |
*
|
|
2338 |
* @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
|
|
2339 |
* @since 2.3.1
|
|
2340 |
*/
|
|
2341 |
function wlwmanifest_link() {
|
5
|
2342 |
echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="',
|
|
2343 |
includes_url( 'wlwmanifest.xml' ), '" /> ', "\n";
|
0
|
2344 |
}
|
|
2345 |
|
|
2346 |
/**
|
|
2347 |
* Display a noindex meta tag if required by the blog configuration.
|
|
2348 |
*
|
|
2349 |
* If a blog is marked as not being public then the noindex meta tag will be
|
|
2350 |
* output to tell web robots not to index the page content. Add this to the wp_head action.
|
|
2351 |
* Typical usage is as a wp_head callback. add_action( 'wp_head', 'noindex' );
|
|
2352 |
*
|
|
2353 |
* @see wp_no_robots
|
|
2354 |
*
|
|
2355 |
* @since 2.1.0
|
|
2356 |
*/
|
|
2357 |
function noindex() {
|
|
2358 |
// If the blog is not public, tell robots to go away.
|
|
2359 |
if ( '0' == get_option('blog_public') )
|
|
2360 |
wp_no_robots();
|
|
2361 |
}
|
|
2362 |
|
|
2363 |
/**
|
|
2364 |
* Display a noindex meta tag.
|
|
2365 |
*
|
|
2366 |
* Outputs a noindex meta tag that tells web robots not to index the page content.
|
|
2367 |
* Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_no_robots' );
|
|
2368 |
*
|
|
2369 |
* @since 3.3.0
|
|
2370 |
*/
|
|
2371 |
function wp_no_robots() {
|
5
|
2372 |
echo "<meta name='robots' content='noindex,follow' />\n";
|
0
|
2373 |
}
|
|
2374 |
|
|
2375 |
/**
|
|
2376 |
* Whether the user should have a WYSIWIG editor.
|
|
2377 |
*
|
|
2378 |
* Checks that the user requires a WYSIWIG editor and that the editor is
|
|
2379 |
* supported in the users browser.
|
|
2380 |
*
|
|
2381 |
* @since 2.0.0
|
|
2382 |
*
|
|
2383 |
* @return bool
|
|
2384 |
*/
|
|
2385 |
function user_can_richedit() {
|
|
2386 |
global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE;
|
|
2387 |
|
|
2388 |
if ( !isset($wp_rich_edit) ) {
|
|
2389 |
$wp_rich_edit = false;
|
|
2390 |
|
|
2391 |
if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users
|
|
2392 |
if ( $is_safari ) {
|
|
2393 |
$wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 );
|
|
2394 |
} elseif ( $is_gecko || $is_chrome || $is_IE || ( $is_opera && !wp_is_mobile() ) ) {
|
|
2395 |
$wp_rich_edit = true;
|
|
2396 |
}
|
|
2397 |
}
|
|
2398 |
}
|
|
2399 |
|
5
|
2400 |
/**
|
|
2401 |
* Filter whether the user can access the rich (Visual) editor.
|
|
2402 |
*
|
|
2403 |
* @since 2.1.0
|
|
2404 |
*
|
|
2405 |
* @param bool $wp_rich_edit Whether the user can access to the rich (Visual) editor.
|
|
2406 |
*/
|
|
2407 |
return apply_filters( 'user_can_richedit', $wp_rich_edit );
|
0
|
2408 |
}
|
|
2409 |
|
|
2410 |
/**
|
|
2411 |
* Find out which editor should be displayed by default.
|
|
2412 |
*
|
|
2413 |
* Works out which of the two editors to display as the current editor for a
|
|
2414 |
* user. The 'html' setting is for the "Text" editor tab.
|
|
2415 |
*
|
|
2416 |
* @since 2.5.0
|
|
2417 |
*
|
|
2418 |
* @return string Either 'tinymce', or 'html', or 'test'
|
|
2419 |
*/
|
|
2420 |
function wp_default_editor() {
|
|
2421 |
$r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
|
5
|
2422 |
if ( wp_get_current_user() ) { // look for cookie
|
0
|
2423 |
$ed = get_user_setting('editor', 'tinymce');
|
|
2424 |
$r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
|
|
2425 |
}
|
5
|
2426 |
|
|
2427 |
/**
|
|
2428 |
* Filter which editor should be displayed by default.
|
|
2429 |
*
|
|
2430 |
* @since 2.5.0
|
|
2431 |
*
|
|
2432 |
* @param array $r An array of editors. Accepts 'tinymce', 'html', 'test'.
|
|
2433 |
*/
|
|
2434 |
return apply_filters( 'wp_default_editor', $r );
|
0
|
2435 |
}
|
|
2436 |
|
|
2437 |
/**
|
|
2438 |
* Renders an editor.
|
|
2439 |
*
|
|
2440 |
* Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
|
5
|
2441 |
* _WP_Editors should not be used directly. See https://core.trac.wordpress.org/ticket/17144.
|
0
|
2442 |
*
|
|
2443 |
* NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
|
|
2444 |
* running wp_editor() inside of a metabox is not a good idea unless only Quicktags is used.
|
|
2445 |
* On the post edit screen several actions can be used to include additional editors
|
|
2446 |
* containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
|
5
|
2447 |
* See https://core.trac.wordpress.org/ticket/19173 for more information.
|
0
|
2448 |
*
|
|
2449 |
* @see wp-includes/class-wp-editor.php
|
|
2450 |
* @since 3.3.0
|
|
2451 |
*
|
|
2452 |
* @param string $content Initial content for the editor.
|
|
2453 |
* @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/.
|
|
2454 |
* @param array $settings See _WP_Editors::editor().
|
|
2455 |
*/
|
|
2456 |
function wp_editor( $content, $editor_id, $settings = array() ) {
|
|
2457 |
if ( ! class_exists( '_WP_Editors' ) )
|
|
2458 |
require( ABSPATH . WPINC . '/class-wp-editor.php' );
|
|
2459 |
|
|
2460 |
_WP_Editors::editor($content, $editor_id, $settings);
|
|
2461 |
}
|
|
2462 |
|
|
2463 |
/**
|
|
2464 |
* Retrieve the contents of the search WordPress query variable.
|
|
2465 |
*
|
|
2466 |
* The search query string is passed through {@link esc_attr()}
|
|
2467 |
* to ensure that it is safe for placing in an html attribute.
|
|
2468 |
*
|
|
2469 |
* @since 2.3.0
|
|
2470 |
*
|
|
2471 |
* @param bool $escaped Whether the result is escaped. Default true.
|
|
2472 |
* Only use when you are later escaping it. Do not use unescaped.
|
|
2473 |
* @return string
|
|
2474 |
*/
|
|
2475 |
function get_search_query( $escaped = true ) {
|
5
|
2476 |
/**
|
|
2477 |
* Filter the contents of the search query variable.
|
|
2478 |
*
|
|
2479 |
* @since 2.3.0
|
|
2480 |
*
|
|
2481 |
* @param mixed $search Contents of the search query variable.
|
|
2482 |
*/
|
0
|
2483 |
$query = apply_filters( 'get_search_query', get_query_var( 's' ) );
|
5
|
2484 |
|
0
|
2485 |
if ( $escaped )
|
|
2486 |
$query = esc_attr( $query );
|
|
2487 |
return $query;
|
|
2488 |
}
|
|
2489 |
|
|
2490 |
/**
|
|
2491 |
* Display the contents of the search query variable.
|
|
2492 |
*
|
|
2493 |
* The search query string is passed through {@link esc_attr()}
|
|
2494 |
* to ensure that it is safe for placing in an html attribute.
|
|
2495 |
*
|
|
2496 |
* @since 2.1.0
|
|
2497 |
*/
|
|
2498 |
function the_search_query() {
|
5
|
2499 |
/**
|
|
2500 |
* Filter the contents of the search query variable for display.
|
|
2501 |
*
|
|
2502 |
* @since 2.3.0
|
|
2503 |
*
|
|
2504 |
* @param mixed $search Contents of the search query variable.
|
|
2505 |
*/
|
0
|
2506 |
echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
|
|
2507 |
}
|
|
2508 |
|
|
2509 |
/**
|
|
2510 |
* Display the language attributes for the html tag.
|
|
2511 |
*
|
|
2512 |
* Builds up a set of html attributes containing the text direction and language
|
|
2513 |
* information for the page.
|
|
2514 |
*
|
|
2515 |
* @since 2.1.0
|
|
2516 |
*
|
|
2517 |
* @param string $doctype The type of html document (xhtml|html).
|
|
2518 |
*/
|
|
2519 |
function language_attributes($doctype = 'html') {
|
|
2520 |
$attributes = array();
|
|
2521 |
|
|
2522 |
if ( function_exists( 'is_rtl' ) && is_rtl() )
|
|
2523 |
$attributes[] = 'dir="rtl"';
|
|
2524 |
|
|
2525 |
if ( $lang = get_bloginfo('language') ) {
|
|
2526 |
if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
|
|
2527 |
$attributes[] = "lang=\"$lang\"";
|
|
2528 |
|
|
2529 |
if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
|
|
2530 |
$attributes[] = "xml:lang=\"$lang\"";
|
|
2531 |
}
|
|
2532 |
|
|
2533 |
$output = implode(' ', $attributes);
|
5
|
2534 |
|
|
2535 |
/**
|
|
2536 |
* Filter the language attributes for display in the html tag.
|
|
2537 |
*
|
|
2538 |
* @since 2.5.0
|
|
2539 |
*
|
|
2540 |
* @param string $output A space-separated list of language attributes.
|
|
2541 |
*/
|
|
2542 |
echo apply_filters( 'language_attributes', $output );
|
0
|
2543 |
}
|
|
2544 |
|
|
2545 |
/**
|
|
2546 |
* Retrieve paginated link for archive post pages.
|
|
2547 |
*
|
|
2548 |
* Technically, the function can be used to create paginated link list for any
|
|
2549 |
* area. The 'base' argument is used to reference the url, which will be used to
|
|
2550 |
* create the paginated links. The 'format' argument is then used for replacing
|
|
2551 |
* the page number. It is however, most likely and by default, to be used on the
|
|
2552 |
* archive post pages.
|
|
2553 |
*
|
|
2554 |
* The 'type' argument controls format of the returned value. The default is
|
|
2555 |
* 'plain', which is just a string with the links separated by a newline
|
|
2556 |
* character. The other possible values are either 'array' or 'list'. The
|
|
2557 |
* 'array' value will return an array of the paginated link list to offer full
|
|
2558 |
* control of display. The 'list' value will place all of the paginated links in
|
|
2559 |
* an unordered HTML list.
|
|
2560 |
*
|
|
2561 |
* The 'total' argument is the total amount of pages and is an integer. The
|
|
2562 |
* 'current' argument is the current page number and is also an integer.
|
|
2563 |
*
|
|
2564 |
* An example of the 'base' argument is "http://example.com/all_posts.php%_%"
|
|
2565 |
* and the '%_%' is required. The '%_%' will be replaced by the contents of in
|
|
2566 |
* the 'format' argument. An example for the 'format' argument is "?page=%#%"
|
|
2567 |
* and the '%#%' is also required. The '%#%' will be replaced with the page
|
|
2568 |
* number.
|
|
2569 |
*
|
|
2570 |
* You can include the previous and next links in the list by setting the
|
|
2571 |
* 'prev_next' argument to true, which it is by default. You can set the
|
|
2572 |
* previous text, by using the 'prev_text' argument. You can set the next text
|
|
2573 |
* by setting the 'next_text' argument.
|
|
2574 |
*
|
|
2575 |
* If the 'show_all' argument is set to true, then it will show all of the pages
|
|
2576 |
* instead of a short list of the pages near the current page. By default, the
|
|
2577 |
* 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
|
|
2578 |
* arguments. The 'end_size' argument is how many numbers on either the start
|
|
2579 |
* and the end list edges, by default is 1. The 'mid_size' argument is how many
|
|
2580 |
* numbers to either side of current page, but not including current page.
|
|
2581 |
*
|
|
2582 |
* It is possible to add query vars to the link by using the 'add_args' argument
|
|
2583 |
* and see {@link add_query_arg()} for more information.
|
|
2584 |
*
|
5
|
2585 |
* The 'before_page_number' and 'after_page_number' arguments allow users to
|
|
2586 |
* augment the links themselves. Typically this might be to add context to the
|
|
2587 |
* numbered links so that screen reader users understand what the links are for.
|
|
2588 |
* The text strings are added before and after the page number - within the
|
|
2589 |
* anchor tag.
|
|
2590 |
*
|
0
|
2591 |
* @since 2.1.0
|
|
2592 |
*
|
5
|
2593 |
* @param string|array $args {
|
|
2594 |
* Optional. Array or string of arguments for generating paginated links for archives.
|
|
2595 |
*
|
|
2596 |
* @type string $base Base of the paginated url. Default empty.
|
|
2597 |
* @type string $format Format for the pagination structure. Default empty.
|
|
2598 |
* @type int $total The total amount of pages. Default is the value WP_Query's
|
|
2599 |
* `max_num_pages` or 1.
|
|
2600 |
* @type int $current The current page number. Default is 'paged' query var or 1.
|
|
2601 |
* @type bool $show_all Whether to show all pages. Default false.
|
|
2602 |
* @type int $end_size How many numbers on either the start and the end list edges.
|
|
2603 |
* Default 1.
|
|
2604 |
* @type int $mid_size How many numbers to either side of the current pages. Default 2.
|
|
2605 |
* @type bool $prev_next Whether to include the previous and next links in the list. Default true.
|
|
2606 |
* @type bool $prev_text The previous page text. Default '« Previous'.
|
|
2607 |
* @type bool $next_text The next page text. Default '« Previous'.
|
|
2608 |
* @type string $type Controls format of the returned value. Possible values are 'plain',
|
|
2609 |
* 'array' and 'list'. Default is 'plain'.
|
|
2610 |
* @type array $add_args An array of query args to add. Default false.
|
|
2611 |
* @type string $add_fragment A string to append to each link. Default empty.
|
|
2612 |
* @type string $before_page_number A string to appear before the page number. Default empty.
|
|
2613 |
* @type string $after_page_number A string to append after the page number. Default empty.
|
|
2614 |
* }
|
0
|
2615 |
* @return array|string String of page links or array of page links.
|
|
2616 |
*/
|
|
2617 |
function paginate_links( $args = '' ) {
|
5
|
2618 |
global $wp_query, $wp_rewrite;
|
|
2619 |
|
|
2620 |
// Setting up default values based on the current URL.
|
|
2621 |
$pagenum_link = html_entity_decode( get_pagenum_link() );
|
|
2622 |
$url_parts = explode( '?', $pagenum_link );
|
|
2623 |
|
|
2624 |
// Get max pages and current page out of the current query, if available.
|
|
2625 |
$total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
|
|
2626 |
$current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
|
|
2627 |
|
|
2628 |
// Append the format placeholder to the base URL.
|
|
2629 |
$pagenum_link = trailingslashit( $url_parts[0] ) . '%_%';
|
|
2630 |
|
|
2631 |
// URL base depends on permalink settings.
|
|
2632 |
$format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
|
|
2633 |
$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
|
|
2634 |
|
0
|
2635 |
$defaults = array(
|
5
|
2636 |
'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
|
|
2637 |
'format' => $format, // ?page=%#% : %#% is replaced by the page number
|
|
2638 |
'total' => $total,
|
|
2639 |
'current' => $current,
|
0
|
2640 |
'show_all' => false,
|
|
2641 |
'prev_next' => true,
|
|
2642 |
'prev_text' => __('« Previous'),
|
|
2643 |
'next_text' => __('Next »'),
|
|
2644 |
'end_size' => 1,
|
|
2645 |
'mid_size' => 2,
|
|
2646 |
'type' => 'plain',
|
5
|
2647 |
'add_args' => array(), // array of query args to add
|
|
2648 |
'add_fragment' => '',
|
|
2649 |
'before_page_number' => '',
|
|
2650 |
'after_page_number' => ''
|
0
|
2651 |
);
|
|
2652 |
|
|
2653 |
$args = wp_parse_args( $args, $defaults );
|
5
|
2654 |
|
|
2655 |
if ( ! is_array( $args['add_args'] ) ) {
|
|
2656 |
$args['add_args'] = array();
|
|
2657 |
}
|
|
2658 |
|
|
2659 |
// Merge additional query vars found in the original URL into 'add_args' array.
|
|
2660 |
if ( isset( $url_parts[1] ) ) {
|
|
2661 |
// Find the format argument.
|
|
2662 |
$format_query = parse_url( str_replace( '%_%', $args['format'], $args['base'] ), PHP_URL_QUERY );
|
|
2663 |
wp_parse_str( $format_query, $format_arg );
|
|
2664 |
|
|
2665 |
// Remove the format argument from the array of query arguments, to avoid overwriting custom format.
|
|
2666 |
wp_parse_str( remove_query_arg( array_keys( $format_arg ), $url_parts[1] ), $query_args );
|
|
2667 |
$args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $query_args ) );
|
|
2668 |
}
|
0
|
2669 |
|
|
2670 |
// Who knows what else people pass in $args
|
5
|
2671 |
$total = (int) $args['total'];
|
|
2672 |
if ( $total < 2 ) {
|
0
|
2673 |
return;
|
5
|
2674 |
}
|
|
2675 |
$current = (int) $args['current'];
|
|
2676 |
$end_size = (int) $args['end_size']; // Out of bounds? Make it the default.
|
|
2677 |
if ( $end_size < 1 ) {
|
|
2678 |
$end_size = 1;
|
|
2679 |
}
|
|
2680 |
$mid_size = (int) $args['mid_size'];
|
|
2681 |
if ( $mid_size < 0 ) {
|
|
2682 |
$mid_size = 2;
|
|
2683 |
}
|
|
2684 |
$add_args = $args['add_args'];
|
0
|
2685 |
$r = '';
|
|
2686 |
$page_links = array();
|
|
2687 |
$dots = false;
|
|
2688 |
|
5
|
2689 |
if ( $args['prev_next'] && $current && 1 < $current ) :
|
|
2690 |
$link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] );
|
|
2691 |
$link = str_replace( '%#%', $current - 1, $link );
|
0
|
2692 |
if ( $add_args )
|
|
2693 |
$link = add_query_arg( $add_args, $link );
|
5
|
2694 |
$link .= $args['add_fragment'];
|
|
2695 |
|
|
2696 |
/**
|
|
2697 |
* Filter the paginated links for the given archive pages.
|
|
2698 |
*
|
|
2699 |
* @since 3.0.0
|
|
2700 |
*
|
|
2701 |
* @param string $link The paginated link URL.
|
|
2702 |
*/
|
|
2703 |
$page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['prev_text'] . '</a>';
|
0
|
2704 |
endif;
|
|
2705 |
for ( $n = 1; $n <= $total; $n++ ) :
|
|
2706 |
if ( $n == $current ) :
|
5
|
2707 |
$page_links[] = "<span class='page-numbers current'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</span>";
|
0
|
2708 |
$dots = true;
|
|
2709 |
else :
|
5
|
2710 |
if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
|
|
2711 |
$link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] );
|
|
2712 |
$link = str_replace( '%#%', $n, $link );
|
0
|
2713 |
if ( $add_args )
|
|
2714 |
$link = add_query_arg( $add_args, $link );
|
5
|
2715 |
$link .= $args['add_fragment'];
|
|
2716 |
|
|
2717 |
/** This filter is documented in wp-includes/general-template.php */
|
|
2718 |
$page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</a>";
|
0
|
2719 |
$dots = true;
|
5
|
2720 |
elseif ( $dots && ! $args['show_all'] ) :
|
0
|
2721 |
$page_links[] = '<span class="page-numbers dots">' . __( '…' ) . '</span>';
|
|
2722 |
$dots = false;
|
|
2723 |
endif;
|
|
2724 |
endif;
|
|
2725 |
endfor;
|
5
|
2726 |
if ( $args['prev_next'] && $current && ( $current < $total || -1 == $total ) ) :
|
|
2727 |
$link = str_replace( '%_%', $args['format'], $args['base'] );
|
|
2728 |
$link = str_replace( '%#%', $current + 1, $link );
|
0
|
2729 |
if ( $add_args )
|
|
2730 |
$link = add_query_arg( $add_args, $link );
|
5
|
2731 |
$link .= $args['add_fragment'];
|
|
2732 |
|
|
2733 |
/** This filter is documented in wp-includes/general-template.php */
|
|
2734 |
$page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['next_text'] . '</a>';
|
0
|
2735 |
endif;
|
5
|
2736 |
switch ( $args['type'] ) {
|
0
|
2737 |
case 'array' :
|
|
2738 |
return $page_links;
|
5
|
2739 |
|
0
|
2740 |
case 'list' :
|
|
2741 |
$r .= "<ul class='page-numbers'>\n\t<li>";
|
|
2742 |
$r .= join("</li>\n\t<li>", $page_links);
|
|
2743 |
$r .= "</li>\n</ul>\n";
|
|
2744 |
break;
|
5
|
2745 |
|
0
|
2746 |
default :
|
|
2747 |
$r = join("\n", $page_links);
|
|
2748 |
break;
|
5
|
2749 |
}
|
0
|
2750 |
return $r;
|
|
2751 |
}
|
|
2752 |
|
|
2753 |
/**
|
|
2754 |
* Registers an admin colour scheme css file.
|
|
2755 |
*
|
|
2756 |
* Allows a plugin to register a new admin colour scheme. For example:
|
5
|
2757 |
*
|
|
2758 |
* wp_admin_css_color( 'classic', __( 'Classic' ), admin_url( "css/colors-classic.css" ), array(
|
|
2759 |
* '#07273E', '#14568A', '#D54E21', '#2683AE'
|
|
2760 |
* ) );
|
0
|
2761 |
*
|
|
2762 |
* @since 2.5.0
|
|
2763 |
*
|
5
|
2764 |
* @todo Properly document optional arguments as such
|
|
2765 |
*
|
0
|
2766 |
* @param string $key The unique key for this theme.
|
|
2767 |
* @param string $name The name of the theme.
|
|
2768 |
* @param string $url The url of the css file containing the colour scheme.
|
|
2769 |
* @param array $colors Optional An array of CSS color definitions which are used to give the user a feel for the theme.
|
5
|
2770 |
* @param array $icons Optional An array of CSS color definitions used to color any SVG icons
|
0
|
2771 |
*/
|
5
|
2772 |
function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) {
|
0
|
2773 |
global $_wp_admin_css_colors;
|
|
2774 |
|
|
2775 |
if ( !isset($_wp_admin_css_colors) )
|
|
2776 |
$_wp_admin_css_colors = array();
|
|
2777 |
|
5
|
2778 |
$_wp_admin_css_colors[$key] = (object) array(
|
|
2779 |
'name' => $name,
|
|
2780 |
'url' => $url,
|
|
2781 |
'colors' => $colors,
|
|
2782 |
'icon_colors' => $icons,
|
|
2783 |
);
|
0
|
2784 |
}
|
|
2785 |
|
|
2786 |
/**
|
|
2787 |
* Registers the default Admin color schemes
|
|
2788 |
*
|
|
2789 |
* @since 3.0.0
|
|
2790 |
*/
|
|
2791 |
function register_admin_color_schemes() {
|
5
|
2792 |
$suffix = is_rtl() ? '-rtl' : '';
|
|
2793 |
$suffix .= defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
|
2794 |
|
|
2795 |
wp_admin_css_color( 'fresh', _x( 'Default', 'admin color scheme' ),
|
|
2796 |
false,
|
|
2797 |
array( '#222', '#333', '#0073aa', '#00a0d2' ),
|
|
2798 |
array( 'base' => '#999', 'focus' => '#00a0d2', 'current' => '#fff' )
|
|
2799 |
);
|
|
2800 |
|
|
2801 |
// Other color schemes are not available when running out of src
|
|
2802 |
if ( false !== strpos( $GLOBALS['wp_version'], '-src' ) )
|
|
2803 |
return;
|
|
2804 |
|
|
2805 |
wp_admin_css_color( 'light', _x( 'Light', 'admin color scheme' ),
|
|
2806 |
admin_url( "css/colors/light/colors$suffix.css" ),
|
|
2807 |
array( '#e5e5e5', '#999', '#d64e07', '#04a4cc' ),
|
|
2808 |
array( 'base' => '#999', 'focus' => '#ccc', 'current' => '#ccc' )
|
|
2809 |
);
|
|
2810 |
|
|
2811 |
wp_admin_css_color( 'blue', _x( 'Blue', 'admin color scheme' ),
|
|
2812 |
admin_url( "css/colors/blue/colors$suffix.css" ),
|
|
2813 |
array( '#096484', '#4796b3', '#52accc', '#74B6CE' ),
|
|
2814 |
array( 'base' => '#e5f8ff', 'focus' => '#fff', 'current' => '#fff' )
|
|
2815 |
);
|
|
2816 |
|
|
2817 |
wp_admin_css_color( 'midnight', _x( 'Midnight', 'admin color scheme' ),
|
|
2818 |
admin_url( "css/colors/midnight/colors$suffix.css" ),
|
|
2819 |
array( '#25282b', '#363b3f', '#69a8bb', '#e14d43' ),
|
|
2820 |
array( 'base' => '#f1f2f3', 'focus' => '#fff', 'current' => '#fff' )
|
|
2821 |
);
|
|
2822 |
|
|
2823 |
wp_admin_css_color( 'sunrise', _x( 'Sunrise', 'admin color scheme' ),
|
|
2824 |
admin_url( "css/colors/sunrise/colors$suffix.css" ),
|
|
2825 |
array( '#b43c38', '#cf4944', '#dd823b', '#ccaf0b' ),
|
|
2826 |
array( 'base' => '#f3f1f1', 'focus' => '#fff', 'current' => '#fff' )
|
|
2827 |
);
|
|
2828 |
|
|
2829 |
wp_admin_css_color( 'ectoplasm', _x( 'Ectoplasm', 'admin color scheme' ),
|
|
2830 |
admin_url( "css/colors/ectoplasm/colors$suffix.css" ),
|
|
2831 |
array( '#413256', '#523f6d', '#a3b745', '#d46f15' ),
|
|
2832 |
array( 'base' => '#ece6f6', 'focus' => '#fff', 'current' => '#fff' )
|
|
2833 |
);
|
|
2834 |
|
|
2835 |
wp_admin_css_color( 'ocean', _x( 'Ocean', 'admin color scheme' ),
|
|
2836 |
admin_url( "css/colors/ocean/colors$suffix.css" ),
|
|
2837 |
array( '#627c83', '#738e96', '#9ebaa0', '#aa9d88' ),
|
|
2838 |
array( 'base' => '#f2fcff', 'focus' => '#fff', 'current' => '#fff' )
|
|
2839 |
);
|
|
2840 |
|
|
2841 |
wp_admin_css_color( 'coffee', _x( 'Coffee', 'admin color scheme' ),
|
|
2842 |
admin_url( "css/colors/coffee/colors$suffix.css" ),
|
|
2843 |
array( '#46403c', '#59524c', '#c7a589', '#9ea476' ),
|
|
2844 |
array( 'base' => '#f3f2f1', 'focus' => '#fff', 'current' => '#fff' )
|
|
2845 |
);
|
|
2846 |
|
0
|
2847 |
}
|
|
2848 |
|
|
2849 |
/**
|
|
2850 |
* Display the URL of a WordPress admin CSS file.
|
|
2851 |
*
|
|
2852 |
* @see WP_Styles::_css_href and its style_loader_src filter.
|
|
2853 |
*
|
|
2854 |
* @since 2.3.0
|
|
2855 |
*
|
|
2856 |
* @param string $file file relative to wp-admin/ without its ".css" extension.
|
|
2857 |
*/
|
|
2858 |
function wp_admin_css_uri( $file = 'wp-admin' ) {
|
|
2859 |
if ( defined('WP_INSTALLING') ) {
|
|
2860 |
$_file = "./$file.css";
|
|
2861 |
} else {
|
|
2862 |
$_file = admin_url("$file.css");
|
|
2863 |
}
|
|
2864 |
$_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
|
|
2865 |
|
5
|
2866 |
/**
|
|
2867 |
* Filter the URI of a WordPress admin CSS file.
|
|
2868 |
*
|
|
2869 |
* @since 2.3.0
|
|
2870 |
*
|
|
2871 |
* @param string $_file Relative path to the file with query arguments attached.
|
|
2872 |
* @param string $file Relative path to the file, minus its ".css" extension.
|
|
2873 |
*/
|
0
|
2874 |
return apply_filters( 'wp_admin_css_uri', $_file, $file );
|
|
2875 |
}
|
|
2876 |
|
|
2877 |
/**
|
|
2878 |
* Enqueues or directly prints a stylesheet link to the specified CSS file.
|
|
2879 |
*
|
|
2880 |
* "Intelligently" decides to enqueue or to print the CSS file. If the
|
|
2881 |
* 'wp_print_styles' action has *not* yet been called, the CSS file will be
|
|
2882 |
* enqueued. If the wp_print_styles action *has* been called, the CSS link will
|
|
2883 |
* be printed. Printing may be forced by passing true as the $force_echo
|
|
2884 |
* (second) parameter.
|
|
2885 |
*
|
|
2886 |
* For backward compatibility with WordPress 2.3 calling method: If the $file
|
|
2887 |
* (first) parameter does not correspond to a registered CSS file, we assume
|
|
2888 |
* $file is a file relative to wp-admin/ without its ".css" extension. A
|
|
2889 |
* stylesheet link to that generated URL is printed.
|
|
2890 |
*
|
|
2891 |
* @since 2.3.0
|
|
2892 |
* @uses $wp_styles WordPress Styles Object
|
|
2893 |
*
|
|
2894 |
* @param string $file Optional. Style handle name or file name (without ".css" extension) relative
|
|
2895 |
* to wp-admin/. Defaults to 'wp-admin'.
|
|
2896 |
* @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
|
|
2897 |
*/
|
|
2898 |
function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
|
|
2899 |
global $wp_styles;
|
5
|
2900 |
if ( ! ( $wp_styles instanceof WP_Styles ) ) {
|
0
|
2901 |
$wp_styles = new WP_Styles();
|
5
|
2902 |
}
|
0
|
2903 |
|
|
2904 |
// For backward compatibility
|
|
2905 |
$handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
|
|
2906 |
|
|
2907 |
if ( $wp_styles->query( $handle ) ) {
|
|
2908 |
if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
|
|
2909 |
wp_print_styles( $handle );
|
|
2910 |
else // Add to style queue
|
|
2911 |
wp_enqueue_style( $handle );
|
|
2912 |
return;
|
|
2913 |
}
|
|
2914 |
|
5
|
2915 |
/**
|
|
2916 |
* Filter the stylesheet link to the specified CSS file.
|
|
2917 |
*
|
|
2918 |
* If the site is set to display right-to-left, the RTL stylesheet link
|
|
2919 |
* will be used instead.
|
|
2920 |
*
|
|
2921 |
* @since 2.3.0
|
|
2922 |
*
|
|
2923 |
* @param string $file Style handle name or filename (without ".css" extension)
|
|
2924 |
* relative to wp-admin/. Defaults to 'wp-admin'.
|
|
2925 |
*/
|
0
|
2926 |
echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
|
5
|
2927 |
|
|
2928 |
if ( function_exists( 'is_rtl' ) && is_rtl() ) {
|
|
2929 |
/** This filter is documented in wp-includes/general-template.php */
|
0
|
2930 |
echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
|
5
|
2931 |
}
|
0
|
2932 |
}
|
|
2933 |
|
|
2934 |
/**
|
|
2935 |
* Enqueues the default ThickBox js and css.
|
|
2936 |
*
|
|
2937 |
* If any of the settings need to be changed, this can be done with another js
|
|
2938 |
* file similar to media-upload.js. That file should
|
|
2939 |
* require array('thickbox') to ensure it is loaded after.
|
|
2940 |
*
|
|
2941 |
* @since 2.5.0
|
|
2942 |
*/
|
|
2943 |
function add_thickbox() {
|
|
2944 |
wp_enqueue_script( 'thickbox' );
|
|
2945 |
wp_enqueue_style( 'thickbox' );
|
|
2946 |
|
|
2947 |
if ( is_network_admin() )
|
|
2948 |
add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
|
|
2949 |
}
|
|
2950 |
|
|
2951 |
/**
|
|
2952 |
* Display the XHTML generator that is generated on the wp_head hook.
|
|
2953 |
*
|
|
2954 |
* @since 2.5.0
|
|
2955 |
*/
|
|
2956 |
function wp_generator() {
|
5
|
2957 |
/**
|
|
2958 |
* Filter the output of the XHTML generator tag.
|
|
2959 |
*
|
|
2960 |
* @since 2.5.0
|
|
2961 |
*
|
|
2962 |
* @param string $generator_type The XHTML generator.
|
|
2963 |
*/
|
0
|
2964 |
the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
|
|
2965 |
}
|
|
2966 |
|
|
2967 |
/**
|
|
2968 |
* Display the generator XML or Comment for RSS, ATOM, etc.
|
|
2969 |
*
|
|
2970 |
* Returns the correct generator type for the requested output format. Allows
|
|
2971 |
* for a plugin to filter generators overall the the_generator filter.
|
|
2972 |
*
|
|
2973 |
* @since 2.5.0
|
|
2974 |
*
|
|
2975 |
* @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
|
|
2976 |
*/
|
|
2977 |
function the_generator( $type ) {
|
5
|
2978 |
/**
|
|
2979 |
* Filter the output of the XHTML generator tag for display.
|
|
2980 |
*
|
|
2981 |
* @since 2.5.0
|
|
2982 |
*
|
|
2983 |
* @param string $generator_type The generator output.
|
|
2984 |
* @param string $type The type of generator to output. Accepts 'html',
|
|
2985 |
* 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'.
|
|
2986 |
*/
|
|
2987 |
echo apply_filters( 'the_generator', get_the_generator($type), $type ) . "\n";
|
0
|
2988 |
}
|
|
2989 |
|
|
2990 |
/**
|
|
2991 |
* Creates the generator XML or Comment for RSS, ATOM, etc.
|
|
2992 |
*
|
|
2993 |
* Returns the correct generator type for the requested output format. Allows
|
|
2994 |
* for a plugin to filter generators on an individual basis using the
|
|
2995 |
* 'get_the_generator_{$type}' filter.
|
|
2996 |
*
|
|
2997 |
* @since 2.5.0
|
|
2998 |
*
|
|
2999 |
* @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
|
|
3000 |
* @return string The HTML content for the generator.
|
|
3001 |
*/
|
|
3002 |
function get_the_generator( $type = '' ) {
|
|
3003 |
if ( empty( $type ) ) {
|
|
3004 |
|
|
3005 |
$current_filter = current_filter();
|
|
3006 |
if ( empty( $current_filter ) )
|
|
3007 |
return;
|
|
3008 |
|
|
3009 |
switch ( $current_filter ) {
|
|
3010 |
case 'rss2_head' :
|
|
3011 |
case 'commentsrss2_head' :
|
|
3012 |
$type = 'rss2';
|
|
3013 |
break;
|
|
3014 |
case 'rss_head' :
|
|
3015 |
case 'opml_head' :
|
|
3016 |
$type = 'comment';
|
|
3017 |
break;
|
|
3018 |
case 'rdf_header' :
|
|
3019 |
$type = 'rdf';
|
|
3020 |
break;
|
|
3021 |
case 'atom_head' :
|
|
3022 |
case 'comments_atom_head' :
|
|
3023 |
case 'app_head' :
|
|
3024 |
$type = 'atom';
|
|
3025 |
break;
|
|
3026 |
}
|
|
3027 |
}
|
|
3028 |
|
|
3029 |
switch ( $type ) {
|
|
3030 |
case 'html':
|
|
3031 |
$gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
|
|
3032 |
break;
|
|
3033 |
case 'xhtml':
|
|
3034 |
$gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
|
|
3035 |
break;
|
|
3036 |
case 'atom':
|
|
3037 |
$gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
|
|
3038 |
break;
|
|
3039 |
case 'rss2':
|
|
3040 |
$gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
|
|
3041 |
break;
|
|
3042 |
case 'rdf':
|
|
3043 |
$gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
|
|
3044 |
break;
|
|
3045 |
case 'comment':
|
|
3046 |
$gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
|
|
3047 |
break;
|
|
3048 |
case 'export':
|
|
3049 |
$gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '" -->';
|
|
3050 |
break;
|
|
3051 |
}
|
5
|
3052 |
|
|
3053 |
/**
|
|
3054 |
* Filter the HTML for the retrieved generator type.
|
|
3055 |
*
|
|
3056 |
* The dynamic portion of the hook name, `$type`, refers to the generator type.
|
|
3057 |
*
|
|
3058 |
* @since 2.5.0
|
|
3059 |
*
|
|
3060 |
* @param string $gen The HTML markup output to {@see wp_head()}.
|
|
3061 |
* @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom',
|
|
3062 |
* 'rss2', 'rdf', 'comment', 'export'.
|
|
3063 |
*/
|
0
|
3064 |
return apply_filters( "get_the_generator_{$type}", $gen, $type );
|
|
3065 |
}
|
|
3066 |
|
|
3067 |
/**
|
|
3068 |
* Outputs the html checked attribute.
|
|
3069 |
*
|
|
3070 |
* Compares the first two arguments and if identical marks as checked
|
|
3071 |
*
|
|
3072 |
* @since 1.0.0
|
|
3073 |
*
|
|
3074 |
* @param mixed $checked One of the values to compare
|
|
3075 |
* @param mixed $current (true) The other value to compare if not just true
|
|
3076 |
* @param bool $echo Whether to echo or just return the string
|
|
3077 |
* @return string html attribute or empty string
|
|
3078 |
*/
|
|
3079 |
function checked( $checked, $current = true, $echo = true ) {
|
|
3080 |
return __checked_selected_helper( $checked, $current, $echo, 'checked' );
|
|
3081 |
}
|
|
3082 |
|
|
3083 |
/**
|
|
3084 |
* Outputs the html selected attribute.
|
|
3085 |
*
|
|
3086 |
* Compares the first two arguments and if identical marks as selected
|
|
3087 |
*
|
|
3088 |
* @since 1.0.0
|
|
3089 |
*
|
|
3090 |
* @param mixed $selected One of the values to compare
|
|
3091 |
* @param mixed $current (true) The other value to compare if not just true
|
|
3092 |
* @param bool $echo Whether to echo or just return the string
|
|
3093 |
* @return string html attribute or empty string
|
|
3094 |
*/
|
|
3095 |
function selected( $selected, $current = true, $echo = true ) {
|
|
3096 |
return __checked_selected_helper( $selected, $current, $echo, 'selected' );
|
|
3097 |
}
|
|
3098 |
|
|
3099 |
/**
|
|
3100 |
* Outputs the html disabled attribute.
|
|
3101 |
*
|
|
3102 |
* Compares the first two arguments and if identical marks as disabled
|
|
3103 |
*
|
|
3104 |
* @since 3.0.0
|
|
3105 |
*
|
|
3106 |
* @param mixed $disabled One of the values to compare
|
|
3107 |
* @param mixed $current (true) The other value to compare if not just true
|
|
3108 |
* @param bool $echo Whether to echo or just return the string
|
|
3109 |
* @return string html attribute or empty string
|
|
3110 |
*/
|
|
3111 |
function disabled( $disabled, $current = true, $echo = true ) {
|
|
3112 |
return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
|
|
3113 |
}
|
|
3114 |
|
|
3115 |
/**
|
|
3116 |
* Private helper function for checked, selected, and disabled.
|
|
3117 |
*
|
|
3118 |
* Compares the first two arguments and if identical marks as $type
|
|
3119 |
*
|
|
3120 |
* @since 2.8.0
|
|
3121 |
* @access private
|
|
3122 |
*
|
|
3123 |
* @param mixed $helper One of the values to compare
|
|
3124 |
* @param mixed $current (true) The other value to compare if not just true
|
|
3125 |
* @param bool $echo Whether to echo or just return the string
|
|
3126 |
* @param string $type The type of checked|selected|disabled we are doing
|
|
3127 |
* @return string html attribute or empty string
|
|
3128 |
*/
|
|
3129 |
function __checked_selected_helper( $helper, $current, $echo, $type ) {
|
|
3130 |
if ( (string) $helper === (string) $current )
|
|
3131 |
$result = " $type='$type'";
|
|
3132 |
else
|
|
3133 |
$result = '';
|
|
3134 |
|
|
3135 |
if ( $echo )
|
|
3136 |
echo $result;
|
|
3137 |
|
|
3138 |
return $result;
|
|
3139 |
}
|
|
3140 |
|
|
3141 |
/**
|
|
3142 |
* Default settings for heartbeat
|
|
3143 |
*
|
|
3144 |
* Outputs the nonce used in the heartbeat XHR
|
|
3145 |
*
|
|
3146 |
* @since 3.6.0
|
|
3147 |
*
|
|
3148 |
* @param array $settings
|
|
3149 |
* @return array $settings
|
|
3150 |
*/
|
|
3151 |
function wp_heartbeat_settings( $settings ) {
|
|
3152 |
if ( ! is_admin() )
|
|
3153 |
$settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' );
|
|
3154 |
|
|
3155 |
if ( is_user_logged_in() )
|
|
3156 |
$settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
|
|
3157 |
|
|
3158 |
return $settings;
|
|
3159 |
}
|