1

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.

2 Answers 2

1

There are few functions/global variable in WP to determine

is_admin() - For checking if in admin panel
global $pagename  - to get the page name of admin 
0

I ended up checking the $_GET['page'] === $this->page->getId() and checking is_admin(). Not the perfect solution, but I did not have anything better for now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.