fix: wp_get_attachment_image_src returns a false result

pull/620/head
Seaton Jiang 2023-04-05 21:32:39 +08:00
parent 89baae6198
commit b6fc9457e7
No known key found for this signature in database
GPG Key ID: B79682F6FE8D30E3
1 changed files with 3 additions and 2 deletions

View File

@ -4,7 +4,7 @@
* 站点相关函数 * 站点相关函数
* @author Seaton Jiang <hi@seatonjiang.com> * @author Seaton Jiang <hi@seatonjiang.com>
* @license GPL-3.0 License * @license GPL-3.0 License
* @version 2022.01.26 * @version 2023.04.05
*/ */
// 标题配置 // 标题配置
@ -109,8 +109,9 @@ function share_thumbnail_url()
return; return;
if (has_post_thumbnail($post->ID)) { if (has_post_thumbnail($post->ID)) {
$post_thumbnail_id = get_post_thumbnail_id($post); $post_thumbnail_id = get_post_thumbnail_id($post);
// Return array|false Array of image data, or boolean false if no image is available.
$img = wp_get_attachment_image_src($post_thumbnail_id, 'full'); $img = wp_get_attachment_image_src($post_thumbnail_id, 'full');
$img = $img[0]; $img && $img = $img[0];
} else { } else {
$content = $post->post_content; $content = $post->post_content;
preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?); ?>/sim', $content, $strResult, PREG_PATTERN_ORDER); preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?); ?>/sim', $content, $strResult, PREG_PATTERN_ORDER);