在 Wordpress 管理区域中为自定义帖子类型创建自定义管理编辑页面

时间:2021-02-09 04:39:23

标签: wordpress

我以前这样做过,但现在不能用了。

对于自定义帖子类型,当我选择“编辑”时,它会转到我自己的特殊管理页面。

我使用...注册我自己的管理页面

add_action( 'admin_menu', [__CLASS__, 'registerAdminPage'] );

public static function registerAdminPage() {
    add_submenu_page(null, 'Manage Lead', 'Manage Lead', 'manage_options', 'nji-manage-lead', [__CLASS__, 'buildPage'] );
}

使用null作为第一个参数,因为我实际上并不希望出现菜单项,我只想注册页面。

一个简单的 html 渲染方法来检查自定义页面是否正常工作...

public static function buildPage() { ?>
    <h1>Leads Edit Page</h1>
<?php }

我过滤了编辑链接,使它们指向自定义管理页面...

add_filter( 'get_edit_post_link', [__CLASS__, 'filterEditPostLink'], 10, 3);    

public static function filterEditPostLink($link, $id, $context ) {
    $post = get_post( $id );

    if( $post->post_type !== self::$_postTypeName )
        return $link;

    return sprintf('edit.php?post=%d&post_type=%s&page=nji-manage-lead', $id, self::getPostTypeName()); 
} 

页面只是给出了这个通知

Error message presented on attempted admin page load

我也以管理员权限登录。我不明白为什么这会失败。

0 个答案:

没有答案