Support » Plugin: Autoptimize » Enable 404 fallbacks option – code issue

  • Resolved AITpro

    (@aitpro)


    On 3 separate sites on 3 different host servers the Enable 404 fallbacks option code below is not creating the ErrorDocument 404 line of htaccess code in the Autoptimize cache folder htaccess file.

                if ( self::do_fallback() === true ) {
                    $content .= "\nErrorDocument 404 " . trailingslashit( parse_url( content_url(), PHP_URL_PATH ) ) . 'autoptimize_404_handler.php';
                }
                @file_put_contents( $htaccess, $content ); // @codingStandardsIgnoreLine
Viewing 15 replies - 1 through 15 (of 22 total)
  • AITpro

    (@aitpro)

    Wow ok this is weird. I deactivated and reactivated AO and the problem was still occurring. I’m pretty sure that I resaved option settings, but maybe I didn’t previously. I deactivated and reactivated AO again and resaved the option settings and this time the ErrorDocument line of htaccess code was successfully created.

    • This reply was modified 1 month ago by AITpro.
    • This reply was modified 1 month ago by AITpro.
    • This reply was modified 1 month ago by AITpro.
    • This reply was modified 1 month ago by AITpro.
    AITpro

    (@aitpro)

    Ok I see the issue that happened now. Uninstalled AO, reinstalled AO, the ErrorDocument line of htaccess code is not created in the AO cache htaccess file even though the Enable 404 fallbacks option is checked by default. Clicked the AO Save Changes button with the Enable 404 fallbacks option checkbox checked does not create the ErrorDocument line of htaccess code. Deactivating and reactivating AO DOES automatically create the ErrorDocument line of htaccess code. So it looks like even though the Enable 404 fallbacks option checkbox is checked, things are not happening as they should be. 😉

    • This reply was modified 1 month ago by AITpro.
    AITpro

    (@aitpro)

    On one of the sites when the AO Enable 404 fallbacks option is used WooCommerce Store/Shop links are broken with 404 errors IF the BPS Root BulletProof Mode htaccess file is in play/activated. That was what I was originally troubleshooting. Anyway that is a problem for another day since unchecking the Enable 404 fallbacks option no longer breaks the WooCommerce Store/Shop links. When I have time to dig deeper into why that is occurring on that 1 particular site, I’ll let you know why that is.

    • This reply was modified 1 month ago by AITpro.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    when you enable the option, try removing the existing .htaccess file to allow AO to re-write it?

    AITpro

    (@aitpro)

    The only existing AO htaccess file in the /wp-content/cache/autoptimize/ folder was the htaccess file that AO created. I did experiment with that though already. The results are exactly the same with the difference being that AO creates a new AO htaccess file with the ErrorDocument line of htaccess code in it. ie on first time AO plugin installation and activation the AO htaccess file is created, deleted the AO htaccess file, clicked the AO Save Changes button with the Enable 404 fallbacks option checkbox checked does not create the ErrorDocument line of htaccess code, deactivate and reactivate the AO plugin
    again does create the ErrorDocument line of htaccess code.

    • This reply was modified 1 month ago by AITpro.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    and when you click “save changes and empty cache”?

    AITpro

    (@aitpro)

    Before doing any additional testing I have a question. The question is this: Is the Enable 404 fallbacks option supposed to be pre-saved by default or is the Enable 404 fallbacks option checkbox checked as a “recommended” option setting? The way my plugin’s checkbox forms work is that a checkbox is only checked if the option’s form value = isset. Or in other words, that particular plugin option is already saved to the DB if the checkbox is checked when the form is not being submitted.

    • This reply was modified 1 month ago by AITpro.
    • This reply was modified 1 month ago by AITpro.
    AITpro

    (@aitpro)

    Your are using this form “checked” processing code:
    echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) ? 'checked="checked" ' : ''; ?>

    I typically use the WordPress checked() function:
    checked( $PFW_whitelist_options['bps_pfw_google'], 1 );

    What I will look at next is to see if the db option value for the Enable 404 fallbacks option is saved to the DB on AO installation and activation. Then check through the various stages for when the Enable 404 fallbacks option is saved to the DB.

    • This reply was modified 1 month ago by AITpro.
    AITpro

    (@aitpro)

    I checked through all of your code and I don’t see an instance of the update_option() function used for the Enable 404 fallbacks option. So maybe you do not want the Enable 404 fallbacks option to be pre-saved to the DB?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    it’s set in the dafaults on code level, see https://github.com/futtta/autoptimize/blob/beta/classes/autoptimizeConfig.php#L755

    that being said, I seem to have forgotten to also assume it’s on if the setting is fetched but not found in a autoptimizeCache.php on line 650, will update that on beta.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    and pushed to beta 🙂

    AITpro

    (@aitpro)

    AO Testing for the Enable 404 fallbacks option:
    ###################################

    Plugin installation and activation:
    ###################################
    The Enable 404 fallbacks option form checkbox is checked.
    The AO htaccess file is created without the ErrorDocument line of htaccess code.
    The autoptimize_cache_fallback DB option does NOT exist (is not pre-saved to the WP DB).

    Clicking the “Save Changes” button on the Autoptimize Settings page:
    ###################################
    The Enable 404 fallbacks option form checkbox is checked.
    The AO htaccess is not updated/written to. The ErrorDocument line of htaccess code is not written to the AO htaccess file.
    The autoptimize_cache_fallback DB option does exist/has been created/saved with a value of: on
    Note: The DB option value is NOT serialized.

    AO htaccess file deletion and resaving of AO plugin settings:
    ###################################
    The Enable 404 fallbacks option form checkbox is checked.
    The AO htaccess is updated/written to. The ErrorDocument line of htaccess code is written to the AO htaccess file.

    AO plugin deactivation and reactivation:
    ###################################
    The Enable 404 fallbacks option form checkbox is checked.
    The AO htaccess is updated/written to. The ErrorDocument line of htaccess code is written to the AO htaccess file.

    Summary|Conclusion:
    ###################################
    Either the Enable 404 fallbacks option is not intended to be pre-saved and the checkbox is checked as a “recommendation” or there is a logic flaw in the AO code.

    • This reply was modified 1 month ago by AITpro.
    • This reply was modified 1 month ago by AITpro.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    guess your reply is held in moderation, but I did receive it by notification mail already aitpro 🙂

    feedback:
    -> do also test with “save changes & empty cache”
    -> do test with the beta-version which has the previously mentioned bugfix

    AITpro

    (@aitpro)

    The post/thread is currently being held in moderation after 2 edits and I need to do 1 more edit for 1 more typo. Pending update once a WP moderator has had a chance to review the post/thread. The edit/typo is this: The AO htaccess “file” is…

    AITpro

    (@aitpro)

    Well I think the test results show that there is an issue unless I am misunderstanding the intention of the Enable 404 fallbacks form checkbox. The issue would either be that it is unclear that the Enable 404 fallbacks is already enabled on plugin installation and activation or the checkbox is checked as a “recommendation” and is not enabled until someone saves AO settings, but that still leaves this issue > The ErrorDocument line of htaccess code in the AO htaccess file is NOT created when clicking the Save Changes button on the AO Settings page. To me it seems like this is a bug that needs to be taken care of. 😉

Viewing 15 replies - 1 through 15 (of 22 total)
  • You must be logged in to reply to this topic.