-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce the class PLL_Options #1237
Conversation
include/options.php
Outdated
'sync' => array(), | ||
'taxonomies' => array(), | ||
'uninstall' => false, | ||
'version' => '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With #1267 in mind, I believe that this should default to POLYLANG_VERSION.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't do that so we can detect the first install.
I'll double-check if it's still necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should keep it empty:
- https://github.com/polylang/polylang/pull/1237/files#diff-5214ac2ea5eb9c1915795e0fe082fab413112c144ce3009764b0d86179d48b69R179
- https://github.com/polylang/polylang/pull/1237/files#diff-7bcdbc1cb24cba2bfcef22987b4a3bc3910e4972ac2cbf5a219a960327d8c939R168
- https://github.com/polylang/polylang/pull/1237/files#diff-7b56c8ba8d31fce73086ef07085559611b4219b1c2d6e723a623f71b581f2745R107
- https://github.com/polylang/polylang/pull/1237/files#diff-a36b4a68ce7c6a8aa48b0b5f5ec135b11f757493710d614497b79a66302e7849R91
We have a |
9542323
to
9b226e3
Compare
Done in 979f3ac. |
The test failing on multisite is fixed in #1319. |
This comes from #1242.
The issues that are already present in `master` are not fixed here.
Not needed anymore.
91c68e1
to
38e3ea3
Compare
New entries:
|
Replaced by #1488. |
Closes https://github.com/polylang/polylang-pro/issues/1160
Fixes #1236
This PR introduces a new class
PLL_Options
to manage Polylang's options.This is requirement if someday we want to use a dependency Injection container.
Key points
ArrayAccess
, meaning that values can still be accessed like with an array.Iterator
(andCountable
), meaning that we can still useforeach
.JsonSerializable
, meaning that usingjson_encode()
will encode the options, not the class (this requiresJSON
to be available on the server though, which is always the case).shutdown
if they have been modified. Note: the system is not perfect but enough for what we do: changing twice a value to revert it to its initial value is still counted as "modified", and will trigger an update. For example:switch_to_blog()
is handled: the class stores the options of each necessary blog. It starts with the current blog by storing its options locally, then on theswitch_block
hook it will switch to the options of this blog (but fetch them first if not already stored locally) and consider them as "current options" (but still keep the options of the previous blog locally).media
andnav_menus
, we only make sure that the array keys are non falsy strings.array_merge()
on options will trigger a fatal error, so the methodPLL_Options::merge()
has been created:PLL_Options::get_reset_options()
is used when$options['version']
is empty (plugin init, plugin activation).PLL_Install::get_default_options()
is a wrapper of this method. The word "reset" is used here instead of "default":$options['hide_default'] = false;
.$options['hide_default'] = true;
.get_install_options()
for example.PHPStan
This allows some type checks on our options. For example, PHPStan knows that
$options['default_lang']
is a string (that can be an empty string).That's why some things have been removed in 75998cb.
Other
update_option( 'polylang', $options )
have been removed.PLL_Install
/PLL_Install_Base
we're still usingget_option()
andupdate_option()
becausePLL()
is not yet available in most cases.$options
class properties have been taggedPLL_Options
instead ofarray
(this allowed better PHPStan checks).Polylang Pro and Polylang for WooCommerce