Support » Plugin: Co-Authors Plus » Possible bug in function coauthors__echo

  • Resolved rcgoncalves


    I believe function coauthors__echo has a bug in line 169:
    $output = rtrim( $output, $separators['between'] );

    Depending on what we use as $separators['between'], rtrim may remove more characters than we want.

    I noticed this bug we making the following call:
    coauthors_posts_links( '</span> <span class="author vcard">', '</span> <span class="author vcard">', '<span class="author vcard">', '</span>', false )

    Basically, I’m trying to put some tags around each author (I don’t know whether there is a better way to achieve this goal). In this case, at least the </a> closing tags will also be removed.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Daniel Bachhuber


    Hand Built

    Depending on what we use as $separators[‘between’], rtrim may remove more characters than we want.

    Yep, it looks like that’s what you’ve run into 🙂 rtrim() is there because the default between is a comma that we strip out (I wasn’t involved in the original decision making to do this).

    I don’t have an immediate answer for you, unfortunately. I *think* we could have a check to see the nature of between, and only conditionally apply rtrim(). I’ve added test coverage to the roadmap for the next release, so I’ll do my best to work out a solution before it’s released. For now, I’d recommend removing the rtrim() call in your version of the plugin, and making a note to apply the fix when WordPress prompts you to update the plugin.

    FWIW, here is how I fixed the bug:

    // Append separators
    if ( ! $i->is_first() && ! $i->is_last() && $i->count() > 2 )
        $output .= $separators['between'];
    if ( $i->is_last() && $i->count() > 1 ) {
        $output .= $separators['betweenLast'];

    I added the ! $i->is_last() in the previous conditional. I guess not adding the separator at all provides a more robust solution than removing it later.

    I cannot simply remove the rtrim, as there is text that needs to be removed. The problem was that rtrim was removing more text than it should.

    I’ve also noticed that the $i->count() > 2 in the first if is useless with the change I made (if an element is neither the first nor the last, there are certainly more than 2 elements).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Possible bug in function coauthors__echo’ is closed to new replies.