Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add custom post type to BeTheme by Muffin Group
//add this to your functions.php or include it there from another file.
function mytheme_includes() {
if (! class_exists('Mfn_Post_Type_Video')) { //change references to 'Video or video' to your post type
class Mfn_Post_Type_Video extends Mfn_Post_Type
{
/**
* Mfn_Post_Type_Video constructor
*/
public function __construct()
{
parent::__construct();
// fires after WordPress has finished loading but before any headers are sent
add_action('init', array($this, 'register'));
// admin only methods
if( is_admin() ){
$this->fields = $this->set_fields();
$this->builder = new Mfn_Builder_Admin();
}
}
/**
* Set post type fields
*/
private function set_fields(){
return array(
'id' => 'mfn-meta-video',
'title' => esc_html__('Video Options', 'mfn-opts'),
'page' => 'video',
'context' => 'normal',
'priority' => 'high',
'fields' => array(
// layout
array(
'id' => 'mfn-meta-info-layout',
'type' => 'info',
'title' => '',
'desc' => __('Layout', 'mfn-opts'),
'class' => 'mfn-info',
),
array(
'id' => 'mfn-post-hide-content',
'type' => 'switch',
'title' => __('Hide The Content', 'mfn-opts'),
'sub_desc' => __('Hide the content from the WordPress editor', 'mfn-opts'),
'desc' => __('<strong>Turn it ON if you build content using Content Builder</strong><br />Use the Content item if you want to display the Content from editor within the Content Builder', 'mfn-opts'),
'options' => array('1' => 'On', '0' => 'Off'),
'std' => '0'
),
array(
'id' => 'mfn-post-layout',
'type' => 'radio_img',
'title' => __('Layout', 'mfn-opts'),
'desc' => __('<b>Full width</b> sections works only <b>without</b> sidebars', 'mfn-opts'),
'options' => array(
'no-sidebar' => array('title' => 'Full width. No sidebar', 'img' => MFN_OPTIONS_URI.'img/1col.png'),
'left-sidebar' => array('title' => 'Left Sidebar', 'img' => MFN_OPTIONS_URI.'img/2cl.png'),
'right-sidebar' => array('title' => 'Right Sidebar', 'img' => MFN_OPTIONS_URI.'img/2cr.png'),
'both-sidebars' => array('title' => 'Both Sidebars', 'img' => MFN_OPTIONS_URI.'img/2sb.png'),
),
'std' => mfn_opts_get('sidebar-layout'),
),
array(
'id' => 'mfn-post-sidebar',
'type' => 'select',
'title' => __('Sidebar', 'mfn-opts'),
'desc' => __('Shows only if layout with sidebar is selected', 'mfn-opts'),
'options' => mfn_opts_get('sidebars'),
),
array(
'id' => 'mfn-post-sidebar2',
'type' => 'select',
'title' => __('Sidebar 2nd', 'mfn-opts'),
'desc' => __('Shows only if layout with both sidebars is selected', 'mfn-opts'),
'options' => mfn_opts_get('sidebars'),
),
array(
'id' => 'mfn-post-template',
'type' => 'select',
'title' => __('Template', 'mfn-opts'),
'options' => array(
'' => __('Default Template', 'mfn-opts'),
'builder' => __('Builder', 'mfn-opts'),
'intro' => __('Intro Header', 'mfn-opts'),
),
),
// media
array(
'id' => 'mfn-meta-info-media',
'type' => 'info',
'title' => '',
'desc' => __('Media', 'mfn-opts'),
'class' => 'mfn-info',
),
array(
'id' => 'mfn-post-slider',
'type' => 'select',
'title' => __('Slider | Revolution Slider', 'mfn-opts'),
'desc' => __('Select one from the list of available <a target="_blank" href="admin.php?page=revslider">Revolution Sliders</a>', 'mfn-opts'),
'options' => Mfn_Builder_Helper::get_sliders('rev'),
),
array(
'id' => 'mfn-post-slider-layer',
'type' => 'select',
'title' => __('Slider | Layer Slider', 'mfn-opts'),
'desc' => __('Select one from the list of available <a target="_blank" href="admin.php?page=layerslider">Layer Sliders</a>', 'mfn-opts'),
'options' => Mfn_Builder_Helper::get_sliders('layer'),
),
array(
'id' => 'mfn-post-video',
'type' => 'text',
'title' => __('Video | ID', 'mfn-opts'),
'sub_desc' => __('YouTube or Vimeo', 'mfn-opts'),
'desc' => __('It`s placed in every YouTube & Vimeo video, for example:<br /><b>YouTube:</b> http://www.youtube.com/watch?v=<u>WoJhnRczeNg</u><br /><b>Vimeo:</b> http://vimeo.com/<u>62954028</u>', 'mfn-opts'),
'class' => 'small-text mfn-post-format video'
),
array(
'id' => 'mfn-post-video-mp4',
'type' => 'upload',
'title' => __('Video | HTML5', 'mfn-opts'),
'sub_desc' => __('m4v [.mp4]', 'mfn-opts'),
'desc' => __('<strong>Notice:</strong> HTML5 video works only in modern browsers', 'mfn-opts'),
'class' => __('video', 'mfn-opts'),
),
array(
'id' => 'mfn-post-header-bg',
'type' => 'upload',
'title' => __('Header Image', 'mfn-opts'),
),
array(
'id' => 'mfn-post-subheader-image',
'type' => 'upload',
'title' => __('Subheader | Image', 'mfn-opts'),
),
// options
array(
'id' => 'mfn-meta-info-options',
'type' => 'info',
'title' => '',
'desc' => __('Options', 'mfn-opts'),
'class' => 'mfn-info',
),
array(
'id' => 'mfn-post-hide-title',
'type' => 'switch',
'title' => __('Subheader | Hide', 'mfn-opts'),
'options' => array('1' => 'On', '0' => 'Off'),
'std' => '0'
),
array(
'id' => 'mfn-post-remove-padding',
'type' => 'switch',
'title' => __('Content | Remove Padding', 'mfn-opts'),
'desc' => __('Remove default Content Padding', 'mfn-opts'),
'options' => array('1' => 'On','0' => 'Off'),
'std' => '0'
),
array(
'id' => 'mfn-post-hide-image',
'type' => 'switch',
'title' => __('Featured Image | Hide', 'mfn-opts'),
'desc' => __('Hide Featured Image in post details', 'mfn-opts'),
'options' => array( '0' => 'Off', '1' => 'On' ),
),
// advanced
array(
'id' => 'mfn-meta-info-advanced',
'type' => 'info',
'title' => '',
'desc' => __('Advanced', 'mfn-opts'),
'class' => 'mfn-info',
),
array(
'id' => 'mfn-post-link',
'type' => 'text',
'title' => __('External Link', 'mfn-opts'),
'desc' => __('for <b>Post Format: Link</b>', 'mfn-opts'),
),
array(
'id' => 'mfn-post-bg',
'type' => 'color',
'title' => __('Background Color', 'mfn-opts'),
'desc' => __('for <b>Blog Layout: Masonry Tiles</b> & <b>Template: Intro</b>', 'mfn-opts'),
),
array(
'id' => 'mfn-post-intro',
'type' => 'checkbox',
'title' => __('Intro | Options', 'mfn-opts'),
'desc' => __('for <b>Template: Intro</b>', 'mfn-opts'),
'options' => array(
'light' => __('Light | light image, dark text', 'mfn-opts'),
'full-screen' => __('Full Screen', 'mfn-opts'),
'parallax' => __('Parallax', 'mfn-opts'),
'cover' => __('Background size: Cover<span>enabled by default in parallax</span>', 'mfn-opts'),
),
),
// seo
array(
'id' => 'mfn-meta-info-seo',
'type' => 'info',
'title' => '',
'desc' => __('SEO <span>below settings overwrite theme options</span>', 'mfn-opts'),
'class' => 'mfn-info',
),
array(
'id' => 'mfn-meta-seo-title',
'type' => 'text',
'title' => __('SEO | Title', 'mfn-opts'),
),
array(
'id' => 'mfn-meta-seo-description',
'type' => 'text',
'title' => __('SEO | Description', 'mfn-opts'),
),
array(
'id' => 'mfn-meta-seo-keywords',
'type' => 'text',
'title' => __('SEO | Keywords', 'mfn-opts'),
),
array(
'id' => 'mfn-meta-seo-og-image',
'type' => 'upload',
'title' => __('Open Graph | Image', 'mfn-opts'),
'sub_desc' => __('e.g. Facebook share image', 'mfn-opts'),
),
),
);
}
public function register()
{
$labels = array(
'name' => esc_html__('Videos', 'mfn-opts'),
'singular_name' => esc_html__('Video', 'mfn-opts'),
'add_new' => esc_html__('Add New', 'mfn-opts'),
'add_new_item' => esc_html__('Add New Video', 'mfn-opts'),
'edit_item' => esc_html__('Edit Video', 'mfn-opts'),
'new_item' => esc_html__('New Video', 'mfn-opts'),
'view_item' => esc_html__('View Videos', 'mfn-opts'),
'search_items' => esc_html__('Search Videos', 'mfn-opts'),
'not_found' => esc_html__('No videos found', 'mfn-opts'),
'not_found_in_trash' => esc_html__('No videos found in Trash', 'mfn-opts'),
);
$args = array(
'labels' => $labels,
'menu_icon' => 'dashicons-format-video',
'public' => true,
'show_ui' => true,
'supports' => array('title', 'editor', 'page-attributes', 'thumbnail', 'excerpt'),
'capability_type' => 'post',
);
register_post_type('video', $args);
register_taxonomy('video-types', 'video', array(
'label' => esc_html__('Video categories', 'mfn-opts'),
'hierarchical' => true,
));
}
}
}
new Mfn_Post_Type_Video();
}
add_action( 'after_setup_theme', 'mytheme_includes' );
@RichardNesbitt
Copy link
Author

RichardNesbitt commented Mar 27, 2020

This probably contains errors and could be trimmed down quite a bit, but COVID-19 has got me scrambling to get work out the door as fast as possible right now. Feel free to suggest edits, I'll include them when I can.

@RichardNesbitt
Copy link
Author

RichardNesbitt commented Mar 27, 2020

I've already noticed that some muffin options settings don't work on the front-end. I ended up modding a single-video.php template file to hide the featured image from showing at the top of the post.

@ptohy
Copy link

ptohy commented Apr 30, 2021

Hello, have you figured out how to do so that the options work on the front end? Here i have the same problem...

@Mike3285
Copy link

Mike3285 commented May 5, 2021

Hello. I am using BeThem with Muffin Builder and Custom Post Types UI. Is this working to show my custom posts?
Another option could be to let the user choose the post source when adding a portfolio grid / news / etc. item

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment