_fix_attachment_links [ WordPress Function ]
_fix_attachment_links ( $post_ID )
| Access: |
|
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Benzer Fonksiyonlar: the_attachment_links, the_attachment_link, get_attachment_link, wp_get_attachment_link, get_the_attachment_link
Replace hrefs of attachment anchors with up-to-date permalinks.
Source
<?php
function _fix_attachment_links( $post_ID ) {
$post = & get_post( $post_ID, ARRAY_A );
$content = $post['post_content'];
// quick sanity check, don't run if no pretty permalinks or post is not published
if ( !get_option('permalink_structure') || $post['post_status'] != 'publish' )
return;
// Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero)
if ( !strpos($content, '?attachment_id=') || !preg_match_all( '/<a ([^>]+)>[\s\S]+?<\/a>/', $content, $link_matches ) )
return;
$site_url = get_bloginfo('url');
$site_url = substr( $site_url, (int) strpos($site_url, '://') ); // remove the http(s)
$replace = '';
foreach ( $link_matches[1] as $key => $value ) {
if ( !strpos($value, '?attachment_id=') || !strpos($value, 'wp-att-')
|| !preg_match( '/href=(["\'])[^"\']*\?attachment_id=(\d+)[^"\']*\\1/', $value, $url_match )
|| !preg_match( '/rel=["\'][^"\']*wp-att-(\d+)/', $value, $rel_match ) )
continue;
$quote = $url_match[1]; // the quote (single or double)
$url_id = (int) $url_match[2];
$rel_id = (int) $rel_match[1];
if ( !$url_id || !$rel_id || $url_id != $rel_id || strpos($url_match[0], $site_url) === false )
continue;
$link = $link_matches[0][$key];
$replace = str_replace( $url_match[0], 'href=' . $quote . get_attachment_link( $url_id ) . $quote, $link );
$content = str_replace( $link, $replace, $content );
}
if ( $replace ) {
$post['post_content'] = $content;
// Escape data pulled from DB.
$post = add_magic_quotes($post);
return wp_update_post($post);
}
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- _fix_attachment_links() WordPress function reference, arguments ...
Replace hrefs of attachment anchors with up-to-date permalinks.
queryposts.com - #8689 (WordPress must not use preg_replace with /e) – WordPress ...
WordPress 2.8.4 violates this again in /wp-admin/includes/post.php around line 6800 in function _fix_attachment_links(). Please don't re-open tickets fixed in old ...
core.trac.wordpress.org - Ticket #13429 - WordPress Trac
It seems that the problem for which _fix_attachment_links() was introduced doesn 't exist ... Overall removing _fix_attachment_links() seems the proper solution.
core.trac.wordpress.org - PHPXRef 0.7 : WordPress : Detail view of post.php
update_meta() _fix_attachment_links() _relocate_children() ...
phpxref.ftwr.co.uk