Last active
August 29, 2015 14:24
-
-
Save ocean90/3551279c9a865e137441 to your computer and use it in GitHub Desktop.
Saves outgoing mails in a post type, drop it into wp-content/mu-plugins.
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 | |
/** | |
* Plugin Name: Debug Mails | |
* Description: Saves outgoing mails in a post type. | |
* Author: Dominik Schilling (ocean90) | |
*/ | |
function ds_register_cpt_mail_debug() { | |
register_post_type( 'mail-debug', array( | |
'label' => 'Mails', | |
'show_ui' => true, | |
'public' => false, | |
'show_in_menu' => 'tools.php', | |
'show_in_nav_menus' => false, | |
'show_in_admin_bar' => false, | |
'publicly_queryable' => false, | |
'can_export' => false, | |
'register_meta_box_cb' => 'ds_register_meta_box', | |
'supports' => array( '' ), | |
) ); | |
} | |
add_action( 'init', 'ds_register_cpt_mail_debug' ); | |
function ds_register_meta_box() { | |
$post = get_post(); | |
add_meta_box( | |
'mail-content', | |
esc_html( $post->post_title ), | |
'ds_mail_box', | |
null, | |
'normal' | |
); | |
remove_meta_box( 'submitdiv', null, 'side' ); | |
remove_meta_box( 'slugdiv', null, 'normal' ); | |
} | |
function ds_mail_box() { | |
$post = get_post(); | |
// Fix <http://...> links | |
$mail = preg_replace( '#(?:(<)(https?:\/\/(?:.*))(>))#', '$2', $post->post_content ); | |
$mail = make_clickable( $mail ); | |
?> | |
<pre> | |
<?php print_r( $mail ); ?> | |
</pre> | |
<?php | |
} | |
function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { | |
return wp_insert_post( array( | |
'post_status' => 'publish', | |
'post_type' => 'mail-debug', | |
'post_title' => $subject . ' (' . $to . ')', | |
'post_content' => $message, | |
) ); | |
} | |
function ds_remove_edit_actions( $actions ) { | |
$post = get_post(); | |
if ( 'post_row_actions' == current_filter() && $post && 'mail-debug' === $post->post_type ) { | |
unset( $actions['inline hide-if-no-js'] ); | |
$actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'View' ) . '</a>'; | |
} else if ( $post && 'mail-debug' === $post->post_type ){ | |
unset( $actions['edit'] ); | |
} | |
return $actions; | |
} | |
add_filter( 'post_row_actions', 'ds_remove_edit_actions' ); | |
add_filter( 'bulk_actions-edit-mail-debug','ds_remove_edit_actions'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment