Skip to content

Commit d5a1878

Browse files
authored
Merge pull request #446 from beyondwords-io/s-6203-fetch-button-for-inspect-panel
Fetch button for Block Editor inspect panel
2 parents 62a376f + 34d2928 commit d5a1878

File tree

20 files changed

+446
-104
lines changed

20 files changed

+446
-104
lines changed

.wp-env.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"core": "WordPress/WordPress#6.8",
2+
"core": null,
33
"phpVersion": "8.4",
44
"plugins": [
55
"./",

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"ergebnis/composer-normalize": "2.28.3",
1919
"php-parallel-lint/php-parallel-lint": "^1.3.2",
2020
"phpmd/phpmd": "^2.13",
21-
"phpro/grumphp": "^1.13",
21+
"phpro/grumphp": "^1.16",
2222
"phpunit/phpunit": "^9.6",
2323
"rregeer/phpunit-coverage-check": "^0.3.1",
2424
"squizlabs/php_codesniffer": "^3.7.2",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "beyondwords-wordpress-plugin",
3-
"version": "5.4.0",
3+
"version": "5.5.0",
44
"private": true,
55
"description": "BeyondWords WordPress Plugin",
66
"repository": {

readme.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Contributors: beyondwords, stuartmcalpine
44
Donate link: https://beyondwords.io
55
Tags: text-to-speech, tts, audio, AI, voice cloning
6-
Stable tag: 5.4.0
6+
Stable tag: 5.5.0
77
Requires PHP: 8.0
88
Tested up to: 6.8
99
License: GPLv2 or later
@@ -80,6 +80,21 @@ Any questions? [Visit our website](https://beyondwords.io/?utm_source=wordpress&
8080

8181
== Changelog ==
8282

83+
= 5.5.0 =
84+
85+
Release date: 2nd July 2025
86+
87+
**Enhancements and Features:**
88+
89+
* [#446](https://github.com/beyondwords-io/wordpress-plugin/pull/446) Fetch button for Block Editor Inspect panel.
90+
* We've added a Fetch option to the Inspect panel in the BeyondWords Block Editor sidebar.
91+
* This allows users to retrieve audio that has already been generated in BeyondWords, helping to quickly restore a missing or broken link between the audio and WordPress post, without needing to regenerate the audio.
92+
* Always show the **Generate audio** checkbox in the Block Editor.
93+
* As part of the Fetch button update the **Generate audio** checkbox is now always shown in the Block Editor.
94+
* If **Generate audio** is unchecked before a post is saved then audio **will not** be regenerated from the updated post content.
95+
* [#444](https://github.com/beyondwords-io/wordpress-plugin/pull/444) PHP 8.4 support.
96+
* Run unit and e2e tests against PHP 8.0 and PHP 8.4 in GitHub Actions.
97+
8398
= 5.4.0 =
8499

85100
Release date: 22nd April 2025

speechkit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Description: The effortless way to make content listenable. Automatically create audio versions and embed via our customizable player.
1616
* Author: BeyondWords
1717
* Author URI: https://beyondwords.io
18-
* Version: 5.4.0
18+
* Version: 5.5.0
1919
* License: GPL-2.0+
2020
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
2121
* Text Domain: speechkit
@@ -35,7 +35,7 @@
3535

3636
// Define constants
3737
// phpcs:disable
38-
define('BEYONDWORDS__PLUGIN_VERSION', '5.4.0');
38+
define('BEYONDWORDS__PLUGIN_VERSION', '5.5.0');
3939
define('BEYONDWORDS__PLUGIN_DIR', plugin_dir_path(__FILE__));
4040
define('BEYONDWORDS__PLUGIN_URI', plugin_dir_url(__FILE__));
4141
// phpcs:enable

src/Component/Plugin/Panel/DocumentSetting/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export default class DocumentSettingPanel extends Component {
2626
title={ __( 'BeyondWords', 'speechkit' ) }
2727
className="beyondwords-sidebar"
2828
>
29-
<GenerateAudio wrapper={ PanelRow } />
3029
<ErrorNotice wrapper={ PanelRow } />
3130
<PendingNotice wrapper={ PanelRow } />
3231
<PlayAudio wrapper={ PanelRow } />
32+
<GenerateAudio wrapper={ PanelRow } />
3333
<PlayerStyle wrapper={ PanelRow } />
3434
<PlayerContent wrapper={ PanelRow } />
3535
<SelectVoice wrapper={ PanelRow } />

src/Component/Post/GenerateAudio/check.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/Component/Post/GenerateAudio/index.js

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ import { compose } from '@wordpress/compose';
77
import { withDispatch, withSelect } from '@wordpress/data';
88
import { Fragment, useEffect } from '@wordpress/element';
99

10-
/**
11-
* Internal dependencies
12-
*/
13-
import GenerateAudioCheck from './check';
14-
1510
export function GenerateAudio( {
1611
generateAudio,
1712
generateAudioEdited,
@@ -28,19 +23,17 @@ export function GenerateAudio( {
2823
}, [ generateAudioEdited, generateAudio ] );
2924

3025
return (
31-
<GenerateAudioCheck>
32-
<Wrapper>
33-
<CheckboxControl
34-
className="beyondwords--generate-audio"
35-
label={ __( 'Generate audio', 'speechkit' ) }
36-
checked={ generateAudio }
37-
onChange={ () => {
38-
setGenerateAudio( ! generateAudio );
39-
} }
40-
__nextHasNoMarginBottom
41-
/>
42-
</Wrapper>
43-
</GenerateAudioCheck>
26+
<Wrapper>
27+
<CheckboxControl
28+
className="beyondwords--generate-audio"
29+
label={ __( 'Generate audio', 'speechkit' ) }
30+
checked={ generateAudio }
31+
onChange={ () => {
32+
setGenerateAudio( ! generateAudio );
33+
} }
34+
__nextHasNoMarginBottom
35+
/>
36+
</Wrapper>
4437
);
4538
}
4639

src/Component/Post/Panel/Inspect/Inspect.php

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use Beyondwords\Wordpress\Component\Post\PostMetaUtils;
1616
use Beyondwords\Wordpress\Component\Settings\SettingsUtils;
17+
use Beyondwords\Wordpress\Core\ApiClient;
1718

1819
/**
1920
* Inspect
@@ -28,7 +29,8 @@ class Inspect
2829
public function init()
2930
{
3031
add_action('admin_enqueue_scripts', array($this, 'adminEnqueueScripts'));
31-
add_action("add_meta_boxes", array($this, 'addMetaBox'));
32+
add_action('add_meta_boxes', array($this, 'addMetaBox'));
33+
add_action('rest_api_init', array($this, 'restApiInit'));
3234

3335
add_filter('default_hidden_meta_boxes', array($this, 'hideMetaBox'));
3436

@@ -311,4 +313,102 @@ public function save($postId)
311313

312314
return $postId;
313315
}
316+
317+
/**
318+
* REST API init.
319+
*
320+
* Register REST API routes.
321+
**/
322+
public function restApiInit()
323+
{
324+
register_rest_route('beyondwords/v1', '/projects/(?P<projectId>[0-9]+)/content/(?P<contentId>[a-zA-Z0-9\-]+)', array( // phpcs:ignore Generic.Files.LineLength.TooLong
325+
'methods' => \WP_REST_Server::READABLE,
326+
'callback' => array($this, 'restApiResponse'),
327+
'permission_callback' => function () {
328+
return current_user_can('edit_posts');
329+
},
330+
));
331+
}
332+
333+
/**
334+
* REST API response.
335+
*
336+
* Fetches a content object from the BeyondWords REST API.
337+
*
338+
* @param \WP_REST_Request $request The REST request object.
339+
*
340+
* @return \WP_REST_Response
341+
**/
342+
public function restApiResponse(\WP_REST_Request $request)
343+
{
344+
$projectId = $request['projectId'] ?? '';
345+
$contentId = $request['contentId'] ?? '';
346+
347+
if (! is_numeric($projectId)) {
348+
return rest_ensure_response(
349+
new \WP_Error(
350+
400,
351+
__('Invalid Project ID', 'speechkit'),
352+
['projectId' => $projectId]
353+
)
354+
);
355+
}
356+
357+
if (empty($contentId)) {
358+
return rest_ensure_response(
359+
new \WP_Error(
360+
400,
361+
__('Invalid Content ID', 'speechkit'),
362+
['contentId' => $contentId]
363+
)
364+
);
365+
}
366+
367+
$response = ApiClient::getContent($contentId, $projectId);
368+
369+
// Check for REST API connection errors.
370+
if (is_wp_error($response)) {
371+
return rest_ensure_response(
372+
new \WP_Error(
373+
500,
374+
__('Could not connect to BeyondWords API', 'speechkit'),
375+
$response->get_error_data()
376+
)
377+
);
378+
}
379+
380+
$code = wp_remote_retrieve_response_code($response);
381+
$body = wp_remote_retrieve_body($response);
382+
383+
// Check for REST API response errors.
384+
if ($code < 200 || $code >= 300) {
385+
return rest_ensure_response(
386+
new \WP_Error(
387+
$code,
388+
/* translators: %d is replaced with the error code. */
389+
sprintf(__('BeyondWords REST API returned error code %d', 'speechkit'), $code),
390+
[
391+
'body' => $body,
392+
]
393+
)
394+
);
395+
}
396+
397+
$data = json_decode($body, true);
398+
399+
// Check for REST API JSON response.
400+
if (! is_array($data)) {
401+
return rest_ensure_response(
402+
new \WP_Error(
403+
500,
404+
__('Invalid response from BeyondWords API', 'speechkit')
405+
)
406+
);
407+
}
408+
409+
// Return the project ID in the response.
410+
$data['project_id'] = $projectId;
411+
412+
return rest_ensure_response($data);
413+
}
314414
}

0 commit comments

Comments
 (0)