Skip to content

badasswp/trash-post-in-block-editor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

trash-post-in-block-editor

Delete a Post from within the WP Block Editor.

trash-post-in-block-editor

Download

Download from WordPress plugin repository.

You can also get the latest version from any of our release tags.

Why Trash Post in Block Editor?

This plugin provides a quick way to delete or trash a Post from within the Block Editor. Previously, the only way to achieve this required a user to exit the article or post before deleting. Not anymore! Now, from the comfort of your Block Editor, you could easily delete the Post you're working on with ease.

clip.mov

Hooks

tpbe_redirect_url

This custom hook provides a simple way to filter the redirect URL the user is taken to after the post is trashed or deleted.

add_filter( 'tpbe_redirect_url', [ $this, 'custom_redirect_url' ] );

public function custom_redirect_url( $url ): string {
    $site_url = 'https://example.com/redirect';

    if ( false === strpos( $url, $site_url ) ) {
        return esc_url( $site_url );
    }

    return $url;
}

Parameters

  • url {string} By default, this will be a the redirect URL the user is taken to after a post is trashed.

tpbe.afterTrashPost

This custom hook (action) provides the ability to fire events after the post is trashed on the JS side:

import { addAction } from '@wordpress/hooks';

addAction(
	'tpbe.afterTrashPost',
	'your-namespace',
	( postId, redirectUrl ) => {
		wp.data.dispatch( YOUR_STORE ).performSomeAction( postId );
	}
);

Parameters

  • postId {number} The trashed Post ID.
  • redirectUrl {string} The Redirect URL where the user is taken after the post is trashed.


Contribute

Contributions are welcome and will be fully credited. To contribute, please fork this repo and raise a PR (Pull Request) against the master branch.

Pre-requisites

You should have the following tools before proceeding to the next steps:

  • Composer
  • Yarn
  • Docker

To enable you start development, please run:

yarn start

This should spin up a local WP env instance for you to work with at:

http://tpbe.localhost:5437

You should now have a functioning local WP env to work with. To login to the wp-admin backend, please username as admin & password as password.

Awesome! - Thanks for being interested in contributing your time and code to this project!