kisukedeath

Send alert when new tag beta

Jun 1st, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.45 KB | None | 0 0
  1. function send_alert_when_new_tag( $data, $postarr ) {
  2.     global $post_id;
  3.     $post_title   = get_the_title( $post_id ); // retrive the post tile
  4.     $post_url     = get_permalink( $post_id ); // retrive the post url
  5.     $author       = get_post( $post_id );      // gets author from post
  6.     $author_id    = $author->post_author;      // gets author id for the post
  7.     $author_name  = get_the_author_meta( 'display_name', $author_id ); // retrive display name
  8.     $current_user = wp_get_current_user();     // retrive current user
  9.     $tag_url      = get_bloginfo( 'url' ).'/wp-admin/edit-tags.php?taxonomy=article_tags&post_type=article'; // tag url
  10.     $subject      = 'Alerta de tag creado por: '.$current_user->display_name;
  11.  
  12.     $taxonomy_array = array( 'post_tag', 'article_tags', 'special_edition_tag', 'topic_tags' );
  13.  
  14.     $args = array(
  15.         'hide_empty' => 0
  16.     );
  17.  
  18.     $global_tags       = get_terms( $taxonomy_array, $args );
  19.     $global_tags_array = array();
  20.  
  21.     foreach ( $global_tags as $value ) {
  22.         array_push( $global_tags_array, $value->slug );
  23.     }
  24.  
  25.     //$term = get_the_terms( $post_id, 'article_tags' );
  26.     //$term = wp_get_post_terms( $post_id, 'article_tags', array( "fields" => "all" ) );
  27.     $term   = wp_get_object_terms( $post_id, 'article_tags' );
  28.     $term_array = array();
  29.  
  30.     if( $term ) {
  31.         foreach ( $term as $value ) {
  32.             /*if ( !in_array( $value->slug , $global_tags_array) ) {
  33.                 array_push( $term_array, $value->slug );
  34.             }*/
  35.             if ( !has_term( $value->slug, 'article_tags' ) ){
  36.                 array_push( $term_array, $value->slug );
  37.             }
  38.         }
  39.     }
  40.  
  41.     // if tag exists
  42.     //if( !empty( $term_array ) ) {
  43.  
  44.         $tags = implode(",", $term_array);
  45.         //$tags = implode(",", $postarr['tags_input'] );
  46.  
  47.         $message      = 'Tag creado:'. $tags ."\n\n";
  48.         $message     .= 'Título del artículo: '.$post_title."\n\n";
  49.         $message     .= 'Usuario: '.$current_user->display_name."\n\n";
  50.         $message     .= 'Author: '.$author_name."\n\n";
  51.         $message     .= 'Url del artículo: '.$post_url."\n\n";
  52.         $message     .= 'Url de tags: ' . $tag_url;
  53.  
  54.         // Send test email
  55.         //wp_mail( '[email protected]', $subject, $message );
  56.     //}
  57.  
  58.     return $data;
  59. }
  60.  
  61. add_filter( 'wp_insert_post_data', 'send_alert_when_new_tag', '99', 2 );
  62. //add_action( 'save_post', 'send_alert_when_new_tag' );
Advertisement
Add Comment
Please, Sign In to add comment