Улучшения для Kama_post_meta_box
Для разширения функциональности класса, предлагаю:
ввести 2 понятия разделителей:
elseif( $rg->type == 'block_break' ){ $out.='<td colspan="2" style="padding:10px 0 2px 0;color:#565656;font-size:24px;border-top:2px solid #565656;background:white">'.$rg->title.'</td>'; } elseif( $rg->type == 'clear' ){ $out.='<td colspan="2" style="padding:2px;font-size:18px;border-top:2px solid #e6e6e6">'.$rg->title.'</td>'; }
для добавления возможности загрузки картинки в метаполе (это оооочень часто требуется)
elseif( $rg->type == 'image' ){ $out.='<td>'.$rg->title.'</td><td>'.media_selector($rg->id, esc_attr($rg->val), $name).'</td>'; }
Функция media_selector
function media_selector($id, $img_id, $name) { if (empty($img_id)||!$img_id||$img_id==null) $img_id = 0; wp_enqueue_media(); ob_start(); ?><div> <div class='image-preview-wrapper'> <img id='image-preview__<?=$id?>' src='<?=wp_get_attachment_url($img_id)?>' style="max-height:200px;max-width:200px;width:auto;height:auto"> </div> <input id="upload_image_button__<?=$id?>" name="<?=$name?>__submit" type="button" class="button" value="<?=__('Upload image','iRemont')?>" /> <input id="upload_image_button__<?=$id?>__remove" type="button" class="button" value="<?=__('Remove image','iRemont')?>" /> <input type='hidden' name='<?=$name?>' id='image_attachment_id__<?=$id?>' value='<?=$img_id?>'> <input type="submit" name="<?=$name?>__submit" value="Save" class="button-primary"> </div> <script type='text/javascript'> jQuery( document ).ready( function( $ ) { var file_frame; var set_to_post_id = <?=$img_id?>; jQuery('#upload_image_button__<?=$id?>').on('click', function( event ){ file_frame = wp.media.frames.file_frame = wp.media({ title: '<?=__('Select a image to upload','iRemont')?>', button: { text: '<?=__('Use this image','iRemont')?>', }, multiple: false }); file_frame.on( 'select', function() { attachment = file_frame.state().get('selection').first().toJSON(); $('#image-preview__<?=$id?>').attr('src',attachment.url); $('#image_attachment_id__<?=$id?>').val(attachment.id); }); file_frame.open(); }); jQuery('#upload_image_button__<?=$id?>__remove').on('click', function( event ){ $('#image-preview__<?=$id?>').attr('src',''); $('#image_attachment_id__<?=$id?>').val(''); }); }); </script> <?php $var = ob_get_contents(); ob_end_clean(); return $var; }
Спасибо добавил в класс, только переделал код, там по комментам думаю разберешься. Версия 1.9.4. Чуть что пиши сюда, будем посмотреть