__( 'Do you want to create a new object called "{title}"?', 'acf-add-rel' ) ) ); } add_action('acf/input/admin_enqueue_scripts', 'admin_enqueue_scripts_acf_rel'); /** * Create new posts via ajax. * Requires title and post_type to be present in $_POST * * @return array */ function acf_create_rel_post() { // validate nonce first if( ! wp_verify_nonce( $_POST['nonce'], 'acf_nonce' ) ) { wp_send_json_error(); } if ( ! current_user_can( 'publish_posts' ) ) { wp_send_json_error(); } // collect and santize data before insertion $title = sanitize_post_field( 'post_title', $_POST['title'], null, 'db' ); $post_type = sanitize_post_field( 'post_type', $_POST['post_type'][0], null, 'db' ); if ( ! empty( $title ) && ! empty( $post_type ) ) { // allow other developers to filter arguments $post_id = wp_insert_post( apply_filters( 'acf_add_rel_post_args', array( 'post_type' => $post_type, 'post_title' => $title ) ) ); } wp_send_json_success( apply_filters( 'acf_add_rel_post_created', $post_id )); } add_action( 'wp_ajax_acf/fields/relationship/create_post', 'acf_create_rel_post' );