Strothi

Add KLEO Portfolio Item to BP Activity Stream

Nov 11th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.93 KB | None | 0 0
  1. function webinars_activity_args() {
  2.     if ( ! bp_is_active( 'activity' ) ) {
  3.         return;
  4.     }
  5.  
  6.     add_post_type_support( 'webinars', 'buddypress-activity' );
  7.  
  8.     bp_activity_set_post_type_tracking_args( 'webinars', array(
  9.         'component_id'             => 'activity',
  10.         'action_id'                => 'new_webinars',
  11.             'bp_activity_admin_filter' => __( 'Published a new Webinar', 'text-domain' ),
  12.             'bp_activity_front_filter' => __( 'Webinar', 'text-domain' ),
  13.             'contexts'                 => array( 'activity', 'member' ),
  14.             'activity_comment'         => true,
  15.             'bp_activity_new_post'     => __( '%1$s posted a new Webinar: <a href="%2$s">[Webinar]</a>', 'text-domain' ),
  16.             'bp_activity_new_post_ms'  => __( '%1$s posted a new Webinar: <a href="%2$s">[Webinar]</a>, on the site %3$s', 'text-domain' ),
  17.             'position'                 => 100,
  18.         ) );
  19. }
  20. add_action( 'init', 'webinars_activity_args' );
  21.  
  22.  
  23. function webinars_include_post_type_title( $action, $activity ) {
  24.     if ( empty( $activity->id ) ) {
  25.         return $action;
  26.     }
  27.  
  28.     if ( 'new_webinars' != $activity->type ) {
  29.         return $action;
  30.     }
  31.  
  32.     preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
  33.  
  34.     if ( empty( $matches[1][1] ) || '[Webinars]' != $matches[1][1] ) {
  35.         return $action;
  36.     }
  37.  
  38.     $post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
  39.  
  40.     if ( empty( $post_type_title ) ) {
  41.  
  42.         switch_to_blog( $activity->item_id );
  43.  
  44.         $post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
  45.  
  46.         // We have a title save it in activity meta to avoid switching blogs too much
  47.         if ( ! empty( $post_type_title ) ) {
  48.             bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
  49.         }
  50.  
  51.         restore_current_blog();
  52.     }
  53.  
  54.     return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
  55. }
  56. add_filter( 'bp_activity_custom_post_type_post_action', 'webinars_include_post_type_title', 10, 2 );
Add Comment
Please, Sign In to add comment