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

'acf_qtranslate_acf_5_image' does not have a method 'wp_prepare_attachment_for_js' #783

Closed
chaofix opened this issue Feb 8, 2020 · 24 comments
Labels
invalid This doesn't seem right module: ACF Integration with ACF need info The submitter must provide more info

Comments

@chaofix
Copy link

chaofix commented Feb 8, 2020

This issue is related to #718 - but this issue is closed there but I'm still having this issue with 5.8.1 or 5.8.2 or latest 5.8.7

When I tried view the media library, I see only a white page and when I tried to upload an image I got the message: "Could not insert post into the database"

I tried the following:

  • Update the permissions of directory and files - doesn't assist
  • Disabled all plugins - one by one - doesn't assist
  • Downgrade version of ACF PRO to 5.8.2 or 5.8.1 - doesn't assist
  • Disabled this line - acf()->fields->register_field_type(new acf_qtranslate_acf_5_image($this->plugin)); - doesn't assit
  • Disabled this line also - require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/image.php'; - doesn't assist

I'm with latest version of Wordpress - 5.3.2
There is space on the server

@NewLifeMan
Copy link

+1

@herrvigg
Copy link
Collaborator

OK sorry i didn't find time to really check this. Will try to look but the main problem is that i don't have ACF PRO so i can't see the specific things related to that version.

@herrvigg herrvigg added the plugin: others Concerns integration with other plugins label Feb 14, 2020
@reddo
Copy link

reddo commented Feb 14, 2020

@herrvigg I can hook you up with the latest version zip, you only need a key to update.

@herrvigg
Copy link
Collaborator

@chaofix @NewLifeMan Can you show me the full stack error message? This issue was fixed in #718 like this:

// removed from ACF 5.8.3
if ( method_exists( $this, 'wp_prepare_attachment_for_js' ) ) {
add_filter( 'wp_prepare_attachment_for_js', array( $this, 'wp_prepare_attachment_for_js' ), 10, 3 );
}

So i really don't see how qTranslate-XT could cause the problem. We should not try to call this function if it's not present in the class (or sub-class). Also, the fact you are downgrading to 5.8.2 and still have the problem does not make any sense. This function wp_prepare_attachment_for_js was removed from acf_field_image in 5.8.3 and as far as i know, there was no problem until then.

Are you sure you don't have conflicts with your plugin versions and loading (old) things that you shouldn't?

@herrvigg
Copy link
Collaborator

Maybe you are using the legacy plugin? If so, you should disable it. But normally you can't use it together with the module if you check the options. Also be sure you don't have qTranslate-X enabled and use the last qTranslate-XT (3.7.1).

But even if you were using it (and you shouldn't), the problem would disappear if you downgrade to ACF Pro 5.8.2 or lower. Then i don't know the changes after 5.8.3 but it's not even the problem here...

@herrvigg
Copy link
Collaborator

herrvigg commented Feb 15, 2020

Similar to #772 though @stefano88ita managed to find a workaround by commenting

acf()->fields->register_field_type(new acf_qtranslate_acf_5_image($this->plugin));

But again this doesn't make any sense. So there's something still very strange about all these issues. I have the feeling the problem is not in qTranslate-XT but let me know more about the context.

@herrvigg herrvigg added the need info The submitter must provide more info label Feb 15, 2020
@chaofix
Copy link
Author

chaofix commented Feb 16, 2020

@herrvigg

I installed a new clean "Wordpress" with q-translate latest plugin
as soon as I tried to upload an image, I got an error and the same issue I had when I opened this thread is accord... so I don't think it it . related to other plugins

I can't supply a screenshots beyond what I already supplied

@herrvigg
Copy link
Collaborator

herrvigg commented Feb 16, 2020

@chaofix which qTranslate are you using? I really need to be sure about all the details because it doesn't make any sense. I still don't see which code is calling the function that raised the error! Technically speaking it don't understand how it could come from qTranslate-XT, this function is used nowhere directly (if it doesn't exist).

First of all, be really sure you DON'T have the ACF qTranslate plugin enabled.

Can you give me the detailed versions? Please go in the Troubleshooting section of qTranslate-XT and copy here the last block with the versions. I need first of all to verify:

  • qTranslate-XT
  • PHP

@herrvigg
Copy link
Collaborator

Also if the problem comes from qTranslate i really need to see the whole calling stack. You can try in debug mode and see if you get more info.

@herrvigg
Copy link
Collaborator

To avoid further confusions, i improved the debug info with more details about the plugins and their versions, now separated from the configuration data for better clarity.

Do you have possibility to download the latest version of qTranslate-XT? It's very easy, you can use the zip archive from github (master branch). Then please give me the "Versions" info in the Troubleshooting section.

@fabienlege
Copy link

