Wordpress插件Boilerplate(插件结构)-自定义帖子类型,元框和保存元信息


Wordpress Plugin Boilerplate (Structure of Plugin) - Custom Post Types, Meta Boxes and Saving Meta Info?

我刚刚掌握了编写第一个插件的窍门。它由两种自定义帖子类型组成,并附加了两种不同类型的自定义元框。我节省了工作时间,甚至还为一个短代码提供了一个功能,并将其显示在前端。

但结果真的很混乱,所以我决定重写它。我发现了一个叫做"WordPress插件沸腾板"的东西,它看起来确实很受欢迎。但我就是不明白我应该把所有东西都放在哪里。

https://github.com/DevinVinson/WordPress-Plugin-Boilerplate

有人能向我解释一下我应该在哪里玩吗?例如,自定义帖子类型,添加元框,保存元框信息等。

如果不是也许有人对良好的插件结构有很好的总结?

好吧,WordPress插件Boilerplate是一些现成的脚手架,基于作者的最佳实践和几个插件所需的通用代码,如果你唯一的要求只是添加自定义帖子类型和添加元框,你就不需要使用它。您所需要的只是创建正确的插件头和CPT代码。

例如:

<?php
/*
Plugin Name: My Toolset
Plugin URI:  http://URI_Of_Page_Describing_Plugin_and_Updates
Description: This describes my plugin in a short sentence
Version:     1.5
Author:      John Smith
Author URI:  http://URI_Of_The_Plugin_Author
License:     GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Domain Path: /languages
Text Domain: my-toolset
*/
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
add_action( 'init', 'create_post_type' );
//Registers the Product's post type
function create_post_type() {
    register_post_type( 'acme_product',
        array(
            'labels' => array(
                'name' => __( 'Products' ),
                'singular_name' => __( 'Product' )
            ),
        'public' => true,
        'has_archive' => true,
        )
    );
}