Created
April 13, 2015 14:52
-
-
Save imath/dce8426f686da1727f82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function job_listing_activity_args() { | |
if ( ! bp_is_active( 'activity' ) ) { | |
return; | |
} | |
add_post_type_support( 'job_listing', 'buddypress-activity' ); | |
bp_activity_set_post_type_tracking_args( 'job_listing', array( | |
'component_id' => 'activity', | |
'action_id' => 'new_job_listing', | |
'bp_activity_admin_filter' => __( 'Published a new Job', 'text-domain' ), | |
'bp_activity_front_filter' => __( 'Job', 'text-domain' ), | |
'contexts' => array( 'activity', 'member' ), | |
'activity_comment' => true, | |
'bp_activity_new_post' => __( '%1$s posted a new Job: <a href="%2$s">[Job]</a>', 'text-domain' ), | |
'bp_activity_new_post_ms' => __( '%1$s posted a new Job: <a href="%2$s">[Job]</a>, on the site %3$s', 'text-domain' ), | |
'position' => 100, | |
) ); | |
} | |
add_action( 'init', 'job_listing_activity_args' ); | |
function job_listing_include_post_type_title( $action, $activity ) { | |
if ( empty( $activity->id ) ) { | |
return $action; | |
} | |
if ( 'new_job_listing' != $activity->type ) { | |
return $action; | |
} | |
preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches ); | |
if ( empty( $matches[1][1] ) || '[Job]' != $matches[1][1] ) { | |
return $action; | |
} | |
$post_type_title = bp_activity_get_meta( $activity->id, 'post_title' ); | |
if ( empty( $post_type_title ) ) { | |
switch_to_blog( $activity->item_id ); | |
$post_type_title = get_post_field( 'post_title', $activity->secondary_item_id ); | |
// We have a title save it in activity meta to avoid switching blogs too much | |
if ( ! empty( $post_type_title ) ) { | |
bp_activity_update_meta( $activity->id, 'post_title', $post_type_title ); | |
} | |
restore_current_blog(); | |
} | |
return str_replace( $matches[1][1], esc_html( $post_type_title ), $action ); | |
} | |
add_filter( 'bp_activity_custom_post_type_post_action', 'job_listing_include_post_type_title', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Merci pour le filtre @imath , ça marche comme un charme et c'est très intéressant !