Skip to content

Commit

Permalink
Fix bugs & clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
bafi committed Aug 27, 2024
1 parent 4ef32dc commit 3cf2eac
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/PccSyncManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,14 @@ private function syncPostMetaAndTags($postId, Article $article): void
wp_set_post_categories($postId, $this->findArticleCategories($article));

// Check if Yoast SEO is installed and active.
if (in_array('wordpress-seo/wp-seo.php', apply_filters('active_plugins', get_option('active_plugins')))) {
$yoastMetaDesc = get_post_meta($postId, '_yoast_wpseo_metadesc', true);
if (!$yoastMetaDesc) {
$activePlugins = apply_filters('active_plugins', get_option('active_plugins'));
if (in_array('wordpress-seo/wp-seo.php', $activePlugins)) {
if (!get_post_meta($postId, '_yoast_wpseo_metadesc', true)) {
update_post_meta($postId, '_yoast_wpseo_metadesc', $article->metadata['description']);
}
}
}


/**
* Set the post feature image.
*
Expand All @@ -177,7 +176,7 @@ private function setPostFeatureImage($postId, Article $article)
}

// If the feature image is empty, delete the existing thumbnail.
$featuredImageURL = $article->metadata['FeaturedImage'] ?: '';
$featuredImageURL = $article->metadata['FeaturedImage'] ?? '';
if ('' === $featuredImageURL) {
delete_post_thumbnail($postId);
return;
Expand Down Expand Up @@ -214,6 +213,7 @@ private function setPostFeatureImage($postId, Article $article)
private function findArticleCategories(Article $article): array
{
$categories = isset($article->metadata['Categories']) ? explode(',', (string) $article->metadata['Categories']) : [];
$categories = array_filter($categories);
if (!$categories) {
return [];
}
Expand All @@ -229,7 +229,7 @@ private function findArticleCategories(Article $article): array
*
* @return array The categories IDs.
*/
private function findOrCreateCategories($categories): array
private function findOrCreateCategories(array $categories): array
{
$ids = [];
if (!function_exists('wp_insert_category')) {
Expand Down Expand Up @@ -361,7 +361,7 @@ public function isPCCConfigured(): bool
$siteId = get_option(PCC_SITE_ID_OPTION_KEY);
$encodedSiteURL = get_option(PCC_ENCODED_SITE_URL_OPTION_KEY);
$apiKey = get_option(PCC_API_KEY_OPTION_KEY);

return true;
if (!$accessToken || !$siteId || !$apiKey || !$encodedSiteURL) {
return false;
}
Expand Down

0 comments on commit 3cf2eac

Please sign in to comment.