Created
January 12, 2016 12:10
-
-
Save imath/6b46b314e5ab463037ef to your computer and use it in GitHub Desktop.
Adds the title of the idea to the BuddyPress activity action string
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 | |
/** | |
* See https://wordpress.org/support/topic/adding-idea-title-to-buddypress-activity-stream | |
*/ | |
function jasonverdelli_set_wp_idea_stream_activity_actions( $wp_idea_stream_activity_actions = array() ) { | |
if ( ! empty( $wp_idea_stream_activity_actions['new_' . wp_idea_stream_get_post_type() ] ) ) { | |
$wp_idea_stream_activity_actions['new_' . wp_idea_stream_get_post_type() ]->action_callback = 'jasonverdelli_format_idea_activity_action'; | |
} | |
return $wp_idea_stream_activity_actions; | |
} | |
add_filter( 'wp_idea_stream_buddypress_get_activity_actions', 'jasonverdelli_set_wp_idea_stream_activity_actions', 10, 1 ); | |
function jasonverdelli_format_idea_activity_action( $action = '', $activity = null ) { | |
if ( ! is_object( $activity ) ) { | |
return false; | |
} | |
if ( isset( $activity->post_title ) ) { | |
$idea_title = $activity->post_title; | |
} elseif ( ! empty( $activity->id ) ) { | |
$idea_title = bp_activity_get_meta( $activity->id, 'wp_idea_stream_idea_title' ); | |
} | |
/** | |
* In case the idea was published without a title | |
* or the activity meta was not found. | |
*/ | |
if ( empty( $idea_title ) ) { | |
// Defaults to no title. | |
$idea_title = esc_html( '(no title)' ); | |
switch_to_blog( $activity->item_id ); | |
$post = get_post( $activity->secondary_item_id ); | |
if ( is_a( $post, 'WP_Post' ) ) { | |
// Does the post have a title ? | |
if ( ! empty( $post->post_title ) ) { | |
$idea_title = $post->post_title; | |
} | |
// Make sure the activity exists before saving the post title in activity meta. | |
if ( ! empty( $activity->id ) ) { | |
bp_activity_update_meta( $activity->id, 'wp_idea_stream_idea_title', $idea_title ); | |
} | |
} | |
restore_current_blog(); | |
} | |
$post_type_object = get_post_type_object( wp_idea_stream_get_post_type() ); | |
$action = sprintf( '%1$s wrote a new %2$s, %3$s', | |
bp_core_get_userlink( $activity->user_id ), | |
esc_html( mb_strtolower( $post_type_object->labels->singular_name, 'UTF-8' ) ), | |
'<a href="' . esc_url( $activity->primary_link ) . '">' . esc_html( $idea_title ) . '</a>' | |
); | |
return apply_filters( 'jasonverdelli_format_idea_activity_action', $action ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment