Issues (2010)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

wp-includes/general-template.php (24 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

Code
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 View Code Duplication
function get_header( $name = null ) {
0 ignored issues
show
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
	 */
35
	do_action( 'get_header', $name );
36
37
	$templates = array();
38
	$name = (string) $name;
39
	if ( '' !== $name ) {
40
		$templates[] = "header-{$name}.php";
41
	}
42
43
	$templates[] = 'header.php';
44
45
	locate_template( $templates, true );
46
}
47
48
/**
49
 * Load footer template.
50
 *
51
 * Includes the footer template for a theme or if a name is specified then a
52
 * specialised footer will be included.
53
 *
54
 * For the parameter, if the file is called "footer-special.php" then specify
55
 * "special".
56
 *
57
 * @since 1.5.0
58
 *
59
 * @param string $name The name of the specialised footer.
60
 */
61 View Code Duplication
function get_footer( $name = null ) {
0 ignored issues
show
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
	/**
63
	 * Fires before the footer template file is loaded.
64
	 *
65
	 * The hook allows a specific footer template file to be used in place of the
66
	 * default footer template file. If your file is called footer-new.php,
67
	 * you would specify the filename in the hook as get_footer( 'new' ).
68
	 *
69
	 * @since 2.1.0
70
	 * @since 2.8.0 $name parameter added.
71
	 *
72
	 * @param string $name Name of the specific footer file to use.
73
	 */
74
	do_action( 'get_footer', $name );
75
76
	$templates = array();
77
	$name = (string) $name;
78
	if ( '' !== $name ) {
79
		$templates[] = "footer-{$name}.php";
80
	}
81
82
	$templates[]    = 'footer.php';
83
84
	locate_template( $templates, true );
85
}
86
87
/**
88
 * Load sidebar template.
89
 *
90
 * Includes the sidebar template for a theme or if a name is specified then a
91
 * specialised sidebar will be included.
92
 *
93
 * For the parameter, if the file is called "sidebar-special.php" then specify
94
 * "special".
95
 *
96
 * @since 1.5.0
97
 *
98
 * @param string $name The name of the specialised sidebar.
99
 */
100 View Code Duplication
function get_sidebar( $name = null ) {
0 ignored issues
show
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
	/**
102
	 * Fires before the sidebar template file is loaded.
103
	 *
104
	 * The hook allows a specific sidebar template file to be used in place of the
105
	 * default sidebar template file. If your file is called sidebar-new.php,
106
	 * you would specify the filename in the hook as get_sidebar( 'new' ).
107
	 *
108
	 * @since 2.2.0
109
	 * @since 2.8.0 $name parameter added.
110
	 *
111
	 * @param string $name Name of the specific sidebar file to use.
112
	 */
113
	do_action( 'get_sidebar', $name );
114
115
	$templates = array();
116
	$name = (string) $name;
117
	if ( '' !== $name )
118
		$templates[] = "sidebar-{$name}.php";
119
120
	$templates[] = 'sidebar.php';
121
122
	locate_template( $templates, true );
123
}
124
125
/**
126
 * Load a template part into a template
127
 *
128
 * Makes it easy for a theme to reuse sections of code in a easy to overload way
129
 * for child themes.
130
 *
131
 * Includes the named template part for a theme or if a name is specified then a
132
 * specialised part will be included. If the theme contains no {slug}.php file
133
 * then no template will be included.
134
 *
135
 * The template is included using require, not require_once, so you may include the
136
 * same template part multiple times.
137
 *
138
 * For the $name parameter, if the file is called "{slug}-special.php" then specify
139
 * "special".
140
 *
141
 * @since 3.0.0
142
 *
143
 * @param string $slug The slug name for the generic template.
144
 * @param string $name The name of the specialised template.
145
 */
146
function get_template_part( $slug, $name = null ) {
147
	/**
148
	 * Fires before the specified template part file is loaded.
149
	 *
150
	 * The dynamic portion of the hook name, `$slug`, refers to the slug name
151
	 * for the generic template part.
152
	 *
153
	 * @since 3.0.0
154
	 *
155
	 * @param string $slug The slug name for the generic template.
156
	 * @param string $name The name of the specialized template.
157
	 */
158
	do_action( "get_template_part_{$slug}", $slug, $name );
159
160
	$templates = array();
161
	$name = (string) $name;
162
	if ( '' !== $name )
163
		$templates[] = "{$slug}-{$name}.php";
164
165
	$templates[] = "{$slug}.php";
166
167
	locate_template($templates, true, false);
168
}
169
170
/**
171
 * Display search form.
172
 *
173
 * Will first attempt to locate the searchform.php file in either the child or
174
 * the parent, then load it. If it doesn't exist, then the default search form
175
 * will be displayed. The default search form is HTML, which will be displayed.
176
 * There is a filter applied to the search form HTML in order to edit or replace
177
 * it. The filter is {@see 'get_search_form'}.
178
 *
179
 * This function is primarily used by themes which want to hardcode the search
180
 * form into the sidebar and also by the search widget in WordPress.
181
 *
182
 * There is also an action that is called whenever the function is run called,
183
 * {@see 'pre_get_search_form'}. This can be useful for outputting JavaScript that the
184
 * search relies on or various formatting that applies to the beginning of the
185
 * search. To give a few examples of what it can be used for.
186
 *
187
 * @since 2.7.0
188
 *
189
 * @param bool $echo Default to echo and not return the form.
190
 * @return string|void String when $echo is false.
191
 */
192
function get_search_form( $echo = true ) {
193
	/**
194
	 * Fires before the search form is retrieved, at the start of get_search_form().
195
	 *
196
	 * @since 2.7.0 as 'get_search_form' action.
197
	 * @since 3.6.0
198
	 *
199
	 * @link https://core.trac.wordpress.org/ticket/19321
200
	 */
201
	do_action( 'pre_get_search_form' );
202
203
	$format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
204
205
	/**
206
	 * Filters the HTML format of the search form.
207
	 *
208
	 * @since 3.6.0
209
	 *
210
	 * @param string $format The type of markup to use in the search form.
211
	 *                       Accepts 'html5', 'xhtml'.
212
	 */
213
	$format = apply_filters( 'search_form_format', $format );
214
215
	$search_form_template = locate_template( 'searchform.php' );
216
	if ( '' != $search_form_template ) {
217
		ob_start();
218
		require( $search_form_template );
219
		$form = ob_get_clean();
220
	} else {
221
		if ( 'html5' == $format ) {
222
			$form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
223
				<label>
224
					<span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
225
					<input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search &hellip;', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" />
226
				</label>
227
				<input type="submit" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
228
			</form>';
229
		} else {
230
			$form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
231
				<div>
232
					<label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
233
					<input type="text" value="' . get_search_query() . '" name="s" id="s" />
234
					<input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
235
				</div>
236
			</form>';
237
		}
238
	}
239
240
	/**
241
	 * Filters the HTML output of the search form.
242
	 *
243
	 * @since 2.7.0
244
	 *
245
	 * @param string $form The search form HTML output.
246
	 */
247
	$result = apply_filters( 'get_search_form', $form );
248
249
	if ( null === $result )
250
		$result = $form;
251
252
	if ( $echo )
253
		echo $result;
254
	else
255
		return $result;
256
}
257
258
/**
259
 * Display the Log In/Out link.
260
 *
261
 * Displays a link, which allows users to navigate to the Log In page to log in
262
 * or log out depending on whether they are currently logged in.
263
 *
264
 * @since 1.5.0
265
 *
266
 * @param string $redirect Optional path to redirect to on login/logout.
267
 * @param bool   $echo     Default to echo and not return the link.
268
 * @return string|void String when retrieving.
269
 */
270
function wp_loginout($redirect = '', $echo = true) {
271
	if ( ! is_user_logged_in() )
272
		$link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
273
	else
274
		$link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
275
276
	if ( $echo ) {
277
		/**
278
		 * Filters the HTML output for the Log In/Log Out link.
279
		 *
280
		 * @since 1.5.0
281
		 *
282
		 * @param string $link The HTML link content.
283
		 */
284
		echo apply_filters( 'loginout', $link );
285
	} else {
286
		/** This filter is documented in wp-includes/general-template.php */
287
		return apply_filters( 'loginout', $link );
288
	}
289
}
290
291
/**
292
 * Retrieves the logout URL.
293
 *
294
 * Returns the URL that allows the user to log out of the site.
295
 *
296
 * @since 2.7.0
297
 *
298
 * @param string $redirect Path to redirect to on logout.
299
 * @return string The logout URL. Note: HTML-encoded via esc_html() in wp_nonce_url().
300
 */
301 View Code Duplication
function wp_logout_url($redirect = '') {
0 ignored issues
show
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
302
	$args = array( 'action' => 'logout' );
303
	if ( !empty($redirect) ) {
304
		$args['redirect_to'] = urlencode( $redirect );
305
	}
306
307
	$logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
308
	$logout_url = wp_nonce_url( $logout_url, 'log-out' );
309
310
	/**
311
	 * Filters the logout URL.
312
	 *
313
	 * @since 2.8.0
314
	 *
315
	 * @param string $logout_url The HTML-encoded logout URL.
316
	 * @param string $redirect   Path to redirect to on logout.
317
	 */
318
	return apply_filters( 'logout_url', $logout_url, $redirect );
319
}
320
321
/**
322
 * Retrieves the login URL.
323
 *
324
 * @since 2.7.0
325
 *
326
 * @param string $redirect     Path to redirect to on log in.
327
 * @param bool   $force_reauth Whether to force reauthorization, even if a cookie is present.
328
 *                             Default false.
329
 * @return string The login URL. Not HTML-encoded.
330
 */
331 View Code Duplication
function wp_login_url($redirect = '', $force_reauth = false) {
0 ignored issues
show
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
332
	$login_url = site_url('wp-login.php', 'login');
333
334
	if ( !empty($redirect) )
335
		$login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
336
337
	if ( $force_reauth )
338
		$login_url = add_query_arg('reauth', '1', $login_url);
339
340
	/**
341
	 * Filters the login URL.
342
	 *
343
	 * @since 2.8.0
344
	 * @since 4.2.0 The `$force_reauth` parameter was added.
345
	 *
346
	 * @param string $login_url    The login URL. Not HTML-encoded.
347
	 * @param string $redirect     The path to redirect to on login, if supplied.
348
	 * @param bool   $force_reauth Whether to force reauthorization, even if a cookie is present.
349
	 */
350
	return apply_filters( 'login_url', $login_url, $redirect, $force_reauth );
351
}
352
353
/**
354
 * Returns the URL that allows the user to register on the site.
355
 *
356
 * @since 3.6.0
357
 *
358
 * @return string User registration URL.
359
 */
360
function wp_registration_url() {
361
	/**
362
	 * Filters the user registration URL.
363
	 *
364
	 * @since 3.6.0
365
	 *
366
	 * @param string $register The user registration URL.
367
	 */
368
	return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
369
}
370
371
/**
372
 * Provides a simple login form for use anywhere within WordPress.
373
 *
374
 * The login format HTML is echoed by default. Pass a false value for `$echo` to return it instead.
375
 *
376
 * @since 3.0.0
377
 *
378
 * @param array $args {
379
 *     Optional. Array of options to control the form output. Default empty array.
380
 *
381
 *     @type bool   $echo           Whether to display the login form or return the form HTML code.
382
 *                                  Default true (echo).
383
 *     @type string $redirect       URL to redirect to. Must be absolute, as in "https://example.com/mypage/".
384
 *                                  Default is to redirect back to the request URI.
385
 *     @type string $form_id        ID attribute value for the form. Default 'loginform'.
386
 *     @type string $label_username Label for the username or email address field. Default 'Username or Email'.
387
 *     @type string $label_password Label for the password field. Default 'Password'.
388
 *     @type string $label_remember Label for the remember field. Default 'Remember Me'.
389
 *     @type string $label_log_in   Label for the submit button. Default 'Log In'.
390
 *     @type string $id_username    ID attribute value for the username field. Default 'user_login'.
391
 *     @type string $id_password    ID attribute value for the password field. Default 'user_pass'.
392
 *     @type string $id_remember    ID attribute value for the remember field. Default 'rememberme'.
393
 *     @type string $id_submit      ID attribute value for the submit button. Default 'wp-submit'.
394
 *     @type bool   $remember       Whether to display the "rememberme" checkbox in the form.
395
 *     @type string $value_username Default value for the username field. Default empty.
396
 *     @type bool   $value_remember Whether the "Remember Me" checkbox should be checked by default.
397
 *                                  Default false (unchecked).
398
 *
399
 * }
400
 * @return string|void String when retrieving.
401
 */
402
function wp_login_form( $args = array() ) {
403
	$defaults = array(
404
		'echo' => true,
405
		// Default 'redirect' value takes the user back to the request URI.
406
		'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
407
		'form_id' => 'loginform',
408
		'label_username' => __( 'Username or Email' ),
409
		'label_password' => __( 'Password' ),
410
		'label_remember' => __( 'Remember Me' ),
411
		'label_log_in' => __( 'Log In' ),
412
		'id_username' => 'user_login',
413
		'id_password' => 'user_pass',
414
		'id_remember' => 'rememberme',
415
		'id_submit' => 'wp-submit',
416
		'remember' => true,
417
		'value_username' => '',
418
		// Set 'value_remember' to true to default the "Remember me" checkbox to checked.
419
		'value_remember' => false,
420
	);
421
422
	/**
423
	 * Filters the default login form output arguments.
424
	 *
425
	 * @since 3.0.0
426
	 *
427
	 * @see wp_login_form()
428
	 *
429
	 * @param array $defaults An array of default login form arguments.
430
	 */
431
	$args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
432
433
	/**
434
	 * Filters content to display at the top of the login form.
435
	 *
436
	 * The filter evaluates just following the opening form tag element.
437
	 *
438
	 * @since 3.0.0
439
	 *
440
	 * @param string $content Content to display. Default empty.
441
	 * @param array  $args    Array of login form arguments.
442
	 */
443
	$login_form_top = apply_filters( 'login_form_top', '', $args );
444
445
	/**
446
	 * Filters content to display in the middle of the login form.
447
	 *
448
	 * The filter evaluates just following the location where the 'login-password'
449
	 * field is displayed.
450
	 *
451
	 * @since 3.0.0
452
	 *
453
	 * @param string $content Content to display. Default empty.
454
	 * @param array  $args    Array of login form arguments.
455
	 */
456
	$login_form_middle = apply_filters( 'login_form_middle', '', $args );
457
458
	/**
459
	 * Filters content to display at the bottom of the login form.
460
	 *
461
	 * The filter evaluates just preceding the closing form tag element.
462
	 *
463
	 * @since 3.0.0
464
	 *
465
	 * @param string $content Content to display. Default empty.
466
	 * @param array  $args    Array of login form arguments.
467
	 */
468
	$login_form_bottom = apply_filters( 'login_form_bottom', '', $args );
469
470
	$form = '
471
		<form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post">
472
			' . $login_form_top . '
473
			<p class="login-username">
474
				<label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
475
				<input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" />
476
			</p>
477
			<p class="login-password">
478
				<label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label>
479
				<input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" />
480
			</p>
481
			' . $login_form_middle . '
482
			' . ( $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>' : '' ) . '
483
			<p class="login-submit">
484
				<input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" />
485
				<input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" />
486
			</p>
487
			' . $login_form_bottom . '
488
		</form>';
489
490
	if ( $args['echo'] )
491
		echo $form;
492
	else
493
		return $form;
494
}
495
496
/**
497
 * Returns the URL that allows the user to retrieve the lost password
498
 *
499
 * @since 2.8.0
500
 *
501
 * @param string $redirect Path to redirect to on login.
502
 * @return string Lost password URL.
503
 */
504
function wp_lostpassword_url( $redirect = '' ) {
505
	$args = array( 'action' => 'lostpassword' );
506
	if ( !empty($redirect) ) {
507
		$args['redirect_to'] = $redirect;
508
	}
509
510
	$lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') );
511
512
	/**
513
	 * Filters the Lost Password URL.
514
	 *
515
	 * @since 2.8.0
516
	 *
517
	 * @param string $lostpassword_url The lost password page URL.
518
	 * @param string $redirect         The path to redirect to on login.
519
	 */
520
	return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
521
}
522
523
/**
524
 * Display the Registration or Admin link.
525
 *
526
 * Display a link which allows the user to navigate to the registration page if
527
 * not logged in and registration is enabled or to the dashboard if logged in.
528
 *
529
 * @since 1.5.0
530
 *
531
 * @param string $before Text to output before the link. Default `<li>`.
532
 * @param string $after  Text to output after the link. Default `</li>`.
533
 * @param bool   $echo   Default to echo and not return the link.
534
 * @return string|void String when retrieving.
535
 */
536
function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
537
	if ( ! is_user_logged_in() ) {
538
		if ( get_option('users_can_register') )
539
			$link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register') . '</a>' . $after;
540
		else
541
			$link = '';
542
	} elseif ( current_user_can( 'read' ) ) {
543
		$link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
544
	} else {
545
		$link = '';
546
	}
