On frontend pages I can do something like
$currentPostId = url_to_postid($_SERVER['REQUEST_URI']);
if ($currentPostId && $currentPostId === $postId)
// ...
So when I add a programmatically generated page I can know in init whether I am on that page. This is very useful because I can process POSTs before rendering the page and so I can redirect with a location header. I am looking for a backend solution:
add_menu_page(
$this->page->getTitle(),
$this->page->getMenuTitle(),
$this->page->getCapability(),
$this->page->getId(),
function (){
$this->page->render();
},
$this->page->getMenuIcon(),
$this->page->getMenuPosition()
);
I do something like the upper, but I'd like to do a page init before rendering. Currently I initialize all the pages which is wasting resources when I know that the form I sent is on a certain page. So I just have to initialize that page and process the POST request.