Jump to content

Wordpress call third party script from functions file


jarvis

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.