<?php
/**
 * Site Menu Navigation
 *
 * @category Plugins
 * @package  Mtc_Site_Menu
 * @author   mtc. Dawid Bestrzynski <dawid.bestrzynski@mtcmedia.co.uk>
 */

namespace Mtc\Plugins\SiteMenu\Classes;

use Mtc\Plugins\SiteMenu\Classes\SiteMenu;

header('Content-Type: application/json');

$path = '../../../';
require($path . 'core/includes/header.inc.php');

$response = [
    'success' => false
];

if (isset($_REQUEST['menu_name']) && !empty($_REQUEST['menu_name'])) {
    $menu_name = strip_tags((string) $_REQUEST['menu_name']);
    $menu      = SiteMenu::where('name', $menu_name)->first();
    SiteMenu::invalidateCache($menu);
    $response['success'] = true;
}

die(json_encode($response));
