From 7e6424f9e12a86796e85e7cfe179be998a043643 Mon Sep 17 00:00:00 2001 From: Giovanni Cascione Date: Sat, 26 Mar 2022 23:24:58 +0100 Subject: [PATCH] generalized manual loaded modules mechanism --- admin/qtx_admin_options_update.php | 17 +++-- admin/qtx_admin_settings.php | 31 +++++--- modules/qtx_modules_handler.php | 70 +++++++++++++++---- .../slugs/includes/class-qtranslate-slug.php | 7 +- .../slugs/includes/qtranslate-slug-admin.php | 24 +++---- .../includes/qtranslate-slug-settings.php | 2 +- modules/slugs/slugs.php | 1 + qtranslate_core.php | 6 +- qtranslate_options.php | 2 +- 9 files changed, 105 insertions(+), 55 deletions(-) diff --git a/admin/qtx_admin_options_update.php b/admin/qtx_admin_options_update.php index 516a2b40..4ec603c7 100644 --- a/admin/qtx_admin_options_update.php +++ b/admin/qtx_admin_options_update.php @@ -528,12 +528,12 @@ function qtranxf_updateSetting( $var, $type = QTX_STRING, $def = null ) { qtranxf_update_setting( $var, $type, $def ); } -function qtranxf_update_setting( $var, $type = QTX_STRING, $def = null ) { +function qtranxf_update_setting( $var, $type = QTX_STRING, $def = null, $bool_allowed = false ) { global $q_config, $qtranslate_options; if ( ! isset( $_POST['submit'] ) ) { return false; } - if ( ! isset( $_POST[ $var ] ) && $type != QTX_BOOLEAN ) { + if ( ! isset( $_POST[ $var ] ) && $type != QTX_BOOLEAN && ! $bool_allowed ) { return false; } @@ -596,10 +596,14 @@ function qtranxf_update_setting( $var, $type = QTX_STRING, $def = null ) { return true; case QTX_ARRAY: - $val = $_POST[ $var ]; - if ( ! is_array( $_POST[ $var ] ) ) { - $val = sanitize_text_field( $val ); - $val = preg_split( '/[\s,]+/', $val, -1, PREG_SPLIT_NO_EMPTY ); + if ( isset($_POST[ $var ] ) ){ + $val=$_POST[ $var ]; + if ( ! is_array( $_POST[ $var ] ) ) { + $val = sanitize_text_field( $val ); + $val = preg_split( '/[\s,]+/', $val, -1, PREG_SPLIT_NO_EMPTY ); + } + }else{ + $val=''; } if ( empty( $val ) && ! is_null( $def ) ) { if ( is_string( $def ) ) { @@ -807,6 +811,7 @@ function qtranxf_update_settings() { qtranxf_update_setting( $name, QTX_ARRAY, $default ); } qtranxf_update_setting( 'filter_options', QTX_ARRAY ); + qtranxf_update_setting( 'ma_module_enabled', QTX_ARRAY, null, true ); switch ( $q_config['url_mode'] ) { case QTX_URL_DOMAIN: diff --git a/admin/qtx_admin_settings.php b/admin/qtx_admin_settings.php index 9dbcc102..21b5dd38 100644 --- a/admin/qtx_admin_settings.php +++ b/admin/qtx_admin_settings.php @@ -259,10 +259,13 @@ private function add_sections( $nonce_action ) { $admin_sections['import'] = __( 'Import', 'qtranslate' ) . '/' . __( 'Export', 'qtranslate' ); $admin_sections['languages'] = __( 'Languages', 'qtranslate' ); - if ( $q_config['slugs_enabled'] ) { - $admin_sections['slugs'] = __( 'Slugs', 'qtranslate' ); + if (isset($q_config['ma_module_enabled'])){ + foreach ( $q_config['ma_module_enabled'] as $module_id=>$module_enabled ){ + if (!$module_enabled) continue; + $ma_module=QTX_Modules_Handler::get_module_def_by_id($module_id); + $admin_sections[$module_id] = $ma_module['name']; + } } - $admin_sections['troubleshooting'] = __( 'Troubleshooting', 'qtranslate' ); ?> @@ -750,19 +753,25 @@ class="qtranxs_explanation"> - - + $module_enabled ): + $module=QTX_Modules_Handler::get_module_def_by_id($module_id); + ?> + + -