很多时候,我可能会检查post数据中是否存在变量,然后做一些事情。我很难理解用户创建或更新帖子时发生了什么。我做任何类型的后端功能都没有问题,但是当我想输出一些东西时,我猜页面被重新定向了?您通常如何处理这项常见任务?如何基于post变量的存在或任何即时操作创建管理通知?
这里发生了什么:
<?php
/*
Plugin Name: Echo something on presence of variable
Plugin URI: http://wordpress-bdd.com/
Description: Hooking into the redirect with post variables
*/
class WhatIsGoingOn{
public function __construct(){
//add meta box:
add_action(\'load-post.php\', array($this, \'doAddMetaBoxes\'));
add_action(\'load-post-new.php\', array($this, \'doAddMetaBoxes\'));
$this->whyCantIechoThisNotice();
}
public function doAddMetaBoxes(){
add_meta_box(\'metaWithInput\', \'Hello\', array($this, \'echoMetaBox\'), \'post\', \'side\', \'high\');
}
public function echoMetaBox(){
echo("<input type = \'text\' name = \'myInput\' id = \'myInput\' />");
}
public function whyCantIechoThisNotice(){
//check for presence of variable and do something:
if (isset($_POST[\'myInput\']) && (!($_POST[\'myInput\'] == ""))){
//If this line is uncomented, the die fires
//die(\'I am here!\');
//How do I get the notice to echo?
echo ("
<div class=\'notice notice-success is-dismissible\'>
<p>This is a notice</p>
</div>
");
}
}
}
$WhatIsGoingOn = new WhatIsGoingOn;