547
548
	/**
549
	 * Filters the HTML link to the Registration or Admin page.
550
	 *
551
	 * Users are sent to the admin page if logged-in, or the registration page
552
	 * if enabled and logged-out.
553
	 *
554
	 * @since 1.5.0
555
	 *
556
	 * @param string $link The HTML code for the link to the Registration or Admin page.
557
	 */
558
	$link = apply_filters( 'register', $link );
559
560
	if ( $echo ) {
561
		echo $link;
562
	} else {
563
		return $link;
564
	}
565
}
566
567
/**
568
 * Theme container function for the 'wp_meta' action.
569
 *
570
 * The {@see 'wp_meta'} action can have several purposes, depending on how you use it,
571
 * but one purpose might have been to allow for theme switching.
572
 *
573
 * @since 1.5.0
574
 *
575
 * @link https://core.trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
576
 */
577
function wp_meta() {
578
	/**
579
	 * Fires before displaying echoed content in the sidebar.
580
	 *
581
	 * @since 1.5.0
582
	 */
583
	do_action( 'wp_meta' );
584
}
585
586
/**
587
 * Displays information about the current site.
588
 *
589
 * @since 0.71
590
 *
591
 * @see get_bloginfo() For possible `$show` values
592
 *
593
 * @param string $show Optional. Site information to display. Default empty.
594
 */
595
function bloginfo( $show = '' ) {
596
	echo get_bloginfo( $show, 'display' );
597
}
598
599
/**
600
 * Retrieves information about the current site.
601
 *
602
 * Possible values for `$show` include:
603
 *
604
 * - 'name' - Site title (set in Settings > General)
605
 * - 'description' - Site tagline (set in Settings > General)
606
 * - 'wpurl' - The WordPress address (URL) (set in Settings > General)
607
 * - 'url' - The Site address (URL) (set in Settings > General)
608
 * - 'admin_email' - Admin email (set in Settings > General)
609
 * - 'charset' - The "Encoding for pages and feeds"  (set in Settings > Reading)
610
 * - 'version' - The current WordPress version
611
 * - 'html_type' - The content-type (default: "text/html"). Themes and plugins
612
 *   can override the default value using the {@see 'pre_option_html_type'} filter
613
 * - 'text_direction' - The text direction determined by the site's language. is_rtl()
614
 *   should be used instead
615
 * - 'language' - Language code for the current site
616
 * - 'stylesheet_url' - URL to the stylesheet for the active theme. An active child theme
617
 *   will take precedence over this value
618
 * - 'stylesheet_directory' - Directory path for the active theme.  An active child theme
619
 *   will take precedence over this value
620
 * - 'template_url' / 'template_directory' - URL of the active theme's directory. An active
621
 *   child theme will NOT take precedence over this value
622
 * - 'pingback_url' - The pingback XML-RPC file URL (xmlrpc.php)
623
 * - 'atom_url' - The Atom feed URL (/feed/atom)
624
 * - 'rdf_url' - The RDF/RSS 1.0 feed URL (/feed/rfd)
625
 * - 'rss_url' - The RSS 0.92 feed URL (/feed/rss)
626
 * - 'rss2_url' - The RSS 2.0 feed URL (/feed)
627
 * - 'comments_atom_url' - The comments Atom feed URL (/comments/feed)
628
 * - 'comments_rss2_url' - The comments RSS 2.0 feed URL (/comments/feed)
629
 *
630
 * Some `$show` values are deprecated and will be removed in future versions.
631
 * These options will trigger the _deprecated_argument() function.
632
 *
633
 * Deprecated arguments include:
634
 *
635
 * - 'siteurl' - Use 'url' instead
636
 * - 'home' - Use 'url' instead
637
 *
638
 * @since 0.71
639
 *
640
 * @global string $wp_version
641
 *
642
 * @param string $show   Optional. Site info to retrieve. Default empty (site name).
643
 * @param string $filter Optional. How to filter what is retrieved. Default 'raw'.
644
 * @return string Mostly string values, might be empty.
645
 */
646
function get_bloginfo( $show = '', $filter = 'raw' ) {
647
	switch( $show ) {
648
		case 'home' : // DEPRECATED
649
		case 'siteurl' : // DEPRECATED
650
			_deprecated_argument( __FUNCTION__, '2.2.0', sprintf(
651
				/* translators: 1: 'siteurl'/'home' argument, 2: bloginfo() function name, 3: 'url' argument */
652
				__( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s option instead.' ),
653
				'<code>' . $show . '</code>',
654
				'<code>bloginfo()</code>',
655
				'<code>url</code>'
656
			) );
657
		case 'url' :
658
			$output = home_url();
659
			break;
660
		case 'wpurl' :
661
			$output = site_url();
662
			break;
663
		case 'description':
664
			$output = get_option('blogdescription');
665
			break;
666
		case 'rdf_url':
667
			$output = get_feed_link('rdf');
668
			break;
669
		case 'rss_url':
670
			$output = get_feed_link('rss');
671
			break;
672
		case 'rss2_url':
673
			$output = get_feed_link('rss2');
674
			break;
675
		case 'atom_url':
676
			$output = get_feed_link('atom');
677
			break;
678
		case 'comments_atom_url':
679
			$output = get_feed_link('comments_atom');
680
			break;
681
		case 'comments_rss2_url':
682
			$output = get_feed_link('comments_rss2');
683
			break;
684
		case 'pingback_url':
685
			$output = site_url( 'xmlrpc.php' );
686
			break;
687
		case 'stylesheet_url':
688
			$output = get_stylesheet_uri();
689
			break;
690
		case 'stylesheet_directory':
691
			$output = get_stylesheet_directory_uri();
692
			break;
693
		case 'template_directory':
694
		case 'template_url':
695
			$output = get_template_directory_uri();
696
			break;
697
		case 'admin_email':
698
			$output = get_option('admin_email');
699
			break;
700
		case 'charset':
701
			$output = get_option('blog_charset');
702
			if ('' == $output) $output = 'UTF-8';
703
			break;
704
		case 'html_type' :
705
			$output = get_option('html_type');
706
			break;
707
		case 'version':
708
			global $wp_version;
709
			$output = $wp_version;
710
			break;
711
		case 'language':
712
			/* translators: Translate this to the correct language tag for your locale,
713
			 * see https://www.w3.org/International/articles/language-tags/ for reference.
714
			 * Do not translate into your own language.
715
			 */
716
			$output = __( 'html_lang_attribute' );
717
			if ( 'html_lang_attribute' === $output || preg_match( '/[^a-zA-Z0-9-]/', $output ) ) {
718
				$output = get_locale();
719
				$output = str_replace( '_', '-', $output );
720
			}
721
			break;
722
		case 'text_direction':
723
			_deprecated_argument( __FUNCTION__, '2.2.0', sprintf(
724
				/* translators: 1: 'text_direction' argument, 2: bloginfo() function name, 3: is_rtl() function name */
725
				__( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s function instead.' ),
726
				'<code>' . $show . '</code>',
727
				'<code>bloginfo()</code>',
728
				'<code>is_rtl()</code>'
729
			) );
730
			if ( function_exists( 'is_rtl' ) ) {
731
				$output = is_rtl() ? 'rtl' : 'ltr';
732
			} else {
733
				$output = 'ltr';
734
			}
735
			break;
736
		case 'name':
737
		default:
738
			$output = get_option('blogname');
739
			break;
740
	}
741
742
	$url = true;
743
	if (strpos($show, 'url') === false &&
744
		strpos($show, 'directory') === false &&
745
		strpos($show, 'home') === false)
746
		$url = false;
747
748
	if ( 'display' == $filter ) {
749
		if ( $url ) {
750
			/**
751
			 * Filters the URL returned by get_bloginfo().
752
			 *
753
			 * @since 2.0.5
754
			 *
755
			 * @param mixed $output The URL returned by bloginfo().
756
			 * @param mixed $show   Type of information requested.
757
			 */
758
			$output = apply_filters( 'bloginfo_url', $output, $show );
759
		} else {
760
			/**
761
			 * Filters the site information returned by get_bloginfo().
762
			 *
763
			 * @since 0.71
764
			 *
765
			 * @param mixed $output The requested non-URL site information.
766
			 * @param mixed $show   Type of information requested.
767
			 */
768
			$output = apply_filters( 'bloginfo', $output, $show );
769
		}
770
	}
771
772
	return $output;
773
}
774
775
/**
776
 * Returns the Site Icon URL.
777
 *
778
 * @since 4.3.0
779
 *
780
 * @param int    $size    Optional. Size of the site icon. Default 512 (pixels).
781
 * @param string $url     Optional. Fallback url if no site icon is found. Default empty.
782
 * @param int    $blog_id Optional. ID of the blog to get the site icon for. Default current blog.
783
 * @return string Site Icon URL.
784
 */
785
function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
786
	if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) {
787
		switch_to_blog( $blog_id );
788
	}
789
790
	$site_icon_id = get_option( 'site_icon' );
791
792
	if ( $site_icon_id ) {
793
		if ( $size >= 512 ) {
794
			$size_data = 'full';
795
		} else {
796
			$size_data = array( $size, $size );
797
		}
798
		$url = wp_get_attachment_image_url( $site_icon_id, $size_data );
799
	}
800
801
	if ( is_multisite() && ms_is_switched() ) {
802
		restore_current_blog();
803
	}
804
805
	/**
806
	 * Filters the site icon URL.
807
	 *
808
	 * @site 4.4.0
809
	 *
810
	 * @param string $url     Site icon URL.
811
	 * @param int    $size    Size of the site icon.
812
	 * @param int    $blog_id ID of the blog to get the site icon for.
813
	 */
814
	return apply_filters( 'get_site_icon_url', $url, $size, $blog_id );
815
}
816
817
/**
818
 * Displays the Site Icon URL.
819
 *
820
 * @since 4.3.0
821
 *
822
 * @param int    $size    Optional. Size of the site icon. Default 512 (pixels).
823
 * @param string $url     Optional. Fallback url if no site icon is found. Default empty.
824
 * @param int    $blog_id Optional. ID of the blog to get the site icon for. Default current blog.
825
 */
826
function site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
827
	echo esc_url( get_site_icon_url( $size, $url, $blog_id ) );
828
}
829
830
/**
831
 * Whether the site has a Site Icon.
832
 *
833
 * @since 4.3.0
834
 *
835
 * @param int $blog_id Optional. ID of the blog in question. Default current blog.
836
 * @return bool Whether the site has a site icon or not.
837
 */
838
function has_site_icon( $blog_id = 0 ) {
839
	return (bool) get_site_icon_url( 512, '', $blog_id );
840
}
841
842
/**
843
 * Determines whether the site has a custom logo.
844
 *
845
 * @since 4.5.0
846
 *
847
 * @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog.
848
 * @return bool Whether the site has a custom logo or not.
849
 */
850
function has_custom_logo( $blog_id = 0 ) {
851
	if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) {
852
		switch_to_blog( $blog_id );
853
	}
854
855
	$custom_logo_id = get_theme_mod( 'custom_logo' );
856
857
	if ( is_multisite() && ms_is_switched() ) {
858
		restore_current_blog();
859
	}
860
861
	return (bool) $custom_logo_id;
862
}
863
864
/**
865
 * Returns a custom logo, linked to home.
866
 *
867
 * @since 4.5.0
868
 *
869
 * @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog.
870
 * @return string Custom logo markup.
871
 */
872
function get_custom_logo( $blog_id = 0 ) {
873
	$html = '';
874
875
	if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) {
876
		switch_to_blog( $blog_id );
877
	}
878
879
	$custom_logo_id = get_theme_mod( 'custom_logo' );
880
881
	// We have a logo. Logo is go.
882
	if ( $custom_logo_id ) {
883
		$html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>',
884
			esc_url( home_url( '/' ) ),
885
			wp_get_attachment_image( $custom_logo_id, 'full', false, array(
886
				'class'    => 'custom-logo',
887
				'itemprop' => 'logo',
888
			) )
889
		);
890
	}
891
892
	// If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview).
893
	elseif ( is_customize_preview() ) {
894
		$html = sprintf( '<a href="%1$s" class="custom-logo-link" style="display:none;"><img class="custom-logo"/></a>',
895
			esc_url( home_url( '/' ) )
896
		);
897
	}
898
899
	if ( is_multisite() && ms_is_switched() ) {
900
		restore_current_blog();
901
	}
902
903
	/**
904
	 * Filters the custom logo output.
905
	 *
906
	 * @since 4.5.0
907
	 * @since 4.6.0 Added the `$blog_id` parameter.
908
	 *
909
	 * @param string $html    Custom logo HTML output.
910
	 * @param int    $blog_id ID of the blog to get the custom logo for.
911
	 */
912
	return apply_filters( 'get_custom_logo', $html, $blog_id );
913
}
914
915
/**
916
 * Displays a custom logo, linked to home.
917
 *
918
 * @since 4.5.0
919
 *
920
 * @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog.
921
 */
922
function the_custom_logo( $blog_id = 0 ) {
923
	echo get_custom_logo( $blog_id );
924
}
925
926
/**
927
 * Returns document title for the current page.
928
 *
929
 * @since 4.4.0
930
 *
931
 * @global int $page  Page number of a single post.
932
 * @global int $paged Page number of a list of posts.
933
 *
934
 * @return string Tag with the document title.
935
 */
936
function wp_get_document_title() {
937
938
	/**
939
	 * Filters the document title before it is generated.
940
	 *
941
	 * Passing a non-empty value will short-circuit wp_get_document_title(),
942
	 * returning that value instead.
943
	 *
944
	 * @since 4.4.0
945
	 *
946
	 * @param string $title The document title. Default empty string.
947
	 */
948
	$title = apply_filters( 'pre_get_document_title', '' );
949
	if ( ! empty( $title ) ) {
950
		return $title;
951
	}
952
953
	global $page, $paged;
954
955
	$title = array(
956
		'title' => '',
957
	);
958
959
	// If it's a 404 page, use a "Page not found" title.
960
	if ( is_404() ) {
961
		$title['title'] = __( 'Page not found' );
962
963
	// If it's a search, use a dynamic search results title.
964
	} elseif ( is_search() ) {
965
		/* translators: %s: search phrase */
966
		$title['title'] = sprintf( __( 'Search Results for &#8220;%s&#8221;' ), get_search_query() );
967
968
	// If on the front page, use the site title.
969
	} elseif ( is_front_page() ) {
970
		$title['title'] = get_bloginfo( 'name', 'display' );
971
972
	// If on a post type archive, use the post type archive title.
973
	} elseif ( is_post_type_archive() ) {
974
		$title['title'] = post_type_archive_title( '', false );
975
976
	// If on a taxonomy archive, use the term title.
977
	} elseif ( is_tax() ) {
978
		$title['title'] = single_term_title( '', false );
979
980
	/*
981
	 * If we're on the blog page that is not the homepage or
982
	 * a single post of any post type, use the post title.
983
	 */
984
	} elseif ( is_home() || is_singular() ) {
985
		$title['title'] = single_post_title( '', false );
986
987
	// If on a category or tag archive, use the term title.
988
	} elseif ( is_category() || is_tag() ) {
989
		$title['title'] = single_term_title( '', false );
990
991
	// If on an author archive, use the author's display name.
992
	} elseif ( is_author() && $author = get_queried_object() ) {
993
		$title['title'] = $author->display_name;
994
995
	// If it's a date archive, use the date as the title.
996
	} elseif ( is_year() ) {
997
		$title['title'] = get_the_date( _x( 'Y', 'yearly archives date format' ) );
998
999
	} elseif ( is_month() ) {
1000
		$title['title'] = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
1001
1002
	} elseif ( is_day() ) {
1003
		$title['title'] = get_the_date();
1004
	}
1005
1006
	// Add a page number if necessary.
1007
	if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
1008
		$title['page'] = sprintf( __( 'Page %s' ), max( $paged, $page ) );
1009
	}
1010
1011
	// Append the description or site title to give context.
1012
	if ( is_front_page() ) {
1013
		$title['tagline'] = get_bloginfo( 'description', 'display' );
1014
	} else {
1015
		$title['site'] = get_bloginfo( 'name', 'display' );
1016
	}
1017
1018
	/**
1019
	 * Filters the separator for the document title.
1020
	 *
1021
	 * @since 4.4.0
1022
	 *
1023
	 * @param string $sep Document title separator. Default '-'.
1024
	 */
1025
	$sep = apply_filters( 'document_title_separator', '-' );
1026
1027
	/**
1028
	 * Filters the parts of the document title.
1029
	 *
1030
	 * @since 4.4.0
1031
	 *
1032
	 * @param array $title {
1033
	 *     The document title parts.
1034
	 *
1035
	 *     @type string $title   Title of the viewed page.
1036
	 *     @type string $page    Optional. Page number if paginated.
1037
	 *     @type string $tagline Optional. Site description when on home page.
1038
	 *     @type string $site    Optional. Site title when not on home page.
1039
	 * }
1040
	 */
