태그 보관물: media

media

사용자 지정 이미지 집합을 사용하여 미디어 업로드 관리자에 새 탭을 추가하는 방법은 무엇입니까? 새 탭을 추가하고 싶습니다. theme_folder/images/patterns 탭을 추가하기 위해

관리자 및 내부 목록 이미지를 업로드하기 위해 새 탭을 추가하고 싶습니다.

theme_folder/images/patterns

탭을 추가하기 위해 이와 같은 것을 시도했지만 미디어 관리자 측면에 탭을 추가하고 있지만 이미지 업로드시 해당 탭이 보이지 않기 때문에 작동하지 않습니다.

function custom_media_upload_tab_name( $tabs ) {
    $newtab = array( 'tab_slug' => 'Patterns' );
    return array_merge( $tabs, $newtab );
}

add_filter( 'media_upload_tabs', 'custom_media_upload_tab_name' );

function custom_media_upload_tab_content() {
    // Add you content here.
    echo 'Hello content';
}
add_action( 'media_upload_tab_slug', 'custom_media_upload_tab_content' );

정확히 말하면 여기에 새 탭을 추가하고 해당 탭에서 테마 폴더의 이미지를 나열하고 싶습니다.

여기에 이미지 설명을 입력하십시오

미디어 관리자 JS를 다시 작성해야한다는 것을 알고 있지만 솔직히 시작해야 할 곳을 모릅니다. 이것을 달성하기 위해 미디어 관리자를 위해 완전히 새로운 템플릿을 작성해야 할 것 같습니다.

나는 모든 제안을 통과했지만 아무도 질문을 읽지 않는 것 같습니다. 조언했듯이 “탭을 추가하기 위해 이와 같은 것을 시도했지만 미디어 관리자 측면에 탭을 추가하고 있지만 이미지를 업로드 할 때 해당 탭이 보이지 않기 때문에 작동하지 않습니다.”

따라서 현재로서는 아무도 이것에 대한 해결책을 찾을 수 없습니다.



답변

이것은 오래된 스레드이지만 여전히 관련성이 있습니다. 나는 멍청하고 여기에 미디어 탭을 추가하기 위해이 코드를 생각해 냈습니다. 아마도 누군가 탭의 내용을 처리하는 방법을 계속하고 싶습니까? 🙂

add_action('admin_enqueue_scripts', function(){
    wp_enqueue_script( 'my-media-tab', plugin_dir_url( __FILE__ ) . '/js/mytab.js', array( 'jquery' ), '', true );
});

그리고 js 파일 :

var l10n = wp.media.view.l10n;
wp.media.view.MediaFrame.Select.prototype.browseRouter = function( routerView ) {
    routerView.set({
        upload: {
            text:     l10n.uploadFilesTitle,
            priority: 20
        },
        browse: {
            text:     l10n.mediaLibraryTitle,
            priority: 40
        },
        my_tab: {
            text:     "My tab",
            priority: 60
        }
    });
};

편집 : 좋아. 내용을 처리하기 위해 wp.media 에서이 작업을 수행하는 좋은 방법을 찾지 못했습니다. 현재 솔루션은 2 개의 lisener입니다. 하나는 미디어 라이브러리를 열고 하나는 미디어 라우터 메뉴를 클릭하기위한 것입니다.

jQuery(document).ready(function($){
    if ( wp.media ) {
        wp.media.view.Modal.prototype.on( "open", function() {
            if($('body').find('.media-modal-content .media-router a.media-menu-item.active')[0].innerText == "My tab")
                doMyTabContent();
        });
        $(wp.media).on('click', '.media-router a.media-menu-item', function(e){
            if(e.target.innerText == "My tab")
                doMyTabContent();
        });
    }
});

함수 doMyTabContent (); 그냥 같은 것입니다;

function doMyTabContent() {
    var html = '<div class="myTabContent">';
    //My tab content here
    html += '</div>';
    $('body .media-modal-content .media-frame-content')[0].innerHTML = html;
}

나는 이것이 훨씬 더 섬세한 방식으로 이루어질 수 있다고 확신합니다. 이것을 읽고 더 나은 해결책을 가진 사람은 다음을 작성하십시오 🙂


답변

WordPress Codex 에 따르면 다음과 같이 미디어 업 로더에 사용자 정의 탭을 추가 할 수 있습니다.

// add the tab
add_filter('media_upload_tabs', 'my_upload_tab');
function my_upload_tab($tabs) {
    $tabs['mytabname'] = "My Tab Name";
    return $tabs;
}

// call the new tab with wp_iframe
add_action('media_upload_mytabname', 'add_my_new_form');
function add_my_new_form() {
    wp_iframe( 'my_new_form' );
}

// the tab content
function my_new_form() {
    echo media_upload_header(); // This function is used for print media uploader headers etc.
    echo '<p>Example HTML content goes here.</p>';
}

그것이 도움이되기를 바랍니다.


답변

   function axcoto_genify_media_menu($tabs) {
            $newtab = array('genify'  => __('Axcoto Genify', 'axcotogenify'));
            return array_merge($tabs, $newtab);
            }
            add_filter('media_upload_tabs', 'axcoto_genify_media_menu');

           array('genify' => __('Axcoto Genify', 'axcotogenify'));


        function axcoto_genify_media_process() {
        media_upload_header();
        echo 'hello';
        }
        function axcoto_genify_media_menu_handle() {
        return wp_iframe( 'axcoto_genify_media_process');
        }



 if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) || 0 === strpos( $content_func, 'media' ) )
        wp_enqueue_style( 'media' );


답변