예제 #1
0
function hocwp_slider_meta_box_field($post_type, $post)
{
    if (!hocwp_is_post($post)) {
        return;
    }
    if ('hocwp_slider' == $post_type) {
        $post_id = $post->ID;
        $meta = new HOCWP_Meta('post');
        $meta->add_post_type('hocwp_slider');
        $meta->set_id('hocwp_slider_information');
        $meta->set_title(__('Slider Information', 'hocwp-theme'));
        $meta->is_on_sidebar(true);
        $all_options = '<option value="">-- ' . __('Choose position', 'hocwp-theme') . ' --</option>';
        $slider_items = hocwp_get_slider_positions();
        $position = hocwp_get_post_meta('position', $post->ID);
        foreach ($slider_items as $slider) {
            $args = array('value' => $slider['id'], 'text' => $slider['name'], 'selected' => $position);
            $all_options .= hocwp_field_get_option($args);
        }
        $args = array('id' => 'position', 'label' => __('Position:', 'hocwp-theme'), 'description' => __('Choose position where you want the slider to be displayed.', 'hocwp-theme'), 'field_class' => 'display-block', 'all_option' => $all_options, 'container_class' => 'margin-bottom-10', 'field_callback' => 'hocwp_field_select');
        $meta->add_field($args);
        $meta->add_field(array('id' => 'active', 'label' => __('Make slider active?', 'hocwp-theme'), 'field_callback' => 'hocwp_field_checkbox'));
        $meta->init();
        $meta = new HOCWP_Meta('post');
        $meta->add_post_type('hocwp_slider');
        $meta->set_title(__('Advanced Settings', 'hocwp-theme'));
        $meta->set_id('hocwp_slider_advanced_settings');
        $meta->is_on_sidebar(true);
        $meta->add_field(array('id' => 'height', 'label' => __('Height:', 'hocwp-theme'), 'field_callback' => 'hocwp_field_input_number', 'default' => 350));
        $meta->add_field(array('id' => 'fit_width', 'label' => __('Stretch slider to fit site width.', 'hocwp-theme'), 'field_callback' => 'hocwp_field_checkbox', 'default' => 1));
        $meta->init();
        $meta = new HOCWP_Meta('post');
        $meta->set_id('hocwp_slider_item_information');
        $meta->set_title(__('Slider Items', 'hocwp-theme'));
        $meta->add_post_type('hocwp_slider');
        $meta->set_use_media_upload(true);
        $meta->register_field('slider_items');
        $value = hocwp_get_slider_items($post_id, true);
        $list_items = $value['items'];
        $item_order = $value['order'];
        if (!is_array($item_order)) {
            $item_order = array();
        }
        $max_item_id = absint(hocwp_get_max_number($item_order));
        $field_html = '';
        foreach ($item_order as $key => $item_id) {
            $item = isset($list_items[$item_id]) ? $list_items[$item_id] : array();
            if (!hocwp_array_has_value($item)) {
                unset($item_order[$key]);
                continue;
            }
            $title = isset($item['title']) ? $item['title'] : '';
            $link = isset($item['link']) ? $item['link'] : '';
            $description = isset($item['description']) ? $item['description'] : '';
            $image_url = isset($item['image_url']) ? $item['image_url'] : '';
            $image_id = isset($item['image_id']) ? $item['image_id'] : 0;
            if ($image_id > 0) {
                $media_url = hocwp_get_media_image_url($image_id);
                if (!empty($media_url)) {
                    $image_url = $media_url;
                }
            }
            if (empty($image_url)) {
                continue;
            }
            ob_start();
            ?>
			<li data-item="<?php 
            echo $item_id;
            ?>
">
				<img class="item-image" src="<?php 
            echo $image_url;
            ?>
">

				<div class="item-info">
					<input type="text" name="slider_items[items][<?php 
            echo $item_id;
            ?>
][title]" class="item-title"
					       value="<?php 
            echo $title;
            ?>
" placeholder="<?php 
            _e('Title', 'hocwp-theme');
            ?>
">
					<input type="url" name="slider_items[items][<?php 
            echo $item_id;
            ?>
][link]" class="item-link"
					       value="<?php 
            echo $link;
            ?>
"
					       placeholder="<?php 
            _e('Link for this item', 'hocwp-theme');
            ?>
">
						<textarea name="slider_items[items][<?php 
            echo $item_id;
            ?>
][description]"
						          class="item-description"><?php 
            echo $description;
            ?>
