FROM {$wpdb->prefix}posts
WHERE post_content LIKE '%<img%'
AND post_type = 'page'";
+ //$sql .= " AND ID = 1366";
$sql .= " AND ID IN (" . implode(',', $currentPostArray) . ")";
$results = $wpdb->get_results($sql, OBJECT);
if (count($results) > 0) {
$content = $post->post_content;
echo '<pre>Updating Media Src\'s: ' . print_r($post->post_title, true) . '</pre>';
echo '<div style="border: 1px solid green; padding: 9px; margin: 10px;">';
+ //echo '<pre>original: '.htmlspecialchars($content).'</pre>';
if (preg_match_all('%(:?\[caption [^\]]+\])?<img ([^>]+)>(:?([^\[]*)\[/caption\])?%', $content, $cMatch)) {
$captionCount = count($cMatch[0]);
//echo '<p>Matches in Caption ' . $captionCount . '</p>';
//echo '<pre>Caption Match: ' . print_r($cMatch[1][$index], true) . '</pre>';
//echo '<pre>Caption Text: ' . print_r($cMatch[2][$index], true) . '/End Caption Text</pre>';
if (preg_match('%src="([^"]+)"%', $cMatch[0][$index], $srcMatch)) {
- //echo '<pre>' . print_r($srcMatch, true) . '</pre>';
+ echo '<pre>' . print_r($srcMatch, true) . '</pre>';
//echo '<pre>Sub Src Match: ' . print_r($srcMatch[1], true) . '</pre>';
$fileInfo = pathinfo($srcMatch[1]);
$fileName = basename($srcMatch[1]);
//echo '<pre>'.var_dump($path).'</pre>';
$imagesKey = $this->_getAttachmentByName($fileBaseName);
- //var_dump($imagesKey);
+ var_dump($imagesKey);
+// echo '<pre>
+// $fileName: '.$fileName.'
+// $fileBaseName: '.$fileBaseName.'
+// $post->ID: '.$post->ID.'
+// $path: '.$path.'
+// </pre>';
if (!$imagesKey) {
$imagesKey = $this->_handleMediaFile(
$fileName,
$fileBaseName,
'',
$post->ID,
- $path
+ $path . '/'
);
}
+ var_dump($imagesKey);
+ //exit;
if ($imagesKey) {
var_dump($imagesKey);
$newImage = wp_get_attachment_image_src($imagesKey, 'medium');
// need to replace the src tags in content with the new image tags
$caption = str_replace(
'src="' . $srcMatch[1] . '"',
- 'src="' . $newImage[0] . '" width="' . $newImage[1] . '" height="' . $newImage[1] . '"',
+ 'src="' . $newImage[0] . '" width="' . $newImage[1] . '" height="' . $newImage[2] . '"',
$cMatch[0][$index]);
if (preg_match('%class="([^"]+)"%', $caption, $classMatch)) {
echo '<pre>First: '.print_r($classMatch).'</pre>';