AnsPress_BP_Hooks::ap_notifier_format( string $action, integer $activity_id, integer $secondary_item_id, integer $total_items, string $format = 'string' )
Description #
Format notifications.
Parameters #
- $actionstring (Required) Action name.
- $activity_idinteger (Required) Activity name.
- $secondary_item_idinteger (Required) Secondary item ID.
- $total_itemsinteger (Required) Total items.
- $formatstring (Optional) Format. Default value: 'string'
Source #
File: addons/free/buddypress.php
public static function ap_notifier_format( $action, $activity_id, $secondary_item_id, $total_items, $format = 'string' ) {
$amount = 'single';
$notification_link = '';
$text = '';
if ( strrpos( $action, 'new_answer' ) !== false ) {
$answer = get_post( $activity_id );
if ( $answer ) {
$notification_link = get_permalink( $answer->ID );
$title = substr( strip_tags( $answer->post_title ), 0, 35 ) . (strlen( $answer->post_title ) > 35 ? '...' : '') ;
if ( (int) $total_items > 1 ) {
$text = sprintf( __( '%1$d answers on - %2$s', 'anspress-question-answer' ), (int) $total_items, $title );
$amount = 'multiple';
} else {
$user_fullname = bp_core_get_user_displayname( $secondary_item_id );
$text = sprintf( __( '%1$s answered on - %2$s', 'anspress-question-answer' ), $user_fullname, $title );
}
}
} elseif ( strrpos( $action, 'new_comment' ) !== false ) {
$comment = get_comment( $activity_id );
$post = get_post( $comment->comment_post_ID ); // WPCS: override okay.
$notification_link = get_permalink( $comment->comment_post_ID );
$type = 'question' === $post->post_type ? __( 'question', 'anspress-question-answer' ) : __( 'answer', 'anspress-question-answer' );
$amount = 'single';
$title = substr( strip_tags( $post->post_title ), 0, 35 ) . ( strlen( $post->post_title ) > 35 ? '...' : '') ;
if ( (int) $total_items > 1 ) {
$text = sprintf( __( '%1$d comments on your %3$s - %2$s', 'anspress-question-answer' ), (int) $total_items, $title, $type );
$amount = 'multiple';
} else {
$user_fullname = bp_core_get_user_displayname( $secondary_item_id );
$text = sprintf( __( '%1$s commented on your %3$s - %2$s', 'anspress-question-answer' ), $user_fullname, $title, $type );
}
}
if ( 'string' === $format ) {
$return = apply_filters( 'ap_notifier_' . $amount . '_at_mentions_notification', '<a href="' . esc_url( $notification_link ) . '">' . esc_html( $text ) . '</a>', $notification_link, (int) $total_items, $activity_id, $secondary_item_id );
} else {
$return = apply_filters( 'ap_notifier_' . $amount . '_at_mentions_notification', array(
'text' => $text,
'link' => $notification_link,
), $notification_link, (int) $total_items, $activity_id, $secondary_item_id );
}
do_action( 'ap_notifier_format_notifications', $action, $activity_id, $secondary_item_id, $total_items );
return $return;
}
Expand full source code Collapse full source code View on GitHub: addons/free/buddypress.php:367
Add your comment