Changeset 24548
- Timestamp:
- 07/03/2013 08:23:48 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/media.php
r24547 r24548 1386 1386 $dimensions .= sprintf( 'width="%d" ', (int) $rawattr['width'] ); 1387 1387 $dimensions .= sprintf( 'height="%d" ', (int) $rawattr['height'] ); 1388 } elseif ( strstr( $url, home_url() ) ) { 1389 $id = attachment_url_to_postid( $url ); 1390 if ( ! empty( $id ) ) { 1391 $meta = wp_get_attachment_metadata( $id ); 1392 if ( ! empty( $meta['width'] ) ) 1393 $dimensions .= sprintf( 'width="%d" ', (int) $meta['width'] ); 1394 if ( ! empty( $meta['height'] ) ) 1395 $dimensions .= sprintf( 'height="%d" ', (int) $meta['height'] ); 1396 } 1397 } 1398 1388 } 1399 1389 $video = sprintf( '[video %s src="%s" /]', $dimensions, esc_url( $url ) ); 1400 1390 return apply_filters( 'wp_embed_handler_video', $video, $attr, $url, $rawattr ); … … 2489 2479 2490 2480 /** 2491 * Retrieve the post id for an attachment file URL2492 *2493 * @since 3.6.02494 *2495 * @param string $url Permalink to check.2496 * @return int Post ID, or 0 on failure.2497 */2498 function attachment_url_to_postid( $url ) {2499 global $wpdb;2500 if ( preg_match( '#\.[a-zA-Z0-9]+$#', $url ) ) {2501 $id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' " .2502 "AND guid = %s", $url ) );2503 2504 if ( ! empty( $id ) )2505 return (int) $id;2506 }2507 2508 return 0;2509 }2510 2511 /**2512 2481 * Retrieve the attachment post id from HTML containing an image. 2513 2482 * … … 2527 2496 $matched_html = $matches[0]; 2528 2497 2529 // Look for attributes.2530 if ( ! preg_match _all( '#(src|class)=([\'"])(.+?)\2#is', $matched_html, $matches ) || empty( $matches ) )2498 // Look for the class attribute. 2499 if ( ! preg_match( '#class=([\'"])(.+?)\1#is', $matched_html, $matches ) || empty( $matches ) ) 2531 2500 return $attachment_id; 2532 2501 2533 $attr = array(); 2534 foreach ( $matches[1] as $key => $attribute_name ) 2535 $attr[ $attribute_name ] = $matches[3][ $key ]; 2536 2537 if ( ! empty( $attr['class'] ) && false !== strpos( $attr['class'], 'wp-image-' ) ) 2538 if ( preg_match( '#wp-image-([0-9]+)#i', $attr['class'], $matches ) ) 2502 $classes = $matches[2]; 2503 if ( ! empty( $classes ) && false !== strpos( $classes, 'wp-image-' ) ) 2504 if ( preg_match( '#wp-image-([0-9]+)#i', $classes, $matches ) ) 2539 2505 $attachment_id = absint( $matches[1] ); 2540 2506 2541 if ( ! $attachment_id && ! empty( $attr['src'] ) )2542 $attachment_id = attachment_url_to_postid( $attr['src'] );2543 2544 2507 return $attachment_id; 2545 2508 }
Note: See TracChangeset
for help on using the changeset viewer.