• Resolved nsp-code

    (@nsp-code)


    Hi,
    I’m the developer of WP Hide plugin https://www.ads-software.com/plugins/wp-hide-security-enhancer/ currently with +60000 active users.

    Our code helps to change default WordPress assets URLs like –domain–/wp-content/themes/my-theme/style.css and –domain–/wp-includes/js/wp-emoji-release.min.js to something else ( e.g. –domain–/custom-slug/style.css and –domain–/inc/wp-emoji-release.min.js). The problem is, when using your plugin, there is no filter available on your side which we can use in our code to change those URLs with customized ones.
    There is an easy approach for this, you should add a filter on your code which we can use to filter the content, before is being saved locally. So at /classes/autoptimizeCache.php at function cache(), at the top of the function code can you add a filter like this:

    $data = apply_filters( ‘autoptimize_optimized_to_cache’ , $data, $mime );

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    but there is; autoptimize_html_after_minify ??

    have fun,
    frank

    Thread Starter nsp-code

    (@nsp-code)

    Hi Frank,
    Sorry but the filter autoptimize_html_after_minify is being used for HTML buffer and not for any optimized CSS or JavaScript, which appears to be saved locally into /wp-content/cache/autoptimize
    Also the mentioned filter trigger after all local cached optimized files has been created.
    So the filter can be found within /classes/autoptimizeMain.php at line 515, but the code which produce the cached assets are right above, in the loop, at line 507:
    $instance->read ( .. ). The stack of calls, for a CSS appears to be the following:

    /classes/autoptimizeCache.php line 507, autoptimizeStyles->read(.. )
    /classes/autoptimizeStyles.php line 342, minify_single()
    /classes/autoptimizeStyles.php line 1232, cache()
    /classes/autoptimizeCache.php line 96, function cache() where your code write the $data into static files
    Still, during the above chain there is no filter which can be used to make changes to the css data before being saved.

    As mentioned above, i think the best place to place a filter is at /classes/autoptimizeCache.php at function cache(), at the top. This is the location being invoked by both your css and javascript autoptimize classes, so through the filter it can catch everything.

    Again, the reason for why i need a filter, is, for example, if a CSS asset contain an URL, our plugin can’t reach to update it, before your code save it locally.

    Hope this helps.

    Thanks

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    well, you also have autoptimize_js_after_minify and autoptimize_css_after_minify at your disposal ??

    Thread Starter nsp-code

    (@nsp-code)

    Actually i’am aware of the mentioned filters, still they also trigger after the assets data has been saved locally into cache files.
    So, as specified in my last message, at /classes/autoptimizeMain.php the code call which produce the cached assets is at line 507 $instance->read ( .. ) but your mentioned filters are used in the next call at line 508 $instance->minify(), obviously after the static caches has been already created.

    I believe you can try it on your side, add the filters into your theme functions.php and attempt to change something into a cached file, you will see nothing changes. Or, you might want to take a closer look by runing into a debug.

    Thanks

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    no, you’re wrong :-p

    instance->read is to get the options for active optimization classes (JS and/ or CSS and/ or HTML). then for each optimization class it does minify first and cache second and getcontent last. the filters are part of minify so are active before the aggregated & minified CSS/ JS is saved to cache.

    Thread Starter nsp-code

    (@nsp-code)

    This is partially correct, check with actual code, i’am sure you will understand.
    Please check with autoptimizeStyles->read() function, at lines 267-365, you have a loop which includes an IF clause with 3 possibilities:
    #1 lines 268-269
    #2 lines 270-328
    #3 lines 329-364
    on last one (#3) at line 342, you have a function minify_single() which goes to cache procedure, meaning it actually create a static cache file before minify ! The outputted filenames for such content are autoptimize_single_HASH

    Hope this makes sense.
    If you can give your e-mail i can send more details to track the issue, as however this discussion is very technical and might not help anyone else.

    Thanks

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    ah, the non-aggregated ones ??

    just added filters, see https://github.com/futtta/autoptimize/commit/5fb94677c40a72d816707aafcd18f60912e258fd, will be in AO 2.7.4 ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Unable to filter the buffer before being saved locally into cache’ is closed to new replies.