WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Post Type; Admin Can't Publish or Delete (3 posts)

  1. deanpence
    Member
    Posted 2 years ago #

    I'm having the strangest time getting capabilities to work correctly with a custom post type. I just want my custom post type to use the same capabilities as standard posts do. (It was working completely fine for a while, and then something changed—I'm not sure what yet—and I got frustrated and started with a completely fresh WordPress install, which didn't fix anything. :))

    Here's how I'm registering the post type: http://pastie.org/3721112 (See the end of this post for an explanation of my visibility settings.)

    I'm always logged in as an admin user.

    When I create one of these post types and click "Publish", it saves as a draft. When I try to manually change the post status, I don't have the option to publish: http://cl.ly/2Z3f1D1I1X1Z2M3n1016

    Also, when I click "Move to Trash" from the post list, I get the "Moved to trash" message, but it's still in the list: http://cl.ly/3q0y3S3D0L0Y411Z3I0h

    In fact, when I click "Move to Trash", my save_post action hook runs. That makes no sense.

    Any ideas? I don't need custom capabilities. I just want to use the existing post capabilities.

    --

    Possible caveats:

    I need only a few out-of-the-ordinary things. Posts of this type:

    • Don't show up in nav menus.
    • Don't have archives.
    • Don't show up in search.

    Basically, the only way to get to one is if there's a link directly to one of them.

  2. deanpence
    Member
    Posted 2 years ago #

    This was not a problem with capabilities at all. It was a problem with nonces.

    Since everyone else with this problem never left any details, all I did was:

    1. Stop using check_admin_referer [docs] and replace it with a simple nonce check with wp_verify_nonce[docs].
    2. Make sure that wp_nonce_field [docs] and wp_verify_nonce were using the correct arguments in the correct order.

    (If you use the code below, use your own nonce name and action strings.)

    In the metabox:

    wp_nonce_field('nonce_action', 'nonce_name');

    In the 'save_post' hook:

    if (!wp_verify_nonce($_POST['nonce_name'], 'nonce_action')) {
        return;
    }
  3. cataua
    Member
    Posted 1 year ago #

    I have this same problem, but in my case I create 3 CPTs and all just show to publish as draft, but just only save like draft, the others two publish normal.

Topic Closed

This topic has been closed to new replies.

About this Topic