1
votes

I just got a hang of writing my first plug-in. It consist of two custom post types, with two different types of custom meta boxes attached to them. I got the saving of that working and even a function for a shortcode and displaying it on the front end.

But it all turned out really messy, so I decided to rewrite it. I came over something called "WordPress Plugin Boilerplate" which did seem pretty popular. But I just can't understand where I should put everything.

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

Could anyone explain to me where I should play for example, custom post type, add meta box, saving that meta box info etc.

IF NOT maybe someone has a good summary on good plugin structure?

1
I think Devin's is a bit complicated boilerplate for someone who's starting... You'll find good examples/links in this results: wordpress.stackexchange.com/questions/tagged/…, like this one - brasofilo

1 Answers

1
votes

Well, WordPress-Plugin-Boilerplate is some ready made scaffolding based on author's best practices and common code required by several plugins, you don't need to use this if your only requirement is just adding custom post types and adding meta boxes. All you need is to create correct plugin header and your CPT code.

For example:

<?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,
        )
    );
}