Dev Kabir
Forum Replies Created
-
Forum: Plugins
In reply to: [Enable CORS] facebook CORS policyDear @zajac007
Thank you for reaching out to me regarding the CORS policy blocking issue with the Facebook Customer Chat Plugin on your WordPress website.
The error message you’re encountering indicates that the request from your website to Facebook’s servers is being blocked due to CORS (Cross-Origin Resource Sharing) policy restrictions. This commonly occurs when the server hosting the requested resource (in this case, Facebook’s servers) does not include the appropriate CORS headers to allow requests from other origins.
To resolve this issue, you can try the following steps:
- Contact Facebook Support: Since the resource being blocked is hosted on Facebook’s servers, it’s best to reach out to Facebook support or consult their documentation to ensure that the Customer Chat Plugin is configured correctly to allow requests from your website’s origin.
- Use a Proxy Server: You can set up a proxy server on your own server to forward requests to Facebook’s servers. This way, the request will originate from your server’s domain, bypassing the CORS restrictions. However, setting up and maintaining a proxy server requires technical expertise and may not be feasible for all users.
- Utilize a CORS Proxy Service: There are third-party CORS proxy services available that can help bypass CORS restrictions by proxying requests through their servers. You can explore these services as a temporary workaround, but keep in mind that relying on third-party services may introduce additional latency and security concerns.
- Check Plugin Settings: Ensure that the settings for the Facebook Customer Chat Plugin within your WordPress dashboard are configured correctly. There might be an option to specify allowed origins or domains from which requests are permitted.
Forum: Plugins
In reply to: [Enable CORS] PHP Warning: Cannot modify header informationSince we haven’t received a response from you, I’m proceeding to close this thread. Please know that you’re welcome to contribute to this thread at any time by adding your message.
Forum: Plugins
In reply to: [Enable CORS] PHP Warning: Cannot modify header informationHi @alian
Thank you for reaching out and bringing this to my attention. The warnings you’re experiencing seem to be related to header modification in this plugin’s code.
Here’s what you can try to resolve this:
Disable all other plugins and see if the issue persists. If it doesn’t, re-enable them one by one to find the conflicting plugin.
If you continue to experience issues after trying these steps, please let me know, and I’ll do my best to assist you further.
Thank you for your patience and cooperation.
Forum: Plugins
In reply to: [Enable CORS] CORS not working for images in wp-content/uploads folders// Register a custom REST API endpoint when the rest_api_init action is triggered add_action('rest_api_init', function () { // Define a REST route under the 'loadImage' namespace with the path '/content/' // Set the HTTP method to 'GET' and specify the callback function as 'fetchImage' register_rest_route('loadImage', '/content/', array( 'methods' => 'GET', 'callback' => 'fetchImage', )); }); // Define the callback function 'fetchImage' that will handle the logic for fetching and returning images function fetchImage($data) { // Retrieve and sanitize the URL parameter from the incoming request data $url = esc_url_raw($data->get_param('url')); // Validate the provided URL if (!filter_var($url, FILTER_VALIDATE_URL)) { // If the URL is invalid, return a WP_Error indicating an invalid URL with a 400 Bad Request status return new WP_Error('invalid_url', 'Invalid URL provided.', array('status' => 400)); } // Get image data (dimensions, MIME type, etc.) for the specified URL /** * Do not use getimagesize() to check that a given file is a valid image. Use a purpose-built solution such as the Fileinfo extension instead. * @link https://www.php.net/manual/en/function.getimagesize.php */ $info = getimagesize($url); // Check if image data is available if (!$info) { // If image data is not available, return a WP_Error indicating an invalid image URL // or an inability to fetch image data with a 400 Bad Request status return new WP_Error('invalid_image', 'Invalid image URL or unable to fetch image data.', array('status' => 400)); } // Set appropriate headers in the response to indicate the MIME type of the image header("Content-type: " . $info['mime']); // Output the binary image data from the specified URL readfile($url); // Terminate the script to prevent additional output die(); }This is the explanation of the code he used to solve this problem.
Forum: Plugins
In reply to: [Enable CORS] CORS not working for images in wp-content/uploads foldersThank you so much for sharing your solution with the community!
I appreciate your proactive approach in finding a resolution to the CORS issue when returning images to another site.
Forum: Plugins
In reply to: [Enable CORS] No support for PATCHThank you for providing detailed information.
My main goal is to be able to restrict
Access-Control-Allow-Originfor/wp-jsonand keep the other headers as is.I believe plugin is well-equipped to achieve this goal effectively.
I actually don’t know if PATCH is in use or not, I’m not that familiar with the WordPress REST API.
Typically, the majority of requests involve GET and POST methods, with OPTIONS commonly employed for pre-flight requests. But as I promised you before,
If any 5 user, like yourself, opens or adds a thread to enable the PATCH method, I will include that in the next update.
Because,
There are five extended versions of this plugin available outside the official repository, each tailored to meet specific client requirements. The versions outside the repository cater to more advanced needs. However, This plugin is designed as a basic solution, primarily targeting non-tech-savvy users seeking a straightforward CORS resolution.
Considering your technical expertise, I believe you have the capability to address any security concerns that may arise, a proficiency that might surpass the typical user of this plugin. Many users of the basic version may not possess the same technical know-how.
If you have any specific security considerations or if there’s anything you’d like assistance with, please feel free to share. Your insights are valuable in enhancing the overall user experience.
Space is optional according to the spec, but improves readability.
It’s important to note that the options’ reader is the server, and in this context, I don’t foresee any noticeable performance improvement with the inclusion of spaces.
The plugin actually uses spaces in
Access-Control-Allow-HeadersI will remove space in next update.
Forum: Plugins
In reply to: [Enable CORS] No support for PATCHIt is only available on the Subversion repository.
“No support for PATCH.”
At this moment, most users of this plugin are utilizing it for GET, POST, and OPTIONS methods. If any 5 user, like yourself, opens or adds a thread to enable the PATCH method, I will include that in the next update.
“Commas should be followed by a space (” “).”
If you could explain or add a relevant resource link discussing the pros and cons of this, I would be grateful to you.
Forum: Plugins
In reply to: [Enable CORS] No support for PATCHHave you tested these options after adding space? Could you please provide a relevant source link so that anyone can review your suggestion?
Forum: Plugins
In reply to: [Enable CORS] Wrong value for access-control-allow-credentialsHello @oyvindwe,
Thank you for getting in touch.
You can set the value of Access-Control-Allow-Credentials to 1 instead of true. As far as I have checked, it’s working fine.
However, it is recommended to use the Boolean value true instead of the string value 1. I will include your fix in the next update.
Forum: Plugins
In reply to: [Enable CORS] CORS not working for images in wp-content/uploads foldersForum: Plugins
In reply to: [Enable CORS] CORS not working for images in wp-content/uploads foldersHello @rogerskk,
Thank you for reaching out.
I believe the plugin has successfully enabled CORS. You can verify this by using the test link. If you want to check whether an image is shared or not, you can do so using this test.
The CORS error you’re encountering is due to the origin
motiontees.combeing added. You can think of the origin as the website domain. So, you’re sendingstore.motiontees.comfrom thecors-test.codehappy.devdomain. and your settings allowedmotiontees.comThe root domain and API are passed because the plugin has added a temporary server configuration to bypass your main server configuration. This allows requests that have a specific extension like .jpg, .mp4, etc., as per your settings. and root or API URL does not have any extensions.
Another test you could perform involves disabling all other plugins, leaving only this one active. Then, observe how it performs. According to this thread, the issue seems to have been caused by another plugin.
If the issue persists, it’s possible that your ASP.NET server doesn’t allow temporary server configurations. In this case, you’ll need to modify your server’s configuration settings for images.
Let me know if you need help with anything else! 😊
FYI: I’m marking this issue as resolved for now. However, feel free to add more replies to this thread at any time. I’ll respond as soon as I can, based on my availability, and assist with any further questions you may have.
If your website is hosted on an nginx server, you can uninstall this plugin as it will not provide any benefits for you.
I have sent you a code snippet via email.
Please confirm whether it is functioning correctly on your site. If everything is working as expected, I will include that code snippet here, so that others can resolve the same issue.
Hello @michaeledi,
Thank you for reaching out and for using my plugin. I understand the frustration you’re experiencing, and I’m here to help.
Firstly, I appreciate you providing detailed information about the issue you’re facing. The CORS test result on https://cors-test.codehappy.dev/ suggests that the necessary headers are being sent correctly by your server. However, the error message you’re encountering on the origin site indicates otherwise.
To assist you further, could you please provide the following information,
Server Configuration, Screenshot of Plugin Configuration, Your Site url.
Feel free to share this information either in this conversation or via email. If you choose to email, you can send the details to [email protected].
Forum: Plugins
In reply to: [Enable CORS] thanks it’s workHello @natthapongw
I appreciate your feedback and your kind words. If you have any other questions or concerns, please let me know.