• Resolved verygoodplugins

    (@verygoodplugins)


    Hey guys,

    Sometime in the last couple of updates Helpful stopped respecting the admin settings.

    I’ve set up a test page at https://wpfusion.com/documentation/additional/helpful-test/

    If you look at the settings here https://share.getcloudapp.com/8LukXG0W

    1. It should not show the form for a Pro vote
    2. When a negative vote is left, the message should be displayed

    In both cases the form is displayed, but no message.

    This affects logged in users, and guests.

    If I enable the “Show form after positive vote” setting, the form is still shown, and no message is shown (it does not make any difference)

    In version 4.4.26, both the positive and negative votes showed the message “Thank you very much. Please write us your opinion, so that we can improve ourselves.” (the default message), despite settings being configured in the admin.

    Updating to 4.4.27 removed the default message, and now no message is shown.

    You can see the Helpful options from the database here https://share.getcloudapp.com/E0u9x2X7

    They all seem correct.

    I tracked down part of the issue to /helpful/core/helpers/class-feedback.php, around line 442

    $type = User::get_user_vote_status( $user_id, $post_id );

    $type is always blank. So there’s no vote status.

    I tried to fix that by adding

    if ( isset( $_POST['type'] ) ) {
        $type = sanitize_text_field( $_POST['type'] );
    }

    but it still didn’t fix the messages or the form display.

    As well, this was working correctly, with no form for positive vote / form + custom message for negative vote as recently as January. We haven’t really changed much on the site. The page is cached, but we have the nonces disabled (which was working before). And regardless, the same bug affects logged in users, who shouldn’t be cached.

    I was going to roll back to the January update of Helpful but thought I’d post here first in case you have any ideas. Thanks!

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Pixelbart

    (@pixelbart)

    @verygoodplugins

    Thank you for your detailed feedback!

    I will look at the whole thing the days and see that I get your problem solved. As soon as I have found a solution and installed the update, I will get back to you here!

    Thanks again and stay healthy!

    Plugin Author Pixelbart

    (@pixelbart)

    @verygoodplugins

    The two bugs should be fixed. The default text is no longer shown, because that had ensured that it was always shown even if you do not want any text there.

    Thank you again!

    Thread Starter verygoodplugins

    (@verygoodplugins)

    @pixelbart thanks for the fast reply!

    Unfortunately it’s still not working at https://wpfusion.com/documentation/additional/helpful-test/ (with the latest update).

    To rule out caching, I’ve installed the latest Helpful on our test site (uncached) at https://test.verygoodplugins.com/helpful-test/

    And it is working there ??

    But…. we can’t leave our entire documentation uncached (they get a lot of traffic).

    All requests to admin-ajax.php should be uncached. Helpful is the only plugin we’ve had cache problems with. If you inspect the Network traffic while leaving a vote at https://wpfusion.com/documentation/additional/helpful-test/ you can see the cache control headers are set to bypass.

    As well, even if the response was being cached, that shouldn’t affect the display of the “Message (Pro)” and “Message (Contra)” strings. Worst case if we had a super-aggressive cache situation we’d see the same response message every time, but here we see no response message at all.

    Just wondered if you had any other ideas? Maybe there’s an aspect of the Helpful config that’s using wp_cache_get() or get_transient() that might be getting messed up by Varnish or Redis. I can also dig into the code and see if I can fix it but I don’t have any extra time this week.

    Thanks

    Plugin Author Pixelbart

    (@pixelbart)

    @verygoodplugins

    Helpful uses the transients only for the statistics in the dashboard. Otherwise it does not work with a cache.

    I can’t see any error there now. On my pages it works everywhere. We also have pages with more than 1000 visitors a day and we don’t use a cache. Nevertheless pagespeed at 98 points.

    I can’t think of anything at the moment. I will think about it. If you think of something else, I am always open. Check the settings of Helpful, if the texts are all set correctly.

    The type none is passed on in the Ajax request, but is no longer used in the request itself. So this can’t be the problem anymore.

    Thread Starter verygoodplugins

    (@verygoodplugins)

    @pixelbart Thanks, I think we’ve got it working better now… added a cache exclusion rule for the “helpful_user” cookie, and then flushed everything. Looks okay now ??

    Plugin Author Pixelbart

    (@pixelbart)

    @verygoodplugins

    Yes the user cookies is always a problem, somehow. That’s why I had built options for it, in case you only want to use sessions or something like that.

    But good to know! I guess I wouldn’t have a better solution either, since this is really always very specific.

    Thread Starter verygoodplugins

    (@verygoodplugins)

    @pixelbart Me again, your favorite person ??

    I should really be working on my own plugins, but tweaking Helpful is more fun.

    Anyway I’m messing around with this a bit today and I have some more feedback. Thanks for your patience so far!

    1. The issue I was running into yesterday was actually not related to the AJAX request being cached, I got hung up on that. It’s related to the localized Helpful script data, specifically

    "ajax_data":{"user_id":"2aab8c6e938962e813161494e01c0c27","_wpnonce":"0b987620ca"}

    When the page is cached, this causes every vote from every visitor to be recorded in the wp_helpful table as from the same user.

    Then, when after_vote() runs and queries User::get_user_vote_status(), the user ID from the helpful_user cookie is used (which is unique to the visitor). Since the cookied ID doesn’t match the user_id that was recorded in the table, a status of “none” is returned from User::get_user_vote_status(), and no confirmation message is displayed.

    To get around that I made two changes. There might be a better solution.

    1. I added this filter:

    add_filter( 'helpful_frontend_ajax_vars', function( $vars ) {
    
    	if ( ! is_user_logged_in() ) {
    		unset( $vars['ajax_data'] );
    	}
    	return $vars;
    
    } );

    since the ajax_data wasn’t helping anyway. It would make sense if the existing setting “Disable nonces” in Helpful also disabled the ajax_data nonce, and it might help other people, but since there’s a filter that works for me.

    Then as a fallback, in Helpful\Core\Helpers\Feedback, I added at line 442, after $type = User::get_user_vote_status( $user_id, $post_id );:

    if ( 'none' == $type && isset( $_POST['value'] ) ) {
       $type = sanitize_text_field( $_POST['value'] );
    }

    That’s just to deal with cases where a vote has just been submitted but it can’t be found in the DB (could probably be handled better but it works for me).

    Finally, during a single vote, after_vote() runs three times, each time hitting the database (via User::get_user_vote_status( $user_id, $post_id );) with an un-cached query. Not great for performance.

    (If it helps, here’s the backtrace from a single vote: https://pastebin.com/aejsUzcv)

    ? The first one makes sense, we call Helpers\Feedback::after_vote() in Helpful\Core\Modules::save_vote()

    ? However, then you call Helpers\Values::convert_tags() with the response, and this calls Helpers\Feedback::after_vote() again, which triggers another database hit.

    This does not spark joy ??

    Since we’re already passing the after_vote() output, let’s re-use it, and change Helpful\Core\Helpers::convert_tags()` line 107 to

    '{feedback_form}' => $string,

    and line 111 from

    Feedback::after_vote( $post_id, true )

    to

    $string

    and that would fix it, saving us two extra database hits.

    Anyway we now have everything working reliably, and tracking votes via cookies, despite our cached pages being served from Cloudflare’s Edge servers.

    So…. I’m happy. I could probably spend some more time optimizing but I need to get back to work ??

    Thanks again
    Jack

    Plugin Author Pixelbart

    (@pixelbart)

    @verygoodplugins

    Once again great feedback. Thank you! 4 eyes see more than two and since I only do Helpful in my spare time (I’m a salaried web developer myself, doing everything just for fun in my spare time), I like to overlook a few things or fix bugs just for the heck of it.

    Therefore: Thank you very much for your feedback! With the latest update, your changes should have found their way into Helpful. I changed them a bit, but at the core they are your changes. Thanks again for your time!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Settings not being respected’ is closed to new replies.