Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* what show on custom box */
- function print_my_custom_notification_box( $post ) {
- wp_nonce_field( 'my_custom_notification_box_nonce_action', 'my_custom_notification_box_nonce_field' ); ?>
- <script type="text/javascript">
- jQuery(document).ready(function(){
- $('#mynotification-box-button').click(function(e){
- e.preventDefault();
- $('#mynotification-box .spinner').show();
- $.ajax({ url: ajaxurl, data: { action: 'sendnotification', postID: $('#post_ID').val(), my_notification_nonce: $('#my_custom_notification_box_nonce_field').val() },
- success: function(content){
- $('#mynotification').text(content).css('visibility','visible');
- setTimeout(function(){
- $('#mynotification').empty().css({'visibility':'hidden'});
- },3000)
- $('#mynotification-box .spinner').hide();
- }
- });
- });
- });
- </script>
- <div class="submitbox" id="mynotification-box" style="padding: 10px 0 0;clear: both;border-top: 1px solid whiteSmoke;margin-top: -2px;">
- <input type="submit" class="button button-primary button-large" id="mynotification-box-button" accesskey="n" value="Send Email Notification" style="float:right">
- <span class="spinner" style="display: none;"></span>
- <div class="clear"></div>
- <p id="mynotification" style="visibility: hidden; height: 1em; margin: 5px 0 10px; text-align: right;"></p>
- </div>
- <?php
- }
- // add our custom box
- function my_custom_notification_box() {
- $posttype = array( 'post', 'page' );
- foreach ($posttype as $type) {
- add_meta_box(
- 'post_email_notification',
- __( 'Email Notification'),
- 'print_my_custom_notification_box',
- $type,
- 'side',
- 'core'
- );
- }
- }
- add_action( 'add_meta_boxes', 'my_custom_notification_box' );
- /* send email function */
- function send_mypost_notification(){
- if(!wp_verify_nonce( $_GET['my_notification_nonce'], 'my_custom_notification_box_nonce_action' ))
- die;
- $postID = $_GET['postID'];
- $firstname = get_post_meta($postID, 'first_name', true);
- $surname = get_post_meta($postID, 'surname', true);
- $email = get_post_meta($postID, 'surname', true);
- $subject = get_bloginfo('name').' Notification';
- $headers = 'From: '.get_bloginfo('name').' <'.get_bloginfo('admin_email').'>' . "\r\n";
- $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>';
- $send_success = wp_mail( $email, $subject, $message, $headers, $attachments );
- if($send_success)
- echo 'Notification is successfully sent';
- else
- echo 'Notification failed to sent';
- die;
- }
- add_action('wp_ajax_sendnotification', 'send_mypost_notification');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement