Skip to content

Instantly share code, notes, and snippets.

@RichardNesbitt
Last active February 13, 2024 22:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardNesbitt/cef7bd43e9429783beccae4c64d9a12d to your computer and use it in GitHub Desktop.
Save RichardNesbitt/cef7bd43e9429783beccae4c64d9a12d to your computer and use it in GitHub Desktop.
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

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

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

@jicao
Copy link

jicao commented Aug 25, 2023

Hello

I was trying to do the same thing and you helped me with add_action( 'after_setup_theme', 'mytheme_includes' );

For those using ACF Pro I made an "option page" under Betheme to select post types where you want to activate BeBuilder

/* Add BeBuilder custom post_type */
function load_cpt_builder() {
	if(!class_exists('Mfn_Post_Type_Custom')) {
		class Mfn_Post_Type_Custom extends Mfn_Post_Type
		{
			/**
			 * Mfn_Post_Type_Custom constructor
			 */
			public function __construct($post_type)
			{
				parent::__construct();
				if(is_admin()) {
					$this->fields = array(
						'id' => 'mfn-meta-'.$post_type,
						'title' => 'Builder',
						'page' => $post_type,
						'context' => 'normal',
						'priority' => 'high',
						'fields' => array(),
					);
					$this->builder = new Mfn_Builder_Admin();
				}
			}
		}
	}

	$cptx = get_option('options_bbcpt');
	if(!empty($cptx) && is_array($cptx)) {
		foreach($cptx as $cpt) {
			new Mfn_Post_Type_Custom($cpt);
		}
	}

	function custom_acf_cpt_choices($field) {
		$post_types = get_post_types(['public' => true,], 'objects');
		$post_type_list = array();
		foreach($post_types as $post_type) {
			if(!in_array($post_type->name, ['post', 'page', 'attachment', 'template', 'client', 'layout', 'offer', 'portfolio', 'slide', 'testimonial'])) {
				$post_type_list[$post_type->name] = $post_type->label;
			}
		}
		$field['choices'] = $post_type_list;
		return $field;
	}
	add_filter('acf/load_field/name=bbcpt', 'custom_acf_cpt_choices');

	add_action('acf/include_fields', function() {
		if(!function_exists('acf_add_local_field_group')) {
			return;
		}

		acf_add_local_field_group(array(
			'key'    => 'group_64e880538ce9f',
			'title'  => 'Options',
			'fields' => array(
				array(
					'key'               => 'field_64e87bcfab8cd',
					'label'             => 'Post types',
					'name'              => 'bbcpt',
					'aria-label'        => '',
					'type'              => 'select',
					'instructions'      => '',
					'required'          => 0,
					'conditional_logic' => 0,
					'wrapper'           => array(
						'width' => '',
						'class' => '',
						'id'    => '',
					),
					'choices'           => array(
						'documents' => 'Documents',
					),
					'default_value'     => array(),
					'return_format'     => 'value',
					'multiple'          => 1,
					'allow_null'        => 0,
					'ui'                => 0,
					'ajax'              => 0,
					'placeholder'       => '',
				),
			),
			'location' => array(
				array(
					array(
						'param'    => 'options_page',
						'operator' => '==',
						'value'    => 'builder_post_type',
					),
				),
			),
			'menu_order'            => 0,
			'position'              => 'normal',
			'style'                 => 'default',
			'label_placement'       => 'top',
			'instruction_placement' => 'label',
			'hide_on_screen'        => '',
			'active'                => true,
			'description'           => '',
			'show_in_rest'          => 0,
		));
	});

	add_action('acf/init', function() {
		acf_add_options_page(array(
			'page_title'  => 'Builder post_type',
			'menu_slug'   => 'builder_post_type',
			'parent_slug' => 'betheme',
			'redirect'    => false,
		));
	});

}
add_action('after_setup_theme', 'load_cpt_builder');
/* Add BeBuilder custom post_type */

Let me know if you have some ideas

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