Skip to content

Instantly share code, notes, and snippets.

@gicolek
Created October 10, 2012 10:57
Show Gist options
  • Save gicolek/3864768 to your computer and use it in GitHub Desktop.
Save gicolek/3864768 to your computer and use it in GitHub Desktop.
Facilitate creation of post types
<?php
/**
* This class facilitates creation of custom post types
* @author Rafal Gicgier <[email protected]>
*/
class Skeleton_Posts {
private $posts = array( );
function __construct($args = array( )) {
$this->posts = $args;
$args = array_merge(
array(
'config_file' => TEMPLATEPATH . DIRECTORY_SEPARATOR . 'skeleton/config.php',
), $args
);
add_action( 'init', array( $this, 'posts_init' ) );
}
function posts_init() {
foreach ( $this->posts as $post ) {
if ( !$post['labels'] ) {
$labels = array(
'name' => _x( 'Slider', 'post type general name' ),
'singular_name' => _x( 'Slider', 'post type singular name' ),
'all_items' => __( 'All slider entries' ),
'add_new' => _x( 'Add new slider entry', 'slider' ),
'add_new_item' => __( 'Add new slider' ),
'edit_item' => __( 'Edit slider entry' ),
'new_item' => __( 'New Slider entry' ),
'view_item' => __( 'View Slider' ),
'search_items' => __( 'Search in slider' ),
'not_found' => __( 'No slider found' ),
'not_found_in_trash' => __( 'No slider found in trash' ),
'parent_item_colon' => '',
);
} else {
$labels = array(
'name' => _x( "{$post['labels']['singular']}", 'post type general name' ),
'singular_name' => _x( "{$post['labels']['singular']}", 'post type singular name' ),
'all_items' => __( "All {$post['labels']['plural']}" ),
'add_new' => _x( "Add new {$post['labels']['singular']} entry", 'slider' ),
'add_new_item' => __( "Add new {$post['labels']['singular']}" ),
'edit_item' => __( "Edit slider {$post['labels']['singular']}" ),
'new_item' => __( "New {$post['labels']['singular']}" ),
'view_item' => __( "View {$post['labels']['singular']}" ),
'search_items' => __( "Search in {$post['labels']['plural']}" ),
'not_found' => __( "No {$post['labels']['plural']} found" ),
'not_found_in_trash' => __( "No {$post['labels']['plural']} found in trash" ),
'parent_item_colon' => '',
);
}
if ( !$post['args'] ) {
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'author', 'custom-fields', 'thumbnail' ),
'has_archive' => 'slider'
);
} else {
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 5,
'supports' => $post['args']['supports'],
'has_archive' => $post['name'],
);
register_post_type( 'skeleton_'.$post['name'], $args );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment