admin管理员组文章数量:1122832
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.
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.
Share Improve this question asked Apr 2, 2024 at 17:22 inf3rnoinf3rno 1356 bronze badges2 Answers
Reset to default 1There 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
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.
本文标签: plugin developmentIs there a way to decide from init whether we are on a certain backend page
版权声明:本文标题:plugin development - Is there a way to decide from init whether we are on a certain backend page? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311816a1934873.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论