Make WordPress Core


Ignore:
Timestamp:
07/27/2024 12:25:44 AM (21 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/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php

    r56753 r58813  
    8888     */
    8989    public function get_items( $request ) {
    90         /*
    91          * Include an unmodified `$wp_version`, so the API can craft a response that's tailored to
    92          * it. Some plugins modify the version in a misguided attempt to improve security by
    93          * obscuring the version, which can cause invalid requests.
    94          */
    95         require ABSPATH . WPINC . '/version.php';
    96 
    9790        $valid_query_args = array(
    9891            'offset'   => true,
     
    107100
    108101        $query_args['locale']             = get_user_locale();
    109         $query_args['wp-version']         = $wp_version;
     102        $query_args['wp-version']         = wp_get_wp_version();
    110103        $query_args['pattern-categories'] = isset( $request['category'] ) ? $request['category'] : false;
    111104        $query_args['pattern-keywords']   = isset( $request['keyword'] ) ? $request['keyword'] : false;
Note: See TracChangeset for help on using the changeset viewer.