list_core_update()
最后更新于:2021-11-27 13:30:30
list_core_update( object$update)Lists available core updates.
参数
- $update
-
(object) (Required)
源文件
文件: gc-admin/update-core.php
function list_core_update( $update ) {
global $gc_local_package, $gcdb;
static $first_pass = true;
$gc_version = get_bloginfo( 'version' );
$version_string = sprintf( '%s–%s', $update->current, get_locale() );
if ( 'en_US' === $update->locale && 'en_US' === get_locale() ) {
$version_string = $update->current;
} elseif ( 'en_US' === $update->locale && $update->packages->partial && $gc_version == $update->partial_version ) {
$updates = get_core_updates();
if ( $updates && 1 === count( $updates ) ) {
// If the only available update is a partial builds, it doesn't need a language-specific version string.
$version_string = $update->current;
}
}
$current = false;
if ( ! isset( $update->response ) || 'latest' === $update->response ) {
$current = true;
}
$message = '';
$form_action = 'update-core.php?action=do-core-upgrade';
$php_version = phpversion();
$mysql_version = $gcdb->db_version();
$show_buttons = true;
// Nightly build versions have two hyphens and a commit number.
if ( preg_match( '/-w+-d+/', $update->current ) ) {
// Retrieve the major version number.
preg_match( '/^d+.d+/', $update->current, $update_major );
/* translators: %s: GeChiUI version. */
$submit = sprintf( __( 'Update to latest %s nightly' ), $update_major[0] );
} else {
/* translators: %s: GeChiUI version. */
$submit = sprintf( __( 'Update to version %s' ), $version_string );
}
if ( 'development' === $update->response ) {
$message = __( 'You can update to the latest nightly build manually:' );
} else {
if ( $current ) {
/* translators: %s: GeChiUI version. */
$submit = sprintf( __( 'Re-install version %s' ), $version_string );
$form_action = 'update-core.php?action=do-core-reinstall';
} else {
$php_compat = version_compare( $php_version, $update->php_version, '>=' );
if ( file_exists( GC_CONTENT_DIR . '/db.php' ) && empty( $gcdb->is_mysql ) ) {
$mysql_compat = true;
} else {
$mysql_compat = version_compare( $mysql_version, $update->mysql_version, '>=' );
}
$version_url = sprintf(
/* translators: %s: GeChiUI version. */
esc_url( __( 'https://gechiui.org/support/gechiui-version/version-%s/' ) ),
sanitize_title( $update->current )
);
$php_update_message = '</p><p>' . sprintf(
/* translators: %s: URL to Update PHP page. */
__( '<a href="https://docs.gechiui.com/functions/list_core_update/%s">Learn more about updating PHP</a>.' ),
esc_url( gc_get_update_php_url() )
);
$annotation = gc_get_update_php_annotation();
if ( $annotation ) {
$php_update_message .= '</p><p><em>' . $annotation . '</em>';
}
if ( ! $mysql_compat && ! $php_compat ) {
$message = sprintf(
/* translators: 1: URL to GeChiUI release notes, 2: GeChiUI version number, 3: Minimum required PHP version number, 4: Minimum required MySQL version number, 5: Current PHP version number, 6: Current MySQL version number. */
__( 'You cannot update because <a href="https://docs.gechiui.com/functions/list_core_update/%1$s">GeChiUI %2$s</a> requires PHP version %3$s or higher and MySQL version %4$s or higher. You are running PHP version %5$s and MySQL version %6$s.' ),
$version_url,
$update->current,
$update->php_version,
$update->mysql_version,
$php_version,
$mysql_version
) . $php_update_message;
} elseif ( ! $php_compat ) {
$message = sprintf(
/* translators: 1: URL to GeChiUI release notes, 2: GeChiUI version number, 3: Minimum required PHP version number, 4: Current PHP version number. */
__( 'You cannot update because <a href="https://docs.gechiui.com/functions/list_core_update/%1$s">GeChiUI %2$s</a> requires PHP version %3$s or higher. You are running version %4$s.' ),
$version_url,
$update->current,
$update->php_version,
$php_version
) . $php_update_message;
} elseif ( ! $mysql_compat ) {
$message = sprintf(
/* translators: 1: URL to GeChiUI release notes, 2: GeChiUI version number, 3: Minimum required MySQL version number, 4: Current MySQL version number. */
__( 'You cannot update because <a href="https://docs.gechiui.com/functions/list_core_update/%1$s">GeChiUI %2$s</a> requires MySQL version %3$s or higher. You are running version %4$s.' ),
$version_url,
$update->current,
$update->mysql_version,
$mysql_version
);
} else {
$message = sprintf(
/* translators: 1: Installed GeChiUI version number, 2: URL to GeChiUI release notes, 3: New GeChiUI version number, including locale if necessary. */
__( 'You can update from GeChiUI %1$s to <a href="https://docs.gechiui.com/functions/list_core_update/%2$s">GeChiUI %3$s</a> manually:' ),
$gc_version,
$version_url,
$version_string
);
}
if ( ! $mysql_compat || ! $php_compat ) {
$show_buttons = false;
}
}
}
echo '<p>';
echo $message;
echo '</p>';
echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
gc_nonce_field( 'upgrade-core' );
echo '<p>';
echo '<input name="version" value="' . esc_attr( $update->current ) . '" type="hidden" />';
echo '<input name="locale" value="' . esc_attr( $update->locale ) . '" type="hidden" />';
if ( $show_buttons ) {
if ( $first_pass ) {
submit_button( $submit, $current ? '' : 'primary regular', 'upgrade', false );
$first_pass = false;
} else {
submit_button( $submit, '', 'upgrade', false );
}
}
if ( 'en_US' !== $update->locale ) {
if ( ! isset( $update->dismissed ) || ! $update->dismissed ) {
submit_button( __( 'Hide this update' ), '', 'dismiss', false );
} else {
submit_button( __( 'Bring back this update' ), '', 'undismiss', false );
}
}
echo '</p>';
if ( 'en_US' !== $update->locale && ( ! isset( $gc_local_package ) || $gc_local_package != $update->locale ) ) {
echo '<p class="hint">' . __( 'This localized version contains both the translation and various other localization fixes.' ) . '</p>';
} elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() && ( ! $update->packages->partial && $gc_version == $update->partial_version ) ) {
// Partial builds don't need language-specific warnings.
echo '<p class="hint">' . sprintf(
/* translators: %s: GeChiUI version. */
__( 'You are about to install GeChiUI %s <strong>in English (US).</strong> There is a chance this update will break your translation. You may prefer to wait for the localized version to be released.' ),
'development' !== $update->response ? $update->current : ''
) . '</p>';
}
echo '</form>';
}