abstract-post-modifier.php
2 years ago
base-post-action.php
2 years ago
insert-action.php
2 years ago
post-author-property.php
2 years ago
post-comments-property.php
2 years ago
post-content-property.php
2 years ago
post-date-gmt-property.php
2 years ago
post-date-property.php
2 years ago
post-excerpt-property.php
2 years ago
post-id-property.php
2 years ago
post-meta-property.php
2 years ago
post-modifier.php
2 years ago
post-parent-property.php
2 years ago
post-status-property.php
2 years ago
post-terms-property.php
2 years ago
post-thumbnail-property.php
2 years ago
post-title-property.php
2 years ago
post-type-property.php
2 years ago
trash-action.php
2 years ago
update-action.php
2 years ago
trash-action.php
47 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Actions\Methods\Post_Modification; |
| 5 | |
| 6 | use Jet_Form_Builder\Actions\Methods\Abstract_Modifier; |
| 7 | use Jet_Form_Builder\Exceptions\Action_Exception; |
| 8 | use Jet_Form_Builder\Exceptions\Handler_Exception; |
| 9 | |
| 10 | // If this file is called directly, abort. |
| 11 | if ( ! defined( 'WPINC' ) ) { |
| 12 | die; |
| 13 | } |
| 14 | |
| 15 | class Trash_Action extends Base_Post_Action { |
| 16 | |
| 17 | public function get_id(): string { |
| 18 | return 'trash'; |
| 19 | } |
| 20 | |
| 21 | public static function is_supported( Abstract_Modifier $modifier ): bool { |
| 22 | return ( |
| 23 | Update_Action::is_supported( $modifier ) && |
| 24 | 'trash' === ( $modifier->source_arr['post_status'] ?? '' ) |
| 25 | ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @throws Action_Exception |
| 30 | */ |
| 31 | public function do_action() { |
| 32 | if ( ! $this->pre_check() ) { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | $post = wp_trash_post( |
| 37 | $this->modifier->source_arr['ID'] ?? 0 |
| 38 | ); |
| 39 | |
| 40 | if ( ! is_a( $post, \WP_Post::class ) ) { |
| 41 | throw new Action_Exception( 'failed' ); |
| 42 | } |
| 43 | |
| 44 | $this->inserted_id = $post->ID; |
| 45 | } |
| 46 | } |
| 47 |