Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Parsely integration for 3.17 #283

Merged
merged 5 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `WP Curate` will be documented in this file.

## 2.4.10 - 2025-02-05

- Bug Fix: Fix integration with version 3.17 of the Parsely plugin.

## 2.4.9 - 2025-01-13

- Bug Fix: Allow manually resetting custom post title back to original title.
Expand Down
28 changes: 15 additions & 13 deletions src/features/class-parsely-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,16 @@ public function add_parsely_trending_posts_query( array $posts, array $args ): a
* @return array<int> An array of post IDs.
*/
public function get_trending_posts( array $args ): array {
$parsely = $GLOBALS['parsely'];
if ( ! $parsely ) {
return [];
}
if ( ! $parsely->api_secret_is_set() ) {
return [];
}
if ( ! class_exists( '\Parsely\Parsely' ) || ! isset( $GLOBALS['parsely'] ) || ! $GLOBALS['parsely'] instanceof Parsely ) {
global $parsely;

if ( ! $parsely instanceof Parsely ) { // @phpstan-ignore class.notFound
return [];
}
if ( ! class_exists( '\Parsely\RemoteAPI\Analytics_Posts_API' ) ) {
if ( ! $parsely->api_secret_is_set() ) { // @phpstan-ignore class.notFound
return [];
}

$parsely_options = $GLOBALS['parsely']->get_options();
$parsely_options = $parsely->get_options(); // @phpstan-ignore class.notFound
/**
* Filter the period start for the Parsely API.
*
Expand Down Expand Up @@ -113,9 +108,16 @@ public function get_trending_posts( array $args ): array {
$cache_key = 'parsely_trending_posts_' . md5( wp_json_encode( $parsely_args ) ); // @phpstan-ignore-line - wp_Json_encode not likely to return false.
$ids = wp_cache_get( $cache_key );
if ( false === $ids || ! is_array( $ids ) ) {
$api = new Analytics_Posts_API( $GLOBALS['parsely'] );
$posts = $api->get_posts_analytics( $parsely_args );
if ( \is_wp_error( $posts ) || ! \is_array( $posts ) ) {
$posts = null;

if ( method_exists( $parsely, 'get_content_api' ) ) {
$posts = $parsely->get_content_api()->get_posts( $parsely_args ); // @phpstan-ignore class.notFound
} elseif ( class_exists( '\Parsely\RemoteAPI\Analytics_Posts_API' ) ) {
$api = new Analytics_Posts_API( $parsely );
$posts = $api->get_posts_analytics( $parsely_args );
}

if ( ! \is_array( $posts ) ) {
return [];
}
$ids = array_map(
Expand Down
2 changes: 1 addition & 1 deletion wp-curate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WP Curate
* Plugin URI: https://github.com/alleyinteractive/wp-curate
* Description: Plugin to curate homepages and other landing pages
* Version: 2.4.9
* Version: 2.4.10
* Author: Alley Interactive
* Author URI: https://github.com/alleyinteractive/wp-curate
* Requires at least: 6.4
Expand Down
Loading