Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ You can even leverage your listenership through audio advertising. Use our self-

= 6.0.1 =

Release date: 25th November 2025
Release date: 26th November 2025

**Fixes**

* [#464](https://github.com/beyondwords-io/wordpress-plugin/pull/464) Use `CoreUtils::getPostMetaKeys` to get all keys for removal.
* [#461](https://github.com/beyondwords-io/wordpress-plugin/pull/461) Accept `null` params from WP Core for `isProtectedMeta`.
* [#460](https://github.com/beyondwords-io/wordpress-plugin/pull/460) Accept a `null` parameter in `getLangCodeFromJsonIfEmpty`.

Expand Down
41 changes: 8 additions & 33 deletions src/Component/Post/PostMetaUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,42 +96,17 @@ public static function getAllBeyondwordsMetadata(int $postId): array

/**
* Remove the BeyondWords metadata for a Post.
*
* @param int $postId Post ID.
*
* @since 4.x Introduced.
* @since 6.0.1 Use CoreUtils::getPostMetaKeys() to get all keys.
*/
public static function removeAllBeyondwordsMetadata(int $postId): void
{
$keysToCheck = [
'beyondwords_generate_audio',
'beyondwords_project_id',
'beyondwords_content_id',
'beyondwords_podcast_id',
'beyondwords_preview_token',
'beyondwords_player_content',
'beyondwords_player_style',
'beyondwords_language_code',
'beyondwords_language_id',
'beyondwords_body_voice_id',
'beyondwords_title_voice_id',
'beyondwords_summary_voice_id',
'beyondwords_error_message',
'beyondwords_disabled',
'beyondwords_delete_content',
'publish_post_to_speechkit',
'speechkit_generate_audio',
'speechkit_project_id',
'speechkit_podcast_id',
'speechkit_error_message',
'speechkit_disabled',
'speechkit_access_key',
'speechkit_error',
'speechkit_info',
'speechkit_response',
'speechkit_retries',
'speechkit_status',
'_speechkit_link',
'_speechkit_text',
];

foreach ($keysToCheck as $key) {
$keys = CoreUtils::getPostMetaKeys('all');

foreach ($keys as $key) {
delete_post_meta($postId, $key, null);
}
}
Expand Down
56 changes: 56 additions & 0 deletions tests/phpunit/Core/PostMetaUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use Beyondwords\Wordpress\Component\Post\PostMetaUtils;
use Beyondwords\Wordpress\Core\CoreUtils;

class PostMetaUtilsTest extends TestCase
{
Expand Down Expand Up @@ -278,4 +279,59 @@ public function hasGenerateAudioProvider()
'speechkit_generate_audio is "1"' => [true, ['post_title' => 'UtilsTest:hasGenerateAudio', 'meta_input' => ['speechkit_generate_audio' => '1']]],
];
}

/**
* Test removeAllBeyondwordsMetadata removes all BeyondWords keys
* without affecting other post meta.
*
* @since 6.0.1
*
* @test
*/
public function removeAllBeyondwordsMetadata()
{
$postId = self::factory()->post->create([
'post_title' => 'PostMetaUtilsTest:removeAllBeyondwordsMetadata',
]);

// Set all BeyondWords meta keys
$beyondwordsKeys = CoreUtils::getPostMetaKeys('all');

foreach ($beyondwordsKeys as $key) {
update_post_meta($postId, $key, 'test_value');
}

// Set a non-BeyondWords meta key that should NOT be removed
$customKey = 'my_custom_meta_key';
update_post_meta($postId, $customKey, 'custom_value');

// Verify all keys are set
foreach ($beyondwordsKeys as $key) {
$this->assertNotEmpty(
get_post_meta($postId, $key, true),
"Expected $key to be set before removal"
);
}
$this->assertEquals('custom_value', get_post_meta($postId, $customKey, true));

// Remove all BeyondWords metadata
PostMetaUtils::removeAllBeyondwordsMetadata($postId);

// Verify all BeyondWords keys are removed
foreach ($beyondwordsKeys as $key) {
$this->assertEmpty(
get_post_meta($postId, $key, true),
"Expected $key to be removed"
);
}

// Verify non-BeyondWords key is still present
$this->assertEquals(
'custom_value',
get_post_meta($postId, $customKey, true),
'Expected custom meta key to remain after removal'
);

wp_delete_post($postId, true);
}
}
Loading