wp_upgrade

Runs WordPress Upgrade functions.

Description

wp_upgrade(); 

Upgrades the database if needed during a site update.


Usage

  1. if ( !function_exists( 'wp_upgrade' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/upgrade.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_upgrade(); 
  7.  

Defined (1)

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

/wp-admin/includes/upgrade.php  
  1. function wp_upgrade() { 
  2. global $wp_current_db_version, $wp_db_version, $wpdb; 
  3.  
  4. $wp_current_db_version = __get_option('db_version'); 
  5.  
  6. // We are up-to-date. Nothing to do. 
  7. if ( $wp_db_version == $wp_current_db_version ) 
  8. return; 
  9.  
  10. if ( ! is_blog_installed() ) 
  11. return; 
  12.  
  13. if ( is_multisite() && is_main_site() ) 
  14.  
  15. if ( is_multisite() ) { 
  16. if ( $wpdb->get_row( "SELECT blog_id FROM {$wpdb->blog_versions} WHERE blog_id = '{$wpdb->blogid}'" ) ) 
  17. $wpdb->query( "UPDATE {$wpdb->blog_versions} SET db_version = '{$wp_db_version}' WHERE blog_id = '{$wpdb->blogid}'" ); 
  18. else 
  19. $wpdb->query( "INSERT INTO {$wpdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( '{$wpdb->blogid}', '{$wp_db_version}', NOW());" ); 
  20.  
  21. /** 
  22. * Fires after a site is fully upgraded. 
  23. * @since 3.9.0 
  24. * @param int $wp_db_version The new $wp_db_version. 
  25. * @param int $wp_current_db_version The old (current) $wp_db_version. 
  26. */ 
  27. do_action( 'wp_upgrade', $wp_db_version, $wp_current_db_version );