Register the post type.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Register our custom post type. */
function gaj_register_post_type() {
    register_post_type('gaj_offer',
        array(
            'capability_type'      => 'post',
            'description'          => 'A print subscription offer',
            'has_archive'          => false,
            'hierarchical'         => false,
            'map_meta_cap'         => true,
            'menu_position'        => 5,
            'register_meta_box_cb' => 'gaj_set_up_metabox',

            # Set up visibility.
            'public'              => true,
            'publicly_queryable'  => true,
            'exclude_from_search' => true,
            'show_ui'             => true,
            'show_in_menu'        => true,
            'show_in_nav_menus'   => false,

            # Set up commonly used labels.
            'labels' =>
                array(
                    'name'               => 'Subscription Offers',
                    'singular_name'      => 'Subscription Offer',
                    'all_items'          => 'Offers',
                    'add_new_item'       => 'Add New Offer',
                    'edit_item'          => 'Edit Offer',
                    'new_item'           => 'New Subscription Offer',
                    'view_item'          => 'View Offer',
                    'search_items'       => 'Search Offers',
                    'not_found'          => 'No subscription offers found',
                    'not_found_in_trash' => 'No subscription offers found in the trash',
                    'menu_name'          => 'Offers'
                ),

            # Set rewrite parameters.
            'rewrite' =>
                array(
                    'slug'       => 'print-subscription',
                    'with_front' => false,
                    'feeds'      => false
                ),

            'supports' => array('title', 'author')
        )
    );
}

Hook into init to register the post type.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Selectively initialize.
function gaj_init() {

    require_once GAJ_LIB_PATH . '/lib-common.php';
    gaj_register_post_type();

    if (is_admin()) {
        require_once GAJ_LIB_PATH . '/run-admin.php';
    }
    else {
        require_once GAJ_LIB_PATH . '/run-frontend.php';
    }
}

# Add our init hook.
add_action('init', 'gaj_init', 0);

Run stuff when activated.

1
2
3
4
5
6
7
8
# Include activation code.
function gaj_activate() {
    require_once GAJ_LIB_PATH . '/run-activation.php';
}

# Run some stuff when the plugin is activated.
register_activation_hook(__FILE__, 'gaj_activate');

From run-activation.php:

1
2
3
4
# Set up the custom post type, probably for the first time.
flush_rewrite_rules();
gaj_register_post_type();