ThemeFuse / Unyson

A WordPress framework that facilitates the development of WP themes
http://unyson.io
921 stars 216 forks source link

Option type issues #1228

Closed alfgago closed 8 years ago

alfgago commented 8 years ago

Hi, I'm making my first theme with Unyson and I must say I'm loving it so far. Just having a few issues when creating custom metabox. and I have a few questions.

So, what I want is to have a different metabox depending on the post format (video, audo, image, etc).

  1. There goes my first question, is there any way to filter the boxes by post format instead of just post type? Or any workaround you can think of?

For the video metabox, so far I have this in post.php:

<?php if ( ! defined ( 'FW' )){
    die ('Forbidden');
}

$options = array(
    'box_id' => array(
        'type' => 'box',
        'title' => __('Video Format Options', 'elias'),
        'attr' => array('class' => 'custom-class', 'data-foo' => 'bar'),
        'options' => array(
            'post_video_embed'  => array(
                'type'  => 'oembed',
                'value' => 'https://vimeo.com/113078377',
                'label' => __('YouTube / Vimeo URL', 'elias'),
                'preview' => array(
                    'width'  => 300, // optional, if you want to set the fixed width to iframe
                    'height' => 300, // optional, if you want to set the fixed height to iframe
                    /**
                     * if is set to false it will force to fit the dimensions,
                     * because some widgets return iframe with aspect ratio and ignore applied dimensions
                     */
                    'keep_ratio' => true
                ),
            ),
            'post_video_webm'  => array(
                'type'  => 'upload',
                'value' => array(),
                'attr'  => array( 'class' => 'custom-class', 'data-foo' => 'bar' ),
                'label' => __('WEBM Video', 'elias'),
                'images_only' => false,
                'attr' => array('class' => 'post-format-video webm'),
                'files_ext' => array( 'webm' ),
            ),//END WEBM VIDEO
            'post_video_ogv'  => array(
                'type'  => 'upload',
                'value' => array(),
                'attr'  => array( 'class' => 'custom-class', 'data-foo' => 'bar' ),
                'label' => __('OGV Video', 'elias'),
                'images_only' => false,
                'attr' => array('class' => 'post-format-video webm'),
                'files_ext' => array( 'ogv' ),
            ),//END OGV VIDEO
            'post_video_mp4'  => array(
                'type'  => 'upload',
                'value' => array(),
                'attr'  => array( 'class' => 'custom-class', 'data-foo' => 'bar' ),
                'label' => __('MP4 Video', 'elias'),
                'images_only' => false,
                'attr' => array('class' => 'post-format-video webm'),
                'files_ext' => array( 'mp4' ),
            ),//END MP4 VIDEO
        ),
        //END OPTIONS
    ),
);

But there's 2 problems with that, and those are my second and third issues:

2) oembed type is not working, it just shows /* UNDEFINED OPTION TYPE */ in the post metabox

3) 'attr' => array( 'class' => 'custom-class', 'data-foo' => 'bar' ), is not doing anything, the class does not appear to be there.

Thank you.

alfgago commented 8 years ago

2 fixed, oembed was not working because I didn't have latest version. Didn't know it was just recently added, that's great.

ghost commented 8 years ago

1) Nope. Similar questions (same answer) https://github.com/ThemeFuse/Unyson/issues/721 https://github.com/ThemeFuse/Unyson/issues/827 2) oembed was added in v2.4.17 https://github.com/ThemeFuse/Unyson-Extensions-Approval/issues/171 3) See the second restriction http://manual.unyson.io/en/latest/options/introduction.html#restrictions

ghost commented 8 years ago

Sorry for late reply.

Have a nice day!

alfgago commented 8 years ago

I found a "solution" for this, it's working great for me if anyone is needing this like I did. Just add the metaboxes in page.php like you would normally do and then in functions.php you can remove those you don't need depending on the page template.

I have something like this for my specific needs, here I remove "one_page_box" option from the options when the template is not selected, and remove others when it is selected:

function elias_remove_meta_fp(){
    $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
    $template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
    // check for a template type
    if ($template_file == 'one-page.php') {
        remove_meta_box( 'eg-meta-box' , 'page', 'normal' );
        remove_meta_box( 'fw-options-box-page-builder-box' , 'page', 'normal' );
        remove_meta_box( 'mymetabox_revslider_0','page','normal' );
        remove_meta_box( 'aFhfcMetaBox','page','normal' );  
        remove_post_type_support( 'page', 'editor' );
    }else{
        remove_meta_box( 'fw-options-box-one_page_box' , 'page', 'normal' );
    }
}
add_action( 'do_meta_boxes', 'elias_remove_meta_fp' );

Hope this helps someone