コード例 #1
0
ファイル: ultimate-fields.php プロジェクト: shesser/selenenw
/**
 * Includes core files and adds the init action.
 * 
 * This function is executed on after_setup_theme, so you can add all the hooks you need
 * in functions.php, which is included before the after_setup_theme action is performed.
 */
function uf_load()
{
    global $ultimatefields;
    # Register plugin textdomain
    $mofile = UF_DIR . "/languages/uf-" . get_locale() . ".mo";
    if (file_exists($mofile)) {
        load_textdomain('uf', $mofile);
    }
    # Most classes will somehow be saved to $ultimatefields
    $ultimatefields = new stdClass();
    # Common functionality that's used accross the framework
    include_once 'common/common.php';
    # Include classes and functions
    include_once 'includes.php';
    # Register additional fields, templates, etc.
    do_action('uf_extend');
    # Buffer certain exceptions, which are not fatal.
    UF_Exceptions::buffer('non_existing_field');
    # Add UF options pages which provide admin interface for fields
    include_once 'settings/settings.php';
    # Indicate that the plugin is present so themes could check it.
    define('UF', true);
    # Fields are set up on init, but only in the admin, with priority 12
    add_action('init', 'uf_init', 12);
}
コード例 #2
0
 /**
  * Prepares type and item_id based on a single string
  * 
  * @param string|int The type
  * @return stdClass An object containing the type and item ID
  */
 public function prepare_type($type = null)
 {
     $item_id = 0;
     if ($type) {
         # There is something passed, process it
         if (preg_match('~^\\d+$~', $type)) {
             # It's just a number
             $item_id = intval($type);
             $type = 'meta';
         } elseif (preg_match('~^([A-Z_-]+)_(\\d+)$~i', $type, $matches)) {
             # There is type + ID
             $type = $matches[1];
             $item_id = $matches[2];
             if (!isset($this->datastores[$matches[1]])) {
                 UF_Exceptions::add(__('Invalid type argument provided to get_uf!', 'uf'));
             }
         } elseif (!isset($this->datastores[$type])) {
             UF_Exceptions::add(__('Invalid type argument provided to get_uf!', 'uf'));
         }
     } else {
         $type = 'meta';
         $item_id = get_the_ID();
     }
     $data = new stdClass();
     $data->type = $type;
     $data->id = $item_id;
     return $data;
 }
コード例 #3
0
ファイル: setup-containers.php プロジェクト: shesser/selenenw
/**
 * Get an array of all registered containers
 */
function uf_setup_containers($data = null)
{
    static $added_containers;
    if (!isset($added_containers)) {
        $added_containers = array();
    }
    $containers = $data ? array($data) : get_option('uf_containers');
    $containers = apply_filters('uf_containers', $containers);
    if (!$containers || !is_array($containers)) {
        return;
    }
    # Prevent duplicate ID exits.
    UF_Exceptions::buffer('unavailable_field_key');
    UF_Exceptions::buffer('unavailable_container_key');
    foreach ($containers as $container) {
        extract($container);
        if (isset($added_containers[$meta['uf_title']])) {
            continue;
        }
        switch ($meta['uf_type']) {
            case 'options':
                uf_setup_options_page(uf_setup_fields($meta['fields'], 'UF_Datastore_Options'), $container);
                break;
            case 'post-meta':
                uf_setup_postmeta_box(uf_setup_fields($meta['fields'], 'UF_Datastore_Postmeta'), $container);
                break;
        }
        # Add underscores to the type
        $type = str_replace('-', '_', $meta['uf_type']);
        do_action("uf_setup_" . $type, $container);
        $added_containers[$meta['uf_title']] = 1;
    }
}
コード例 #4
0
 /**
  * Check if a field with the same key has been registered
  *
  * @param string $key The key of the field
  */
 function check_field_id($key)
 {
     if (isset(UF_Datastore_Options::$field_keys[$key])) {
         UF_Exceptions::add(sprintf(__('Error: Trying to register an option field with the %s key twice!', 'uf'), $key), 'unavailable_field_key');
         return false;
     } else {
         UF_Datastore_Options::$field_keys[$key] = 1;
         return true;
     }
 }
コード例 #5
0
ファイル: UF_Field.php プロジェクト: shesser/selenenw
 /**
  * Creates a specific field and returns it
  * 
  * @param string $type The type of the field, like text or google_font
  * @param string $id The ID of the field. Containers of single types cannot have identical field IDs
  * @param string $title The title that's to be assigned to the field. If skipped, it's generated from the id
  * 
  * @return UF_Field the newly created field, ready for chaining
  */
 public static function factory($type, $id, $title = '')
 {
     $class_name = self::get_class($type);
     if (!class_exists($class_name) || !is_subclass_of($class_name, 'UF_Field')) {
         $message = __('<strong>Ultimate Fields:</strong> A "%s" field class does not exist. The reason for this could be a missing or deactivated plugin. If you can&apos;t solve the issue, you might want to contact the author of the last theme or plugin that you either activated or updated.', 'uf');
         $message = sprintf($message, ucwords(str_replace('_', ' ', $type)));
         UF_Exceptions::add($message, 'non_existing_field');
         return null;
     }
     return new $class_name($id, $title);
 }