WordPressを読む 36-7 /blog/wp-includes/link-template.php 7
2014/12/18
目次
/blog/wp-includes/link-template.php 7
関数 get_dashboard_url()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | /** * Get the URL to the user's dashboard. * * If a user does not belong to any site, the global user dashboard is used. If the user belongs to the current site, * the dashboard for the current site is returned. If the user cannot edit the current site, the dashboard to the user's * primary blog is returned. * * @since 3.1.0 * * @param int $user_id Optional. User ID. Defaults to current user. * @param string $path Optional path relative to the dashboard. Use only paths known to both blog and user admins. * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. * @return string Dashboard url link with optional path appended. */ function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) { $user_id = $user_id ? (int) $user_id : get_current_user_id(); $blogs = get_blogs_of_user( $user_id ); if ( ! is_super_admin() && empty($blogs) ) { $url = user_admin_url( $path, $scheme ); } elseif ( ! is_multisite() ) { $url = admin_url( $path, $scheme ); } else { $current_blog = get_current_blog_id(); if ( $current_blog && ( is_super_admin( $user_id ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) { $url = admin_url( $path, $scheme ); } else { $active = get_active_blog_for_user( $user_id ); if ( $active ) $url = get_admin_url( $active->blog_id, $path, $scheme ); else $url = user_admin_url( $path, $scheme ); } } /** * Filter the dashboard URL for a user. * * @since 3.1.0 * * @param string $url The complete URL including scheme and path. * @param int $user_id The user ID. * @param string $path Path relative to the URL. Blank string if no path is specified. * @param string $scheme Scheme to give the URL context. Accepts 'http', 'https', 'login', * 'login_post', 'admin', 'relative' or null. */ return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme); } |
関数 get_edit_profile_url()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | /** * Get the URL to the user's profile editor. * * @since 3.1.0 * * @param int $user_id Optional. User ID. Defaults to current user. * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). * 'http' or 'https' can be passed to force those schemes. * @return string Dashboard url link with optional path appended. */ function get_edit_profile_url( $user_id = 0, $scheme = 'admin' ) { $user_id = $user_id ? (int) $user_id : get_current_user_id(); if ( is_user_admin() ) $url = user_admin_url( 'profile.php', $scheme ); elseif ( is_network_admin() ) $url = network_admin_url( 'profile.php', $scheme ); else $url = get_dashboard_url( $user_id, 'profile.php', $scheme ); /** * Filter the URL for a user's profile editor. * * @since 3.1.0 * * @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); } |
関数 rel_canonical()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /** * Output rel=canonical for singular queries. * * @since 2.9.0 */ function rel_canonical() { if ( !is_singular() ) return; global $wp_the_query; if ( !$id = $wp_the_query->get_queried_object_id() ) return; $link = get_permalink( $id ); if ( $page = get_query_var('cpage') ) $link = get_comments_pagenum_link( $page ); echo "<link rel='canonical' href='$link' />\n"; } |
関数 wp_get_shortlink()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | /** * Return a shortlink for a post, page, attachment, or blog. * * 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 pre_get_shortlink filter or filter the output * via the get_shortlink filter. * * @since 3.0.0. * * @param int $id A post or blog id. Default is 0, which means the current post or blog. * @param string $context Whether the id is a 'blog' 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 is 'post'. * @param bool $allow_slugs Whether to allow post slugs in the shortlink. It is up to the plugin how and whether to honor this. * @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks are not enabled. */ function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) { /** * Filter whether to preempt generating a shortlink for the given post. * * Passing a truthy value to the filter will effectively short-circuit the * shortlink-generation process, returning that value instead. * * @since 3.0.0 * * @param bool|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 ) return $shortlink; global $wp_query; $post_id = 0; if ( 'query' == $context && is_singular() ) { $post_id = $wp_query->get_queried_object_id(); $post = get_post( $post_id ); } elseif ( 'post' == $context ) { $post = get_post( $id ); if ( ! empty( $post->ID ) ) $post_id = $post->ID; } $shortlink = ''; // 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 && $post->ID == get_option( 'page_on_front' ) && 'page' == get_option( 'show_on_front' ) ) { $shortlink = home_url( '/' ); } elseif ( $post_type->public ) { $shortlink = home_url( '?p=' . $post_id ); } } /** * Filter the shortlink for a post. * * @since 3.0.0 * * @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 ); } |
関数 wp_shortlink_wp_head()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /** * Inject rel=shortlink into head if a shortlink is defined for the current page. * * Attached to the wp_head action. * * @since 3.0.0 * * @uses wp_get_shortlink() */ function wp_shortlink_wp_head() { $shortlink = wp_get_shortlink( 0, 'query' ); if ( empty( $shortlink ) ) return; echo "<link rel='shortlink' href='" . esc_url( $shortlink ) . "' />\n"; } |
関数 wp_shortlink_header()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /** * Send a Link: rel=shortlink header if a shortlink is defined for the current page. * * Attached to the wp action. * * @since 3.0.0 * * @uses wp_get_shortlink() */ function wp_shortlink_header() { if ( headers_sent() ) return; $shortlink = wp_get_shortlink(0, 'query'); if ( empty($shortlink) ) return; header('Link: <' . $shortlink . '>; rel=shortlink', false); } |
関数 the_shortlink()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | /** * Display the Short Link for a Post * * Must be called from inside "The Loop" * * Call like the_shortlink(__('Shortlinkage FTW')) * * @since 3.0.0 * * @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. * @param string $after Optional HTML to display after the link. */ function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) { $post = get_post(); if ( empty( $text ) ) $text = __('This is the short link.'); if ( empty( $title ) ) $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>'; /** * Filter the shortlink anchor tag for a post. * * @since 3.0.0 * * @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; } } |