wp/wp-admin/includes/misc.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    37  * Detects Apache's mod_rewrite, IIS 7.0+ permalink support, and nginx.
    37  * Detects Apache's mod_rewrite, IIS 7.0+ permalink support, and nginx.
    38  *
    38  *
    39  * @since 3.7.0
    39  * @since 3.7.0
    40  *
    40  *
    41  * @global bool $is_nginx
    41  * @global bool $is_nginx
       
    42  * @global bool $is_caddy
    42  *
    43  *
    43  * @return bool Whether the server supports URL rewriting.
    44  * @return bool Whether the server supports URL rewriting.
    44  */
    45  */
    45 function got_url_rewrite() {
    46 function got_url_rewrite() {
    46 	$got_url_rewrite = ( got_mod_rewrite() || $GLOBALS['is_nginx'] || iis7_supports_permalinks() );
    47 	$got_url_rewrite = ( got_mod_rewrite() || $GLOBALS['is_nginx'] || $GLOBALS['is_caddy'] || iis7_supports_permalinks() );
    47 
    48 
    48 	/**
    49 	/**
    49 	 * Filters whether URL rewriting is available.
    50 	 * Filters whether URL rewriting is available.
    50 	 *
    51 	 *
    51 	 * @since 3.7.0
    52 	 * @since 3.7.0
    74 	$markerdata = explode( "\n", implode( '', file( $filename ) ) );
    75 	$markerdata = explode( "\n", implode( '', file( $filename ) ) );
    75 
    76 
    76 	$state = false;
    77 	$state = false;
    77 
    78 
    78 	foreach ( $markerdata as $markerline ) {
    79 	foreach ( $markerdata as $markerline ) {
    79 		if ( false !== strpos( $markerline, '# END ' . $marker ) ) {
    80 		if ( str_contains( $markerline, '# END ' . $marker ) ) {
    80 			$state = false;
    81 			$state = false;
    81 		}
    82 		}
    82 
    83 
    83 		if ( $state ) {
    84 		if ( $state ) {
    84 			if ( '#' === substr( $markerline, 0, 1 ) ) {
    85 			if ( str_starts_with( $markerline, '#' ) ) {
    85 				continue;
    86 				continue;
    86 			}
    87 			}
    87 
    88 
    88 			$result[] = $markerline;
    89 			$result[] = $markerline;
    89 		}
    90 		}
    90 
    91 
    91 		if ( false !== strpos( $markerline, '# BEGIN ' . $marker ) ) {
    92 		if ( str_contains( $markerline, '# BEGIN ' . $marker ) ) {
    92 			$state = true;
    93 			$state = true;
    93 		}
    94 		}
    94 	}
    95 	}
    95 
    96 
    96 	return $result;
    97 	return $result;
   192 	$existing_lines   = array();
   193 	$existing_lines   = array();
   193 	$found_marker     = false;
   194 	$found_marker     = false;
   194 	$found_end_marker = false;
   195 	$found_end_marker = false;
   195 
   196 
   196 	foreach ( $lines as $line ) {
   197 	foreach ( $lines as $line ) {
   197 		if ( ! $found_marker && false !== strpos( $line, $start_marker ) ) {
   198 		if ( ! $found_marker && str_contains( $line, $start_marker ) ) {
   198 			$found_marker = true;
   199 			$found_marker = true;
   199 			continue;
   200 			continue;
   200 		} elseif ( ! $found_end_marker && false !== strpos( $line, $end_marker ) ) {
   201 		} elseif ( ! $found_end_marker && str_contains( $line, $end_marker ) ) {
   201 			$found_end_marker = true;
   202 			$found_end_marker = true;
   202 			continue;
   203 			continue;
   203 		}
   204 		}
   204 
   205 
   205 		if ( ! $found_marker ) {
   206 		if ( ! $found_marker ) {
   401 	if ( is_array( $tree ) ) {
   402 	if ( is_array( $tree ) ) {
   402 		$index = 0;
   403 		$index = 0;
   403 		$size  = count( $tree );
   404 		$size  = count( $tree );
   404 
   405 
   405 		foreach ( $tree as $label => $theme_file ) :
   406 		foreach ( $tree as $label => $theme_file ) :
   406 			$index++;
   407 			++$index;
   407 
   408 
   408 			if ( ! is_array( $theme_file ) ) {
   409 			if ( ! is_array( $theme_file ) ) {
   409 				wp_print_theme_file_tree( $theme_file, $level, $index, $size );
   410 				wp_print_theme_file_tree( $theme_file, $level, $index, $size );
   410 				continue;
   411 				continue;
   411 			}
   412 			}
   412 			?>
   413 			?>
   413 			<li role="treeitem" aria-expanded="true" tabindex="-1"
   414 			<li role="treeitem" aria-expanded="true" tabindex="-1"
   414 				aria-level="<?php echo esc_attr( $level ); ?>"
   415 				aria-level="<?php echo esc_attr( $level ); ?>"
   415 				aria-setsize="<?php echo esc_attr( $size ); ?>"
   416 				aria-setsize="<?php echo esc_attr( $size ); ?>"
   416 				aria-posinset="<?php echo esc_attr( $index ); ?>">
   417 				aria-posinset="<?php echo esc_attr( $index ); ?>">
   417 				<span class="folder-label"><?php echo esc_html( $label ); ?> <span class="screen-reader-text"><?php _e( 'folder' ); ?></span><span aria-hidden="true" class="icon"></span></span>
   418 				<span class="folder-label"><?php echo esc_html( $label ); ?> <span class="screen-reader-text">
       
   419 					<?php
       
   420 					/* translators: Hidden accessibility text. */
       
   421 					_e( 'folder' );
       
   422 					?>
       
   423 				</span><span aria-hidden="true" class="icon"></span></span>
   418 				<ul role="group" class="tree-folder"><?php wp_print_theme_file_tree( $theme_file, $level + 1, $index, $size ); ?></ul>
   424 				<ul role="group" class="tree-folder"><?php wp_print_theme_file_tree( $theme_file, $level + 1, $index, $size ); ?></ul>
   419 			</li>
   425 			</li>
   420 			<?php
   426 			<?php
   421 		endforeach;
   427 		endforeach;
   422 	} else {
   428 	} else {
   498 	if ( is_array( $tree ) ) {
   504 	if ( is_array( $tree ) ) {
   499 		$index = 0;
   505 		$index = 0;
   500 		$size  = count( $tree );
   506 		$size  = count( $tree );
   501 
   507 
   502 		foreach ( $tree as $label => $plugin_file ) :
   508 		foreach ( $tree as $label => $plugin_file ) :
   503 			$index++;
   509 			++$index;
   504 
   510 
   505 			if ( ! is_array( $plugin_file ) ) {
   511 			if ( ! is_array( $plugin_file ) ) {
   506 				wp_print_plugin_file_tree( $plugin_file, $label, $level, $index, $size );
   512 				wp_print_plugin_file_tree( $plugin_file, $label, $level, $index, $size );
   507 				continue;
   513 				continue;
   508 			}
   514 			}
   509 			?>
   515 			?>
   510 			<li role="treeitem" aria-expanded="true" tabindex="-1"
   516 			<li role="treeitem" aria-expanded="true" tabindex="-1"
   511 				aria-level="<?php echo esc_attr( $level ); ?>"
   517 				aria-level="<?php echo esc_attr( $level ); ?>"
   512 				aria-setsize="<?php echo esc_attr( $size ); ?>"
   518 				aria-setsize="<?php echo esc_attr( $size ); ?>"
   513 				aria-posinset="<?php echo esc_attr( $index ); ?>">
   519 				aria-posinset="<?php echo esc_attr( $index ); ?>">
   514 				<span class="folder-label"><?php echo esc_html( $label ); ?> <span class="screen-reader-text"><?php _e( 'folder' ); ?></span><span aria-hidden="true" class="icon"></span></span>
   520 				<span class="folder-label"><?php echo esc_html( $label ); ?> <span class="screen-reader-text">
       
   521 					<?php
       
   522 					/* translators: Hidden accessibility text. */
       
   523 					_e( 'folder' );
       
   524 					?>
       
   525 				</span><span aria-hidden="true" class="icon"></span></span>
   515 				<ul role="group" class="tree-folder"><?php wp_print_plugin_file_tree( $plugin_file, '', $level + 1, $index, $size ); ?></ul>
   526 				<ul role="group" class="tree-folder"><?php wp_print_plugin_file_tree( $plugin_file, '', $level + 1, $index, $size ); ?></ul>
   516 			</li>
   527 			</li>
   517 			<?php
   528 			<?php
   518 		endforeach;
   529 		endforeach;
   519 	} else {
   530 	} else {
   543 		<?php
   554 		<?php
   544 	}
   555 	}
   545 }
   556 }
   546 
   557 
   547 /**
   558 /**
   548  * Flushes rewrite rules if siteurl, home or page_on_front changed.
   559  * Flushes rewrite rules if `siteurl`, `home` or `page_on_front` changed.
   549  *
   560  *
   550  * @since 2.1.0
   561  * @since 2.1.0
   551  *
   562  *
   552  * @param string $old_value
   563  * @param string $old_value
   553  * @param string $value
   564  * @param string $value
   562 	} else {
   573 	} else {
   563 		flush_rewrite_rules();
   574 		flush_rewrite_rules();
   564 	}
   575 	}
   565 }
   576 }
   566 
   577 
   567 
   578 /**
   568 /**
   579  * Resets global variables based on `$_GET` and `$_POST`.
   569  * Resets global variables based on $_GET and $_POST.
       
   570  *
   580  *
   571  * This function resets global variables based on the names passed
   581  * This function resets global variables based on the names passed
   572  * in the $vars array to the value of $_POST[$var] or $_GET[$var] or ''
   582  * in the `$vars` array to the value of `$_POST[$var]` or `$_GET[$var]` or an
   573  * if neither is defined.
   583  * empty string if neither is defined.
   574  *
   584  *
   575  * @since 2.0.0
   585  * @since 2.0.0
   576  *
   586  *
   577  * @param array $vars An array of globals to reset.
   587  * @param array $vars An array of globals to reset.
   578  */
   588  */
   661 	 */
   671 	 */
   662 	$ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions );
   672 	$ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions );
   663 
   673 
   664 	$ignore_functions = array_unique( $ignore_functions );
   674 	$ignore_functions = array_unique( $ignore_functions );
   665 
   675 
   666 	$out = array();
   676 	$output = array();
   667 
   677 
   668 	foreach ( $functions as $function ) {
   678 	foreach ( $functions as $function ) {
   669 		if ( in_array( $function, $ignore_functions, true ) ) {
   679 		if ( in_array( $function, $ignore_functions, true ) ) {
   670 			continue;
   680 			continue;
   671 		}
   681 		}
   672 
   682 
   673 		$out[] = $function;
   683 		$output[] = $function;
   674 	}
   684 	}
   675 
   685 
   676 	return $out;
   686 	return $output;
   677 }
   687 }
   678 
   688 
   679 /**
   689 /**
   680  * Saves option for number of rows when listing posts, pages, comments, etc.
   690  * Saves option for number of rows when listing posts, pages, comments, etc.
   681  *
   691  *
   738 			break;
   748 			break;
   739 
   749 
   740 		default:
   750 		default:
   741 			$screen_option = false;
   751 			$screen_option = false;
   742 
   752 
   743 			if ( '_page' === substr( $option, -5 ) || 'layout_columns' === $option ) {
   753 			if ( str_ends_with( $option, '_page' ) || 'layout_columns' === $option ) {
   744 				/**
   754 				/**
   745 				 * Filters a screen option value before it is set.
   755 				 * Filters a screen option value before it is set.
   746 				 *
   756 				 *
   747 				 * The filter can also be used to modify non-standard [items]_per_page
   757 				 * The filter can also be used to modify non-standard `[items]_per_page`
   748 				 * settings. See the parent function for a full list of standard options.
   758 				 * settings. See the parent function for a full list of standard options.
   749 				 *
   759 				 *
   750 				 * Returning false from the filter will skip saving the current option.
   760 				 * Returning false from the filter will skip saving the current option.
   751 				 *
   761 				 *
   752 				 * @since 2.8.0
   762 				 * @since 2.8.0
  1010 	if ( empty( $current_color ) || ! isset( $_wp_admin_css_colors[ $current_color ] ) ) {
  1020 	if ( empty( $current_color ) || ! isset( $_wp_admin_css_colors[ $current_color ] ) ) {
  1011 		$current_color = 'fresh';
  1021 		$current_color = 'fresh';
  1012 	}
  1022 	}
  1013 	?>
  1023 	?>
  1014 	<fieldset id="color-picker" class="scheme-list">
  1024 	<fieldset id="color-picker" class="scheme-list">
  1015 		<legend class="screen-reader-text"><span><?php _e( 'Admin Color Scheme' ); ?></span></legend>
  1025 		<legend class="screen-reader-text"><span>
       
  1026 			<?php
       
  1027 			/* translators: Hidden accessibility text. */
       
  1028 			_e( 'Admin Color Scheme' );
       
  1029 			?>
       
  1030 		</span></legend>
  1016 		<?php
  1031 		<?php
  1017 		wp_nonce_field( 'save-color-scheme', 'color-nonce', false );
  1032 		wp_nonce_field( 'save-color-scheme', 'color-nonce', false );
  1018 		foreach ( $_wp_admin_css_colors as $color => $color_info ) :
  1033 		foreach ( $_wp_admin_css_colors as $color => $color_info ) :
  1019 
  1034 
  1020 			?>
  1035 			?>
  1021 			<div class="color-option <?php echo ( $color === $current_color ) ? 'selected' : ''; ?>">
  1036 			<div class="color-option <?php echo ( $color === $current_color ) ? 'selected' : ''; ?>">
  1022 				<input name="admin_color" id="admin_color_<?php echo esc_attr( $color ); ?>" type="radio" value="<?php echo esc_attr( $color ); ?>" class="tog" <?php checked( $color, $current_color ); ?> />
  1037 				<input name="admin_color" id="admin_color_<?php echo esc_attr( $color ); ?>" type="radio" value="<?php echo esc_attr( $color ); ?>" class="tog" <?php checked( $color, $current_color ); ?> />
  1023 				<input type="hidden" class="css_url" value="<?php echo esc_url( $color_info->url ); ?>" />
  1038 				<input type="hidden" class="css_url" value="<?php echo esc_url( $color_info->url ); ?>" />
  1024 				<input type="hidden" class="icon_colors" value="<?php echo esc_attr( wp_json_encode( array( 'icons' => $color_info->icon_colors ) ) ); ?>" />
  1039 				<input type="hidden" class="icon_colors" value="<?php echo esc_attr( wp_json_encode( array( 'icons' => $color_info->icon_colors ) ) ); ?>" />
  1025 				<label for="admin_color_<?php echo esc_attr( $color ); ?>"><?php echo esc_html( $color_info->name ); ?></label>
  1040 				<label for="admin_color_<?php echo esc_attr( $color ); ?>"><?php echo esc_html( $color_info->name ); ?></label>
  1026 				<table class="color-palette">
  1041 				<div class="color-palette">
  1027 					<tr>
  1042 				<?php
       
  1043 				foreach ( $color_info->colors as $html_color ) {
       
  1044 					?>
       
  1045 					<div class="color-palette-shade" style="background-color: <?php echo esc_attr( $html_color ); ?>">&nbsp;</div>
  1028 					<?php
  1046 					<?php
  1029 					foreach ( $color_info->colors as $html_color ) {
  1047 				}
  1030 						?>
  1048 				?>
  1031 						<td style="background-color: <?php echo esc_attr( $html_color ); ?>">&nbsp;</td>
  1049 				</div>
  1032 						<?php
       
  1033 					}
       
  1034 					?>
       
  1035 					</tr>
       
  1036 				</table>
       
  1037 			</div>
  1050 			</div>
  1038 			<?php
  1051 			<?php
  1039 
  1052 
  1040 		endforeach;
  1053 		endforeach;
  1041 		?>
  1054 		?>
  1254 
  1267 
  1255 	return $response;
  1268 	return $response;
  1256 }
  1269 }
  1257 
  1270 
  1258 /**
  1271 /**
  1259  * Adds the latest Heartbeat and REST-API nonce to the Heartbeat response.
  1272  * Refresh nonces used with meta boxes in the block editor.
       
  1273  *
       
  1274  * @since 6.1.0
       
  1275  *
       
  1276  * @param array  $response  The Heartbeat response.
       
  1277  * @param array  $data      The $_POST data sent.
       
  1278  * @return array The Heartbeat response.
       
  1279  */
       
  1280 function wp_refresh_metabox_loader_nonces( $response, $data ) {
       
  1281 	if ( empty( $data['wp-refresh-metabox-loader-nonces'] ) ) {
       
  1282 		return $response;
       
  1283 	}
       
  1284 
       
  1285 	$received = $data['wp-refresh-metabox-loader-nonces'];
       
  1286 	$post_id  = (int) $received['post_id'];
       
  1287 
       
  1288 	if ( ! $post_id ) {
       
  1289 		return $response;
       
  1290 	}
       
  1291 
       
  1292 	if ( ! current_user_can( 'edit_post', $post_id ) ) {
       
  1293 		return $response;
       
  1294 	}
       
  1295 
       
  1296 	$response['wp-refresh-metabox-loader-nonces'] = array(
       
  1297 		'replace' => array(
       
  1298 			'metabox_loader_nonce' => wp_create_nonce( 'meta-box-loader' ),
       
  1299 			'_wpnonce'             => wp_create_nonce( 'update-post_' . $post_id ),
       
  1300 		),
       
  1301 	);
       
  1302 
       
  1303 	return $response;
       
  1304 }
       
  1305 
       
  1306 /**
       
  1307  * Adds the latest Heartbeat and REST API nonce to the Heartbeat response.
  1260  *
  1308  *
  1261  * @since 5.0.0
  1309  * @since 5.0.0
  1262  *
  1310  *
  1263  * @param array $response The Heartbeat response.
  1311  * @param array $response The Heartbeat response.
  1264  * @return array The Heartbeat response.
  1312  * @return array The Heartbeat response.
  1346 	}
  1394 	}
  1347 
  1395 
  1348 	// Ensure we're using an absolute URL.
  1396 	// Ensure we're using an absolute URL.
  1349 	$current_url  = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
  1397 	$current_url  = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
  1350 	$filtered_url = remove_query_arg( $removable_query_args, $current_url );
  1398 	$filtered_url = remove_query_arg( $removable_query_args, $current_url );
       
  1399 
       
  1400 	/**
       
  1401 	 * Filters the admin canonical URL value.
       
  1402 	 *
       
  1403 	 * @since 6.5.0
       
  1404 	 *
       
  1405 	 * @param string $filtered_url The admin canonical URL value.
       
  1406 	 */
       
  1407 	$filtered_url = apply_filters( 'wp_admin_canonical_url', $filtered_url );
  1351 	?>
  1408 	?>
  1352 	<link id="wp-admin-canonical" rel="canonical" href="<?php echo esc_url( $filtered_url ); ?>" />
  1409 	<link id="wp-admin-canonical" rel="canonical" href="<?php echo esc_url( $filtered_url ); ?>" />
  1353 	<script>
  1410 	<script>
  1354 		if ( window.history.replaceState ) {
  1411 		if ( window.history.replaceState ) {
  1355 			window.history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href + window.location.hash );
  1412 			window.history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href + window.location.hash );
  1420 		'hash'     => $hash,
  1477 		'hash'     => $hash,
  1421 		'newemail' => $value,
  1478 		'newemail' => $value,
  1422 	);
  1479 	);
  1423 	update_option( 'adminhash', $new_admin_email );
  1480 	update_option( 'adminhash', $new_admin_email );
  1424 
  1481 
  1425 	$switched_locale = switch_to_locale( get_user_locale() );
  1482 	$switched_locale = switch_to_user_locale( get_current_user_id() );
  1426 
  1483 
  1427 	/* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */
  1484 	/* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */
  1428 	$email_text = __(
  1485 	$email_text = __(
  1429 		'Howdy ###USERNAME###,
  1486 		'Howdy ###USERNAME###,
  1430 
  1487 
  1447 
  1504 
  1448 	/**
  1505 	/**
  1449 	 * Filters the text of the email sent when a change of site admin email address is attempted.
  1506 	 * Filters the text of the email sent when a change of site admin email address is attempted.
  1450 	 *
  1507 	 *
  1451 	 * The following strings have a special meaning and will get replaced dynamically:
  1508 	 * The following strings have a special meaning and will get replaced dynamically:
  1452 	 * ###USERNAME###  The current user's username.
  1509 	 *  - ###USERNAME###  The current user's username.
  1453 	 * ###ADMIN_URL### The link to click on to confirm the email change.
  1510 	 *  - ###ADMIN_URL### The link to click on to confirm the email change.
  1454 	 * ###EMAIL###     The proposed new site admin email address.
  1511 	 *  - ###EMAIL###     The proposed new site admin email address.
  1455 	 * ###SITENAME###  The name of the site.
  1512 	 *  - ###SITENAME###  The name of the site.
  1456 	 * ###SITEURL###   The URL to the site.
  1513 	 *  - ###SITEURL###   The URL to the site.
  1457 	 *
  1514 	 *
  1458 	 * @since MU (3.0.0)
  1515 	 * @since MU (3.0.0)
  1459 	 * @since 4.9.0 This filter is no longer Multisite specific.
  1516 	 * @since 4.9.0 This filter is no longer Multisite specific.
  1460 	 *
  1517 	 *
  1461 	 * @param string $email_text      Text in the email.
  1518 	 * @param string $email_text      Text in the email.
  1479 		$site_title = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
  1536 		$site_title = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
  1480 	} else {
  1537 	} else {
  1481 		$site_title = parse_url( home_url(), PHP_URL_HOST );
  1538 		$site_title = parse_url( home_url(), PHP_URL_HOST );
  1482 	}
  1539 	}
  1483 
  1540 
  1484 	wp_mail(
  1541 	$subject = sprintf(
  1485 		$value,
  1542 		/* translators: New admin email address notification email subject. %s: Site title. */
  1486 		sprintf(
  1543 		__( '[%s] New Admin Email Address' ),
  1487 			/* translators: New admin email address notification email subject. %s: Site title. */
  1544 		$site_title
  1488 			__( '[%s] New Admin Email Address' ),
       
  1489 			$site_title
       
  1490 		),
       
  1491 		$content
       
  1492 	);
  1545 	);
       
  1546 
       
  1547 	/**
       
  1548 	 * Filters the subject of the email sent when a change of site admin email address is attempted.
       
  1549 	 *
       
  1550 	 * @since 6.5.0
       
  1551 	 *
       
  1552 	 * @param string $subject Subject of the email.
       
  1553 	 */
       
  1554 	$subject = apply_filters( 'new_admin_email_subject', $subject );
       
  1555 
       
  1556 	wp_mail( $value, $subject, $content );
  1493 
  1557 
  1494 	if ( $switched_locale ) {
  1558 	if ( $switched_locale ) {
  1495 		restore_previous_locale();
  1559 		restore_previous_locale();
  1496 	}
  1560 	}
  1497 }
  1561 }
  1520  * Checks if the user needs to update PHP.
  1584  * Checks if the user needs to update PHP.
  1521  *
  1585  *
  1522  * @since 5.1.0
  1586  * @since 5.1.0
  1523  * @since 5.1.1 Added the {@see 'wp_is_php_version_acceptable'} filter.
  1587  * @since 5.1.1 Added the {@see 'wp_is_php_version_acceptable'} filter.
  1524  *
  1588  *
  1525  * @return array|false Array of PHP version data. False on failure.
  1589  * @return array|false {
       
  1590  *     Array of PHP version data. False on failure.
       
  1591  *
       
  1592  *     @type string $recommended_version The PHP version recommended by WordPress.
       
  1593  *     @type string $minimum_version     The minimum required PHP version.
       
  1594  *     @type bool   $is_supported        Whether the PHP version is actively supported.
       
  1595  *     @type bool   $is_secure           Whether the PHP version receives security updates.
       
  1596  *     @type bool   $is_acceptable       Whether the PHP version is still acceptable or warnings
       
  1597  *                                       should be shown and an update recommended.
       
  1598  * }
  1526  */
  1599  */
  1527 function wp_check_php_version() {
  1600 function wp_check_php_version() {
  1528 	$version = phpversion();
  1601 	$version = PHP_VERSION;
  1529 	$key     = md5( $version );
  1602 	$key     = md5( $version );
  1530 
  1603 
  1531 	$response = get_site_transient( 'php_check_' . $key );
  1604 	$response = get_site_transient( 'php_check_' . $key );
  1532 
  1605 
  1533 	if ( false === $response ) {
  1606 	if ( false === $response ) {
  1543 
  1616 
  1544 		if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
  1617 		if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
  1545 			return false;
  1618 			return false;
  1546 		}
  1619 		}
  1547 
  1620 
  1548 		/**
       
  1549 		 * Response should be an array with:
       
  1550 		 *  'recommended_version' - string - The PHP version recommended by WordPress.
       
  1551 		 *  'is_supported' - boolean - Whether the PHP version is actively supported.
       
  1552 		 *  'is_secure' - boolean - Whether the PHP version receives security updates.
       
  1553 		 *  'is_acceptable' - boolean - Whether the PHP version is still acceptable for WordPress.
       
  1554 		 */
       
  1555 		$response = json_decode( wp_remote_retrieve_body( $response ), true );
  1621 		$response = json_decode( wp_remote_retrieve_body( $response ), true );
  1556 
  1622 
  1557 		if ( ! is_array( $response ) ) {
  1623 		if ( ! is_array( $response ) ) {
  1558 			return false;
  1624 			return false;
  1559 		}
  1625 		}
  1576 		 * @param string $version       PHP version checked.
  1642 		 * @param string $version       PHP version checked.
  1577 		 */
  1643 		 */
  1578 		$response['is_acceptable'] = (bool) apply_filters( 'wp_is_php_version_acceptable', true, $version );
  1644 		$response['is_acceptable'] = (bool) apply_filters( 'wp_is_php_version_acceptable', true, $version );
  1579 	}
  1645 	}
  1580 
  1646 
       
  1647 	$response['is_lower_than_future_minimum'] = false;
       
  1648 
       
  1649 	// The minimum supported PHP version will be updated to 7.4 in the future. Check if the current version is lower.
       
  1650 	if ( version_compare( $version, '7.4', '<' ) ) {
       
  1651 		$response['is_lower_than_future_minimum'] = true;
       
  1652 
       
  1653 		// Force showing of warnings.
       
  1654 		$response['is_acceptable'] = false;
       
  1655 	}
       
  1656 
  1581 	return $response;
  1657 	return $response;
  1582 }
  1658 }