Skip to content

Instantly share code, notes, and snippets.

@donini
Last active September 7, 2019 21:39
Show Gist options
  • Save donini/1ef85421462fea9a72aebca4ba446ad9 to your computer and use it in GitHub Desktop.
Save donini/1ef85421462fea9a72aebca4ba446ad9 to your computer and use it in GitHub Desktop.
<?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