diff --git a/src/init.php b/src/init.php index 0cf1bac7..0ac471ef 100644 --- a/src/init.php +++ b/src/init.php @@ -82,6 +82,8 @@ function qtranxf_init_language(): void { $url_info['language'] = qtranxf_detect_language( $url_info ); $q_config['language'] = apply_filters( 'qtranslate_language', $url_info['language'], $url_info ); + QTX_Module_Loader::load_active_modules_early_hooks(); + assert( isset( $q_config['url_info']['doing_front_end'] ) ); if ( $q_config['url_info']['doing_front_end'] && qtranxf_can_redirect() ) { qtranxf_check_url_maybe_redirect( $url_info ); diff --git a/src/modules/module_loader.php b/src/modules/module_loader.php index c0ccd0ec..48080430 100644 --- a/src/modules/module_loader.php +++ b/src/modules/module_loader.php @@ -39,4 +39,24 @@ public static function load_active_modules(): void { } } } + + /** + * Loads early hooks from modules previously activated in the options. + * + * Attention! This assumes the current states stored in the options are valid. + * This doesn't perform any check, neither on the plugin conditions nor the folder structure. + * In the worst case the state can be refreshed by reactivating the plugin. + * + * Note also the modules should be loaded before "qtranslate_init_language" is triggered. + */ + public static function load_active_modules_early_hooks(): void { + $modules_state = get_option( QTX_OPTIONS_MODULES_STATE, array() ); + + foreach ( $modules_state as $module_id => $state ) { + $target = QTRANSLATE_DIR . '/src/modules/' . $module_id . '/' . 'early_hooks.php'; + if ( $state === QTX_MODULE_STATE_ACTIVE && file_exists( $target ) ) { + require_once( $target ); + } + } + } } diff --git a/src/modules/slugs/early_hooks.php b/src/modules/slugs/early_hooks.php new file mode 100644 index 00000000..56d6249e --- /dev/null +++ b/src/modules/slugs/early_hooks.php @@ -0,0 +1,31 @@ +