/**
 * For each field, checks to see if it has a custom style callback.
 * If callback exists, runs it to generate the style and adds that 
 * style to the master array of styles.  Then saves all styles back
 * to the DB in an array format 
 * ($menu_id => $selector => $property => $value )
 * 
 * @param  string  $menu_id The ID of the menu instance to save
 * @param  boolean $fields  An optional set of fields to use.  
 *                          Uses all registered settings by default
 */
function ubermenu_save_menu_styles($menu_id, $fields = false)
{
    $menu_key = UBERMENU_PREFIX . $menu_id;
    if (!$fields) {
        $all_fields = ubermenu_get_settings_fields();
        $fields = $all_fields[$menu_key];
    }
    $menu_styles = array();
    /*
    if( !isset( $menu_styles[$menu_id] ) ){
    	$menu_styles[$menu_id] = array();
    }
    */
    foreach ($fields as $field) {
        if (isset($field['custom_style'])) {
            $callback = 'ubermenu_get_menu_style_' . $field['custom_style'];
            if (function_exists($callback)) {
                $callback($field, $menu_id, $menu_styles);
            }
        }
    }
    //up( $menu_styles );
    $all_styles = get_option(UBERMENU_MENU_STYLES, array());
    $all_styles[$menu_id] = $menu_styles;
    //up( $all_styles );
    update_option(UBERMENU_MENU_STYLES, $all_styles);
}
/**
 * Registers settings section and fields
 */
function ubermenu_admin_init()
{
    $prefix = UBERMENU_PREFIX;
    $sections = ubermenu_get_settings_sections();
    $fields = ubermenu_get_settings_fields();
    //set up defaults so they are accessible
    _UBERMENU()->set_defaults();
    $settings_api = _UBERMENU()->settings_api();
    //set sections and fields
    $settings_api->set_sections($sections);
    $settings_api->set_fields($fields);
    //initialize them
    $settings_api->admin_init();
}
Example #3
0
function ubermenu_generate_menu_preview_styles($config_id, $fields = false)
{
    $menu_key = UBERMENU_PREFIX . $config_id;
    if (!$fields) {
        $all_fields = ubermenu_get_settings_fields();
        $fields = $all_fields[$menu_key];
    }
    $menu_styles = array();
    /*
    if( !isset( $menu_styles[$config_id] ) ){
    	$menu_styles[$config_id] = array();
    }
    */
    foreach ($fields as $field) {
        if (isset($field['custom_style'])) {
            $callback = 'ubermenu_get_menu_style_' . $field['custom_style'];
            if (function_exists($callback)) {
                $callback($field, $config_id, $menu_styles);
            }
        }
    }
    return $menu_styles;
}