FACEBOOK_PAGE_PUBLISH_PHOTO::process_action( $user_id,  $action_data,  $recipe_id,  $args,  $parsed )

Process the action.


Parameters Parameters

$user_id

(Required)

$action_data

(Required)

$recipe_id

(Required)

$args

(Required)

$parsed

(Required)


Top ↑

Return Return

(Uncanny_Automatorvoid.)


Source Source

File: src/integrations/facebook/actions/facebook-page-publish-photo.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 = isset( $parsed['FACEBOOK_PAGE_PUBLISH_PHOTO_META'] ) ? sanitize_text_field( $parsed['FACEBOOK_PAGE_PUBLISH_PHOTO_META'] ) : 0;
		$image_url = isset( $parsed['FACEBOOK_PAGE_PUBLISH_PHOTO_IMAGE_URL'] ) ? sanitize_text_field( $parsed['FACEBOOK_PAGE_PUBLISH_PHOTO_IMAGE_URL'] ) : '';
		$access_token = $facebook->get_user_page_access_token( $page_id );
		$http_request_query = array(
			'body' => array(
				'action'       => 'image-to-page',
				'access_token' => $access_token,
				'image_url'    => $image_url,
				'page_id'      => $page_id,
			),
		);
		if ( DEFINED( 'UO_AUTOMATOR_DEV_FB_ENDPOINT_URL' ) ) {
			$http_request_query['sslverify'] = false;
		}
		$request = wp_remote_post(
			$this->fb_endpoint_uri,
			$http_request_query
		);
		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() );
		}
	}