1041
	$title = apply_filters( 'document_title_parts', $title );
1042
1043
	$title = implode( " $sep ", array_filter( $title ) );
1044
	$title = wptexturize( $title );
1045
	$title = convert_chars( $title );
1046
	$title = esc_html( $title );
1047
	$title = capital_P_dangit( $title );
1048
1049
	return $title;
1050
}
1051
1052
/**
1053
 * Displays title tag with content.
1054
 *
1055
 * @ignore
1056
 * @since 4.1.0
1057
 * @since 4.4.0 Improved title output replaced `wp_title()`.
1058
 * @access private
1059
 */
1060
function _wp_render_title_tag() {
1061
	if ( ! current_theme_supports( 'title-tag' ) ) {
1062
		return;
1063
	}
1064
1065
	echo '<title>' . wp_get_document_title() . '</title>' . "\n";
1066
}
1067
1068
/**
1069
 * Display or retrieve page title for all areas of blog.
1070
 *
1071
 * By default, the page title will display the separator before the page title,
1072
 * so that the blog title will be before the page title. This is not good for
1073
 * title display, since the blog title shows up on most tabs and not what is
1074
 * important, which is the page that the user is looking at.
1075
 *
1076
 * There are also SEO benefits to having the blog title after or to the 'right'
1077
 * of the page title. However, it is mostly common sense to have the blog title
1078
 * to the right with most browsers supporting tabs. You can achieve this by
1079
 * using the seplocation parameter and setting the value to 'right'. This change
1080
 * was introduced around 2.5.0, in case backward compatibility of themes is
1081
 * important.
1082
 *
1083
 * @since 1.0.0
1084
 *
1085
 * @global WP_Locale $wp_locale
1086
 *
1087
 * @param string $sep         Optional, default is '&raquo;'. How to separate the various items
1088
 *                            within the page title.
1089
 * @param bool   $display     Optional, default is true. Whether to display or retrieve title.
1090
 * @param string $seplocation Optional. Direction to display title, 'right'.
1091
 * @return string|null String on retrieve, null when displaying.
1092
 */
1093
function wp_title( $sep = '&raquo;', $display = true, $seplocation = '' ) {
1094
	global $wp_locale;
1095
1096
	$m        = get_query_var( 'm' );
1097
	$year     = get_query_var( 'year' );
1098
	$monthnum = get_query_var( 'monthnum' );
1099
	$day      = get_query_var( 'day' );
1100
	$search   = get_query_var( 's' );
1101
	$title    = '';
1102
1103
	$t_sep = '%WP_TITLE_SEP%'; // Temporary separator, for accurate flipping, if necessary
1104
1105
	// If there is a post
1106
	if ( is_single() || ( is_home() && ! is_front_page() ) || ( is_page() && ! is_front_page() ) ) {
1107
		$title = single_post_title( '', false );
1108
	}
1109
1110
	// If there's a post type archive
1111
	if ( is_post_type_archive() ) {
1112
		$post_type = get_query_var( 'post_type' );
1113
		if ( is_array( $post_type ) ) {
1114
			$post_type = reset( $post_type );
1115
		}
1116
		$post_type_object = get_post_type_object( $post_type );
1117
		if ( ! $post_type_object->has_archive ) {
1118
			$title = post_type_archive_title( '', false );
1119
		}
1120
	}
1121
1122
	// If there's a category or tag
1123
	if ( is_category() || is_tag() ) {
1124
		$title = single_term_title( '', false );
1125
	}
1126
1127
	// If there's a taxonomy
1128
	if ( is_tax() ) {
1129
		$term = get_queried_object();
1130
		if ( $term ) {
1131
			$tax   = get_taxonomy( $term->taxonomy );
1132
			$title = single_term_title( $tax->labels->name . $t_sep, false );
1133
		}
1134
	}
1135
1136
	// If there's an author
1137
	if ( is_author() && ! is_post_type_archive() ) {
1138
		$author = get_queried_object();
1139
		if ( $author ) {
1140
			$title = $author->display_name;
1141
		}
1142
	}
1143
1144
	// Post type archives with has_archive should override terms.
1145
	if ( is_post_type_archive() && $post_type_object->has_archive ) {
0 ignored issues
show
The variable $post_type_object does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1146
		$title = post_type_archive_title( '', false );
1147
	}
1148
1149
	// If there's a month
1150
	if ( is_archive() && ! empty( $m ) ) {
1151
		$my_year  = substr( $m, 0, 4 );
1152
		$my_month = $wp_locale->get_month( substr( $m, 4, 2 ) );
1153
		$my_day   = intval( substr( $m, 6, 2 ) );
1154
		$title    = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
1155
	}
1156
1157
	// If there's a year
1158
	if ( is_archive() && ! empty( $year ) ) {
1159
		$title = $year;
1160
		if ( ! empty( $monthnum ) ) {
1161
			$title .= $t_sep . $wp_locale->get_month( $monthnum );
1162
		}
1163
		if ( ! empty( $day ) ) {
1164
			$title .= $t_sep . zeroise( $day, 2 );
1165
		}
1166
	}
1167
1168
	// If it's a search
1169
	if ( is_search() ) {
1170
		/* translators: 1: separator, 2: search phrase */
1171
		$title = sprintf( __( 'Search Results %1$s %2$s' ), $t_sep, strip_tags( $search ) );
1172
	}
1173
1174
	// If it's a 404 page
1175
	if ( is_404() ) {
1176
		$title = __( 'Page not found' );
1177
	}
1178
1179
	$prefix = '';
1180
	if ( ! empty( $title ) ) {
1181
		$prefix = " $sep ";
1182
	}
1183
1184
	/**
1185
	 * Filters the parts of the page title.
1186
	 *
1187
	 * @since 4.0.0
1188
	 *
1189
	 * @param array $title_array Parts of the page title.
1190
	 */
1191
	$title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
1192
1193
	// Determines position of the separator and direction of the breadcrumb
1194
	if ( 'right' == $seplocation ) { // sep on right, so reverse the order
1195
		$title_array = array_reverse( $title_array );
1196
		$title       = implode( " $sep ", $title_array ) . $prefix;
1197
	} else {
1198
		$title = $prefix . implode( " $sep ", $title_array );
1199
	}
1200
1201
	/**
1202
	 * Filters the text of the page title.
1203
	 *
1204
	 * @since 2.0.0
1205
	 *
1206
	 * @param string $title Page title.
1207
	 * @param string $sep Title separator.
1208
	 * @param string $seplocation Location of the separator (left or right).
1209
	 */
1210
	$title = apply_filters( 'wp_title', $title, $sep, $seplocation );
1211
1212
	// Send it out
1213
	if ( $display ) {
1214
		echo $title;
1215
	} else {
1216
		return $title;
1217
	}
1218
}
1219
1220
/**
1221
 * Display or retrieve page title for post.
1222
 *
1223
 * This is optimized for single.php template file for displaying the post title.
1224
 *
1225
 * It does not support placing the separator after the title, but by leaving the
1226
 * prefix parameter empty, you can set the title separator manually. The prefix
1227
 * does not automatically place a space between the prefix, so if there should
1228
 * be a space, the parameter value will need to have it at the end.
1229
 *
1230
 * @since 0.71
1231
 *
1232
 * @param string $prefix  Optional. What to display before the title.
1233
 * @param bool   $display Optional, default is true. Whether to display or retrieve title.
1234
 * @return string|void Title when retrieving.
1235
 */
1236
function single_post_title( $prefix = '', $display = true ) {
1237
	$_post = get_queried_object();
1238
1239
	if ( !isset($_post->post_title) )
1240
		return;
1241
1242
	/**
1243
	 * Filters the page title for a single post.
1244
	 *
1245
	 * @since 0.71
1246
	 *
1247
	 * @param string $_post_title The single post page title.
1248
	 * @param object $_post       The current queried object as returned by get_queried_object().
1249
	 */
1250
	$title = apply_filters( 'single_post_title', $_post->post_title, $_post );
1251
	if ( $display )
1252
		echo $prefix . $title;
1253
	else
1254
		return $prefix . $title;
1255
}
1256
1257
/**
1258
 * Display or retrieve title for a post type archive.
1259
 *
1260
 * This is optimized for archive.php and archive-{$post_type}.php template files
1261
 * for displaying the title of the post type.
1262
 *
1263
 * @since 3.1.0
1264
 *
1265
 * @param string $prefix  Optional. What to display before the title.
1266
 * @param bool   $display Optional, default is true. Whether to display or retrieve title.
1267
 * @return string|void Title when retrieving, null when displaying or failure.
1268
 */
1269
function post_type_archive_title( $prefix = '', $display = true ) {
1270
	if ( ! is_post_type_archive() )
1271
		return;
1272
1273
	$post_type = get_query_var( 'post_type' );
1274
	if ( is_array( $post_type ) )
1275
		$post_type = reset( $post_type );
1276
1277
	$post_type_obj = get_post_type_object( $post_type );
1278
1279
	/**
1280
	 * Filters the post type archive title.
1281
	 *
1282
	 * @since 3.1.0
1283
	 *
1284
	 * @param string $post_type_name Post type 'name' label.
1285
	 * @param string $post_type      Post type.
1286
	 */
1287
	$title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
1288
1289
	if ( $display )
1290
		echo $prefix . $title;
1291
	else
1292
		return $prefix . $title;
1293
}
1294
1295
/**
1296
 * Display or retrieve page title for category archive.
1297
 *
1298
 * Useful for category template files for displaying the category page title.
1299
 * The prefix does not automatically place a space between the prefix, so if
1300
 * there should be a space, the parameter value will need to have it at the end.
1301
 *
1302
 * @since 0.71
1303
 *
1304
 * @param string $prefix  Optional. What to display before the title.
1305
 * @param bool   $display Optional, default is true. Whether to display or retrieve title.
1306
 * @return string|void Title when retrieving.
1307
 */
1308
function single_cat_title( $prefix = '', $display = true ) {
1309
	return single_term_title( $prefix, $display );
1310
}
1311
1312
/**
1313
 * Display or retrieve page title for tag post archive.
1314
 *
1315
 * Useful for tag template files for displaying the tag page title. The prefix
1316
 * does not automatically place a space between the prefix, so if there should
1317
 * be a space, the parameter value will need to have it at the end.
1318
 *
1319
 * @since 2.3.0
1320
 *
1321
 * @param string $prefix  Optional. What to display before the title.
1322
 * @param bool   $display Optional, default is true. Whether to display or retrieve title.
1323
 * @return string|void Title when retrieving.
1324
 */
1325
function single_tag_title( $prefix = '', $display = true ) {
1326
	return single_term_title( $prefix, $display );
1327
}
1328
1329
/**
1330
 * Display or retrieve page title for taxonomy term archive.
1331
 *
1332
 * Useful for taxonomy term template files for displaying the taxonomy term page title.
1333
 * The prefix does not automatically place a space between the prefix, so if there should
1334
 * be a space, the parameter value will need to have it at the end.
1335
 *
1336
 * @since 3.1.0
1337
 *
1338
 * @param string $prefix  Optional. What to display before the title.
1339
 * @param bool   $display Optional, default is true. Whether to display or retrieve title.
1340
 * @return string|void Title when retrieving.
1341
 */
1342
function single_term_title( $prefix = '', $display = true ) {
1343
	$term = get_queried_object();
1344
1345
	if ( !$term )
1346
		return;
1347
1348
	if ( is_category() ) {
1349
		/**
1350
		 * Filters the category archive page title.
1351
		 *
1352
		 * @since 2.0.10
1353
		 *
1354
		 * @param string $term_name Category name for archive being displayed.
1355
		 */
1356
		$term_name = apply_filters( 'single_cat_title', $term->name );
1357
	} elseif ( is_tag() ) {
1358
		/**
1359
		 * Filters the tag archive page title.
1360
		 *
1361
		 * @since 2.3.0
1362
		 *
1363
		 * @param string $term_name Tag name for archive being displayed.
1364
		 */
1365
		$term_name = apply_filters( 'single_tag_title', $term->name );
1366
	} elseif ( is_tax() ) {
1367
		/**
1368
		 * Filters the custom taxonomy archive page title.
1369
		 *
1370
		 * @since 3.1.0
1371
		 *
1372
		 * @param string $term_name Term name for archive being displayed.
1373
		 */
1374
		$term_name = apply_filters( 'single_term_title', $term->name );
1375
	} else {
1376
		return;
1377
	}
1378
1379
	if ( empty( $term_name ) )
1380
		return;
1381
1382
	if ( $display )
1383
		echo $prefix . $term_name;
1384
	else
1385
		return $prefix . $term_name;
1386
}
1387
1388
/**
1389
 * Display or retrieve page title for post archive based on date.
1390
 *
1391
 * Useful for when the template only needs to display the month and year,
1392
 * if either are available. The prefix does not automatically place a space
1393
 * between the prefix, so if there should be a space, the parameter value
1394
 * will need to have it at the end.
1395
 *
1396
 * @since 0.71
1397
 *
1398
 * @global WP_Locale $wp_locale
1399
 *
1400
 * @param string $prefix  Optional. What to display before the title.
1401
 * @param bool   $display Optional, default is true. Whether to display or retrieve title.
1402
 * @return string|void Title when retrieving.
1403
 */
1404
function single_month_title($prefix = '', $display = true ) {
1405
	global $wp_locale;
1406
1407
	$m = get_query_var('m');
1408
	$year = get_query_var('year');
1409
	$monthnum = get_query_var('monthnum');
1410
1411
	if ( !empty($monthnum) && !empty($year) ) {
1412
		$my_year = $year;
1413
		$my_month = $wp_locale->get_month($monthnum);
1414
	} elseif ( !empty($m) ) {
1415
		$my_year = substr($m, 0, 4);
1416
		$my_month = $wp_locale->get_month(substr($m, 4, 2));
1417
	}
1418
1419
	if ( empty($my_month) )
1420
		return false;
1421
1422
	$result = $prefix . $my_month . $prefix . $my_year;
0 ignored issues
show
The variable $my_year does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1423
1424
	if ( !$display )
1425
		return $result;
1426
	echo $result;
1427
}
1428
1429
/**
1430
 * Display the archive title based on the queried object.
1431
 *
1432
 * @since 4.1.0
1433
 *
1434
 * @see get_the_archive_title()
1435
 *
1436
 * @param string $before Optional. Content to prepend to the title. Default empty.
1437
 * @param string $after  Optional. Content to append to the title. Default empty.
1438
 */
1439
function the_archive_title( $before = '', $after = '' ) {
1440
	$title = get_the_archive_title();
1441
1442
	if ( ! empty( $title ) ) {
1443
		echo $before . $title . $after;
1444
	}
1445
}
1446
1447
/**
1448
 * Retrieve the archive title based on the queried object.
1449
 *
1450
 * @since 4.1.0
1451
 *
1452
 * @return string Archive title.
1453
 */
1454
function get_the_archive_title() {
1455
	if ( is_category() ) {
1456
		$title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) );
1457
	} elseif ( is_tag() ) {
1458
		$title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) );
1459
	} elseif ( is_author() ) {
1460
		$title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . get_the_author() . '</span>' );
1461
	} elseif ( is_year() ) {
1462
		$title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) );
1463
	} elseif ( is_month() ) {
1464
		$title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) );
1465
	} elseif ( is_day() ) {
1466
		$title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) );
1467
	} elseif ( is_tax( 'post_format' ) ) {
1468
		if ( is_tax( 'post_format', 'post-format-aside' ) ) {
1469
			$title = _x( 'Asides', 'post format archive title' );
1470
		} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
1471
			$title = _x( 'Galleries', 'post format archive title' );
1472
		} elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
1473
			$title = _x( 'Images', 'post format archive title' );
1474
		} elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
1475
			$title = _x( 'Videos', 'post format archive title' );
1476
		} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
1477
			$title = _x( 'Quotes', 'post format archive title' );
1478
		} elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
1479
			$title = _x( 'Links', 'post format archive title' );
1480
		} elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
1481
			$title = _x( 'Statuses', 'post format archive title' );
1482
		} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
1483
			$title = _x( 'Audio', 'post format archive title' );
1484
		} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
1485
			$title = _x( 'Chats', 'post format archive title' );
1486
		}
1487
	} elseif ( is_post_type_archive() ) {
1488
		$title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) );
1489
	} elseif ( is_tax() ) {
1490
		$tax = get_taxonomy( get_queried_object()->taxonomy );
1491
		/* translators: 1: Taxonomy singular name, 2: Current taxonomy term */
1492
		$title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) );
1493
	} else {
1494
		$title = __( 'Archives' );
1495
	}
1496
1497
	/**
1498
	 * Filters the archive title.
1499
	 *
1500
	 * @since 4.1.0
1501
	 *
1502
	 * @param string $title Archive title to be displayed.
1503
	 */
1504
	return apply_filters( 'get_the_archive_title', $title );
0 ignored issues
show
The variable $title does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1505
}
1506
1507
/**
1508
 * Display category, tag, or term description.
1509
 *
1510
 * @since 4.1.0
1511
 *
1512
 * @see get_the_archive_description()
1513
 *
1514
 * @param string $before Optional. Content to prepend to the description. Default empty.
1515
 * @param string $after  Optional. Content to append to the description. Default empty.
1516
 */
