Пример #1
0
function mgop_setting_string()
{
    $options = get_option('mgop_options');
    $post_types_data = get_post_types(array('show_in_nav_menus' => '1'), 'object');
    $post_types = array();
    foreach ($post_types_data as $obj) {
        $post_types[$obj->name] = $obj->labels->singular_name;
    }
    foreach ($post_types as $post_name => $post_label) {
        ?>
			<div class="mgop-filed">
				<div class="mgop-filed-header">
					<input class="mgop-post-type" data-for="content_<?php 
        echo $post_name;
        ?>
" id="mgop_post_<?php 
        echo $post_name;
        ?>
" name="mgop_options[<?php 
        echo $post_name;
        ?>
][active]" type="checkbox" value="<?php 
        echo $post_name;
        ?>
" <?php 
        echo $options[$post_name]['active'] ? 'checked' : '';
        ?>
 /><label for="mgop_post_<?php 
        echo $post_name;
        ?>
" class="checkbox-label"><?php 
        echo $post_label;
        ?>
</label>
				</div>
				<div id="content_<?php 
        echo $post_name;
        ?>
" class="mgop-filed-content<?php 
        echo $options[$post_name]['active'] ? '' : ' inactive';
        ?>
">
					<ul id="list_<?php 
        echo $post_name;
        ?>
" class="sortable-list">
						<?php 
        if (count($options[$post_name]['titles'])) {
            foreach ($options[$post_name]['titles'] as $slug => $label) {
                ?>
							<li>
								<div class="drag-icon"></div>
								<div class="sortable-list-item-wrapper">
									<div class="field-item">
										<label>Metabox Title</label>
										<input type="text" name="mgop_options[<?php 
                echo $post_name;
                ?>
][titles][]" value="<?php 
                echo $label['title'];
                ?>
" class="mgop-textfield" />
									</div>				
									<div class="field-item">
										<label>Metabox Slug</label>
										<input type="text" name="" value="<?php 
                echo $slug;
                ?>
" class="mgop-textfield" disabled />
									</div>
									<div class="field-item">
										<label>Output Location</label>
										<select name="mgop_options[<?php 
                echo $post_name;
                ?>
][position][]" class="mgop-selectfield">
											<option <?php 
                echo $label['position'] == 'after' ? 'selected' : '';
                ?>
 value="after">After post content</option>
											<option <?php 
                echo $label['position'] == 'before' ? 'selected' : '';
                ?>
 value="before">Before post content</option>
											<option <?php 
                echo $label['position'] == 'shortcode' ? 'selected' : '';
                ?>
 value="shortcode">By Shortcode</option>
										</select>
									</div>
									<div class="field-item">
										<label>Available Shortcodes</label>
										<div class="mgop-contentfield">
											<code><?php 
                echo mgop_create_shortcode($slug, 'ul');
                ?>
</code><br/>
											<code><?php 
                echo mgop_create_shortcode($slug, 'ol');
                ?>
</code><br/>
											<code><?php 
                echo mgop_create_shortcode($slug, 'div');
                ?>
</code>
										</div>
									</div>
									<a href="#" class="delete-this"><span>delete</span></a>
								</div>
							</li>
						<?php 
            }
        } else {
            ?>
						<li>
							<div class="drag-icon"></div>
							<div class="sortable-list-item-wrapper">							
								<div class="field-item">
									<label>Metabox Title</label>
									<input type="text" name="mgop_options[<?php 
            echo $post_name;
            ?>
][titles][]" value="Gallery on Post" class="mgop-textfield" />
								</div>	
								<div class="field-item">
									<label>Output Location</label>
									<select name="mgop_options[<?php 
            echo $post_name;
            ?>
][position][]" class="mgop-selectfield">
										<option value="after">After post content</option>
										<option value="before">Before post content</option>
										<option value="shortcode">By Shortcode</option>
									</select>
								</div>
							</div>
							<a href="#" class="delete-this"><span>delete</span></a>
						</li>
						<?php 
        }
        ?>
					</ul>				
					<a href="#" data-rel="<?php 
        echo $post_name;
        ?>
" class="mgop-add-new">Add New</a>
				</div>
			</div>		
			<?php 
    }
    ?>
		
		<script>
			jQuery(document).ready( function($) {
				
				mgop_apply_delete = function (el){
					el.find('.delete-this').bind('click', function(event){
						event.preventDefault();
						if($(this).parent().parent().parent().children().size() > 1){
							$(this).parent().parent().fadeOut('fast', function(){
								$(this).remove();
							});
						}else{
							alert('Sorry, you cannot remove all the title.');
						}
					});
				}
				
				$('.sortable-list').sortable({handle: '.drag-icon'});
				mgop_apply_delete($('.sortable-list'));
				
				$('.mgop-add-new').bind('click', function(event){
					event.preventDefault();
					
					var post_name = $(this).attr('data-rel');
					var html = $('\
						<li>\
							<div class="drag-icon"></div>\
							<div class="sortable-list-item-wrapper">\
								<div class="field-item">\
									<label>Metabox Title</label>\
									<input type="text" name="mgop_options['+ post_name +'][titles][]" value="Gallery on Post" class="mgop-textfield" />\
								</div>\
								<div class="field-item">\
									<label>Output Location</label>\
									<select name="mgop_options['+ post_name +'][position][]" class="mgop-selectfield">\
										<option value="after">After post content</option>\
										<option value="before">Before post content</option>\
										<option value="shortcode">By Shortcode</option>\
									</select>\
								</div>\
								<a href="#" class="delete-this"><span>delete</span></a>\
							</div>\
						</li>\
					');
					mgop_apply_delete(html);
					$('#list_' + post_name).append(html);
					
					
				});
				
				$('.mgop-post-type').change(function(event){
					
					var data_for = $(this).attr('data-for');
					if($(this).is(':checked')){
						$('#' + data_for).removeClass('inactive');
					}else{
						$('#' + data_for).addClass('inactive');
					}
					
				});
				
			});
		</script>
		
		<?php 
}
Пример #2
0
        add_post_meta($post_ID, 'mgop_media_value', $data, true) or update_post_meta($post_ID, 'mgop_media_value', $data);
    }
    public function mb_callback($post, $box)
    {
        $value = get_post_meta($post->ID, 'mgop_media_value', true);
        $value = isset($value[$box['id']]) ? $value[$box['id']] : array();
        wp_nonce_field(plugin_basename(__FILE__), 'mgop_noncename');
        ?>
		
		<a href="#" class="mgop_add" data-for="<?php 
        echo $box['id'];
        ?>
" title="<?php 
        echo $box['title'];
        ?>
">Add Image</a>
		<ul id="mgop_<?php 
        echo $box['id'];
        ?>
" class="mgop-wrapper-sortable">
			<?php 
        if (is_array($value) && count($value)) {
            foreach ($value as $attc_id) {
                $url = wp_get_attachment_thumb_url($attc_id);
                ?>
				<li class="mgop_thumnails" title="Drag and drop to sort the item"><div><span class="mgop-movable"></span><a href="#" class="mgop_remove_item" title="Click to delete this item"><span>delete</span></a><img src="<?php 
                echo $url;
                ?>
"><input type="hidden" name="mgop_media[<?php 
                echo $box['id'];
                ?>
][]" value="<?php 
                echo $attc_id;
                ?>
" /></div></li>
			<?php 
            }
        }
        ?>
		</ul>
		<div class="mgop-detail" style="border-top: 1px solid #ccc;">
			<ul>
				<li><label>Gallery Slug</label>: <code><?php 
        echo $box['args']['slug'];
        ?>
</code></li>
				<li><label>Output Location</label>: <?php 
        echo $this->positions[$box['args']['position']];
        ?>
</li>