• Resolved jmires

    (@jmires)


    Hi,

    I have a perplexing issue with not being able to add a new post for a custom post type. I am getting the “Submit for Review” button instead of “Publish” when trying to add a new post.

    After researching, I know this can be caused by a number of issues: problems with the database, auto_increment not set or working correctly on tables, improper database user privileges, etc. – I have looked into all of these and can’t find anything wrong.

    This problem did only appear after exporting and importing the database to a new domain, so it does seem likely it’s an issue with the database. However, the only post type affected by this is the one created by this plugin. All other post types (pages, posts, attachments, custom posts created by other plugins, etc) don’t have this problem.

    So far I have:
    — tried switching themes
    — tried disabling plugins
    — verified correct database user permissions
    — checked all tables using CHECK TABLE and mysqlcheck (none needed to be repaired)
    — verified auto_increment is set for all primary_keys, and auto_increment values are reasonable
    — tried changing wordpress user permission from admin to contributor, then back to admin

    By using chrome dev tools, I have discovered that the post_ID is 0 when adding a new post with this post_type instead of the proper auto_increment value, so it does seem there is some kind of issue there: https://dl.dropboxusercontent.com/s/g5v65sfekegzcvk/2016-01-06%20at%2011.49%20AM.png

    What I can’t figure out is why it only affects this one post_type.

    Any direction on how to address this would be super appreciated – I’m a bit at my wits end.

    Thanks!

    https://wordpress.org/plugins/custom-post-type-ui/

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Can't add new post for registered custom post type’ is closed to new replies.