Comments (9)
I like the pre_option way of doing it b/c you can see it easier in the codebase. People understand how it relates to WordPress by using a core function. By doing an array compare, you are introducing custom logic that might be foreign to outsiders. You are also introducing a storage place for the temp version. Where does that get stored? Can it be lost or corrupted? How can you delete it when needed?
from intervention.
Yes, I have the same question.
In principle, the pre_option_{$option}
seems better, which bypass all the logic of the get_option
function and returns the desired value. The downside is that you lose all settings when exporting or if you need to disable Intervention.
The update_option
store your config on DB and solves previous downside. It should really only update on the first page load because update_option
compares the values and if they are equal, they are not updated and there is no database hit. But there is a problem with numeric values: they are strictly compared with DB (string) value and always return false so forces an DB update on every page load.
I have actually added a filter that prevents this problem on this branch (I'm not sure if it's the best file to add this code) and stops with DB updates on every load.
I am open to suggestions to modify it or to make a pull request ๐
from intervention.
I'm all with @claytoncollie here. pre_option
seems the better option IMO. I think it's fair to assume that using the plugin is short cutting options handling and obviously deactivating it will result in falling back to default, unchanged, database options. Describing clearly that behavior in the readme should be enough.
Maybe the best option would be to introduce a way to manually set options to DB if needed?
from intervention.
Hey @claytoncollie,
I'm open to the suggestion of changing to pre_option
, initially I wanted to update the DB value, but perhaps that's not necessary. What's your thoughts? I'm trying to preempt any downsides to using pre_option
for users.
from intervention.
I have not used this package yet so this is only thinking out loud. If you enabled all options in your config array then went to random pages in the wp-admin with Query Monitor turned on, you could see how many queries are being generated on each page load. My thought is that you are performing 2 database actions for each page load for each option. First to make the update_option
call, then the standard get_option
call afterward. With pre_option_
it might be able to get rid of both. The only problem is that your database is not a source of truth anymore when you export for some reason. Pushing and pulling between environments would be fine if the codebase is version controlled, but your DB could potentially be "out of date" to what your config is.
My original question was to see if any thought was given to it and if using update_option
was a conscious decision. Sounds like it was when you first started the project. I don't know the project well enough if you can give the option to filter the option or update the database.
from intervention.
Hey @claytoncollie,
Let me give it some more thought and do a little prototyping, perhaps an approach that uses both, only updating the DB at certain intervals, or on the dashboard/settings pages, or a version of that, and pre_option
otherwise.
Edit: Thinking about it more, I don't think it's a deal breaker if the DB actually doesn't update, the plugin should always be enabled to pass across those options in my opinion. I'll keep this issue open so that others can also weigh in.
from intervention.
Hey @pacotole,
This looks great, thank you! I think having it in that file is perfect.
I'll do some prototyping with update_option
and pre_option
.
Another line of thought could be comparing the application config with a temp version, and if there are changes to the application config, updating the DB and the temp version. Then we wouldn't even really need pre_option
, while also removing unnecessary requests/guesswork. Thoughts?
Edit: PR request for the above would be great, I'll prob change array_map
to an Laravel collection to match the rest of the codebase, but I can change that up!
from intervention.
Yea, fair points that I agree with, thanks for thinking that through. Alright, so letโs go with pre_option
and an occasional DB request! Iโll take a look at getting it changed soon.
from intervention.
This has been addressed in d5ee64 with a new internal Options API, which now uses pre_option
.
from intervention.
Related Issues (20)
- Composer dependency incompatibilities with Sage 9 HOT 7
- Remove activate and deactivate actions when defining plugin state in config HOT 5
- Publish plugin to wordpress.org HOT 3
- [application.media] HOT 18
- Add support for WordPress code style/format/linting HOT 3
- Fatal error HOT 22
- [Featured Request] Additional Page Attribute Settings HOT 3
- Post types with "-" HOT 4
- Upgrade illuminate/collections HOT 2
- Settings to disable WP components
- Deprecated messages on PHP 8.2 HOT 1
- Need help to install plugin HOT 3
- Docker + Roots wrong composer inclusion path HOT 7
- Plugin could not be activated because it triggered a fatal error HOT 3
- Noob trouble trying to get Intervention working. HOT 7
- Something goes wrong setting options / saving to database HOT 7
- Rename the master branch to main HOT 2
- Feature idea: add theme supports HOT 2
- Translatable labels HOT 2
- Setting timezone through intervention without setting it in the DB: new posts are scheduled HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from intervention.