我正在创建一个插件来显示所有自定义帖子类型的所有帖子。这有点像edit.php
, 但我不想显示单一的帖子类型,而是希望在一个页面中显示来自多个自定义帖子类型的所有帖子。
我在以下位置学习教程here 创建插件,我做到了。但是现在有一个问题,我想在每个列出的帖子下面添加垃圾链接(就像edit.php
). 此字段需要一个nonce才能运行,但我无法了解它的工作方式。
这是我的代码:
function column_post_title($item){
$actions = array(
\'edit\' => sprintf(\'<a href="\'.admin_url(\'post.php?post=%s&action=edit\').\'">Edit</a>\',$item[\'ID\']),//this part is fine
\'trash\'=> sprintf(\'<a href="\'.wp_nonce_url(admin_url().\'post.php?post=%s&action=trash\', \'trash-%s\').\'">Trash</a>\',$item[\'ID\'],$item[\'ID\']),//here I cant get it right!!
);
return sprintf(\'%1$s %2$s\', $item[\'post_title\'], $this->row_actions($actions) );
}
我需要创建自己的nonce吗?或者使用exist(如果有)。根据上面的代码,它会给我WordPress故障通知,并带有:是否确实要执行此操作?请重试。