1517
function the_archive_description( $before = '', $after = '' ) {
1518
	$description = get_the_archive_description();
1519
	if ( $description ) {
1520
		echo $before . $description . $after;
1521
	}
1522
}
1523
1524
/**
1525
 * Retrieve category, tag, or term description.
1526
 *
1527
 * @since 4.1.0
1528
 *
1529
 * @return string Archive description.
1530
 */
1531
function get_the_archive_description() {
1532
	/**
1533
	 * Filters the archive description.
1534
	 *
1535
	 * @since 4.1.0
1536
	 *
1537
	 * @see term_description()
1538
	 *
1539
	 * @param string $description Archive description to be displayed.
1540
	 */
1541
	return apply_filters( 'get_the_archive_description', term_description() );
1542
}
1543
1544
/**
1545
 * Retrieve archive link content based on predefined or custom code.
1546
 *
1547
 * The format can be one of four styles. The 'link' for head element, 'option'
1548
 * for use in the select element, 'html' for use in list (either ol or ul HTML
1549
 * elements). Custom content is also supported using the before and after
1550
 * parameters.
1551
 *
1552
 * The 'link' format uses the `<link>` HTML element with the **archives**
1553
 * relationship. The before and after parameters are not used. The text
1554
 * parameter is used to describe the link.
1555
 *
1556
 * The 'option' format uses the option HTML element for use in select element.
1557
 * The value is the url parameter and the before and after parameters are used
1558
 * between the text description.
1559
 *
1560
 * The 'html' format, which is the default, uses the li HTML element for use in
1561
 * the list HTML elements. The before parameter is before the link and the after
1562
 * parameter is after the closing link.
1563
 *
1564
 * The custom format uses the before parameter before the link ('a' HTML
1565
 * element) and the after parameter after the closing link tag. If the above
1566
 * three values for the format are not used, then custom format is assumed.
1567
 *
1568
 * @since 1.0.0
1569
 *
1570
 * @param string $url    URL to archive.
1571
 * @param string $text   Archive text description.
1572
 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
1573
 * @param string $before Optional. Content to prepend to the description. Default empty.
1574
 * @param string $after  Optional. Content to append to the description. Default empty.
1575
 * @return string HTML link content for archive.
1576
 */
1577
function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
1578
	$text = wptexturize($text);
1579
	$url = esc_url($url);
1580
1581
	if ('link' == $format)
1582
		$link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
1583
	elseif ('option' == $format)
1584
		$link_html = "\t<option value='$url'>$before $text $after</option>\n";
1585
	elseif ('html' == $format)
1586
		$link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
1587
	else // custom
1588
		$link_html = "\t$before<a href='$url'>$text</a>$after\n";
1589
1590
	/**
1591
	 * Filters the archive link content.
1592
	 *
1593
	 * @since 2.6.0
1594
	 * @since 4.5.0 Added the `$url`, `$text`, `$format`, `$before`, and `$after` parameters.
1595
	 *
1596
	 * @param string $link_html The archive HTML link content.
1597
	 * @param string $url       URL to archive.
1598
	 * @param string $text      Archive text description.
1599
	 * @param string $format    Link format. Can be 'link', 'option', 'html', or custom.
1600
	 * @param string $before    Content to prepend to the description.
1601
	 * @param string $after     Content to append to the description.
1602
	 */
1603
	return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after );
1604
}
1605
1606
/**
1607
 * Display archive links based on type and format.
1608
 *
1609
 * @since 1.2.0
1610
 * @since 4.4.0 $post_type arg was added.
1611
 *
1612
 * @see get_archives_link()
1613
 *
1614
 * @global wpdb      $wpdb
1615
 * @global WP_Locale $wp_locale
1616
 *
1617
 * @param string|array $args {
1618
 *     Default archive links arguments. Optional.
1619
 *
1620
 *     @type string     $type            Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly',
1621
 *                                       'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha'
1622
 *                                       display the same archive link list as well as post titles instead
1623
 *                                       of displaying dates. The difference between the two is that 'alpha'
1624
 *                                       will order by post title and 'postbypost' will order by post date.
1625
 *                                       Default 'monthly'.
1626
 *     @type string|int $limit           Number of links to limit the query to. Default empty (no limit).
1627
 *     @type string     $format          Format each link should take using the $before and $after args.
1628
 *                                       Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html'
1629
 *                                       (`<li>` tag), or a custom format, which generates a link anchor
1630
 *                                       with $before preceding and $after succeeding. Default 'html'.
1631
 *     @type string     $before          Markup to prepend to the beginning of each link. Default empty.
1632
 *     @type string     $after           Markup to append to the end of each link. Default empty.
1633
 *     @type bool       $show_post_count Whether to display the post count alongside the link. Default false.
1634
 *     @type bool|int   $echo            Whether to echo or return the links list. Default 1|true to echo.
1635
 *     @type string     $order           Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'.
1636
 *                                       Default 'DESC'.
1637
 *     @type string     $post_type       Post type. Default 'post'.
1638
 * }
1639
 * @return string|void String when retrieving.
1640
 */
1641
function wp_get_archives( $args = '' ) {
1642
	global $wpdb, $wp_locale;
1643
1644
	$defaults = array(
1645
		'type' => 'monthly', 'limit' => '',
1646
		'format' => 'html', 'before' => '',
1647
		'after' => '', 'show_post_count' => false,
1648
		'echo' => 1, 'order' => 'DESC',
1649
		'post_type' => 'post'
1650
	);
1651
1652
	$r = wp_parse_args( $args, $defaults );
1653
1654
	$post_type_object = get_post_type_object( $r['post_type'] );
1655
	if ( ! is_post_type_viewable( $post_type_object ) ) {
0 ignored issues
show
It seems like $post_type_object defined by get_post_type_object($r['post_type']) on line 1654 can be null; however, is_post_type_viewable() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
1656
		return;
1657
	}
1658
	$r['post_type'] = $post_type_object->name;
1659
1660
	if ( '' == $r['type'] ) {
1661
		$r['type'] = 'monthly';
1662
	}
1663
1664
	if ( ! empty( $r['limit'] ) ) {
1665
		$r['limit'] = absint( $r['limit'] );
1666
		$r['limit'] = ' LIMIT ' . $r['limit'];
1667
	}
1668
1669
	$order = strtoupper( $r['order'] );
1670
	if ( $order !== 'ASC' ) {
1671
		$order = 'DESC';
1672
	}
1673
1674
	// this is what will separate dates on weekly archive links
1675
	$archive_week_separator = '&#8211;';
1676
1677
	$sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $r['post_type'] );
1678
1679
	/**
1680
	 * Filters the SQL WHERE clause for retrieving archives.
1681
	 *
1682
	 * @since 2.2.0
1683
	 *
1684
	 * @param string $sql_where Portion of SQL query containing the WHERE clause.
1685
	 * @param array  $r         An array of default arguments.
1686
	 */
1687
	$where = apply_filters( 'getarchives_where', $sql_where, $r );
1688
1689
	/**
1690
	 * Filters the SQL JOIN clause for retrieving archives.
1691
	 *
1692
	 * @since 2.2.0
1693
	 *
1694
	 * @param string $sql_join Portion of SQL query containing JOIN clause.
1695
	 * @param array  $r        An array of default arguments.
1696
	 */
1697
	$join = apply_filters( 'getarchives_join', '', $r );
1698
1699
	$output = '';
1700
1701
	$last_changed = wp_cache_get( 'last_changed', 'posts' );
1702
	if ( ! $last_changed ) {
1703
		$last_changed = microtime();
1704
		wp_cache_set( 'last_changed', $last_changed, 'posts' );
1705
	}
1706
1707
	$limit = $r['limit'];
1708
1709
	if ( 'monthly' == $r['type'] ) {
1710
		$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";
1711
		$key = md5( $query );
1712
		$key = "wp_get_archives:$key:$last_changed";
1713 View Code Duplication
		if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1714
			$results = $wpdb->get_results( $query );
1715
			wp_cache_set( $key, $results, 'posts' );
1716
		}
1717
		if ( $results ) {
1718
			$after = $r['after'];
1719
			foreach ( (array) $results as $result ) {
1720
				$url = get_month_link( $result->year, $result->month );
1721
				if ( 'post' !== $r['post_type'] ) {
1722
					$url = add_query_arg( 'post_type', $r['post_type'], $url );
1723
				}
1724
				/* translators: 1: month name, 2: 4-digit year */
1725
				$text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );
1726 View Code Duplication
				if ( $r['show_post_count'] ) {
1727
					$r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
1728
				}
1729
				$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1730
			}
1731
		}
1732
	} elseif ( 'yearly' == $r['type'] ) {
1733
		$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";
1734
		$key = md5( $query );
1735
		$key = "wp_get_archives:$key:$last_changed";
1736 View Code Duplication
		if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1737
			$results = $wpdb->get_results( $query );
1738
			wp_cache_set( $key, $results, 'posts' );
1739
		}
1740
		if ( $results ) {
1741
			$after = $r['after'];
1742
			foreach ( (array) $results as $result) {
1743
				$url = get_year_link( $result->year );
1744
				if ( 'post' !== $r['post_type'] ) {
1745
					$url = add_query_arg( 'post_type', $r['post_type'], $url );
1746
				}
1747
				$text = sprintf( '%d', $result->year );
1748 View Code Duplication
				if ( $r['show_post_count'] ) {
1749
					$r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
1750
				}
1751
				$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1752
			}
1753
		}
1754
	} elseif ( 'daily' == $r['type'] ) {
1755
		$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";
1756
		$key = md5( $query );
1757
		$key = "wp_get_archives:$key:$last_changed";
1758 View Code Duplication
		if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1759
			$results = $wpdb->get_results( $query );
1760
			wp_cache_set( $key, $results, 'posts' );
1761
		}
1762
		if ( $results ) {
1763
			$after = $r['after'];
1764
			foreach ( (array) $results as $result ) {
1765
				$url  = get_day_link( $result->year, $result->month, $result->dayofmonth );
1766
				if ( 'post' !== $r['post_type'] ) {
1767
					$url = add_query_arg( 'post_type', $r['post_type'], $url );
1768
				}
1769
				$date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth );
1770
				$text = mysql2date( get_option( 'date_format' ), $date );
1771 View Code Duplication
				if ( $r['show_post_count'] ) {
1772
					$r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
1773
				}
1774
				$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1775
			}
1776
		}
1777
	} elseif ( 'weekly' == $r['type'] ) {
1778
		$week = _wp_mysql_week( '`post_date`' );
1779
		$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";
1780
		$key = md5( $query );
1781
		$key = "wp_get_archives:$key:$last_changed";
1782 View Code Duplication
		if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1783
			$results = $wpdb->get_results( $query );
1784
			wp_cache_set( $key, $results, 'posts' );
1785
		}
1786
		$arc_w_last = '';
1787
		if ( $results ) {
1788
			$after = $r['after'];
1789
			foreach ( (array) $results as $result ) {
1790
				if ( $result->week != $arc_w_last ) {
1791
					$arc_year       = $result->yr;
1792
					$arc_w_last     = $result->week;
1793
					$arc_week       = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) );
1794
					$arc_week_start = date_i18n( get_option( 'date_format' ), $arc_week['start'] );
1795
					$arc_week_end   = date_i18n( get_option( 'date_format' ), $arc_week['end'] );
1796
					$url            = add_query_arg( array( 'm' => $arc_year, 'w' => $result->week, ), home_url( '/' ) );
1797
					if ( 'post' !== $r['post_type'] ) {
1798
						$url = add_query_arg( 'post_type', $r['post_type'], $url );
1799
					}
1800
					$text           = $arc_week_start . $archive_week_separator . $arc_week_end;
1801 View Code Duplication
					if ( $r['show_post_count'] ) {
1802
						$r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
1803
					}
1804
					$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1805
				}
1806
			}
1807
		}
1808
	} elseif ( ( 'postbypost' == $r['type'] ) || ('alpha' == $r['type'] ) ) {
1809
		$orderby = ( 'alpha' == $r['type'] ) ? 'post_title ASC ' : 'post_date DESC, ID DESC ';
1810
		$query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
1811
		$key = md5( $query );
1812
		$key = "wp_get_archives:$key:$last_changed";
1813 View Code Duplication
		if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1814
			$results = $wpdb->get_results( $query );
1815
			wp_cache_set( $key, $results, 'posts' );
1816
		}
1817
		if ( $results ) {
1818
			foreach ( (array) $results as $result ) {
1819
				if ( $result->post_date != '0000-00-00 00:00:00' ) {
1820
					$url = get_permalink( $result );
1821
					if ( $result->post_title ) {
1822
						/** This filter is documented in wp-includes/post-template.php */
1823
						$text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
1824
					} else {
1825
						$text = $result->ID;
1826
					}
1827
					$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
0 ignored issues
show
It seems like $url defined by get_permalink($result) on line 1820 can also be of type false; however, get_archives_link() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
1828
				}
1829
			}
1830
		}
1831
	}
1832
	if ( $r['echo'] ) {
1833
		echo $output;
1834
	} else {
1835
		return $output;
1836
	}
1837
}
1838
1839
/**
1840
 * Get number of days since the start of the week.
1841
 *
1842
 * @since 1.5.0
1843
 *
1844
 * @param int $num Number of day.
1845
 * @return int Days since the start of the week.
1846
 */
1847
function calendar_week_mod($num) {
1848
	$base = 7;
1849
	return ($num - $base*floor($num/$base));
1850
}
1851
1852
/**
1853
 * Display calendar with days that have posts as links.
1854
 *
1855
 * The calendar is cached, which will be retrieved, if it exists. If there are
1856
 * no posts for the month, then it will not be displayed.
1857
 *
1858
 * @since 1.0.0
1859
 *
1860
 * @global wpdb      $wpdb
1861
 * @global int       $m
1862
 * @global int       $monthnum
1863
 * @global int       $year
1864
 * @global WP_Locale $wp_locale
1865
 * @global array     $posts
1866
 *
1867
 * @param bool $initial Optional, default is true. Use initial calendar names.
1868
 * @param bool $echo    Optional, default is true. Set to false for return.
1869
 * @return string|void String when retrieving.
1870
 */
1871
function get_calendar( $initial = true, $echo = true ) {
1872
	global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
1873
1874
	$key = md5( $m . $monthnum . $year );
1875
	$cache = wp_cache_get( 'get_calendar', 'calendar' );
1876
1877
	if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) {
1878
		/** This filter is documented in wp-includes/general-template.php */
1879
		$output = apply_filters( 'get_calendar', $cache[ $key ] );
1880
1881
		if ( $echo ) {
1882
			echo $output;
1883
			return;
1884
		}
1885
1886
		return $output;
1887
	}
1888
1889
	if ( ! is_array( $cache ) ) {
1890
		$cache = array();
1891
	}
1892
1893
	// Quick check. If we have no posts at all, abort!
1894
	if ( ! $posts ) {
1895
		$gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
1896
		if ( ! $gotsome ) {
1897
			$cache[ $key ] = '';
1898
			wp_cache_set( 'get_calendar', $cache, 'calendar' );
1899
			return;
1900
		}
1901
	}
1902
1903
	if ( isset( $_GET['w'] ) ) {
1904
		$w = (int) $_GET['w'];
1905
	}
1906
	// week_begins = 0 stands for Sunday
1907
	$week_begins = (int) get_option( 'start_of_week' );
1908
	$ts = current_time( 'timestamp' );
1909
1910
	// Let's figure out when we are
1911
	if ( ! empty( $monthnum ) && ! empty( $year ) ) {
1912
		$thismonth = zeroise( intval( $monthnum ), 2 );
1913
		$thisyear = (int) $year;
1914
	} elseif ( ! empty( $w ) ) {
1915
		// We need to get the month from MySQL
1916
		$thisyear = (int) substr( $m, 0, 4 );
1917
		//it seems MySQL's weeks disagree with PHP's
1918
		$d = ( ( $w - 1 ) * 7 ) + 6;
1919
		$thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
1920
	} elseif ( ! empty( $m ) ) {
1921
		$thisyear = (int) substr( $m, 0, 4 );
1922
		if ( strlen( $m ) < 6 ) {
1923
			$thismonth = '01';
1924
		} else {
1925
			$thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 );
1926
		}
1927
	} else {
1928
		$thisyear = gmdate( 'Y', $ts );
1929
		$thismonth = gmdate( 'm', $ts );
1930
	}
1931
1932
	$unixmonth = mktime( 0, 0 , 0, $thismonth, 1, $thisyear );
1933
	$last_day = date( 't', $unixmonth );
1934
1935
	// Get the next and previous month and year with at least one post
1936
	$previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
1937
		FROM $wpdb->posts
1938
		WHERE post_date < '$thisyear-$thismonth-01'
1939
		AND post_type = 'post' AND post_status = 'publish'
1940
			ORDER BY post_date DESC
