ID, 'broadnews-meta-image-options', true); $broadnews_post_class = !empty($broadnews_post_image_alignment) ? $broadnews_post_image_alignment : $broadnews_theme_class; if ($broadnews_post_class != 'no-image') : ?>
/i', $broadnews_post_content, $matches); if (isset($matches[1][0])) { $broadnews_img_id = broadnews_find_post_id_from_path($matches[1][0]); $broadnews_img_url = wp_get_attachment_image_src($broadnews_img_id, $broadnews_thumbnail_size); if (isset($broadnews_img_url[0])) if ($return) { $broadnews_img_html = wp_get_attachment_image($broadnews_img_id, $broadnews_thumbnail_size); return $broadnews_img_html; } else { echo wp_kses_post(wp_get_attachment_image($broadnews_img_id, $broadnews_thumbnail_size)); } } } } endif; /** * Find the post ID for a file PATH or URL * * @param string $path * * @return int */ function broadnews_find_post_id_from_path($path) { // detect if is a media resize, and strip resize portion of file name if (preg_match('/(-\d{1,4}x\d{1,4})\.(jpg|jpeg|png|gif)$/i', $path, $matches)) { $path = str_ireplace($matches[1], '', $path); } // process and include the year / month folders so WP function below finds properly if (preg_match('/uploads\/(\d{1,4}\/)?(\d{1,2}\/)?(.+)$/i', $path, $matches)) { unset($matches[0]); $path = implode('', $matches); } // at this point, $path contains the year/month/file name (without resize info) // call WP native function to find post ID properly return attachment_url_to_postid($path); }