| 1 |
<?php |
| 2 |
/** |
| 3 |
* Delete Post |
| 4 |
* |
| 5 |
* @package AutomatorWP\Integrations\WordPress\Actions\Delete_Post_Action |
| 6 |
* @author AutomatorWP <contact@automatorwp.com>, Ruben Garcia <rubengcdev@gmail.com> |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
class AutomatorWP_WordPress_Delete_Post_Action extends AutomatorWP_Integration_Action { |
| 13 |
|
| 14 |
/** |
| 15 |
* Initialize the trigger |
| 16 |
* |
| 17 |
* @since 1.0.0 |
| 18 |
*/ |
| 19 |
public function __construct( $integration ) { |
| 20 |
|
| 21 |
$this->integration = $integration; |
| 22 |
$this->action = $integration . '_delete_post_action'; |
| 23 |
|
| 24 |
parent::__construct(); |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Register the trigger |
| 30 |
* |
| 31 |
* @since 1.0.0 |
| 32 |
*/ |
| 33 |
public function register() { |
| 34 |
|
| 35 |
automatorwp_register_action( $this->action, array( |
| 36 |
'integration' => $this->integration, |
| 37 |
'label' => __( 'Delete a post', 'automatorwp' ), |
| 38 |
'select_option' => __( 'Delete <strong>a post</strong>', 'automatorwp' ), |
| 39 |
/* translators: %1$s: Post. */ |
| 40 |
'edit_label' => sprintf( __( 'Delete %1$s', 'automatorwp' ), '{post}' ), |
| 41 |
/* translators: %1$s: Post. */ |
| 42 |
'log_label' => sprintf( __( 'Delete %1$s', 'automatorwp' ), '{post}' ), |
| 43 |
'options' => array( |
| 44 |
'post' => automatorwp_utilities_post_option( array( |
| 45 |
'post_type' => 'any', |
| 46 |
'option_none_label' => __( 'any post', 'automatorwp' ), |
| 47 |
'option_custom' => true, |
| 48 |
'option_custom_desc' => __( 'Post ID', 'automatorwp' ), |
| 49 |
) ) |
| 50 |
), |
| 51 |
) ); |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Action execution function |
| 57 |
* |
| 58 |
* @since 1.0.0 |
| 59 |
* |
| 60 |
* @param stdClass $action The action object |
| 61 |
* @param int $user_id The user ID |
| 62 |
* @param array $action_options The action's stored options (with tags already passed) |
| 63 |
* @param stdClass $automation The action's automation object |
| 64 |
*/ |
| 65 |
public function execute( $action, $user_id, $action_options, $automation ) { |
| 66 |
|
| 67 |
$post_id = absint( $action_options['post'] ); |
| 68 |
|
| 69 |
// Bail if not post ID provided |
| 70 |
if( $post_id === 0 ) { |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
wp_delete_post( $post_id, true ); |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
new AutomatorWP_WordPress_Delete_Post_Action( 'wordpress' ); |
| 81 |
new AutomatorWP_WordPress_Delete_Post_Action( 'posts' ); |