WordPress.org

Forums

Co-Authors Plus
[resolved] Possible bug in function coauthors__echo (3 posts)

  1. rcgoncalves
    Member
    Posted 1 year ago #

    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.

    https://wordpress.org/plugins/co-authors-plus/

  2. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    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.

  3. rcgoncalves
    Member
    Posted 1 year ago #

    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.

    EDIT:
    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).

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Co-Authors Plus
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.