• Resolved drathy

    (@drathy)


    Hi guys,

    first of all, thanks for developing ths great plugin!

    I’m trying to flush the cache of a custom endpoint automatically.

    As I read here this only works if the “Object Type” is set in the list of the “Endpoint API Caches” in WordPress Backend.

    My problem is that I’m not able to set the Object Type, it is always “unknown”, even if I try it with this code:

    function wprc_determine_object_type( $object_type, $cache_key, $data, $uri ){
        if($object_type !== 'unknown' || strpos( $uri, 'appdata/v1/articles' ) === false){
            return $object_type;
        }
        return 'post';
    }

    The result in the “Endpoint API Cache” list are the following:
    b8966941f22f6ad94908f5ec71b72674 /wp-json/wp/v2/posts [] GET post Flushed
    27704311643cf55f8775637e561ea846 /wp-json/appdata/v1/articles [] GET unknown 2021-05-19 11:56:41

    As you see the Object Type is “unknown” and I also wonder about the other “v2/posts” entry…

    I tried and read really a lot, but I wasn’t able to solve the problem.

    I hope you could help!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Richard Korthuis

    (@rockfire)

    Hi @drathy

    Thank you for using our plugin!

    Since it is missing in your code snippet, did you also add the correct filter?
    add_filter( 'wp_rest_cache/determine_object_type', 'wprc_determine_object_type', 10, 4 );

    Thread Starter drathy

    (@drathy)

    Hi Richard,

    thank you for your quick reply. Yes, sorry, here is my complete code:

    function wprc_determine_object_type( $object_type, $cache_key, $data, $uri ){
        if($object_type !== 'unknown' || strpos( $uri, 'appdata/v1/articles' ) === false){
            return $object_type;
        }
    
        return 'post';
    }
    add_filter( 'wp_rest_cache/determine_object_type', 'wprc_determine_object_type', 10, 4 );
    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @drathy

    Where did you put your code? Are you sure it is being executed?

    And did you flush your caches after adding this code?

    Thread Starter drathy

    (@drathy)

    Hi Richard,

    I wrote it in an PHP file which is included in funcions.php. Yes, it is executed, I set some var_dump() to get the output… It’s really strange… ??

    Caching plugin currently deactivated.

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @drathy

    But did you flush your caches after adding this code? The object type will only be set the first time, so not after a new cache hit. So you have to flush it for the code to have any effect

    Thread Starter drathy

    (@drathy)

    Hi Richard,

    oh, sorry, of course you meant the “WP REST Cache”-Cache….but yes, I flushed it…and I just flushed it again to be absolutely sure…but Object Type is still “unknown”…

    Thread Starter drathy

    (@drathy)

    Hi Richard,

    do you have more ideas what the problem might be?

    Best regards,
    Christian

    Thread Starter drathy

    (@drathy)

    Hi again Richard,

    I just saw by chance, that object types are now correct!!! :-O I didn’t change anything besides moving the installation to the final domain and remove the .htaccess directory protection…

    Do you know any problems by using such a protection?

    Best regards,
    Christian

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @drathy

    Sorry for the late reply.

    No I don’t have any clue as to why it wasn’t working and why it is working on the final domain. The .htaccess directory protection shouldn’t be any problem, if you can request the endpoint, the endpoint can be cached.

    But great to hear it is working for you now!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Problem with “Object Type” unknown’ is closed to new replies.