从插件注册自定义发布类型

时间:2011-07-12 作者:Peter Gibbons

我试图在激活时从插件注册CPT,但似乎遇到了问题。。。有人看到我丢了什么吗?我没有收到任何错误,但CPT没有显示在仪表板链接中。。。。

    function ctg_cpt_init() {
    register_post_type( \'ctg_questions\',
        array(
            \'labels\' => array(
                \'name\' => __( \'Questions\' ),
                \'singular_name\' => __( \'Question\' )
                ),
        \'public\' => true,
        \'has_archive\' => true,
        \'rewrite\' => array( \'slug\' => \'questions\' )
        )
    );
}
add_action( \'init\', \'ctg_cpt_init\' );

function ctg_rewrite_flush() {
    ctg_cpt_init();
    flush_rewrite_rules();
}
register_activation_hook( __FILE__, \'ctg_rewrite_flush\' );
谢谢你,

1 个回复
最合适的回答,由SO网友:Chip Bennett 整理而成

将CPT注册功能从插件激活挂钩中拉出,以便在init, 在你想要的地方。

插件激活挂钩是一次性挂钩;您需要您的CPT在init 胡克,不止一次。

结束

相关推荐

GPL and plugins

插件开发中心说:“您的插件必须与GPLv2兼容。”。但我发现Topsy插件在GPLv3下。http://www.gnu.org/licenses/rms-why-gplv3.html 声明GPLv2和GPLv3不兼容。那么这应该被允许吗?我想使用Topsy插件中的一些代码。那么,我应该在GPLv2或GPLv3下发布插件吗??