1941
			LIMIT 1");
1942
	$next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
1943
		FROM $wpdb->posts
1944
		WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
1945
		AND post_type = 'post' AND post_status = 'publish'
1946
			ORDER BY post_date ASC
1947
			LIMIT 1");
1948
1949
	/* translators: Calendar caption: 1: month name, 2: 4-digit year */
1950
	$calendar_caption = _x('%1$s %2$s', 'calendar caption');
1951
	$calendar_output = '<table id="wp-calendar">
1952
	<caption>' . sprintf(
1953
		$calendar_caption,
1954
		$wp_locale->get_month( $thismonth ),
1955
		date( 'Y', $unixmonth )
1956
	) . '</caption>
1957
	<thead>
1958
	<tr>';
1959
1960
	$myweek = array();
1961
1962
	for ( $wdcount = 0; $wdcount <= 6; $wdcount++ ) {
1963
		$myweek[] = $wp_locale->get_weekday( ( $wdcount + $week_begins ) % 7 );
1964
	}
1965
1966
	foreach ( $myweek as $wd ) {
1967
		$day_name = $initial ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd );
1968
		$wd = esc_attr( $wd );
1969
		$calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
1970
	}
1971
1972
	$calendar_output .= '
1973
	</tr>
1974
	</thead>
1975
1976
	<tfoot>
1977
	<tr>';
1978
1979 View Code Duplication
	if ( $previous ) {
1980
		$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link( $previous->year, $previous->month ) . '">&laquo; ' .
1981
			$wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) .
1982
		'</a></td>';
1983
	} else {
1984
		$calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
1985
	}
1986
1987
	$calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
1988
1989 View Code Duplication
	if ( $next ) {
1990
		$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link( $next->year, $next->month ) . '">' .
1991
			$wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) .
1992
		' &raquo;</a></td>';
1993
	} else {
1994
		$calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
1995
	}
1996
1997
	$calendar_output .= '
1998
	</tr>
1999
	</tfoot>
2000
2001
	<tbody>
2002
	<tr>';
2003
2004
	$daywithpost = array();
2005
2006
	// Get days with posts
2007
	$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
2008
		FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
2009
		AND post_type = 'post' AND post_status = 'publish'
2010
		AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
2011
	if ( $dayswithposts ) {
2012
		foreach ( (array) $dayswithposts as $daywith ) {
2013
			$daywithpost[] = $daywith[0];
2014
		}
2015
	}
2016
2017
	// See how much we should pad in the beginning
2018
	$pad = calendar_week_mod( date( 'w', $unixmonth ) - $week_begins );
2019
	if ( 0 != $pad ) {
2020
		$calendar_output .= "\n\t\t".'<td colspan="'. esc_attr( $pad ) .'" class="pad">&nbsp;</td>';
2021
	}
2022
2023
	$newrow = false;
2024
	$daysinmonth = (int) date( 't', $unixmonth );
2025
2026
	for ( $day = 1; $day <= $daysinmonth; ++$day ) {
2027
		if ( isset($newrow) && $newrow ) {
2028
			$calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
2029
		}
2030
		$newrow = false;
2031
2032
		if ( $day == gmdate( 'j', $ts ) &&
2033
			$thismonth == gmdate( 'm', $ts ) &&
2034
			$thisyear == gmdate( 'Y', $ts ) ) {
2035
			$calendar_output .= '<td id="today">';
2036
		} else {
2037
			$calendar_output .= '<td>';
2038
		}
2039
2040
		if ( in_array( $day, $daywithpost ) ) {
2041
			// any posts today?
2042
			$date_format = date( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) );
2043
			$label = sprintf( __( 'Posts published on %s' ), $date_format );
2044
			$calendar_output .= sprintf(
2045
				'<a href="%s" aria-label="%s">%s</a>',
2046
				get_day_link( $thisyear, $thismonth, $day ),
2047
				esc_attr( $label ),
2048
				$day
2049
			);
2050
		} else {
2051
			$calendar_output .= $day;
2052
		}
2053
		$calendar_output .= '</td>';
2054
2055
		if ( 6 == calendar_week_mod( date( 'w', mktime(0, 0 , 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) {
2056
			$newrow = true;
2057
		}
2058
	}
2059
2060
	$pad = 7 - calendar_week_mod( date( 'w', mktime( 0, 0 , 0, $thismonth, $day, $thisyear ) ) - $week_begins );
2061
	if ( $pad != 0 && $pad != 7 ) {
2062
		$calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr( $pad ) .'">&nbsp;</td>';
2063
	}
2064
	$calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
2065
2066
	$cache[ $key ] = $calendar_output;
2067
	wp_cache_set( 'get_calendar', $cache, 'calendar' );
2068
2069
	if ( $echo ) {
2070
		/**
2071
		 * Filters the HTML calendar output.
2072
		 *
2073
		 * @since 3.0.0
2074
		 *
2075
		 * @param string $calendar_output HTML output of the calendar.
2076
		 */
2077
		echo apply_filters( 'get_calendar', $calendar_output );
2078
		return;
2079
	}
2080
	/** This filter is documented in wp-includes/general-template.php */
2081
	return apply_filters( 'get_calendar', $calendar_output );
2082
}
2083
2084
/**
2085
 * Purge the cached results of get_calendar.
2086
 *
2087
 * @see get_calendar
2088
 * @since 2.1.0
2089
 */
2090
function delete_get_calendar_cache() {
2091
	wp_cache_delete( 'get_calendar', 'calendar' );
2092
}
2093
2094
/**
2095
 * Display all of the allowed tags in HTML format with attributes.
2096
 *
2097
 * This is useful for displaying in the comment area, which elements and
2098
 * attributes are supported. As well as any plugins which want to display it.
2099
 *
2100
 * @since 1.0.1
2101
 *
2102
 * @global array $allowedtags
2103
 *
2104
 * @return string HTML allowed tags entity encoded.
2105
 */
2106
function allowed_tags() {
2107
	global $allowedtags;
2108
	$allowed = '';
2109
	foreach ( (array) $allowedtags as $tag => $attributes ) {
2110
		$allowed .= '<'.$tag;
2111
		if ( 0 < count($attributes) ) {
2112
			foreach ( $attributes as $attribute => $limits ) {
2113
				$allowed .= ' '.$attribute.'=""';
2114
			}
2115
		}
2116
		$allowed .= '> ';
2117
	}
2118
	return htmlentities( $allowed );
2119
}
2120
2121
/***** Date/Time tags *****/
2122
2123
/**
2124
 * Outputs the date in iso8601 format for xml files.
2125
 *
2126
 * @since 1.0.0
2127
 */
2128
function the_date_xml() {
2129
	echo mysql2date( 'Y-m-d', get_post()->post_date, false );
2130
}
2131
2132
/**
2133
 * Display or Retrieve the date the current post was written (once per date)
2134
 *
2135
 * Will only output the date if the current post's date is different from the
2136
 * previous one output.
2137
 *
2138
 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
2139
 * function is called several times for each post.
2140
 *
2141
 * HTML output can be filtered with 'the_date'.
2142
 * Date string output can be filtered with 'get_the_date'.
2143
 *
2144
 * @since 0.71
2145
 *
2146
 * @global string|int|bool $currentday
2147
 * @global string|int|bool $previousday
2148
 *
2149
 * @param string $d      Optional. PHP date format defaults to the date_format option if not specified.
2150
 * @param string $before Optional. Output before the date.
2151
 * @param string $after  Optional. Output after the date.
2152
 * @param bool   $echo   Optional, default is display. Whether to echo the date or return it.
2153
 * @return string|void String if retrieving.
2154
 */
2155
function the_date( $d = '', $before = '', $after = '', $echo = true ) {
2156
	global $currentday, $previousday;
2157
2158
	if ( is_new_day() ) {
2159
		$the_date = $before . get_the_date( $d ) . $after;
2160
		$previousday = $currentday;
2161
2162
		/**
2163
		 * Filters the date a post was published for display.
2164
		 *
2165
		 * @since 0.71
2166
		 *
2167
		 * @param string $the_date The formatted date string.
2168
		 * @param string $d        PHP date format. Defaults to 'date_format' option
2169
		 *                         if not specified.
2170
		 * @param string $before   HTML output before the date.
2171
		 * @param string $after    HTML output after the date.
2172
		 */
2173
		$the_date = apply_filters( 'the_date', $the_date, $d, $before, $after );
2174
2175
		if ( $echo )
2176
			echo $the_date;
2177
		else
2178
			return $the_date;
2179
	}
2180
}
2181
2182
/**
2183
 * Retrieve the date on which the post was written.
2184
 *
2185
 * Unlike the_date() this function will always return the date.
2186
 * Modify output with the {@see 'get_the_date'} filter.
2187
 *
2188
 * @since 3.0.0
2189
 *
2190
 * @param  string      $d    Optional. PHP date format defaults to the date_format option if not specified.
2191
 * @param  int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
2192
 * @return false|string Date the current post was written. False on failure.
2193
 */
2194
function get_the_date( $d = '', $post = null ) {
2195
	$post = get_post( $post );
2196
2197
	if ( ! $post ) {
2198
		return false;
2199
	}
2200
2201 View Code Duplication
	if ( '' == $d ) {
2202
		$the_date = mysql2date( get_option( 'date_format' ), $post->post_date );
2203
	} else {
2204
		$the_date = mysql2date( $d, $post->post_date );
2205
	}
2206
2207
	/**
2208
	 * Filters the date a post was published.
2209
	 *
2210
	 * @since 3.0.0
2211
	 *
2212
	 * @param string      $the_date The formatted date.
2213
	 * @param string      $d        PHP date format. Defaults to 'date_format' option
2214
	 *                              if not specified.
2215
	 * @param int|WP_Post $post     The post object or ID.
2216
	 */
2217
	return apply_filters( 'get_the_date', $the_date, $d, $post );
2218
}
2219
2220
/**
2221
 * Display the date on which the post was last modified.
2222
 *
2223
 * @since 2.1.0
2224
 *
2225
 * @param string $d      Optional. PHP date format defaults to the date_format option if not specified.
2226
 * @param string $before Optional. Output before the date.
2227
 * @param string $after  Optional. Output after the date.
2228
 * @param bool   $echo   Optional, default is display. Whether to echo the date or return it.
2229
 * @return string|void String if retrieving.
2230
 */
2231
function the_modified_date( $d = '', $before = '', $after = '', $echo = true ) {
2232
	$the_modified_date = $before . get_the_modified_date($d) . $after;
2233
2234
	/**
2235
	 * Filters the date a post was last modified for display.
2236
	 *
2237
	 * @since 2.1.0
2238
	 *
2239
	 * @param string $the_modified_date The last modified date.
2240
	 * @param string $d                 PHP date format. Defaults to 'date_format' option
2241
	 *                                  if not specified.
2242
	 * @param string $before            HTML output before the date.
2243
	 * @param string $after             HTML output after the date.
2244
	 */
2245
	$the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $d, $before, $after );
2246
2247
	if ( $echo )
2248
		echo $the_modified_date;
2249
	else
2250
		return $the_modified_date;
2251
2252
}
2253
2254
/**
2255
 * Retrieve the date on which the post was last modified.
2256
 *
2257
 * @since 2.1.0
2258
 * @since 4.6.0 Added the `$post` parameter.
2259
 *
2260
 * @param string      $d    Optional. PHP date format defaults to the date_format option if not specified.
2261
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
2262
 * @return false|string Date the current post was modified. False on failure.
2263
 */
2264 View Code Duplication
function get_the_modified_date( $d = '', $post = null ) {
0 ignored issues
show
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2265
	$post = get_post( $post );
2266
2267
	if ( ! $post ) {
2268
		// For backward compatibility, failures go through the filter below.
2269
		$the_time = false;
2270
	} elseif ( empty( $d ) ) {
2271
		$the_time = get_post_modified_time( get_option( 'date_format' ), false, $post, true );
0 ignored issues
show
It seems like $post defined by get_post($post) on line 2265 can also be of type array; however, get_post_modified_time() does only seem to accept integer|object<WP_Post>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
2272
	} else {
2273
		$the_time = get_post_modified_time( $d, false, $post, true );
0 ignored issues
show
It seems like $post defined by get_post($post) on line 2265 can also be of type array; however, get_post_modified_time() does only seem to accept integer|object<WP_Post>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
2274
	}
2275
2276
	/**
2277
	 * Filters the date a post was last modified.
2278
	 *
2279
	 * @since 2.1.0
2280
	 * @since 4.6.0 Added the `$post` parameter.
2281
	 *
2282
	 * @param string  $the_time The formatted date.
2283
	 * @param string  $d        PHP date format. Defaults to value specified in
2284
	 *                          'date_format' option.
2285
	 * @param WP_Post $post     WP_Post object.
2286
	 */
2287
	return apply_filters( 'get_the_modified_date', $the_time, $d, $post );
2288
}
2289
2290
/**
2291
 * Display the time at which the post was written.
2292
 *
2293
 * @since 0.71
2294
 *
2295
 * @param string $d Either 'G', 'U', or php date format.
2296
 */
2297
function the_time( $d = '' ) {
2298
	/**
2299
	 * Filters the time a post was written for display.
2300
	 *
2301
	 * @since 0.71
2302
	 *
2303
	 * @param string $get_the_time The formatted time.
2304
	 * @param string $d            The time format. Accepts 'G', 'U',
2305
	 *                             or php date format.
2306
	 */
2307
	echo apply_filters( 'the_time', get_the_time( $d ), $d );
2308
}
2309
2310
/**
2311
 * Retrieve the time at which the post was written.
2312
 *
2313
 * @since 1.5.0
2314
 *
2315
 * @param string      $d    Optional. Format to use for retrieving the time the post
2316
 *                          was written. Either 'G', 'U', or php date format defaults
2317
 *                          to the value specified in the time_format option. Default empty.
2318
 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
2319
 * @return string|int|false Formatted date string or Unix timestamp if `$id` is 'U' or 'G'. False on failure.
2320
 */
2321 View Code Duplication
function get_the_time( $d = '', $post = null ) {
0 ignored issues
show
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2322
	$post = get_post($post);
2323
2324
	if ( ! $post ) {
2325
		return false;
2326
	}
2327
2328
	if ( '' == $d )
2329
		$the_time = get_post_time(get_option('time_format'), false, $post, true);
0 ignored issues
show
It seems like $post defined by get_post($post) on line 2322 can also be of type array; however, get_post_time() does only seem to accept integer|object<WP_Post>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
2330
	else
2331
		$the_time = get_post_time($d, false, $post, true);
0 ignored issues
show
It seems like $post defined by get_post($post) on line 2322 can also be of type array; however, get_post_time() does only seem to accept integer|object<WP_Post>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
2332
2333
	/**
2334
	 * Filters the time a post was written.
2335
	 *
2336
	 * @since 1.5.0
2337
	 *
2338
	 * @param string      $the_time The formatted time.
2339
	 * @param string      $d        Format to use for retrieving the time the post was written.
2340
	 *                              Accepts 'G', 'U', or php date format value specified
2341
	 *                              in 'time_format' option. Default empty.
2342
	 * @param int|WP_Post $post     WP_Post object or ID.
2343
	 */
2344
	return apply_filters( 'get_the_time', $the_time, $d, $post );
2345
}
2346
2347
/**
2348
 * Retrieve the time at which the post was written.
2349
 *
2350
 * @since 2.0.0
2351
 *
2352
 * @param string      $d         Optional. Format to use for retrieving the time the post
2353
 *                               was written. Either 'G', 'U', or php date format. Default 'U'.
2354
 * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
2355
 * @param int|WP_Post $post      WP_Post object or ID. Default is global $post object.
2356
 * @param bool        $translate Whether to translate the time string. Default false.
2357
 * @return string|int|false Formatted date string or Unix timestamp if `$id` is 'U' or 'G'. False on failure.
2358
 */
2359 View Code Duplication
function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
0 ignored issues
show
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2360
	$post = get_post($post);
2361
2362
	if ( ! $post ) {
2363
		return false;
2364
	}
2365
2366
	if ( $gmt )
2367
		$time = $post->post_date_gmt;
2368
	else
2369
		$time = $post->post_date;
2370
2371
	$time = mysql2date($d, $time, $translate);
2372
2373
	/**
2374
	 * Filters the localized time a post was written.
2375
	 *
2376
	 * @since 2.6.0
2377
	 *
2378
	 * @param string $time The formatted time.
2379
	 * @param string $d    Format to use for retrieving the time the post was written.
2380
	 *                     Accepts 'G', 'U', or php date format. Default 'U'.
2381
	 * @param bool   $gmt  Whether to retrieve the GMT time. Default false.
2382
	 */
2383
	return apply_filters( 'get_post_time', $time, $d, $gmt );
2384
}
2385
2386
/**
2387
 * Display the time at which the post was last modified.
2388
 *
2389
 * @since 2.0.0
2390
 *
2391
 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
2392
 */
