I am building a Wordpress plugin that has standalone PHP that is run via AJAX. As such I am using
define( 'SHORTINIT', true );
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
at the top of the PHP file so that Wordpress functions are available throughout my class and its member functions. However, the Wordpress functions are not available in the member functions.
This is a simplified version of my class but I am getting the error :
Uncaught Error: Call to undefined function wp_insert_post()
define( 'SHORTINIT', true );
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
class fpe_events {
public function add_post_and_meta( $post_data ) {
if( $post_data["ID"] ) {
// Post exists, update it
wp_update_post( $post_data );
} else {
wp_insert_post( $post_data );
}
}
}