The get_core_updates() WordPress PHP function retrieves available core updates for your WordPress installation.
Usage
To use the get_core_updates() function, pass an array of options as a parameter:
$core_updates = get_core_updates($options);
For example:
$options = array('dismissed' => true, 'available' => false); $core_updates = get_core_updates($options);
Parameters
$options
(array) – Optional. Set$options['dismissed']
totrue
to show dismissed upgrades too, set$options['available']
tofalse
to skip not-dismissed updates. Default:array()
More information
See WordPress Developer Resources: get_core_updates()
Examples
Get all available core updates
Retrieve all available core updates, including dismissed updates:
$options = array('dismissed' => true); $core_updates = get_core_updates($options); // Display available updates foreach ($core_updates as $update) { echo "Version: " . $update->current . ", URL: " . $update->download; }
Get only non-dismissed core updates
Retrieve only non-dismissed core updates:
$options = array('dismissed' => false); $core_updates = get_core_updates($options); // Display available updates foreach ($core_updates as $update) { echo "Version: " . $update->current . ", URL: " . $update->download; }
Check for a specific version update
Check if a specific version update is available:
$desired_version = "5.9"; $core_updates = get_core_updates(); // Check if desired version is available foreach ($core_updates as $update) { if ($update->current == $desired_version) { echo "Version $desired_version is available for update."; break; } }
Count available core updates
Get the count of available core updates:
$core_updates = get_core_updates(); $update_count = count($core_updates); echo "There are $update_count updates available.";
Display update details
Retrieve and display the details of available core updates:
$core_updates = get_core_updates(); // Display details of available updates foreach ($core_updates as $update) { echo "Version: " . $update->current; echo "URL: " . $update->download; echo "Locale: " . $update->locale; echo "Package: " . $update->package; }