Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. <?php
  2.  
  3. function wpf_apply_tags_on_view( $post ) {
  4.  
  5. if( ! function_exists( 'wp_fusion' ) ) {
  6. return;
  7. }
  8.  
  9. if ( is_admin() || ! is_singular() || ! is_user_logged_in() || $post->post_type != 'post' ) {
  10. return;
  11. }
  12.  
  13. $tags_to_apply = array();
  14.  
  15. $categories = get_the_terms( $post, 'category' );
  16.  
  17. if( ! empty( $categories ) && ! is_wp_error( $categories ) ) {
  18.  
  19. foreach( $categories as $category ) {
  20.  
  21. $tags_to_apply[] = $category->name;
  22.  
  23. }
  24.  
  25. }
  26.  
  27. $tags = get_the_terms( $post, 'post_tag' );
  28.  
  29. if( ! empty( $tags ) && ! is_wp_error( $tags ) ) {
  30.  
  31. foreach( $tags as $tag ) {
  32.  
  33. $tags_to_apply[] = $tag->name;
  34.  
  35. }
  36.  
  37. }
  38.  
  39. wp_fusion()->user->apply_tags( $apply_tags );
  40.  
  41. }
  42.  
  43. add_action( 'the_post', 'wpf_apply_tags_on_view' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement