• Resolved jhotadhari

    (@jhotadhari)


    Hi,

    would like to skip the catching for all requests from wp-admin.

    Currently I added some lines to Endpoint_Api::skip_caching:

    if ( substr( $_SERVER['HTTP_REFERER'], 0, strlen( admin_url()  )) === admin_url() ) {	
    	return true;
    }

    Would be nice to have a filter there, so I could write an mu-plugin and hook my custom skip function. Some filter like this:

    if ( apply_filters( 'wp_rest_cache/skip_caching', false ) ) {
    	return true;
    }

    To skip all requests from wp-admin referer solves/skips all gutenberg issues.
    Adding an option to the plugin settings page would be great. Think that might help some users.

    Some background: I got this issue using wpml. It always shows the cached custom taxonomies and terms in the editor inspector, that leads into weird language syncing issues.
    Example: gutenberg wants to list our custom taxonomy terms for prefix_region and calls /wp-json/wp/v2/prefix_region?per_page=100&orderby=name&order=asc&_fields=id%2Cname%2Cparent&_locale=user. The request url is same for all languages.

    And thanks for your plugin! its great. and the code is nice to read, lovely poetry

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter jhotadhari

    (@jhotadhari)

    Hi, in snippet above, I forgot to check if HTTP_REFERER is existing in $_SERVER array. So, should work without error:

    if ( array_key_exists( 'HTTP_REFERER', $_SERVER ) && substr( $_SERVER['HTTP_REFERER'], 0, strlen( admin_url() ) ) === admin_url() ) {
    	return true;
    }
    Thread Starter jhotadhari

    (@jhotadhari)

    Well, since we can’t trust HTTP_REFERER, could skip caching if a user logged in. its to early for is_user_logged_in, but cookie should be there.

    if ( isset( $_COOKIE ) ) {
    	foreach( $_COOKIE as $key => $val ) {
    		if ( substr( $key, 0, strlen( 'wordpress_logged_in_' ) ) === 'wordpress_logged_in_' ) {
    			return true;
    		}
    	};
    }

    this will skip caching everywhere, frontend and backend. But at least the editor works fine.

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @jhotadhari

    Thank you for using our plugin and your kind words!

    I understand your issue, but I don’t think we will be implementing something to skip all requests from the wp-admin, since there are situations where you do want to cache those requests. However I will discuss with my colleagues your suggestion of adding a filter so you can implement your own rules using a mu-plugin (I am glad you already understand it should be a mu-plugin and not a normal plugin ?? )

    Thread Starter jhotadhari

    (@jhotadhari)

    With a filter, I will be happily satisfied ??

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @jhotadhari

    Sorry for the late reply, but we just released a new version of our plugin which includes the wp_rest_cache/skip_caching filter. If you use the filter to return true the cache will be skipped.

    Thread Starter jhotadhari

    (@jhotadhari)

    Works great! thank you.

    Sorry forgot to answer ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘allow skip catching for wp-admin referer, or by filter’ is closed to new replies.