Making WordPress.org

Changeset 5223


Ignore:
Timestamp:
03/30/2017 11:01:40 PM (8 years ago)
Author:
iandunn
Message:

WordCamp Helpers: Remove trailing slash from partial endpoint path

If the path ended in a /, like with /wp-json/wp/v2/sessions/, and then a client visits the unslashed endpoint URL (e.g., https://2016.seattle.wordcamp.org/wp-json/wp/v2/sessions), then the function would return early and the fields would not be registered.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/helper-functions.php

    r5219 r5223  
    322322 * @param array  $meta_fields An array index by the field slug, with values to be passed to `register_meta()` as
    323323 *                            `$args`. For example, `array( '_wcpt_session_slides' => array( 'single' => true ) )`
    324  * @param string $endpoint    The full path of the endpoint. For example, '/wp-json/wp/v2/sessions/'
     324 * @param string $endpoint    The partial path of the endpoint. For example, '/wp-json/wp/v2/sessions'.
    325325 */
    326326function wcorg_register_meta_only_on_endpoint( $meta_type, $meta_fields, $endpoint ) {
    327     $is_correct_endpoint_request = false !== strpos( $_SERVER['REQUEST_URI'], $endpoint );
     327    $is_correct_endpoint_request = false !== strpos( $_SERVER['REQUEST_URI'], untrailingslashit( $endpoint ) );
    328328
    329329    if ( ! $is_correct_endpoint_request ) {
Note: See TracChangeset for help on using the changeset viewer.