Make WordPress Core


Ignore:
Timestamp:
07/27/2024 12:25:44 AM (22 months ago)
Author:
peterwilsoncc
Message:

General: Introduce wp_get_wp_version() to get unmodified version.

Introduces wp_get_wp_version() to get an unmodified value of $wp_version from wp-includes/version.php. Some plugins modify the global in an attempt to improve security through obscurity. This practice can cause errors in WordPress so the ability to get an unmodified version is needed.

Replaces instances within the code base in which version.php was required in order to get an unmodified value. script-loader.php is intentionally excluded from the replacements as the function is not always available to the file.

Props debarghyabanerjee, afragen, costdev.
See #61627.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/update.php

    r58409 r58813  
    3232    }
    3333
    34     // Include an unmodified $wp_version.
    35     require ABSPATH . WPINC . '/version.php';
    3634    $php_version = PHP_VERSION;
    3735
     
    4038
    4139    // Invalidate the transient when $wp_version changes.
    42     if ( is_object( $current ) && $wp_version !== $current->version_checked ) {
     40    if ( is_object( $current ) && wp_get_wp_version() !== $current->version_checked ) {
    4341        $current = false;
    4442    }
     
    4745        $current                  = new stdClass();
    4846        $current->updates         = array();
    49         $current->version_checked = $wp_version;
     47        $current->version_checked = wp_get_wp_version();
    5048    }
    5149
     
    9694    sort( $extensions, SORT_STRING | SORT_FLAG_CASE );
    9795    $query = array(
    98         'version'            => $wp_version,
     96        'version'            => wp_get_wp_version(),
    9997        'php'                => $php_version,
    10098        'locale'             => $locale,
     
    192190    $options = array(
    193191        'timeout'    => $doing_cron ? 30 : 3,
    194         'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
     192        'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ),
    195193        'headers'    => array(
    196194            'wp_install' => $wp_install,
     
    267265    $updates->updates         = $offers;
    268266    $updates->last_checked    = time();
    269     $updates->version_checked = $wp_version;
     267    $updates->version_checked = wp_get_wp_version();
    270268
    271269    if ( isset( $body['translations'] ) ) {
     
    315313        return;
    316314    }
    317 
    318     // Include an unmodified $wp_version.
    319     require ABSPATH . WPINC . '/version.php';
    320315
    321316    // If running blog-side, bail unless we've not checked in the last 12 hours.
     
    424419            'all'          => wp_json_encode( true ),
    425420        ),
    426         'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
     421        'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ),
    427422    );
    428423
     
    591586    }
    592587
    593     // Include an unmodified $wp_version.
    594     require ABSPATH . WPINC . '/version.php';
    595 
    596588    $installed_themes = wp_get_themes();
    597589    $translations     = wp_get_installed_translations( 'themes' );
     
    706698            'locale'       => wp_json_encode( $locales ),
    707699        ),
    708         'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
     700        'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ),
    709701    );
    710702
     
    990982 */
    991983function _maybe_update_core() {
    992     // Include an unmodified $wp_version.
    993     require ABSPATH . WPINC . '/version.php';
    994 
    995984    $current = get_site_transient( 'update_core' );
    996985
    997986    if ( isset( $current->last_checked, $current->version_checked )
    998987        && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked )
    999         && $current->version_checked === $wp_version
     988        && wp_get_wp_version() === $current->version_checked
    1000989    ) {
    1001990        return;
Note: See TracChangeset for help on using the changeset viewer.