add_action('rest_api_init', function () {
register_rest_route('custom/v1', '/sync', [
'methods' => 'POST',
'callback' => 'handle_sheet_data',
'permission_callback' => '__return_true'
]);
});
function handle_sheet_data($request) {
$data = $request->get_json_params();
$post_id = wp_insert_post([
'post_title' => sanitize_text_field($data['name']),
'post_type' => 'menu_item',
'post_status' => 'publish'
]);
update_field('price', $data['price'], $post_id);
update_field('description', $data['description'], $post_id);
return ['status' => 'success'];
}