2393
function the_modified_time($d = '') {
2394
	/**
2395
	 * Filters the localized time a post was last modified, for display.
2396
	 *
2397
	 * @since 2.0.0
2398
	 *
2399
	 * @param string $get_the_modified_time The formatted time.
2400
	 * @param string $d                     The time format. Accepts 'G', 'U',
2401
	 *                                      or php date format. Defaults to value
2402
	 *                                      specified in 'time_format' option.
2403
	 */
2404
	echo apply_filters( 'the_modified_time', get_the_modified_time($d), $d );
2405
}
2406
2407
/**
2408
 * Retrieve the time at which the post was last modified.
2409
 *
2410
 * @since 2.0.0
2411
 * @since 4.6.0 Added the `$post` parameter.
2412
 *
2413
 * @param string      $d     Optional. Format to use for retrieving the time the post
2414
 *                           was modified. Either 'G', 'U', or php date format defaults
2415
 *                           to the value specified in the time_format option. Default empty.
2416
 * @param int|WP_Post $post  Optional. Post ID or WP_Post object. Default current post.
2417
 * @return false|string Formatted date string or Unix timestamp. False on failure.
2418
 */
2419 View Code Duplication
function get_the_modified_time( $d = '', $post = null ) {
0 ignored issues
show
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2420
	$post = get_post( $post );
2421
2422
	if ( ! $post ) {
2423
		// For backward compatibility, failures go through the filter below.
2424
		$the_time = false;
2425
	} elseif ( empty( $d ) ) {
2426
		$the_time = get_post_modified_time( get_option( 'time_format' ), false, $post, true );
0 ignored issues
show
It seems like $post defined by get_post($post) on line 2420 can also be of type array; however, get_post_modified_time() does only seem to accept integer|object<WP_Post>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
2427
	} else {
2428
		$the_time = get_post_modified_time( $d, false, $post, true );
0 ignored issues
show
It seems like $post defined by get_post($post) on line 2420 can also be of type array; however, get_post_modified_time() does only seem to accept integer|object<WP_Post>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
2429
	}
2430
2431
	/**
2432
	 * Filters the localized time a post was last modified.
2433
	 *
2434
	 * @since 2.0.0
2435
	 * @since 4.6.0 Added the `$post` parameter.
2436
	 *
2437
	 * @param string $the_time The formatted time.
2438
	 * @param string $d        Format to use for retrieving the time the post was
2439
	 *                         written. Accepts 'G', 'U', or php date format. Defaults
2440
	 *                         to value specified in 'time_format' option.
2441
	 * @param WP_Post $post    WP_Post object.
2442
	 */
2443
	return apply_filters( 'get_the_modified_time', $the_time, $d, $post );
2444
}
2445
2446
/**
2447
 * Retrieve the time at which the post was last modified.
2448
 *
2449
 * @since 2.0.0
2450
 *
2451
 * @param string      $d         Optional. Format to use for retrieving the time the post
2452
 *                               was modified. Either 'G', 'U', or php date format. Default 'U'.
2453
 * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
2454
 * @param int|WP_Post $post      WP_Post object or ID. Default is global $post object.
2455
 * @param bool        $translate Whether to translate the time string. Default false.
2456
 * @return string|int|false Formatted date string or Unix timestamp if `$id` is 'U' or 'G'. False on failure.
2457
 */
2458 View Code Duplication
function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
0 ignored issues
show
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2459
	$post = get_post($post);
2460
2461
	if ( ! $post ) {
2462
		return false;
2463
	}
2464
2465
	if ( $gmt )
2466
		$time = $post->post_modified_gmt;
2467
	else
2468
		$time = $post->post_modified;
2469
	$time = mysql2date($d, $time, $translate);
2470
2471
	/**
2472
	 * Filters the localized time a post was last modified.
2473
	 *
2474
	 * @since 2.8.0
2475
	 *
2476
	 * @param string $time The formatted time.
2477
	 * @param string $d    The date format. Accepts 'G', 'U', or php date format. Default 'U'.
2478
	 * @param bool   $gmt  Whether to return the GMT time. Default false.
2479
	 */
2480
	return apply_filters( 'get_post_modified_time', $time, $d, $gmt );
2481
}
2482
2483
/**
2484
 * Display the weekday on which the post was written.
2485
 *
2486
 * @since 0.71
2487
 *
2488
 * @global WP_Locale $wp_locale
2489
 */
2490
function the_weekday() {
2491
	global $wp_locale;
2492
	$the_weekday = $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
2493
2494
	/**
2495
	 * Filters the weekday on which the post was written, for display.
2496
	 *
2497
	 * @since 0.71
2498
	 *
2499
	 * @param string $the_weekday
2500
	 */
2501
	echo apply_filters( 'the_weekday', $the_weekday );
2502
}
2503
2504
/**
2505
 * Display the weekday on which the post was written.
2506
 *
2507
 * Will only output the weekday if the current post's weekday is different from
2508
 * the previous one output.
2509
 *
2510
 * @since 0.71
2511
 *
2512
 * @global WP_Locale       $wp_locale
2513
 * @global string|int|bool $currentday
2514
 * @global string|int|bool $previousweekday
2515
 *
2516
 * @param string $before Optional Output before the date.
2517
 * @param string $after Optional Output after the date.
2518
 */
2519
function the_weekday_date($before='',$after='') {
2520
	global $wp_locale, $currentday, $previousweekday;
2521
	$the_weekday_date = '';
2522
	if ( $currentday != $previousweekday ) {
2523
		$the_weekday_date .= $before;
2524
		$the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
2525
		$the_weekday_date .= $after;
2526
		$previousweekday = $currentday;
2527
	}
2528
2529
	/**
2530
	 * Filters the localized date on which the post was written, for display.
2531
	 *
2532
	 * @since 0.71
2533
	 *
2534
	 * @param string $the_weekday_date
2535
	 * @param string $before           The HTML to output before the date.
2536
	 * @param string $after            The HTML to output after the date.
2537
	 */
2538
	$the_weekday_date = apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after );
2539
	echo $the_weekday_date;
2540
}
2541
2542
/**
2543
 * Fire the wp_head action.
2544
 *
2545
 * See {@see 'wp_head'}.
2546
 *
2547
 * @since 1.2.0
2548
 */
2549
function wp_head() {
2550
	/**
2551
	 * Prints scripts or data in the head tag on the front end.
2552
	 *
2553
	 * @since 1.5.0
2554
	 */
2555
	do_action( 'wp_head' );
2556
}
2557
2558
/**
2559
 * Fire the wp_footer action.
2560
 *
2561
 * See {@see 'wp_footer'}.
2562
 *
2563
 * @since 1.5.1
2564
 */
2565
function wp_footer() {
2566
	/**
2567
	 * Prints scripts or data before the closing body tag on the front end.
2568
	 *
2569
	 * @since 1.5.1
2570
	 */
2571
	do_action( 'wp_footer' );
2572
}
2573
2574
/**
2575
 * Display the links to the general feeds.
2576
 *
2577
 * @since 2.8.0
2578
 *
2579
 * @param array $args Optional arguments.
2580
 */
2581
function feed_links( $args = array() ) {
2582
	if ( !current_theme_supports('automatic-feed-links') )
2583
		return;
2584
2585
	$defaults = array(
2586
		/* translators: Separator between blog name and feed type in feed links */
2587
		'separator'	=> _x('&raquo;', 'feed link'),
2588
		/* translators: 1: blog title, 2: separator (raquo) */
2589
		'feedtitle'	=> __('%1$s %2$s Feed'),
2590
		/* translators: 1: blog title, 2: separator (raquo) */
2591
		'comstitle'	=> __('%1$s %2$s Comments Feed'),
2592
	);
2593
2594
	$args = wp_parse_args( $args, $defaults );
2595
2596
	/**
2597
	 * Filters whether to display the posts feed link.
2598
	 *
2599
	 * @since 4.4.0
2600
	 *
2601
	 * @param bool $show Whether to display the posts feed link. Default true.
2602
	 */
2603 View Code Duplication
	if ( apply_filters( 'feed_links_show_posts_feed', true ) ) {
2604
		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";
2605
	}
2606
2607
	/**
2608
	 * Filters whether to display the comments feed link.
2609
	 *
2610
	 * @since 4.4.0
2611
	 *
2612
	 * @param bool $show Whether to display the comments feed link. Default true.
2613
	 */
2614 View Code Duplication
	if ( apply_filters( 'feed_links_show_comments_feed', true ) ) {
2615
		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";
2616
	}
2617
}
2618
2619
/**
2620
 * Display the links to the extra feeds such as category feeds.
2621
 *
2622
 * @since 2.8.0
2623
 *
2624
 * @param array $args Optional arguments.
2625
 */
2626
function feed_links_extra( $args = array() ) {
2627
	$defaults = array(
2628
		/* translators: Separator between blog name and feed type in feed links */
2629
		'separator'   => _x('&raquo;', 'feed link'),
2630
		/* translators: 1: blog name, 2: separator(raquo), 3: post title */
2631
		'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
2632
		/* translators: 1: blog name, 2: separator(raquo), 3: category name */
2633
		'cattitle'    => __('%1$s %2$s %3$s Category Feed'),
2634
		/* translators: 1: blog name, 2: separator(raquo), 3: tag name */
2635
		'tagtitle'    => __('%1$s %2$s %3$s Tag Feed'),
2636
		/* translators: 1: blog name, 2: separator(raquo), 3: term name, 4: taxonomy singular name */
2637
		'taxtitle'    => __('%1$s %2$s %3$s %4$s Feed'),
2638
		/* translators: 1: blog name, 2: separator(raquo), 3: author name  */
2639
		'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
2640
		/* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
2641
		'searchtitle' => __('%1$s %2$s Search Results for &#8220;%3$s&#8221; Feed'),
2642
		/* translators: 1: blog name, 2: separator(raquo), 3: post type name */
2643
		'posttypetitle' => __('%1$s %2$s %3$s Feed'),
2644
	);
2645
2646
	$args = wp_parse_args( $args, $defaults );
2647
2648
	if ( is_singular() ) {
2649
		$id = 0;
2650
		$post = get_post( $id );
2651
2652
		if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
2653
			$title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], the_title_attribute( array( 'echo' => false ) ) );
2654
			$href = get_post_comments_feed_link( $post->ID );
2655
		}
2656
	} elseif ( is_post_type_archive() ) {
2657
		$post_type = get_query_var( 'post_type' );
2658
		if ( is_array( $post_type ) )
2659
			$post_type = reset( $post_type );
2660
2661
		$post_type_obj = get_post_type_object( $post_type );
2662
		$title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name );
2663
		$href = get_post_type_archive_feed_link( $post_type_obj->name );
2664
	} elseif ( is_category() ) {
2665
		$term = get_queried_object();
2666
2667 View Code Duplication
		if ( $term ) {
2668
			$title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name );
2669
			$href = get_category_feed_link( $term->term_id );
2670
		}
2671
	} elseif ( is_tag() ) {
2672
		$term = get_queried_object();
2673
2674 View Code Duplication
		if ( $term ) {
2675
			$title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name );
2676
			$href = get_tag_feed_link( $term->term_id );
2677
		}
2678
	} elseif ( is_tax() ) {
2679
 		$term = get_queried_object();
2680
 		$tax = get_taxonomy( $term->taxonomy );
2681
 		$title = sprintf( $args['taxtitle'], get_bloginfo('name'), $args['separator'], $term->name, $tax->labels->singular_name );
2682
 		$href = get_term_feed_link( $term->term_id, $term->taxonomy );
2683
	} elseif ( is_author() ) {
2684
		$author_id = intval( get_query_var('author') );
2685
2686
		$title = sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) );
2687
		$href = get_author_feed_link( $author_id );
2688
	} elseif ( is_search() ) {
2689
		$title = sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) );
2690
		$href = get_search_feed_link();
2691
	} elseif ( is_post_type_archive() ) {
2692
		$title = sprintf( $args['posttypetitle'], get_bloginfo('name'), $args['separator'], post_type_archive_title( '', false ) );
2693
		$post_type_obj = get_queried_object();
2694
		if ( $post_type_obj )
2695
			$href = get_post_type_archive_feed_link( $post_type_obj->name );
2696
	}
2697
2698
	if ( isset($title) && isset($href) )
2699
		echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n";
0 ignored issues
show
It seems like $href can also be of type false; however, esc_url() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
2700
}
2701
2702
/**
2703
 * Display the link to the Really Simple Discovery service endpoint.
2704
 *
2705
 * @link http://archipelago.phrasewise.com/rsd
2706
 * @since 2.0.0
2707
 */
2708
function rsd_link() {
2709
	echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) ) . '" />' . "\n";
2710
}
2711
2712
/**
2713
 * Display the link to the Windows Live Writer manifest file.
2714
 *
2715
 * @link https://msdn.microsoft.com/en-us/library/bb463265.aspx
2716
 * @since 2.3.1
2717
 */
2718
function wlwmanifest_link() {
2719
	echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="',
2720
		includes_url( 'wlwmanifest.xml' ), '" /> ', "\n";
2721
}
2722
2723
/**
2724
 * Displays a noindex meta tag if required by the blog configuration.
2725
 *
2726
 * If a blog is marked as not being public then the noindex meta tag will be
2727
 * output to tell web robots not to index the page content. Add this to the
2728
 * {@see 'wp_head'} action.
2729
 *
2730
 * Typical usage is as a {@see 'wp_head'} callback:
2731
 *
2732
 *     add_action( 'wp_head', 'noindex' );
2733
 *
2734
 * @see wp_no_robots
2735
 *
2736
 * @since 2.1.0
2737
 */
2738
function noindex() {
2739
	// If the blog is not public, tell robots to go away.
2740
	if ( '0' == get_option('blog_public') )
2741
		wp_no_robots();
2742
}
2743
2744
/**
2745
 * Display a noindex meta tag.
2746
 *
2747
 * Outputs a noindex meta tag that tells web robots not to index the page content.
2748
 * Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_no_robots' );
2749
 *
2750
 * @since 3.3.0
2751
 */
2752
function wp_no_robots() {
2753
	echo "<meta name='robots' content='noindex,follow' />\n";
2754
}
2755
2756
/**
2757
 * Display site icon meta tags.
2758
 *
2759
 * @since 4.3.0
2760
 *
2761
 * @link https://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon HTML5 specification link icon.
2762
 */
2763
function wp_site_icon() {
2764
	if ( ! has_site_icon() && ! is_customize_preview() ) {
2765
		return;
2766
	}
2767
2768
	$meta_tags = array(
2769
		sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( get_site_icon_url( 32 ) ) ),
2770
		sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( get_site_icon_url( 192 ) ) ),
2771
		sprintf( '<link rel="apple-touch-icon-precomposed" href="%s" />', esc_url( get_site_icon_url( 180 ) ) ),
2772
		sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( get_site_icon_url( 270 ) ) ),
2773
	);
2774
2775
	/**
2776
	 * Filters the site icon meta tags, so Plugins can add their own.
2777
	 *
2778
	 * @since 4.3.0
2779
	 *
2780
	 * @param array $meta_tags Site Icon meta elements.
2781
	 */
2782
	$meta_tags = apply_filters( 'site_icon_meta_tags', $meta_tags );
2783
	$meta_tags = array_filter( $meta_tags );
2784
2785
	foreach ( $meta_tags as $meta_tag ) {
2786
		echo "$meta_tag\n";
2787
	}
2788
}
2789
2790
/**
2791
 * Prints resource hints to browsers for pre-fetching, pre-rendering
2792
 * and pre-connecting to web sites.
2793
 *
2794
 * Gives hints to browsers to prefetch specific pages or render them
2795
 * in the background, to perform DNS lookups or to begin the connection
2796
 * handshake (DNS, TCP, TLS) in the background.
2797
 *
2798
 * These performance improving indicators work by using `<link rel"…">`.
2799
 *
2800
 * @since 4.6.0
2801
 */
2802
function wp_resource_hints() {
2803
	$hints = array(
2804
		'dns-prefetch' => wp_dependencies_unique_hosts(),
2805
		'preconnect'   => array(),
2806
		'prefetch'     => array(),
2807
		'prerender'    => array(),
2808
	);
2809
2810
	/*
2811
	 * Add DNS prefetch for the Emoji CDN.
2812
	 * The path is removed in the foreach loop below.
2813
	 */
2814
	/** This filter is documented in wp-includes/formatting.php */
2815
	$hints['dns-prefetch'][] = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' );
2816
2817
	foreach ( $hints as $relation_type => $urls ) {
2818
		/**
2819
		 * Filters domains and URLs for resource hints of relation type.
2820
		 *
2821
		 * @since 4.6.0
2822
		 *
2823
		 * @param array  $urls          URLs to print for resource hints.
2824
		 * @param string $relation_type The relation type the URLs are printed for, e.g. 'preconnect' or 'prerender'.
2825
		 */
2826
		$urls = apply_filters( 'wp_resource_hints', $urls, $relation_type );
2827
2828
		foreach ( $urls as $key => $url ) {
2829
			$url = esc_url( $url, array( 'http', 'https' ) );
2830
			if ( ! $url ) {
2831
				unset( $urls[ $key ] );
2832
				continue;
2833
			}
2834
2835
			if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) {
2836
				$parsed = wp_parse_url( $url );
2837
				if ( empty( $parsed['host'] ) ) {
2838
					unset( $urls[ $key ] );
2839
					continue;
2840
				}
2841
2842
				if ( 'preconnect' === $relation_type && ! empty( $parsed['scheme'] ) ) {
2843
					$url = $parsed['scheme'] . '://' . $parsed['host'];
2844
				} else {
2845
					// Use protocol-relative URLs for dns-prefetch or if scheme is missing.
2846
					$url = '//' . $parsed['host'];
2847
				}
2848
			}
2849
2850
			$urls[ $key ] = $url;
2851
		}
2852
2853
		$urls = array_unique( $urls );
2854
2855
		foreach ( $urls as $url ) {
2856
			printf( "<link rel='%s' href='%s'>\n", $relation_type, $url );
2857
		}
2858
	}
