6

WordPress 3.5 업 로더에 새 이미지가 업로드되면 코드를 실행해야합니다. 다음의 코드 /의 JS/미디어 views.js 나는이 업로드 기능의 하단에 ('새 이미지를 업로드!') 경고를 추가WordPress 3.5 업 로더에서 새 이미지가 업로드되는 즉시 코드를 실행하는 방법

uploading: function(attachment) { 
     var content = this.frame.content; 

     // If the uploader was selected, navigate to the browser. 
     if ('upload' === content.mode()) 
      this.frame.content.mode('browse'); 

     // If we're in a workflow that supports multiple attachments, 
     // automatically select any uploading attachments. 
     if (this.get('multiple')) 
      this.get('selection').add(attachment); 
    }, 

(선 529-540) 및을 WP는-포함 브라우저 알림 '새 이미지 업로드 됨!' 새로운 이미지가 업로드되었을 때. 그러나 WordPress의 핵심을 해킹하고 싶지는 않습니다. 동일한 주제를 수행 할 수있는 몇 가지 코드를 작성할 수있는 방법이 있는지 궁금합니다. 미안해, 내 영어로. 관심 주셔서 감사합니다!

+0

http://wordpress.stackexchange.com/ –

답변

8

This line ofWP-plupload.js은 업 로더 큐가 완료에 다시 것을 보여줍니다. 그래서 당신은이 작업을 수행 할 수 있습니다

wp.Uploader.queue.on('reset', function() { 
    alert('Upload Complete!'); 
}); 

나는 그것을 테스트했습니다 그것은 WP 3.5 사이트에서 작동합니다.

그래서, 여기에 "업로드 뉴미디어"페이지와 "미디어 삽입"대화을에 새로운 plupload 업 로더에 대한 일반 업 로더 모두에 대한 지원을 포함한 전체 버전입니다.

라는 이름의 자바 스크립트 파일 만들기 : wp-admin-extender.js 및 템플릿 디렉토리 내에서 /custom/js/ 폴더 또는 어떤으로 저장합니다.

// Hack for "Upload New Media" Page (old uploader) 

// Overriding the uploadSuccess function: 
if (typeof uploadSuccess !== 'undefined') { 
    // First backup the function into a new variable. 
    var uploadSuccess_original = uploadSuccess; 
    // The original uploadSuccess function with has two arguments: fileObj, serverData 
    // So we globally declare and override the function with two arguments (argument names shouldn't matter) 
    uploadSuccess = function(fileObj, serverData) 
    { 
     // Fire the original procedure with the same arguments 
     uploadSuccess_original(fileObj, serverData); 
     // Execute whatever you want here: 
     alert('Upload Complete!'); 
    } 
} 

// Hack for "Insert Media" Dialog (new plupload uploader) 

// Hooking on the uploader queue (on reset): 
if (typeof wp.Uploader !== 'undefined' && typeof wp.Uploader.queue !== 'undefined') { 
    wp.Uploader.queue.on('reset', function() { 
     alert('Upload Complete!'); 
    }); 
} 

그리고 마지막으로;

//You can also use other techniques to add/register the script for WP Admin. 
function extend_admin_js() { 
    wp_enqueue_script('wp-admin-extender.js', get_template_directory_uri().'/custom/js/wp-admin-extender.js', array('media-upload', 'swfupload', 'plupload'), false, true); 
} 
add_action('admin_enqueue_scripts', 'extend_admin_js'); 

이것은 합법적 인 솔루션이 아닐 수도 있지만 적어도 해결의 : WP 관리자에서이 기능을 얻을 수 있도록 테마의 functions.php에 이것을 추가합니다.

+0

니스. 리셋이 정확한지 잘 모르겠다면 각 상황에 가장 적합한 것이 무엇인지 보려면'on ('all', function (e) {console.log (e)})'시도해 볼 수 있습니다. 이 회피책은 페이지의 ALL에 대한 것이고, 커스텀'wp.media' 업 로더에 액션 추가를 찾고 있었지만, 실제로 작동 할 수도 있습니다. 이것은'wp.media'의 열기 및 닫기 이벤트에서 이것을 켜고 끌 수 있습니다. – NoBugs

+0

'on ('all', fucntion() {...})'은 업로드를 위해 첨부 파일/파일을 선택/추가 할 때마다 실행됩니다. 그래서 '리셋'이 최선의 방법이라고 생각합니다. 그리고 확실히 작동합니다. 요점은 업로드가 완료 될 때만 대기열이 재설정된다는 것입니다. –

+0

도움을 주셔서 감사합니다. 명확히하기 위해 페이지에있는 모든 내용을 말했을 때 페이지의 모든 업 로더에 대해 코드가 실행되어야한다는 의미였습니다. 우리가 이것을 하나의 커스텀'wp.media' 윈도우에 대해서만하고 싶다면 어떻게해야할까요? – NoBugs

-1

자바 스크립트에서이 도움이 될 수

wp.media.view.Attachments.prototype.on('ready',function(){console.log('your code here');}); 

도 일할 수있는 PHP 코드의 조치가있을 수 있습니다, 나는 async-upload .PHP의 끝에 echo apply_filters("async_upload_{$type}", $id); 거기에 나타났습니다.

+0

에 대해 알려 주셔서 감사합니다.그러나 새로운 이미지가 업로드 된 직후가 아니라 미디어 라이브러리를 열 때마다 실행됩니다. – Alvin

-1

아마도 add_attachement 작업에 참여할 수 있습니까?

function do_my_attachment_manipulation($attachment_ID) 
{   
    $attachment = get_attached_file($attachment_ID); // Gets path to attachment 
    // Javascript alert: 
    ?> 
     <script> 
       alert('Media uploaded!'); 
     </script> 
    <?php 

} 

add_action("add_attachment", 'do_my_attachment_manipulation'); 
+0

이 작업에서 어떻게 브라우저에 자바 스크립트를 보내시겠습니까? – NoBugs

+0

나는 위의 대답을 편집하여 보여줍니다. – billerby

+0

코드가 업로드 프로세스를 중단시킵니다. ***'업로드 중에 오류가 발생했습니다. 잠시 후 다시 시도하십시오 .' *** – brasofilo

0

의해 답변을 Onur Yıldırım이 모든 업로드가 완료 될 때까지 연결을 제안합니다. 하지만 질문에 따르면 성공적으로 업로드 할 때마다 연결해야합니다. wp.Uploader.prototype을 확장하여 할 수있는 작업. jQuery를위한 적절한 지침 stackexchange 링크를 따르십시오 : 제가 테스트 한 https://wordpress.stackexchange.com/a/131295

, 정말 당신이에 "성공"응답 후크 할 수 있습니다 상징하는 (초기화, 오류를 포함하고 다른 사람을, 진행, 완료, 추가) async-upload.php json 문자열을 가져 와서 각 파일에 개별적으로 plupload "FileUploaded"자체 실행 이벤트를 생성합니다.