Skip to content

Commit 4d148b9

Browse files
singerbsamhotchkiss
authored andcommitted
Use the sharing filters in e-mail too (Automattic#6342)
* Use the sharing filters in e-mail too Fixes Automattic#5989 Per the issue, the URL and title shared are filterable for the other sharing types, but not e-mail. This change makes sure to call the same functions when sharing via e-mail. Test plan: - Have a server where e-mail sharing works and apply patch - Share a post via e-mail, verify it looks normal - Add `sharing_permalink` and `sharing_title` filters and share a post again; verify you get the new values * Add missing file Missed the other file from the first commit.
1 parent b8868c6 commit 4d148b9

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

‎modules/sharedaddy/sharedaddy.php‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ function sharing_email_send_post( $data ) {
2525
$headers[] = sprintf( 'From: %1$s <%2$s>', $data['name'], $from_email );
2626
$headers[] = sprintf( 'Reply-To: %1$s <%2$s>', $data['name'], $data['source'] );
2727

28-
wp_mail( $data['target'], '['.__( 'Shared Post', 'jetpack' ).'] '.$data['post']->post_title, $content, $headers );
28+
// Make sure to pass the title through the normal sharing filters.
29+
$title = $data['sharing_source']->get_share_title( $data['post']->ID );
30+
31+
wp_mail( $data['target'], '[' . __( 'Shared Post', 'jetpack' ) . '] ' . $title, $content, $headers );
2932
}
3033

3134

@@ -39,7 +42,7 @@ function sharing_email_check_for_spam_via_akismet( $data ) {
3942
// Prepare the body_request for akismet
4043
$body_request = array(
4144
'blog' => get_option( 'home' ),
42-
'permalink' => get_permalink( $data['post']->ID ),
45+
'permalink' => $data['sharing_source']->get_share_url( $data['post']->ID ),
4346
'comment_type' => 'share',
4447
'comment_author' => $data['name'],
4548
'comment_author_email' => $data['source'],
@@ -67,8 +70,9 @@ function sharing_email_send_post_content( $data ) {
6770
/* translators: included in email when post is shared via email. First item is sender's name. Second is sender's email address. */
6871
$content = sprintf( __( '%1$s (%2$s) thinks you may be interested in the following post:', 'jetpack' ), $data['name'], $data['source'] );
6972
$content .= "\n\n";
70-
$content .= $data['post']->post_title."\n";
71-
$content .= get_permalink( $data['post']->ID )."\n";
73+
// Make sure to pass the title and URL through the normal sharing filters.
74+
$content .= $data['sharing_source']->get_share_title( $data['post']->ID ) . "\n";
75+
$content .= $data['sharing_source']->get_share_url( $data['post']->ID ) . "\n";
7276
return $content;
7377
}
7478

‎modules/sharedaddy/sharing-sources.php‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,11 @@ public function process_request( $post, array $post_data ) {
426426
*/
427427
if ( apply_filters( 'sharing_email_check', true, $post, $post_data ) ) {
428428
$data = array(
429-
'post' => $post,
430-
'source' => $source_email,
431-
'target' => $target_email,
432-
'name' => $source_name,
429+
'post' => $post,
430+
'source' => $source_email,
431+
'target' => $target_email,
432+
'name' => $source_name,
433+
'sharing_source' => $this,
433434
);
434435
// todo: implement an error message when email doesn't get sent.
435436
/**

0 commit comments

Comments
 (0)