daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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' );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top