Skip to content

Commit 6ba7f27

Browse files
authored
Merge pull request #449 from beyondwords-io/s-7095-scope-out-integrating-the-magic-embed-script-into-wordpress
Magic Embed for WordPress
2 parents c5ac8bf + 5048237 commit 6ba7f27

File tree

69 files changed

+2161
-2837
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2161
-2837
lines changed

.mockoon/beyondwords-api.json

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,6 @@
119119
"filePath": "",
120120
"sendFileAsBody": false,
121121
"rules": [
122-
{
123-
"target": "header",
124-
"modifier": "Content-Type",
125-
"value": "application/json",
126-
"operator": "equals",
127-
"invert": false
128-
},
129122
{
130123
"target": "header",
131124
"modifier": "X-Api-Key",
@@ -276,7 +269,7 @@
276269
},
277270
{
278271
"uuid": "ecdb7657-8a38-4380-937e-54204529d2e5",
279-
"body": "{\n \"id\": \"9279c9e0-e0b5-4789-9040-f44478ed3e9e\",\n \"title\": \"{{body 'title' 'Title'}}\",\n \"type\": \"auto_segment\",\n \"source_id\": \"{{body 'source_id' '90e4cbff-6382-4a88-adc5-1eb3ffa16c6d'}}\",\n \"source_url\": \"{{body 'source_url' 'https://example.com'}}\",\n \"author\": \"{{body 'author' 'Jane Smith'}}\",\n \"image_url\": \"{{body 'image' 'https://example.com/image.jpg'}}\",\n \"audio\": [\n {\n \"id\": 12192819,\n \"content_type\": \"application/x-mpegURL\",\n \"url\": \"https://beyondwords-cdn-b7fyckdeejejb6dj.a03.azurefd.net/audio/projects/9969/podcasts/3161419/media/e8219ee2f3465d6834984f9ae607a81e.m3u8\",\n \"duration\": 2685,\n \"base64_file\": null,\n \"variant\": \"article\"\n },\n {\n \"id\": 12192811,\n \"content_type\": \"audio/mpeg\",\n \"url\": \"https://beyondwords-cdn-b7fyckdeejejb6dj.a03.azurefd.net/audio/projects/9969/podcasts/3161419/media/fd7108e13a7c7fee6820a1b07bb676e0_compiled.mp3\",\n \"duration\": 2712,\n \"base64_file\": null,\n \"variant\": \"article\"\n }\n ],\n \"video\": [],\n \"ads_enabled\": true,\n \"is_copy\": false,\n \"title_voice_id\": 2517,\n \"summary_voice_id\": 2517,\n \"body_voice_id\": 2517,\n \"title_enabled\": true,\n \"body_enabled\": true,\n \"summary_enabled\": true,\n \"summary_title_enabled\": false,\n \"summarization\": {\n \"audio\": [],\n \"video\": []\n },\n \"background_track\": null,\n \"language\": \"{{body 'language' 'en_US'}}\",\n \"preview_token\": \"d9ce36ea-ddc4-4611-b60c-4f90ed0fc082\",\n \"status\": \"processed\",\n \"metadata\": {\n \"categories\": [\n \"News\", \n \"Audio\"\n ]\n },\n \"created\": \"2022-01-02T23:59:59Z\",\n \"updated\": \"2022-03-04T00:00:00Z\",\n \"published\": true,\n \"publish_date\": \"2099-12-31T23:59:59Z\",\n \"auto_segment_updates_enabled\": false,\n \"ai_summary_updates_enabled\": true,\n \"summary\": \"{{body 'summary' 'Summary'}}\",\n \"body\": \"<p>Test.</p>\",\n \"summarization_settings\": null,\n \"video_settings\": null\n}",
272+
"body": "{\n \"id\": \"9279c9e0-e0b5-4789-9040-f44478ed3e9e\",\n \"title\": \"{{body 'title' 'Title'}}\",\n \"type\": \"auto_segment\",\n \"source_id\": \"{{body 'source_id' '90e4cbff-6382-4a88-adc5-1eb3ffa16c6d'}}\",\n \"source_url\": \"{{body 'source_url' 'https://example.com'}}\",\n \"author\": \"{{body 'author' 'Jane Smith'}}\",\n \"image_url\": \"{{body 'image' 'https://example.com/image.jpg'}}\",\n \"audio\": [\n {\n \"id\": 12192819,\n \"content_type\": \"application/x-mpegURL\",\n \"url\": \"https://beyondwords-cdn-b7fyckdeejejb6dj.a03.azurefd.net/audio/projects/9969/podcasts/3161419/media/e8219ee2f3465d6834984f9ae607a81e.m3u8\",\n \"duration\": 2685,\n \"base64_file\": null,\n \"variant\": \"article\"\n },\n {\n \"id\": 12192811,\n \"content_type\": \"audio/mpeg\",\n \"url\": \"https://beyondwords-cdn-b7fyckdeejejb6dj.a03.azurefd.net/audio/projects/9969/podcasts/3161419/media/fd7108e13a7c7fee6820a1b07bb676e0_compiled.mp3\",\n \"duration\": 2712,\n \"base64_file\": null,\n \"variant\": \"article\"\n }\n ],\n \"video\": [],\n \"ads_enabled\": true,\n \"is_copy\": false,\n \"title_voice_id\": 2517,\n \"summary_voice_id\": 2517,\n \"body_voice_id\": 2517,\n \"title_enabled\": true,\n \"body_enabled\": true,\n \"summary_enabled\": true,\n \"summary_title_enabled\": false,\n \"summarization\": {\n \"audio\": [],\n \"video\": []\n },\n \"background_track\": null,\n \"language\": \"{{body 'language' 'en_US'}}\",\n \"preview_token\": \"d9ce36ea-ddc4-4611-b60c-4f90ed0fc082\",\n \"status\": \"processed\",\n \"metadata\": {\n \"categories\": [\n \"News\", \n \"Audio\"\n ]\n },\n \"created\": \"2022-01-02T23:59:59Z\",\n \"updated\": \"2022-03-04T00:00:00Z\",\n \"published\": true,\n \"publish_date\": \"2099-12-31T23:59:59Z\",\n \"auto_segment_updates_enabled\": true,\n \"ai_summary_updates_enabled\": true,\n \"summary\": \"{{body 'summary' 'Summary'}}\",\n \"body\": \"<p>Test.</p>\",\n \"summarization_settings\": null,\n \"video_settings\": null\n}",
280273
"latency": 0,
281274
"statusCode": 200,
282275
"label": "OK",
@@ -414,7 +407,7 @@
414407
},
415408
{
416409
"uuid": "52762211-f2da-4e53-a68f-74883e69e862",
417-
"body": "{\n \"id\": \"9279c9e0-e0b5-4789-9040-f44478ed3e9e\",\n \"title\": \"{{body 'title' 'Title'}}\",\n \"type\": \"auto_segment\",\n \"source_id\": \"{{body 'source_id' '90e4cbff-6382-4a88-adc5-1eb3ffa16c6d'}}\",\n \"source_url\": \"{{body 'source_url' 'https://example.com'}}\",\n \"author\": \"{{body 'author' 'Jane Smith'}}\",\n \"image_url\": \"{{body 'image' 'https://example.com/image.jpg'}}\",\n \"audio\": [\n {\n \"id\": 12192819,\n \"content_type\": \"application/x-mpegURL\",\n \"url\": \"https://beyondwords-cdn-b7fyckdeejejb6dj.a03.azurefd.net/audio/projects/9969/podcasts/3161419/media/e8219ee2f3465d6834984f9ae607a81e.m3u8\",\n \"duration\": 2685,\n \"base64_file\": null,\n \"variant\": \"article\"\n },\n {\n \"id\": 12192811,\n \"content_type\": \"audio/mpeg\",\n \"url\": \"https://beyondwords-cdn-b7fyckdeejejb6dj.a03.azurefd.net/audio/projects/9969/podcasts/3161419/media/fd7108e13a7c7fee6820a1b07bb676e0_compiled.mp3\",\n \"duration\": 2712,\n \"base64_file\": null,\n \"variant\": \"article\"\n }\n ],\n \"video\": [],\n \"ads_enabled\": true,\n \"is_copy\": false,\n \"title_voice_id\": 2517,\n \"summary_voice_id\": 2517,\n \"body_voice_id\": 2517,\n \"title_enabled\": true,\n \"body_enabled\": true,\n \"summary_enabled\": true,\n \"summary_title_enabled\": false,\n \"summarization\": {\n \"audio\": [],\n \"video\": []\n },\n \"background_track\": null,\n \"language\": \"{{body 'language' 'en_US'}}\",\n \"preview_token\": \"d9ce36ea-ddc4-4611-b60c-4f90ed0fc082\",\n \"status\": \"processed\",\n \"metadata\": {\n \"categories\": [\n \"News\", \n \"Audio\"\n ]\n },\n \"created\": \"2022-01-02T23:59:59Z\",\n \"updated\": \"2022-03-04T00:00:00Z\",\n \"published\": true,\n \"publish_date\": \"2099-12-31T23:59:59Z\",\n \"auto_segment_updates_enabled\": false,\n \"ai_summary_updates_enabled\": true,\n \"summary\": \"{{body 'summary' 'Summary'}}\",\n \"body\": \"<p>Test.</p>\",\n \"summarization_settings\": null,\n \"video_settings\": null\n}",
410+
"body": "{\n \"id\": \"9279c9e0-e0b5-4789-9040-f44478ed3e9e\",\n \"title\": \"{{body 'title' 'Title'}}\",\n \"type\": \"auto_segment\",\n \"source_id\": \"{{body 'source_id' '90e4cbff-6382-4a88-adc5-1eb3ffa16c6d'}}\",\n \"source_url\": \"{{body 'source_url' 'https://example.com'}}\",\n \"author\": \"{{body 'author' 'Jane Smith'}}\",\n \"image_url\": \"{{body 'image' 'https://example.com/image.jpg'}}\",\n \"audio\": [\n {\n \"id\": 12192819,\n \"content_type\": \"application/x-mpegURL\",\n \"url\": \"https://beyondwords-cdn-b7fyckdeejejb6dj.a03.azurefd.net/audio/projects/9969/podcasts/3161419/media/e8219ee2f3465d6834984f9ae607a81e.m3u8\",\n \"duration\": 2685,\n \"base64_file\": null,\n \"variant\": \"article\"\n },\n {\n \"id\": 12192811,\n \"content_type\": \"audio/mpeg\",\n \"url\": \"https://beyondwords-cdn-b7fyckdeejejb6dj.a03.azurefd.net/audio/projects/9969/podcasts/3161419/media/fd7108e13a7c7fee6820a1b07bb676e0_compiled.mp3\",\n \"duration\": 2712,\n \"base64_file\": null,\n \"variant\": \"article\"\n }\n ],\n \"video\": [],\n \"ads_enabled\": true,\n \"is_copy\": false,\n \"title_voice_id\": 2517,\n \"summary_voice_id\": 2517,\n \"body_voice_id\": 2517,\n \"title_enabled\": true,\n \"body_enabled\": true,\n \"summary_enabled\": true,\n \"summary_title_enabled\": false,\n \"summarization\": {\n \"audio\": [],\n \"video\": []\n },\n \"background_track\": null,\n \"language\": \"{{body 'language' 'en_US'}}\",\n \"preview_token\": \"d9ce36ea-ddc4-4611-b60c-4f90ed0fc082\",\n \"status\": \"processed\",\n \"metadata\": {\n \"categories\": [\n \"News\", \n \"Audio\"\n ]\n },\n \"created\": \"2022-01-02T23:59:59Z\",\n \"updated\": \"2022-03-04T00:00:00Z\",\n \"published\": true,\n \"publish_date\": \"2099-12-31T23:59:59Z\",\n \"auto_segment_updates_enabled\": true,\n \"ai_summary_updates_enabled\": true,\n \"summary\": \"{{body 'summary' 'Summary'}}\",\n \"body\": \"<p>Test.</p>\",\n \"summarization_settings\": null,\n \"video_settings\": null\n}",
418411
"latency": 0,
419412
"statusCode": 200,
420413
"label": "OK",
@@ -720,13 +713,6 @@
720713
"filePath": "",
721714
"sendFileAsBody": false,
722715
"rules": [
723-
{
724-
"target": "header",
725-
"modifier": "Content-Type",
726-
"value": "application/json",
727-
"operator": "equals",
728-
"invert": false
729-
},
730716
{
731717
"target": "header",
732718
"modifier": "X-Api-Key",
@@ -962,13 +948,6 @@
962948
"filePath": "",
963949
"sendFileAsBody": false,
964950
"rules": [
965-
{
966-
"target": "header",
967-
"modifier": "Content-Type",
968-
"value": "application/json",
969-
"operator": "equals",
970-
"invert": false
971-
},
972951
{
973952
"target": "header",
974953
"modifier": "X-Api-Key",

doc/wp-config.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,3 @@ Defaults to `true`.
2020
```php
2121
define('BEYONDWORDS_AUTOREGENERATE', false);
2222
```
23-
24-
## BEYONDWORDS_PLAYER_INLINE_SCRIPT_TAG
25-
26-
Use the recommended BeyondWords inline player script.
27-
Defaults to `false`.
28-
From plugin version `6.0` this will default to `true`.
29-
30-
```php
31-
define('BEYONDWORDS_PLAYER_INLINE_SCRIPT_TAG', true);
32-
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@wordpress/eslint-plugin": "^22.5.1",
1818
"@wordpress/scripts": "^30.12.1",
1919
"badge-maker": "^4.1.0",
20-
"cypress": "14.3.3",
20+
"cypress": "15.1.0",
2121
"cypress-fail-fast": "^7.1.1",
2222
"cypress-map": "^1.45.0",
2323
"cypress-multi-reporters": "^2.0.5",

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ Release date: TBC
8686

8787
**Enhancements and Features:**
8888

89-
* Make PHP methods static.
89+
* [#449](https://github.com/beyondwords-io/wordpress-plugin/pull/449) Magic Embed for WordPress.
90+
* An **Integration method** plugin setting has been added in the *Content* tab.
91+
* The default is **REST API**. This method will continue to send post content and metadata to BeyondWords using REST API calls.
92+
* If **Magic Embed** is selected then [Client-Side Integration](https://github.com/beyondwords-io/player/blob/main/doc/client-side-integration.md) will be enabed for new posts. With this method BeyondWords handles the extraction and delivery of audio content using the rendered HTML for the post.
93+
* [#447](https://github.com/beyondwords-io/wordpress-plugin/pull/447) Make PHP methods static.
9094

9195
= 5.5.0 =
9296

src/Compatibility/WPGraphQL/WPGraphQL.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ public static function init()
3434
* @since 3.6.0
3535
* @since 4.0.0 Register contentId field, and contentId/podcastId are now String, not Int
3636
* @since 4.7.0 Moved graphqlRegisterTypes() from Beyondwords\Wordpress\Core to here.
37-
* @since 6.0.0 Make static.
37+
* @since 6.0.0 Make static, add sourceId field.
3838
*/
3939
public static function graphqlRegisterTypes()
4040
{
4141
register_graphql_object_type('Beyondwords', [
4242
'description' => __('BeyondWords audio details. Use this data to embed an audio player using the BeyondWords JavaScript SDK.', 'speechkit'), // phpcs:ignore Generic.Files.LineLength.TooLong
4343
'fields' => [
44+
'sourceId' => [
45+
'description' => __('BeyondWords source ID', 'speechkit'),
46+
'type' => 'String'
47+
],
4448
'projectId' => [
4549
'description' => __('BeyondWords project ID', 'speechkit'),
4650
'type' => 'Int'
@@ -70,22 +74,24 @@ public static function graphqlRegisterTypes()
7074
'type' => 'Beyondwords',
7175
'description' => __('BeyondWords audio details', 'speechkit'),
7276
'resolve' => function (WPGraphQLPlugin\Model\Post $post) {
73-
$beyondwords = [];
77+
$fields = [
78+
'sourceId' => (string) $post->ID,
79+
];
7480

75-
$contentId = PostMetaUtils::getContentId($post->ID);
81+
$projectId = PostMetaUtils::getProjectId($post->ID);
7682

77-
if (! empty($contentId)) {
78-
$beyondwords['contentId'] = $contentId;
79-
$beyondwords['podcastId'] = $contentId; // legacy
83+
if (! empty($projectId)) {
84+
$fields['projectId'] = $projectId;
8085
}
8186

82-
$projectId = PostMetaUtils::getProjectId($post->ID);
87+
$contentId = PostMetaUtils::getContentId($post->ID);
8388

84-
if (! empty($projectId)) {
85-
$beyondwords['projectId'] = $projectId;
89+
if (! empty($contentId)) {
90+
$fields['contentId'] = $contentId;
91+
$fields['podcastId'] = $contentId; // legacy
8692
}
8793

88-
return ! empty($beyondwords) ? $beyondwords : null;
94+
return $fields;
8995
}
9096
]);
9197
}

src/Component/Post/BlockAttributes/BlockAttributes.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static function registerMarkerAttribute($args)
9090
*
9191
* @since 4.0.0
9292
* @since 4.2.2 Rename method to renderBlock.
93-
* @since 6.0.0 Make static.
93+
* @since 6.0.0 Make static and update for Magic Embed.
9494
*
9595
* @param string $blockContent The block content (HTML).
9696
* @param string $block The full block, including name and attributes.
@@ -100,12 +100,12 @@ public static function registerMarkerAttribute($args)
100100
public static function renderBlock($blockContent, $block)
101101
{
102102
// Skip adding marker if player UI is disabled
103-
if (get_option('beyondwords_player_ui', PlayerUI::ENABLED) === PlayerUI::DISABLED) {
103+
if (get_option(PlayerUI::OPTION_NAME) === PlayerUI::DISABLED) {
104104
return $blockContent;
105105
}
106106

107-
// Skip adding marker if no content ID exists
108-
if (! PostMetaUtils::getContentId(get_the_ID())) {
107+
// Skip adding marker if no content exists
108+
if (! PostMetaUtils::hasContent(get_the_ID())) {
109109
return $blockContent;
110110
}
111111

src/Component/Post/DisplayPlayer/DisplayPlayer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static function save($postId)
7979
*
8080
* @since 6.0.0 Make static.
8181
*
82-
* @param WP_Post $post The post object.
82+
* @param \WP_Post $post The post object.
8383
*/
8484
public static function element($post)
8585
{

src/Component/Post/GenerateAudio/GenerateAudio.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public static function init()
4444
/**
4545
* Check whether the post type should preselect the "Generate audio" checkbox.
4646
*
47+
* @param \WP_Post|int $post The post object or ID.
48+
*
4749
* @todo move this function to somewhere reusable for the Block editor.
4850
*
4951
* @since 6.0.0 Make static.
@@ -73,22 +75,13 @@ public static function shouldPreselectGenerateAudio($post)
7375
/**
7476
* Render the element.
7577
*
76-
* @since 6.0.0 Make static.
78+
* @since 6.0.0 Make static and refactor generate audio check.
7779
*/
7880
public static function element($post)
7981
{
8082
wp_nonce_field('beyondwords_generate_audio', 'beyondwords_generate_audio_nonce');
8183

8284
$generateAudio = PostMetaUtils::hasGenerateAudio($post->ID);
83-
84-
if (! $generateAudio) {
85-
// Check whether "0" has explicitly been saved
86-
$generateAudioMeta = PostMetaUtils::getRenamedPostMeta($post->ID, 'generate_audio', true);
87-
88-
if ($generateAudioMeta !== '0' && self::shouldPreselectGenerateAudio($post)) {
89-
$generateAudio = true;
90-
}
91-
}
9285
?>
9386
<!-- checkbox -->
9487
<p id="beyondwords-metabox-generate-audio">

src/Component/Post/GenerateAudio/index.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,13 @@ export default compose( [
7373
beyondwords_generate_audio,
7474
/* eslint-disable-next-line camelcase */
7575
speechkit_generate_audio,
76-
/* eslint-disable-next-line camelcase */
77-
publish_post_to_speechkit,
7876
} = getCurrentPostAttribute( 'meta' );
7977

8078
if (
8179
/* eslint-disable-next-line camelcase */
8280
beyondwords_generate_audio === '1' ||
8381
/* eslint-disable-next-line camelcase */
84-
speechkit_generate_audio === '1' ||
85-
/* eslint-disable-next-line camelcase */
86-
publish_post_to_speechkit === '1'
82+
speechkit_generate_audio === '1'
8783
) {
8884
return true;
8985
}
@@ -92,9 +88,7 @@ export default compose( [
9288
/* eslint-disable-next-line camelcase */
9389
beyondwords_generate_audio === '0' ||
9490
/* eslint-disable-next-line camelcase */
95-
speechkit_generate_audio === '0' ||
96-
/* eslint-disable-next-line camelcase */
97-
publish_post_to_speechkit === '0'
91+
speechkit_generate_audio === '0'
9892
) {
9993
return false;
10094
}

0 commit comments

Comments
 (0)