Using WordPress ‘list_core_update()’ PHP function

The list_core_update() WordPress PHP function lists available core updates.

Usage

list_core_update($update);

Custom example:

$update = get_core_updates();
list_core_update($update[0]);

Parameters

  • $update (object) (required) – The update object containing information about the core updates.

More information

See WordPress Developer Resources: list_core_update

Examples

Display available core updates

Display a list of available core updates.

// Get core updates
$core_updates = get_core_updates();

// Check if updates are available
if (!empty($core_updates)) {
  // Loop through and display each update
  foreach ($core_updates as $update) {
    list_core_update($update);
  }
}

Display a specific core update

Display a specific core update by index.

// Get core updates
$core_updates = get_core_updates();

// Display the first core update in the list
if (!empty($core_updates)) {
  list_core_update($core_updates[0]);
}

Show updates with a minimum version

Display core updates with a minimum version.

// Get core updates
$core_updates = get_core_updates();

// Minimum version
$min_version = '5.8.0';

// Loop through and display updates with version greater than or equal to the minimum version
foreach ($core_updates as $update) {
  if (version_compare($update->version, $min_version, '>=')) {
    list_core_update($update);
  }
}

Show updates with a maximum version

Display core updates with a maximum version.

// Get core updates
$core_updates = get_core_updates();

// Maximum version
$max_version = '5.8.0';

// Loop through and display updates with version less than or equal to the maximum version
foreach ($core_updates as $update) {
  if (version_compare($update->version, $max_version, '<=')) {
    list_core_update($update);
  }
}

Display updates in a custom format

Display available core updates in a custom format.

// Get core updates
$core_updates = get_core_updates();

// Custom output format
if (!empty($core_updates)) {
  echo '<ul>';
  foreach ($core_updates as $update) {
    echo '<li>Version: ' . $update->version . ' | Package: ' . $update->package . '</li>';
  }
  echo '</ul>';
}