I've the same issue...
i've just tried from a fresh git clone of this repo (commit 024ed01) and same error :

  • wp : 5.3.2
  • qtranslate-xt : dev-master (commit 024ed01)
  • acf PRO : 5.8.7

version infos :

{
  "PHP_VERSION": "7.3.14-5+0~20200202.52+debian8~1.gbpa71879",
  "WP_VERSION": "5.3.2",
  "QTX_VERSION": "3.7.2.dev.1",
  "Plugins": [
    "InfiniteWP - Client 1.9.4.5",
    "404page - your smart custom 404 error page 11.2.1",
    "Advanced Custom Fields: Page Builder Field 1.0.3",
    "Advanced Custom Fields: qTranslate 1.7.25",
    "iThemes Security 7.6.1",
    "Classic Editor 1.5",
    "Contact Form 7 5.1.6",
    "Display Widgets 2.7",
    "Favicon par RealFaviconGenerator 1.3.17",
    "Google Analytics for WordPress by MonsterInsights 7.10.4",
    "Google Language Translator by NSI 5.0.04",
    "heatmap for WordPress 0.5.2",
    "Leaflet Maps Marker 3.12.3",
    "Meta Box 5.2.7",
    "MetaSlider 3.15.3",
    "NSI Cauterets Live Actus 1.0.0",
    "NSI Météo - Saisie manuelle ",
    "NSI N'Py Réservation ",
    "NSI Post Slider 1.0",
    "NSI Scrolltop 1.0.0",
    "NSI Social Board 1.0.0",
    "Popup Builder 3.61.1",
    "qTranslate-XT 3.7.1",
    "Redirection 4.7",
    "Regenerate Thumbnails 3.1.3",
    "Responsive Lightbox & Gallery 2.2.3",
    "Page Builder by SiteOrigin 2.10.14",
    "SiteOrigin Widgets Bundle 1.16.0",
    "TinyMCE Advanced 5.3.0",
    "Total Slider updated by ho5 1.1.5",
    "W3 Total Cache 0.13.1",
    "10Web Social Photo Feed 1.3.24",
    "Yoast SEO 13.0",
    "WP Crontrol 1.7.1",
    "WP Force SSL 1.55",
    "WP RSS Aggregator 4.17.3",
    "Tourinsoft 1.0"
  ]
}

By consulting this log : i've see that i've installed another plugin : Advanced Custom Fields: qTranslate. if I disable this plugin, error disapear. Maybe it can help other users, but problem probably come from Advanced Custom Fields: qTranslate plugin, not from qtranslate-xt. @chaofix do you use Advanced Custom Fields: qTranslate extension to ?

@herrvigg
Copy link
Collaborator

herrvigg commented Feb 17, 2020

Yes that's it! Happy my last patch helped to sort this out 😄

As i expected, the problem comes from the legacy plugin "Advanced Custom Fields: qTranslate 1.7.25". But really, i don't understand how people can miss it. There is a HUGE notice like this:

image

It's quite clear no?! Or i don't know... 😅

@chaofix @NewLifeMan can you confirm this fixes the problem?

@herrvigg herrvigg added the invalid This doesn't seem right label Feb 17, 2020
@stefano88ita
Copy link

Similar to #772 though @stefano88ita managed to find a workaround by commenting

acf()->fields->register_field_type(new acf_qtranslate_acf_5_image($this->plugin));

But again this doesn't make any sense. So there's something still very strange about all these issues. I have the feeling the problem is not in qTranslate-XT but let me know more about the context.

Regarding this, i resolved commenting this line because if you go deep you find:
acf_qtranslate_acf_5_image is subclass of acf_field_image
acf_field_image in acf has a method named wp_prepare_attachment_for_js
acf_qtranslate_acf_5_image does not have the same method

I know that in the perfect world a subclass must have the same methods (clearly if not cover by override), but in the wordpress buggy environment probably this won't work. Maybe you can cover the issue by adding in acf_qtranslate_acf_5_image something like:
function wp_prepare_attachment_for_js( $response, $attachment, $meta ) {
parent::wp_prepare_attachment_for_js( $response, $attachment, $meta );
}
I did't try, but probably it works.

In the new version of plugin you add the line:
if ( method_exists( $this, 'wp_prepare_attachment_for_js' ) ) {
add_filter( 'wp_prepare_attachment_for_js', array( $this, 'wp_prepare_attachment_for_js' ), 10, 3 );
}
But in theory it works only because it never enter in this line. So the filter is never added and in the media explorer the function used is the one defined in acf: acf_field_image class.

Give a try!

@herrvigg
Copy link
Collaborator

@stefano88ita i'm not sure i'm following. You wrote in #772 that the current version of qTranslate solved the problem, so it works without commenting anything, no? We are still waiting for @chaofix @NewLifeMan to confirm they have been using the legacy plugin causing the bug which is not in qTranslate-XT.

if ( method_exists( $this, 'wp_prepare_attachment_for_js' ) is supposed to work on the object instance. Since it inherits from the class having this function, this should work. This part has nothing to do with WordPress but PHP. It works for everyone as far as i know.

@herrvigg
Copy link
Collaborator

Also, you should definitly NOT call:

parent::wp_prepare_attachment_for_js( $response, $attachment, $meta );

...before checking the function exists. This is the reason of the bug, because the function was removed in ACF PRO 5.8.3. The only reason i kept the conditional call is to support older versions of ACF as they were.

@stefano88ita
Copy link

@stefano88ita i'm not sure i'm following. You wrote in #772 that the current version of qTranslate solved the problem, so it works without commenting anything, no? We are still waiting for @chaofix @NewLifeMan to confirm they have been using the legacy plugin causing the bug which is not in qTranslate-XT.

if ( method_exists( $this, 'wp_prepare_attachment_for_js' ) is supposed to work on the object instance. Since it inherits from the class having this function, this should work. This part has nothing to do with WordPress but PHP. It works for everyone as far as i know.

You are right, in the new version it works without commenting anything, so the issue is closed. I updated also acf pro and wp_prepare_attachment_for_js has been removed, so the solution is correct, because the method doesn't exists and the filter is not added. Before that i was using acf 5.8.2 and wp_prepare_attachment_for_js was present and:

  1. method_exists( $this, 'wp_prepare_attachment_for_js' ) give true in dump
  2. add_filter( 'wp_prepare_attachment_for_js', array( $this, 'wp_prepare_attachment_for_js' ), 10, 3 ); give error with log: "Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'acf_qtranslate_acf_5_image' does not have a method 'wp_prepare_attachment_for_js" so probably wordpress doesn't consider inheritance in add_fields

So my comment was only to try to explain what was wrong before the update! Sorry :)

@herrvigg
Copy link
Collaborator

Then it's fine for now (at least for you). However i don't understand the point 2. If you use ACF 5.8.2 why would this call fail? It was exactly the same call as before (in case the function exists) and this has been working for ages. I didn't change anything here except the conditional check, see related commit. So again this doesn't make any sense. What version of WP and PHP are you using?

@stefano88ita
Copy link

Then it's fine for now (at least for you). However i don't understand the point 2. If you use ACF 5.8.2 why would this call fail? It was exactly the same call as before (in case the function exists) and this has been working for ages. I didn't change anything here except the conditional check, see related commit. So again this doesn't make any sense. What version of WP and PHP are you using?

It never works for me. When i dismiss Qtranslate + ACF qtranslate in favour of Qtranslate XT the error was there, only on uploading images in repeater's subfield...

@herrvigg
Copy link
Collaborator

That sounds really weird... To be clear, there should only be two cases:

  • with ACF 5.8.3+ the function is removed, so you need absolutely the fix with qT-XT 3.6.2+ and not use the (still buggy) ACF qT plugin. It's a different plugin which becomes legacy with the new module.
  • with ACF 5.8.2 or below, the function is there so you could normally use whatever combi you want (qT-X + ACF plugin or qT-XT any version from 3.6.0) and it should work all the same.

I can't see any rationale behind the last point you describe so i believe there's some other factor that is creating some confusion, maybe some cache or mixup with the versions. Or something else with PHP or WP that i'm missing (?!).

In any case, imo this is solved from qT-XT 3.6.2 which was released especially for this problem.

@chaofix
Copy link
Author

chaofix commented Feb 18, 2020

So.... these are the details

PHP ver 7.2.26
ACF PRO ver 5.8.7
qTranslate-X ver 3.4.6.8

@herrvigg
Copy link
Collaborator

@chaofix All right, qTranslate-X is the parent project, which is not maintained since June 2016... Here it's qTranslate-XT which is a different project. Please read carefully our README to see all the history behind and how to install it.

Note for the support of ACF we have now a built-in module so you don't need the old plugin ACF for qTranslate, it is incompatible with qT-XT (see screenshot that i posted earlier in this thread). Switch to qT-XT and you will see many, many problems solved :)

(apart from the bugs i don't even understand how qT-X still works on recent PHP versions...)

@yokotsumo
Copy link

ACF: 5.8.12
Qtranslate-XT : 3.6.0

I have the same problem and the above solution is not working.

@herrvigg
Copy link
Collaborator

You have all the history in this thread. Fixed in 3.6.2 almost one year ago... why are you using such an old version? Last release is 3.8.1.

@yokotsumo
Copy link

Sorry, I did not notice that qtranslate-XT does not notify for new versions in Wordpress.

@herrvigg herrvigg added module: ACF Integration with ACF and removed plugin: others Concerns integration with other plugins labels Dec 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right module: ACF Integration with ACF need info The submitter must provide more info
Projects
None yet
Development

No branches or pull requests

7 participants