qtranslate-xt
qtranslate-xt copied to clipboard
Conflict with Custom Field Suite plugin
Very bad error. I have installed plugin https://wordpress.org/plugins/custom-field-suite/ latest WP, php 7.4 latest QT-xt-3.10.1
In admin page has meta-box with dynamic fields, when page is saved error is displayed.
Pleace HELP.
Fatal error: Uncaught TypeError: preg_match(): Argument #2 ($subject) must be of type string, array given in /home/myfolder/public_html/wp-content/plugins/qtranslate-xt/qtranslate_utils.php:389 Stack trace: #0 /home/myfolder/public_html/wp-content/plugins/qtranslate-xt/qtranslate_utils.php(389): preg_match('/<!--:[a-z]{2,3...', Array) #1 /home/myfolder/public_html/wp-content/plugins/qtranslate-xt/admin/qtx_admin.php(47): qtranxf_isMultilingual(Array) #2 /home/myfolder/public_html/wp-content/plugins/qtranslate-xt/admin/qtx_admin.php(62): qtranxf_collect_translations(Array, Array, 'bg') #3 /home/myfolder/public_html/wp-content/plugins/qtranslate-xt/admin/qtx_admin.php(62): qtranxf_collect_translations(Array, Array, 'bg') #4 /home/myfolder/public_html/wp-content/plugins/qtranslate-xt/admin/qtx_admin.php(62): qtranxf_collect_translations(Array, Array, 'bg') #5 /home/myfolder/public_html/wp-content/plugins/qtranslate-xt/admin/qtx_admin.php(62): qtranxf_collect_translations(Array, Array, 'bg') #6 /home/myfolder/public_html/wp-content/plugins/qtranslate-xt/admin/qtx_admin.php(62): qtranxf_collect_translations(Array, Array, 'bg') #7 /home/myfolder/public_html/wp-content/plugins/qtranslate-xt/admin/qtx_admin.php(96): qtranxf_collect_translations(Array, Array, 'bg') #8 /home/myfolder/public_html/wp-includes/class-wp-hook.php(292): qtranxf_collect_translations_posted('') #9 /home/myfolder/public_html/wp-includes/class-wp-hook.php(316): WP_Hook->apply_filters(NULL, Array) #10 /home/myfolder/public_html/wp-includes/plugin.php(484): WP_Hook->do_action(Array) #11 /home/myfolder/public_html/wp-settings.php(423): do_action('plugins_loaded') #12 /home/myfolder/public_html/wp-config.php(90): require_once('/home/myfolder/...') #13 /home/myfolder/public_html/wp-load.php(37): require_once('/home/myfolder/...') #14 /home/myfolder/public_html/wp-admin/admin.php(34): require_once('/home/myfolder/...') #15 /home/myfolder/public_html/wp-admin/post.php(12): require_once('/home/myfolder/...') #16 {main} thrown in /home/myfolder/public_html/wp-content/plugins/qtranslate-xt/qtranslate_utils.php on line 389
ONLY THIS FIX HELPS
function qtranxf_isMultilingual( $str ) { $lang_code = QTX_LANG_CODE_FORMAT;
if( is_admin() AND is_array($str) ) { $str = $str[0]; } // FIX !!!
return preg_match( "/<!--:$lang_code-->|\[:$lang_code]|{:$lang_code}/im", $str );
}
In fact qtranxf_isMultilingual
expects a string, not an array. I'm not so sure this fix is good enough.
Normally, the REQUEST['qtranslate-fields'] should look like
qtranslate-fields['post_title']['en']
qtranslate-fields['post_title']['fr']
qtranslate-fields['post_title']['de']
qtranslate-fields['content']['en']
qtranslate-fields['content']['fr']
qtranslate-fields['content']['de']
...
What do you have in your case?
Whit this plugin you can add new metabox with editor fiield! If qtranslate is active when you save page you get error. https://wordpress.org/plugins/custom-field-suite/
The error is: Fatal error: Uncaught TypeError: preg_match(): Argument https://github.com/qtranslate/qtranslate-xt/issues/2 ($subject) must be of type string, array given in ..... /wp-content/plugins/qtranslate-xt/qtranslate_utils.php on line 389
Its because we have second editor here.
My intention is to strongly type the arguments even more in the future with modern versions of PHP so I'd rather avoid handling this with a loosely defined type in qtranxf_isMultilingual
. If it's an array what does it mean? Why would we only take the first element? Better stick to a string and fix the calling side.
How does your $REQUEST
look like, in particular REQUEST['qtranslate-fields']
?
(asked one year ago but no answer)
array(5) { ["post_title"]=> array(2) { ["bg"]=> string(12) "Начало" ["en"]=> string(4) "Home" } ["content"]=> array(2) { ["bg"]=> string(0) "" ["en"]=> string(0) "" } ["btmenu_text"]=> array(2) { ["bg"]=> string(0) "" ["en"]=> string(0) "" } ["cfs"]=> &array(1) { ["input"]=> &array(2) { [1]=> array(1) { ["value"]=> array(2) { ["bg"]=> string(0) "" ["en"]=> string(0) "" } } [6]=> &array(2) { [0]=> &array(1) { [5]=> &array(1) { ["value"]=> &array(2) { ["bg"]=> array(1) { [0]=> string(11) "fcgjhgfhjg1" } ["en"]=> array(1) { [0]=> string(11) "fcgjhgfhjg2" } } } } [1]=> array(1) { [5]=> array(1) { ["value"]=> array(3) { ["bg"]=> array(1) { [0]=> string(7) "sfgd bg" } ["en"]=> array(1) { [0]=> string(7) "sfgd en" } ["qtranslate-separator"]=> string(1) "[" } } } } } } ["excerpt"]=> array(3) { ["bg"]=> string(0) "" ["en"]=> string(0) "" ["qtranslate-separator"]=> string(1) "[" } } array(1) { [0]=> string(11) "fcgjhgfhjg1" }
Hello. This is happening to me as well. I may provide details if you need. The proposed fix did the trick, but it would be nice to further investigate the issue
function qtranxf_isMultilingual($input): bool { // Check if the input is an array if (is_array($input)) { // Iterate over each element in the array foreach ($input as $str) { // Check if the element is a string and contains multilingual content if (is_string($str) && qtranxf_has_multilingual_content($str)) { return true; // Return true if multilingual content is found } } return false; // Return false if multilingual content is not found in any element } elseif (is_string($input)) { // Check if the input is a string and contains multilingual content return qtranxf_has_multilingual_content($input); } return false; // Return false for other types of input }
function qtranxf_has_multilingual_content(?string $str): bool { $lang_code = QTX_LANG_CODE_FORMAT; return !is_null($str) && preg_match("/|[:$lang_code]|{:$lang_code}/im", $str); }