示例#1
0
<?php

/**
 * Add a settings page
 */
global $ultimatefields;
$fields = array();
# This will control the multilingual functionality
$fields[] = UF_Field::factory('checkbox', 'uf_multilingual', __('Multilingual Fields', 'uf'))->set_text(__('Enable', 'uf'))->set_description(__('This plugin is compatible with qTranslate, which is a WordPress multilingual plugin. If you enable the multilingual fields and you use qTranslate, we will automatically get the available languages and display two field versions for each language. Please remember that each field will have it&apos;s own setting and you will need to use it in order to make it multilingual.', 'uf'));
# Add a theme chooser field
$themes = $ultimatefields->themes->get();
if (true || $themes) {
    # Start with the default theme
    $themes = array_merge(array(array('id' => 'default', 'title' => __('Default Theme', 'uf'), 'dir' => UF_DIR . 'templates', 'url' => UF_URL . 'templates', 'image' => UF_URL . 'settings/images/screenshot.png')), $themes);
    foreach ($themes as $theme) {
        $options[$theme['id']] = $theme['title'];
    }
    # Add the field
    $fields[] = UF_Field::factory('select', 'uf_theme', __('Theme', 'uf'))->add_options($options);
}
# Create the page
$page = UF_Options::page('Settings', array('parent' => 'edit.php?post_type=ultimatefields', 'title' => __('Settings', 'uf')))->tab('general', $fields, 'dashicons dashicons-admin-generic', __('General', 'uf'));
/**
 * Allows adding of additional fields to the container for specific fields.
 * 
 * @param UF_Options $page The page which works with the options.
 * 
 * @since 2.0
 */
do_action('uf_settings', $page);
示例#2
0
/**
 * Setup an options page
 */
function uf_setup_options_page($fields, $data)
{
    # An array of settings that will be passed to the page
    $args = array();
    # Extract what we actually care about
    $meta = extract(uf_parse_args_array($data['meta'], array('page_type', 'parent_page', 'page_parent_slug', 'page_slug', 'icon', 'menu_position'), 'uf_options_'));
    # Prepare the title
    $title = UF_ML::split($data['meta']['uf_title']);
    $args['title'] = $title;
    # Prepare the description
    if ($description = UF_ML::split($data['post']->post_content)) {
        $args['description'] = $description;
    }
    # If there's a slug set, it will be used
    if ($page_slug) {
        $args['id'] = $page_slug;
    }
    if ($page_type == 'menu') {
        # Main page, it's default but might have extra options
        if ($menu_position) {
            $args['position'] = $menu_position;
        }
        # Icon
        if ($icon) {
            $args['icon'] = wp_get_attachment_url($icon);
        }
    } elseif ($page_type == 'other_page') {
        $args['parent'] = $page_parent_slug;
    } elseif ($page_type == 'other_uf_page') {
        if (isset($parent_page) && ($page = get_post($parent_page))) {
            $args['parent'] = ($custom = get_post_meta($page->ID, 'uf_options_page_slug', true)) ? $custom : sanitize_title($page->post_title);
        }
    } else {
        $args['type'] = $page_type;
    }
    $page = UF_Options::page($title, $args);
    # Add fields
    $page->add_fields_array($fields);
}