Why is json_decode failing?

I'm trying to determine if this is related to my having the latest version of PHP on my server while using the latest version of Wordpress. Or if I'm just doing it wrong: Here's my function that is correctly returning values (I can see them when I do an echo or a var dump): function my_Get_CURL (){ $url = 'http://someotherserver/event/94303?radius=30'; // Initiate curl $ch = curl_init(); // Disable SSL verification curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Will return the response, if false …
Category: Web

Is curl required?

My admin panel is very slow I've tried to debug the issue. I nailed it to the function wp_remote_post and an internal error message thrown by curl on this line return new WP_Error( 'http_request_failed', curl_error( $handle ) ); I wonder what would have happened if I uninstalled curl. Can WordPress use other mechanisms to make http requests or is curl required?
Category: Web

Creating a post with the REST API, curl and oauth returning 401 error

I'm trying to create a WordPress post using the REST API, OAuth, and cURL. However, I'm running into some trouble. I'm able to create a blank post (no title, slug, etc) using the following code: $header = array(buildAuthorizationHeader($oauth), 'Expect:'); $options = array( CURLOPT_HTTPHEADER => $header, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_POST => true, CURLOPT_URL => $url, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false); This works as expected - authorizes successfully, and …
Category: Web

How to convert this cURL to wp_remote_*?

My function below includes a cURL call which throws a text string at a Google Cloud text analysis API, returning a response object, which we then parse to get a specific piece. It has been recommended to me that I switch the cURL PHP statement to use WordPress' wp_remote_get. I have read the docs for that but, to be honest, I don't understand how my cURL header fields should map to wp_remote_get arguments. Or even if it should be wp_remote_post …
Category: Web

Simulating timeout is not working

I am trying to simulate a timeout response when using wp_remote_get() for better debugging. This is the code I'm using: set_time_limit( -0 ); ini_set('max_execution_time', 0); $args = array( 'headers' => array( 'Content-Type' => 'application/json', 'timeout' => 15, ), ); $request_response = wp_remote_get( $this->token_url . '&sleep=10', $args ); This is the response (WP_Error): cURL error 28: Operation timed out after 5000 milliseconds with 0 bytes received It doesn't matter if I change the value of set_time_limit It doesn't matter if I …
Category: Web

Using file_get_contents within admin but keep logged in

Quick question as I'm not having much luck finding an answer on Google. I'm running a file_get_contents in a plugin I'm building to get the HTML of another page within the admin. The HTML is showing but the problem is, it's loading the /wp-login.php page HTML and not the specified URL. $data = file_get_contents('wp-admin/options-general.php?page=another_page'); $html_sourcecode_get = htmlentities($data); echo $html_sourcecode_get; Does anyone know how to keep the HTML grab as if I was still logged in? Do I need to use …
Category: Web

mysqli_query(): MySQL server has gone away for Curl Request

I have created a WordPress Plugin which after activating shows result in jquery Datatable. We are fetching the result via CURL Post. The Post URL is a ASP.Net Application on Windows Server. The plugin is created for my client who is experiencing below error after adding my shortcode in a Post. Client is using Elegant Themes' Divi (latest version), WordPress 5.2.2 running on Apache / PHP 7.2.21 This error is showing only on that Post page where the shortcode is …
Category: Web

cURL External API request displays content above other content on page

I've built a plugin to display our customer feedback on our WordPress website. We use an external feedback system called 'Customer Thermometer'. They have a simple API to use a URL to request stats and comments etc. This example is showing total stats but I have a bigger comments block function that shows recent comments in a slider. Sample URL to get the total responses back: https://app.customerthermometer.com/api.php?apiKey=[apiKey-here]&getMethod=getNumResponsesValue I can get the responses back fine using the code below but the …
Category: Web

Wordpress from url get external source title

Hi I am building a news website. I am trying to automate it. News url (metabox) Title Content area Image (featured image option on wordpress) When paste the site url I would like the other metabox to pull the data from the source http://www.bbc.co.uk/news/technology-34527439 I want title and description to pulled form bbc website News url: http://www.bbc.co.uk/news/technology-34527439 Title: Should be fetched from <title> Content area: should be from <meta name="description".> Image: Should be first image on the content I see …
Category: Web

How to convert this cURL to wp_remote_get?

I want to convert curl to wp_remote_get. $url = 'https://accounts.google.com/o/oauth2/token'; $curl_post = 'client_id=' . $client_id . '&redirect_uri=' . $redirect_uri . '&client_secret=' . $client_secret . '&code=' . $code . '&grant_type=authorization_code'; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $ch, CURLOPT_POST, 1 ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $curl_post ); $data = json_decode( curl_exec( $ch ), true ); $http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
Category: Web

