wp_get_update_data

Collect counts and UI strings for available updates.

Description

(array) wp_get_update_data(); 

Returns (array)


Usage

  1. if ( !function_exists( 'wp_get_update_data' ) ) { 
  2. require_once ABSPATH . WPINC . '/update.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_get_update_data(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/update.php  
  1. function wp_get_update_data() { 
  2. $counts = array( 'plugins' => 0, 'themes' => 0, 'wordpress' => 0, translations => 0 ); 
  3.  
  4. if ( $plugins = current_user_can( 'update_plugins' ) ) { 
  5. $update_plugins = get_site_transient( 'update_plugins' ); 
  6. if ( ! empty( $update_plugins->response ) ) 
  7. $counts['plugins'] = count( $update_plugins->response ); 
  8.  
  9. if ( $themes = current_user_can( 'update_themes' ) ) { 
  10. $update_themes = get_site_transient( 'update_themes' ); 
  11. if ( ! empty( $update_themes->response ) ) 
  12. $counts['themes'] = count( $update_themes->response ); 
  13.  
  14. if ( ( $core = current_user_can( 'update_core' ) ) && function_exists( 'get_core_updates' ) ) { 
  15. $update_wordpress = get_core_updates( array('dismissed' => false) ); 
  16. if ( ! empty( $update_wordpress ) && ! in_array( $update_wordpress[0]->response, array('development', 'latest') ) && current_user_can('update_core') ) 
  17. $counts['wordpress'] = 1; 
  18.  
  19. if ( ( $core || $plugins || $themes ) && wp_get_translation_updates() ) 
  20. $counts[translations] = 1; 
  21.  
  22. $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'] + $counts[translations]; 
  23. $titles = array(); 
  24. if ( $counts['wordpress'] ) { 
  25. /** translators: 1: Number of updates available to WordPress */ 
  26. $titles['wordpress'] = sprintf( __( '%d WordPress Update'), $counts['wordpress'] ); 
  27. if ( $counts['plugins'] ) { 
  28. /** translators: 1: Number of updates available to plugins */ 
  29. $titles['plugins'] = sprintf( _n( '%d Plugin Update', '%d Plugin Updates', $counts['plugins'] ), $counts['plugins'] ); 
  30. if ( $counts['themes'] ) { 
  31. /** translators: 1: Number of updates available to themes */ 
  32. $titles['themes'] = sprintf( _n( '%d Theme Update', '%d Theme Updates', $counts['themes'] ), $counts['themes'] ); 
  33. if ( $counts[translations] ) { 
  34. $titles[translations] = __( 'Translation Updates' ); 
  35.  
  36. $update_title = $titles ? esc_attr( implode( ', ', $titles ) ) : ''; 
  37.  
  38. $update_data = array( 'counts' => $counts, 'title' => $update_title ); 
  39. /** 
  40. * Filters the returned array of update data for plugins, themes, and WordPress core. 
  41. * @since 3.5.0 
  42. * @param array $update_data { 
  43. * Fetched update data. 
  44. * @type array $counts An array of counts for available plugin, theme, and WordPress updates. 
  45. * @type string $update_title Titles of available updates. 
  46. * } 
  47. * @param array $titles An array of update counts and UI strings for available updates. 
  48. */ 
  49. return apply_filters( 'wp_get_update_data', $update_data, $titles );