Skip to content

Instantly share code, notes, and snippets.

@ironprogrammer
Last active June 27, 2023 23:11
Show Gist options
  • Save ironprogrammer/1aaff6f60b263c1842e3584365729ffc to your computer and use it in GitHub Desktop.
Save ironprogrammer/1aaff6f60b263c1842e3584365729ffc to your computer and use it in GitHub Desktop.
Trac 57662 test plugin -- enables custom WordPress package update
<?php
/**
* Plugin Name: Fake WordPress Update
* Description: Filters the value of <code>site_transient_update_core</code> to allow a custom install package.
* Author: WordPress Core Contributors
* Author URI: https://make.wordpress.org/core
* License: GPLv2 or later
* Version: 1.0.0
*
* Adapted from https://gist.githubusercontent.com/hellofromtonya/bb0aa2d4b2311c8b40fa5ae8ada4dc19
*/
add_filter(
'site_transient_update_core',
function ( $value ) {
if ( ! isset( $value->updates ) ) {
return $value;
}
$fake_update_location = trailingslashit( get_bloginfo( 'url' ) ) . 'wordpress-custom.zip';
$fake_update = (object) array(
'response' => 'upgrade',
'download' => $fake_update_location,
'locale' => 'en_US',
'packages' =>
(object) array(
'full' => $fake_update_location,
'no_content' => $fake_update_location,
'new_bundled' => $fake_update_location,
'partial' => '',
'rollback' => '',
),
'current' => '6.3.0-custom',
'version' => '6.3.0-custom',
'php_version' => '5.6.20',
'mysql_version' => '5.0',
'new_bundled' => '6.3',
'partial_version' => '',
'version_checked' => '',
);
array_unshift( $value->updates, $fake_update );
return $value;
}
);
@ironprogrammer
Copy link
Author

ironprogrammer commented Feb 7, 2023

To test the patch for Trac 57662 using this plugin:

  1. First follow the setup Steps 1-7 outlined here: https://core.trac.wordpress.org/ticket/57662#comment:3
  2. Refer to the following commands to prepare a custom package ZIP that contains the patch (this is instead of using the WordPress Beta Tester plugin to upgrade):
# AFTER COMPLETING TEST STEP 7, CONTINUE HERE:

# PREPARE CUSTOM PACKAGE ZIP
# download 6.2-beta1 (or update to a newer zip if needed)
curl -O https://downloads.wordpress.org/release/wordpress-6.2-beta1.zip
unzip wordpress-6.2-beta1.zip
# download patch file for PR 4029 (for update-core.php)
cd wordpress
curl -O https://patch-diff.githubusercontent.com/raw/WordPress/wordpress-develop/pull/4029.diff
# apply patch
patch wp-admin/includes/update-core.php 4029.diff
# should show: patching file wp-admin/includes/update-core.php
# now zip the customized package
cd ..
zip -r wordpress-custom.zip wordpress
# change directory to test site root, e.g.
cd ~/Sites/wp-install-test/
# copy custom package into the site root, e.g.
cp ~/Downloads/wordpress-custom.zip .
# NOTE: Custom ZIP file must be accessible at:
#   http://<your-test.site>/wordpress-custom.zip

# PREPARE CUSTOM UPDATE PLUGIN
# install custom wordpress update plugin
curl https://gist.githubusercontent.com/ironprogrammer/1aaff6f60b263c1842e3584365729ffc/raw/782e3683a88f560c665313c8365c807b6093847b/fake-wordpress-update.php -o wp-content/plugins/fake-wordpress-update.php
# enable the plugin
wp plugin activate fake-wordpress-update

# NOW PROCEED WITH TEST STEP 10
  1. Now continue with the original test instructions at Step 10.

Once testing is complete, deactivate the plugin to prevent the fake update nag.

@ironprogrammer
Copy link
Author

On 2023-06-27 updated plugin to fake version 6.3.0-custom for Trac 58206 testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment