2017-01-19 2 views
-1

내 WordPress function.php 파일에 이미지 업로드 기능이 있지만 내 function.php 파일이 ioncube 인코더로 인코딩되어 있으므로 해당 기능을 편집 할 수 없습니다.function wordpress를 오버라이드

하지만 내 테마 작성자가 제공 한 기능의 전체 코드가 있습니다. 제작자가 작동 할 기능을 무효화하라고 말했습니다.

내 함수 이름 pinc_upload_pin()이며이 add_action('wp_ajax_pinc-upload-pin', 'pinc_upload_pin');

같은 추가되어 지금은 그 위의 함수를 재정의해야합니다.

저는 하나의 별도 파일 이름 function_new.php를 만들고 에 require_once처럼 포함 시키려고했습니다. 위의 기능을 제거하려면 remove_action('wp_ajax_pinc-upload-pin', 'pinc_upload_pin');

을 입력하고 자체 함수를 추가하고 연결하십시오. 아래에있는 내 function_new.php 코드

remove_action('wp_ajax_pinc-upload-pin', 'pinc_upload_pin'); 

function pinc_upload_pin_new(){ 
    check_ajax_referer('upload_pin', 'ajax-nonce'); 

    do_action('pinc_before_upload_pin', $_POST); 

    $minWidth = 2; 
    $minHeight = 2; 

    $minWidth = apply_filters('pinc_minwidth', $minWidth); 
    $minHeight = apply_filters('pinc_minheight', $minHeight); 

    require_once(ABSPATH . 'wp-admin/includes/image.php'); 
    require_once(ABSPATH . 'wp-admin/includes/file.php'); 
    require_once(ABSPATH . 'wp-admin/includes/media.php'); 

    if ($_POST['mode'] == 'computer') { 
     if ($_FILES) { 
      foreach ($_FILES as $file => $array) {   
       $imageTypes = array (
        1, //IMAGETYPE_GIF 
        2, //IMAGETYPE_JPEG 
        3 //IMAGETYPE_PNG 
       ); 

       $imageinfo = getimagesize($_FILES[$file]['tmp_name']); 
       $width = @$imageinfo[0]; 
       $height = @$imageinfo[1]; 
       $type = @$imageinfo[2]; 
       $mime = @$imageinfo['mime']; 

       if (!in_array($type, $imageTypes)) { 
        @unlink($_FILES[$file]['tmp_name']); 
        echo 'error'; 
        die(); 
       } 

       if ($width < $minWidth || $height < $minWidth) { 
        @unlink($_FILES[$file]['tmp_name']); 
        echo 'errorsize'; 
        die(); 
       } 

       if($mime != 'image/gif' && $mime != 'image/jpeg' && $mime != 'image/png') { 
        @unlink($_FILES[$file]['tmp_name']); 
        echo 'error'; 
        die(); 
       } 

       switch($type) { 
        case 1: 
         $ext = '.gif'; 

         //check if is animated gif 
         $frames = 0; 
         if(($fh = @fopen($_FILES[$file]['tmp_name'], 'rb')) && $error != 'error') { 
          while(!feof($fh) && $frames < 2) { 
           $chunk = fread($fh, 1024 * 100); //read 100kb at a time 
           $frames += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches); 
          } 
         } 
         fclose($fh); 

         break; 
        case 2: 
         $ext = '.jpg'; 
         break; 
        case 3: 
         $ext = '.png'; 
         break; 
       } 
       $transliterationTable = array('á' => 'a', 'Á' => 'A', 'à' => 'a', 'À' => 'A', 'ă' => 'a', 'Ă' => 'A', 'â' => 'a', 'Â' => 'A', 'å' => 'a', 'Å' => 'A', 'ã' => 'a', 'Ã' => 'A', 'ą' => 'a', 'Ą' => 'A', 'ā' => 'a', 'Ā' => 'A', 'ä' => 'ae', 'Ä' => 'AE', 'æ' => 'ae', 'Æ' => 'AE', 'ḃ' => 'b', 'Ḃ' => 'B', 'ć' => 'c', 'Ć' => 'C', 'ĉ' => 'c', 'Ĉ' => 'C', 'č' => 'c', 'Č' => 'C', 'ċ' => 'c', 'Ċ' => 'C', 'ç' => 'c', 'Ç' => 'C', 'ď' => 'd', 'Ď' => 'D', 'ḋ' => 'd', 'Ḋ' => 'D', 'đ' => 'd', 'Đ' => 'D', 'ð' => 'dh', 'Ð' => 'Dh', 'é' => 'e', 'É' => 'E', 'è' => 'e', 'È' => 'E', 'ĕ' => 'e', 'Ĕ' => 'E', 'ê' => 'e', 'Ê' => 'E', 'ě' => 'e', 'Ě' => 'E', 'ë' => 'e', 'Ë' => 'E', 'ė' => 'e', 'Ė' => 'E', 'ę' => 'e', 'Ę' => 'E', 'ē' => 'e', 'Ē' => 'E', 'ḟ' => 'f', 'Ḟ' => 'F', 'ƒ' => 'f', 'Ƒ' => 'F', 'ğ' => 'g', 'Ğ' => 'G', 'ĝ' => 'g', 'Ĝ' => 'G', 'ġ' => 'g', 'Ġ' => 'G', 'ģ' => 'g', 'Ģ' => 'G', 'ĥ' => 'h', 'Ĥ' => 'H', 'ħ' => 'h', 'Ħ' => 'H', 'í' => 'i', 'Í' => 'I', 'ì' => 'i', 'Ì' => 'I', 'î' => 'i', 'Î' => 'I', 'ï' => 'i', 'Ï' => 'I', 'ĩ' => 'i', 'Ĩ' => 'I', 'į' => 'i', 'Į' => 'I', 'ī' => 'i', 'Ī' => 'I', 'ĵ' => 'j', 'Ĵ' => 'J', 'ķ' => 'k', 'Ķ' => 'K', 'ĺ' => 'l', 'Ĺ' => 'L', 'ľ' => 'l', 'Ľ' => 'L', 'ļ' => 'l', 'Ļ' => 'L', 'ł' => 'l', 'Ł' => 'L', 'ṁ' => 'm', 'Ṁ' => 'M', 'ń' => 'n', 'Ń' => 'N', 'ň' => 'n', 'Ň' => 'N', 'ñ' => 'n', 'Ñ' => 'N', 'ņ' => 'n', 'Ņ' => 'N', 'ó' => 'o', 'Ó' => 'O', 'ò' => 'o', 'Ò' => 'O', 'ô' => 'o', 'Ô' => 'O', 'ő' => 'o', 'Ő' => 'O', 'õ' => 'o', 'Õ' => 'O', 'ø' => 'oe', 'Ø' => 'OE', 'ō' => 'o', 'Ō' => 'O', 'ơ' => 'o', 'Ơ' => 'O', 'ö' => 'oe', 'Ö' => 'OE', 'ṗ' => 'p', 'Ṗ' => 'P', 'ŕ' => 'r', 'Ŕ' => 'R', 'ř' => 'r', 'Ř' => 'R', 'ŗ' => 'r', 'Ŗ' => 'R', 'ś' => 's', 'Ś' => 'S', 'ŝ' => 's', 'Ŝ' => 'S', 'š' => 's', 'Š' => 'S', 'ṡ' => 's', 'Ṡ' => 'S', 'ş' => 's', 'Ş' => 'S', 'ș' => 's', 'Ș' => 'S', 'ß' => 'SS', 'ť' => 't', 'Ť' => 'T', 'ṫ' => 't', 'Ṫ' => 'T', 'ţ' => 't', 'Ţ' => 'T', 'ț' => 't', 'Ț' => 'T', 'ŧ' => 't', 'Ŧ' => 'T', 'ú' => 'u', 'Ú' => 'U', 'ù' => 'u', 'Ù' => 'U', 'ŭ' => 'u', 'Ŭ' => 'U', 'û' => 'u', 'Û' => 'U', 'ů' => 'u', 'Ů' => 'U', 'ű' => 'u', 'Ű' => 'U', 'ũ' => 'u', 'Ũ' => 'U', 'ų' => 'u', 'Ų' => 'U', 'ū' => 'u', 'Ū' => 'U', 'ư' => 'u', 'Ư' => 'U', 'ü' => 'ue', 'Ü' => 'UE', 'ẃ' => 'w', 'Ẃ' => 'W', 'ẁ' => 'w', 'Ẁ' => 'W', 'ŵ' => 'w', 'Ŵ' => 'W', 'ẅ' => 'w', 'Ẅ' => 'W', 'ý' => 'y', 'Ý' => 'Y', 'ỳ' => 'y', 'Ỳ' => 'Y', 'ŷ' => 'y', 'Ŷ' => 'Y', 'ÿ' => 'y', 'Ÿ' => 'Y', 'ź' => 'z', 'Ź' => 'Z', 'ž' => 'z', 'Ž' => 'Z', 'ż' => 'z', 'Ż' => 'Z', 'þ' => 'th', 'Þ' => 'Th', 'µ' => 'u', 'а' => 'a', 'А' => 'a', 'б' => 'b', 'Б' => 'b', 'в' => 'v', 'В' => 'v', 'г' => 'g', 'Г' => 'g', 'д' => 'd', 'Д' => 'd', 'е' => 'e', 'Е' => 'E', 'ё' => 'e', 'Ё' => 'E', 'ж' => 'zh', 'Ж' => 'zh', 'з' => 'z', 'З' => 'z', 'и' => 'i', 'И' => 'i', 'й' => 'j', 'Й' => 'j', 'к' => 'k', 'К' => 'k', 'л' => 'l', 'Л' => 'l', 'м' => 'm', 'М' => 'm', 'н' => 'n', 'Н' => 'n', 'о' => 'o', 'О' => 'o', 'п' => 'p', 'П' => 'p', 'р' => 'r', 'Р' => 'r', 'с' => 's', 'С' => 's', 'т' => 't', 'Т' => 't', 'у' => 'u', 'У' => 'u', 'ф' => 'f', 'Ф' => 'f', 'х' => 'h', 'Х' => 'h', 'ц' => 'c', 'Ц' => 'c', 'ч' => 'ch', 'Ч' => 'ch', 'ш' => 'sh', 'Ш' => 'sh', 'щ' => 'sch', 'Щ' => 'sch', 'ъ' => '', 'Ъ' => '', 'ы' => 'y', 'Ы' => 'y', 'ь' => '', 'Ь' => '', 'э' => 'e', 'Э' => 'e', 'ю' => 'ju', 'Ю' => 'ju', 'я' => 'ja', 'Я' => 'ja'); 

       $fname = $_FILES[$file]['name']; 
       $fname = str_replace(array_keys($transliterationTable), array_values($transliterationTable), $fname); 
       $filename = time() . str_shuffle('pcl48'); 
       $original_filename = preg_replace('/[^(\x20|\x61-\x7A)]*/', '', strtolower(str_ireplace($ext, '', $fname))); //preg_replace('/[^(\x48-\x7A)]*/' strips non-utf character. Ref: http://www.ssec.wisc.edu/~tomw/java/unicode.html#x0000 
       $_FILES[$file]['name'] = strtolower(substr($original_filename, 0, 100)) . '-' . $filename . $ext; 

       $attach_id = media_handle_upload($file, $post_id); 

       if (is_wp_error($attach_id)) { 
        @unlink($_FILES[$file]['tmp_name']); 
        echo 'error'; 
        die(); 
       } else { 
        if ($frames > 1) { 
         update_post_meta($attach_id, 'a_gif', 'yes'); 
        } 
       } 
      } 
     } 

     update_post_meta($attach_id, 'pinc_unattached', 'yes'); 

     $return = array(); 

     $thumbnail = wp_get_attachment_image_src($attach_id, 'medium'); 
     $return['thumbnail'] = $thumbnail[0]; 
     $return['id'] = $attach_id; 

     do_action('pinc_after_upload_pin_computer', $attach_id); 
     echo json_encode($return); 
    } else if ($_POST['mode'] == 'web') { 
     $url = esc_url_raw($_POST['pin_upload_web']); 

     if (function_exists('curl_init')) { 
      $ch = curl_init(); 
      curl_setopt($ch, CURLOPT_URL, $url); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
      $image = curl_exec($ch); 
      curl_close($ch); 
     } elseif (ini_get('allow_url_fopen')) { 
      $image = file_get_contents($url, false, $context); 
     } 

     if (!$image) { 
      echo 'error'; 
      die(); 
     } 

     $filename = time() . str_shuffle('pcl48'); 
     $file_array['tmp_name'] = WP_CONTENT_DIR . "/" . $filename . '.tmp'; 
     $filetmp = file_put_contents($file_array['tmp_name'], $image); 

     if (!$filetmp) { 
      @unlink($file_array['tmp_name']); 
      echo 'error'; 
      die(); 
     } 

     $imageTypes = array (
      1, //IMAGETYPE_GIF 
      2, //IMAGETYPE_JPEG 
      3 //IMAGETYPE_PNG 
     ); 

     $imageinfo = getimagesize($file_array['tmp_name']); 
     $width = @$imageinfo[0]; 
     $height = @$imageinfo[1]; 
     $type = @$imageinfo[2]; 
     $mime = @$imageinfo['mime']; 

     if (!in_array ($type, $imageTypes)) { 
      @unlink($file_array['tmp_name']); 
      echo 'error'; 
      die(); 
     } 

     if ($width < $minWidth || $height < $minWidth) { 
      @unlink($file_array['tmp_name']); 
      echo 'errorsize'; 
      die(); 
     } 

     if($mime != 'image/gif' && $mime != 'image/jpeg' && $mime != 'image/png') { 
      @unlink($file_array['tmp_name']); 
      echo 'error'; 
      die(); 
     } 

     switch($type) { 
      case 1: 
       $ext = '.gif'; 

       //check if is animated gif 
       $frame = 0; 
       if(($fh = @fopen($file_array['tmp_name'], 'rb')) && $error != 'error') { 
        while(!feof($fh) && $frames < 2) { 
         $chunk = fread($fh, 1024 * 100); //read 100kb at a time 
         $frames += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches); 
        } 
       } 
       fclose($fh); 

       break; 
      case 2: 
       $ext = '.jpg'; 
       break; 
      case 3: 
       $ext = '.png'; 
       break; 
     } 
     $original_filename = preg_replace('/[^(\x20|\x61-\x7A)]*/', '', strtolower(str_ireplace($ext, '', basename($url)))); //preg_replace('/[^(\x48-\x7A)]*/' strips non-utf character. Ref: http://www.ssec.wisc.edu/~tomw/java/unicode.html#x0000 
     $file_array['name'] = strtolower(substr($original_filename, 0, 100)) . '-' . $filename . $ext; 

     $attach_id = media_handle_sideload($file_array, $post_id); 

     if (is_wp_error($attach_id)) { 
      @unlink($file_array['tmp_name']); 
      echo 'error'; 
      die(); 
     } else { 
      if ($frames > 1) { 
       update_post_meta($attach_id, 'a_gif', 'yes'); 
      } 
     } 

     update_post_meta($attach_id, 'pinc_unattached', 'yes'); 

     $return = array(); 
     $thumbnail = wp_get_attachment_image_src($attach_id, 'medium'); 
     $return['thumbnail'] = $thumbnail[0]; 
     $return['id'] = $attach_id; 

     do_action('pinc_after_upload_pin_web', $attach_id); 
     echo json_encode($return); 
    } 
    exit; 
} 
add_action('wp_ajax_pinc-upload-pin', 'pinc_upload_pin_new'); 

하지만 내이 새로운 기능을 호출 할 수 있습니다. 여전히 기존 기능을 호출 pinc_upload_pin();

내가 뭔가를

+0

'pinc_upload_pin' 후크를 제거하려고 할 때 이미 추가되었으므로 코드가 실행되지 않아야 해당 후크를 추가 할 수 있습니까? –

+0

pinc_upload_pin 후크를 function.php에 추가하면 header.php에서 해당 후크가 제거됩니다. 맞습니까? – dhavald99

+0

내 바닥 글과 두 파일 모두 인코딩되어 있으므로 – dhavald99

답변

0

을 잃었 곳 저를 인도하십시오 당신은 어떻게 기존 기능보다 높은 우선 순위로 당신에게 새로운 기능을 훅하고 새로운에만 수 있도록 그 함수 내부 이전 후크를 제거에 대해 함수가 호출됩니다. 아래

시험하지 만 (기본 우선 순위 레벨이 지정되지 않은 경우 10이기 때문에 10 미만의 모든 숫자)는 훅 우선 순위 (9)를 제공하여 작동 할 수 있습니다 : 사람들을위한

add_action('wp_ajax_pinc-upload-pin', 'pinc_upload_pin_new',9); // High priority 
add_action('wp_ajax_nopriv_pinc-upload-pin', 'pinc_upload_pin_new',9); // Use this line only if you need this hook for non-logged in users as well 

