Skip to content

Commit deb7755

Browse files
committed
Refactor display_ticket_replies()
It is now converted to loop instead of twice duplication of everything
1 parent c063ceb commit deb7755

File tree

1 file changed

+31
-42
lines changed

1 file changed

+31
-42
lines changed

classes/class-supportflow-admin.php

+31-42
Original file line numberDiff line numberDiff line change
@@ -956,53 +956,36 @@ public function meta_box_replies() {
956956
}
957957

958958
public function display_ticket_replies() {
959-
$private_replies = SupportFlow()->get_ticket_replies( get_the_ID(), array( 'status' => 'private' ) );
959+
$all_replies = array(
960+
'private' => SupportFlow()->get_ticket_replies( get_the_ID(), array( 'status' => 'private' ) ),
961+
'public' => SupportFlow()->get_ticket_replies( get_the_ID(), array( 'status' => 'public' ) ),
962+
);
960963

961-
if ( ! empty( $private_replies ) ) {
962-
echo '<ul class="private-replies">';
963-
foreach ( $private_replies as $reply ) {
964-
echo '<li>';
965-
echo '<div class="ticket-reply">';
966-
$post_content = wpautop( stripslashes( $reply->post_content ) );
967-
// Make link clickable
968-
$post_content = make_clickable( $post_content );
969-
$post_content = $this->hide_quoted_text( $post_content );
970-
echo $post_content;
971-
if ( $attachment_ids = get_post_meta( $reply->ID, 'sf_attachments' ) ) {
972-
echo '<ul class="ticket-reply-attachments">';
973-
foreach ( $attachment_ids as $attachment_id ) {
974-
$attachment_link = SupportFlow()->extend->attachments->get_attachment_url( $attachment_id );
975-
echo '<li><a target="_blank" href="' . esc_url( $attachment_link ) . '">' . esc_html( get_the_title( $attachment_id ) ) . '</a></li>';
976-
}
977-
echo '</ul>';
978-
}
979-
echo '</div>';
980-
$reply_author = get_post_meta( $reply->ID, 'reply_author', true );
981-
$reply_timestamp = sprintf( __( 'Noted by %1$s on %2$s at %3$s', 'supportflow' ), $reply_author, get_the_date( '', $reply->ID ), get_the_time( '', $reply->ID ) );
982-
$modified_gmt = get_post_modified_time( 'U', true, $reply->ID );
983-
$last_activity = sprintf( __( '%s ago', 'supportflow' ), human_time_diff( $modified_gmt ) );
984-
echo '<div class="ticket-meta"><span class="reply-timestamp">' . esc_html( $reply_timestamp ) . ' (' . $last_activity . ')' . '</span></div>';
985-
echo '</li>';
964+
foreach ( $all_replies as $status => $replies ) {
965+
if ( empty( $replies ) ) {
966+
continue;
986967
}
987-
echo '</ul>';
988-
}
989968

990-
$replies = SupportFlow()->get_ticket_replies( get_the_ID(), array( 'status' => 'public' ) );
991-
if ( ! empty( $replies ) ) {
992-
echo '<ul class="ticket-replies">';
969+
$class = 'private' == $status ? 'private-replies' : 'ticket-replies';
970+
echo "<ul class='$class'>";
971+
993972
foreach ( $replies as $reply ) {
994-
$reply_author = get_post_meta( $reply->ID, 'reply_author', true );
995-
$reply_author_email = get_post_meta( $reply->ID, 'reply_author_email', true );
996973
echo '<li>';
997-
echo '<div class="reply-avatar">' . get_avatar( $reply_author_email, 72 );
998-
echo '<p class="reply-author">' . esc_html( $reply_author ) . '</p>';
999-
echo '</div>';
974+
975+
if ( 'public' == $status ) {
976+
$reply_author = get_post_meta( $reply->ID, 'reply_author', true );
977+
$reply_author_email = get_post_meta( $reply->ID, 'reply_author_email', true );
978+
echo '<div class="reply-avatar">' . get_avatar( $reply_author_email, 72 );
979+
echo '<p class="reply-author">' . esc_html( $reply_author ) . '</p>';
980+
echo '</div>';
981+
}
982+
1000983
echo '<div class="ticket-reply">';
1001984
$post_content = wpautop( stripslashes( $reply->post_content ) );
1002-
// Make link clickable
1003985
$post_content = make_clickable( $post_content );
1004986
$post_content = $this->hide_quoted_text( $post_content );
1005987
echo $post_content;
988+
1006989
if ( $attachment_ids = get_post_meta( $reply->ID, 'sf_attachments' ) ) {
1007990
echo '<ul class="ticket-reply-attachments">';
1008991
foreach ( $attachment_ids as $attachment_id ) {
@@ -1012,17 +995,23 @@ public function display_ticket_replies() {
1012995
echo '</ul>';
1013996
}
1014997
echo '</div>';
1015-
$reply_timestamp = sprintf( __( '%s at %s', 'supportflow' ), get_the_date( '', $reply->ID ), get_the_time( '', $reply->ID ) );
1016-
$modified_gmt = get_post_modified_time( 'U', true, $reply->ID );
1017-
$last_activity = sprintf( __( '%s ago', 'supportflow' ), human_time_diff( $modified_gmt ) );
998+
999+
if ( 'private' == $status ) {
1000+
$reply_author = get_post_meta( $reply->ID, 'reply_author', true );
1001+
$reply_timestamp = sprintf( __( 'Noted by %1$s on %2$s at %3$s', 'supportflow' ), $reply_author, get_the_date( '', $reply->ID ), get_the_time( '', $reply->ID ) );
1002+
}
1003+
if ( 'public' == $status ) {
1004+
$reply_timestamp = sprintf( __( '%s at %s', 'supportflow' ), get_the_date( '', $reply->ID ), get_the_time( '', $reply->ID ) );
1005+
}
1006+
1007+
$modified_gmt = get_post_modified_time( 'U', true, $reply->ID );
1008+
$last_activity = sprintf( __( '%s ago', 'supportflow' ), human_time_diff( $modified_gmt ) );
10181009
echo '<div class="ticket-meta"><span class="reply-timestamp">' . esc_html( $reply_timestamp ) . ' (' . $last_activity . ')' . '</span></div>';
10191010
echo '</li>';
10201011
}
10211012
echo '</ul>';
10221013
}
1023-
10241014
echo '<div class="clear"></div>';
1025-
10261015
}
10271016

10281017
/**

0 commit comments

Comments
 (0)