Просмотр исходного кода

fixed Undefined offset: 0 - error in bones_getSocialimage()

Dominic Giglio 14 лет назад
Родитель
Сommit
09342541b7
1 измененных файлов с 12 добавлено и 8 удалено
  1. 12 8
      library/plugins.php

+ 12 - 8
library/plugins.php

@@ -28,19 +28,23 @@ out: http://yoast.com/facebook-open-graph-protocol/
 
 // get the image for the google + and facebook integration 
 function bones_get_socialimage() {
+  global $post, $posts;
+
   $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '', '' );
+
   if ( has_post_thumbnail($post->ID) ) {
     $socialimg = $src[0];
   } else {
-    global $post, $posts;
     $socialimg = '';
-    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i',
-    $post->post_content, $matches);
-    $socialimg = $matches [1] [0];
-  }
-  if(empty($socialimg)) {
-	$socialimg = get_template_directory_uri() . '/library/images/nothumb.gif';
+    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
+    if (array_key_exists(1, $matches))
+      if (array_key_exists(0, $matches[1]))
+        $socialimg = $matches [1] [0];
   }
+
+  if(empty($socialimg))
+    $socialimg = get_template_directory_uri() . '/library/images/nothumb.gif';
+
   return $socialimg;
 }
 
@@ -99,4 +103,4 @@ function bones_add_user_fields( $contactmethods ) {
 add_filter('user_contactmethods','bones_add_user_fields',10,1);
 
 
-?>
+?>