You could try to replace:
if (is_front_page()) {
$menuIdOfCurrentPage = 0;
with a check for the page_on_front
option:
if(
is_int( $postID )
&& $postID > 0
&& $postID === (int) get_option( 'page_on_front' )
) {
$menuIdOfCurrentPage = 0;
Here we added a check to see if $postID
is a positive integer, because the page_on_front
option is 0 if no page is selected as a frontpage.
Then consider renaming $menuIdOfCurrentPage
to $menuIdOfPage
.
In PHP 7, we could for example use strict scalar type declerations:
function getMenuChildren( int $menuId, int $postId )
{
where it would throw a TypeError when used with non integer input arguments:
Fatal error: Uncaught TypeError: Argument 1 passed to
getMenuChildren() must be of the type integer, none given, called in
[…][…] on line 10 and defined in […][…]
using declare( strict_types = 1 );
.