What is set for the capabilities field for this post type?
I did a quick test, and it seems that if a user is of a “contributor” role, you get the “Submit for Review” button text, since they can’t publish. However, it’s possible that a custom capabilities field may change some things here, at least for this post type. Note that “post” is the default value with CPTUI.
So that’s what I’d check first. The user role of the user you’re trying with in the new site, and what capabilities are associated here, if anything custom.
Thread Starter
jmires
(@jmires)
Thanks for the quick reply. I am trying to add posts as admin. I don’t think it’s an issue with roles or capabilities, as:
1) I’m trying to add posts with a user with admin priveleges
2) I can edit posts, just not add new ones for this post_type
3) In CPTUI, the capability is “post”
It definitely seems to be something with retrieving the correct post_ID for the next post when adding a new one for this type. It should have the value for the next auto_increment value for wp_posts, but it’s returning 0 every time, which I think is the cause of the “Submit for Review” issue.
I just don’t see anything wrong with the database that would cause this. Any other ideas?
Thread Starter
jmires
(@jmires)
Ugh, turns out it was a plugin conflict after all – I wasn’t as careful as I thought in checking every plugin initially. Resolved now, not a CPTUI issue. Very sorry to have bothered you with this.
For sake of anyone coming in with the same issue, what plugin was causing the conflict?
No bother, it was an odd issue to come up. Happy things are resolved.
Thread Starter
jmires
(@jmires)
It was Page Comments Off Please (https://wordpress.org/plugins/page-comments-off-please/) which was actually duplicating functionality that was available in the theme options for the theme the organization is using. Deactivating Page Comments Off Please restored correct functionality for adding new posts.
Thanks.
Have a good rest of the day.
@jmires, do you have any more details about the conflict involved? I’ve found the same issue with a plugin I’m not able to do without.
Thread Starter
jmires
(@jmires)
I didn’t look into the details of it since the plugin causing the issue was one no longer needed.
If debugging the conflict with your necessary plugin is challenging, you might try installing Page Comments Off Please on a dev copy of your site and seeing if it causes the same issue for you. If so, that might be easier to debug since Page Comments Off Please is a pretty small amount of code.
Thanks, nice idea but no luck 🙁 I might have a quick look at the code anyway, got nothing else to go on…
Thread Starter
jmires
(@jmires)
Good luck – if you discover anything please report back for others’ benefit.
Solved it. Turns out the fault wasn’t in the plugin, it was some code in my custom theme which only ran when that plugin’s active (because a bit of the code depends on that plugin).
Anyway, here’s the code. It’s part of a hack I did to allow articles to be credited to multiple authors, so I replaced the standard author meta box with a custom field, and this passes the first of the multiple authors through to the standard author field. It’s intended for when the post is saved, but auto-drafts where obviously causing a problem.
add_filter( 'wp_insert_post_data', 'aotc_post_data_filter', 10, 2 );
function aotc_post_data_filter( $data, $postarr ) {
// Post author for articles
if ( $data['post_type'] == 'article' && PILAU_PLUGIN_EXISTS_DEVELOPERS_CUSTOM_FIELDS ) {
// First of the multiple authors
$data['post_author'] = $postarr[ slt_cf_field_key( 'article_author' ) ][0];
}
return $data;
}
The solution was to add, in the if condition, a test for the existence of $postarr[ slt_cf_field_key( 'article_author' ) ]
. I guess when an auto-draft was being saved for a new article, there’s no custom fields in the $postarr
, and post_author
gets set to null or something, screwing up capabilities checks.
This code was working fine until very recently – either 4.4. or 4.4.1. I imagine it’s the case that WP core has tightened up some sloppy coding that allowed my sloppy coding to work.
Anyway, this was triggering the ‘Submit for review’ instead of ‘Publish’ button, based on the same zero post ID issue as above. Hopefully this solution adds to the pile of remedies for this symptom!
Thread Starter
jmires
(@jmires)
Thanks very much for the sleuthing and reporting back! I now suspect that my issue may have been similar (auto drafts and issues with post_author field for this post_type) rather than really caused by the Page Comments Off Please plugin.