Last active
September 7, 2019 21:39
-
-
Save donini/1ef85421462fea9a72aebca4ba446ad9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'bulk_actions-edit-post', 'new_bulk_actions' ); | |
function new_bulk_actions( $bulk_actions ) { | |
$bulk_actions['send_by_email'] = __( 'Send By E-mail', 'text_domain' ); | |
return $bulk_actions; | |
} | |
add_filter( 'handle_bulk_actions-edit-post', 'new_bulk_action_handler', 10, 3 ); | |
function new_bulk_action_handler( $redirect_to, $doaction, $post_ids ) { | |
/* Exit if it's not send by email action */ | |
if ( 'send_by_email' !== $doaction ) { | |
return $redirect_to; | |
} | |
/* Send e-mails */ | |
foreach ( $post_ids as $post_id ) { | |
$current_user = wp_get_current_user(); | |
$current_post = get_post( $post_id ); | |
wp_mail( | |
$current_user->user_email, | |
$current_post->post_title, | |
sprintf( '<a href="%1$s">%2$s</a>\n%3$s', | |
$current_post->guid, | |
$current_post->post_title, | |
$current_post->post_content | |
) | |
); | |
} | |
$redirect_to = add_query_arg( 'bulk_emailed_posts', count( $post_ids ), $redirect_to ); | |
return $redirect_to; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment