WordPressを読む 39-4 /blog/wp-includes/post-template.php 4
2015/01/07
目次
- 1 /blog/wp-includes/post-template.php 4
- 2 クラス Walker_PageDropdown::クラス変数
- 3 クラス Walker_PageDropdown::start_el()
- 4 関数 the_attachment_link()
- 5 関数 wp_get_attachment_link()
- 6 関数 prepend_attachment()
- 7 関数 get_the_password_form()
- 8 関数 is_page_template()
- 9 関数 get_page_template_slug()
- 10 関数 wp_post_revision_title()
- 11 関数 wp_post_revision_title_expanded()
- 12 関数 wp_list_post_revisions()
/blog/wp-includes/post-template.php 4
クラス Walker_PageDropdown::クラス変数
継承元::Walker /blog/wp-includes/class-wp-walker.php
クラス Walker::
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 | /** * Create HTML dropdown list of pages. * * @since 2.1.0 * @uses Walker */ class Walker_PageDropdown extends Walker { /** * @see Walker::$tree_type * @since 2.1.0 * @var string */ public $tree_type = 'page'; /** * @see Walker::$db_fields * @since 2.1.0 * @todo Decouple this * @var array */ public $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); /** * @see Walker::start_el() * @since 2.1.0 * * @param string $output Passed by reference. Used to append additional content. * @param object $page Page data object. * @param int $depth Depth of page in reference to parent pages. Used for padding. * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element. * @param int $id */ |
クラス Walker_PageDropdown::start_el()
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 | public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) { $pad = str_repeat(' ', $depth * 3); $output .= "\t<option class=\"level-$depth\" value=\"$page->ID\""; if ( $page->ID == $args['selected'] ) $output .= ' selected="selected"'; $output .= '>'; $title = $page->post_title; if ( '' === $title ) { $title = sprintf( __( '#%d (no title)' ), $page->ID ); } /** * Filter the page title when creating an HTML drop-down list of pages. * * @since 3.1.0 * * @param string $title Page title. * @param object $page Page data object. */ $title = apply_filters( 'list_pages', $title, $page ); $output .= $pad . esc_html( $title ); $output .= "</option>\n"; } } |
関数 the_attachment_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | // // Attachments // /** * Display an attachment page link using an image or icon. * * @since 2.0.0 * * @param int|WP_Post $id Optional. Post ID or post object. * @param bool $fullsize Optional, default is false. Whether to use full size. * @param bool $deprecated Deprecated. Not used. * @param bool $permalink Optional, default is false. Whether to include permalink. */ function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) { if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, '2.5' ); if ( $fullsize ) echo wp_get_attachment_link($id, 'full', $permalink); else echo wp_get_attachment_link($id, 'thumbnail', $permalink); } |
関数 wp_get_attachment_link()
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 | /** * Retrieve an attachment page link using an image or icon, if possible. * * @since 2.5.0 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function. * * @param int|WP_Post $id Optional. Post ID or post object. * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. * @param bool $permalink Optional, default is false. Whether to add permalink to image. * @param bool $icon Optional, default is false. Whether to include icon. * @param string|bool $text Optional, default is false. If string, then will be link text. * @return string HTML content. */ function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) { $id = intval( $id ); $_post = get_post( $id ); if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) return __( 'Missing Attachment' ); if ( $permalink ) $url = get_attachment_link( $_post->ID ); if ( $text ) $link_text = $text; elseif ( $size && 'none' != $size ) $link_text = wp_get_attachment_image( $id, $size, $icon ); else $link_text = ''; if ( trim( $link_text ) == '' ) $link_text = $_post->post_title; /** * Filter a retrieved attachment page link. * * @since 2.7.0 * * @param string $link_html The page link HTML output. * @param int $id Post ID. * @param string $size Image size. Default 'thumbnail'. * @param bool $permalink Whether to add permalink to image. Default false. * @param bool $icon Whether to include an icon. Default false. * @param string|bool $text If string, will be link text. Default false. */ return apply_filters( 'wp_get_attachment_link', "<a href='$url'>$link_text</a>", $id, $size, $permalink, $icon, $text ); } |
関数 prepend_attachment()
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 | /** * Wrap attachment in <<p>> element before content. * * @since 2.0.0 * * @param string $content * @return string */ function prepend_attachment($content) { $post = get_post(); if ( empty($post->post_type) || $post->post_type != 'attachment' ) return $content; if ( 0 === strpos( $post->post_mime_type, 'video' ) ) { $meta = wp_get_attachment_metadata( get_the_ID() ); $atts = array( 'src' => wp_get_attachment_url() ); if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) { $atts['width'] = (int) $meta['width']; $atts['height'] = (int) $meta['height']; } if ( has_post_thumbnail() ) { $atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() ); } $p = wp_video_shortcode( $atts ); } elseif ( 0 === strpos( $post->post_mime_type, 'audio' ) ) { $p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) ); } else { $p = '<p class="attachment">'; // show the medium sized image representation of the attachment if available, and link to the raw file $p .= wp_get_attachment_link(0, 'medium', false); $p .= '</p>'; } /** * Filter the attachment markup to be prepended to the post content. * * @since 2.0.0 * * @see prepend_attachment() * * @param string $p The attachment HTML output. */ $p = apply_filters( 'prepend_attachment', $p ); return "$p\n$content"; } |
関数 get_the_password_form()
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 | // // Misc // /** * Retrieve protected post password form content. * * @since 1.0.0 * * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. * @return string HTML content for password form for password protected post. */ function get_the_password_form( $post = 0 ) { $post = get_post( $post ); $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID ); $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post"> <p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p> <p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__( 'Submit' ) . '" /></p></form> '; /** * Filter the HTML output for the protected post password form. * * If modifying the password field, please note that the core database schema * limits the password field to 20 characters regardless of the value of the * size attribute in the form input. * * @since 2.7.0 * * @param string $output The password form HTML output. */ return apply_filters( 'the_password_form', $output ); } |
関数 is_page_template()
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 | /** * Whether currently in a page template. * * This template tag allows you to determine if you are in a page template. * You can optionally provide a template name and then the check will be * specific to that template. * * @since 2.5.0 * @uses $wp_query * * @param string $template The specific template name if specific matching is required. * @return bool True on success, false on failure. */ function is_page_template( $template = '' ) { if ( ! is_page() ) return false; $page_template = get_page_template_slug( get_queried_object_id() ); if ( empty( $template ) ) return (bool) $page_template; if ( $template == $page_template ) return true; if ( 'default' == $template && ! $page_template ) return true; return false; } |
関数 get_page_template_slug()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** * Get the specific template name for a page. * * @since 3.4.0 * * @param int $post_id Optional. The page ID to check. Defaults to the current post, when used in the loop. * @return string|bool Page template filename. Returns an empty string when the default page template * is in use. Returns false if the post is not a page. */ function get_page_template_slug( $post_id = null ) { $post = get_post( $post_id ); if ( ! $post || 'page' != $post->post_type ) return false; $template = get_post_meta( $post->ID, '_wp_page_template', true ); if ( ! $template || 'default' == $template ) return ''; return $template; } |
関数 wp_post_revision_title()
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 | /** * Retrieve formatted date timestamp of a revision (linked to that revisions's page). * * @since 2.6.0 * * @uses date_i18n() * * @param int|object $revision Revision ID or revision object. * @param bool $link Optional, default is true. Link to revisions's page? * @return string i18n formatted datetimestamp or localized 'Current Revision'. */ function wp_post_revision_title( $revision, $link = true ) { if ( !$revision = get_post( $revision ) ) return $revision; if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) return false; /* translators: revision date format, see http://php.net/date */ $datef = _x( 'j F, Y @ G:i', 'revision date format'); /* translators: 1: date */ $autosavef = _x( '%1$s [Autosave]', 'post revision title extra' ); /* translators: 1: date */ $currentf = _x( '%1$s [Current Revision]', 'post revision title extra' ); $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) $date = "<a href='$link'>$date</a>"; if ( !wp_is_post_revision( $revision ) ) $date = sprintf( $currentf, $date ); elseif ( wp_is_post_autosave( $revision ) ) $date = sprintf( $autosavef, $date ); return $date; } |
関数 wp_post_revision_title_expanded()
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 | /** * Retrieve formatted date timestamp of a revision (linked to that revisions's page). * * @since 3.6.0 * * @uses date_i18n() * * @param int|object $revision Revision ID or revision object. * @param bool $link Optional, default is true. Link to revisions's page? * @return string gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'. */ function wp_post_revision_title_expanded( $revision, $link = true ) { if ( !$revision = get_post( $revision ) ) return $revision; if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) return false; $author = get_the_author_meta( 'display_name', $revision->post_author ); /* translators: revision date format, see http://php.net/date */ $datef = _x( 'j F, Y @ G:i:s', 'revision date format'); $gravatar = get_avatar( $revision->post_author, 24 ); $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) $date = "<a href='$link'>$date</a>"; $revision_date_author = sprintf( /* translators: post revision title: 1: author avatar, 2: author name, 3: time ago, 4: date */ _x( '%1$s %2$s, %3$s ago (%4$s)', 'post revision title' ), $gravatar, $author, human_time_diff( strtotime( $revision->post_modified ), current_time( 'timestamp' ) ), $date ); $autosavef = __( '%1$s [Autosave]' ); $currentf = __( '%1$s [Current Revision]' ); if ( !wp_is_post_revision( $revision ) ) $revision_date_author = sprintf( $currentf, $revision_date_author ); elseif ( wp_is_post_autosave( $revision ) ) $revision_date_author = sprintf( $autosavef, $revision_date_author ); return $revision_date_author; } |
関数 wp_list_post_revisions()
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 | /** * Display list of a post's revisions. * * Can output either a UL with edit links or a TABLE with diff interface, and * restore action links. * * @since 2.6.0 * * @uses wp_get_post_revisions() * @uses wp_post_revision_title_expanded() * @uses get_edit_post_link() * @uses get_the_author_meta() * * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. * @param string $type 'all' (default), 'revision' or 'autosave' * @return null */ function wp_list_post_revisions( $post_id = 0, $type = 'all' ) { if ( ! $post = get_post( $post_id ) ) return; // $args array with (parent, format, right, left, type) deprecated since 3.6 if ( is_array( $type ) ) { $type = ! empty( $type['type'] ) ? $type['type'] : $type; _deprecated_argument( __FUNCTION__, '3.6' ); } if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) return; $rows = ''; foreach ( $revisions as $revision ) { if ( ! current_user_can( 'read_post', $revision->ID ) ) continue; $is_autosave = wp_is_post_autosave( $revision ); if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) continue; $rows .= "\t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>\n"; } echo "<div class='hide-if-js'><p>" . __( 'JavaScript must be enabled to use this feature.' ) . "</p></div>\n"; echo "<ul class='post-revisions hide-if-no-js'>\n"; echo $rows; echo "</ul>"; } |