0

We have a custom plugin we have created for a customer, it simply configures a custom post type.

They upgraded to wp 4.4 today. Now that custom post type is the only one that you cannot add a new post for.I can edit a custom post with out issue and I can add the standard posts and other custom post types created with a third party plugin.

I have uploaded the plugin to a clean install of 4.4 with a default theme and it still has the issue.

My custom post has the capabilities of 'post'. All I get once logged in is "Submit for Review". If you fill out the form and click the "submit for review" button then you get the message "You are not allowed to edit this post."

Here is the custom post declaration:

$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'query_var' => true,
    'menu_icon' => plugins_url( 'images/image.png', __FILE__ ),
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => null,
    'supports' => array('')
);

register_post_type( 'new_post_type' , $args );

I have double checked the DB has the right primary keys and auto increment too.

I have even tried creating new users and I have installed plugins to check the role capabilities which all look fine.

Any thoughts on how to diagnose?

Update I believe that the capabilities are correct. After changing core WordPress file to retrieve the post type via query string rather than the blank new post object it passes around the correct info appeared.

The problem seems to be when you click the add new button in the main navigation WordPress creates a blank post in the DB, this does not persist for some reason. As a result I get a post id of 0 returned rather than the next incremented id I should have.

This means that when it tries to pull out the meta info for id 0 it does not have the post type it is returned as '', therefore when it tries to get the capabilities for '' it fails and puts the form into the simplest view "submit for review".

  • I would recommend to look at 4.4 changelog and make sure that your code isn't using anything deprecated or is using anything that changed. register_post_type() didn't change in 4.4, Im afraid problem is somewhere else. – N00b Dec 17 '15 at 19:28
  • Thanks for the help, after a lot of playing around with the WP core files and debugging what is wrong I have found that $post->post_type returns nothing when creating a new post (wp-admin/includes/meta-boxes.php). If I hardcode in the correct post type all works fine. The hunt continues... – Tim Jarvis Dec 17 '15 at 22:51
  • Make sure to declare global $post; before your code. – N00b Dec 17 '15 at 22:59
  • I think I maybe getting closer to the issue but not the fix. When I go to create the new post the id is 0 where when I go to a different post to add it has a value of the next id. Still searching. – Tim Jarvis Dec 18 '15 at 10:01
  • Is post a custom cap? Try changing your cap to edit_posts and let's know if that works. – Abhik Dec 18 '15 at 12:53
0

Is the post content empty or null? I had similar problem with inserting a new post that mainly used custom fields and not using post content. I had excluded them from the array. This worked up to 4.3, but 4.4 gave a "Could not update post in the database" wp_error object. Adding contents cured the problem.

  • Thank you for your help but the problem appear to not be related to capabilities, if I change the core WordPress files so that it pulls out the right post type (which appears to be the problem) the new post page looks as it should with a publish button, but because of the issue clicking the button does not work as the checks are else where too, so I am confident that the capabilities are correct. – Tim Jarvis Dec 22 '15 at 9:06
0

The problem

There are two kinds of capabilities defiend in wordpress:

  • meta capabilities (edit_post, read_post, and delete_post)
  • primitive capabilities

for the meta capabilities to function correctly for your custom post type, you need to map them using map_meta_cap argument, while using register_post_type.

The solution

  1. In your register_post_type, the map_meta_cap has a null default value. set it to be true for the post capabilities desired functionality.
  2. Don't use the capabilities argument. If so, map_meta_cap would not function correctly.
  • Thank you for your comment. I originally used an inbuilt capability of 'post', to see if this was the issue I did try to use custom created capabilities where I used the map_meta_cap method as you suggested but it did not work. I believe the issue is due to persisting the new post to the DB before it returns to my custom form. still digging :) – Tim Jarvis Dec 22 '15 at 9:08
  • You did not follow the step I suggested in my answer. I didnt tell u to create custom capabilities. Please read more carefully – Pmpr Dec 22 '15 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.