Skip to content

Commit 47ddc01

Browse files
Alexia-Soareclaude
andcommitted
fix: Bluesky link card repeats the post caption as the embed description
Leave the external embed description empty instead of copying the post content already sent as the record text. Applies to both link posts and image posts that carry a URL. Fixes Codeinwp/tweet-old-post-pro#676 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 4f5e647 commit 47ddc01

3 files changed

Lines changed: 82 additions & 1 deletion

File tree

includes/admin/helpers/class-rop-bluesky-api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ private function get_external_post_url( $post ) {
504504
'external' => array(
505505
'uri' => $post['post_url'],
506506
'title' => isset( $post['title'] ) ? $post['title'] : '',
507-
'description' => isset( $post['content'] ) ? $post['content'] : '',
507+
'description' => '',
508508
),
509509
);
510510
}

phpunit.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
<testsuite name="bluesky-image">
4747
<directory>./tests/test-bluesky-image.php</directory>
4848
</testsuite>
49+
<testsuite name="bluesky-card">
50+
<directory>./tests/test-bluesky-card.php</directory>
51+
</testsuite>
4952
<testsuite name="x-premium-limit">
5053
<directory>./tests/test-x-premium-limit.php</directory>
5154
</testsuite>

tests/test-bluesky-card.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* ROP Test Bluesky link card embed for PHPUnit.
4+
*
5+
* Reproduces GitHub issue Codeinwp/tweet-old-post-pro#676: the link card
6+
* (app.bsky.embed.external) must not repeat the post caption as its
7+
* description — Bluesky renders cards without a description as title + domain.
8+
*
9+
* @package ROP
10+
* @subpackage Tests
11+
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
12+
*/
13+
14+
/**
15+
* Test Bluesky link card. class.
16+
*/
17+
class Test_RopBlueskyCard extends WP_UnitTestCase {
18+
19+
/**
20+
* The link card description must be empty, not a copy of the post body.
21+
*
22+
* @covers Rop_Bluesky_Api::create_post
23+
*/
24+
public function test_link_card_description_is_empty() {
25+
$captured = null;
26+
27+
$interceptor = function ( $preempt, $args, $url ) use ( &$captured ) {
28+
if ( false === strpos( $url, 'com.atproto.repo.createRecord' ) ) {
29+
return $preempt;
30+
}
31+
$captured = json_decode( $args['body'], true );
32+
33+
return array(
34+
'headers' => array(),
35+
'body' => wp_json_encode(
36+
array(
37+
'uri' => 'at://did:plc:test/app.bsky.feed.post/test',
38+
'cid' => 'test-cid',
39+
)
40+
),
41+
'response' => array(
42+
'code' => 200,
43+
'message' => 'OK',
44+
),
45+
'cookies' => array(),
46+
'filename' => null,
47+
);
48+
};
49+
add_filter( 'pre_http_request', $interceptor, 10, 3 );
50+
51+
$api = new Rop_Bluesky_Api( 'test.bsky.social', 'test-app-password' );
52+
$api->create_post(
53+
'did:plc:test',
54+
array(
55+
'content' => 'My caption text for this share.',
56+
'title' => 'My Post Title',
57+
'post_url' => 'https://example.org/my-post/',
58+
),
59+
'link',
60+
'',
61+
'test-access-token'
62+
);
63+
64+
remove_filter( 'pre_http_request', $interceptor, 10 );
65+
66+
$this->assertNotNull( $captured, 'create_post() should have attempted a createRecord request.' );
67+
68+
$embed = $captured['record']['embed'];
69+
$this->assertSame( 'app.bsky.embed.external', $embed['$type'] );
70+
$this->assertSame( 'https://example.org/my-post/', $embed['external']['uri'] );
71+
$this->assertSame( 'My Post Title', $embed['external']['title'] );
72+
$this->assertSame(
73+
'',
74+
$embed['external']['description'],
75+
'Link card description must be empty, not a duplicate of the post caption (issue #676).'
76+
);
77+
}
78+
}

0 commit comments

Comments
 (0)