</textarea>
				</div>
				<div class="clear"></div>
				<div class="advance">
					<div class="dashicons dashicons-editor-expand"></div>
					<div class="box-content">
						<div class="settings">
							<div class="col-left col50 hocwp-col">
								<?php 
            $field_args = array('name' => 'slider_items[items][' . $item_id . '][background_color]', 'label' => __('Background Color', 'hocwp-theme'), 'value' => hocwp_get_value_by_key($item, 'background_color'));
            hocwp_field_color_picker($field_args);
            ?>
							</div>
							<div class="col-right col50 hocwp-col">

							</div>
						</div>
					</div>
				</div>
				<input type="hidden" class="item-image-url" value="<?php 
            echo $image_url;
            ?>
"
				       name="slider_items[items][<?php 
            echo $item_id;
            ?>
][image_url]">
				<input type="hidden" class="item-image-id" value="<?php 
            echo $image_id;
            ?>
"
				       name="slider_items[items][<?php 
            echo $item_id;
            ?>
][image_id]">
				<span title="<?php 
            _e('Delete this item', 'hocwp-theme');
            ?>
"
				      class="item-icon icon-delete icon-sortable-ui"></span>
				<span title="<?php 
            _e('Re-order this item', 'hocwp-theme');
            ?>
"
				      class="item-icon icon-drag icon-sortable-ui"></span>
				<span title="<?php 
            _e('Add child item', 'hocwp-theme');
            ?>
"
				      class="item-icon icon-add icon-sortable-ui"></span>
			</li>
			<?php 
            $field_html .= ob_get_clean();
        }
        $meta->add_field(array('id' => 'list_slider_items', 'class' => 'list-slider-items ui-sortable sortable hocwp-sortable', 'tag' => 'ul', 'field_callback' => 'hocwp_field_html_tag', 'attributes' => array('data-max-id' => $max_item_id, 'data-items' => count($item_order), 'data-post' => $post->ID, 'data-disable-selection' => 0), 'html' => $field_html, 'after_html' => '<input type="hidden" name="slider_items[order]" value="' . implode(',', $item_order) . '" class="item-order" autocomplete="off">'));
        $meta->add_field(array('id' => 'add_slider', 'label' => __('Add item', 'hocwp-theme'), 'field_callback' => 'hocwp_field_button'));
        $meta->init();
    }
}
예제 #2
0
function hocwp_sanitize_media_value($value)
{
    $url = isset($value['url']) ? $value['url'] : '';
    $has_url = false;
    if (!empty($url)) {
        $has_url = true;
    }
    $id = isset($value['id']) ? $value['id'] : '';
    $id = absint($id);
    if (0 < $id && hocwp_media_file_exists($id)) {
        $url = hocwp_get_media_image_url($id);
    }
    if (0 >= $id && !is_array($value) && !empty($value)) {
        $url = $value;
    }
    if ($has_url && empty($url)) {
        $url = wp_get_attachment_url($id);
    }
    $icon = wp_mime_type_icon($id);
    $size = hocwp_get_media_size($id);
    $result = array('id' => $id, 'url' => $url, 'type_icon' => $icon, 'is_image' => hocwp_is_image($url, $id), 'size' => $size, 'size_format' => hocwp_size_converter($size), 'mime_type' => get_post_mime_type($id));
    return $result;
}