wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_get_auto_update_message › WordPress Function

Since5.5.0
Deprecatedn/a
› wp_get_auto_update_message ( $type = '' )
Parameters:
  • (string) $type Optional. The type of update the message is for: 'plugin' or 'theme'. Determines which directory is checked. Default empty, which checks ABSPATH.
    Required: No
    Default: (empty)
Returns:
  • (string) The update message to be shown.
Defined at:
Codex:
Change Log:
  • 7.2.0

Determines the appropriate auto-update message to be displayed.



Source

function wp_get_auto_update_message( $type = '' ) {
	// Loads Automatic_Upgrader_Skin and WP_Automatic_Updater.
	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';

	if ( ! function_exists( 'request_filesystem_credentials' ) ) {
		require_once ABSPATH . 'wp-admin/includes/file.php';
	}

	switch ( $type ) {
		case 'plugin':
			$context = WP_PLUGIN_DIR;
			break;
		case 'theme':
			$context = get_theme_root();
			break;
		default:
			$context = ABSPATH;
	}

	/*
	 * These mirror the checks in WP_Automatic_Updater::should_update(), which skips
	 * the update regardless of the schedule if either one fails.
	 */
	$skin    = new Automatic_Upgrader_Skin();
	$updater = new WP_Automatic_Updater();

	$message = '';
	if ( ! $skin->request_filesystem_credentials( false, $context ) ) {
		$message = __( 'Automatic update will not run because WordPress needs FTP credentials to update files.' );
	} elseif ( $updater->is_vcs_checkout( $context ) ) {
		$message = __( 'Automatic update will not run because this site appears to be under version control.' );
	}

	if ( $message ) {
		if ( current_user_can( 'view_site_health_checks' ) ) {
			$message .= ' ' . sprintf(
				/* translators: %s: URL to the Site Health screen. */
				__( '<a href="%s">Learn more in Site Health</a>.' ),
				esc_url( admin_url( 'site-health.php' ) )
			);
		}

		return $message;
	}

	$next_update_time = wp_next_scheduled( 'wp_version_check' );

	// Check if the event exists.
	if ( false === $next_update_time ) {
		$message = __( 'Automatic update not scheduled. There may be a problem with WP-Cron.' );
	} else {
		$time_to_next_update = human_time_diff( (int) $next_update_time );

		// See if cron is overdue.
		$overdue = ( time() - $next_update_time ) > 0;

		if ( $overdue ) {
			$message = sprintf(
				/* translators: %s: Duration that WP-Cron has been overdue. */
				__( 'Automatic update overdue by %s. There may be a problem with WP-Cron.' ),
				$time_to_next_update
			);
		} else {
			$message = sprintf(
				/* translators: %s: Time until the next update. */
				__( 'Automatic update scheduled in %s.' ),
				$time_to_next_update
			);
		}
	}

	return $message;
}