jarvis Posted August 25, 2017 Share Posted August 25, 2017 Hi All, I'm going mad trying to get something to work. I've a script add.php which is a cURL script and passes an XML file to another site. - If I run this script on it's own, it works What I'm trying to do: When a new post is published, run a function (below) that generates an XML file (this works), then fire/trigger the other script (add.php) so the cURL part does its job and posts the XML file to the other site. However, no matter how I try to reference the add.php file within my function, it simply won't run (I've set an email to be triggered if successful within add.php). Here's the function and the various attempts I've tried: add_action( 'transition_post_status', 'my_function', 10, 3 ); function my_function( $new_status, $old_status, $post ) { if ( 'publish' !== $new_status or 'publish' === $old_status || 'post_type' !== get_post_type( $post ) ) return; #code to create xml goes here #require_once dirname(__FILE__) . '/add.php'; #wp_enqueue_script ( 'add', get_template_directory_uri() . '/add.php' ); #include ('https://www.domain.co.uk/wp-content/themes/theme_name/add.php'); #include( get_home_path() . '/add.php' ); #include( get_template_directory() . '/add.php' ); require ('https://www.domain.co.uk/wp-content/themes/theme_name/add.php'); } Am I missing something obvious? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/304708-wordpress-call-third-party-script-from-functions-file/ Share on other sites More sharing options...
requinix Posted August 25, 2017 Share Posted August 25, 2017 That require ('https://www.domain.co.uk/wp-content/themes/theme_name/add.php');is no good. Bad, even. Never use require/include to execute PHP code from some URL, even if it's your own site. What is the code for the script that works on its own? Quote Link to comment https://forums.phpfreaks.com/topic/304708-wordpress-call-third-party-script-from-functions-file/#findComment-1550186 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.