@@ -1551,33 +1551,32 @@ function cleanup() {
15511551}
15521552
15531553/**
1554- * WordPress Automatic Upgrader helper class
1554+ * WordPress automatic background upgrader.
15551555 *
15561556 * @since 3.7.0
15571557 */
15581558class WP_Automatic_Upgrader {
15591559
1560- static $ upgrade_results = array ();
1560+ protected $ update_results = array ();
15611561
1562- static function upgrader_disabled () {
1563- // That's a no if you don't want files changes
1562+ function is_disabled () {
1563+ // Background updates are disabled if you don't want file changes.
15641564 if ( defined ( 'DISALLOW_FILE_MODS ' ) && DISALLOW_FILE_MODS )
15651565 return true ;
15661566
1567- // More fine grained control can be done through the WP_AUTO_UPDATE_CORE constant and filters
1568- if ( defined ( 'AUTOMATIC_UPDATER_DISABLED ' ) && AUTOMATIC_UPDATER_DISABLED )
1569- return true ;
1570-
15711567 if ( defined ( 'WP_INSTALLING ' ) )
15721568 return true ;
15731569
1574- return apply_filters ( 'auto_upgrader_disabled ' , false );
1570+ // More fine grained control can be done through the WP_AUTO_UPDATE_CORE constant and filters.
1571+ $ disabled = defined ( 'AUTOMATIC_UPDATES_DISABLED ' ) && AUTOMATIC_UPDATES_DISABLED ;
1572+
1573+ return apply_filters ( 'auto_upgrader_disabled ' , $ disabled );
15751574 }
15761575
15771576 /**
15781577 * Check for GIT/SVN checkouts.
15791578 */
1580- static function is_vcs_checkout ( $ context ) {
1579+ function is_vcs_checkout ( $ context ) {
15811580 $ context_dirs = array ( untrailingslashit ( $ context ) );
15821581 if ( $ context !== ABSPATH )
15831582 $ context_dirs [] = untrailingslashit ( ABSPATH );
@@ -1607,17 +1606,16 @@ static function is_vcs_checkout( $context ) {
16071606 /**
16081607 * Tests to see if we can and should upgrade a specific item.
16091608 */
1610- static function should_auto_update ( $ type , $ item , $ context ) {
1609+ function should_upgrade ( $ type , $ item , $ context ) {
1610+ if ( $ this ->is_disabled () )
1611+ return false ;
16111612
16121613 // Checks to see if WP_Filesystem is set up to allow unattended upgrades.
16131614 $ skin = new Automatic_Upgrader_Skin ;
16141615 if ( ! $ skin ->request_filesystem_credentials ( false , $ context ) )
16151616 return false ;
16161617
1617- if ( self ::upgrader_disabled () )
1618- return false ;
1619-
1620- if ( self ::is_vcs_checkout ( $ context ) )
1618+ if ( $ this ->is_vcs_checkout ( $ context ) )
16211619 return false ;
16221620
16231621 // Next up, do we actually have it enabled for this type of update?
@@ -1657,7 +1655,7 @@ static function should_auto_update( $type, $item, $context ) {
16571655 return true ;
16581656 }
16591657
1660- static function upgrade ( $ type , $ item ) {
1658+ function upgrade ( $ type , $ item ) {
16611659
16621660 $ skin = new Automatic_Upgrader_Skin ();
16631661
@@ -1683,7 +1681,7 @@ static function upgrade( $type, $item ) {
16831681 }
16841682
16851683 // Determine whether we can and should perform this upgrade.
1686- if ( ! self :: should_auto_update ( $ type , $ item , $ context ) )
1684+ if ( ! $ this -> should_upgrade ( $ type , $ item , $ context ) )
16871685 return false ;
16881686
16891687 switch ( $ type ) {
@@ -1724,7 +1722,7 @@ static function upgrade( $type, $item ) {
17241722 }
17251723 }
17261724
1727- self :: $ upgrade_results [ $ type ][] = (object ) array (
1725+ $ this -> update_results [ $ type ][] = (object ) array (
17281726 'item ' => $ item ,
17291727 'result ' => $ upgrade_result ,
17301728 'name ' => $ item_name ,
@@ -1737,8 +1735,7 @@ static function upgrade( $type, $item ) {
17371735 /**
17381736 * Kicks off a upgrade request for each item in the upgrade "queue"
17391737 */
1740- static function perform_auto_updates () {
1741-
1738+ function run () {
17421739 $ lock_name = 'auto_upgrader.lock ' ;
17431740 if ( get_site_option ( $ lock_name ) ) {
17441741 // Test to see if it was set more than an hour ago, if so, cleanup.
@@ -1762,7 +1759,7 @@ static function perform_auto_updates() {
17621759 $ plugin_updates = get_site_transient ( 'update_plugins ' );
17631760 if ( $ plugin_updates && !empty ( $ plugin_updates ->response ) ) {
17641761 foreach ( array_keys ( $ plugin_updates ->response ) as $ plugin ) {
1765- self :: upgrade ( 'plugin ' , $ plugin );
1762+ $ this -> upgrade ( 'plugin ' , $ plugin );
17661763 }
17671764 // Force refresh of plugin update information
17681765 wp_clean_plugins_cache ();
@@ -1773,7 +1770,7 @@ static function perform_auto_updates() {
17731770 $ theme_updates = get_site_transient ( 'update_themes ' );
17741771 if ( $ theme_updates && !empty ( $ theme_updates ->response ) ) {
17751772 foreach ( array_keys ( $ theme_updates ->response ) as $ theme ) {
1776- self :: upgrade ( 'theme ' , $ theme );
1773+ $ this -> upgrade ( 'theme ' , $ theme );
17771774 }
17781775 // Force refresh of theme update information
17791776 wp_clean_themes_cache ();
@@ -1783,19 +1780,24 @@ static function perform_auto_updates() {
17831780 wp_version_check (); // Check for Core updates
17841781 $ extra_update_stats = array ();
17851782 $ core_update = find_core_auto_update ();
1783+
17861784 if ( $ core_update ) {
17871785 $ start_time = time ();
1788- $ core_update_result = self ::upgrade ( 'core ' , $ core_update );
1786+
1787+ $ core_update_result = $ this ->upgrade ( 'core ' , $ core_update );
17891788 delete_site_transient ( 'update_core ' );
1789+
17901790 $ extra_update_stats ['success ' ] = is_wp_error ( $ core_update_result ) ? $ core_update_result ->get_error_code () : true ;
17911791 $ extra_update_stats ['error_data ' ] = is_wp_error ( $ core_update_result ) ? $ core_update_result ->get_error_data () : '' ;
1792+
17921793 if ( is_wp_error ( $ core_update_result ) && 'rollback_was_required ' == $ core_update_result ->get_error_code () ) {
17931794 $ rollback_data = $ core_update_result ->get_error_data ();
17941795 $ extra_update_stats ['success ' ] = is_wp_error ( $ rollback_data ['update ' ] ) ? $ rollback_data ['update ' ]->get_error_code () : $ rollback_data ['update ' ];
17951796 $ extra_update_stats ['error_data ' ] = is_wp_error ( $ rollback_data ['update ' ] ) ? $ rollback_data ['update ' ]->get_error_data () : '' ;
17961797 $ extra_update_stats ['rollback ' ] = is_wp_error ( $ rollback_data ['rollback ' ] ) ? $ rollback_data ['rollback ' ]->get_error_code () : true ; // If it's not a WP_Error, the rollback was successful.
17971798 $ extra_update_stats ['rollback_data ' ] = is_wp_error ( $ rollback_data ['rollback ' ] ) ? $ rollback_data ['rollback ' ]->get_error_data () : '' ;
17981799 }
1800+
17991801 $ extra_update_stats ['fs_method ' ] = $ GLOBALS ['wp_filesystem ' ]->method ;
18001802 $ extra_update_stats ['fs_method_forced ' ] = defined ( 'FS_METHOD ' ) || has_filter ( 'filesystem_method ' );
18011803 $ extra_update_stats ['time_taken ' ] = ( time () - $ start_time );
@@ -1811,8 +1813,9 @@ static function perform_auto_updates() {
18111813 $ language_updates = wp_get_translation_updates ();
18121814 if ( $ language_updates ) {
18131815 foreach ( $ language_updates as $ update ) {
1814- self :: upgrade ( 'language ' , $ update );
1816+ $ this -> upgrade ( 'language ' , $ update );
18151817 }
1818+
18161819 // Clear existing caches
18171820 wp_clean_plugins_cache ();
18181821 wp_clean_themes_cache ();
@@ -1823,33 +1826,20 @@ static function perform_auto_updates() {
18231826 wp_update_plugins (); // Check for Plugin updates
18241827 }
18251828
1826- /**
1827- * Filter whether to email an update summary to the site administrator.
1828- *
1829- * @since 3.7.0
1830- *
1831- * @param bool Whether or not email should be sent to administrator. Default true.
1832- * @param bool|array $core_update An array of core update data, false otherwise.
1833- * @param object $theme_updates Object containing theme update properties.
1834- * @param object $plugin_updates Object containing plugin update properties.
1835- * @param array $language_updates Array containing the Language updates available.
1836- * @param array $upgrade_results Array of the upgrade results keyed by upgrade type, and plugin/theme slug.
1837- */
1838- if ( apply_filters ( 'enable_auto_upgrade_email ' , true , $ core_update , $ theme_updates , $ plugin_updates , $ language_updates , self ::$ upgrade_results ) )
1839- self ::send_email ();
1829+ $ this ->send_debug_email ();
18401830
18411831 // Clear the lock
18421832 delete_site_option ( $ lock_name );
18431833
18441834 }
18451835
1846- static function send_email () {
1836+ function send_debug_email () {
18471837
1848- if ( empty ( self :: $ upgrade_results ) )
1838+ if ( empty ( $ this -> update_results ) )
18491839 return ;
18501840
18511841 $ upgrade_count = 0 ;
1852- foreach ( self :: $ upgrade_results as $ type => $ upgrades )
1842+ foreach ( $ this -> update_results as $ type => $ upgrades )
18531843 $ upgrade_count += count ( $ upgrades );
18541844
18551845 $ body = array ();
@@ -1858,8 +1848,8 @@ static function send_email() {
18581848 $ body [] = 'WordPress site: ' . network_home_url ( '/ ' );
18591849
18601850 // Core
1861- if ( isset ( self :: $ upgrade_results ['core ' ] ) ) {
1862- $ result = self :: $ upgrade_results ['core ' ][0 ];
1851+ if ( isset ( $ this -> update_results ['core ' ] ) ) {
1852+ $ result = $ this -> update_results ['core ' ][0 ];
18631853 if ( $ result ->result && ! is_wp_error ( $ result ->result ) ) {
18641854 $ body [] = sprintf ( 'SUCCESS: WordPress was successfully updated to %s ' , $ result ->name );
18651855 } else {
@@ -1871,18 +1861,18 @@ static function send_email() {
18711861
18721862 // Plugins, Themes, Languages
18731863 foreach ( array ( 'plugin ' , 'theme ' , 'language ' ) as $ type ) {
1874- if ( ! isset ( self :: $ upgrade_results [ $ type ] ) )
1864+ if ( ! isset ( $ this -> update_results [ $ type ] ) )
18751865 continue ;
1876- $ success_items = wp_list_filter ( self :: $ upgrade_results [ $ type ], array ( 'result ' => true ) );
1866+ $ success_items = wp_list_filter ( $ this -> update_results [ $ type ], array ( 'result ' => true ) );
18771867 if ( $ success_items ) {
18781868 $ body [] = "The following {$ type }s were successfully updated: " ;
18791869 foreach ( wp_list_pluck ( $ success_items , 'name ' ) as $ name )
18801870 $ body [] = ' * SUCCESS: ' . $ name ;
18811871 }
1882- if ( $ success_items != self :: $ upgrade_results [ $ type ] ) {
1872+ if ( $ success_items != $ this -> update_results [ $ type ] ) {
18831873 // Failed updates
18841874 $ body [] = "The following {$ type }s failed to update: " ;
1885- foreach ( self :: $ upgrade_results [ $ type ] as $ item ) {
1875+ foreach ( $ this -> update_results [ $ type ] as $ item ) {
18861876 if ( ! $ item ->result || is_wp_error ( $ item ->result ) ) {
18871877 $ body [] = ' * FAILED: ' . $ item ->name ;
18881878 $ failures ++;
@@ -1913,9 +1903,9 @@ static function send_email() {
19131903 $ body [] = '' ;
19141904
19151905 foreach ( array ( 'core ' , 'plugin ' , 'theme ' , 'language ' ) as $ type ) {
1916- if ( ! isset ( self :: $ upgrade_results [ $ type ] ) )
1906+ if ( ! isset ( $ this -> update_results [ $ type ] ) )
19171907 continue ;
1918- foreach ( self :: $ upgrade_results [ $ type ] as $ upgrade ) {
1908+ foreach ( $ this -> update_results [ $ type ] as $ upgrade ) {
19191909 $ body [] = $ upgrade ->name ;
19201910 $ body [] = str_repeat ( '- ' , strlen ( $ upgrade ->name ) );
19211911 foreach ( $ upgrade ->messages as $ message )
0 commit comments