qtranslate / qtranslate-xt

qTranslate-XT (eXTended) - reviving qTranslate-X multilingual plugin for WordPress. A new community-driven plugin soon. Built-in modules for WooCommerce, ACF, slugs and others.
GNU General Public License v2.0
546 stars 103 forks source link

ACF Post Object [qTranslate-XT] does not work #1320

Closed salt-istanbul closed 1 year ago

salt-istanbul commented 1 year ago

ACF Post Object [qTranslate-XT] field always getting 400 Bad Request. I can't get any post objects. I checked ACF's native Post Object field but it's working.

ACF Pro 6.1.3 qTranslate-XT 3.14.0

herrvigg commented 1 year ago

I confirm there's a bug, I can reproduce it. The standard ACF Post Object is working, without translation.

herrvigg commented 1 year ago

Indeed there's a regression in 3.14.0. Now fixed in master. You can also copy the 4 lines of code shown in the patch above: #2e8e453.

salt-istanbul commented 1 year ago

Indeed there's a regression in 3.14.0. Now fixed in master. You can also copy the 4 lines of code shown in the patch above: #2e8e453.

thanks, ACF Post Object [qTranslate-XT] is working now but I'm getting errors similar to the following after your latest release. Fatal error: Uncaught TypeError: qtranxf_checkCanonical(): Argument #2 ($requested_url) must be of type string, I'm not sure but this problem about function argument's type declarations.

herrvigg commented 1 year ago

What is following "must be of type string, ..."? By case, do you use Yoast (wp-seo)? I see there are two potential problems (1) this function is used wrongly by a hook in the Yoast module, (2) the WordPress documentation is not reliable, they say string are passed but it can be other types 😕

salt-istanbul commented 1 year ago

What is following "must be of type string, ..."? By case, do you use Yoast (wp-seo)? I see there are two potential problems (1) this function is used wrongly by a hook in the Yoast module, (2) the WordPress documentation is not reliable, they say string are passed but it can be other types 😕

Yes, i'm using Yoast(wp-seo) and i think this function is used wrongly by a hook in the Yoast module. Because $requested_url atgument is return "undefined" on qtranxf_checkCanonical function. There's already a comment before this function line "// TODO check API with Yoast, seems it's only 1 parameter?"

Same problem on qtranxf_wpseo_webpage_schema( array $piece, string $context ) function. qtranslate-xt\src\modules\wp-seo\wp-seo-front.php on line 34

$context atgument is return "undefined"and getting this error. Fatal error: Uncaught TypeError: qtranxf_wpseo_webpage_schema(): Argument #2 ($context) must be of type string,

I'm getting no error when I remove this arguments from functions.

herrvigg commented 1 year ago

Yes, the Yoast hooks are ill-defined. The second parameter in Yoast is Indexable_Presentation, not a string giving the requested URL that is expected in qtranxf_checkCanonical. Though this parameter is not used, I reverted the type checks so it should work now. I also reverted all the type checks in the Yoast hooks, it feels too risky at this point. Please retry with master, ACF and Yoast should be fixed for you now.

Strong type checks with PHP is the way to go because it helps to find such wrong usage. The drawback is that is it can create regressions. It's unfortunate the WP documentation is not accurate and their APIs are so messy with many mixed types often undocumented. I will comment more in #1314 and possibly do other reverts.

herrvigg commented 1 year ago

Released fix for ACF Post Object in 3.14.1.