Jump to content

Wordpress call third party script from functions file

Recommended Posts

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 ) )
        #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?



Share this post

Link to post
Share on other sites


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?

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.