Make WordPress Core


Ignore:
Timestamp:
07/27/2024 12:25:44 AM (10 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-admin/includes/plugin-install.php

    r58409 r58813  
    101101 */
    102102function plugins_api( $action, $args = array() ) {
    103     // Include an unmodified $wp_version.
    104     require ABSPATH . WPINC . '/version.php';
    105 
    106103    if ( is_array( $args ) ) {
    107104        $args = (object) $args;
     
    119116
    120117    if ( ! isset( $args->wp_version ) ) {
    121         $args->wp_version = substr( $wp_version, 0, 3 ); // x.y
     118        $args->wp_version = substr( wp_get_wp_version(), 0, 3 ); // x.y
    122119    }
    123120
     
    169166        $http_args = array(
    170167            'timeout'    => 15,
    171             'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
     168            'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ),
    172169        );
    173170        $request   = wp_remote_get( $url, $http_args );
Note: See TracChangeset for help on using the changeset viewer.