PluginProbe
OttoKit: All-in-One Automation Platform / 1.0.83
OttoKit: All-in-One Automation Platform v1.0.83
1.1.38 1.1.37 1.1.36 1.1.35 1.1.34 1.1.33 1.1.32 1.1.31 1.1.30 1.1.29 1.1.28 1.1.27 1.1.9 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 All 124 releases
suretriggers / src / Integrations / projecthuddle / actions / create-mockup.php
create-mockup.php
108 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CreateMockup.
4 * php version 5.6
5 *
6 * @category CreateMockup
7 * @package SureTriggers
8 * @author BSF <username@example.com>
9 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
10 * @link https://www.brainstormforce.com/
11 * @since 1.0.0
12 */
13
14 namespace SureTriggers\Integrations\ProjectHuddle\Actions;
15
16 use SureTriggers\Integrations\AutomateAction;
17 use SureTriggers\Traits\SingletonLoader;
18 use SureTriggers\Integrations\WordPress\WordPress;
19 use Exception;
20
21 /**
22 * CreateMockup
23 *
24 * @category CreateMockup
25 * @package SureTriggers
26 * @author BSF <username@example.com>
27 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
28 * @link https://www.brainstormforce.com/
29 * @since 1.0.0
30 */
31 class CreateMockup extends AutomateAction {
32
33 /**
34 * Integration type.
35 *
36 * @var string
37 */
38 public $integration = 'ProjectHuddle';
39
40 /**
41 * Action name.
42 *
43 * @var string
44 */
45 public $action = 'ph_create_mockup';
46
47 use SingletonLoader;
48
49 /**
50 * Register a action.
51 *
52 * @param array $actions actions.
53 * @return array
54 */
55 public function register( $actions ) {
56 $actions[ $this->integration ][ $this->action ] = [
57 'label' => __( 'Post: Create a Post', 'suretriggers' ),
58 'action' => 'ph_create_mockup',
59 'function' => [ $this, 'action_listener' ],
60 ];
61
62 return $actions;
63 }
64
65 /**
66 * Action listener.
67 *
68 * @param int $user_id user_id.
69 * @param int $automation_id automation_id.
70 * @param array $fields fields.
71 * @param array $selected_options selectedOptions.
72 *
73 * @return bool|array
74 * @throws Exception Error.
75 */
76 public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) {
77 $result_arr = [];
78 foreach ( $fields as $field ) {
79 if ( isset( $field['name'] ) && isset( $selected_options[ $field['name'] ] ) && ( trim( wp_strip_all_tags( $selected_options[ $field['name'] ] ) ) !== '' ) ) {
80 $result_arr[ $field['name'] ] = $selected_options[ $field['name'] ];
81 }
82 }
83 // Set title as post_name.
84 $result_arr ['post_title'] = $selected_options['post_name'];
85
86 // Set post_status as publish.
87 $result_arr ['post_status'] = 'publish';
88
89 // Create for Mockup post type.
90 $result_arr['post_type'] = 'ph-project';
91
92 $post_id = wp_insert_post( $result_arr );
93
94 if ( ! $post_id ) {
95 throw new Exception( 'Failed to insert mockup!' );
96 }
97 $project_access_link = get_post_meta( $post_id, 'access_token', true );
98
99 $post = WordPress::get_post_context( $post_id );
100 $permalink = get_the_permalink( $post_id );
101 $post['project_access_link'] = $permalink . '?access_token=' . $project_access_link;
102
103 return $post;
104 }
105 }
106
107 CreateMockup::get_instance();
108