PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.1
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.1
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
automatorwp / integrations / mycred / includes / actions / award-user-points.php

award-user-points.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.1, at integrations/mycred/includes/actions/award-user-points.php

130 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Award User Points
4 *
5 * @package AutomatorWP\Integrations\MyCred\Actions\Award_User_Points
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_MyCred_Award_User_Points extends AutomatorWP_Integration_Action {
13
14 public $integration = 'mycred';
15 public $action = 'mycred_award_user_points';
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' => __( 'Award points to user', 'automatorwp' ),
27 'select_option' => __( 'Award <strong>points</strong> to user', 'automatorwp' ),
28 /* translators: %1$s: Points amount. %2$s: Post title. %3$s: User. */
29 'edit_label' => sprintf( __( 'Award %1$s %2$s to %3$s', 'automatorwp' ), '{points}', '{points_type}', '{user}' ),
30 /* translators: %1$s: Points amount. %2$s: Post title. %3$s: User. */
31 'log_label' => sprintf( __( 'Award %1$s %2$s to %3$s', 'automatorwp' ), '{points}', '{points_type}', '{user}' ),
32 'options' => array(
33 'points' => array(
34 'from' => 'points',
35 'fields' => array(
36 'points' => array(
37 'name' => __( 'Points amount:', 'automatorwp' ),
38 'type' => 'text',
39 'default' => '1'
40 ),
41 'reference' => array(
42 'name' => __( 'Reference:', 'automatorwp' ),
43 'desc' => __( 'The reference to log. Leave blank for "Automatorwp Reward" default value', 'automatorwp' ),
44 'type' => 'text',
45 'default' => ''
46 ),
47 'earning_text' => array(
48 'name' => __( 'User earning text:', 'automatorwp' ),
49 'desc' => __( 'Enter the text for the user entry. Leave blank for "Automatorwp Reward" default value.', 'automatorwp' ),
50 'type' => 'text',
51 'default' => ''
52 )
53 )
54 ),
55 'points_type' => automatorwp_utilities_ajax_selector_option( array(
56 'field' => 'points_type',
57 'option_default' => __( 'points type', 'automatorwp' ),
58 'name' => __( 'Points Type:', 'automatorwp' ),
59 'option_none' => false,
60 'action_cb' => 'automatorwp_mycred_get_point_types',
61 'options_cb' => 'automatorwp_mycred_options_cb_point_type',
62 'placeholder' => 'Select a point type',
63 'default' => ''
64 ) ),
65 'user' => array(
66 'from' => 'user',
67 'default' => __( 'user', 'automatorwp' ),
68 'fields' => array(
69 'user' => array(
70 'name' => __( 'User ID:', 'automatorwp' ),
71 'desc' => __( 'User ID that will receive this points. Leave blank to award the points to the user that completes the automation.', 'automatorwp' ),
72 'type' => 'text',
73 'default' => ''
74 ),
75 )
76 ),
77 ),
78 ) );
79
80 }
81
82 /**
83 * Action execution function
84 *
85 * @since 1.0.0
86 *
87 * @param stdClass $action The action object
88 * @param int $user_id The user ID
89 * @param array $action_options The action's stored options (with tags already passed)
90 * @param stdClass $automation The action's automation object
91 */
92 public function execute( $action, $user_id, $action_options, $automation ) {
93
94 // Shorthand
95 $points = absint( $action_options['points'] );
96 $points_type = $action_options['points_type'];
97 $reference = $action_options['reference'];
98 $earning_text = $action_options['earning_text'];
99 $user_id_to_award = absint( $action_options['user'] );
100
101 if( $user_id_to_award === 0 ) {
102 $user_id_to_award = $user_id;
103 }
104
105 $user = get_userdata( $user_id_to_award );
106
107 // Bail if user does not exists
108 if( ! $user ) {
109 return;
110 }
111
112 // Bail if no points to award
113 if( $points === 0 ) {
114 return;
115 }
116
117 if ( empty ( $reference ) )
118 $reference = 'automatorwp_reward';
119
120 if ( empty ( $earning_text ) )
121 $earning_text = 'AutomatorWP Reward';
122
123 mycred_add( $reference, $user_id_to_award, $points, $earning_text, '', '', $points_type );
124
125
126 }
127
128 }
129
130 new AutomatorWP_MyCred_Award_User_Points();