-
Notifications
You must be signed in to change notification settings - Fork 110
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
Harmonize module options #1158
Harmonize module options #1158
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,3 +91,39 @@ function qtranxf_admin_load_config() { | |
|
||
qtranxf_add_conf_filters(); | ||
} | ||
|
||
/** | ||
* Import legacy option by recopying its value if the new option doesn't already exist. | ||
* | ||
* @param string $old_name | ||
* @param string $new_name | ||
* @param bool|string $autoload as in update_option | ||
* | ||
* @return void | ||
*/ | ||
function qtranxf_import_legacy_option( $old_name, $new_name, $autoload = null ) { | ||
assert( strpos( $new_name, 'qtranslate_' ) === 0 ); | ||
if ( ! get_option( $new_name ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure new named option should always have the priority. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea of the import is a one-shot action at activation, the goal is that QT-XT cares of its own options (modules). The normal scenario is that new options don't exist yet. If we can import a value such as ACF or slugs legacy settings (coming from original plugins) the new option is created from these values to ensure the transition from the old plugins. But from that point we want to remain with the QT-XT setup and ignore the legacy stuff once we have all set in QT-XT. The most tricky case is when the QT-XT options are reset, we don't really want to import again but in that case we expect the admin to save a new set of options right after the reset. If this is not done, a new import can happen again. This patch is only valid for the modules as it's a new feature in QT-XT but this will be expanded to all other options later once we cut completely the links with QT-X (not XT). |
||
$old_value = get_option( $old_name ); | ||
if ( $old_value ) { | ||
update_option( $new_name, $old_value, $autoload ); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Rename a legacy option: import and cleanup. | ||
* Only applies to `qtranslate` options, preserve external plugin options. | ||
* | ||
* @param string $old_name | ||
* @param string $new_name | ||
* @param bool|string $autoload as in update_option | ||
* | ||
* @return void | ||
*/ | ||
function qtranxf_rename_legacy_option( $old_name, $new_name, $autoload = null ) { | ||
assert( strpos( $new_name, 'qtranslate_' ) === 0 ); | ||
assert( strpos( $old_name, 'qtranslate_' ) === 0 ); | ||
qtranxf_import_legacy_option( $old_name, $new_name, $autoload ); | ||
delete_option( $old_name ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With a rename the old option should be deleted in any case or if it it appears again. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -360,7 +360,9 @@ function qtranxf_reset_config() { | |
// internal private options not loaded by default | ||
delete_option( 'qtranslate_next_update_mo' ); | ||
delete_option( 'qtranslate_next_thanks' ); | ||
delete_option( 'qtranslate_modules_state' ); | ||
delete_option( QTX_OPTIONS_MODULES_STATE ); | ||
delete_option( QTX_OPTIONS_MODULE_ACF ); | ||
delete_option( QTX_OPTIONS_MODULE_SLUGS ); | ||
Comment on lines
+363
to
+365
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These would look better somewhere in modules source files to make things cleaner, maybe a new function to be called from here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also thought this, but this belongs more to general admin functionalities for the whole QT-XT plugin. For the same reason as for the option names, better keep those with the rest and not split them to avoid the risks of missing updates/deletions. |
||
|
||
// obsolete options | ||
delete_option( 'qtranslate_custom_pages' ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,10 +55,22 @@ | |
// Language code format: ISO 639-1 (2 alpha), 639-2 or 639-3 (3 alpha) | ||
define( 'QTX_LANG_CODE_FORMAT', '[a-z]{2,3}' ); | ||
|
||
/** | ||
* Option names. | ||
*/ | ||
const QTX_OPTIONS_MODULES_STATE = 'qtranslate_modules_state'; | ||
const QTX_OPTIONS_MODULE_ACF = 'qtranslate_module_acf'; | ||
const QTX_OPTIONS_MODULE_SLUGS = 'qtranslate_module_slugs'; | ||
Comment on lines
+61
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These definitions would look better in modules source files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is that all options definitions should be kept consistent in a unique place (the options names are used both for front and admin). Currently it's hard to to understand where a general option is set or read in the code because the values are spread everywhere and most of the settings are generated from intermediate strings (with |
||
|
||
/** | ||
* @global array Global configuration, interpreted from settings and i18n configuration loaded from JSON. | ||
*/ | ||
global $q_config; | ||
global $qtranslate_options; | ||
|
||
/** | ||
* @global array Global options, mapped at a lower level to the settings. | ||
*/ | ||
global $qtranslate_options; | ||
|
||
/** | ||
* array of default option values | ||
|
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.
Should this function return
update_option
result (andtrue
for other cases)?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 haven't found a case where I'd need it.