Skip to content

Commit

Permalink
Merge branch 'release/8.0.13'
Browse files Browse the repository at this point in the history
  • Loading branch information
BracketSpaceWorker committed Oct 26, 2022
2 parents c7065b7 + 27bb47f commit 8fc4425
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 21 deletions.
2 changes: 1 addition & 1 deletion notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Description: Customisable email and webhook notifications with powerful developer friendly API for custom triggers and notifications. Send alerts easily.
* Author: BracketSpace
* Author URI: https://bracketspace.com
* Version: 8.0.12
* Version: 8.0.13
* License: GPL3
* Text Domain: notification
* Domain Path: /languages
Expand Down
18 changes: 12 additions & 6 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: notification, bracketspace, Kubitomakita, tomaszadamowicz, insejn,
Tags: notification, notify, alert, email, mail, webhook, API, developer, framework
Requires at least: 4.9
Tested up to: 5.8
Stable tag: 8.0.12
Stable tag: 8.0.13
Requires PHP: 7.0
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Expand Down Expand Up @@ -302,13 +302,19 @@ Yes! We're offering a [custom plugin development](https://bracketspace.com/custo

== Changelog ==

= 8.0.13 =

* [Fixed] Regression with REST API check.
* [Changed] `repeater_api` internal runtime component to `api`.
* [Added] `get_endpoint` method to the API class.

= 8.0.12 =

* [Changed] Logic of assigning property name is moved to Abstract Merge Tag Class
* [Added] Property names to Term Merge Tags
* [Added] 6h cache expire to the user queries
* [Added] Email / Merge tag recipient now can also be separated with semicolon
* [Added] Endpoint to check whether the REST api is enabled
* [Changed] Logic of assigning property name is moved to Abstract Merge Tag Class.
* [Added] Property names to Term Merge Tags.
* [Added] 6h cache expire to the user queries.
* [Added] Email / Merge tag recipient now can also be separated with semicolon.
* [Added] Endpoint to check whether the REST api is enabled.

= 8.0.11 =

Expand Down
32 changes: 19 additions & 13 deletions src/Admin/CheckRestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,31 @@ class CheckRestApi {
* @return void
*/
public function test_rest_api() {
$response = wp_remote_get( get_rest_url( null, 'notification/v1/check/' ) );
$message = json_decode( wp_remote_retrieve_body( $response ), true );

$is_available = false;
$is_edit = false;

if ( array_key_exists( 'data', $message ) ) {
$is_available = 'RestApi' === $message['data'];
}

$is_edit = false;
$current_screen = get_current_screen();

if ( $current_screen instanceof \WP_Screen ) {
$is_edit = 'post' === $current_screen->base && 'notification' === $current_screen->post_type;
}

if ( ! $is_available && $is_edit ) {
$class = 'notice notice-error';
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), 'The Notification plugin requires enabled REST API endpoint: notification/v1/. Please ensure your WP REST API works correctly.' );
if ( ! $is_edit ) {
return;
}

$response = wp_remote_get( get_rest_url(
null,
\Notification::component( 'api' )->get_endpoint( 'check' )
) );

$message = json_decode( wp_remote_retrieve_body( $response ), true );

$is_available = false;

if ( ! is_array( $message ) || ! array_key_exists( 'data', $message ) || 'RestApi' !== $message['data'] ) {
printf(
'<div class="notice notice-error"><p>%1$s</p></div>',
'The Notification plugin requires enabled REST API endpoint: notification/v1/. Please ensure your WP REST API works correctly.'
);
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,21 @@ public function rest_api_init() {
}

}

/**
* Gets API endpoint
*
* @since 8.0.13
* @param string $endpoint Endopint name.
* @return string
*/
public function get_endpoint( $endpoint ) {

return sprintf(
'%s/%s/',
$this->namespace,
untrailingslashit( $endpoint )
);

}
}
2 changes: 1 addition & 1 deletion src/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function singletons() {
$this->add_component( 'integration_wp_emails', new Integration\WordPressEmails() );
$this->add_component( 'integration_2fa', new Integration\TwoFactor() );

$this->add_component( 'repeater_api', new Api\Api() );
$this->add_component( 'api', new Api\Api() );
}

/**
Expand Down

0 comments on commit 8fc4425

Please sign in to comment.