Skip to content

Commit

Permalink
feat: add support in fb old method
Browse files Browse the repository at this point in the history
  • Loading branch information
girishpanchal30 committed Jan 8, 2025
1 parent 4ab8b57 commit b820995
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions includes/admin/services/class-rop-facebook-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,16 @@ private function try_post( $new_post, $page_id, $token, $post_id, $posting_type
$this->rop_fb_scrape_url( $posting_type, $post_id, $token );
}

$api->post( $path, $new_post, $token );
$response = $api->post( $path, $new_post, $token );
$fb_post_id = $response->getGraphNode()->getField( 'id' );
$fb_helper = new ROP_Pro_Facebook_Helper();
$fb_helper->share_as_first_comment(
$fb_post_id,
array(
'message' => $share_link_text,
'access_token' => $token,
)
);

return true;
} catch ( Facebook\Exceptions\FacebookResponseException $e ) {
Expand All @@ -750,8 +759,16 @@ private function try_post( $new_post, $page_id, $token, $post_id, $posting_type
}

try {
$api->post( $path, $new_post, $token );

$response = $api->post( $path, $new_post, $token );
$fb_post_id = $response->getGraphNode()->getField( 'id' );
$fb_helper = new ROP_Pro_Facebook_Helper();
$fb_helper->share_as_first_comment(
$fb_post_id,
array(
'message' => $share_link_text,
'access_token' => $token,
)
);
return true;
} catch ( Facebook\Exceptions\FacebookResponseException $e ) {
$this->logger->alert_error( 'Unable to share post for facebook. (FacebookResponseException) Error: ' . $e->getMessage() );
Expand Down Expand Up @@ -907,6 +924,14 @@ private function try_post( $new_post, $page_id, $token, $post_id, $posting_type
}

if ( ! empty( $body['id'] ) ) {
$fb_helper = new ROP_Pro_Facebook_Helper();
$fb_helper->share_as_first_comment(
$body['id'],
array(
'message' => $share_link_text,
'access_token' => $token,
)
);
return true;
} elseif ( ! empty( $body['error']['message'] ) ) {
$this->logger->alert_error( 'Error Posting to Facebook: ' . $body['error']['message'] );
Expand Down

0 comments on commit b820995

Please sign in to comment.