Forum Replies Created

Viewing 15 replies - 46 through 60 (of 518 total)
  • Plugin Author Richard Korthuis

    (@rockfire)

    Hi @superjin001,

    Good to hear it works for you! I must admit I am not always this quick in answering. You just happened to have send your question just before I opened my email and had time to respond ??

    If you have any more questions, feel free to open a new topic!

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @superjin001

    Thank you for using our plugin!

    Yes, you can do something like this:

    /**
     * Change the timeout for different endpoints.
     *
     * @param int $timeout The timeout as set in the settings.
     * @param array $options An array of options, containing the current uri ('uri'), the object type ('object_type'), the request headers ('request_headers') and the request method ('request_method').
     *
     * @return int
     */
    function wprc_variable_timeout( $timeout, $options ) {
    	if ( false !== strpos( 'wp/v2/posts', $options['uri'] ) ) {
    		$timeout = DAY_IN_SECONDS;
    	}
    
    	return $timeout;
    }
    
    add_filter( 'wp_rest_cache/timeout', 'wprc_variable_timeout', 10, 2 );
    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @nikhilgudadhe

    Thank you for using our plugin!

    Have you read our FAQ? Specifically the section “Can I register my own endpoint for caching?” This explains how you can add your own custom endpoints for caching.

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @mcsr

    Thank you for using our plugin!

    It is not because of the query parameter, custom endpoints aren’t cached by default. You can tell our plugin to cache your endpoint as described in our FAQ

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @kendawes

    Thank you for using our plugin!

    The multiple WP REST Cache notices should be resolved in our latest release. You should see only one notice, even if you updated multiple plugins.

    I am not familiair with iControlWP, but we also have a WP CLI action you could use to clear the caches: wp wp-rest-cache flush I don’t know if iControlWP has an option to run a WP CLI command, but that would be the way I would do it.

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @dezvolta

    Thank you for using our plugin!

    I just did a test on a clean WordPress install with your code snippet and our plugin. I didn’t get any error. Can you tell me what error you got?

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @stepantwnty

    Thank you for using our plugin!

    I see you marked your topic already as resolved, but just for anyone who reeds it I will still answer it.

    You should omit the regex part for the id from the allowed endpoints array. So your code should look like this:

    function wprc_add_acf_posts_endpoint( $allowed_endpoints ) {
    	if ( !isset( $allowed_endpoints[ 'product/v1' ] ) || !in_array( 'get', $allowed_endpoints[ 'product/v1' ] ) ) {
    		$allowed_endpoints[ 'product/v1' ][] = 'get';
    	}
    	return $allowed_endpoints;
    }
    add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_acf_posts_endpoint', 10, 1);
    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @jussipv , @jilfransoi and @adinehnsio

    Sorry it took me so long, I have been extremely busy, but we just released a new version of our plugin which includes a filter wp_rest_cache/pre_output_headers which can be used (from a mu-plugin with a name which is alfabetically before wp-rest-cache.php) to alter the headers. For example like this:

    /**
     * Add Access-Control-Allow-Headers headers to the response.
     *
     * @param array $headers The headers that will be sent to the client.
     * @param string $request_uri The REST URI that is being requested.
     *
     * @return array
     */
    function wprc_pre_output_headers( $headers, $request_uri ) {
    	$headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept';
    	return $headers;
    }
    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @mcsr

    Thank you for using our plugin!

    Yes, your issue is caused by the way our plugin works: if a call to the API is done, before any other code is executed, our plugin checks if a cache record is available for the current request. Now if a cache record is available it is returned and no other code is executed. So if later on there is an authentication check, that is also not executed. This is also why our plugin doesn’t cache any calls that have a nonce in their header, just to prevent caching of authenticated endpoints.

    You can have our plugin cache requests with a nonce using the filter wp_rest_cache/skip_nonce_caching See my reply in a previous topic about how to use it. You could also use this filter to first check the authentication and only if the user is authenticated to return the cached record. I have explained this in that reply as well.

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @mohdasad18

    Please keep in mind any support we provide is free of charge, so it might take some time before I respond, because I have to do it in any spare time I have.

    I have had a look at the data you send me and I think the main issue here is that your endpoint doesn’t provide the id of the landing-page post. So if you would add it ( 'id' => <post-id> ) I think everything will work fine. Without that ID our plugin has no way of knowing which caches to flush whenever you edit a landing-page post.

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @eddr

    I actually got a similar request recently. See my reply here, that is probably how I would do it in your case.

    Plugin Author Richard Korthuis

    (@rockfire)

    This thread has been marked as resolved due to lack of activity.

    You’re always welcome to open a new topic.

    Thanks for understanding!

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @mohdasad18

    Without having more information about your endpoints it is hard for me to tell you why the code isn’t doing what you expected. Could you perhaps send met the contents of one endpoint call? Perhaps if I see what your endpoint is returning I can determine how to solve it. You could email it to plugins at acato dot nl.

    About auto-generating the cache: we do have an option to automatically regenerate expired or flushed caches. You can enable it by going to “Settings” > “WP REST Cache” > Tab “Settings” and check the checkbox for “Enable cache regeneration”.

    Plugin Author Richard Korthuis

    (@rockfire)

    @geochanto Well as said, our regeneration script is also using the wp_remote_get function, so that should work. Did you check if it actually receives the expected endpoint-output? Maybe it is receiving an error or for some reason isn’t able to reach the server (i.e. itself)?

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @stevejonk

    Thank you for using our plugin!

    Yes you can make our plugin also cache requests with a nonce, using the wp_rest_cache/skip_nonce_caching filter like this:

    /**
    * Always allow caching of requests with a nonce.
    *
    * @param bool             $skip_nonce_caching False if cache should not be skipped when nonce is present.
    * @param \WP_REST_Request $request The current REST Request.
    * @param string           $request_uri The REST URI that is being requested.
    *
    * @return boolean
    */
    function wprc_skip_nonce_caching( $skip_nonce_caching, $request, $request_uri ) {
        $skip_nonce_caching = false;
    
        return $skip_nonce_caching;
    }
    
    add_filter( 'wp_rest_cache/skip_nonce_caching', 'wprc_skip_nonce_caching', 10, 3 );

    There are however some things you have to keep in mind when using this filter:

    • First of all because of the way our plugin works, this filter has to be in a must use plugin (in the mu-plugins directory) which is alphabetically before wp-rest-cache.php Otherwise it will not work.
    • Second: because if a endpoint is cached (and caching isn’t skipped for whatever reason) the cache is returned without any other code being executed. So if you still want to check if a user is logged in, you would have to do this check somewhere in the function that is called by the filter. So return false only if the user is logged in and return true if the user isn’t logged in so no cache is used (and the user will not see the results).
Viewing 15 replies - 46 through 60 (of 518 total)