Skip to content

Commit

Permalink
fix: check if helper class exists
Browse files Browse the repository at this point in the history
  • Loading branch information
girishpanchal30 committed Jan 30, 2025
1 parent ba387b9 commit b3237b8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 44 deletions.
73 changes: 41 additions & 32 deletions includes/admin/services/class-rop-facebook-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,14 +724,17 @@ private function try_post( $new_post, $page_id, $token, $post_id, $posting_type

$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' => $this->share_link_text,
'access_token' => $token,
)
);

if ( class_exists( 'ROP_Pro_Facebook_Helper' ) ) {
$fb_helper = new ROP_Pro_Facebook_Helper();
$fb_helper->share_as_first_comment(
$fb_post_id,
array(
'message' => $this->share_link_text,
'access_token' => $token,
)
);
}

return true;
} catch ( Facebook\Exceptions\FacebookResponseException $e ) {
Expand All @@ -757,14 +760,16 @@ private function try_post( $new_post, $page_id, $token, $post_id, $posting_type
try {
$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' => $this->share_link_text,
'access_token' => $token,
)
);
if ( class_exists( 'ROP_Pro_Facebook_Helper' ) ) {
$fb_helper = new ROP_Pro_Facebook_Helper();
$fb_helper->share_as_first_comment(
$fb_post_id,
array(
'message' => $this->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 @@ -853,14 +858,16 @@ 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' => $this->share_link_text,
'access_token' => $token,
)
);
if ( class_exists( 'ROP_Pro_Facebook_Helper' ) ) {
$fb_helper = new ROP_Pro_Facebook_Helper();
$fb_helper->share_as_first_comment(
$body['id'],
array(
'message' => $this->share_link_text,
'access_token' => $token,
)
);
}
return true;
} elseif ( ! empty( $body['error']['message'] ) ) {
if (
Expand Down Expand Up @@ -920,14 +927,16 @@ 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' => $this->share_link_text,
'access_token' => $token,
)
);
if ( class_exists( 'ROP_Pro_Facebook_Helper' ) ) {
$fb_helper = new ROP_Pro_Facebook_Helper();
$fb_helper->share_as_first_comment(
$body['id'],
array(
'message' => $this->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
26 changes: 14 additions & 12 deletions includes/admin/services/class-rop-linkedin-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,19 +610,21 @@ public function share( $post_details, $args = array() ) {
}
}

$linkedin_helper = new ROP_Pro_Linkdin_Helper();
$linkedin_helper->share_as_first_comment(
$post_id,
array(
'token' => $token,
'body' => array(
'actor' => $new_post['author'],
'message' => array(
'text' => $this->share_link_text,
if ( class_exists( 'ROP_Pro_Linkdin_Helper' ) ) {
$linkedin_helper = new ROP_Pro_Linkdin_Helper();
$linkedin_helper->share_as_first_comment(
$post_id,
array(
'token' => $token,
'body' => array(
'actor' => $new_post['author'],
'message' => array(
'text' => $this->share_link_text,
),
),
),
)
);
)
);
}
}

$title = isset( $new_post['content']['media']['title'] ) ? $new_post['content']['media']['title'] : $new_post['content']['article']['title'];
Expand Down

0 comments on commit b3237b8

Please sign in to comment.