Forum Replies Created

Viewing 1 replies (of 1 total)
  • Hi, it seems that when a author is adding an image a different img tag is generated then when a admin does this.
    The difference is the admin has a title=”{text}” tag, and a author has not.

    author generates:
    <img class=”alignnone size-medium wp-image-42″ src=”http://www.vragen.org/wp-content/uploads/2009/10/antwoorden-300×225.jpg&#8221; alt=”antwoorden” width=”300″ height=”225″ />

    admin generates:
    <img class=”alignnone size-medium wp-image-42″ title=”antwoorden” src=”http://www.vragen.org/wp-content/uploads/2009/10/antwoorden-300×225.jpg&#8221; alt=”antwoorden” width=”300″ height=”225″ />

    I’ve changed the function to the following

    function get_post_image ($post_id=0, $width=0, $height=0, $img_script='') {
    	global $wpdb;
    	if($post_id > 0) {
    
    		 // select the post content from the db
    
    		 $sql = 'SELECT post_content FROM ' . $wpdb->posts . ' WHERE id = ' . $wpdb->escape($post_id);
    		 $row = $wpdb->get_row($sql);
    		 $the_content = $row->post_content;
    		 if(strlen($the_content)) {
    
    			  // use regex to find the src of the image
    
    			preg_match("/<img src\=('|\")(.*)('|\") .*( |)\/>/", $the_content, $matches);
    			if(!$matches) {
    				preg_match("/<img class\=\".*\" title\=\".*\" src\=('|\")(.*)('|\") .*( |)\/>/U", $the_content, $matches);
    			}
    			if(!$matches) {
    				preg_match("/<img class\=\".*\" src\=('|\")(.*)('|\") .*( |)\/>/U", $the_content, $matches);
    			}
                            $the_image = '';
                            $the_image_src = $matches[2];
    			$frags = preg_split("/(\"|')/", $the_image_src);
    			if(count($frags)) {
    				$the_image_src = $frags[0];
    			}
    
    			  // if src found, then create a new img tag
    
    			  if(strlen($the_image_src)) {
    				   if(strlen($img_script)) {
    
    					    // if the src starts with http/https, then strip out server name
    
    					    if(preg_match("/^(http(|s):\/\/)/", $the_image_src)) {
    						     $the_image_src = preg_replace("/^(http(|s):\/\/)/", '', $the_image_src);
    						     $frags = split("\/", $the_image_src);
    						     array_shift($frags);
    						     $the_image_src = '/' . join("/", $frags);
    					    }
    					    $the_image = '<img alt="" src="' . $img_script . $the_image_src . '" />';
    				   }
    				   else {
    					    $the_image = '<img alt="" src="' . $the_image_src . '" width="' . $width . '" height="' . $height . '" />';
    				   }
    			  }
    			  return $the_image;
    		 }
    	}
    }
Viewing 1 replies (of 1 total)