FACEBOOK_PAGE_PUBLISH_POST::process_action( $user_id, $action_data, $recipe_id, $args, $parsed )
Process the action.
Contents
Parameters Parameters
- $user_id
-
(Required)
- $action_data
-
(Required)
- $recipe_id
-
(Required)
- $args
-
(Required)
- $parsed
-
(Required)
Return Return
(Uncanny_Automatorvoid.)
Source Source
File: src/integrations/facebook/actions/facebook-page-publish-post.php
protected function process_action( int $user_id, array $action_data, int $recipe_id, array $args, $parsed ) { $facebook = Automator()->helpers->recipe->facebook->options; $page_id = sanitize_text_field( $parsed['FACEBOOK_PAGE_PUBLISH_POST_META'] ); $message = sanitize_textarea_field( $parsed['FACEBOOK_PAGE_MESSAGE'] ); $access_token = $facebook->get_user_page_access_token( $page_id ); $request = wp_remote_post( $facebook->get_endpoint_url(), array( 'body' => array( 'action' => 'post-to-page', 'access_token' => $access_token, 'message' => $message, 'page_id' => $page_id, ), ) ); // Check to see if there are any errors regarding our request to the api. if ( ! is_wp_error( $request ) ) { $response = json_decode( wp_remote_retrieve_body( $request ) ); if ( 200 !== $response->statusCode ) { $action_data['complete_with_errors'] = true; // Log error if there are any error messages. Automator()->complete->action( $user_id, $action_data, $recipe_id, $response->error->description ); } else { // Otherwise, complete the action. Automator()->complete->action( $user_id, $action_data, $recipe_id ); } } else { // Log if there are any http errors. $action_data['complete_with_errors'] = true; Automator()->complete->action( $user_id, $action_data, $recipe_id, $request->get_error_message() ); } }
Expand full source code Collapse full source code View on Github