This topic contains 4 reply and 2 voices, and was last updated by ggsalas 5 years, 11 months ago
Viewing 4 Posts - 1 through 4 (of 4 total)
Author Posts
October 12, 2013 at 7:37 am 8947
ggsalas Hi I would like to create a link inside the "edit post page" to delete the post and redirect to a page after deletion. The code I use is this and it works:
add_action( 'wpuf_edit_post_form_bottom', 'wpufe_edit_delete', 10, 2 );
function wpufe_edit_delete( $form_id, $post_id ) {
	if( !(get_post_status() == 'trash') ) :
		$delLink = get_delete_post_link( $post_id, true );
		$link = 'Borrar este artículo';
		$message = 'Estás SEGURO de querer borrar' .get_the_title($post_id). '?';
		echo "<a href='" . $delLink . "' onclick = \"if ( confirm('".$message."' ) ) { execute(); return true; } return false;\"/>".$link."</a>";
	endif; 
}
The code I use to try to "redirect to a webpage" is this:
add_action('deleted_post','redireccion_borrar',10,1);
function redireccion_borrar($post_id) {
   if (!is_admin()) {
    $url_redireccion = 'http://www.redminka.com/usuarios/juan_minka/publicaciones/todas';
    return wp_redirect($url_redireccion);
    exit;
   }
}
The "redirect to a webpage" code not work. Can I use another action instead of "deleted_post"? Thanks and best regards.
October 16, 2013 at 5:47 pm 9071
ggsalas ggsalas

Hi, the codes that I show are working in a wordpress post but not work in the edit post page. In this page I need to use a WPUF hook to delete the post ID (without this I have deleted the “edit post page”).

Somebody has been able to add a delete button in the edit post page?

Best regards

October 19, 2013 at 9:04 pm 9203
ggsalas ggsalas

I have thinking on an alternative, to add a message after trash the post:

add_action('wpuf_edit_post_form_top', 'trash_message');
function trash_message($form_id, $post_id){
	if( get_post_status($post_id) == 'trash' ) {
	echo '<div class="alert"> Esta publicación ha sido eliminada</div>';	
	}
}

The filter to know the post status not work, and I don’t know why. If i delete the filter the message shows well:

add_action('wpuf_edit_post_form_top', 'trash_message');
function trash_message($form_id, $post_id){
	echo '<div class="alert"> Esta publicación ha sido eliminada</div>';	
}
October 19, 2013 at 9:38 pm 9207
Tareq Hasan Tareq Hasan

Take a look at the dashboard page’s delete post link and put that same link to your edit page. That way, the user will be redirected to the dashboard page when he clicks the delete link in edit page.

Showing a deleted message is not logical in the edit post page as the post is moved to trash and you can’t edit the post anymore.

October 20, 2013 at 2:50 am 9217
ggsalas ggsalas

Hi Tareq,

I have add this in my functions.php but the button not appears:

add_filter( 'wpuf_edit_post_form_bottom', 'wpufe_edit_delete',10,2 );

function wpufe_edit_delete($form_id, $post_id ) {
$del_url = add_query_arg( array('action' => 'del', 'pid' => $post->ID) );
$del_href = wp_nonce_url( $del_url, 'wpuf_del' );
echo 	'<a href="'.$del_href.'>borralo</a>';
}

  /**
     * Delete a post
     *
     * Only post author and editors has the capability to delete a post
     */
    function delete_post() {
        global $userdata;

        $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>';
        }
    }

Another problem is that my dashboard page not work: http://redminka.com/dashboard/ I not use it, but I think is maybe the problem

Thanks

Viewing 4 Posts - 1 through 4 (of 4 total)