abstract-post-modifier.php
7 months ago
base-post-action.php
1 year ago
insert-action.php
1 year ago
post-author-property.php
1 year ago
post-comments-property.php
1 year ago
post-content-property.php
1 year ago
post-date-gmt-property.php
1 year ago
post-date-property.php
1 year ago
post-excerpt-property.php
1 year ago
post-id-property.php
1 year ago
post-meta-property.php
7 months ago
post-modifier.php
7 months ago
post-parent-property.php
1 year ago
post-status-property.php
1 year ago
post-terms-property.php
1 year ago
post-thumbnail-property.php
8 months ago
post-title-property.php
1 year ago
post-type-property.php
1 year ago
trash-action.php
1 year ago
update-action.php
1 year ago
base-post-action.php
110 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\Actions_V2\Insert_Post\Properties; |
| 5 | |
| 6 | use Jet_Form_Builder\Actions\Methods\Base_Modifier_Action; |
| 7 | use JFB_Modules\Actions_V2\Insert_Post\Insert_Post_Action; |
| 8 | |
| 9 | // If this file is called directly, abort. |
| 10 | if ( ! defined( 'WPINC' ) ) { |
| 11 | die; |
| 12 | } |
| 13 | |
| 14 | abstract class Base_Post_Action extends Base_Modifier_Action { |
| 15 | |
| 16 | protected $inserted_id = 0; |
| 17 | |
| 18 | /** |
| 19 | * Inserted ID getter. |
| 20 | * |
| 21 | * @return integer |
| 22 | */ |
| 23 | public function get_inserted_id(): int { |
| 24 | return $this->inserted_id; |
| 25 | } |
| 26 | |
| 27 | public function do_after() { |
| 28 | if ( ! $this->inserted_id ) { |
| 29 | return; |
| 30 | } |
| 31 | $this->add_inserted_post_id(); |
| 32 | $this->add_context_once(); |
| 33 | |
| 34 | /** |
| 35 | * Perform any actions after post inserted/updated |
| 36 | */ |
| 37 | do_action( |
| 38 | 'jet-form-builder/action/after-post-' . $this->get_id(), |
| 39 | jet_fb_action_handler()->get_current_action(), |
| 40 | jet_fb_action_handler(), |
| 41 | $this |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | public function pre_check(): bool { |
| 46 | return apply_filters( |
| 47 | 'jet-form-builder/action/insert-post/pre-check', |
| 48 | true, |
| 49 | $this->modifier->source_arr, |
| 50 | jet_fb_action_handler()->get_current_action() |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | public function add_inserted_post_id() { |
| 55 | $handler = jet_fb_action_handler(); |
| 56 | |
| 57 | if ( ! $handler->in_loop() ) { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | if ( empty( $handler->response_data['inserted_post_id'] ) ) { |
| 62 | $handler->response_data['inserted_post_id'] = $this->inserted_id; |
| 63 | jet_fb_context()->update_request( $this->inserted_id, 'inserted_post_id' ); |
| 64 | } else { |
| 65 | $handler->response_data['inserted_posts'][] = array( |
| 66 | 'post_id' => $this->inserted_id, |
| 67 | 'action_id' => $handler->get_current_action()->_id, |
| 68 | ); |
| 69 | } |
| 70 | |
| 71 | $post_type = $this->modifier->source_arr['post_type'] ?? ''; |
| 72 | |
| 73 | if ( ! $post_type ) { |
| 74 | $post_type = get_post_type( $this->inserted_id ); |
| 75 | } |
| 76 | |
| 77 | $inserted_key = jet_fb_context()->get_unique_name( |
| 78 | 'inserted_' . $post_type |
| 79 | ); |
| 80 | |
| 81 | jet_fb_context()->update_request( $this->inserted_id, $inserted_key ); |
| 82 | } |
| 83 | |
| 84 | public function add_context_once() { |
| 85 | if ( ! jet_fb_action_handler()->in_loop() ) { |
| 86 | return; |
| 87 | } |
| 88 | /** |
| 89 | * For Redirect to Page action |
| 90 | */ |
| 91 | jet_fb_action_handler()->add_context_once( |
| 92 | 'insert_post', |
| 93 | array( |
| 94 | Insert_Post_Action::get_context_post_key( $this->inserted_id ) => array_merge( |
| 95 | array( |
| 96 | '__action' => $this->get_id(), |
| 97 | 'ID' => $this->inserted_id, |
| 98 | ), |
| 99 | $this->modifier->source_arr |
| 100 | ), |
| 101 | ) |
| 102 | ); |
| 103 | } |
| 104 | |
| 105 | public function get_inserted(): int { |
| 106 | return $this->inserted_id; |
| 107 | } |
| 108 | |
| 109 | } |
| 110 |