Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter FredTheAnt

    (@fredtheant)

    Couldn’t wait. Debugged it myself. ??

    The strip_tags function is removing more text than, I think, you expected it to. On the blog post I linked to above, it was truncating everything subsequent to the first inline html element included with my blog post. Specifically, it returned everything up to ‘At one point I spent something like $50 bucks on a’ and truncated the rest. The next word in that sentence is encapsulated in an anchor element. My quick fix was to remove all occurrences of strip_tags from your code. The word counts might be slightly inflated now, but that’s better than severely reduced. There’s probably a better way to address the situation, but I’m not a PHP guy. I’ll leave that to you.

    On a side note, I went ahead and added this:

    $full .= $time_in_minutes == 1 ? 'minute' : 'minutes';
    $full .= '</p></span>';

    Maybe in a future release, something like that can be included as well so that we see “1 minute” rather than “1 minutes”.

    – Nick

    Plugin Author paperleaf

    (@paperleaf)

    Hey Fred,
    Thanks for pointing this out.

    So I think what was actually happening was that we were stripping tags off of the variable $content rather than off of a temp variable, holding the content. This caused the content to become a different length than intended, skewing the reading numbers.

    When calculating the word count length in from a WordPress content section, though, you need to calculate the word count from the content with the tags pre-stripped.

    This should all be fixed in the update that was pushed this morning. Again, thank you for brining this up.

    The next question is when did you see the ‘1 minutes’ text occur? Is there anyway you could provide the length of the post, and your settings so I can try to duplicate this on our test environment? If you can, send this in an email to [email protected].

    Thanks again.

    Thread Starter FredTheAnt

    (@fredtheant)

    Just tried your fix; didn’t work. :\

    Not sure I understand why saving $content to a temp variable would help? Why would you expect different results for…

    $temp = $content;
    $word_count = str_word_count( strip_tags( $temp ) );

    versus…

    $word_count = str_word_count( strip_tags( $content ) );

    ?

    Both return the same value for $word_count, at least when I run it. Do you get different results?

    Regarding the ‘1 minutes’ thing, your code is hardcoded to show ‘minutes’ (plural) by default:

    $full .= 'minutes</p></span>';

    Plugin Author paperleaf

    (@paperleaf)

    It seemed as though there was an issue with the $content variable, as that’s what we were using to output the content. I assumed that it was outputting a shortened version, but it seems that didn’t fix the problem you were having.

    I’m unsure as to why this is happening on your post. Is there anyway you can send me the full HTML output of your post’s first paragraph, or even write it in here? The function strip_tags should only be parsing out the HTML elements of the post, and leaving the plain text to be counted by str_word_count. This seems to be working on our test servers here, and we haven’t had this bug come up before, so I’d like to dig a little deeper into this.

    As for the minutes question, you are correct that is it hardcoded to show minutes (plural), but not by default. To show minutes rather than minute it has to pass through this if statement: if ($time_in_minutes < 1).

    Can I ask your exact word count for this specific post you’re talking about? It might help me trouble shoot more if I can recreate the environment locally.

    Thanks

    Plugin Author paperleaf

    (@paperleaf)

    Hey Fred,

    Please let us know if you’re continuing to have this problem, or if has been solved. If you’re still having this problem, please refer to the last post we’ve made.

    If there isn’t a response in the next week, I’ll mark this as resolved.

    Thanks!

    Nick

    (@refactorsaurusrex)

    Hey sorry, I’ve been on vacation. I’ll respond as soon as I can.

    Nick

    (@refactorsaurusrex)

    Here’s the raw text of the post in question:

    https://gist.github.com/refactorsaurusrex/25ef46797544aa8be7df

    Sorry for the delay,

    Nick

    Nick

    (@refactorsaurusrex)

    Hey guys,

    Any updates on this?

    Thanks,

    Nick

    Plugin Author paperleaf

    (@paperleaf)

    Hey Nick,

    Sorry for the delay here! Swamped with client work – we’ll try and get to this and get back to you this upcoming week.

    Plugin Author paperleaf

    (@paperleaf)

    Hey Nick,

    Can you try this for me?

    In your post right now is this line of text:

    At one point I spent something like $50 bucks on a <a href="https://www.refactorsaurusrex.com/wp-content/uploads/2014/11/AtlasBookStand.jpg" title="Book Stand" class="lightbox" data-lightbox-gallery="fancybox-item-01", ">professional book stand</a>

    Can we change it to this:
    At one point I spent something like $50 bucks on a <a href="https://www.refactorsaurusrex.com/wp-content/uploads/2014/11/AtlasBookStand.jpg" title="Book Stand" class="lightbox" data-lightbox-gallery="fancybox-item-01">professional book stand</a>

    I think there was a syntax error in the inline-link, which caused the strip_tags to pull out more than necessary.

    Let me know if that works.

    Nick

    (@refactorsaurusrex)

    Wow. I cannot believe I missed that. All my internet points to you. That seems to solve the problem.

    Thank you!

    Thread Starter FredTheAnt

    (@fredtheant)

    <logged in with old profile to mark thread as resolved>

    Plugin Author paperleaf

    (@paperleaf)

    Yes! MOAR INTERNET POINTS!

    Thanks Nick, happy it all works.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Wrong math?’ is closed to new replies.