Support » Developing with WordPress » 403 Error on saving custom post type

  • Resolved katmacau

    (@katmacau)


    hello. I have custom post types in my site. They were working fine for a long time but have suddenly started getting a 403 Access denied error when I try to save them. I can still save posts, pages. I can still view the CPT in admin view but when I press save, it gives me the 403 error.
    If I try make a new post, it will save a draft but not create new.
    I have tried disabling plugins and resetting htaccess.
    There must be something in my CPT save function that is triggering the block. But I can’t see what.

    
    add_action('save_post', 'my_profiles_save_meta_data', 10, 2);
    function my_profiles_save_meta_data($post_id, $post){
    	
    	/* Verify the nonce before proceeding. */
    	if ( !isset( $_POST['my_profiles_summary_nonce'] ) || !wp_verify_nonce( $_POST['my_profiles_summary_nonce'], 'my_profiles_the_action_name' ) )
    		return $post_id;
    		
    	/* Get the post type object. */
    	$post_type = get_post_type_object( $post->post_type );
     
    	/* Check if the current user has permission to edit the post. */
    	if ( !current_user_can( $post_type->cap->edit_post, $post_id ) )
    		return $post_id;
     }

    Is there anything that’s changed in the latest wordpress that would block this?

    • This topic was modified 5 months ago by katmacau.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Your code doesn’t really do anything by returning $post_id. “save_post” is an action. Anything returned by the callback is ignored. You return data with filters, not actions.

    In any case, your code wouldn’t cause a 403 error. I suspect your host has altered their mod_sec (server security module) configuration. They may need to whitelist POST requests involving your CPT’s slug.

    Thanks. I will see what the hosts say about this.

    Thank you. The hosts changed security settings and this fixed it!

    Moderator bcworkz

    (@bcworkz)

    Awesome! You’re welcome.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.