2859
}
2860
2861
/**
2862
 * Retrieves a list of unique hosts of all enqueued scripts and styles.
2863
 *
2864
 * @since 4.6.0
2865
 *
2866
 * @return array A list of unique hosts of enqueued scripts and styles.
2867
 */
2868
function wp_dependencies_unique_hosts() {
2869
	global $wp_scripts, $wp_styles;
2870
2871
	$unique_hosts = array();
2872
2873
	foreach ( array( $wp_scripts, $wp_styles ) as $dependencies ) {
2874
		if ( $dependencies instanceof WP_Dependencies && ! empty( $dependencies->queue ) ) {
2875
			foreach ( $dependencies->queue as $handle ) {
2876
				if ( ! isset( $dependencies->registered[ $handle ] ) ) {
2877
					continue;
2878
				}
2879
2880
				/* @var _WP_Dependency $dependency */
2881
				$dependency = $dependencies->registered[ $handle ];
2882
				$parsed     = wp_parse_url( $dependency->src );
2883
2884
				if ( ! empty( $parsed['host'] ) && ! in_array( $parsed['host'], $unique_hosts ) && $parsed['host'] !== $_SERVER['SERVER_NAME'] ) {
2885
					$unique_hosts[] = $parsed['host'];
2886
				}
2887
			}
2888
		}
2889
	}
2890
2891
	return $unique_hosts;
2892
}
2893
2894
/**
2895
 * Whether the user should have a WYSIWIG editor.
2896
 *
2897
 * Checks that the user requires a WYSIWIG editor and that the editor is
2898
 * supported in the users browser.
2899
 *
2900
 * @since 2.0.0
2901
 *
2902
 * @global bool $wp_rich_edit
2903
 * @global bool $is_gecko
2904
 * @global bool $is_opera
2905
 * @global bool $is_safari
2906
 * @global bool $is_chrome
2907
 * @global bool $is_IE
2908
 *
2909
 * @return bool
2910
 */
2911
function user_can_richedit() {
2912
	global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE, $is_edge;
2913
2914
	if ( !isset($wp_rich_edit) ) {
2915
		$wp_rich_edit = false;
2916
2917
		if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users
2918
			if ( $is_safari ) {
2919
				$wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 );
2920
			} elseif ( $is_gecko || $is_chrome || $is_IE || $is_edge || ( $is_opera && !wp_is_mobile() ) ) {
2921
				$wp_rich_edit = true;
2922
			}
2923
		}
2924
	}
2925
2926
	/**
2927
	 * Filters whether the user can access the rich (Visual) editor.
2928
	 *
2929
	 * @since 2.1.0
2930
	 *
2931
	 * @param bool $wp_rich_edit Whether the user can access to the rich (Visual) editor.
2932
	 */
2933
	return apply_filters( 'user_can_richedit', $wp_rich_edit );
2934
}
2935
2936
/**
2937
 * Find out which editor should be displayed by default.
2938
 *
2939
 * Works out which of the two editors to display as the current editor for a
2940
 * user. The 'html' setting is for the "Text" editor tab.
2941
 *
2942
 * @since 2.5.0
2943
 *
2944
 * @return string Either 'tinymce', or 'html', or 'test'
2945
 */
2946
function wp_default_editor() {
2947
	$r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
2948
	if ( wp_get_current_user() ) { // look for cookie
2949
		$ed = get_user_setting('editor', 'tinymce');
2950
		$r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
2951
	}
2952
2953
	/**
2954
	 * Filters which editor should be displayed by default.
2955
	 *
2956
	 * @since 2.5.0
2957
	 *
2958
	 * @param array $r An array of editors. Accepts 'tinymce', 'html', 'test'.
2959
	 */
2960
	return apply_filters( 'wp_default_editor', $r );
2961
}
2962
2963
/**
2964
 * Renders an editor.
2965
 *
2966
 * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
2967
 * _WP_Editors should not be used directly. See https://core.trac.wordpress.org/ticket/17144.
2968
 *
2969
 * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
2970
 * running wp_editor() inside of a meta box is not a good idea unless only Quicktags is used.
2971
 * On the post edit screen several actions can be used to include additional editors
2972
 * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
2973
 * See https://core.trac.wordpress.org/ticket/19173 for more information.
2974
 *
2975
 * @see _WP_Editors::editor()
2976
 * @since 3.3.0
2977
 *
2978
 * @param string $content   Initial content for the editor.
2979
 * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/.
2980
 * @param array  $settings  See _WP_Editors::editor().
2981
 */
2982
function wp_editor( $content, $editor_id, $settings = array() ) {
2983
	if ( ! class_exists( '_WP_Editors', false ) )
2984
		require( ABSPATH . WPINC . '/class-wp-editor.php' );
2985
2986
	_WP_Editors::editor($content, $editor_id, $settings);
2987
}
2988
2989
/**
2990
 * Retrieves the contents of the search WordPress query variable.
2991
 *
2992
 * The search query string is passed through esc_attr() to ensure that it is safe
2993
 * for placing in an html attribute.
2994
 *
2995
 * @since 2.3.0
2996
 *
2997
 * @param bool $escaped Whether the result is escaped. Default true.
2998
 * 	                    Only use when you are later escaping it. Do not use unescaped.
2999
 * @return string
3000
 */
3001
function get_search_query( $escaped = true ) {
3002
	/**
3003
	 * Filters the contents of the search query variable.
3004
	 *
3005
	 * @since 2.3.0
3006
	 *
3007
	 * @param mixed $search Contents of the search query variable.
3008
	 */
3009
	$query = apply_filters( 'get_search_query', get_query_var( 's' ) );
3010
3011
	if ( $escaped )
3012
		$query = esc_attr( $query );
3013
	return $query;
3014
}
3015
3016
/**
3017
 * Displays the contents of the search query variable.
3018
 *
3019
 * The search query string is passed through esc_attr() to ensure that it is safe
3020
 * for placing in an html attribute.
3021
 *
3022
 * @since 2.1.0
3023
 */
3024
function the_search_query() {
3025
	/**
3026
	 * Filters the contents of the search query variable for display.
3027
	 *
3028
	 * @since 2.3.0
3029
	 *
3030
	 * @param mixed $search Contents of the search query variable.
3031
	 */
3032
	echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
3033
}
3034
3035
/**
3036
 * Gets the language attributes for the html tag.
3037
 *
3038
 * Builds up a set of html attributes containing the text direction and language
3039
 * information for the page.
3040
 *
3041
 * @since 4.3.0
3042
 *
3043
 * @param string $doctype Optional. The type of html document. Accepts 'xhtml' or 'html'. Default 'html'.
3044
 */
3045
function get_language_attributes( $doctype = 'html' ) {
3046
	$attributes = array();
3047
3048
	if ( function_exists( 'is_rtl' ) && is_rtl() )
3049
		$attributes[] = 'dir="rtl"';
3050
3051
	if ( $lang = get_bloginfo('language') ) {
3052
		if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
3053
			$attributes[] = "lang=\"$lang\"";
3054
3055
		if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
3056
			$attributes[] = "xml:lang=\"$lang\"";
3057
	}
3058
3059
	$output = implode(' ', $attributes);
3060
3061
	/**
3062
	 * Filters the language attributes for display in the html tag.
3063
	 *
3064
	 * @since 2.5.0
3065
	 * @since 4.3.0 Added the `$doctype` parameter.
3066
	 *
3067
	 * @param string $output A space-separated list of language attributes.
3068
	 * @param string $doctype The type of html document (xhtml|html).
3069
	 */
3070
	return apply_filters( 'language_attributes', $output, $doctype );
3071
}
3072
3073
/**
3074
 * Displays the language attributes for the html tag.
3075
 *
3076
 * Builds up a set of html attributes containing the text direction and language
3077
 * information for the page.
3078
 *
3079
 * @since 2.1.0
3080
 * @since 4.3.0 Converted into a wrapper for get_language_attributes().
3081
 *
3082
 * @param string $doctype Optional. The type of html document. Accepts 'xhtml' or 'html'. Default 'html'.
3083
 */
3084
function language_attributes( $doctype = 'html' ) {
3085
	echo get_language_attributes( $doctype );
3086
}
3087
3088
/**
3089
 * Retrieve paginated link for archive post pages.
3090
 *
3091
 * Technically, the function can be used to create paginated link list for any
3092
 * area. The 'base' argument is used to reference the url, which will be used to
3093
 * create the paginated links. The 'format' argument is then used for replacing
3094
 * the page number. It is however, most likely and by default, to be used on the
3095
 * archive post pages.
3096
 *
3097
 * The 'type' argument controls format of the returned value. The default is
3098
 * 'plain', which is just a string with the links separated by a newline
3099
 * character. The other possible values are either 'array' or 'list'. The
3100
 * 'array' value will return an array of the paginated link list to offer full
3101
 * control of display. The 'list' value will place all of the paginated links in
3102
 * an unordered HTML list.
3103
 *
3104
 * The 'total' argument is the total amount of pages and is an integer. The
3105
 * 'current' argument is the current page number and is also an integer.
3106
 *
3107
 * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
3108
 * and the '%_%' is required. The '%_%' will be replaced by the contents of in
3109
 * the 'format' argument. An example for the 'format' argument is "?page=%#%"
3110
 * and the '%#%' is also required. The '%#%' will be replaced with the page
3111
 * number.
3112
 *
3113
 * You can include the previous and next links in the list by setting the
3114
 * 'prev_next' argument to true, which it is by default. You can set the
3115
 * previous text, by using the 'prev_text' argument. You can set the next text
3116
 * by setting the 'next_text' argument.
3117
 *
3118
 * If the 'show_all' argument is set to true, then it will show all of the pages
3119
 * instead of a short list of the pages near the current page. By default, the
3120
 * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
3121
 * arguments. The 'end_size' argument is how many numbers on either the start
3122
 * and the end list edges, by default is 1. The 'mid_size' argument is how many
3123
 * numbers to either side of current page, but not including current page.
3124
 *
3125
 * It is possible to add query vars to the link by using the 'add_args' argument
3126
 * and see add_query_arg() for more information.
3127
 *
3128
 * The 'before_page_number' and 'after_page_number' arguments allow users to
3129
 * augment the links themselves. Typically this might be to add context to the
3130
 * numbered links so that screen reader users understand what the links are for.
3131
 * The text strings are added before and after the page number - within the
3132
 * anchor tag.
3133
 *
3134
 * @since 2.1.0
3135
 *
3136
 * @global WP_Query   $wp_query
3137
 * @global WP_Rewrite $wp_rewrite
3138
 *
3139
 * @param string|array $args {
3140
 *     Optional. Array or string of arguments for generating paginated links for archives.
3141
 *
3142
 *     @type string $base               Base of the paginated url. Default empty.
3143
 *     @type string $format             Format for the pagination structure. Default empty.
3144
 *     @type int    $total              The total amount of pages. Default is the value WP_Query's
3145
 *                                      `max_num_pages` or 1.
3146
 *     @type int    $current            The current page number. Default is 'paged' query var or 1.
3147
 *     @type bool   $show_all           Whether to show all pages. Default false.
3148
 *     @type int    $end_size           How many numbers on either the start and the end list edges.
3149
 *                                      Default 1.
3150
 *     @type int    $mid_size           How many numbers to either side of the current pages. Default 2.
3151
 *     @type bool   $prev_next          Whether to include the previous and next links in the list. Default true.
3152
 *     @type bool   $prev_text          The previous page text. Default '« Previous'.
3153
 *     @type bool   $next_text          The next page text. Default '« Previous'.
3154
 *     @type string $type               Controls format of the returned value. Possible values are 'plain',
3155
 *                                      'array' and 'list'. Default is 'plain'.
3156
 *     @type array  $add_args           An array of query args to add. Default false.
3157
 *     @type string $add_fragment       A string to append to each link. Default empty.
3158
 *     @type string $before_page_number A string to appear before the page number. Default empty.
3159
 *     @type string $after_page_number  A string to append after the page number. Default empty.
3160
 * }
3161
 * @return array|string|void String of page links or array of page links.
3162
 */
3163
function paginate_links( $args = '' ) {
3164
	global $wp_query, $wp_rewrite;
3165
3166
	// Setting up default values based on the current URL.
3167
	$pagenum_link = html_entity_decode( get_pagenum_link() );
3168
	$url_parts    = explode( '?', $pagenum_link );
3169
3170
	// Get max pages and current page out of the current query, if available.
3171
	$total   = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
3172
	$current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
3173
3174
	// Append the format placeholder to the base URL.
3175
	$pagenum_link = trailingslashit( $url_parts[0] ) . '%_%';
3176
3177
	// URL base depends on permalink settings.
3178
	$format  = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
3179
	$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
3180
3181
	$defaults = array(
3182
		'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
3183
		'format' => $format, // ?page=%#% : %#% is replaced by the page number
3184
		'total' => $total,
3185
		'current' => $current,
3186
		'show_all' => false,
3187
		'prev_next' => true,
3188
		'prev_text' => __('&laquo; Previous'),
3189
		'next_text' => __('Next &raquo;'),
3190
		'end_size' => 1,
3191
		'mid_size' => 2,
3192
		'type' => 'plain',
3193
		'add_args' => array(), // array of query args to add
3194
		'add_fragment' => '',
3195
		'before_page_number' => '',
3196
		'after_page_number' => ''
3197
	);
3198
3199
	$args = wp_parse_args( $args, $defaults );
3200
3201
	if ( ! is_array( $args['add_args'] ) ) {
3202
		$args['add_args'] = array();
3203
	}
3204
3205
	// Merge additional query vars found in the original URL into 'add_args' array.
3206
	if ( isset( $url_parts[1] ) ) {
3207
		// Find the format argument.
3208
		$format = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) );
3209
		$format_query = isset( $format[1] ) ? $format[1] : '';
3210
		wp_parse_str( $format_query, $format_args );
3211
3212
		// Find the query args of the requested URL.
3213
		wp_parse_str( $url_parts[1], $url_query_args );
3214
3215
		// Remove the format argument from the array of query arguments, to avoid overwriting custom format.
3216
		foreach ( $format_args as $format_arg => $format_arg_value ) {
3217
			unset( $url_query_args[ $format_arg ] );
3218
		}
3219
3220
		$args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ) );
3221
	}
3222
3223
	// Who knows what else people pass in $args
3224
	$total = (int) $args['total'];
3225
	if ( $total < 2 ) {
3226
		return;
3227
	}
3228
	$current  = (int) $args['current'];
3229
	$end_size = (int) $args['end_size']; // Out of bounds?  Make it the default.
3230
	if ( $end_size < 1 ) {
3231
		$end_size = 1;
3232
	}
3233
	$mid_size = (int) $args['mid_size'];
3234
	if ( $mid_size < 0 ) {
3235
		$mid_size = 2;
3236
	}
3237
	$add_args = $args['add_args'];
3238
	$r = '';
3239
	$page_links = array();
3240
	$dots = false;
3241
3242
	if ( $args['prev_next'] && $current && 1 < $current ) :
3243
		$link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] );
3244
		$link = str_replace( '%#%', $current - 1, $link );
3245
		if ( $add_args )
3246
			$link = add_query_arg( $add_args, $link );
3247
		$link .= $args['add_fragment'];
3248
3249
		/**
3250
		 * Filters the paginated links for the given archive pages.
3251
		 *
3252
		 * @since 3.0.0
3253
		 *
3254
		 * @param string $link The paginated link URL.
3255
		 */
3256
		$page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['prev_text'] . '</a>';
3257
	endif;
3258
	for ( $n = 1; $n <= $total; $n++ ) :
3259
		if ( $n == $current ) :
3260
			$page_links[] = "<span class='page-numbers current'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</span>";
3261
			$dots = true;
3262
		else :
3263
			if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
3264
				$link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] );
3265
				$link = str_replace( '%#%', $n, $link );
3266
				if ( $add_args )
3267
					$link = add_query_arg( $add_args, $link );
3268
				$link .= $args['add_fragment'];
3269
3270
				/** This filter is documented in wp-includes/general-template.php */
3271
				$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>";
