• Hey Frank, hope you’re well,

    I was wondering is you might clarify the most proper use of autoptimize_helper.php.

    What we have been doing is simply inserting the filter(s) we need in a theme’s functions.php and calling it a day. The instructions, however, seem to imply that this is not the best way of making use of the Helper/its filters.

    I’ll explain:

    How can I use/ activate autoptimize_helper.php_example?

    Copy it to /wp-content/plugins/autoptimize_helper.php and activate it in WordPress’ plugin page. After that you can simple remove the one of the comment-sequences (double-slash) to activate one (or more) of the functions in there.

    1.) I don’t quite understand what is meant by “Copy it to /wp-content/plugins/autoptimize_helper.php and activate it in WordPress’ plugin page”. The helper is already there in the plugin’s files, so from where and to where is it supposed to be “copied”?

    2.) As the instructions read, there is apparently supposed to be a second, separate AO plugin available on the Plugins page in WP Admin so long as one has “copied” autoptimize_helper.php to /wp-content/plugins/autoptimize_helper.php… Is this correct or am I reading this incorrectly?

    I have a couple more questions but need to know the answers to the above to know which ones to ask.

    Anyway, it’s not infrequently that we get the ‘White Screen of Death’ when attempting to add AO’s filters via a theme’s functions.php, especially when attempting to make use of more complicated filters (attempting to return different inlined CSS for different URLs as a primary example). So, I thought I’d try and get some direction so that we’re using the Helper and its filters in the most technically appropriate manner.

    Best, and thanks as always,
    AJ

    https://www.ads-software.com/plugins/autoptimize/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Frank Goossens

    (@futtta)

    adding stuff to your theme’s functions.php is OK, as long as there are no updates to the theme, as those typically overwrite the modified functions.php. so best practice is to either create a child theme with it’s own functions.php or to create a separate plugin with the code that uses the API.

    autoptimize_helpers.php_example is aimed to be used as a template for a separate plugin (the 2nd approach), which should indeed be copied (without trailing “_example” in the name) to /wp-content/plugins, after which it can be activated as a 2nd autoptimize plugin (“autoptimize helper”).

    hope this clarifies,
    frank

    Thread Starter AJ @ WpFASTER.org

    (@ajm_1976)

    That does clarify, thanks!

    After that you can simple remove the one of the comment-sequences (double-slash) to activate one (or more) of the functions in there

    I understand that this activates the filter, but I’m not clear as to how to then specify exactly what we want the filter doing and where that specific code is to go…

    After un-commenting the generic filter in the “autoptimize helper” plugin so as to activate that filter,
    A.) are we, other than un-commenting it, otherwise not touching the generic filter?
    B.) Where do we put the specific filter code i.e. the code with specific instructions (I’m guessing at the bottom of “autoptimize helper”?)

    For Example:

    .
    .
    .
    .
    /* autoptimize_filter_css_datauri_exclude: exclude background images from being turned into data uri's;
    
    @param $imageexcl: default images excluded (empty)
    @return: comma-seperated list of images to exclude */
    add_filter('autoptimize_filter_css_datauri_exclude','my_ao_exclude_image',10,1);
    function my_ao_exclude_image($imageexcl) {
    	return "adfreebutton.jpg, otherimage.png";
    	}
    
    .
    .
    .
    .
    .
    
    (End/bottom of autoptimze helper plugin template)
    
    add_filter('autoptimize_filter_css_datauri_exclude','my_ao_exclude_image',10,1);
    function my_ao_exclude_image($imageexcl) {
    	return "1specific.jpg, 2specific.jpg,, 3specific.jpg, 4specific.jpg,";
    	}

    ^ Would that be correct?

    Hope I’m making sense,
    AJ

    Plugin Author Frank Goossens

    (@futtta)

    that would not be correct, as in that case you’d be declaring the my_ao_exclude_image-filter twice.

    best approach would be to remove everything in the file and just add you own filters (prepended with AJ_, so AJ_ao_exclude_image) just using the (then removed) code as an example.

    your own code (that filters the input from the hook) would be inside the function. an example;

    add_filter('autoptimize_filter_css_datauri_exclude','AJ_ao_exclude_image',10,1);
    function AJ_ao_exclude_image($imageexcl) {
    	return "background1.jpg, background2.jpg";
    	}

    Do take care of what you are doing, because as you wrote earlier using the API can break your sites, so test extensively! ??

    frank

    Thread Starter AJ @ WpFASTER.org

    (@ajm_1976)

    Great, Frank, thanks. You’re always such a big help. ??

    AJ

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Clarification on the Use of autoptimize_helper.php’ is closed to new replies.