I use a Private Message script where it adds a Re:
to the message subject upon every reply. Unfortunately, if there are more than one reply to the same message, it adds another Re:
, so by the time a few PMs have been exchanged, it looks like this:
Re: Re: Re: Re: Re: Re: Re: Re: Hello World!
Here are the relevant parts of the script that does this:
| <a class="reply"
href="<?php echo wp_nonce_url( "?page=rwpm_send&recipient=$msg->sender&id=$msg->id&subject=Re: " . stripcslashes( $msg->subject ), 'rwpm-reply_inbox_msg_' . $msg->id ); ?>"><?php _e( 'Reply', 'pm4wp' ); ?></a>
So I want to adjust the script so that it only adds one Re:
if there is a reply. How do I do that? I am guessing maybe an IF statement checking if there is already a Re:
there or not...
So, add the "Re: " only if there is no:
| <a class="reply" href="<?php echo wp_nonce_url( "?page=rwpm_send&recipient=$msg->sender&id=$msg->id&subject=".(strpos($msg->subject, "Re:") === false ? "Re: " : ""). stripcslashes( $msg->subject ), 'rwpm-reply_inbox_msg_' . $msg->id ); ?>"><?php _e( 'Reply', 'pm4wp' ); ?></a>
And, when it only should stay on the beginning:
| <a class="reply" href="<?php echo wp_nonce_url( "?page=rwpm_send&recipient=$msg->sender&id=$msg->id&subject=".(substr($msg->subject, 0, 3) != "Re:" ? "Re: " : ""). stripcslashes( $msg->subject ), 'rwpm-reply_inbox_msg_' . $msg->id ); ?>"><?php _e( 'Reply', 'pm4wp' ); ?></a>
ow about a simple regexp?
$replysubject = preg_replace('/^(Re: )*/', 'Re: ', stripcslashes( $subject ));
This will output a string with just one 'Re: ' at the beginning, regardless of how many of them are in the input string.
In your case:
href="<?php echo wp_nonce_url( "?page=rwpm_send&recipient=$msg->sender&id=$msg->id&subject=" . $replysubject, 'rwpm-reply_inbox_msg_' . $msg->id ); ?>"