Advertisement
nefi_c

email notification box

Feb 10th, 2013
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.81 KB | None | 0 0
  1. <?php
  2.  
  3. /* what show on custom box */
  4. function print_my_custom_notification_box( $post ) {
  5.     wp_nonce_field( 'my_custom_notification_box_nonce_action', 'my_custom_notification_box_nonce_field' ); ?>
  6.     <script type="text/javascript">
  7.     jQuery(document).ready(function(){
  8.         $('#mynotification-box-button').click(function(e){
  9.             e.preventDefault();
  10.             $('#mynotification-box .spinner').show();
  11.             $.ajax({ url: ajaxurl, data: { action: 'sendnotification', postID: $('#post_ID').val(), my_notification_nonce: $('#my_custom_notification_box_nonce_field').val() },
  12.                 success: function(content){  
  13.                     $('#mynotification').text(content).css('visibility','visible');
  14.                     setTimeout(function(){
  15.                         $('#mynotification').empty().css({'visibility':'hidden'});
  16.                     },3000)
  17.                     $('#mynotification-box .spinner').hide();
  18.                 }
  19.             });
  20.         });
  21.     });
  22.     </script>
  23.     <div class="submitbox" id="mynotification-box" style="padding: 10px 0 0;clear: both;border-top: 1px solid whiteSmoke;margin-top: -2px;">
  24.         <input type="submit" class="button button-primary button-large" id="mynotification-box-button" accesskey="n" value="Send Email Notification" style="float:right">
  25.         <span class="spinner" style="display: none;"></span>
  26.         <div class="clear"></div>
  27.         <p id="mynotification" style="visibility: hidden; height: 1em; margin: 5px 0 10px; text-align: right;"></p>
  28.     </div>
  29. <?php
  30. }
  31. // add our custom box
  32. function my_custom_notification_box() {
  33.     $posttype = array( 'post', 'page' );
  34.     foreach ($posttype as $type) {
  35.         add_meta_box(
  36.             'post_email_notification',
  37.             __( 'Email Notification'),
  38.             'print_my_custom_notification_box',
  39.             $type,
  40.             'side',
  41.             'core'
  42.         );
  43.     }
  44. }
  45. add_action( 'add_meta_boxes', 'my_custom_notification_box' );
  46.  
  47. /* send email function */
  48. function send_mypost_notification(){
  49.     if(!wp_verify_nonce( $_GET['my_notification_nonce'],  'my_custom_notification_box_nonce_action' ))
  50.         die;
  51.        
  52.     $postID = $_GET['postID'];
  53.    
  54.     $firstname = get_post_meta($postID, 'first_name', true);
  55.     $surname = get_post_meta($postID, 'surname', true);
  56.     $email = get_post_meta($postID, 'surname', true);
  57.    
  58.     $subject = get_bloginfo('name').' Notification';
  59.     $headers = 'From: '.get_bloginfo('name').' <'.get_bloginfo('admin_email').'>' . "\r\n";
  60.     $message = 'Hello '.$firstname.',\n\n Your page has been updated.\n <a href="'.get_permalink($postID).'" target="_blank">Click here to view your page.</a>\n\n From the team.\n <a href="'.get_bloginfo('url').'" target="_blank">'.get_bloginfo('url').'</a>';
  61.    
  62.     $send_success = wp_mail( $email, $subject, $message, $headers, $attachments );
  63.    
  64.     if($send_success)
  65.         echo 'Notification is successfully sent';
  66.     else
  67.         echo 'Notification failed to sent';
  68.     die;
  69. }
  70. add_action('wp_ajax_sendnotification', 'send_mypost_notification');
  71.  
  72.  
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement