These are chat archives for WebDevStudios/CMB2

23rd
Sep 2015
Scott Kingsley Clark
@sc0ttkclark
Sep 23 2015 17:39
@ronalfy put together basic customizer integration
he did it against master, but you can easily see the changes he made and how they'll fit right into the trunk branch, even after the nesting tweaks
there's not any field type handling, just text fields for now
customizer field types will need some sort of reflective class object that would map to all the handling that CMB2 Field types do
or whatever it would be
Ronald Huereca
@ronalfy
Sep 23 2015 18:07
I just added everything to customizer branch
I'll merge master too.. sorry, fucked that up
Scott Kingsley Clark
@sc0ttkclark
Sep 23 2015 18:07
!language
:)
Ronald Huereca
@ronalfy
Sep 23 2015 18:07
oh my god.. sorry.. used to web dev peeps in the old school days
Filter is on :D
Scott Kingsley Clark
@sc0ttkclark
Sep 23 2015 18:08
!god
JK :)
Ronald Huereca
@ronalfy
Sep 23 2015 18:08
anyways, I updated my gist. I map the field types.
Scott Kingsley Clark
@sc0ttkclark
Sep 23 2015 18:08
ok cool
can you paste your gist here?
Ronald Huereca
@ronalfy
Sep 23 2015 18:08
For the rest, we'll need toextend objects
Sorry, I've never used gitter
Basically turns 500 LOC into maybe 50 or so.. plus you can use one plugin, which is CMB2.
Scott Kingsley Clark
@sc0ttkclark
Sep 23 2015 18:09
sounds great
Ronald Huereca
@ronalfy
Sep 23 2015 18:10
I've been trying to get ahold of Justin all day. I'm slightly excited.
Scott Kingsley Clark
@sc0ttkclark
Sep 23 2015 18:10
this is where you should be getting ahold of him for sure
Ronald Huereca
@ronalfy
Sep 23 2015 18:10
@jtsternberg yo!
:D
Scott Kingsley Clark
@sc0ttkclark
Sep 23 2015 18:10
he's probably busy, they just got back from their week long company retreat
so there's work to be done
Ronald Huereca
@ronalfy
Sep 23 2015 18:10
oooh
Yeah, he might have some questions on why I bootstrapped it, but if I didn't do it that way, it was loaded too late.
Scott Kingsley Clark
@sc0ttkclark
Sep 23 2015 18:11
i'd like to fast track this myself, but we'll have to figure out the other field type coverage first, and this should probably wait until we figure out repeating / group fields because that's getting some refactoring
Ronald Huereca
@ronalfy
Sep 23 2015 18:11
I honestly would just love to stick with the regular fields
I know why devs hate the customizer now. Such a pain!
@sc0ttkclark pardon my noobness, but how do you paste a snippet in here?
$field_type_mapping = array(
            'title'         => 'WP_Customize_Control',
            'text'          => 'WP_Customize_Control',
            'text_small'    => 'WP_Customize_Control',
            'text_medium'   => 'WP_Customize_Control',
            'text_email'    => 'WP_Customize_Control',
            'text_url'      => 'WP_Customize_Control',
            'text_money'    => 'WP_Customize_Control',
            'colorpicker'   => 'WP_Customize_Color_Control',
            'file'          => 'WP_Customize_Media_Control',
        );
found it
So those are the fields I mapped over.
Scott Kingsley Clark
@sc0ttkclark
Sep 23 2015 18:14
cool
what fields does that leave?
Ronald Huereca
@ronalfy
Sep 23 2015 18:14
select, checkboxes, etc.
taxonomies
we'd have to create custom WP_Customize_Control for those
no big deal, but a lot of coding
anyways, @jtsternberg and I talked about an add-on, but I do not see a way but integrating it with the base plugin


    public function __construct( $wp_customize ) {
        $this->start_customizer( $wp_customize );
    }

    public function start_customizer( $wp_customize ) {

        $customizer_objects = array();
        $customizer_boxes = CMB2_Boxes::get_all();
        foreach( $customizer_boxes as $type => $instance ) {
            $customizer_objects[] = cmb2_get_metabox( $type, 0, 'customizer' );
        }

        $field_type_mapping = array(
            'title'         => 'WP_Customize_Control',
            'text'          => 'WP_Customize_Control',
            'text_small'    => 'WP_Customize_Control',
            'text_medium'   => 'WP_Customize_Control',
            'text_email'    => 'WP_Customize_Control',
            'text_url'      => 'WP_Customize_Control',
            'text_money'    => 'WP_Customize_Control',
            'colorpicker'   => 'WP_Customize_Color_Control',
            'file'          => 'WP_Customize_Media_Control',
        );


        foreach( $customizer_objects as $index => $cmb ) {
            /* Add Address Info to Customizer */
            $customizer_id = $cmb->prop( 'id' );
            $wp_customize->add_section( 
                $customizer_id, 
                array(
                    'title'       => $cmb->prop( 'title' ),
                    'priority'    => $cmb->prop( 'priority' ),
                    'capability'  => 'edit_theme_options',
                ) 
            );
            $fields = $cmb->prop( 'fields' );
            foreach( $fields as $field_type ) {
                $type = $field_type[ 'type' ];
                $type_class = isset( $field_type_mapping[ $type ] ) ? $field_type_mapping[ $type ] : false;

                /* Street */
                $wp_customize->add_setting( $field_type[ 'id' ],
                array(
                    'type' => 'option',
                    )
                );



                $wp_customize->add_control( new $type_class( 
                $wp_customize, 
                    $field_type[ 'id' ],
                    array(
                        'label'    => $field_type[ 'name' ], 
                        'section'  => $customizer_id,
                        'settings' => $field_type[ 'id' ],
                        'priority' => 10,
                    )
                ));

            }
        }    
    }
}
This does all the magic.. grabs customizer fields and its subfields, and outputs them
Scott Kingsley Clark
@sc0ttkclark
Sep 23 2015 18:19
can you start filling out WebDevStudios/CMB2#465 with a list of checkboxes for each field type you want to cover, for documentation purposes?
just add a comment with your checkboxes
This message was deleted
- [ ] Item 1
- [x] Checked item 2
Ronald Huereca
@ronalfy
Sep 23 2015 18:20
Will do. I'd like to justin first.
Thanks Scott.
Scott Kingsley Clark
@sc0ttkclark
Sep 23 2015 18:21
if ( ! isset( $field_type_mapping[ $type ] ) ) { continue; }
$type_class = $field_type_mapping[ $type ];
sure np
Ronald Huereca
@ronalfy
Sep 23 2015 18:21
Chat later. GTG.
Scott Kingsley Clark
@sc0ttkclark
Sep 23 2015 18:22
ok cool, great work!