Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Inline options group option type suggestion

Open danyj opened this issue 11 years ago • 18 comments

This one is for other Unyson users , I already made my own but this can come in handy to others. I got bit tired of adding easy to understand options under each other and not using the space so I combined my spinner, short-text and short-select in to one option

the outcome screenshot_1

array output

screenshot_2

option array

'group_of_options' => array(
    'type' => 'thz-multi-options',
    'label' => __('Option group', 'fw'),
    'desc' => __('This is the space between the element and the surrounding elements.', 'fw'),

    'value' => array(
        'type_spinner' =>20,
        'type_text' =>'I am a text',
        'type_select' =>'select3'
    ),

    'thz_options' => array(
        'type_spinner' => array(
            'type' =>'spinner',
            'title' => __('Spinn me', 'fw'),
            'addon' => 'px',
            'min' => 0,
            'max' => 100
        ),
        'type_text' => array(
            'type' =>'text',
            'title' => __('Some text', 'fw'),

        ),
        'type_select' => array(
            'type' =>'select',
            'title' => 'Select something',
            'choices' => array(
                'select1' => __('select1', 'fw'),
                'select2' => __('select2', 'fw'),
                'select3' => __('select3', 'fw')
            ),
        )
    )
),

thnx to @moldcraft for help and this suggestion https://github.com/ThemeFuse/Unyson/issues/1061

note that I have my own spinner which is not included in Unyson but you get the idea why something like this can be useful.

Here is dummy scenario for slider setup

screenshot_3

danyj avatar Dec 02 '15 08:12 danyj

here I just combined

spinner text short-text select short-select color picker

screenshot_5

output

screenshot_6

danyj avatar Dec 02 '15 08:12 danyj

In the Unyson already exists this prototype , the multi option-type the main difference is in design , the @danyj s option type show the options horizontal the multi option type show it as simple option types but in the database is grouped in one key.

llemurya avatar Dec 02 '15 09:12 llemurya

@llemurya I know , saw it already , you might want to add inline option in there than if you decide. As you can see this is compact for fast options that need no explaining. Here is my usage example http://prntscr.com/99ei20 all of those are easy to understand and if not I can add help in there.

danyj avatar Dec 02 '15 09:12 danyj

Check this out , http://prntscr.com/99eir8

now if I were to add those under each other my modal would already be full.

danyj avatar Dec 02 '15 09:12 danyj

Hi danyj,

Can you share your thz-multi-options? Can we add this to core? I agree that's it's crucial to have mutli-inline options.

NwpDeveloper avatar Jan 22 '16 10:01 NwpDeveloper

Love this way. Share with us buddy :)

Ataurr avatar Jan 22 '16 10:01 Ataurr

making one for u , few min

danyj avatar Jan 22 '16 12:01 danyj

OK , see if you can get this https://www.dropbox.com/s/sr90buxpdzu6tu0/fw-multi-inline.zip?dl=0

extract and drop the folder in

yourtheme/inc/includes/option-types/

open file

option-types.php  

and include the class ,

my option-types.php is in

 mytheme/inc/includes/

so my include path is

    require_once dirname(__FILE__) . '/option-types/fw-multi-inline/class-fw-option-type-fw-multi-inline.php';

the option is now called

fw-multi-inline

and this is how it is used