File Type Is Not Permitted - Cronjob

I am currently developing a cron job that downloads a xml file from an external source and stores it within wordpress media. For debugging proposals, I have installed the plugin Advanced Cron Manager, which allows me to run cron jobs manually. The manual execution of the cronjob works fine, without any problems. When the cronjob is executed by its schedule, I am facing: "Sorry, This File Type Is Not Permitted for Security Reasons". Within my cron function, I have configured: …
Category: Web

Curl error while creating user

I have a problem when trying to create users with authentication via plugin: "application passwords" curl -X POST --user "applogin:y530 8Uf9 OMSW sSsR Q0S8 zaqS" "http://website.com//wp-json/wp/v2/users" -d "username=TestUser&password=A1b2c3d4&[email protected]" -H "Content-Type: application/x-www-form-urlencoded" return errror: "Sorry, you are not allowed to create new users" What could this be caused by? On the local instance it worked
Topic: curl Wordpress
Category: Web

export a csv file from the database with a cronjob

I'm using an event plugin, which doesn't have a user-friendly function for showing a list of bookings. That's why I wrote a php+js script myself to display that data in a nice way. But to use my own script I need the booking data from the wp database. The MEC-plugin gives me an option to export this booking data in csv format from the admin dashboard. But I want to use this export as a cronjob, but have the hardest …
Category: Web

Call external API in wordpress based on user input

I want to create a simple wordpress website in which I want to display a search box on a page. On searching a string in text/search box, an external API call should be made based on that string and the data returned by the API should be shown to user. I have successfully referred code from below URL so far - https://rapidapi.com/blog/integrate-external-api-wordpress/. But I am not able to make a call to API based on string passed in text box. …
Category: Web

CURL error with REST API

Having a very odd behavior. Using site health plugin; I was getting errors with CURL & Loopback. At any rate, I fixed both these issues on the server; however, it appears that other websites (also wordpress) on the same server still exhibit the error. Is there someway to make WP notice the changes that I am missing?
Category: Web

Getting Download failed. cURL error 28: Connection timed out after 10001 milliseconds

I'm trying to install some external plugins that came with my theme and I can't see to find a way to get the communication to work properly. I also have this issue being reported when trying to start a scan in Wordfence. Likewise, I am using Cyberpanel and Open Litespeed. Furthermore, I own the server, so I can make changes there both in the firewall and well as the configurations. If anyone could help me with this issue it would …
Category: Web

Download failed cURL error 7: . Can't update anything

Please, help. I want to update WordPress(or plugins), but always the same error: 'Download failed: cURL error 7: .' OS: Linux Fedora 30. Server: nginx. DB: MySQL 8.0. PHP 7.3 I have installed all the needed PHP extensions. Curl is working - I tested to download google HTML using curl and info.php says thas cURL is enabled. Why WordPress can't update anything? Nginx error.log does not have mistakes. On another laptop (Windows 10) with the same development environment, everything works. …
Category: Web

How to create a post using REST API with sending data as a JSON body?

I am able to create posts on my WordPress website using it's REST API with the below curl request format. Website uses basic auth plugin for the authentication process. curl --user "username:password" -X POST -i https://mywebsite.com/wp-json/wp/v2/posts?title=myTitle&content=MyContent However, my problem is I need to set custom fields of the post when creating a post using REST API. I tried to send data as a JSON body using the below command and it didn't work. It just returns all the posts without …
Category: Web

Wordpress curl timing out and saying 'Moved Permanently'

I tried updating to wordpress 5.6 and it did not work. I tried installing a plugin for offline updates and the plugin install gave the same error: Download failed.: cURL error 28: Connection timed out after 10001 milliseconds Which is very strange since when I'm SSH'd in I can curl the exact link that it is updating to just fine, but it actually gives me what appears to be the problem: $ curl http://downloads.wordpress.org/release/wordpress-5.6-new-bundled.zip <html> <head><title>301 Moved Permanently</title></head> <body> <center><h1>301 …
Category: Web

wp_remote_get - cURL error 28 - only on same domain

On my website I use wp_remote_get to fetch data from mydomain.com/wp-json/wp/v2/pages/75 When I run it on my localhost it works fine, but after sending to production server (mydomain.com) suddenly I’m getting error: ‘cURL error 28: Operation timed out after 5000 milliseconds with 0 bytes received’ + VPS starts acting crazy (100% cpu usage and memory). It can’t retrieve data from the same domain. When I changed url to some random REST mockup it is working again. How can I get …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.