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

Process Facebook 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-link.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_LINK_PAGE'] ) ? sanitize_text_field( $parsed['FACEBOOK_PAGE_PUBLISH_LINK_PAGE'] ) : 0;

		$message = isset( $parsed['FACEBOOK_PAGE_PUBLISH_LINK_MESSAGE'] ) ? sanitize_text_field( $parsed['FACEBOOK_PAGE_PUBLISH_LINK_MESSAGE'] ) : '';

		$link = isset( $parsed['FACEBOOK_PAGE_PUBLISH_LINK_URL'] ) ? sanitize_text_field( $parsed['FACEBOOK_PAGE_PUBLISH_LINK_URL'] ) : '';

		$access_token = $facebook->get_user_page_access_token( $page_id );

		$http_request_query = array(
			'body' => array(
				'access_token' => $access_token,
				'action'       => 'link-to-page',
				'page_id'      => $page_id,
				'message'      => $message,
				'link'         => $link,
			),
		);

		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 {

				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() );
		}

	}