1

WooCommerce customers are creating custom posts using Gravity Forms and then the customer is assigned as the author of the post. The custom post type is set up using the CPT UI plugin. I have this bit of code on a custom-templated page that allows them to delete the custom post. This page uses the custom post id to pull in an image and the post title but has other content of it's own.

<?php if ( current_user_can( 'delete_post', $custom_post_id ) ) : ?>
<li class="deleteprofile"><a onclick="return confirm('Do you really want to delete this post?')" href="<?php echo get_delete_post_link($custom_post_id); ?>">Delete Post</a></li>
<?php endif; ?>

As an administrator user I can view and click the delete button just fine and the custom post gets deleted on the backend. Upon deletion I have a bit of code that will redirect them to a custom page - but the downside is that it also redirects when administrators delete from the backend as well:

function x_child_deleted_post_handler($post_id) {
    $post_type = get_post_type($post_id);
    if ( $post_type == "my_custom_type") {
        wp_redirect( get_permalink( 9295 ) );
        exit();
    }
}
add_action('trashed_post','x_child_deleted_post_handler',10,1);

When I'm the customer user I can see the delete button, but nothing happens when I try to delete the post. The confirmation dialog works fine but when I click yes to confirm it stays on the page and the custom post remains published.

I have the Capability Manager Enhanced plugin installed so that I can have the customer roles delete posts and delete published posts.

What else am I missing for the customer role to be able to delete their custom posts?

Update:

Capability Manager Enhanced Version 1.7 added a new option "Type-Specific Capabilities" which will "Ensure permissions can be controlled separately from other post types."

I've selected my custom post type under this new option and now I can see my custom post type under Editing and Deletion Capabilities. After playing around with these settings I can get the delete to work if under Editing Capabilities I've selected Posts and my custom post type. Selecting Edit will then show the WordPress admin bar up top - this seems required to be able to delete the custom post type on the front-end. However I don't necessarily want Customers to be on the WordPress back-end, so I've removed the bar with:

if (!current_user_can('manage_options')) {
    add_filter('show_admin_bar', '__return_false');
}

This will remove the WordPress admin bar for all non-admin users. However savvy customers will still be able to access the WordPress back-end dashboard by directly accessing /wp-admin.

Your Answer

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

Browse other questions tagged or ask your own question.