Skip to content

Commit

Permalink
Merge pull request #1117 from Parsely/release/3.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
acicovic authored Sep 28, 2022
2 parents 747c7be + 3862944 commit f6c00c9
Show file tree
Hide file tree
Showing 26 changed files with 328 additions and 76 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.5.2](https://github.com/Parsely/wp-parsely/compare/3.5.1...3.5.2) - 2022-09-27

### Changed

- Use Parsely->get_options() in the whole codebase ([#1098](https://github.com/Parsely/wp-parsely/pull/1098))
- Content Helper: Show "Contact Us" message when Site ID or API Secret are not set ([#1114](https://github.com/Parsely/wp-parsely/pull/1114))

## [3.5.1](https://github.com/Parsely/wp-parsely/compare/3.5.0...3.5.1) - 2022-09-13

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Parse.ly

Stable tag: 3.5.1
Stable tag: 3.5.2
Requires at least: 5.0
Tested up to: 6.0.1
Tested up to: 6.0.2
Requires PHP: 7.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down
2 changes: 1 addition & 1 deletion build/content-helper.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-url'), 'version' => '4de2014303dbe6c5c613');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-url'), 'version' => '5586b7cf1f5a7b47b471');
2 changes: 1 addition & 1 deletion build/content-helper.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-parsely",
"version": "3.5.1",
"version": "3.5.2",
"private": true,
"description": "The Parse.ly plugin facilitates real-time and historical analytics to your content through a platform designed and built for digital publishing.",
"author": "parsely, hbbtstar, jblz, mikeyarce, GaryJ, parsely_mike, pauarge",
Expand Down
10 changes: 8 additions & 2 deletions src/Endpoints/class-base-api-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,20 @@ protected function get_data( WP_REST_Request $request, bool $require_api_secret
if ( false === $this->parsely->api_key_is_set() ) {
return (object) array(
'data' => array(),
'error' => new WP_Error( 400, __( 'A Parse.ly API Key must be set in site options to use this endpoint', 'wp-parsely' ) ),
'error' => new WP_Error(
'parsely_site_id_not_set',
__( 'A Parse.ly API Key must be set in site options to use this endpoint', 'wp-parsely' )
),
);
}

if ( true === $require_api_secret && false === $this->parsely->api_secret_is_set() ) {
return (object) array(
'data' => array(),
'error' => new WP_Error( 400, __( 'A Parse.ly API Secret must be set in site options to use this endpoint', 'wp-parsely' ) ),
'error' => new WP_Error(
'parsely_api_secret_not_set',
__( 'A Parse.ly API Secret must be set in site options to use this endpoint', 'wp-parsely' )
),
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Integrations/class-amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @since 2.6.0 Moved from Parsely class to this file.
*/
class Amp implements Integration {
class Amp extends Integration {
/**
* Applies the hooks that integrate the plugin or theme with the Parse.ly
* plugin.
Expand Down Expand Up @@ -53,7 +53,7 @@ public function is_amp_request(): bool {
* @return bool True is an AMP request and not disabled, false otherwise.
*/
public function can_handle_amp_request(): bool {
$options = get_option( Parsely::OPTIONS_KEY );
$options = self::$parsely->get_options();

return $this->is_amp_request() && is_array( $options ) && ! $options['disable_amp'];
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public function register_parsely_for_amp_native_analytics( ?array $analytics ):
$analytics = array();
}

$options = get_option( Parsely::OPTIONS_KEY );
$options = self::$parsely->get_options();

if ( isset( $options['disable_amp'] ) && true === $options['disable_amp'] ) {
return $analytics;
Expand Down Expand Up @@ -159,7 +159,7 @@ public static function construct_amp_json(): string {
* @return array<string, array<string, string>>
*/
public static function construct_amp_config(): array {
$options = get_option( Parsely::OPTIONS_KEY );
$options = self::$parsely->get_options();

if ( isset( $options['apikey'] ) && is_string( $options['apikey'] ) && '' !== $options['apikey'] ) {
return array(
Expand Down
2 changes: 1 addition & 1 deletion src/Integrations/class-facebook-instant-articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @since 2.6.0 Moved from Parsely class to this file.
*/
final class Facebook_Instant_Articles implements Integration {
final class Facebook_Instant_Articles extends Integration {
private const REGISTRY_IDENTIFIER = 'parsely-analytics-for-wordpress';
private const REGISTRY_DISPLAY_NAME = 'Parse.ly Analytics';

Expand Down
2 changes: 1 addition & 1 deletion src/Integrations/class-google-web-stories.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @since 3.2.0
*/
final class Google_Web_Stories implements Integration {
final class Google_Web_Stories extends Integration {
/**
* Applies the hooks that integrate the plugin or theme with the Parse.ly
* plugin.
Expand Down
27 changes: 23 additions & 4 deletions src/Integrations/class-integration.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Integrations: Integration interface
* Integrations: Abstract base class for all integration implementations
*
* @package Parsely
* @since 2.6.0
Expand All @@ -10,17 +10,36 @@

namespace Parsely\Integrations;

use Parsely\Parsely;

/**
* Integration classes are expected to implement this interface.
* Base class that all integrations should extend from.
*
* @since 2.6.0
* @since 3.5.2 Converted from interface to abstract class.
*/
interface Integration {
abstract class Integration {
/**
* Instance of Parsely class.
*
* @var Parsely
*/
protected static $parsely;

/**
* Constructor.
*
* @param Parsely $parsely Instance of Parsely class.
*/
public function __construct( Parsely $parsely ) {
self::$parsely = $parsely;
}

/**
* Applies the hooks that integrate the plugin or theme with the Parse.ly
* plugin.
*
* @since 2.6.0
*/
public function integrate(): void;
abstract public function integrate(): void;
}
20 changes: 19 additions & 1 deletion src/Integrations/class-integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace Parsely\Integrations;

use Parsely\Parsely;

/**
* Integrations are registered to this collection.
*
Expand All @@ -19,6 +21,22 @@
* @since 2.6.0
*/
class Integrations {
/**
* Instance of Parsely class.
*
* @var Parsely
*/
private $parsely;

/**
* Constructor.
*
* @param Parsely $parsely Instance of Parsely class.
*/
public function __construct( Parsely $parsely ) {
$this->parsely = $parsely;
}

/**
* Collection of registered integrations.
*
Expand All @@ -38,7 +56,7 @@ class Integrations {
public function register( string $key, $class_or_object ): void {
// If a Foo::class or other fully qualified class name is passed, instantiate it.
if ( ! is_object( $class_or_object ) ) {
$class_or_object = new $class_or_object();
$class_or_object = new $class_or_object( $this->parsely );
}
$this->integrations[ $key ] = $class_or_object;
}
Expand Down
18 changes: 15 additions & 3 deletions src/UI/class-recommended-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Parsely\UI;

use Parsely\Parsely;
use WP_Widget;

use const Parsely\PARSELY_FILE;
Expand All @@ -19,10 +20,19 @@
* Provides a widget with Parse.ly recommended articles.
*/
final class Recommended_Widget extends WP_Widget {
/**
* Instance of Parsely class.
*
* @var Parsely
*/
private $parsely;

/**
* Constructor.
*
* @param Parsely $parsely Instance of Parsely class.
*/
public function __construct() {
public function __construct( Parsely $parsely ) {
parent::__construct(
'Parsely_Recommended_Widget',
__( 'Parse.ly Recommended Widget', 'wp-parsely' ),
Expand All @@ -31,6 +41,8 @@ public function __construct() {
'description' => __( 'Display a list of post recommendations, personalized for a visitor or the current post.', 'wp-parsely' ),
)
);

$this->parsely = $parsely;
}

/**
Expand Down Expand Up @@ -97,7 +109,7 @@ public function widget( $args, $instance ): void {
echo wp_kses_post( $title_html );

// Set up the variables.
$options = get_option( 'parsely' );
$options = $this->parsely->get_options();
$api_url = $this->get_api_url(
$options['apikey'],
$instance['published_within'],
Expand Down Expand Up @@ -312,7 +324,7 @@ private function get_boost_params(): array {
* False otherwise.
*/
private function api_key_and_secret_are_populated(): bool {
$options = get_option( 'parsely' );
$options = $this->parsely->get_options();

// No options are saved, so API key is not available.
if ( ! is_array( $options ) ) {
Expand Down
56 changes: 51 additions & 5 deletions src/blocks/content-helper/components/post-list.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { Spinner } from '@wordpress/components';
import { useEffect, useState } from '@wordpress/element';

Expand All @@ -13,9 +14,12 @@ import { SuggestedPost } from '../models/suggested-post';

const FETCH_RETRIES = 3;

function PostList() {
/**
* List of the related top posts.
*/
function RelatedTopPostList() {
const [ loading, setLoading ] = useState<boolean>( true );
const [ error, setError ] = useState<string>( null );
const [ error, setError ] = useState( null );
const [ message, setMessage ] = useState<string>( null );
const [ posts, setPosts ] = useState<SuggestedPost[]>( [] );

Expand All @@ -27,7 +31,7 @@ function PostList() {
setMessage( result.message );
setLoading( false );
} )
.catch( async ( err: string ) => {
.catch( async ( err ) => {
if ( retries > 0 ) {
await new Promise( ( r ) => setTimeout( r, 500 ) );
await fetchPosts( retries - 1 );
Expand All @@ -42,10 +46,25 @@ function PostList() {
fetchPosts( FETCH_RETRIES );
}, [] );

// Show error message or contact message.
if ( error ) {
return <p>{ error }</p>;
// Errors that should be converted to a contact message.
if ( error?.errors?.parsely_site_id_not_set ||
error?.errors?.parsely_api_secret_not_set ) {
return ContactUsMessage();
}

// Error coming from apiFetch.
if ( error?.message ) {
return <p>{ __( 'Error:', 'wp-parsely' ) } { error.message }</p>;
}

// Error coming from the WordPress REST API.
const errorMessage = JSON.stringify( error ).match( /\[\"(.*?)\"\]/ )[ 1 ];
return <p>{ __( 'Error:', 'wp-parsely' ) } { errorMessage }</p>;
}

// Show related top posts list.
const postList = posts.map( ( post ) => <PostCard key={ post.id } post={ post } /> );
return (
<>
Expand All @@ -55,4 +74,31 @@ function PostList() {
);
}

export default PostList;
/**
* "Contact Us" component that we display in place of certain errors.
*/
function ContactUsMessage() {
return (
<>
<p>
{ /* eslint-disable-next-line react/jsx-no-target-blank */ }
<a href="https://www.parse.ly/contact" target="_blank" rel="noopener">
{ __( 'Contact us', 'wp-parsely' ) + ' ' }
</a>
{ __( 'about advanced plugin features and the Parse.ly dashboard.', 'wp-parsely' ) }
</p>
<p>
{ __(
'Existing Parse.ly customers can enable this feature by setting their Site ID and API Secret in',
'wp-parsely'
) + ' ' }
{ /* eslint-disable-next-line react/jsx-no-target-blank */ }
<a href="/wp-admin/options-general.php?page=parsely" target="_blank" rel="noopener">
{ __( 'wp-parsely options.', 'wp-parsely' ) }
</a>
</p>
</>
);
}

export default RelatedTopPostList;
Loading

0 comments on commit f6c00c9

Please sign in to comment.