add-post-profile-wall.php
10 months ago
add-post-to-collection.php
10 months ago
add-post-wall.php
10 months ago
assign-listing-plan-to-user.php
5 months ago
change-membership-plan.php
6 months ago
claim-post.php
10 months ago
delete-post.php
6 months ago
delete-wall-post.php
10 months ago
find-post.php
6 months ago
follow-post.php
10 months ago
get-address-by-coordinates.php
10 months ago
get-coordinates-by-address.php
10 months ago
get-member-by-email.php
9 months ago
get-member-by-id.php
9 months ago
get-member-by-profile-id.php
9 months ago
get-post-by-id.php
10 months ago
get-posts-by-voxel-field.php
10 months ago
new-collection-post.php
1 year ago
new-post.php
1 year ago
new-profile.php
10 months ago
remove-post-from-collection.php
10 months ago
send-custom-in-app-notification.php
2 years ago
send-direct-message.php
10 months ago
send-email.php
10 months ago
set-collection-post-verified.php
10 months ago
set-custom-priority.php
10 months ago
set-post-verified.php
10 months ago
set-profile-verified.php
10 months ago
update-collection-post.php
1 year ago
update-post.php
10 months ago
update-profile.php
10 months ago
update-voxel-post-field.php
9 months ago
update-voxel-taxonomy.php
9 months ago
add-post-wall.php
136 lines
| 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 |