2012-11-06 3 views
1

WordPress 플러그인에서 실행되는 기능이 있으며 wp_debug가 활성화되면이 오류 메시지가 나타납니다."정의되지 않은 오프셋 : 0 인치"오류 메시지를 방지하고 수정하는 방법

"불확정 오프셋 : 0 /.../wp-content/plugins/advanced-widget-pack/lib/advanced_widget_pack.class.php 선에 568는"여기

가에서 사용되는 함수 플러그인 : 나는 어떻게 확실하지 않다

$first_img = $matches[1][0]; 

:

/** 
* Retrieves the image for a post 
* 
* Uses the post_thumbnails if available or 
* searches through the post and retrieves the first found image for use as thumbnails 
*/ 
function featured_image_thumb($size = 50) { 
    global $post; 
    // If a featured image has been set, use the featured-thumbnail size that was set above with the class of 'thumb' 
    if(has_post_thumbnail()) { 
     echo '<a href="'.get_permalink().'" title="'.get_the_title().'" >'; 
     the_post_thumbnail(array($size,$size),array('class' => 'thumb')); 
     echo '</a>'; 
    } 
    // If a featured image is not set, get the first image in the post content 
    else { 
     $first_img = ''; 
     ob_start(); 
     ob_end_clean(); 
     $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); 
     $first_img = $matches[1][0]; 

     // Define a default fallback image in case a featured image is not set and there are no images in the post content 
     if(empty($first_img)){ 
      $first_img = WP_PLUGIN_URL.'/advanced-widget-pack/images/nothumb.png'; 
     } 

     // Generate the HTML code to display the image and resize the image with timthumb.php 
     return '<a title="'.get_the_title().'" href="'.get_permalink().'"><img class="thumb" src="'.WP_PLUGIN_URL.'/advanced-widget-pack/timthumb.php?src=' . $first_img .'&w='.$size.'&h='.$size.'" alt="" /></a>'; 
    } 
} 

라인 (568) 또는 오류가 발생하는 장소는 코드 섹션입니다 이 오류를 방지하거나 수정하십시오.

도움이나 조언을 주시면 감사하겠습니다. 감사합니다.

+0

$ 일치 :

는 당신이 조건부를 사용하는 것 같아요? – loQ

답변

0

위의 preg_match가 아무 것도 찾지 못했기 때문에 배열의 첫 번째 색인이 prob로 정의되지 않았 음을 의미합니다. 당신은 정말 그것에 대해 걱정할 필요가 야해하지만 다음과 퍼팅 위해서는 ob_end_clean은 내 경우

$matches[1][0] = ''; 
+0

앤드류 감사합니다. – Jason

1

을주의해야 후 조건과 포용 나를 위해 그것을했다 :

if($output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);) 

모든주의 사항은 지나간! :)

2

정의되지 않은 오프셋 $ X [Y]는 배열 X에 키 Y가 없음을 의미합니다. $ matches [1]에는 첫 번째 요소가 없습니다. 모든 가치가 나던

if(preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches)){ 
    $first_img = $matches[1][0]; 
} 
관련 문제