Answer the question
In order to leave comments, you need to log in
How to connect wp functions to your php file?
I created a WP plugin, in the plugin folder I created a second php file that executes a post cURL request and direct access is allowed to it .
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
$body = array(
'id' => '1',
'user_id' => '100'
);
$args = array(
'body' => $body
);
$response = wp_remote_post( 'https://site.ru/test.php', $args );
$body = wp_remote_retrieve_body( $response );
echo $body;
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
? If you need to have 'pages' directly accessible by an external service, then you must use query_vars and/or rewrite the rules to create a virtual page that calls the function.
Please see the plugins API reference for more information: codex.wordpress.org/Plugin_API
if you are trying to use AJAX please read this: codex.wordpress.org/AJAX_in_Plugins
For other possibilities, or better understand why we don't allow it, read this: ottopress.com/2010/dont-include-wp-load-please
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
’s impossible to connect, because. this loads the entire wp system and the file path may be different for different wp users. Answer the question
In order to leave comments, you need to log in
Use CURL?
$curl = curl_init();
$url = "https://site.ru/test.php";
$args = array(
'id' => '1',
'user_id' => '100'
);
curl_setopt_array($curl,
array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $args,
CURLOPT_RETURNTRANSFER => true,
)
);
$data = curl_exec($curl);
curl_close($curl);
echo $data;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question