Search code examples
wordpresscustom-post-typerevision

wordpress revisions are being saved, but are not accessible in revisions.php


When I click on browse next to revisions, which links to .../wp-admin/revision.php?revision=190, I get redirected to /wp-admin/edit.php

Some facts:

  • this problem only applies to custom post types, not posts or pages.
  • revisions were not supported when the post types were first registered, but they are now
  • the revisions are saved to the database, and I find no abnormality in the structure
  • both wp_get_post_revision and wp_get_post_revisions work as expected
  • the revisions meta box is empty regardless of how many revisions I make
  • WP_DEBUG is set to true, but I have seen no errors

I have googled a lot, but I only find answers for how to activate revisions, which is not the problem I'm having.

Has anyone experienced anything like this, and how should I troubleshoot this problem?

TL;DR: revisions are inaccessable through /wp-admin/revisions.php dispite showing up in wp_get_post_revisions

UPDATE:

I tried to add yet another custom post type, to see if the problem persisted with post types that have not been subjected to the various manipulations that the other ones has.

When adding a new custom post type, the other post types (not only customs) appear to be empty (the list shows no posts).

This also persists even if I remove all other hooks, filters, and other code in the functions.php file, until there is ONLY the registration of these custom post types.

TL;DR: Registering another custom post type causes all post lists to appear empty.

UPDATE 2:

The problem in the previous update occurs only if publicly_queryable is set to true when registering this new custom post type.

Changing publicly_queryable to true for custom post types that I have added previously does not result in this behaviour, only with this new custom post type (which I only added to troubleshoot).


Solution

  • These custom post types, the revisions of which I was unable to access, had been registered with custom capabilities.

    I also had installed the Members plugin (https://wordpress.org/plugins/members/) to manage these capabilities for custom user roles.

    --

    I ran the following test:

    // 188 is the ID of a post revision
    echo current_user_can( 'read_post', 188 ) ? '1' : '0'; 
    
    // 190 is the ID of a custom post revision
    echo current_user_can( 'read_kurs', 190 ) ? '1' : '0'; 
    

    This code returned '10', meaning posts can be edited, but not a custom post type.

    --

    In other words, it seems that I didn't have access to the post type, dispite being an administrator. I also tested with the ID of an actual post, not a revision, and it gave the same result.

    I am however able to read all the posts, this is only affecting the revisions for some reason.

    Granting myself the ability to 'read_kurs' (in the Members plugin) fixed this problem.

    The reason I did not have this capability to begin with was that I this capability did not appear in Edit capabilites, so dispite having checked everything I still did not have access to read.

    I had to add 'read_kurs' under Custom Capability, and then check it under 'All' (since it did not appear under the capabilities of the custom post type).