function pinc_upload_pin_new(){ 
    remove_action('wp_ajax_pinc-upload-pin', 'pinc_upload_pin'); 

    check_ajax_referer('upload_pin', 'ajax-nonce'); 

    do_action('pinc_before_upload_pin', $_POST); 

    $minWidth = 2; 
    $minHeight = 2; 

    $minWidth = apply_filters('pinc_minwidth', $minWidth); 
    $minHeight = apply_filters('pinc_minheight', $minHeight); 

    require_once(ABSPATH . 'wp-admin/includes/image.php'); 
    require_once(ABSPATH . 'wp-admin/includes/file.php'); 
    require_once(ABSPATH . 'wp-admin/includes/media.php'); 

    if ($_POST['mode'] == 'computer') { 
     if ($_FILES) { 
      foreach ($_FILES as $file => $array) {   
       $imageTypes = array (
        1, //IMAGETYPE_GIF 
        2, //IMAGETYPE_JPEG 
        3 //IMAGETYPE_PNG 
       ); 

       $imageinfo = getimagesize($_FILES[$file]['tmp_name']); 
       $width = @$imageinfo[0]; 
       $height = @$imageinfo[1]; 
       $type = @$imageinfo[2]; 
       $mime = @$imageinfo['mime']; 

       if (!in_array($type, $imageTypes)) { 
        @unlink($_FILES[$file]['tmp_name']); 
        echo 'error'; 
        die(); 
       } 

       if ($width < $minWidth || $height < $minWidth) { 
        @unlink($_FILES[$file]['tmp_name']); 
        echo 'errorsize'; 
        die(); 
       } 

       if($mime != 'image/gif' && $mime != 'image/jpeg' && $mime != 'image/png') { 
        @unlink($_FILES[$file]['tmp_name']); 
        echo 'error'; 
        die(); 
       } 

       switch($type) { 
        case 1: 
         $ext = '.gif'; 

         //check if is animated gif 
         $frames = 0; 
         if(($fh = @fopen($_FILES[$file]['tmp_name'], 'rb')) && $error != 'error') { 
          while(!feof($fh) && $frames < 2) { 
           $chunk = fread($fh, 1024 * 100); //read 100kb at a time 
           $frames += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches); 
          } 
         } 
         fclose($fh); 

         break; 
        case 2: 
         $ext = '.jpg'; 
         break; 
        case 3: 
         $ext = '.png'; 
         break; 
       } 
       $transliterationTable = array('á' => 'a', 'Á' => 'A', 'à' => 'a', 'À' => 'A', 'ă' => 'a', 'Ă' => 'A', 'â' => 'a', 'Â' => 'A', 'å' => 'a', 'Å' => 'A', 'ã' => 'a', 'Ã' => 'A', 'ą' => 'a', 'Ą' => 'A', 'ā' => 'a', 'Ā' => 'A', 'ä' => 'ae', 'Ä' => 'AE', 'æ' => 'ae', 'Æ' => 'AE', 'ḃ' => 'b', 'Ḃ' => 'B', 'ć' => 'c', 'Ć' => 'C', 'ĉ' => 'c', 'Ĉ' => 'C', 'č' => 'c', 'Č' => 'C', 'ċ' => 'c', 'Ċ' => 'C', 'ç' => 'c', 'Ç' => 'C', 'ď' => 'd', 'Ď' => 'D', 'ḋ' => 'd', 'Ḋ' => 'D', 'đ' => 'd', 'Đ' => 'D', 'ð' => 'dh', 'Ð' => 'Dh', 'é' => 'e', 'É' => 'E', 'è' => 'e', 'È' => 'E', 'ĕ' => 'e', 'Ĕ' => 'E', 'ê' => 'e', 'Ê' => 'E', 'ě' => 'e', 'Ě' => 'E', 'ë' => 'e', 'Ë' => 'E', 'ė' => 'e', 'Ė' => 'E', 'ę' => 'e', 'Ę' => 'E', 'ē' => 'e', 'Ē' => 'E', 'ḟ' => 'f', 'Ḟ' => 'F', 'ƒ' => 'f', 'Ƒ' => 'F', 'ğ' => 'g', 'Ğ' => 'G', 'ĝ' => 'g', 'Ĝ' => 'G', 'ġ' => 'g', 'Ġ' => 'G', 'ģ' => 'g', 'Ģ' => 'G', 'ĥ' => 'h', 'Ĥ' => 'H', 'ħ' => 'h', 'Ħ' => 'H', 'í' => 'i', 'Í' => 'I', 'ì' => 'i', 'Ì' => 'I', 'î' => 'i', 'Î' => 'I', 'ï' => 'i', 'Ï' => 'I', 'ĩ' => 'i', 'Ĩ' => 'I', 'į' => 'i', 'Į' => 'I', 'ī' => 'i', 'Ī' => 'I', 'ĵ' => 'j', 'Ĵ' => 'J', 'ķ' => 'k', 'Ķ' => 'K', 'ĺ' => 'l', 'Ĺ' => 'L', 'ľ' => 'l', 'Ľ' => 'L', 'ļ' => 'l', 'Ļ' => 'L', 'ł' => 'l', 'Ł' => 'L', 'ṁ' => 'm', 'Ṁ' => 'M', 'ń' => 'n', 'Ń' => 'N', 'ň' => 'n', 'Ň' => 'N', 'ñ' => 'n', 'Ñ' => 'N', 'ņ' => 'n', 'Ņ' => 'N', 'ó' => 'o', 'Ó' => 'O', 'ò' => 'o', 'Ò' => 'O', 'ô' => 'o', 'Ô' => 'O', 'ő' => 'o', 'Ő' => 'O', 'õ' => 'o', 'Õ' => 'O', 'ø' => 'oe', 'Ø' => 'OE', 'ō' => 'o', 'Ō' => 'O', 'ơ' => 'o', 'Ơ' => 'O', 'ö' => 'oe', 'Ö' => 'OE', 'ṗ' => 'p', 'Ṗ' => 'P', 'ŕ' => 'r', 'Ŕ' => 'R', 'ř' => 'r', 'Ř' => 'R', 'ŗ' => 'r', 'Ŗ' => 'R', 'ś' => 's', 'Ś' => 'S', 'ŝ' => 's', 'Ŝ' => 'S', 'š' => 's', 'Š' => 'S', 'ṡ' => 's', 'Ṡ' => 'S', 'ş' => 's', 'Ş' => 'S', 'ș' => 's', 'Ș' => 'S', 'ß' => 'SS', 'ť' => 't', 'Ť' => 'T', 'ṫ' => 't', 'Ṫ' => 'T', 'ţ' => 't', 'Ţ' => 'T', 'ț' => 't', 'Ț' => 'T', 'ŧ' => 't', 'Ŧ' => 'T', 'ú' => 'u', 'Ú' => 'U', 'ù' => 'u', 'Ù' => 'U', 'ŭ' => 'u', 'Ŭ' => 'U', 'û' => 'u', 'Û' => 'U', 'ů' => 'u', 'Ů' => 'U', 'ű' => 'u', 'Ű' => 'U', 'ũ' => 'u', 'Ũ' => 'U', 'ų' => 'u', 'Ų' => 'U', 'ū' => 'u', 'Ū' => 'U', 'ư' => 'u', 'Ư' => 'U', 'ü' => 'ue', 'Ü' => 'UE', 'ẃ' => 'w', 'Ẃ' => 'W', 'ẁ' => 'w', 'Ẁ' => 'W', 'ŵ' => 'w', 'Ŵ' => 'W', 'ẅ' => 'w', 'Ẅ' => 'W', 'ý' => 'y', 'Ý' => 'Y', 'ỳ' => 'y', 'Ỳ' => 'Y', 'ŷ' => 'y', 'Ŷ' => 'Y', 'ÿ' => 'y', 'Ÿ' => 'Y', 'ź' => 'z', 'Ź' => 'Z', 'ž' => 'z', 'Ž' => 'Z', 'ż' => 'z', 'Ż' => 'Z', 'þ' => 'th', 'Þ' => 'Th', 'µ' => 'u', 'а' => 'a', 'А' => 'a', 'б' => 'b', 'Б' => 'b', 'в' => 'v', 'В' => 'v', 'г' => 'g', 'Г' => 'g', 'д' => 'd', 'Д' => 'd', 'е' => 'e', 'Е' => 'E', 'ё' => 'e', 'Ё' => 'E', 'ж' => 'zh', 'Ж' => 'zh', 'з' => 'z', 'З' => 'z', 'и' => 'i', 'И' => 'i', 'й' => 'j', 'Й' => 'j', 'к' => 'k', 'К' => 'k', 'л' => 'l', 'Л' => 'l', 'м' => 'm', 'М' => 'm', 'н' => 'n', 'Н' => 'n', 'о' => 'o', 'О' => 'o', 'п' => 'p', 'П' => 'p', 'р' => 'r', 'Р' => 'r', 'с' => 's', 'С' => 's', 'т' => 't', 'Т' => 't', 'у' => 'u', 'У' => 'u', 'ф' => 'f', 'Ф' => 'f', 'х' => 'h', 'Х' => 'h', 'ц' => 'c', 'Ц' => 'c', 'ч' => 'ch', 'Ч' => 'ch', 'ш' => 'sh', 'Ш' => 'sh', 'щ' => 'sch', 'Щ' => 'sch', 'ъ' => '', 'Ъ' => '', 'ы' => 'y', 'Ы' => 'y', 'ь' => '', 'Ь' => '', 'э' => 'e', 'Э' => 'e', 'ю' => 'ju', 'Ю' => 'ju', 'я' => 'ja', 'Я' => 'ja'); 

       $fname = $_FILES[$file]['name']; 
       $fname = str_replace(array_keys($transliterationTable), array_values($transliterationTable), $fname); 
       $filename = time() . str_shuffle('pcl48'); 
       $original_filename = preg_replace('/[^(\x20|\x61-\x7A)]*/', '', strtolower(str_ireplace($ext, '', $fname))); //preg_replace('/[^(\x48-\x7A)]*/' strips non-utf character. Ref: http://www.ssec.wisc.edu/~tomw/java/unicode.html#x0000 
       $_FILES[$file]['name'] = strtolower(substr($original_filename, 0, 100)) . '-' . $filename . $ext; 

       $attach_id = media_handle_upload($file, $post_id); 

       if (is_wp_error($attach_id)) { 
        @unlink($_FILES[$file]['tmp_name']); 
        echo 'error'; 
        die(); 
       } else { 
        if ($frames > 1) { 
         update_post_meta($attach_id, 'a_gif', 'yes'); 
        } 
       } 
      } 
     } 

     update_post_meta($attach_id, 'pinc_unattached', 'yes'); 

     $return = array(); 

     $thumbnail = wp_get_attachment_image_src($attach_id, 'medium'); 
     $return['thumbnail'] = $thumbnail[0]; 
     $return['id'] = $attach_id; 

     do_action('pinc_after_upload_pin_computer', $attach_id); 
     echo json_encode($return); 
    } else if ($_POST['mode'] == 'web') { 
     $url = esc_url_raw($_POST['pin_upload_web']); 

     if (function_exists('curl_init')) { 
      $ch = curl_init(); 
      curl_setopt($ch, CURLOPT_URL, $url); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
      $image = curl_exec($ch); 
      curl_close($ch); 
     } elseif (ini_get('allow_url_fopen')) { 
      $image = file_get_contents($url, false, $context); 
     } 

     if (!$image) { 
      echo 'error'; 
      die(); 
     } 

     $filename = time() . str_shuffle('pcl48'); 
     $file_array['tmp_name'] = WP_CONTENT_DIR . "/" . $filename . '.tmp'; 
     $filetmp = file_put_contents($file_array['tmp_name'], $image); 

     if (!$filetmp) { 
      @unlink($file_array['tmp_name']); 
      echo 'error'; 
      die(); 
     } 

     $imageTypes = array (
      1, //IMAGETYPE_GIF 
      2, //IMAGETYPE_JPEG 
      3 //IMAGETYPE_PNG 
     ); 

     $imageinfo = getimagesize($file_array['tmp_name']); 
     $width = @$imageinfo[0]; 
     $height = @$imageinfo[1]; 
     $type = @$imageinfo[2]; 
     $mime = @$imageinfo['mime']; 

     if (!in_array ($type, $imageTypes)) { 
      @unlink($file_array['tmp_name']); 
      echo 'error'; 
      die(); 
     } 

     if ($width < $minWidth || $height < $minWidth) { 
      @unlink($file_array['tmp_name']); 
      echo 'errorsize'; 
      die(); 
     } 

     if($mime != 'image/gif' && $mime != 'image/jpeg' && $mime != 'image/png') { 
      @unlink($file_array['tmp_name']); 
      echo 'error'; 
      die(); 
     } 

     switch($type) { 
      case 1: 
       $ext = '.gif'; 

       //check if is animated gif 
       $frame = 0; 
       if(($fh = @fopen($file_array['tmp_name'], 'rb')) && $error != 'error') { 
        while(!feof($fh) && $frames < 2) { 
         $chunk = fread($fh, 1024 * 100); //read 100kb at a time 
         $frames += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches); 
        } 
       } 
       fclose($fh); 

       break; 
      case 2: 
       $ext = '.jpg'; 
       break; 
      case 3: 
       $ext = '.png'; 
       break; 
     } 
     $original_filename = preg_replace('/[^(\x20|\x61-\x7A)]*/', '', strtolower(str_ireplace($ext, '', basename($url)))); //preg_replace('/[^(\x48-\x7A)]*/' strips non-utf character. Ref: http://www.ssec.wisc.edu/~tomw/java/unicode.html#x0000 
     $file_array['name'] = strtolower(substr($original_filename, 0, 100)) . '-' . $filename . $ext; 

     $attach_id = media_handle_sideload($file_array, $post_id); 

     if (is_wp_error($attach_id)) { 
      @unlink($file_array['tmp_name']); 
      echo 'error'; 
      die(); 
     } else { 
      if ($frames > 1) { 
       update_post_meta($attach_id, 'a_gif', 'yes'); 
      } 
     } 

     update_post_meta($attach_id, 'pinc_unattached', 'yes'); 

     $return = array(); 
     $thumbnail = wp_get_attachment_image_src($attach_id, 'medium'); 
     $return['thumbnail'] = $thumbnail[0]; 
     $return['id'] = $attach_id; 

     do_action('pinc_after_upload_pin_web', $attach_id); 
     echo json_encode($return); 
    } 
    exit; 
} 
+0

예 우선 순위를 높였지만 pinc_upload_pin_new() 함수는 새로운 함수에 exit를 넣었습니다. 문제가 무엇인지 호출하지 않습니다. – dhavald99

+0

콘솔에 오류가 있습니까? 아약스 전화가 걸리는 동안? – Yamu

+0

콘솔에 오류가 없습니다. 그리고 인쇄하고있는 media_handle_uplod에 $ _files를 인쇄했습니다.media_handle_uplod가 새로운 함수에 exit를 넣었 기 때문에 호출해서는 안됩니다. – dhavald99

0

위의 대답은 않을 경우 테마가 추가 한 액션 후크를 제거하는 대안적인 방법이 있습니다.

function wpso682524_remove_action() 
{ 
    //Remove the unwanted previous hook added by your theme. 
    remove_action('wp_ajax_pinc-upload-pin', 'pinc_upload_pin'); 

    //Now hook your new function to that hook. 
    add_action('wp_ajax_pinc-upload-pin', 'pinc_upload_pin_new',9); 
} 

add_action('after_setup_theme', 'wpso682524_remove_action');