<?php
defined( 'ABSPATH' ) || exit;

function AVUP_search_video() {
	check_ajax_referer( 'ajax-nonce', 'nonce' );

	$params = $_POST;

	$search_video = new AVUP_search_video( $params );

	$errors = array();

	if ( $search_video->has_errors() ) {
		$errors = $search_video->get_errors();
	}

	$video = $search_video->get_video();

	wp_send_json(
		array(
			'video'  => $video,
			'errors' => $errors,
		)
	);

	wp_die();
}
add_action( 'wp_ajax_AVUP_search_video', 'AVUP_search_video' );
