vafour / vafpress-framework

Wordpress theme options framework, check out the demo.
http://demo.vafpress.com/vafpress-framework
Other
240 stars 98 forks source link

Is there any chance to make vafpress work with customizer? #106

Open sohan5005 opened 9 years ago

sohan5005 commented 9 years ago

Hi, I wanted to know if it's already implemented or can be done anyhow. I can't find anything about customnizer in vafpress documentation.

Is there any function available to update vp_option fields from somewhere else? Then I think, we can make this work with the live customizer.

Thanks

padalec commented 9 years ago

Hi, no, I don't think to VP has this options, but this can be very useful! That is why I think to build it. Maybe someone also would like to build this function and help me on this?

sohan5005 commented 9 years ago

the project, currently i'm working on, needs this functionality. So I have a basic Idea to do this, but need help.

The idea is, there must be a function which used to update the fields in vp_option when we hit save. But I can't find it in the core files. If we execute the function in the customizer, then it probably going to work. Because, the options data must be saved in database.

padalec commented 9 years ago

vp_option is used only to get options from db. In my theme I don't use vp_option function. If You only need to update options You should use: http://codex.wordpress.org/Function_Reference/update_option Regards

sohan5005 commented 9 years ago

ok, if I want to use update_option function, then how should I call the option id or option name?

padalec commented 9 years ago

Your option key is ('option_key') the key Your passed to VP_Option() class http://vafpress.com/documentation/vafpress-framework/options/builder.html if You want to see all options just use this code below: $options = get_option('option_key'); print_r($options);

padalec commented 9 years ago

Hi, how is your customizer integration? Regards

sohan5005 commented 9 years ago

I haven't integrated any options to the customizer. I'll try that later. But there should be a solution. :(

sohan5005 commented 9 years ago

By the way, one more problem here. I'm registering the options panel in top level menu in dashboard. The position is '61' which is under appearance and above plugins. But I didn't get the submenus of my options panel as other frameworks do. Is there any option that I need to enable or I need to register the submenus manually?

padalec commented 9 years ago

Do Your looking for submenu in your options groups? If yes you should use "nested menu" http://vafpress.com/documentation/vafpress-framework/options/group.html in your option template array.

sohan5005 commented 9 years ago

No, I don't mean that. As we usually add the options in Appearance > Theme options. I've added my options panel directly in top level menus in admin panel. When you hover over to the appearance, you see submenu with themes, customize, widget, menus etc. When you hover on plugins, you see installed plugin, add new, editor. Like that, I have added my options panel in top level menu and I want to show submenu like Basic styles, fonts, blog options, sidebar options etc. I'm already using nested menu. Does VF has any option to have submenus when we register the options panel in top level? Or we have to register the submenu manually? submenu

padalec commented 9 years ago

This option isn't available in VP but you can grouping your options in nested menu.

sohan5005 commented 9 years ago

I think this option should be included as other frameworks do.

padalec commented 9 years ago

Maybe you have right by this is not user friendly because always when you go to another sub page the page is refreshed.

padalec commented 9 years ago

Look what I found for customizer http://kirki.org/ :)

sohan5005 commented 9 years ago

Looks great for the customizer.

I'm trying to achieve the submenus. If I'm done, I'll pull a request.

sohan5005 commented 9 years ago

I have used this code to register the submenus on my theme. This actually makes a little work but doesn't do a great job. When you first click on any submenu, it will link you to the actual menu but you can't change group with it. So this code needs to be furnished a little bit.

I think this can be integrated into the framework with some modifications.

// add the action on admin_menu init
add_action('admin_menu', 'register_vp_submenus');

// declare the function
function register_vp_submenus() {

    // the file which contains the array of options
    $settings = include get_template_directory() . '/admin/option.php';

    // slug of the options panel
    $option_slug = 'my_slug';

    // minimum role
    $min_role = 'edit_theme_options';

    // select the 'menu' items from array
    $do_submenus = $settings['menus'];

    // loop to check and add submenu items
    foreach ($do_submenus as $do_submenu) {

        // if nested menu, add the actual groups which contain options
        if( is_array($do_submenu['menus']) ) {
            foreach ( $do_submenu['menus'] as $group_sub ) {
                add_submenu_page( 
                        $option_slug,
                        $group_sub['title'],
                        $group_sub['title'],
                        $min_role,
                        '/admin.php?page=' . $option_slug . '#_' . $group_sub['name']
                    );
            }
        } else {
        add_submenu_page( 
                $option_slug,
                $do_submenu['title'],
                $do_submenu['title'],
                $min_role,
                '/admin.php?page=' . $option_slug . '#_' . $do_submenu['name']
            );
        }
    }

    // Add the utility menu which is not in the user created array
    add_submenu_page( 
             $option_slug,
            __( 'Utility' , 'textdomain' ),
            __( 'Utility' , 'textdomain' ),
            $min_role,
            '/admin.php?page=' . $option_slug . '#_menu_util'
        );

}