Last active
September 8, 2019 14:33
-
-
Save pfefferle/db0dc8f1001292d72a8daa8a21baa142 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function webmention_url_to_postid( $url ) { | |
$id = wp_cache_get( base64_encode( $url ), 'webmention_url_to_postid' ); | |
if ( $id ) { | |
return apply_filters( 'webmention_post_id', $id, $url ); | |
} | |
if ( '/' === wp_make_link_relative( trailingslashit( $url ) ) ) { | |
return apply_filters( 'webmention_post_id', get_option( 'webmention_home_mentions' ), $url ); | |
} | |
$id = url_to_postid( $url ); | |
if ( ! $id && post_type_supports( 'attachment', 'webmentions' ) ) { | |
$ext = pathinfo( wp_parse_url( $url, PHP_URL_PATH ), PATHINFO_EXTENSION ); | |
if ( ! empty( $ext ) ) { | |
$id = attachment_url_to_postid( $url ); | |
} | |
} | |
wp_cache_set( base64_encode( $url ), $id, 'webmention_url_to_postid', 300 ); | |
return apply_filters( 'webmention_post_id', $id, $url ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment