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

Error when add/update post - Invalid argument supplied for foreach() - qtx_admin.php on line 14 #392

Closed
herrvigg opened this issue Jun 23, 2018 · 22 comments
Labels
enhancement New feature or request legacy issue Legacy issue imported from original repo

Comments

@herrvigg
Copy link
Collaborator

Issue by nunospot
Wednesday Jun 08, 2016 at 14:07 GMT
Originally opened as qTranslate-Team/qtranslate-x#392


I get a error when I try to add or update a post:

Warning: Invalid argument supplied for foreach() in .../wp-content/plugins/qtranslate-x/admin/qtx_admin.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at .../wp-content/plugins/qtranslate-x/admin/qtx_admin.php:14) in .../wp-includes/pluggable.php on line 1171

I saw a thread on wordpress support page with the same error - https://wordpress.org/support/topic/warning-shown-on-page-update-qtranslate-xadminqtx_adminphp-on-line-14?replies=8

I'm using the workaround set by david.sota.ads, but like John Clause said this will only solve the error messages not the actual problem.

@herrvigg herrvigg added enhancement New feature or request legacy issue Legacy issue imported from original repo labels Jun 23, 2018
@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Wednesday Jun 08, 2016 at 22:21 GMT


I still have no idea how that happens ... Probably older version of PHP is at fault, but what exactly is happening? Nobody troubleshooted it to the answer. We could never reproduce it and we have never gained an admin access to troubleshoot it. Would you have enough PHP skills to figure out what is going on?

@herrvigg
Copy link
Collaborator Author

Comment by nunospot
Thursday Jun 09, 2016 at 09:26 GMT


I'm developing on my localhost, I didn't test it online yet, but I will give it a try. Anyway my php version is 4.6.1, so I don't think it's a php problem.

I'm using the qtranslate-x with the ACF to translate a several fields. I think the problem is when this fields are not filled so the $content on the foreach is NULL, in others words, the argument is invalid. And no, i'm not that good in PHP :\

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Thursday Jun 09, 2016 at 14:34 GMT


4.6.1 is pretty low by now.

NULL is what I do not understand, $content comes from $_POST, which should never have any nulls. Where this NULL come from? Sounds like an imperfection in ACF, which is not important anywhere else, but just causes this message. Could you try to figure out a simple reproducible case?

@herrvigg
Copy link
Collaborator Author

Comment by nunospot
Thursday Jun 09, 2016 at 15:33 GMT


Yeah sorry, I was telling the phpMyAdmin version. The php is 5.5.19.

NULL I think comes from the fields that have not been filled.

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Thursday Jun 09, 2016 at 15:40 GMT


Yes, they apparently come from that, but it should not be a case. Empty fields come as empty strings, not NULL, in normal case. We can put "if(is_null(...)) ...", but it is strange to run an extra code just to offset either older PHP or imperfections in other plugin development? I would like to find out the true cause of this first. And for that I need a way to reproduce it.

@herrvigg
Copy link
Collaborator Author

Comment by nunospot
Thursday Jun 09, 2016 at 16:36 GMT


I have the ACF pro version. I can give you access to the development in if you want.

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Thursday Jun 09, 2016 at 16:46 GMT


Access to localhost? I would think ACF Pro and regular would behave the same, as it seems basic. Could you describe the minimum steps to reproduce first? What kind of field one need to create and not to fill and where in order to see this message? Please, assume no knowledge of ACF for a reader. Maybe I will eventually able to reproduce on my localhost.

@herrvigg
Copy link
Collaborator Author

Comment by nunospot
Thursday Jun 09, 2016 at 17:04 GMT


I have a dev environment on a server. What do you need specifically? I have several fields to fill (for example: text fields, wysiwyg editors, repeaters, images e etc) for this post and those fields, except the images, can be translated by the q-translate.

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Thursday Jun 09, 2016 at 22:14 GMT


I've never done anything with ACF and I would not like to spend time to learn. It would be great, if you could give me set of instructions what to do to see the error message you are seeing.

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Friday Jun 10, 2016 at 14:31 GMT


I tried a few fields, and I cannot hit this problem, never was able to to. If you wish to help, give us precise instructions what to do to reproduce, or admin access to a site with explanation what page to go and wht to do to observe the problem.

@herrvigg
Copy link
Collaborator Author

Comment by nunospot
Friday Jun 10, 2016 at 21:22 GMT


Hi John, yeah ofc. I can't give you the access right because I don't have the access here you my personal computer, but monday on the work I can give it to you or reproduce another environment where you can see what going on.

@herrvigg
Copy link
Collaborator Author

Comment by nunospot
Monday Jun 13, 2016 at 11:25 GMT


Hi john. Give me your email so I can send you the access.

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Monday Jun 13, 2016 at 15:19 GMT


The contact information is in the link I sent you: https://qtranslatexteam.wordpress.com/contact-us/

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Wednesday Jun 15, 2016 at 02:26 GMT


Thank you very much, @NC0STA, for setting up a test server for us.We would never be able to reproduce it on our servers, because it happens when a page has a hidden, unused translatable field and when user has the first language chosen when "Update" is pressed 👍 It happens with ACF mostly, but potentially can happen in other plugins too.

The fix is here: qTranslate-Team/qtranslate-x@7586ff0
and it will be included in the next release.

@herrvigg
Copy link
Collaborator Author

Comment by riverofjanuary
Thursday Sep 29, 2016 at 20:53 GMT


FWIW I just installed the very latest version from the git repo (3.4.8) and had this exact error (on ACF site with fields moved around). I had to manually apply the "isset" fix (that @johnclause links to immediately above) to the qtranxf_collect_translations function and it fixed the problem... Was the fix applied to June 14 commit, then dropped out of a later version??

@herrvigg
Copy link
Collaborator Author

Comment by pwolfert
Wednesday Oct 19, 2016 at 20:13 GMT


I had the same problem as @riverofjanuary and saw that the fix is in the stable branch but not in master. I've manually installed the latest stable version, and it fixed this and one other problem (https://piklist.com/support/topic/conflict-with-qtranslate-x-plugin-and-group-fields/).

@herrvigg
Copy link
Collaborator Author

Comment by dxit-gg
Tuesday Feb 21, 2017 at 13:47 GMT


Hi there,
I have a similar problem with ACF.
I fix it with this code:

function qtranxf_collect_translations( &$qfields, &$request, $edit_lang ) { if(isset($qfields['qtranslate-separator'])){ $sep = $qfields['qtranslate-separator']; unset($qfields['qtranslate-separator']); $qfields[$edit_lang] = $request; $request = qtranxf_collect_translations_deep($qfields,$sep); }else{ foreach($qfields as $nm => &$vals){ if(!isset($request[$nm])){ unset($request[$nm]); continue; } qtranxf_collect_translations($vals,$request[$nm],$edit_lang); // recursive call } } }

Regards

@herrvigg
Copy link
Collaborator Author

Comment by fabianhijlkema
Thursday Mar 02, 2017 at 13:40 GMT


Had the same issue, @dxit-gg answer fixed it for me too. Also using ACF pro.

@herrvigg
Copy link
Collaborator Author

Comment by janeschindler
Friday Feb 16, 2018 at 20:12 GMT


I had two conflicts with ACF-qtranslate (the ACF integration plugin). 1) I got this error on line 14. Thank you for the fix (I haven't confirmed that it's working because I don't understand what you mean by 'first language' in this comment: qTranslate-Team/qtranslate-x#392 (comment). I have the issue but haven't been able to reproduce reliably. Would be great if you could clarify). 2) When I edited and saved group ACF fields, the fields I had put inside groups were all replicated outside the groups but without field names (funkjedi/acf-qtranslate#111). After a quick test this also seems to have been fixed. Is that possible? I really hope it doesn't happen any more.

@herrvigg
Copy link
Collaborator Author

Comment by janeschindler
Sunday Feb 18, 2018 at 21:47 GMT


I am using the stable branch now with the fix and just had this error again (invalid argument on line 14). My site deletes the entirety of the post in the language that's being edited (but not the other languages). I've upped the max_input_vars for php and hope that might help. Very glad if anyone has other ideas.

@Marko-Markovic
Copy link

Hey everyone!

I'm still experiencing the issue as the fix by @dixit-gg did not work for me. It simply bypasses the error while avoiding to save any fields or rows beyond the "affected" one which returns empty brackets.

I'm running the following:

q-Translate-X Version 3.4.6.8
Advanced Custom Fields: qTranslate 1.7.23
Advanced Custom Fields PRO 5.6.10

Am I missing something aside from applying the provided code in the qt-admin.pp ?

@Marko-Markovic
Copy link

Marko-Markovic commented Jul 26, 2018

Update:

As I seem to have used quite a lot of fields, and this occurred on out-of-the-box local web server it never occurred to me that the limits might be too narrow. After upping the memory limits of php/wp the issue did not reappear (no other changes were made).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request legacy issue Legacy issue imported from original repo
Projects
None yet
Development

No branches or pull requests

2 participants