Created
May 17, 2016 20:31
-
-
Save ronalfy/bc23787360ca92a7583dbdf86a46f99e to your computer and use it in GitHub Desktop.
Custom Theme Types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Custom Theme Types | |
Plugin URI: http://bigwing.com | |
Description: Content Types and Meta Boxes | |
Author: BigWing Interactive | |
Version: 1.0.0 | |
Requires at least: 4.1 | |
Author URI: http://bigwing.com | |
Contributors: ronalfy, bigwing | |
*/ | |
class Custom_Theme_Types { | |
private static $instance = null; | |
private $post_types = ''; | |
//Singleton | |
public static function get_instance() { | |
if ( null == self::$instance ) { | |
self::$instance = new self; | |
} | |
return self::$instance; | |
} //end get_instance | |
private function __construct() { | |
add_action( 'init', array( &$this, 'init' ), 9 ); | |
add_action( 'cmb2_admin_init', array( &$this, 'custom_meta_boxes' ) ); | |
$this->post_types = array( | |
'gallery', | |
); | |
require_once( 'class-cpt-sub-menus.php' ); | |
foreach( $this->post_types as $post_type ) { | |
new Custom_Theme_CPT_Admin( $post_type ); | |
} | |
} //end init | |
public function init() { | |
$labels = array( | |
'name' => 'Galleries', | |
'singular_name' => 'Gallery', | |
'menu_name' => 'Galleries', | |
'name_admin_bar' => 'Galleries', | |
'add_new' => 'Add New', | |
'add_new_item' => 'Add New Gallery', | |
'new_item' => 'New Gallery', | |
'edit_item' => 'Edit Gallery', | |
'view_item' => 'View Gallery', | |
'all_items' => 'All Galleries', | |
'search_items' => 'Search Galleries', | |
'parent_item_colon' => 'Parent Gallery:', | |
'not_found' => 'No Galleries found.', | |
'not_found_in_trash' => 'No Galleries in trash.' | |
); | |
register_post_type( 'gallery', array( | |
'public' => true, | |
'label' => 'Galleries', | |
'labels' => $labels, | |
'hierarchical' => false, | |
'menu_position' => 20, | |
'menu_icon' => 'dashicons-format-image', | |
'supports' => array( 'title', 'page-attributes' ), | |
'has_archive' => true, | |
'rewrite' => array( | |
'slug' => 'gallery', | |
'with_front' => false, | |
) | |
) ); | |
} | |
public function custom_meta_boxes() { | |
$cmb = new_cmb2_box( array( | |
'id' => 'galleries', | |
'title' => 'Gallery Images', | |
'object_types' => array( 'gallery' ), // Post type | |
'context' => 'normal', | |
'priority' => 'high', | |
'show_names' => true, // Show field names on the left | |
// 'cmb_styles' => false, // false to disable the CMB stylesheet | |
// 'closed' => true, // Keep the metabox closed by default | |
) ); | |
$cmb->add_field( array( | |
'name' => 'Gallery Files', | |
'desc' => '', | |
'id' => '_gallery_list', | |
'type' => 'file_list', | |
// 'preview_size' => array( 100, 100 ), // Default: array( 50, 50 ) | |
// Optional, override default text strings | |
'text' => array( | |
'add_upload_files_text' => 'Gallery Image', // default: "Add or Upload Files" | |
'remove_image_text' => 'Gallery Image', // default: "Remove Image" | |
'file_text' => 'Gallery Image', // default: "File:" | |
'file_download_text' => 'Gallery Image', // default: "Download" | |
'remove_text' => 'Gallery Image', // default: "Remove" | |
), | |
) ); | |
} | |
} | |
add_action( 'plugins_loaded', 'custom_theme_instantiate' ); | |
function custom_theme_instantiate() { | |
Custom_Theme_Types::get_instance(); | |
} //end braumstypes_instantiate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment