Skip to content

Commit

Permalink
Merge pull request #2735 from Parsely/refactor/internal-api-settings
Browse files Browse the repository at this point in the history
REST API Refactor: Settings namespace implementation
  • Loading branch information
acicovic authored Sep 6, 2024
2 parents 8380fc2 + d68ad09 commit b2eb9bb
Show file tree
Hide file tree
Showing 28 changed files with 974 additions and 1,397 deletions.
2 changes: 1 addition & 1 deletion build/content-helper/dashboard-widget.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-element', 'wp-i18n', 'wp-url'), 'version' => 'd852566173ef137708b0');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => 'b654f2e02d29a1665104');
2 changes: 1 addition & 1 deletion build/content-helper/dashboard-widget.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/content-helper/editor-sidebar.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => 'eaad1ca5764f3fbdb9e6');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => '7d87b64bdabeaf1dc579');
6 changes: 3 additions & 3 deletions build/content-helper/editor-sidebar.js

Large diffs are not rendered by default.

281 changes: 0 additions & 281 deletions src/Endpoints/class-base-api-proxy.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Parsely\RemoteAPI\ContentSuggestions;

use Parsely\Endpoints\Base_Endpoint;
use Parsely\Parsely;
use Parsely\RemoteAPI\Base_Endpoint_Remote;
use UnexpectedValueException;
Expand Down Expand Up @@ -61,7 +60,7 @@ public function is_available_to_current_user( $request = null ): bool {
return current_user_can(
// phpcs:ignore WordPress.WP.Capabilities.Undetermined
$this->apply_capability_filters(
Base_Endpoint::DEFAULT_ACCESS_CAPABILITY
self::DEFAULT_ACCESS_CAPABILITY
)
);
}
Expand Down
8 changes: 5 additions & 3 deletions src/content-helper/common/class-content-helper-feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,17 @@ protected function inject_inline_scripts(
$settings = rest_do_request(
new WP_REST_Request(
'GET',
'/wp-parsely/v1' . $settings_route
'/wp-parsely/v2/settings/' . $settings_route
)
)->get_data();
}

if ( ! is_string( $settings ) ) {
$settings = '';
if ( ! is_array( $settings ) ) {
$settings = array();
}

$settings = wp_json_encode( $settings );

wp_add_inline_script(
static::get_script_id(),
"window.wpParselyContentHelperSettings = '$settings';",
Expand Down
3 changes: 2 additions & 1 deletion src/content-helper/common/settings/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type ReactDeps = React.DependencyList | undefined;
*
* @since 3.13.0
* @since 3.14.0 Moved from `content-helper/common/hooks/useSaveSettings.ts`.
* @since 3.17.0 Updated to the new API endpoints.
*
* @param {string} endpoint The settings endpoint to send the data to.
* @param {Settings} data The data to send.
Expand All @@ -96,7 +97,7 @@ const useSaveSettings = (
}

apiFetch( {
path: '/wp-parsely/v1/user-meta/content-helper/' + endpoint,
path: '/wp-parsely/v2/settings/' + endpoint,
method: 'PUT',
data,
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Parsely\Content_Helper;

use Parsely\Endpoints\User_Meta\Dashboard_Widget_Settings_Endpoint;
use Parsely\Parsely;
use Parsely\RemoteAPI\Analytics_Posts_API;

Expand Down Expand Up @@ -136,7 +135,7 @@ public function enqueue_assets(): void {
true
);

$this->inject_inline_scripts( Dashboard_Widget_Settings_Endpoint::get_route() );
$this->inject_inline_scripts( 'dashboard-widget' );

wp_enqueue_style(
static::get_style_id(),
Expand Down
2 changes: 1 addition & 1 deletion src/content-helper/dashboard-widget/dashboard-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ window.addEventListener(
if ( null !== container ) {
const component =
<SettingsProvider
endpoint="dashboard-widget-settings"
endpoint="dashboard-widget"
defaultSettings={ getSettingsFromJson( window.wpParselyContentHelperSettings ) }
>
<VerifyCredentials>
Expand Down
4 changes: 1 addition & 3 deletions src/content-helper/editor-sidebar/class-editor-sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

use Parsely\Content_Helper\Editor_Sidebar\Smart_Linking;
use Parsely\Dashboard_Link;
use Parsely\Endpoints\User_Meta\Editor_Sidebar_Settings_Endpoint;
use Parsely\Parsely;
use Parsely\Content_Helper\Content_Helper_Feature;

use Parsely\Utils\Utils;
use WP_Post;
Expand Down Expand Up @@ -163,7 +161,7 @@ public function run(): void {
true
);

$this->inject_inline_scripts( Editor_Sidebar_Settings_Endpoint::get_route() );
$this->inject_inline_scripts( 'editor-sidebar' );

// Inject inline variables for the editor sidebar, without UTM parameters.
$parsely_post_url = $this->get_parsely_post_url( null, false );
Expand Down
Loading

0 comments on commit b2eb9bb

Please sign in to comment.