Skip to content
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

Conflict with Custom Field Suite plugin #1037

Open
Buildbetter opened this issue Jun 9, 2021 · 6 comments
Open

Conflict with Custom Field Suite plugin #1037

Buildbetter opened this issue Jun 9, 2021 · 6 comments
Labels
core Core functionalities, including the admin section enhancement New feature or request need info The submitter must provide more info plugin: others Concerns integration with other plugins

Comments

@Buildbetter
Copy link

Buildbetter commented Jun 9, 2021

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 );

}

@herrvigg herrvigg added the enhancement New feature or request label Jun 12, 2021
@herrvigg
Copy link
Collaborator

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?

@herrvigg herrvigg added core Core functionalities, including the admin section plugin: others Concerns integration with other plugins need info The submitter must provide more info labels Jun 12, 2021
@Buildbetter
Copy link
Author

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 #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.

@herrvigg
Copy link
Collaborator

herrvigg commented Nov 4, 2022

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)

@Buildbetter
Copy link
Author

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" }

@leicestersq
Copy link

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

@Buildbetter
Copy link
Author

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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core functionalities, including the admin section enhancement New feature or request need info The submitter must provide more info plugin: others Concerns integration with other plugins
Projects
None yet
Development

No branches or pull requests

3 participants