  We present a joint theoretical and experimental study of the oxygen $K$-edge
spectra for LaFeO$_3$ and homovalent Ni-substituted LaFeO$_3$
(LaFe$_{0.75}$Ni$_{0.25}$O$_3$), using first-principles simulations based on
density-functional theory with extended Hubbard functionals and x-ray
absorption near edge structure (XANES) measurements. Ground-state and
excited-state XANES calculations employ Hubbard on-site $U$ and inter-site $V$
parameters determined from first principles and the Lanczos recursive method to
obtain absorption cross sections, which allows for a reliable description of
XANES spectra in transition-metal compounds in a very broad energy range, with
an accuracy comparable to that of hybrid functionals but at a substantially
lower cost. We show that standard gradient-corrected exchange-correlation
functionals fail in capturing accurately the electronic properties of both
materials. In particular, for LaFe$_{0.75}$Ni$_{0.25}$O$_3$ they do not
reproduce its semiconducting behaviour and provide a poor description of the
pre-edge features at the O $K$ edge. The inclusion of Hubbard interactions
leads to a drastic improvement, accounting for the semiconducting ground state
of LaFe$_{0.75}$Ni$_{0.25}$O$_3$ and for a good agreement between calculated
and measured XANES spectra. We show that the partial substitution of Fe for Ni
affects the conduction-band bottom by generating a strongly hybridized
O($2p$)-Ni($3d$) minority-spin empty electronic state. The present work, based
on a consistent correction of self-interaction errors, outlines the crucial
role of extended Hubbard functionals to describe the electronic structure of
complex transition-metal oxides such as LaFeO$_3$ and
LaFe$_{0.75}$Ni$_{0.25}$O$_3$ and paves the way to future studies on similar
systems.
