PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.3
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.3
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 / bluesky / includes / actions / create-post.php

create-post.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.3, at integrations/bluesky/includes/actions/create-post.php

194 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Create Post
4 *
5 * @package AutomatorWP\Integrations\Bluesky\Actions\Create-Post
6 * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]>
7 * @since 1.0.0
8 */
9
10 // Exit if accessed directly
11 if( !defined('ABSPATH')) exit;
12
13 class AutomatorWP_Bluesky_Create_Post extends AutomatorWP_Integration_Action {
14
15 public $integration = 'bluesky';
16 public $action = 'bluesky_create_post';
17
18 /**
19 * Register the action
20 *
21 * @since 1.0.0
22 */
23 public function register(){
24
25 automatorwp_register_action( $this->action, array(
26 'integration' => $this->integration,
27 'label' => __( 'Create a new post', 'automatorwp'),
28 'select_option' => __( 'Create a new <strong>post</strong>', 'automatorwp'),
29 /* translators: %1$s: Card. */
30 'edit_label' => sprintf( __( 'Create a new %1$s', 'automatorwp' ), '{post}' ),
31 /* translators: %1$s: Card. */
32 'log_label' => sprintf( __( 'Create a new %1$s', 'automatorwp' ) , '{post}' ),
33 'options' => array(
34 'post' => array(
35 //'from' => 'post',
36 'default' => __('post', 'automatorwp'),
37 'fields' => array(
38 'post_content' => array(
39 'name' => __('Post content:', 'automatorwp'),
40 'type' => 'textarea',
41 'default' => '',
42 'required' => true
43 )
44 ),
45 )
46 ),
47 ),
48 );
49
50 }
51
52 /**
53 * Action execution function
54 *
55 * @since 1.0.0
56 *
57 * @param stdClass $action The action object
58 * @param int $user_id The user ID
59 * @param array $action_options The action's stored options (with tags already passed)
60 * @param stdClass $automation The action's automation object
61 */
62 public function execute( $action, $user_id, $action_options, $automation ) {
63
64 // Shorthand
65 $post_content = $action_options['post_content'];
66
67 // Bail if Bluesky not configured
68 if( ! automatorwp_bluesky_get_api() ) {
69 $this->result = __( 'Bluesky integration is not configured in AutomatorWP settings', 'automatorwp' );
70 return;
71 }
72
73 $response = automatorwp_bluesky_create_post( $post_content );
74
75 if( $response === 200 ) {
76 $this->result = __( 'Post created.', 'autoamtorwp-bluesky' );
77 }else {
78 $this->result = __( 'The post could not be created', 'automatorwp' );
79 }
80
81 }
82
83 /**
84 * Register required hooks
85 *
86 * @since 1.0.0
87 */
88 public function hooks() {
89
90 // Configuration notice
91 add_filter( 'automatorwp_automation_ui_after_item_label', array( $this, 'configuration_notice' ), 10, 2 );
92
93 // Log meta data
94 add_filter( 'automatorwp_user_completed_action_log_meta', array( $this, 'log_meta' ), 10, 5 );
95
96 // Log fields
97 add_filter( 'automatorwp_log_fields', array( $this, 'log_fields' ), 10, 5 );
98
99 parent::hooks();
100
101 }
102
103 /**
104 * Configuration notice
105 *
106 * @since 1.0.0
107 *
108 * @param stdClass $object The trigger/action object
109 * @param string $item_type The object type (trigger|action)
110 */
111 public function configuration_notice( $object, $item_type ) {
112
113 // Bail if action type don't match this action
114 if( $item_type !== 'action' ) {
115 return;
116 }
117
118 if( $object->type !== $this->action ) {
119 return;
120 }
121
122 // Warn user if the authorization has not been setup from settings
123 if( ! automatorwp_bluesky_get_api() ) : ?>
124 <div class="automatorwp-notice-warning" style="margin-top: 10px; margin-bottom: 0;">
125 <?php echo sprintf(
126 __( 'You need to configure the <a href="%s" target="_blank">Bluesky settings</a> to get this action to work.', 'automatorwp' ),
127 get_admin_url() . 'admin.php?page=automatorwp_settings&tab=opt-tab-bluesky'
128 ); ?>
129 <?php echo sprintf(
130 __( '<a href="%s" target="_blank">Documentation</a>', 'automatorwp' ),
131 'https://automatorwp.com/docs/bluesky/'
132 ); ?>
133 </div>
134 <?php endif;
135 }
136
137 /**
138 * Action custom log meta
139 *
140 * @since 1.0.0
141 *
142 * @param array $log_meta Log meta data
143 * @param stdClass $action The action object
144 * @param int $user_id The user ID
145 * @param array $action_options The action's stored options (with tags already passed)
146 * @param stdClass $automation The action's automation object
147 *
148 * @return array
149 */
150 public function log_meta( $log_meta, $action, $user_id, $action_options, $automation ) {
151
152 // Bail if action type don't match this action
153 if( $action->type !== $this->action ) {
154 return $log_meta;
155 }
156
157 // Store the action's result
158 $log_meta['result'] = $this->result;
159
160 return $log_meta;
161 }
162
163 /**
164 * Action custom log fields
165 *
166 * @since 1.0.0
167 *
168 * @param array $log_fields The log fields
169 * @param stdClass $log The log object
170 * @param stdClass $object The trigger/action/automation object attached to the log
171 *
172 * @return array
173 */
174 public function log_fields( $log_fields, $log, $object ) {
175
176 // Bail if log is not assigned to an action
177 if( $log->type !== 'action' ) {
178 return $log_fields;
179 }
180
181 // Bail if action type don't match this action
182 if( $object->type !== $this->action ) {
183 return $log_fields;
184 }
185
186 $log_fields['result'] = array(
187 'name' => __( 'Result:', 'automatorwp' ),
188 'type' => 'text',
189 );
190
191 return $log_fields;
192 }
193 }
194 new AutomatorWP_Bluesky_Create_Post();