Skip to content

Commit

Permalink
[BUGS-7497] fix wp version checker (#31)
Browse files Browse the repository at this point in the history
* move pantheon wp version check to a functions helper file

* require the new version in the Pantheon namespace

* test that the function exists
this is a bit of a vanity test because I wasn't able to successfully reproduce the failure state for this

* bump the pantheon mu plugin version
didn't get updated after the last update

* linting fixes

* update the test name

* remove a test that isn't really helpful
  • Loading branch information
jazzsequence authored Feb 14, 2024
1 parent 7d1d919 commit dbe012b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
18 changes: 18 additions & 0 deletions inc/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Pantheon mu-plugin helper functions
*
* @package pantheon
*/

namespace Pantheon;

/**
* Helper function that returns the current WordPress version.
*
* @return string
*/
function _pantheon_get_current_wordpress_version(): string {
include ABSPATH . WPINC . '/version.php';
return $wp_version; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
}
18 changes: 4 additions & 14 deletions inc/pantheon-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ function _pantheon_hide_update_nag() {
remove_action( 'network_admin_notices', 'update_nag', 3 );
}

/**
* Helper function that returns the current WordPress version.
*
* @return string
*/
function _pantheon_get_current_wordpress_version(): string {
include ABSPATH . WPINC . '/version.php';
return $wp_version; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
}

/**
* Get the latest WordPress version.
*
Expand All @@ -59,7 +49,7 @@ function _pantheon_get_latest_wordpress_version(): ?string {
*/
function _pantheon_is_wordpress_core_latest(): bool {
$latest_wp_version = _pantheon_get_latest_wordpress_version();
$wp_version = _pantheon_get_current_wordpress_version();
$wp_version = Pantheon\_pantheon_get_current_wordpress_version();

if ( null === $latest_wp_version ) {
return true;
Expand All @@ -75,7 +65,7 @@ function _pantheon_is_wordpress_core_latest(): bool {
* @return bool
*/
function _pantheon_is_wordpress_core_prerelease(): bool {
$wp_version = _pantheon_get_current_wordpress_version();
$wp_version = Pantheon\_pantheon_get_current_wordpress_version();

// Return true if our version is a prerelease. Pre-releases are identified by a dash in the version number.
return false !== strpos( $wp_version, '-' ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
Expand All @@ -88,7 +78,7 @@ function _pantheon_is_wordpress_core_prerelease(): bool {
* @return void
*/
function _pantheon_upstream_update_notice() {
$wp_version = _pantheon_get_current_wordpress_version();
$wp_version = Pantheon\_pantheon_get_current_wordpress_version();
$screen = get_current_screen();
// Translators: %s is a URL to the user's Pantheon Dashboard.
$notice_message = sprintf( __( 'Check for updates on <a href="%s">your Pantheon dashboard</a>.', 'pantheon-systems' ), 'https://dashboard.pantheon.io/sites/' . $_ENV['PANTHEON_SITE'] );
Expand Down Expand Up @@ -159,7 +149,7 @@ function _pantheon_register_upstream_update_notice() {
* @return object
*/
function _pantheon_disable_wp_updates(): object {
$wp_version = _pantheon_get_current_wordpress_version();
$wp_version = Pantheon\_pantheon_get_current_wordpress_version();
return (object) [
'updates' => [],
'version_checked' => $wp_version, // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
Expand Down
8 changes: 4 additions & 4 deletions pantheon.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
* Plugin Name: Pantheon
* Plugin URI: https://pantheon.io/
* Description: Building on Pantheon's and WordPress's strengths, together.
* Version: 1.2.1
* Version: 1.3.1
* Author: Pantheon
* Author URI: https://pantheon.io/
*
* @package pantheon
*/

define( 'PANTHEON_MU_PLUGIN_VERSION', '1.2.1' );
define( 'PANTHEON_MU_PLUGIN_VERSION', '1.3.1' );

if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ) {

require_once 'inc/functions.php';
require_once 'inc/pantheon-page-cache.php';
if ( ! defined( 'DISABLE_PANTHEON_UPDATE_NOTICES' ) || ! DISABLE_PANTHEON_UPDATE_NOTICES ) {
require_once 'inc/pantheon-updates.php';
}
// If the WP Font Library exists, we can add our font directory modifications. Use version_compare because the Font Library isn't actually loaded yet.
if ( version_compare( _pantheon_get_current_wordpress_version(), '6.5' ) ) {
if ( version_compare( Pantheon\_pantheon_get_current_wordpress_version(), '6.5' ) ) {
require_once 'inc/fonts.php';
}
if ( ! defined( 'RETURN_TO_PANTHEON_BUTTON' ) || RETURN_TO_PANTHEON_BUTTON ) {
Expand Down
10 changes: 9 additions & 1 deletion tests/phpunit/test-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class Test_Main extends WP_UnitTestCase {
*/
public function test_mu_plugin_constants() {
$this->assertTrue( defined( 'PANTHEON_MU_PLUGIN_VERSION' ) );
$this->assertEquals( '1.2.1', PANTHEON_MU_PLUGIN_VERSION );
$this->assertTrue( defined( 'FS_METHOD' ) );
$this->assertEquals( 'direct', FS_METHOD );

Expand All @@ -26,4 +25,13 @@ public function test_mu_plugin_constants() {
$this->assertTrue( MULTISITE );
}
}

/**
* Test that _pantheon_get_current_wordpress_version is available.
*/
public function test_get_current_wp_version_exists() {
// Check _pantheon_get_current_wordpress_version() is defined.
$this->assertTrue( function_exists( 'Pantheon\\_pantheon_get_current_wordpress_version' ) );
$this->assertIsString( Pantheon\_pantheon_get_current_wordpress_version() );
}
}
6 changes: 3 additions & 3 deletions tests/phpunit/test-pantheon-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Test_Pantheon_Updates extends WP_UnitTestCase {
*/
public function __construct() {
parent::__construct();
self::$wp_version = _pantheon_get_current_wordpress_version();
self::$wp_version = Pantheon\_pantheon_get_current_wordpress_version();
}

/**
Expand Down Expand Up @@ -64,7 +64,7 @@ public function test_pantheon_hide_update_nag() {
*/
public function test_pantheon_get_current_wordpress_version() {
// Run the function.
$result = _pantheon_get_current_wordpress_version();
$result = Pantheon\_pantheon_get_current_wordpress_version();
$current_version = self::get_latest_wp_version_from_file();

// If the current version is greater than the result, then we downloaded a nightly version for testing.
Expand Down Expand Up @@ -179,7 +179,7 @@ private static function get_next_beta_version() {
* Check if we're using a beta version.
*/
private static function is_prerelease() {
$current_version = _pantheon_get_current_wordpress_version();
$current_version = Pantheon\_pantheon_get_current_wordpress_version();
$installed_version = self::get_latest_wp_version_from_file();

// If the current version and the installed version are the same, then we're not using a prerelease.
Expand Down

0 comments on commit dbe012b

Please sign in to comment.