'multiinlintest' => array(
    'type' => 'fw-multi-inline',
    'label' => __('Option group', 'fw'),
    'desc' => __('This is the space between the element and the surrounding elements.', 'creatus'),

    'value' => array(
        'type_text' =>'I am longer than the other',
        'type_short_text' =>'I am short',
        'type_short_select' =>'select3',
        'type_select' =>'select2',
        'type_color' =>'#ff6600',
        'type_rgbacolor' =>'#ff0000'
    ),

    'fw_multi_options' => array(
        'type_short_text' => array(
            'type' =>'short-text',
            'title' => __('Short text', 'fw'),

        ),
        'type_text' => array(
            'type' =>'text',
            'title' => __('Longer text', 'fw'),

        ),
        'type_short_select' => array(
            'type' =>'short-select',
            'title' => 'Select something',
            'choices' => array(
                'select1' => __('select1', 'fw'),
                'select2' => __('select2', 'fw'),
                'select3' => __('select3', 'fw')
            ),
        ),

        'type_select' => array(
            'type' =>'select',
            'title' => 'Select something longer',
            'choices' => array(
                'select1' => __('Select something larger', 'fw'),
                'select2' => __('Select something larger 2', 'fw'),
                'select3' => __('Select something larger 3', 'fw')
            ),
        ),
        'type_color' => array(
            'type' =>'color',
            'title' => __('I am a color', 'fw'),

        ),  

        'type_rgbacolor' => array(
            'type' =>'rgbacolor',
            'title' => __('I am a rgba color', 'fw'),

        ),      

    )
),

This is backend

screenshot_12

And this is option print

w8edan4

you can add these options

text
short-text
select
short-select
color
rgbacolor

here is short example

'multiinlintest' => array(
    'type' => 'fw-multi-inline',
    'label' => __('Option group', 'fw'),
    'desc' => __('This is the space between the element and the surrounding elements.', 'creatus'),

    'value' => array(
        'type_short_text' =>'I am short',

    ),

    'fw_multi_options' => array(
        'type_short_text' => array(
            'type' =>'short-text',
            'title' => __('Short text', 'fw'),

        ),
    )
),

Have fun!

danyj avatar Jan 22 '16 12:01 danyj

Note that I dont like hiding errors so I purposely let the option error out if your option index is missing. This way it keeps me in check. So if you see a notice like this

screenshot_14

you should check the name of your value key

screenshot_15

danyj avatar Jan 22 '16 12:01 danyj

You have built some awesome option types. ;) if possible please share #911 this one to :)

Thanks very much mate.

Ataurr avatar Jan 22 '16 15:01 Ataurr

glad you like it , here is the icon option https://github.com/ThemeFuse/Unyson/issues/911#issuecomment-173953084

danyj avatar Jan 22 '16 15:01 danyj

Ahh got it :beers:

Ataurr avatar Jan 22 '16 15:01 Ataurr

Thanks for putting that up!

How do you get the popup button working with this multi-inline option? I'm getting Error: wrong option when I hit the button. It doesn't look like data-for-js get's the data.

NwpDeveloper avatar Jan 27 '16 21:01 NwpDeveloper

Got the popup working. When passing the sub option to render for html: html .= fw()->backend->option_type( $type )->render($id, $option, $data)

You need to pass the nested option for popup: $option['fw_multi_options'][$key] OR you can explicitly pieces of the sub option array.

NwpDeveloper avatar Jan 28 '16 20:01 NwpDeveloper

as advised in description , I made this work only for these

text short-text select short-select color rgbacolor

what you do with it is up to you

danyj avatar Jan 28 '16 21:01 danyj

Thanks danyj. How do you access the $atts value of a nested popup option?

For example, I have: 'foo' => array( 'type' => 'fw-multi-inline'... 'value'=> ... 'fw_multi_options' =>.... 'bar' => 'type' => 'popup',

If I dump $atts['foo'] I only get the default values in the value array for bar. I can't access bar directly.

NwpDeveloper avatar Jan 29 '16 10:01 NwpDeveloper

Wow dude! Thank you so much!

I got a class error when I included the files. So I just hook them up.

function _action_theme_include_custom_option_types() { require_once dirname(__FILE__) . '/includes/option-types/fw-multi-inline/class-fw-option-type-fw-multi-inline.php'; } add_action('fw_option_types_init', '_action_theme_include_custom_option_types');

Cheers!

jonmlas avatar Mar 18 '17 04:03 jonmlas

Something like this in the Unyson core would be awesome. The Theme Options pages can get quite lengthy since all options are positioned vertically by default.

Thanks for sharing @danyj!!

warudin avatar Apr 26 '17 13:04 warudin