Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function send_alert_when_new_tag( $data, $postarr ) {
- global $post_id;
- $post_title = get_the_title( $post_id ); // retrive the post tile
- $post_url = get_permalink( $post_id ); // retrive the post url
- $author = get_post( $post_id ); // gets author from post
- $author_id = $author->post_author; // gets author id for the post
- $author_name = get_the_author_meta( 'display_name', $author_id ); // retrive display name
- $current_user = wp_get_current_user(); // retrive current user
- $tag_url = get_bloginfo( 'url' ).'/wp-admin/edit-tags.php?taxonomy=article_tags&post_type=article'; // tag url
- $subject = 'Alerta de tag creado por: '.$current_user->display_name;
- $taxonomy_array = array( 'post_tag', 'article_tags', 'special_edition_tag', 'topic_tags' );
- $args = array(
- 'hide_empty' => 0
- );
- $global_tags = get_terms( $taxonomy_array, $args );
- $global_tags_array = array();
- foreach ( $global_tags as $value ) {
- array_push( $global_tags_array, $value->slug );
- }
- //$term = get_the_terms( $post_id, 'article_tags' );
- //$term = wp_get_post_terms( $post_id, 'article_tags', array( "fields" => "all" ) );
- $term = wp_get_object_terms( $post_id, 'article_tags' );
- $term_array = array();
- if( $term ) {
- foreach ( $term as $value ) {
- /*if ( !in_array( $value->slug , $global_tags_array) ) {
- array_push( $term_array, $value->slug );
- }*/
- if ( !has_term( $value->slug, 'article_tags' ) ){
- array_push( $term_array, $value->slug );
- }
- }
- }
- // if tag exists
- //if( !empty( $term_array ) ) {
- $tags = implode(",", $term_array);
- //$tags = implode(",", $postarr['tags_input'] );
- $message = 'Tag creado:'. $tags ."\n\n";
- $message .= 'Título del artículo: '.$post_title."\n\n";
- $message .= 'Usuario: '.$current_user->display_name."\n\n";
- $message .= 'Author: '.$author_name."\n\n";
- $message .= 'Url del artículo: '.$post_url."\n\n";
- $message .= 'Url de tags: ' . $tag_url;
- // Send test email
- //wp_mail( '[email protected]', $subject, $message );
- //}
- return $data;
- }
- add_filter( 'wp_insert_post_data', 'send_alert_when_new_tag', '99', 2 );
- //add_action( 'save_post', 'send_alert_when_new_tag' );
Advertisement
Add Comment
Please, Sign In to add comment