WordPress.org

Forums

WP User Frontend
[resolved] Cannot delete posts from frontend. (3 posts)

  1. Swennet
    Member
    Posted 2 years ago #

    Hello, I have been editing my wpuf files for some time today to make them suit my needs. However, upon testing the functionality of the Dashboard I've stumbled upon an error.

    While deleting the post it sends the following error message to the page:

    You are not the post author. Cheeting huh!

    I looked into wpuf-dashboard.php file for the post-deletion code and found this.

    /**
         * Delete a post
         *
         * Only post author and editors has the capability to delete a post
         */
        function delete_post() {
            $nonce = $_REQUEST['_wpnonce'];
            if ( !wp_verify_nonce( $nonce, 'wpuf_del' ) ) {
                die( "Security check" );
            }
    
            //check, if the requested user is the post author
            $maybe_delete = get_post( $_REQUEST['pid'] );
    
            if ( ($maybe_delete->post_author == $userdata->ID) || current_user_can( 'delete_others_pages' ) ) {
                wp_delete_post( $_REQUEST['pid'] );
    
                //redirect
                $redirect = add_query_arg( array('msg' => 'deleted'), get_permalink() );
                wp_redirect( $redirect );
            } else {
                echo '<div class="error">' . __( 'You are not the post author. Cheeting huh!', 'wpuf' ) . '</div>';
            }
        }

    I'm not sure why it is not working, I tried printing the $maybe_delete variable in the browser which gave me another error:

    Catchable fatal error: Object of class WP_Post could not be converted to string in /wp-content/plugins/wp-user-frontend/wpuf-dashboard.php on line 212

    Is the code broken? Did I break it?

    http://wordpress.org/extend/plugins/wp-user-frontend/

  2. Tareq Hasan
    Member
    Plugin Author

    Posted 2 years ago #

    There might a missing global $userdata in the function, try to add this one the beginging of the function.

    About the fatal error, you are trying to echo an Object, you can't do that.

    [Advertisement moderated]

  3. Swennet
    Member
    Posted 2 years ago #

    Thanks! This fixed the issue. Might want to check your plugin for this same error since I don't remember removing the global $userdata function.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP User Frontend
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic