qTranslate-Team / qtranslate-x

Wordpress plugin: Adds user-friendly and database-friendly multilingual content management and translation support.
http://qtranslatexteam.wordpress.com/about/
GNU General Public License v3.0
203 stars 151 forks source link

Error Cors #609

Open marianagarciaferreira opened 5 years ago

marianagarciaferreira commented 5 years ago

When it is active erro Cors Access to fetch at 'http://api.local.lab/wp-json/wp/v2/slides?lang=pb' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

and when it deactivates the plugin does not occur cors error and cors back function normal.

my cors works perfect when deactivates the plugin add_action( 'rest_api_init', function () {

remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );

add_filter( 'rest_pre_serve_request', function ( $value ) {
    header( 'Access-Control-Allow-Origin: ' . get_frontend_origin() );
    header( 'Access-Control-Allow-Methods: GET' );
    header( 'Access-Control-Allow-Credentials: true' );
    return $value;
});

}, 15 );

marianagarciaferreira commented 5 years ago

I was able to solve it like this:

I include the following lines at the top of the qtranslate.php file: ` header ('Access-Control-Allow-Origin: http: // localhost: 8080'); header ('Access-Control-Allow-Methods: GET'); header ('Access-Control-Allow-Credentials: true');

` captura de tela 2019-02-26 as 22 42 55

marianagarciaferreira commented 5 years ago

Does anyone know why I may be having color error when the qtranslate plugin is enabled?

Yesterday I thought I had solved it, but today it was a problem again.

herrvigg commented 5 years ago

Note qTranslate-X is abandoned since 2016 so you will hardly get some help here. But we have been reviving it as qTranslate-XT in this repo: https://github.com/qtranslate/qtranslate-xt

About CORS i have never had some problems but there were redirect issues with the REST API so this might be fixed if this is related.