abstract-post-modifier.php
3 years ago
base-post-action.php
3 years ago
insert-action.php
3 years ago
post-author-property.php
3 years ago
post-comments-property.php
3 years ago
post-content-property.php
3 years ago
post-date-gmt-property.php
3 years ago
post-date-property.php
3 years ago
post-excerpt-property.php
3 years ago
post-id-property.php
3 years ago
post-meta-property.php
3 years ago
post-modifier.php
3 years ago
post-parent-property.php
3 years ago
post-status-property.php
3 years ago
post-terms-property.php
3 years ago
post-thumbnail-property.php
3 years ago
post-title-property.php
3 years ago
post-type-property.php
3 years ago
trash-action.php
3 years ago
update-action.php
3 years ago
post-title-property.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Actions\Methods\Post_Modification; |
| 5 | |
| 6 | |
| 7 | use Jet_Form_Builder\Actions\Methods\Abstract_Modifier; |
| 8 | use Jet_Form_Builder\Actions\Methods\Base_Object_Property; |
| 9 | |
| 10 | class Post_Title_Property extends Base_Object_Property { |
| 11 | |
| 12 | protected $is_empty = false; |
| 13 | |
| 14 | public function get_id(): string { |
| 15 | return 'post_title'; |
| 16 | } |
| 17 | |
| 18 | public function get_label(): string { |
| 19 | return __( 'Post Title', 'jet-form-builder' ); |
| 20 | } |
| 21 | |
| 22 | public function get_value( Abstract_Modifier $modifier ) { |
| 23 | $action = $modifier->get_action(); |
| 24 | |
| 25 | if ( ! is_a( $action, Insert_Action::class ) || |
| 26 | $this->value |
| 27 | ) { |
| 28 | return parent::get_value( $modifier ); |
| 29 | } |
| 30 | |
| 31 | $this->value = '(empty)'; |
| 32 | $this->is_empty = true; |
| 33 | |
| 34 | return parent::get_value( $modifier ); |
| 35 | } |
| 36 | |
| 37 | public function do_after( Abstract_Modifier $modifier ) { |
| 38 | if ( ! $this->is_empty ) { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | /** @var Base_Post_Action $action */ |
| 43 | $action = $modifier->get_action(); |
| 44 | $id = $action->get_inserted(); |
| 45 | |
| 46 | $post_type_obj = get_post_type_object( $modifier->source_arr['post_type'] ); |
| 47 | $title = "{$post_type_obj->labels->singular_name} #{$id}"; |
| 48 | $name = "{$post_type_obj->labels->singular_name}-{$id}"; |
| 49 | |
| 50 | wp_update_post( |
| 51 | array( |
| 52 | 'ID' => $id, |
| 53 | 'post_title' => $title, |
| 54 | 'post_name' => $name, |
| 55 | ) |
| 56 | ); |
| 57 | } |
| 58 | } |