• Resolved belabbesislam

    (@belabbesislam)


    Hey, there is an issue with the plugin site.com/wp-json does not work when doing client-side requests.

    doing fetch(“site.com/wp-json) on the client side returns 200 OK with empty response text but doing the same server-side works fine

    this is the request raw when the plugin is on

    HTTP/1.1 200 OK
    Date: Sun, 27 Jul 2025 16:21:03 GMT
    Server: Apache
    cf-edge-cache: no-cache
    Content-Encoding: gzip
    Vary: Accept-Encoding
    Cache-Control: max-age=2592000
    Expires: Tue, 26 Aug 2025 16:21:03 GMT
    Referrer-Policy: no-referrer-when-downgrade
    Keep-Alive: timeout=100
    Connection: Keep-Alive
    Transfer-Encoding: chunked
    Content-Type: text/html; charset=UTF-8

    when the plugin is off

    HTTP/1.1 200 OK
    Date: Sun, 27 Jul 2025 16:22:27 GMT
    Server: Apache
    cf-edge-cache: no-cache
    X-Robots-Tag: noindex
    X-Content-Type-Options: nosniff
    Access-Control-Expose-Headers: X-WP-Total, X-WP-TotalPages, Link
    Access-Control-Allow-Headers: Authorization, X-WP-Nonce, Content-Disposition, Content-MD5, Content-Type
    X-WP-Nonce: xxxx
    X-WP-Total: 306
    X-WP-TotalPages: 31
    Link: xxxxxx/wp-json/wp/v2/users?_locale=user&page=2; rel="next"
    Allow: GET, POST
    Expires: Wed, 11 Jan 1984 05:00:00 GMT
    Cache-Control: no-cache, must-revalidate, max-age=0, no-store, private
    Content-Encoding: gzip
    Vary: Accept-Encoding
    Referrer-Policy: no-referrer-when-downgrade
    Keep-Alive: timeout=100
    Connection: Keep-Alive
    Transfer-Encoding: chunked
    Content-Type: application/json; charset=UTF-8
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Alexandru Tapuleasa

    (@talextech)

    Hi,

    Please try going to the Exceptions tab and uncheck All for the “Apply settings on” option and just leave the sub-options checked and see if that fixes it 🙂

    Thread Starter belabbesislam

    (@belabbesislam)

    This is already the case. i’m only checking Post content

    But currently, for anyone stuck with the same issue, the workaround I did was create a must-use plugin that disables the plugin if we are doing REST.

    <?php
    /*
    Plugin Name: wp external links rest api exclude
    Description: Disable wp external links plugin on rest api requests
    */

    function is_rest_api_request() {
    if ( empty( $_SERVER['REQUEST_URI'] ) ) {
    // Probably a CLI request
    return false;
    }

    $rest_prefix = trailingslashit( rest_get_url_prefix() );
    $is_rest_api_request = strpos( $_SERVER['REQUEST_URI'], $rest_prefix ) !== false;

    return apply_filters( 'is_rest_api_request', $is_rest_api_request );
    }

    add_filter( 'option_active_plugins', function( $plugins ) {

    if ( ! is_rest_api_request() ) {
    return $plugins;
    }

    // Only run this logic during REST requests
    $denylist_plugins = array_flip(
    array(
    'wp-external-links/wp-external-links.php',
    )
    );

    /**
    * Loop through the active plugins.
    * If it's in the deny list, remove it from the list of plugins to load.
    */
    foreach ( $plugins as $key => $plugin ) {
    if ( isset( $denylist_plugins[ $plugin ] ) ) {
    unset( $plugins[ $key ] );
    }
    }

    return $plugins;
    } );

    Or simply

     return array_filter( $plugins, function( $plugin ) {
    return ! in_array( $plugin, [
    'wp-external-links/wp-external-links.php',
    ], true );
    } );
    • This reply was modified 10 months, 1 week ago by belabbesislam.
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Rest Api returns empty 200 ok’ is closed to new replies.