PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.4
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.4
6.0.4 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 All 35 releases
← All changes | integrations/gamipress/includes/actions/user-rank.php +104 -0 5.8.2 → 6.0.4 View file →
@@ -1,0 +1,104 @@
1 +<?php
2 +/**
3 + * User Rank
4 + *
5 + * @package AutomatorWP\Integrations\GamiPress\Actions\User_Rank
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_GamiPress_User_Rank extends AutomatorWP_Integration_Action {
13 +
14 + public $integration = 'gamipress';
15 + public $action = 'gamipress_user_rank';
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 rank to user', 'automatorwp' ),
27 + 'select_option' => __( 'Award <strong>rank</strong> to user', 'automatorwp' ),
28 + /* translators: %1$s: Post title. %2$s: User. */
29 + 'edit_label' => sprintf( __( 'Award the rank: %1$s to %2$s', 'automatorwp' ), '{post}', '{user}' ),
30 + /* translators: %1$s: Post title. %2$s: User. */
31 + 'log_label' => sprintf( __( 'Award the rank: %1$s to %2$s', 'automatorwp' ), '{post}', '{user}' ),
32 + 'options' => array(
33 + 'post' => automatorwp_gamipress_utilities_post_option( array(
34 + 'name' => __( 'Rank:', 'automatorwp' ),
35 + 'option_default' => __( 'Select an rank', 'automatorwp' ),
36 + 'option_none' => false,
37 + 'option_custom' => true,
38 + 'option_custom_desc' => __( 'Achievement ID', 'automatorwp' ),
39 + 'post_type_cb' => 'gamipress_get_rank_types_slugs'
40 + ) ),
41 + 'user' => array(
42 + 'from' => 'user',
43 + 'default' => __( 'user', 'automatorwp' ),
44 + 'fields' => array(
45 + 'user' => array(
46 + 'name' => __( 'User ID:', 'automatorwp' ),
47 + 'desc' => __( 'User ID that will receive this rank. Leave blank to award the rank to the user that completes the automation.', 'automatorwp' ),
48 + 'type' => 'text',
49 + 'default' => ''
50 + ),
51 + )
52 + ),
53 + ),
54 + ) );
55 +
56 + }
57 +
58 + /**
59 + * Action execution function
60 + *
61 + * @since 1.0.0
62 + *
63 + * @param stdClass $action The action object
64 + * @param int $user_id The user ID
65 + * @param array $action_options The action's stored options (with tags already passed)
66 + * @param stdClass $automation The action's automation object
67 + */
68 + public function execute( $action, $user_id, $action_options, $automation ) {
69 +
70 + // Shorthand
71 + $post_id = absint( $action_options['post'] );
72 + $user_id_to_award = absint( $action_options['user'] );
73 +
74 + if( $user_id_to_award === 0 ) {
75 + $user_id_to_award = $user_id;
76 + }
77 +
78 + $user = get_userdata( $user_id_to_award );
79 +
80 + // Bail if user does not exists
81 + if( ! $user ) {
82 + return;
83 + }
84 +
85 + $post = get_post( $post_id );
86 +
87 + // Bail if post doesn't exists
88 + if( ! $post ) {
89 + return;
90 + }
91 +
92 + // Bail if post is not an rank
93 + if( ! in_array( $post->post_type, gamipress_get_rank_types_slugs() ) ) {
94 + return;
95 + }
96 +
97 + // Award the rank
98 + gamipress_award_rank_to_user( $post_id, $user_id_to_award );
99 +
100 + }
101 +
102 +}
103 +
104 +new AutomatorWP_GamiPress_User_Rank();