The find_core_update() WordPress PHP function finds the available update for WordPress core. It uses a specific version string and locale for this purpose.
Usage
Here’s a simple usage of the function:
$update = find_core_update('5.8', 'en_US');if ($update) { echo "Update found!"; } else { echo "No update found."; }
In this example, the function checks for updates to version 5.8 of WordPress in the en_US locale. If it finds an update, it prints “Update found!”, otherwise it prints “No update found.”
Parameters
- $version (string) – The version string to find the update for.
- $locale (string) – The locale to find the update for.
More information
See WordPress Developer Resources: find_core_update()
This function is available in all versions of WordPress after 3.7.0.
Examples
Checking for a specific update
This example checks for an update to WordPress version 5.8 for the en_US locale:
$update = find_core_update('5.8', 'en_US'); if ($update) { echo "Update for 5.8 en_US found!"; }
Handling no update
This code checks for an update and prints a custom message if no update is found:
$update = find_core_update('5.8', 'en_US'); if (!$update) { echo "No updates for 5.8 en_US."; }
Checking multiple versions
This example checks updates for multiple versions:
$versions = ['5.7', '5.8', '5.9'];foreach ($versions as $version) { $update = find_core_update($version, 'en_US'); if ($update) { echo "Update for version $version found!"; } }
Checking multiple locales
This example checks for updates for multiple locales:
$locales = ['en_US', 'fr_FR', 'de_DE'];foreach ($locales as $locale) { $update = find_core_update('5.8', $locale); if ($update) { echo "Update for locale $locale found!"; } }
Combining multiple versions and locales
This example checks updates for multiple versions and locales:
$versions = ['5.7', '5.8', '5.9']; $locales = ['en_US', 'fr_FR', 'de_DE'];foreach ($versions as $version) { foreach ($locales as $locale) { $update = find_core_update($version, $locale); if ($update) { echo "Update for version $version and locale $locale found!"; } } }