: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$user_id = $user_id ? (int) $user_id : get_current_user_id();
$url = user_admin_url( 'profile.php', $scheme );
} elseif ( is_network_admin() ) {
$url = network_admin_url( 'profile.php', $scheme );
$url = get_dashboard_url( $user_id, 'profile.php', $scheme );
* Filters the URL for a user's profile editor.
* @param string $url The complete URL including scheme and path.
* @param int $user_id The user ID.
* @param string $scheme Scheme to give the URL context. Accepts 'http', 'https', 'login',
* 'login_post', 'admin', 'relative' or null.
return apply_filters( 'edit_profile_url', $url, $user_id, $scheme );
* Returns the canonical URL for a post.
* When the post is the same as the current requested page the function will handle the
* pagination arguments too.
* @param int|WP_Post $post Optional. Post ID or object. Default is global `$post`.
* @return string|false The canonical URL. False if the post does not exist
* or has not been published yet.
function wp_get_canonical_url( $post = null ) {
$post = get_post( $post );
if ( 'publish' !== $post->post_status ) {
$canonical_url = get_permalink( $post );
// If a canonical is being generated for the current page, make sure it has pagination if needed.
if ( get_queried_object_id() === $post->ID ) {
$page = get_query_var( 'page', 0 );
if ( ! get_option( 'permalink_structure' ) ) {
$canonical_url = add_query_arg( 'page', $page, $canonical_url );
$canonical_url = trailingslashit( $canonical_url ) . user_trailingslashit( $page, 'single_paged' );
$cpage = get_query_var( 'cpage', 0 );
$canonical_url = get_comments_pagenum_link( $cpage );
* Filters the canonical URL for a post.
* @param string $canonical_url The post's canonical URL.
* @param WP_Post $post Post object.
return apply_filters( 'get_canonical_url', $canonical_url, $post );
* Outputs rel=canonical for singular queries.
* @since 4.6.0 Adjusted to use `wp_get_canonical_url()`.
function rel_canonical() {
$id = get_queried_object_id();
$url = wp_get_canonical_url( $id );
echo '<link rel="canonical" href="' . esc_url( $url ) . '" />' . "\n";
* Returns a shortlink for a post, page, attachment, or site.
* This function exists to provide a shortlink tag that all themes and plugins can target.
* A plugin must hook in to provide the actual shortlinks. Default shortlink support is
* limited to providing ?p= style links for posts. Plugins can short-circuit this function
* via the {@see 'pre_get_shortlink'} filter or filter the output via the {@see 'get_shortlink'}
* @param int $id Optional. A post or site ID. Default is 0, which means the current post or site.
* @param string $context Optional. Whether the ID is a 'site' ID, 'post' ID, or 'media' ID. If 'post',
* the post_type of the post is consulted. If 'query', the current query is consulted
* to determine the ID and context. Default 'post'.
* @param bool $allow_slugs Optional. Whether to allow post slugs in the shortlink. It is up to the plugin how
* and whether to honor this. Default true.
* @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks
function wp_get_shortlink( $id = 0, $context = 'post', $allow_slugs = true ) {
* Filters whether to preempt generating a shortlink for the given post.
* Returning a value other than false from the filter will short-circuit
* the shortlink generation process, returning that value instead.
* @param false|string $return Short-circuit return value. Either false or a URL string.
* @param int $id Post ID, or 0 for the current post.
* @param string $context The context for the link. One of 'post' or 'query',
* @param bool $allow_slugs Whether to allow post slugs in the shortlink.
$shortlink = apply_filters( 'pre_get_shortlink', false, $id, $context, $allow_slugs );
if ( false !== $shortlink ) {
if ( 'query' === $context && is_singular() ) {
$post_id = get_queried_object_id();
$post = get_post( $post_id );
} elseif ( 'post' === $context ) {
if ( ! empty( $post->ID ) ) {
// Return `?p=` link for all public post types.
if ( ! empty( $post_id ) ) {
$post_type = get_post_type_object( $post->post_type );
if ( 'page' === $post->post_type
&& 'page' === get_option( 'show_on_front' ) && (int) get_option( 'page_on_front' ) === $post->ID
$shortlink = home_url( '/' );
} elseif ( $post_type && $post_type->public ) {
$shortlink = home_url( '?p=' . $post_id );
* Filters the shortlink for a post.
* @param string $shortlink Shortlink URL.
* @param int $id Post ID, or 0 for the current post.
* @param string $context The context for the link. One of 'post' or 'query',
* @param bool $allow_slugs Whether to allow post slugs in the shortlink. Not used by default.
return apply_filters( 'get_shortlink', $shortlink, $id, $context, $allow_slugs );
* Injects rel=shortlink into the head if a shortlink is defined for the current page.
* Attached to the {@see 'wp_head'} action.
function wp_shortlink_wp_head() {
$shortlink = wp_get_shortlink( 0, 'query' );
if ( empty( $shortlink ) ) {
echo "<link rel='shortlink' href='" . esc_url( $shortlink ) . "' />\n";
* Sends a Link: rel=shortlink header if a shortlink is defined for the current page.
* Attached to the {@see 'wp'} action.
function wp_shortlink_header() {
$shortlink = wp_get_shortlink( 0, 'query' );
if ( empty( $shortlink ) ) {
header( 'Link: <' . $shortlink . '>; rel=shortlink', false );
* Displays the shortlink for a post.
* Must be called from inside "The Loop"
* Call like the_shortlink( __( 'Shortlinkage FTW' ) )
* @param string $text Optional The link text or HTML to be displayed. Defaults to 'This is the short link.'
* @param string $title Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.
* @param string $before Optional HTML to display before the link. Default empty.
* @param string $after Optional HTML to display after the link. Default empty.
function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
$text = __( 'This is the short link.' );
$title = the_title_attribute( array( 'echo' => false ) );
$shortlink = wp_get_shortlink( $post->ID );
if ( ! empty( $shortlink ) ) {
$link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>';
* Filters the short link anchor tag for a post.
* @param string $link Shortlink anchor tag.
* @param string $shortlink Shortlink URL.
* @param string $text Shortlink's text.
* @param string $title Shortlink's title attribute.
$link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title );
echo $before, $link, $after;
* Retrieves the avatar URL.
* @param mixed $id_or_email The avatar to retrieve a URL for. Accepts a user ID, Gravatar MD5 hash,
* user email, WP_User object, WP_Post object, or WP_Comment object.
* Optional. Arguments to use instead of the default arguments.
* @type int $size Height and width of the avatar in pixels. Default 96.
* @type string $default URL for the default image or a default type. Accepts:
* - '404' (return a 404 instead of a default image)
* - 'retro' (a 8-bit arcade-style pixelated face)
* - 'monsterid' (a monster)
* - 'wavatar' (a cartoon face)
* - 'identicon' (the "quilt", a geometric pattern)
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man)
* - 'blank' (transparent GIF)
* - 'gravatar_default' (the Gravatar logo)
* Default is the value of the 'avatar_default' option,
* with a fallback of 'mystery'.
* @type bool $force_default Whether to always show the default image, never the Gravatar.
* @type string $rating What rating to display avatars up to. Accepts:
* - 'G' (suitable for all audiences)
* - 'PG' (possibly offensive, usually for audiences 13 and above)
* - 'R' (intended for adult audiences above 17)
* - 'X' (even more mature than above)
* Default is the value of the 'avatar_rating' option.
* @type string $scheme URL scheme to use. See set_url_scheme() for accepted values.
* @type array $processed_args When the function returns, the value will be the processed/sanitized $args
* plus a "found_avatar" guess. Pass as a reference. Default null.
* @return string|false The URL of the avatar on success, false on failure.
function get_avatar_url( $id_or_email, $args = null ) {
$args = get_avatar_data( $id_or_email, $args );
* Check if this comment type allows avatars to be retrieved.
* @param string $comment_type Comment type to check.
* @return bool Whether the comment type is allowed for retrieving avatars.
function is_avatar_comment_type( $comment_type ) {
* Filters the list of allowed comment types for retrieving avatars.
* @param array $types An array of content types. Default only contains 'comment'.
$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
return in_array( $comment_type, (array) $allowed_comment_types, true );
* Retrieves default data about the avatar.
* @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
* user email, WP_User object, WP_Post object, or WP_Comment object.
* Optional. Arguments to use instead of the default arguments.
* @type int $size Height and width of the avatar in pixels. Default 96.
* @type int $height Display height of the avatar in pixels. Defaults to $size.
* @type int $width Display width of the avatar in pixels. Defaults to $size.
* @type string $default URL for the default image or a default type. Accepts:
* - '404' (return a 404 instead of a default image)
* - 'retro' (a 8-bit arcade-style pixelated face)
* - 'monsterid' (a monster)
* - 'wavatar' (a cartoon face)
* - 'identicon' (the "quilt", a geometric pattern)
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man)
* - 'blank' (transparent GIF)
* - 'gravatar_default' (the Gravatar logo)
* Default is the value of the 'avatar_default' option,
* with a fallback of 'mystery'.
* @type bool $force_default Whether to always show the default image, never the Gravatar.
* @type string $rating What rating to display avatars up to. Accepts:
* - 'G' (suitable for all audiences)
* - 'PG' (possibly offensive, usually for audiences 13 and above)
* - 'R' (intended for adult audiences above 17)
* - 'X' (even more mature than above)
* Default is the value of the 'avatar_rating' option.
* @type string $scheme URL scheme to use. See set_url_scheme() for accepted values.
* @type array $processed_args When the function returns, the value will be the processed/sanitized $args
* plus a "found_avatar" guess. Pass as a reference. Default null.
* @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized.
* Along with the arguments passed in `$args`, this will contain a couple of extra arguments.
* @type bool $found_avatar True if an avatar was found for this user,
* false or not set if none was found.
* @type string|false $url The URL of the avatar that was found, or false.
function get_avatar_data( $id_or_email, $args = null ) {
'default' => get_option( 'avatar_default', 'mystery' ),
'force_default' => false,
'rating' => get_option( 'avatar_rating' ),
'processed_args' => null, // If used, should be a reference.
if ( is_numeric( $args['size'] ) ) {
$args['size'] = absint( $args['size'] );
if ( is_numeric( $args['height'] ) ) {
$args['height'] = absint( $args['height'] );
if ( ! $args['height'] ) {
$args['height'] = $args['size'];
$args['height'] = $args['size'];
if ( is_numeric( $args['width'] ) ) {
$args['width'] = absint( $args['width'] );
if ( ! $args['width'] ) {
$args['width'] = $args['size'];
$args['width'] = $args['size'];
if ( empty( $args['default'] ) ) {
$args['default'] = get_option( 'avatar_default', 'mystery' );
switch ( $args['default'] ) {
$args['default'] = false;
$args['force_default'] = (bool) $args['force_default'];
$args['rating'] = strtolower( $args['rating'] );
$args['found_avatar'] = false;
* Filters whether to retrieve the avatar URL early.
* Passing a non-null value in the 'url' member of the return array will
* effectively short circuit get_avatar_data(), passing the value through
* the {@see 'get_avatar_data'} filter and returning early.
* @param array $args Arguments passed to get_avatar_data(), after processing.
* @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
* user email, WP_User object, WP_Post object, or WP_Comment object.
$args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email );
if ( isset( $args['url'] ) ) {
/** This filter is documented in wp-includes/link-template.php */
return apply_filters( 'get_avatar_data', $args, $id_or_email );
if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) {
$id_or_email = get_comment( $id_or_email );
// Process the user identifier.
if ( is_numeric( $id_or_email ) ) {
$user = get_user_by( 'id', absint( $id_or_email ) );
} elseif ( is_string( $id_or_email ) ) {
if ( str_contains( $id_or_email, '@md5.gravatar.com' ) ) {
list( $email_hash ) = explode( '@', $id_or_email );
} elseif ( $id_or_email instanceof WP_User ) {
} elseif ( $id_or_email instanceof WP_Post ) {
$user = get_user_by( 'id', (int) $id_or_email->post_author );
} elseif ( $id_or_email instanceof WP_Comment ) {
if ( ! is_avatar_comment_type( get_comment_type( $id_or_email ) ) ) {
/** This filter is documented in wp-includes/link-template.php */
return apply_filters( 'get_avatar_data', $args, $id_or_email );
if ( ! empty( $id_or_email->user_id ) ) {
$user = get_user_by( 'id', (int) $id_or_email->user_id );
if ( ( ! $user || is_wp_error( $user ) ) && ! empty( $id_or_email->comment_author_email ) ) {
$email = $id_or_email->comment_author_email;