Download the PHP package typisttech/wp-option-store without Composer
On this page you can find all versions of the php package typisttech/wp-option-store. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download typisttech/wp-option-store
More information about typisttech/wp-option-store
Files in typisttech/wp-option-store
Package wp-option-store
Short Description Extending WordPress Options API, read options from places other than database, the OOP way
License GPL-2.0-or-later
Homepage https://typist.tech/projects/wp-option-store
Informations about the package wp-option-store
WP Option Store
Extending WordPress Options API, read options from places other than database, the OOP way.
- The Goals, or What This Package Does?
- Install
- Usage
- Example
- ConstantStrategy
- DatabaseStrategy
- OptionStore
__construct(StrategyInterface ...$strategies)
get(string $optionName)
- Type casting
- FilteredOptionStore
get(string $optionName)
- Factory
build(): FilteredOptionStore
- Frequently Asked Questions
- Can I implement my own strategy classes?
- Can I change the order of the strategies?
- Is this a plugin?
- What to do when wp.org plugin team tell me to clean up the
vendor
folder? - Can two different plugins use this package at the same time?
- Do you have real life examples that use this package?
- Will you add support for older PHP versions?
- It looks awesome. Where can I find some more goodies like this?
- Where can I give :star::star::star::star::star: reviews?
- Sponsoring :heart:
- GitHub Sponsors Matching Fund
- Why don't you hire me?
- Want to help in other way? Want to be a sponsor?
- Running the Tests
- Feedback
- Change log
- Security
- Credits
- License
The Goals, or What This Package Does?
WordPress Option API only allows you get_option
from database. This package is for those who not accepting the status quo.
Install
Installation should be done via composer, details of how to install composer can be found at https://getcomposer.org/.
You should put all WP Option Store
classes under your own namespace to avoid class name conflicts.
Usage
Example
ConstantStrategy
This strategy gets options from PHP constants.
DatabaseStrategy
This strategy gets options from WordPress Options API.
Important: An unset value should be null
instead of WordPress' default false
.
OptionStore
This class gets option values from strategies.
__construct(StrategyInterface ...$strategies)
OptionStore
constructor.
- @param StrategyInterface[] ...$strategies Strategies that get option values.
Note: Strategies order matters!
get(string $optionName)
Get an option value.
- @param string $optionName Name of option to retrieve.
Type casting
OptionStore
provides several helper methods for type casting.
FilteredOptionStore
This is a subclass of OptionStore
.
get(string $optionName)
Get an option value.
- @param string $optionName Name of option to retrieve.
Note: Filters are applied before type casting.
Factory
Factory is a helper class to reduce boilerplate code for those who use default strategies. If you use a reorder the strategies, don't use this class.
build(): FilteredOptionStore
Frequently Asked Questions
Can I implement my own strategy classes?
Of course! Just implements the StrategyInterface
.
Take a look at classes ConstantStrategy
and DatabaseStrategy
as well as their tests for example implementations of StrategyInterface
.
If you'd like to create a open-source package to do this to help others, open a new issue to let us know, we'd love to help you with it.
Can I change the order of the strategies?
Why not? Don't use Factory
.
Is this a plugin?
No, this is a package that should be part of your plugin.
What to do when wp.org plugin team tell me to clean up the vendor
folder?
Re-install packages via the following command. This package exports only necessary files to dist
.
Can two different plugins use this package at the same time?
Yes, if put all WP Option Store
classes under your own namespace to avoid class name conflicts.
Do you have real life examples that use this package?
Here you go:
Add your own plugin here
Will you add support for older PHP versions?
Never! This plugin will only work on actively supported PHP versions.
Don't use it on end of life or security fixes only PHP versions.
It looks awesome. Where can I find some more goodies like this?
- Articles on Typist Tech's blog
- More projects on Typist Tech's GitHub profile
- More plugins on TangRufus' wp.org profiles
- Stay tuned on Typist Tech's newsletter
- Follow @TangRufus on Twitter
- Hire Tang Rufus to build your next awesome site
Where can I give :star::star::star::star::star: reviews?
Thanks! Glad you like it. It's important to let my know somebody is using this project. Since this is not hosted on wordpress.org, please consider:
- tweet something good with mentioning @TangRufus
- :star: star this Github repo
- :eyes: watch this Github repo
- write blog posts
- submit pull requests
- sponsor Tang Rufus to maintain his open source projects
- hire Tang Rufus to build your next awesome site
Sponsoring :heart:
Love WP Option Store
? Help me maintain it, a sponsorship here can help with it.
GitHub Sponsors Matching Fund
Do you know GitHub is going to match your sponsorship?
Sponsor now via GitHub to double your greatness.
Why don't you hire me?
Ready to take freelance WordPress jobs. Contact me via the contact form here or, via email [email protected]
Want to help in other way? Want to be a sponsor?
Contact: Tang Rufus
Running the Tests
Run the tests:
Feedback
Please provide feedback! We want to make this project useful in as many projects as possible. Please submit an issue and point out what you do and don't like, or fork the project and make suggestions. No issue is too small.
Change log
Please see CHANGELOG for more information on what has changed recently.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
WP Option Store
is a Typist Tech project and maintained by Tang Rufus, freelance developer for hire.
Full list of contributors can be found here.
License
The MIT License (MIT). Please see License File for more information.