function custom_init()
{
    global $template_directory;
    require $template_directory . '/inc/classes/bfi-thumb.php';
    require $template_directory . '/inc/classes/custom-post-type.php';
    require $template_directory . '/inc/classes/category-dropdown-url-walker.php';
    if (function_exists('get_field')) {
        $work_uri = get_page_uri(get_field('work_page', 'options'));
        $family_uri = get_page_uri(get_field('family_page', 'options'));
        //Works custom post type
        if ($work_uri) {
            $works = new Custom_Post_Type('Work', array('rewrite' => array('with_front' => false, 'slug' => $work_uri), 'capability_type' => 'post', 'publicly_queryable' => true, 'has_archive' => true, 'hierarchical' => true, 'menu_position' => null, 'menu_icon' => 'dashicons-admin-generic', 'supports' => array('title', 'editor', 'thumbnail'), 'plural' => "Work"));
            $works->register_taxonomy("Client", array('name' => 'client', 'rewrite' => array('slug' => 'clients')), array('plural' => "Clients"));
            $works->register_post_type();
        }
        //Family custom post type
        if ($family_uri) {
            $family = new Custom_Post_Type('Family', array('rewrite' => array('with_front' => false, 'slug' => $family_uri), 'capability_type' => 'post', 'publicly_queryable' => true, 'has_archive' => false, 'hierarchical' => true, 'menu_position' => null, 'menu_icon' => 'dashicons-admin-users', 'supports' => array('title', 'editor', 'thumbnail'), 'plural' => "Family"));
            $family->register_taxonomy("Family Category", array('name' => 'family_cat', 'rewrite' => array('slug' => 'family-category')), array('plural' => "Family Categories"));
            $family->register_post_type();
        }
        //Slides custom post type
        $slides = new Custom_Post_Type('Slides', array('rewrite' => array('with_front' => false, 'slug' => 'slides'), 'capability_type' => 'post', 'publicly_queryable' => true, 'has_archive' => true, 'hierarchical' => true, 'menu_position' => null, 'menu_icon' => 'dashicons-format-gallery', 'supports' => array('title', 'editor', 'thumbnail'), 'plural' => "Slides"));
        $slides->register_post_type();
    }
}
 public function __construct($name = null, $post_types = array(), $args = array(), $capabilities = array(), $labels = array())
 {
     $this->taxonomy_name = Custom_Post_Type::uglify($name);
     $this->taxonomy_post_types = $post_types;
     $this->taxonomy_args = $args;
     $this->taxonomy_capabilities = $capabilities;
     $this->taxonomy_labels = $labels;
     if (!taxonomy_exists($this->taxonomy_name)) {
         $name = Custom_Post_Type::beautify($name);
         $plural = Custom_Post_Type::pluralize($name);
         $labels = array_merge(array('name' => _x($plural, 'taxonomy general name'), 'singular_name' => _x($name, 'taxonomy singular name'), 'search_items' => __('Search ' . $plural), 'all_items' => __('All ' . $plural), 'parent_item' => __('Parent ' . $name), 'parent_item_colon' => __('Parent ' . $name . ':'), 'edit_item' => __('Edit ' . $name), 'update_item' => __('Update ' . $name), 'add_new_item' => __('Add New ' . $name), 'new_item_name' => __('New ' . $name . ' Name'), 'menu_name' => __($name)), $this->taxonomy_labels);
         $capabilities = $this->merge_caps($this->taxonomy_args, $this->taxonomy_capabilities);
         // Default arguments, overwritten with the given arguments
         $args = array_merge(array('label' => $plural, 'labels' => $labels, 'public' => true, 'show_ui' => true, 'show_in_nav_menus' => true, 'hierarchical' => true, '_builtin' => false, 'capabilities' => $capabilities), $this->taxonomy_args);
         // Add the taxonomy to the post types
         add_action('init', function () use($args) {
             register_taxonomy($this->taxonomy_name, $this->taxonomy_post_types, $args);
         });
     } else {
         /* The taxonomy already exists. We are going to attach the existing taxonomy to the object type (post type) */
         add_action('init', function () {
             foreach ($this->taxonomy_post_types as $type) {
                 register_taxonomy_for_object_type($this->taxonomy_name, $type);
             }
         });
     }
 }
 public static function set_up()
 {
     // static:: used to reference the called class in a context of static inheritance, as self:: will call the original method definition
     // Explanation http://stackoverflow.com/questions/151969/when-to-use-self-vs-this
     // static:: refers to class, $this refers to current object
     Custom_Post_Type::all_custom_post_types();
     static::register_taxonomies();
     flush_rewrite_rules();
 }
<?php

$metabox = new Custom_Post_Type();
$metabox->post_type_name = 'page';
$metabox->add_meta_box('Layout Options', array('Hide Page Title' => array('type' => 'checkbox', 'data' => array('checked' => 'on')), 'Related Recipe' => 'custom-post-type-select'), 'side', 'low', array('custom-post-type-select' => array('Related Recipe' => array('post_type' => 'wpmon_recipe', 'default_label' => 'Default', 'args' => array()))), '', false);
示例#5
0
<?php

/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                            CREATE $cpt_name
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
$portfolioSongs = new Custom_Post_Type($cpt_name);
$portfolioSongs->add_taxonomy($cpt_taxonomy);
// $portfolioSongs->add_meta_box($cpt_metaName, array(
// 		'Instruments used' => 'textarea',
// 		'Link to song' => 'text'
// 	)
// );
<?php

// Initialize Post Type
$my_recipe = new Custom_Post_Type('Recipe', 'wpmon', array('menu_position' => '25', 'menu_icon' => 'dashicons-images-alt', 'has_archive' => 'false', 'supports' => array('title', 'editor', 'thumbnail')), array('menu_name' => 'Recipes'), 'Recipe', true);
// Add Custom Taxonomy
$my_recipe->add_taxonomy('meal');
$my_recipe->add_taxonomy('cuisine');
// Add Metaboxes
$my_recipe->add_meta_box('Example Options', array('instructions' => 'html-block', 'Select Some Things' => 'select', 'Meal' => 'category-multi-select', 'Test Question IDs' => 'hidden', 'More Information Link' => 'content-url', 'Date' => 'date', 'Time' => 'time'), 'normal', 'default', array('select_options' => array('Select Some Things' => array('My Option 1' => 'option-1', 'My Option 2' => 'option-2', 'My Option 3' => 'option-3', 'My Option 4' => 'option-4')), 'category_multi_select' => array('Meal' => array('post_type' => 'wpmon_recipe', 'taxonomy' => 'wpmon_meals')), 'html_block' => array('instructions' => array('heading' => 'Instructions', 'html' => '[my-shortcode]'))), '', false);
function example_shortcode_function()
{
    $output = '<p>Here, you can place HTML content to give your users some good direction.</p>';
    $output .= '<p>You can even use shortcodes!!</p>';
    return $output;
}
add_shortcode('my-shortcode', 'example_shortcode_function');
示例#7
0
 /**
  * @return void
  */
 public function register_taxonomy()
 {
     register_taxonomy($this->name, $this->post_type->get_name(), $this->args);
 }