← All changes
|
integrations/buddyboss/includes/actions/add-user-activity.php
+125
-0
5.7.2
→
6.0.3
View file →
| @@ -1,0 +1,125 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Add User Activity | |
| 4 | + * | |
| 5 | + * @package AutomatorWP\Integrations\BuddyBoss\Actions\Add_User_Activity | |
| 6 | + * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]> | |
| 7 | + * @since 1.0.0 | |
| 8 | + */ | |
| 9 | +// Exit if accessed directly | |
| 10 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 11 | + | |
| 12 | +class AutomatorWP_BuddyBoss_Add_User_Activity extends AutomatorWP_Integration_Action { | |
| 13 | + | |
| 14 | + public $integration = 'buddyboss'; | |
| 15 | + public $action = 'buddyboss_add_user_activity'; | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * Register the trigger | |
| 19 | + * | |
| 20 | + * @since 1.0.0 | |
| 21 | + */ | |
| 22 | + public function register() { | |
| 23 | + | |
| 24 | + automatorwp_register_action( $this->action, array( | |
| 25 | + 'integration' => $this->integration, | |
| 26 | + 'label' => __( 'Add an activity to the user', 'automatorwp' ), | |
| 27 | + 'select_option' => __( 'Add an <strong>activity</strong> to the user', 'automatorwp' ), | |
| 28 | + /* translators: %1$s: Activity. */ | |
| 29 | + 'edit_label' => sprintf( __( 'Add an %1$s to the user', 'automatorwp' ), '{activity}' ), | |
| 30 | + /* translators: %1$s: Activity. */ | |
| 31 | + 'log_label' => sprintf( __( 'Add an %1$s to the user', 'automatorwp' ), '{activity}' ), | |
| 32 | + 'options' => array( | |
| 33 | + 'activity' => array( | |
| 34 | + 'default' => __( 'activity', 'automatorwp' ), | |
| 35 | + 'fields' => array( | |
| 36 | + // Note: "action" key is reserved | |
| 37 | + 'activity_action' => array( | |
| 38 | + 'name' => __( 'Action:', 'automatorwp' ), | |
| 39 | + 'desc' => __( 'Activity\'s action.', 'automatorwp' ), | |
| 40 | + 'type' => 'text', | |
| 41 | + 'default' => '' | |
| 42 | + ), | |
| 43 | + 'content' => array( | |
| 44 | + 'name' => __( 'Content:', 'automatorwp' ), | |
| 45 | + 'desc' => __( 'Activity\'s content.', 'automatorwp' ), | |
| 46 | + 'type' => 'wysiwyg', | |
| 47 | + 'default' => '' | |
| 48 | + ), | |
| 49 | + 'link_preview' => array( | |
| 50 | + 'name' => __( 'Link Preview (Optional):', 'automatorwp' ), | |
| 51 | + 'desc' => __( 'URL link to show as preview with the activity.', 'automatorwp' ), | |
| 52 | + 'type' => 'text', | |
| 53 | + 'default' => '' | |
| 54 | + ), | |
| 55 | + 'link' => array( | |
| 56 | + 'name' => __( 'Link:', 'automatorwp' ), | |
| 57 | + 'desc' => __( 'URL link associated to the activity.', 'automatorwp' ), | |
| 58 | + 'type' => 'text', | |
| 59 | + 'default' => '' | |
| 60 | + ), | |
| 61 | + 'hide_sitewide' => array( | |
| 62 | + 'name' => __( 'Hide on the sitewide activity stream:', 'automatorwp' ), | |
| 63 | + 'desc' => __( 'Check this option to hide this activity from the sitewide activity stream.', 'automatorwp' ), | |
| 64 | + 'type' => 'checkbox', | |
| 65 | + 'classes' => 'cmb2-switch' | |
| 66 | + ), | |
| 67 | + ) | |
| 68 | + ) | |
| 69 | + ), | |
| 70 | + ) ); | |
| 71 | + | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * Action execution function | |
| 76 | + * | |
| 77 | + * @since 1.0.0 | |
| 78 | + * | |
| 79 | + * @param stdClass $action The action object | |
| 80 | + * @param int $user_id The user ID | |
| 81 | + * @param array $action_options The action's stored options (with tags already passed) | |
| 82 | + * @param stdClass $automation The action's automation object | |
| 83 | + */ | |
| 84 | + public function execute( $action, $user_id, $action_options, $automation ) { | |
| 85 | + | |
| 86 | + if( ! function_exists( 'bp_activity_add' ) ) { | |
| 87 | + return; | |
| 88 | + } | |
| 89 | + | |
| 90 | + // Shorthand | |
| 91 | + $activity_action = $action_options['activity_action']; | |
| 92 | + $content = $action_options['content']; | |
| 93 | + $link_preview = $action_options['link_preview']; | |
| 94 | + $link = $action_options['link']; | |
| 95 | + $hide = $action_options['hide_sitewide']; | |
| 96 | + | |
| 97 | + // Add the activity to the user | |
| 98 | + $activity_id = bp_activity_add( array( | |
| 99 | + 'action' => $activity_action, | |
| 100 | + 'content' => $content, | |
| 101 | + 'component' => 'automatorwp', | |
| 102 | + 'type' => 'activity_update', | |
| 103 | + 'primary_link' => $link, | |
| 104 | + 'user_id' => $user_id, | |
| 105 | + 'item_id' => false, | |
| 106 | + 'secondary_item_id' => false, | |
| 107 | + 'hide_sitewide' => (bool) $hide, | |
| 108 | + ) ); | |
| 109 | + | |
| 110 | + // Activity link preview | |
| 111 | + if( $activity_id && ! empty( $link_preview ) ) { | |
| 112 | + | |
| 113 | + $preview_data = automatorwp_buddyboss_get_link_preview( $link_preview ); | |
| 114 | + | |
| 115 | + if( $preview_data !== false ) { | |
| 116 | + bp_activity_update_meta( $activity_id, '_link_embed', '1' ); | |
| 117 | + bp_activity_update_meta( $activity_id, '_link_preview_data', $preview_data ); | |
| 118 | + } | |
| 119 | + } | |
| 120 | + | |
| 121 | + } | |
| 122 | + | |
| 123 | +} | |
| 124 | + | |
| 125 | +new AutomatorWP_BuddyBoss_Add_User_Activity(); | |