kisukedeath

Send alert when new tag final

Jun 2nd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. function send_alert_when_new_tag( $term_id, $tt_id, $taxonomy ) {
  2.  
  3.     global $post_id;
  4.     $post_title   = get_the_title( $post_id ); // retrive the post tile
  5.     $post_url     = get_permalink( $post_id ); // retrive the post url
  6.     $author       = get_post( $post_id );      // gets author from post
  7.     $author_id    = $author->post_author;      // gets author id for the post
  8.     $author_name  = get_the_author_meta( 'display_name', $author_id ); // retrive display name
  9.     $current_user = wp_get_current_user();     // retrive current user
  10.     $tag_url      = get_bloginfo( 'url' ).'/wp-admin/edit-tags.php?taxonomy=article_tags&post_type=article'; // tag url
  11.     $subject      = 'Alerta de tag creado por: '.$current_user->display_name;
  12.     $tag          = get_term_by( 'id', $term_id, $taxonomy );
  13.     $to           = array( '[email protected]', '[email protected]', '[email protected]', '[email protected]' );
  14.  
  15.     $message      = 'Tag creado:'. $tag->name ."\n\n";
  16.     $message     .= 'Título del artículo: '.$post_title."\n\n";
  17.     $message     .= 'Usuario: '.$current_user->display_name."\n\n";
  18.     $message     .= 'Author: '.$author_name."\n\n";
  19.     $message     .= 'Url del artículo: '.$post_url."\n\n";
  20.     $message     .= 'Url de tags: ' . $tag_url;
  21.  
  22.     // Send test email
  23.     wp_mail( $to, $subject, $message );
  24.  
  25.     }
  26.  
  27.     // Notify when new tag is created
  28.     add_action( 'created_term', 'send_alert_when_new_tag', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment