Make WordPress Core

Opened 5 years ago

Last modified 5 years ago

#47301 new defect (bug)

Core_Upgrader class not extending or working properly

Reported by: techeshta's profile techeshta Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Upgrade/Install Keywords: has-screenshots reporter-feedback
Focuses: Cc:

Description

It might be the first time as I am trying to create manual functionality via extending Core_Upgrader class.

And it's not working same like WordPress Updates doing by default or not giving response too!

Ref. https://wordpress.org/support/topic/looking-for-the-help-core_upgrader/

Let me attach some screenshots here.

---

Actually, what I am trying to do?

Getting a list of WordPress Updates and selecting the latest one and do a manual update with Ajax call.

Ref. https://developer.wordpress.org/reference/functions/get_core_updates/

Attachments (3)

full-response.png (22.4 KB) - added by techeshta 5 years ago.
Full original response of WordPress Updates
response2.png (4.0 KB) - added by techeshta 5 years ago.
Response for WordPress updates via manual code
response3.png (83.9 KB) - added by techeshta 5 years ago.
Response during WordPress updates with error codes via manual code

Download all attachments as: .zip

Change History (6)

@techeshta
5 years ago

Full original response of WordPress Updates

@techeshta
5 years ago

Response for WordPress updates via manual code

@techeshta
5 years ago

Response during WordPress updates with error codes via manual code

#1 @SergeyBiryukov
5 years ago

  • Component changed from General to Upgrade/Install
  • Keywords reporter-feedback added

Hi @techeshta, welcome to WordPress Trac! Thanks for the report.

It might be the first time as I am trying to create manual functionality via extending Core_Upgrader class.

What's the difference between this manual functionality and default WordPress updates?

And it's not working same like WordPress Updates doing by default or not giving response too!

Could you share an example piece of code to reproduce the problem?

#2 @techeshta
5 years ago

Hi @SergeyBiryukov,

Thanks for your comment on the issue.

What's the difference between this manual functionality and default WordPress updates?

There is a one-click update instead of going to the WordPress Updates page.

Could you share an example piece of code to reproduce the problem?

Yes, of course. Why not!

Here it is,

function ff_wordpress_instant_update() {
	ini_set('max_execution_time', 10000);
	global $wp_version;
	$res = array();
	ob_start();

	include_once ( ABSPATH . '/wp-admin/includes/admin.php' );
	require_once ( ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' );
	include_once ( ABSPATH . '/wp-admin/includes/update.php' );
	$core_updates = get_core_updates();
	$cur_phpversion = phpversion();
	$wp_phpversion = $core_updates[0]->php_version;
	if($cur_phpversion < $wp_phpversion) {
		$res['phpvermsg'] = "WordPress update requires PHP version ".$wp_phpversion." or higher. You are currently running PHP version ".$cur_phpversion." Please contact your host to upgrade your PHP version. You may also be able to do it via cPanel, under Software ==> PHP Selector.";
		$res['isres'] = false;
		echo json_encode($res);
		exit;
	}
	
	if (count($core_updates) > 0) {

		foreach ($core_updates as $core_update) {
			global $latest_version;

			if ('latest' === $core_update->response) {
				$information['upgrade'] = 'SUCCESS';
			} else {
				if ('upgrade' === $core_update->response && $core_update->locale === get_locale() && version_compare($wp_version, $core_update->current, '<=')) {
					// Upgrade!
					$upgrade = false;
					if (class_exists('Core_Upgrader')) {
						$core = new Core_Upgrader();
						$upgrade = $core->upgrade($core_update);							
					}
					break;
				}
			}
		}
	}
}

Let me know if you want any other things from my end.

Thanks

#3 @dd32
5 years ago

Core_Upgrader is a bit special, in that it doesn't actually contain all the upgrade logic, and doesn't utilise the WP_Upgrader abstractions and niceties other than for the initial bootstrap of the UI.

Just before it starts coping all files over, Core_Upgrader ceases to send updates to the Upgrader_Skin and instead passes them to the update_feedback filter in update_core(), you'll have to do some juggling with filters and $skin to get all the messages in the right order in the right place.

Additionally, upgrades through that method will also trigger HTTP redirects to the about page amongst others. You may want to look up how the background updates work: https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/class-wp-automatic-updater.php#L439

Note: See TracTickets for help on using tickets.