3272
				$dots = true;
3273
			elseif ( $dots && ! $args['show_all'] ) :
3274
				$page_links[] = '<span class="page-numbers dots">' . __( '&hellip;' ) . '</span>';
3275
				$dots = false;
3276
			endif;
3277
		endif;
3278
	endfor;
3279
	if ( $args['prev_next'] && $current && ( $current < $total || -1 == $total ) ) :
3280
		$link = str_replace( '%_%', $args['format'], $args['base'] );
3281
		$link = str_replace( '%#%', $current + 1, $link );
3282
		if ( $add_args )
3283
			$link = add_query_arg( $add_args, $link );
3284
		$link .= $args['add_fragment'];
3285
3286
		/** This filter is documented in wp-includes/general-template.php */
3287
		$page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['next_text'] . '</a>';
3288
	endif;
3289
	switch ( $args['type'] ) {
3290
		case 'array' :
3291
			return $page_links;
3292
3293
		case 'list' :
3294
			$r .= "<ul class='page-numbers'>\n\t<li>";
3295
			$r .= join("</li>\n\t<li>", $page_links);
3296
			$r .= "</li>\n</ul>\n";
3297
			break;
3298
3299
		default :
3300
			$r = join("\n", $page_links);
3301
			break;
3302
	}
3303
	return $r;
3304
}
3305
3306
/**
3307
 * Registers an admin colour scheme css file.
3308
 *
3309
 * Allows a plugin to register a new admin colour scheme. For example:
3310
 *
3311
 *     wp_admin_css_color( 'classic', __( 'Classic' ), admin_url( "css/colors-classic.css" ), array(
3312
 *         '#07273E', '#14568A', '#D54E21', '#2683AE'
3313
 *     ) );
3314
 *
3315
 * @since 2.5.0
3316
 *
3317
 * @global array $_wp_admin_css_colors
3318
 *
3319
 * @param string $key    The unique key for this theme.
3320
 * @param string $name   The name of the theme.
3321
 * @param string $url    The URL of the CSS file containing the color scheme.
3322
 * @param array  $colors Optional. An array of CSS color definition strings which are used
3323
 *                       to give the user a feel for the theme.
3324
 * @param array  $icons {
3325
 *     Optional. CSS color definitions used to color any SVG icons.
3326
 *
3327
 *     @type string $base    SVG icon base color.
3328
 *     @type string $focus   SVG icon color on focus.
3329
 *     @type string $current SVG icon color of current admin menu link.
3330
 * }
3331
 */
3332
function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) {
3333
	global $_wp_admin_css_colors;
3334
3335
	if ( !isset($_wp_admin_css_colors) )
3336
		$_wp_admin_css_colors = array();
3337
3338
	$_wp_admin_css_colors[$key] = (object) array(
3339
		'name' => $name,
3340
		'url' => $url,
3341
		'colors' => $colors,
3342
		'icon_colors' => $icons,
3343
	);
3344
}
3345
3346
/**
3347
 * Registers the default Admin color schemes
3348
 *
3349
 * @since 3.0.0
3350
 *
3351
 * @global string $wp_version
3352
 */
3353
function register_admin_color_schemes() {
3354
	$suffix = is_rtl() ? '-rtl' : '';
3355
	$suffix .= SCRIPT_DEBUG ? '' : '.min';
3356
3357
	wp_admin_css_color( 'fresh', _x( 'Default', 'admin color scheme' ),
3358
		false,
0 ignored issues
show
false is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
3359
		array( '#222', '#333', '#0073aa', '#00a0d2' ),
3360
		array( 'base' => '#82878c', 'focus' => '#00a0d2', 'current' => '#fff' )
3361
	);
3362
3363
	// Other color schemes are not available when running out of src
3364
	if ( false !== strpos( $GLOBALS['wp_version'], '-src' ) )
3365
		return;
3366
3367
	wp_admin_css_color( 'light', _x( 'Light', 'admin color scheme' ),
3368
		admin_url( "css/colors/light/colors$suffix.css" ),
3369
		array( '#e5e5e5', '#999', '#d64e07', '#04a4cc' ),
3370
		array( 'base' => '#999', 'focus' => '#ccc', 'current' => '#ccc' )
3371
	);
3372
3373
	wp_admin_css_color( 'blue', _x( 'Blue', 'admin color scheme' ),
3374
		admin_url( "css/colors/blue/colors$suffix.css" ),
3375
		array( '#096484', '#4796b3', '#52accc', '#74B6CE' ),
3376
		array( 'base' => '#e5f8ff', 'focus' => '#fff', 'current' => '#fff' )
3377
	);
3378
3379
	wp_admin_css_color( 'midnight', _x( 'Midnight', 'admin color scheme' ),
3380
		admin_url( "css/colors/midnight/colors$suffix.css" ),
3381
		array( '#25282b', '#363b3f', '#69a8bb', '#e14d43' ),
3382
		array( 'base' => '#f1f2f3', 'focus' => '#fff', 'current' => '#fff' )
3383
	);
3384
3385
	wp_admin_css_color( 'sunrise', _x( 'Sunrise', 'admin color scheme' ),
3386
		admin_url( "css/colors/sunrise/colors$suffix.css" ),
3387
		array( '#b43c38', '#cf4944', '#dd823b', '#ccaf0b' ),
3388
		array( 'base' => '#f3f1f1', 'focus' => '#fff', 'current' => '#fff' )
3389
	);
3390
3391
	wp_admin_css_color( 'ectoplasm', _x( 'Ectoplasm', 'admin color scheme' ),
3392
		admin_url( "css/colors/ectoplasm/colors$suffix.css" ),
3393
		array( '#413256', '#523f6d', '#a3b745', '#d46f15' ),
3394
		array( 'base' => '#ece6f6', 'focus' => '#fff', 'current' => '#fff' )
3395
	);
3396
3397
	wp_admin_css_color( 'ocean', _x( 'Ocean', 'admin color scheme' ),
3398
		admin_url( "css/colors/ocean/colors$suffix.css" ),
3399
		array( '#627c83', '#738e96', '#9ebaa0', '#aa9d88' ),
3400
		array( 'base' => '#f2fcff', 'focus' => '#fff', 'current' => '#fff' )
3401
	);
3402
3403
	wp_admin_css_color( 'coffee', _x( 'Coffee', 'admin color scheme' ),
3404
		admin_url( "css/colors/coffee/colors$suffix.css" ),
3405
		array( '#46403c', '#59524c', '#c7a589', '#9ea476' ),
3406
		array( 'base' => '#f3f2f1', 'focus' => '#fff', 'current' => '#fff' )
3407
	);
3408
3409
}
3410
3411
/**
3412
 * Displays the URL of a WordPress admin CSS file.
3413
 *
3414
 * @see WP_Styles::_css_href and its {@see 'style_loader_src'} filter.
3415
 *
3416
 * @since 2.3.0
3417
 *
3418
 * @param string $file file relative to wp-admin/ without its ".css" extension.
3419
 * @return string
3420
 */
3421
function wp_admin_css_uri( $file = 'wp-admin' ) {
3422
	if ( defined('WP_INSTALLING') ) {
3423
		$_file = "./$file.css";
3424
	} else {
3425
		$_file = admin_url("$file.css");
3426
	}
3427
	$_file = add_query_arg( 'version', get_bloginfo( 'version' ),  $_file );
3428
3429
	/**
3430
	 * Filters the URI of a WordPress admin CSS file.
3431
	 *
3432
	 * @since 2.3.0
3433
	 *
3434
	 * @param string $_file Relative path to the file with query arguments attached.
3435
	 * @param string $file  Relative path to the file, minus its ".css" extension.
3436
	 */
3437
	return apply_filters( 'wp_admin_css_uri', $_file, $file );
3438
}
3439
3440
/**
3441
 * Enqueues or directly prints a stylesheet link to the specified CSS file.
3442
 *
3443
 * "Intelligently" decides to enqueue or to print the CSS file. If the
3444
 * {@see 'wp_print_styles'} action has *not* yet been called, the CSS file will be
3445
 * enqueued. If the {@see 'wp_print_styles'} action has been called, the CSS link will
3446
 * be printed. Printing may be forced by passing true as the $force_echo
3447
 * (second) parameter.
3448
 *
3449
 * For backward compatibility with WordPress 2.3 calling method: If the $file
3450
 * (first) parameter does not correspond to a registered CSS file, we assume
3451
 * $file is a file relative to wp-admin/ without its ".css" extension. A
3452
 * stylesheet link to that generated URL is printed.
3453
 *
3454
 * @since 2.3.0
3455
 *
3456
 * @param string $file       Optional. Style handle name or file name (without ".css" extension) relative
3457
 * 	                         to wp-admin/. Defaults to 'wp-admin'.
3458
 * @param bool   $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
3459
 */
3460
function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
3461
	// For backward compatibility
3462
	$handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
3463
3464
	if ( wp_styles()->query( $handle ) ) {
3465
		if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
3466
			wp_print_styles( $handle );
3467
		else // Add to style queue
3468
			wp_enqueue_style( $handle );
3469
		return;
3470
	}
3471
3472
	/**
3473
	 * Filters the stylesheet link to the specified CSS file.
3474
	 *
3475
	 * If the site is set to display right-to-left, the RTL stylesheet link
3476
	 * will be used instead.
3477
	 *
3478
	 * @since 2.3.0
3479
	 *
3480
	 * @param string $file Style handle name or filename (without ".css" extension)
3481
	 *                     relative to wp-admin/. Defaults to 'wp-admin'.
3482
	 */
3483
	echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
3484
3485
	if ( function_exists( 'is_rtl' ) && is_rtl() ) {
3486
		/** This filter is documented in wp-includes/general-template.php */
3487
		echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
3488
	}
3489
}
3490
3491
/**
3492
 * Enqueues the default ThickBox js and css.
3493
 *
3494
 * If any of the settings need to be changed, this can be done with another js
3495
 * file similar to media-upload.js. That file should
3496
 * require array('thickbox') to ensure it is loaded after.
3497
 *
3498
 * @since 2.5.0
3499
 */
3500
function add_thickbox() {
3501
	wp_enqueue_script( 'thickbox' );
3502
	wp_enqueue_style( 'thickbox' );
3503
3504
	if ( is_network_admin() )
3505
		add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
3506
}
3507
3508
/**
3509
 * Displays the XHTML generator that is generated on the wp_head hook.
3510
 *
3511
 * See {@see 'wp_head'}.
3512
 *
3513
 * @since 2.5.0
3514
 */
3515
function wp_generator() {
3516
	/**
3517
	 * Filters the output of the XHTML generator tag.
3518
	 *
3519
	 * @since 2.5.0
3520
	 *
3521
	 * @param string $generator_type The XHTML generator.
3522
	 */
3523
	the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
3524
}
3525
3526
/**
3527
 * Display the generator XML or Comment for RSS, ATOM, etc.
3528
 *
3529
 * Returns the correct generator type for the requested output format. Allows
3530
 * for a plugin to filter generators overall the {@see 'the_generator'} filter.
3531
 *
3532
 * @since 2.5.0
3533
 *
3534
 * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
3535
 */
3536
function the_generator( $type ) {
3537
	/**
3538
	 * Filters the output of the XHTML generator tag for display.
3539
	 *
3540
	 * @since 2.5.0
3541
	 *
3542
	 * @param string $generator_type The generator output.
3543
	 * @param string $type           The type of generator to output. Accepts 'html',
3544
	 *                               'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'.
3545
	 */
3546
	echo apply_filters( 'the_generator', get_the_generator($type), $type ) . "\n";
3547
}
3548
3549
/**
3550
 * Creates the generator XML or Comment for RSS, ATOM, etc.
3551
 *
3552
 * Returns the correct generator type for the requested output format. Allows
3553
 * for a plugin to filter generators on an individual basis using the
3554
 * {@see 'get_the_generator_$type'} filter.
3555
 *
3556
 * @since 2.5.0
3557
 *
3558
 * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
3559
 * @return string|void The HTML content for the generator.
3560
 */
3561
function get_the_generator( $type = '' ) {
3562
	if ( empty( $type ) ) {
3563
3564
		$current_filter = current_filter();
3565
		if ( empty( $current_filter ) )
3566
			return;
3567
3568
		switch ( $current_filter ) {
3569
			case 'rss2_head' :
3570
			case 'commentsrss2_head' :
3571
				$type = 'rss2';
3572
				break;
3573
			case 'rss_head' :
3574
			case 'opml_head' :
3575
				$type = 'comment';
3576
				break;
3577
			case 'rdf_header' :
3578
				$type = 'rdf';
3579
				break;
3580
			case 'atom_head' :
3581
			case 'comments_atom_head' :
3582
			case 'app_head' :
3583
				$type = 'atom';
3584
				break;
3585
		}
3586
	}
3587
3588
	switch ( $type ) {
3589
		case 'html':
3590
			$gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
3591
			break;
3592
		case 'xhtml':
3593
			$gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
3594
			break;
3595
		case 'atom':
3596
			$gen = '<generator uri="https://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
3597
			break;
3598
		case 'rss2':
3599
			$gen = '<generator>https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
3600
			break;
3601
		case 'rdf':
3602
			$gen = '<admin:generatorAgent rdf:resource="https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
3603
			break;
3604
		case 'comment':
3605
			$gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
3606
			break;
3607
		case 'export':
3608
			$gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '" -->';
3609
			break;
3610
	}
3611
3612
	/**
3613
	 * Filters the HTML for the retrieved generator type.
3614
	 *
3615
	 * The dynamic portion of the hook name, `$type`, refers to the generator type.
3616
	 *
3617
	 * @since 2.5.0
3618
	 *
3619
	 * @param string $gen  The HTML markup output to wp_head().
3620
	 * @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom',
3621
	 *                     'rss2', 'rdf', 'comment', 'export'.
3622
	 */
3623
	return apply_filters( "get_the_generator_{$type}", $gen, $type );
0 ignored issues
show
The variable $gen does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
3624
}
3625
3626
/**
3627
 * Outputs the html checked attribute.
3628
 *
3629
 * Compares the first two arguments and if identical marks as checked
3630
 *
3631
 * @since 1.0.0
3632
 *
3633
 * @param mixed $checked One of the values to compare
3634
 * @param mixed $current (true) The other value to compare if not just true
3635
 * @param bool  $echo    Whether to echo or just return the string
3636
 * @return string html attribute or empty string
3637
 */
3638
function checked( $checked, $current = true, $echo = true ) {
3639
	return __checked_selected_helper( $checked, $current, $echo, 'checked' );
3640
}
3641
3642
/**
3643
 * Outputs the html selected attribute.
3644
 *
3645
 * Compares the first two arguments and if identical marks as selected
3646
 *
3647
 * @since 1.0.0
3648
 *
3649
 * @param mixed $selected One of the values to compare
3650
 * @param mixed $current  (true) The other value to compare if not just true
3651
 * @param bool  $echo     Whether to echo or just return the string
3652
 * @return string html attribute or empty string
3653
 */
3654
function selected( $selected, $current = true, $echo = true ) {
3655
	return __checked_selected_helper( $selected, $current, $echo, 'selected' );
3656
}
3657
3658
/**
3659
 * Outputs the html disabled attribute.
3660
 *
3661
 * Compares the first two arguments and if identical marks as disabled
3662
 *
3663
 * @since 3.0.0
3664
 *
3665
 * @param mixed $disabled One of the values to compare
3666
 * @param mixed $current  (true) The other value to compare if not just true
3667
 * @param bool  $echo     Whether to echo or just return the string
3668
 * @return string html attribute or empty string
3669
 */
3670
function disabled( $disabled, $current = true, $echo = true ) {
3671
	return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
3672
}
3673
3674
/**
3675
 * Private helper function for checked, selected, and disabled.
3676
 *
3677
 * Compares the first two arguments and if identical marks as $type
3678
 *
3679
 * @since 2.8.0
3680
 * @access private
3681
 *
3682
 * @param mixed  $helper  One of the values to compare
3683
 * @param mixed  $current (true) The other value to compare if not just true
3684
 * @param bool   $echo    Whether to echo or just return the string
3685
 * @param string $type    The type of checked|selected|disabled we are doing
3686
 * @return string html attribute or empty string
3687
 */
3688
function __checked_selected_helper( $helper, $current, $echo, $type ) {
3689
	if ( (string) $helper === (string) $current )
3690
		$result = " $type='$type'";
3691
	else
3692
		$result = '';
3693
3694
	if ( $echo )
3695
		echo $result;
3696
3697
	return $result;
3698
}
3699
3700
/**
3701
 * Default settings for heartbeat
3702
 *
3703
 * Outputs the nonce used in the heartbeat XHR
3704
 *
3705
 * @since 3.6.0
3706
 *
3707
 * @param array $settings
3708
 * @return array $settings
3709
 */
3710
function wp_heartbeat_settings( $settings ) {
3711
	if ( ! is_admin() )
3712
		$settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' );
3713
3714
	if ( is_user_logged_in() )
3715
		$settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
3716
3717
	return $settings;
3718
}
3719