the-events-calendar / the-events-calendar-category-colors

Plugin add-on for The Events Calendar to colorize categories
https://wordpress.org/plugins/the-events-calendar-category-colors
44 stars 19 forks source link

Allow file write operations to be disabled with a filter #136

Closed kadamwhite closed 2 years ago

kadamwhite commented 2 years ago

On WordPress VIP this plugin appears to work correctly from an end-user's perspective, but it throws dozens and dozens of errors in the PHP logs because write operations are not permitted on WordPress VIP outside of a specific temp directory. (Most enterprise-grade hosts lock down file operations in a similar fashion.)

This PR introduces a new filter teccc_write_files which can be used to opt out from file writes and rely solely on the transient for storing the CSS.

Example usage:

// Turn off file operations to silence PHP errors on deployed environment.
add_filter( 'teccc_write_files', '__return_false' );
afragen commented 2 years ago

Hey @kadamwhite thanks for the PR. I think we need to include some method of saving the CSS to a transient and then loading the CSS from the transient.

afragen commented 2 years ago

Long ago I think I just wrote all the CSS into the <head>. I switched to using a file as it created a small page size and could be cached.

Any thoughts on how to load the CSS in this instance?

afragen commented 2 years ago

@kadamwhite I think I came up with a better solution. In the past I was loading the CSS in wp_head. I found this to be very inefficient and so I began writing the CSS to a file and enqueuing it. While looking for a solution to your issue. I discovered that I could enqueue the CSS string using wp_add_inline_style().

What I came up with was saving the generated CSS as an option expiring after 4 weeks or on a refresh_css query arg. I then add the CSS using wp_add_inline_style(). No more files.

Let me know what you think and how it works for WordPress VIP. It's in the no-file branch.

kadamwhite commented 2 years ago

@afragen That sounds very promising! I don't think my proposal would have prevented the transient from being set, but agree switching to an inline style sounds like a more robust solution. I should be able to test the updated code in the next two days, but thankfully I see my delayed response didn't hold you up 🙂

afragen commented 2 years ago

I've merged it into the develop branch so testing that will be sufficient.

CSS should refresh by adding the refresh_css query arg to a calendar URL or by saving and Category Colors settings.

I also fixed a ton of WPCS linting issues.

kadamwhite commented 2 years ago

@afragen Plugin is working great on our dev environment on VIP, colors are there as expected and log is blissfully silent. Thanks for the quick action! We'll upgrade in production as soon as a new full version is pushed out, but no rush at all on our end.

I'm going to close this PR out. Thank you again!

afragen commented 2 years ago

Merged and pushed to dot org. Thank you. 🙇