PluginProbe
OttoKit: All-in-One Automation Platform / 1.1.34
OttoKit: All-in-One Automation Platform v1.1.34
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 / voxel / actions / add-post-wall.php
add-post-wall.php
136 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * AddPostWall.
4 * php version 5.6
5 *
6 * @category AddPostWall
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\Voxel\Actions;
15
16 use SureTriggers\Integrations\AutomateAction;
17 use SureTriggers\Traits\SingletonLoader;
18 use SureTriggers\Integrations\WordPress\WordPress;
19 use SureTriggers\Integrations\Voxel\Voxel;
20 use Exception;
21
22 /**
23 * AddPostWall
24 *
25 * @category AddPostWall
26 * @package SureTriggers
27 * @author BSF <username@example.com>
28 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
29 * @link https://www.brainstormforce.com/
30 * @since 1.0.0
31 */
32 class AddPostWall extends AutomateAction {
33
34 /**
35 * Integration type.
36 *
37 * @var string
38 */
39 public $integration = 'Voxel';
40
41 /**
42 * Action name.
43 *
44 * @var string
45 */
46 public $action = 'voxel_add_post_wall';
47
48 use SingletonLoader;
49
50 /**
51 * Register action.
52 *
53 * @param array $actions action data.
54 * @return array
55 */
56 public function register( $actions ) {
57 $actions[ $this->integration ][ $this->action ] = [
58 'label' => __( 'Add Post to Wall', 'suretriggers' ),
59 'action' => 'voxel_add_post_wall',
60 'function' => [ $this, 'action_listener' ],
61 ];
62
63 return $actions;
64 }
65
66 /**
67 * Action listener.
68 *
69 * @param int $user_id user_id.
70 * @param int $automation_id automation_id.
71 * @param array $fields fields.
72 * @param array $selected_options selectedOptions.
73 *
74 * @throws Exception Exception.
75 *
76 * @return bool|array
77 */
78 public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) {
79 $user_email = $selected_options['wp_user_email'];
80 $content = $selected_options['content'];
81 $post_id = (int) $selected_options['post_id'];
82 $file_ids = isset( $selected_options['image_ids'] ) && '' !== $selected_options['image_ids'] ? explode( ',', $selected_options['image_ids'] ) : [];
83
84 if ( ! class_exists( 'Voxel\Post' ) || ! class_exists( 'Voxel\Timeline\Status' ) || ! class_exists( 'Voxel\Events\Timeline\Statuses\Post_Wall_Status_Created_Event' ) || ! defined( 'Voxel\MODERATION_APPROVED' ) || ! defined( 'Voxel\MODERATION_PENDING' ) ) {
85 return false;
86 }
87
88 if ( is_email( $user_email ) ) {
89 $user = get_user_by( 'email', $user_email );
90 $user_id = $user ? $user->ID : 1;
91 }
92
93 // Get the post.
94 $post = \Voxel\Post::force_get( $post_id );
95 if ( ! $post ) {
96 return [
97 'status' => 'error',
98 'message' => 'Post not found',
99 ];
100 }
101
102 $details = [];
103 if ( ! empty( $file_ids ) ) {
104 $details['files'] = Voxel::sanitize_files( $file_ids );
105 }
106
107 $status = \Voxel\Timeline\Status::create(
108 [
109 'feed' => 'post_wall',
110 'user_id' => $user_id,
111 'post_id' => $post->get_id(),
112 'content' => $content,
113 'details' => ! empty( $details ) ? $details : null,
114 'moderation' => $post->post_type->timeline->wall_posts_require_approval() ? \Voxel\MODERATION_PENDING : \Voxel\MODERATION_APPROVED,
115 ],
116 [ 'link_preview' => 'instant' ]
117 );
118
119 // Create and send the wall post created event.
120 ( new \Voxel\Events\Timeline\Statuses\Post_Wall_Status_Created_Event( $post->post_type ) )->dispatch( $status->get_id() );
121
122 return [
123 'success' => true,
124 'message' => esc_attr__( "Post added to Post's wall successfully", 'suretriggers' ),
125 'post_id' => $post_id,
126 'post_url' => get_permalink( $post_id ),
127 'status_id' => $status->get_id(),
128 'creator' => WordPress::get_user_context( $user_id ),
129 'content' => $content,
130 ];
131 }
132
133 }
134
135 AddPostWall::get_instance();
136