wp/wp-includes/post-template.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress Post Template Functions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * Gets content for the current post in the loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * @subpackage Template
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * Display the ID of the current item in the WordPress Loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
function the_ID() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
	echo get_the_ID();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 * Retrieve the ID of the current item in the WordPress Loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
 * @return int|bool The ID of the current item in the WordPress Loop. False if $post is not set.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
function get_the_ID() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
	$post = get_post();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
	return ! empty( $post ) ? $post->ID : false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
 * Display or retrieve the current post title with optional content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
 * @param string $before Optional. Content to prepend to the title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
 * @param string $after Optional. Content to append to the title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
 * @param bool $echo Optional, default to true.Whether to display or return.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
 * @return null|string Null on no title. String if $echo parameter is false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
function the_title($before = '', $after = '', $echo = true) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	$title = get_the_title();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	if ( strlen($title) == 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
	$title = $before . $title . $after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
		echo $title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
		return $title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
 * Sanitize the current title when retrieving or displaying.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
 * Works like {@link the_title()}, except the parameters can be in a string or
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
 * an array. See the function for what can be override in the $args parameter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
 * The title before it is displayed will have the tags stripped and {@link
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
 * esc_attr()} before it is passed to the user or displayed. The default
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
 * as with {@link the_title()}, is to display the title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
 * @param string|array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
 *     Title attribute arguments. Optional.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
 *     @type string  $before Markup to prepend to the title. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
 *     @type string  $after  Markup to append to the title. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
 *     @type bool    $echo   Whether to echo or return the title. Default true for echo.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
 *     @type WP_Post $post   Current post object to retrieve the title for.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
 * @return string|null Null on failure or display. String when echo is false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
function the_title_attribute( $args = '' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
	$defaults = array( 'before' => '', 'after' =>  '', 'echo' => true, 'post' => get_post() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
	$r = wp_parse_args( $args, $defaults );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
	$title = get_the_title( $r['post'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
	if ( strlen( $title ) == 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
		return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
	$title = $r['before'] . $title . $r['after'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
	$title = esc_attr( strip_tags( $title ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    91
	if ( $r['echo'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
		echo $title;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		return $title;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
 * Retrieve post title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
 * If the post is protected and the visitor is not an admin, then "Protected"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
 * will be displayed before the post title. If the post is private, then
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
 * "Private" will be located before the post title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   107
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
function get_the_title( $post = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
	$post = get_post( $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
	$title = isset( $post->post_title ) ? $post->post_title : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
	$id = isset( $post->ID ) ? $post->ID : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	if ( ! is_admin() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		if ( ! empty( $post->post_password ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   118
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
			 * Filter the text prepended to the post title for protected posts.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
			 * The filter is only applied on the front end.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
			 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   126
			 * @param string  $prepend Text displayed before the post title.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
			 *                         Default 'Protected: %s'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
			 * @param WP_Post $post    Current post object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
			$protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
			$title = sprintf( $protected_title_format, $title );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   132
		} elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   134
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
			 * Filter the text prepended to the post title of private posts.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   136
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
			 * The filter is only applied on the front end.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
			 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
			 * @param string  $prepend Text displayed before the post title.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
			 *                         Default 'Private: %s'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   143
			 * @param WP_Post $post    Current post object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   145
			$private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ), $post );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
			$title = sprintf( $private_title_format, $title );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
	 * Filter the post title.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
	 * @since 0.71
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
	 * @param string $title The post title.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
	 * @param int    $id    The post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   157
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
	return apply_filters( 'the_title', $title, $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
 * Display the Post Global Unique Identifier (guid).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
 * The guid will appear to be a link, but should not be used as an link to the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
 * post. The reason you should not use it as a link, is because of moving the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
 * blog across domains.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
 * Url is escaped to make it xml safe
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
 * @param int|WP_Post $id Optional. Post ID or post object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
function the_guid( $id = 0 ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
	 * Filter the escaped Global Unique Identifier (guid) of the post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
	 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
	 * @see get_the_guid()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   181
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
	 * @param string $post_guid Escaped Global Unique Identifier (guid) of the post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   183
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
	echo apply_filters( 'the_guid', get_the_guid( $id ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
 * Retrieve the Post Global Unique Identifier (guid).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
 * The guid will appear to be a link, but should not be used as an link to the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
 * post. The reason you should not use it as a link, is because of moving the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
 * blog across domains.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   196
 * @param int|WP_Post $id Optional. Post ID or post object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
function get_the_guid( $id = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
	$post = get_post($id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   203
	 * Filter the Global Unique Identifier (guid) of the post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   204
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   205
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
	 * @param string $post_guid Global Unique Identifier (guid) of the post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
	return apply_filters( 'get_the_guid', $post->guid );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
 * Display the post content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
 * @param string $more_link_text Optional. Content for when there is more text.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
 * @param bool   $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
function the_content( $more_link_text = null, $strip_teaser = false) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
	$content = get_the_content( $more_link_text, $strip_teaser );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   223
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   224
	 * Filter the post content.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   225
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   226
	 * @since 0.71
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   228
	 * @param string $content Content of the current post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   229
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
	$content = apply_filters( 'the_content', $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
	$content = str_replace( ']]>', ']]&gt;', $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
	echo $content;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
 * Retrieve the post content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
 * @param string $more_link_text Optional. Content for when there is more text.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   241
 * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
function get_the_content( $more_link_text = null, $strip_teaser = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
	global $page, $more, $preview, $pages, $multipage;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
	$post = get_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
	if ( null === $more_link_text )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
		$more_link_text = __( '(more&hellip;)' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
	$output = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
	$has_teaser = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
	// If post password required and it doesn't match the cookie.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
	if ( post_password_required( $post ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
		return get_the_password_form( $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
	if ( $page > count( $pages ) ) // if the requested page doesn't exist
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
		$page = count( $pages ); // give them the highest numbered page that DOES exist
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
	$content = $pages[$page - 1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
	if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
		$content = explode( $matches[0], $content, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
		if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
			$more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
		$has_teaser = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
		$content = array( $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
		$strip_teaser = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	$teaser = $content[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
	if ( $more && $strip_teaser && $has_teaser )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
		$teaser = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
	$output .= $teaser;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
	if ( count( $content ) > 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
		if ( $more ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
			$output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
			if ( ! empty( $more_link_text ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   289
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
				 * Filter the Read More link text.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   291
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
				 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   293
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
				 * @param string $more_link_element Read More link element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
				 * @param string $more_link_text    Read More text.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
				 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
				$output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
			$output = force_balance_tags( $output );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
	if ( $preview ) // Preview fix for JavaScript bug with foreign languages.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
		$output =	preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
	return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   309
 * Preview fix for JavaScript bug with foreign languages.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
 * @param array $match Match array from preg_replace_callback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
function _convert_urlencoded_to_entities( $match ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
	return '&#' . base_convert( $match[1], 16, 10 ) . ';';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
 * Display the post excerpt.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
function the_excerpt() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
	 * Filter the displayed post excerpt.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
	 * @since 0.71
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
	 * @see get_the_excerpt()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   334
	 * @param string $post_excerpt The post excerpt.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   335
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   336
	echo apply_filters( 'the_excerpt', get_the_excerpt() );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
 * Retrieve the post excerpt.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
 * @param mixed $deprecated Not used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
function get_the_excerpt( $deprecated = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
	if ( !empty( $deprecated ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
		_deprecated_argument( __FUNCTION__, '2.3' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
	$post = get_post();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
	if ( empty( $post ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   353
		return '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   354
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
	if ( post_password_required() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
		return __( 'There is no excerpt because this is a protected post.' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   360
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   361
	 * Filter the retrieved post excerpt.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   362
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   363
	 * @since 1.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   364
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   365
	 * @param string $post_excerpt The post excerpt.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   366
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
	return apply_filters( 'get_the_excerpt', $post->post_excerpt );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
 * Whether post has excerpt.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
 * @param int|WP_Post $id Optional. Post ID or post object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
function has_excerpt( $id = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
	$post = get_post( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
	return ( !empty( $post->post_excerpt ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
 * Display the classes for the post div.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
 * @param string|array $class One or more classes to add to the class list.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   389
 * @param int|WP_Post $post_id Optional. Post ID or post object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
function post_class( $class = '', $post_id = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
	// Separates classes with a single space, collates classes for post DIV
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
	echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
 * Retrieve the classes for the post div as an array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   399
 * The class names are many. If the post is a sticky, then the 'sticky'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   400
 * class name. The class 'hentry' is always added to each post. If the post has a
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   401
 * post thumbnail, 'has-post-thumbnail' is added as a class. For each taxonomy that
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   402
 * the post belongs to, a class will be added of the format '{$taxonomy}-{$slug}' -
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   403
 * eg 'category-foo' or 'my_custom_taxonomy-bar'. The 'post_tag' taxonomy is a special
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   404
 * case; the class has the 'tag-' prefix instead of 'post_tag-'. All classes are
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   405
 * passed through the filter, 'post_class' with the list of classes, followed by
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   406
 * $class parameter value, with the post ID as the last parameter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
 * @since 2.7.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   409
 * @since 4.2.0 Custom taxonomy classes were added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
 * @param string|array $class   One or more classes to add to the class list.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
 * @param int|WP_Post  $post_id Optional. Post ID or post object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
 * @return array Array of classes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
function get_post_class( $class = '', $post_id = null ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   416
	$post = get_post( $post_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
	$classes = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   420
	if ( $class ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   421
		if ( ! is_array( $class ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   422
			$class = preg_split( '#\s+#', $class );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   423
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   424
		$classes = array_map( 'esc_attr', $class );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   425
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   426
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   427
	if ( ! $post ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
		return $classes;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
	$classes[] = 'post-' . $post->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
	if ( ! is_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
		$classes[] = $post->post_type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
	$classes[] = 'type-' . $post->post_type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
	$classes[] = 'status-' . $post->post_status;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
	// Post Format
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
	if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
		$post_format = get_post_format( $post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
		if ( $post_format && !is_wp_error($post_format) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
			$classes[] = 'format-' . sanitize_html_class( $post_format );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
			$classes[] = 'format-standard';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
	// Post requires password
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
	if ( post_password_required( $post->ID ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
		$classes[] = 'post-password-required';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   450
	// Post thumbnails
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   451
	} elseif ( ! is_attachment( $post ) && current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   452
		$classes[] = 'has-post-thumbnail';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   453
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
	// sticky for Sticky Posts
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   456
	if ( is_sticky( $post->ID ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   457
		if ( is_home() && ! is_paged() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   458
			$classes[] = 'sticky';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
		} elseif ( is_admin() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
			$classes[] = 'status-sticky';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   461
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   462
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
	// hentry for hAtom compliance
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
	$classes[] = 'hentry';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   467
	// All public taxonomies
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   468
	$taxonomies = get_taxonomies( array( 'public' => true ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   469
	foreach ( (array) $taxonomies as $taxonomy ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   470
		if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
			foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   472
				if ( empty( $term->slug ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
					continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   475
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   476
				$term_class = sanitize_html_class( $term->slug, $term->term_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
				if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   478
					$term_class = $term->term_id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
				// 'post_tag' uses the 'tag' prefix for backward compatibility.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
				if ( 'post_tag' == $taxonomy ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
					$classes[] = 'tag-' . $term_class;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
				} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
					$classes[] = sanitize_html_class( $taxonomy . '-' . $term_class, $taxonomy . '-' . $term->term_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   486
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
	$classes = array_map( 'esc_attr', $classes );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   493
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
	 * Filter the list of CSS classes for the current post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   497
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   498
	 * @param array  $classes An array of post classes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   499
	 * @param string $class   A comma-separated list of additional classes added to the post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   500
	 * @param int    $post_id The post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   502
	$classes = apply_filters( 'post_class', $classes, $class, $post->ID );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   504
	return array_unique( $classes );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
 * Display the classes for the body element.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
 * @param string|array $class One or more classes to add to the class list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
function body_class( $class = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
	// Separates classes with a single space, collates classes for body element
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
	echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
 * Retrieve the classes for the body element as an array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
 * @param string|array $class One or more classes to add to the class list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
 * @return array Array of classes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
function get_body_class( $class = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
	global $wp_query, $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
	$classes = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
	if ( is_rtl() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
		$classes[] = 'rtl';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
	if ( is_front_page() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
		$classes[] = 'home';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
	if ( is_home() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
		$classes[] = 'blog';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
	if ( is_archive() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
		$classes[] = 'archive';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
	if ( is_date() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
		$classes[] = 'date';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
	if ( is_search() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
		$classes[] = 'search';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
		$classes[] = $wp_query->posts ? 'search-results' : 'search-no-results';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	if ( is_paged() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
		$classes[] = 'paged';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
	if ( is_attachment() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
		$classes[] = 'attachment';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
	if ( is_404() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
		$classes[] = 'error404';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
	if ( is_single() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
		$post_id = $wp_query->get_queried_object_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
		$post = $wp_query->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
		$classes[] = 'single';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
		if ( isset( $post->post_type ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
			$classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
			$classes[] = 'postid-' . $post_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
			// Post Format
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
			if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
				$post_format = get_post_format( $post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
				if ( $post_format && !is_wp_error($post_format) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
					$classes[] = 'single-format-' . sanitize_html_class( $post_format );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
					$classes[] = 'single-format-standard';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
		if ( is_attachment() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
			$mime_type = get_post_mime_type($post_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
			$mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
			$classes[] = 'attachmentid-' . $post_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
			$classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
	} elseif ( is_archive() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
		if ( is_post_type_archive() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
			$classes[] = 'post-type-archive';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
			$post_type = get_query_var( 'post_type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
			if ( is_array( $post_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
				$post_type = reset( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
			$classes[] = 'post-type-archive-' . sanitize_html_class( $post_type );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   587
		} elseif ( is_author() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
			$author = $wp_query->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
			$classes[] = 'author';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
			if ( isset( $author->user_nicename ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
				$classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
				$classes[] = 'author-' . $author->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
		} elseif ( is_category() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
			$cat = $wp_query->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
			$classes[] = 'category';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
			if ( isset( $cat->term_id ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   598
				$cat_class = sanitize_html_class( $cat->slug, $cat->term_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   599
				if ( is_numeric( $cat_class ) || ! trim( $cat_class, '-' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   600
					$cat_class = $cat->term_id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   601
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   602
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   603
				$classes[] = 'category-' . $cat_class;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
				$classes[] = 'category-' . $cat->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
		} elseif ( is_tag() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   607
			$tag = $wp_query->get_queried_object();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
			$classes[] = 'tag';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   609
			if ( isset( $tag->term_id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   610
				$tag_class = sanitize_html_class( $tag->slug, $tag->term_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   611
				if ( is_numeric( $tag_class ) || ! trim( $tag_class, '-' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   612
					$tag_class = $tag->term_id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   613
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   614
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   615
				$classes[] = 'tag-' . $tag_class;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   616
				$classes[] = 'tag-' . $tag->term_id;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
		} elseif ( is_tax() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
			$term = $wp_query->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
			if ( isset( $term->term_id ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   621
				$term_class = sanitize_html_class( $term->slug, $term->term_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   622
				if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   623
					$term_class = $term->term_id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   624
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   625
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
				$classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   627
				$classes[] = 'term-' . $term_class;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
				$classes[] = 'term-' . $term->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
	} elseif ( is_page() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
		$classes[] = 'page';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
		$page_id = $wp_query->get_queried_object_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
		$post = get_post($page_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
		$classes[] = 'page-id-' . $page_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   640
		if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
			$classes[] = 'page-parent';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   642
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
		if ( $post->post_parent ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
			$classes[] = 'page-child';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
			$classes[] = 'parent-pageid-' . $post->post_parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
		if ( is_page_template() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
			$classes[] = 'page-template';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   650
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   651
			$template_slug  = get_page_template_slug( $page_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   652
			$template_parts = explode( '/', $template_slug );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   653
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   654
			foreach ( $template_parts as $part ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   655
				$classes[] = 'page-template-' . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   656
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   657
			$classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', $template_slug ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
			$classes[] = 'page-template-default';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
	if ( is_user_logged_in() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
		$classes[] = 'logged-in';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
	if ( is_admin_bar_showing() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
		$classes[] = 'admin-bar';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
		$classes[] = 'no-customize-support';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   671
	if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
		$classes[] = 'custom-background';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
	$page = $wp_query->get( 'page' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   676
	if ( ! $page || $page < 2 )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
		$page = $wp_query->get( 'paged' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   679
	if ( $page && $page > 1 && ! is_404() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
		$classes[] = 'paged-' . $page;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
		if ( is_single() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
			$classes[] = 'single-paged-' . $page;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
		elseif ( is_page() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
			$classes[] = 'page-paged-' . $page;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
		elseif ( is_category() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
			$classes[] = 'category-paged-' . $page;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
		elseif ( is_tag() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
			$classes[] = 'tag-paged-' . $page;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
		elseif ( is_date() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
			$classes[] = 'date-paged-' . $page;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
		elseif ( is_author() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
			$classes[] = 'author-paged-' . $page;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
		elseif ( is_search() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
			$classes[] = 'search-paged-' . $page;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
		elseif ( is_post_type_archive() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
			$classes[] = 'post-type-paged-' . $page;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
	if ( ! empty( $class ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
		if ( !is_array( $class ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
			$class = preg_split( '#\s+#', $class );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
		$classes = array_merge( $classes, $class );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
		// Ensure that we always coerce class to being an array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
		$class = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
	$classes = array_map( 'esc_attr', $classes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   711
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   712
	 * Filter the list of CSS body classes for the current post or page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   713
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   714
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   715
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   716
	 * @param array  $classes An array of body classes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   717
	 * @param string $class   A comma-separated list of additional classes added to the body.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   718
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   719
	$classes = apply_filters( 'body_class', $classes, $class );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   720
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   721
	return array_unique( $classes );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
 * Whether post requires password and correct password has been provided.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
 * @param int|WP_Post $post An optional post. Global $post used if not provided.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
 * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
function post_password_required( $post = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
	$post = get_post($post);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
	if ( empty( $post->post_password ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
	if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   741
	require_once ABSPATH . WPINC . '/class-phpass.php';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
	$hasher = new PasswordHash( 8, true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
	$hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
	if ( 0 !== strpos( $hash, '$P$B' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
	return ! $hasher->CheckPassword( $post->post_password, $hash );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   751
//
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   752
// Page Template Functions for usage in Themes
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   753
//
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
 * The formatted output of a list of pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
 * Displays page links for paginated posts (i.e. includes the <!--nextpage-->.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
 * Quicktag one or more times). This tag must be within The Loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   763
 * @param string|array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   764
 *     Optional. Array or string of default arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   765
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   766
 *     @type string       $before           HTML or text to prepend to each link. Default is `<p> Pages:`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   767
 *     @type string       $after            HTML or text to append to each link. Default is `</p>`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   768
 *     @type string       $link_before      HTML or text to prepend to each link, inside the `<a>` tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   769
 *                                          Also prepended to the current item, which is not linked. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   770
 *     @type string       $link_after       HTML or text to append to each Pages link inside the `<a>` tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   771
 *                                          Also appended to the current item, which is not linked. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   772
 *     @type string       $next_or_number   Indicates whether page numbers should be used. Valid values are number
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   773
 *                                          and next. Default is 'number'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   774
 *     @type string       $separator        Text between pagination links. Default is ' '.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   775
 *     @type string       $nextpagelink     Link text for the next page link, if available. Default is 'Next Page'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   776
 *     @type string       $previouspagelink Link text for the previous page link, if available. Default is 'Previous Page'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   777
 *     @type string       $pagelink         Format string for page numbers. The % in the parameter string will be
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   778
 *                                          replaced with the page number, so 'Page %' generates "Page 1", "Page 2", etc.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   779
 *                                          Defaults to '%', just the page number.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   780
 *     @type int|bool     $echo             Whether to echo or not. Accepts 1|true or 0|false. Default 1|true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   781
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
 * @return string Formatted output in HTML.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
function wp_link_pages( $args = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
		'before'           => '<p>' . __( 'Pages:' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
		'after'            => '</p>',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
		'link_before'      => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
		'link_after'       => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
		'next_or_number'   => 'number',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
		'separator'        => ' ',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
		'nextpagelink'     => __( 'Next page' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
		'previouspagelink' => __( 'Previous page' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
		'pagelink'         => '%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
		'echo'             => 1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   798
	$params = wp_parse_args( $args, $defaults );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   799
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   800
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   801
	 * Filter the arguments used in retrieving page links for paginated posts.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   802
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   803
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   804
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   805
	 * @param array $params An array of arguments for page links for paginated posts.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   806
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   807
	$r = apply_filters( 'wp_link_pages_args', $params );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
	global $page, $numpages, $multipage, $more;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
	$output = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
	if ( $multipage ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   813
		if ( 'number' == $r['next_or_number'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   814
			$output .= $r['before'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
			for ( $i = 1; $i <= $numpages; $i++ ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   816
				$link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   817
				if ( $i != $page || ! $more && 1 == $page ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
					$link = _wp_link_page( $i ) . $link . '</a>';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   819
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   820
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   821
				 * Filter the HTML output of individual page number links.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   822
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   823
				 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   824
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   825
				 * @param string $link The page number HTML output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   826
				 * @param int    $i    Page number for paginated posts' page links.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   827
				 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
				$link = apply_filters( 'wp_link_pages_link', $link, $i );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   829
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   830
				// Use the custom links separator beginning with the second link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   831
				$output .= ( 1 === $i ) ? ' ' : $r['separator'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   832
				$output .= $link;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   834
			$output .= $r['after'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
		} elseif ( $more ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   836
			$output .= $r['before'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   837
			$prev = $page - 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   838
			if ( $prev ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   839
				$link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   840
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   841
				/** This filter is documented in wp-includes/post-template.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   842
				$output .= apply_filters( 'wp_link_pages_link', $link, $prev );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   844
			$next = $page + 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   845
			if ( $next <= $numpages ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   846
				if ( $prev ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   847
					$output .= $r['separator'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   848
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   849
				$link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . '</a>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   850
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   851
				/** This filter is documented in wp-includes/post-template.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   852
				$output .= apply_filters( 'wp_link_pages_link', $link, $next );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   854
			$output .= $r['after'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   858
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   859
	 * Filter the HTML output of page links for paginated posts.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   860
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   861
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   862
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   863
	 * @param string $output HTML output of paginated posts' page links.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   864
	 * @param array  $args   An array of arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   865
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   866
	$html = apply_filters( 'wp_link_pages', $output, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   868
	if ( $r['echo'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   869
		echo $html;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   870
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   871
	return $html;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
 * Helper function for wp_link_pages().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
 * @param int $i Page number.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
 * @return string Link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
function _wp_link_page( $i ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
	$post = get_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
	if ( 1 == $i ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
		$url = get_permalink();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
		if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
			$url = add_query_arg( 'page', $i, get_permalink() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
		elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
			$url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
			$url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   898
	if ( is_preview() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   899
		$url = add_query_arg( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   900
			'preview' => 'true'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   901
		), $url );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   902
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   903
		if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   904
			$url = add_query_arg( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   905
				'preview_id'    => wp_unslash( $_GET['preview_id'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   906
				'preview_nonce' => wp_unslash( $_GET['preview_nonce'] )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   907
			), $url );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   908
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   909
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   910
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
	return '<a href="' . esc_url( $url ) . '">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
// Post-meta: Custom per-post fields.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
 * Retrieve post custom meta data field.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
 * @param string $key Meta data key name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
 * @return bool|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
function post_custom( $key = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
	$custom = get_post_custom();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
	if ( !isset( $custom[$key] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
	elseif ( 1 == count($custom[$key]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
		return $custom[$key][0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
		return $custom[$key];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
 * Display list of post custom fields.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
 * @internal This will probably change at some point...
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
function the_meta() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
	if ( $keys = get_post_custom_keys() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
		echo "<ul class='post-meta'>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
		foreach ( (array) $keys as $key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
			$keyt = trim($key);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
			if ( is_protected_meta( $keyt, 'post' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
			$values = array_map('trim', get_post_custom_values($key));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
			$value = implode($values,', ');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   952
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   953
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   954
			 * Filter the HTML output of the li element in the post custom fields list.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   955
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   956
			 * @since 2.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   957
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   958
			 * @param string $html  The HTML output for the li element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   959
			 * @param string $key   Meta key.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   960
			 * @param string $value Meta value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   961
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   962
			echo apply_filters( 'the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
		echo "</ul>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
// Pages
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
 * Retrieve or display list of pages as a dropdown (select list).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   976
 * @since 4.2.0 The `$value_field` argument was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   978
 * @param array|string $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   979
 *     Optional. Array or string of arguments to generate a pages drop-down element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   980
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   981
 *     @type int          $depth                 Maximum depth. Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   982
 *     @type int          $child_of              Page ID to retrieve child pages of. Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   983
 *     @type int|string   $selected              Value of the option that should be selected. Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   984
 *     @type bool|int     $echo                  Whether to echo or return the generated markup. Accepts 0, 1,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   985
 *                                               or their bool equivalents. Default 1.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   986
 *     @type string       $name                  Value for the 'name' attribute of the select element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   987
 *                                               Default 'page_id'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   988
 *     @type string       $id                    Value for the 'id' attribute of the select element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   989
 *                                               Defaults to the value of `$name`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   990
 *     @type string       $show_option_none      Text to display for showing no pages. Default empty (does not display).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   991
 *     @type string       $show_option_no_change Text to display for "no change" option. Default empty (does not display).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   992
 *     @type string       $option_none_value     Value to use when no page is selected. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   993
 *     @type string       $value_field           Post field used to populate the 'value' attribute of the option
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   994
 *                                               elements. Accepts any valid post field. Default 'ID'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   995
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
 * @return string HTML content, if not displaying.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   998
function wp_dropdown_pages( $args = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
		'depth' => 0, 'child_of' => 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
		'selected' => 0, 'echo' => 1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
		'name' => 'page_id', 'id' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
		'show_option_none' => '', 'show_option_no_change' => '',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1004
		'option_none_value' => '',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1005
		'value_field' => 'ID',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
	$r = wp_parse_args( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1010
	$pages = get_pages( $r );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
	$output = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
	// Back-compat with old system where both id and name were based on $name argument
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1013
	if ( empty( $r['id'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1014
		$r['id'] = $r['name'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1015
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1017
	if ( ! empty( $pages ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1018
		$output = "<select name='" . esc_attr( $r['name'] ) . "' id='" . esc_attr( $r['id'] ) . "'>\n";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1019
		if ( $r['show_option_no_change'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1020
			$output .= "\t<option value=\"-1\">" . $r['show_option_no_change'] . "</option>\n";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1021
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1022
		if ( $r['show_option_none'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1023
			$output .= "\t<option value=\"" . esc_attr( $r['option_none_value'] ) . '">' . $r['show_option_none'] . "</option>\n";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1024
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1025
		$output .= walk_page_dropdown_tree( $pages, $r['depth'], $r );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
		$output .= "</select>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1029
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1030
	 * Filter the HTML output of a list of pages as a drop down.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1031
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1032
	 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1033
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1034
	 * @param string $output HTML output for drop down list of pages.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1035
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1036
	$html = apply_filters( 'wp_dropdown_pages', $output );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1038
	if ( $r['echo'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1039
		echo $html;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1040
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1041
	return $html;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1042
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1044
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
 * Retrieve or display list of pages in list (li) format.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1049
 * @see get_pages()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1050
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1051
 * @param array|string $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1052
 *     Array or string of arguments. Optional.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1053
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1054
 *     @type int    $child_of     Display only the sub-pages of a single page by ID. Default 0 (all pages).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1055
 *     @type string $authors      Comma-separated list of author IDs. Default empty (all authors).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1056
 *     @type string $date_format  PHP date format to use for the listed pages. Relies on the 'show_date' parameter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1057
 *                                Default is the value of 'date_format' option.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1058
 *     @type int    $depth        Number of levels in the hierarchy of pages to include in the generated list.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1059
 *                                Accepts -1 (any depth), 0 (all pages), 1 (top-level pages only), and n (pages to
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1060
 *                                the given n depth). Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1061
 *     @type bool   $echo         Whether or not to echo the list of pages. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1062
 *     @type string $exclude      Comma-separated list of page IDs to exclude. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1063
 *     @type array  $include      Comma-separated list of page IDs to include. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1064
 *     @type string $link_after   Text or HTML to follow the page link label. Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1065
 *     @type string $link_before  Text or HTML to precede the page link label. Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1066
 *     @type string $post_type    Post type to query for. Default 'page'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1067
 *     @type string $post_status  Comma-separated list of post statuses to include. Default 'publish'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1068
 *     @type string $show_date	  Whether to display the page publish or modified date for each page. Accepts
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1069
 *                                'modified' or any other value. An empty value hides the date. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1070
 *     @type string $sort_column  Comma-separated list of column names to sort the pages by. Accepts 'post_author',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1071
 *                                'post_date', 'post_title', 'post_name', 'post_modified', 'post_modified_gmt',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1072
 *                                'menu_order', 'post_parent', 'ID', 'rand', or 'comment_count'. Default 'post_title'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1073
 *     @type string $title_li     List heading. Passing a null or empty value will result in no heading, and the list
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1074
 *                                will not be wrapped with unordered list `<ul>` tags. Default 'Pages'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1075
 *     @type Walker $walker       Walker instance to use for listing pages. Default empty (Walker_Page).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1076
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1077
 * @return string HTML list of pages.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1079
function wp_list_pages( $args = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
		'depth' => 0, 'show_date' => '',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1082
		'date_format' => get_option( 'date_format' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
		'child_of' => 0, 'exclude' => '',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1084
		'title_li' => __( 'Pages' ), 'echo' => 1,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
		'authors' => '', 'sort_column' => 'menu_order, post_title',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
		'link_before' => '', 'link_after' => '', 'walker' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1087
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
	$r = wp_parse_args( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
	$output = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
	$current_page = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1094
	// sanitize, mostly to keep spaces out
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1095
	$r['exclude'] = preg_replace( '/[^0-9,]/', '', $r['exclude'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1097
	// Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array)
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1098
	$exclude_array = ( $r['exclude'] ) ? explode( ',', $r['exclude'] ) : array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1099
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1100
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1101
	 * Filter the array of pages to exclude from the pages list.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1102
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1103
	 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1104
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1105
	 * @param array $exclude_array An array of page IDs to exclude.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1106
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1107
	$r['exclude'] = implode( ',', apply_filters( 'wp_list_pages_excludes', $exclude_array ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
	// Query pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1110
	$r['hierarchical'] = 0;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1111
	$pages = get_pages( $r );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1112
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1113
	if ( ! empty( $pages ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1114
		if ( $r['title_li'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
			$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1116
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
		global $wp_query;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1118
		if ( is_page() || is_attachment() || $wp_query->is_posts_page ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1119
			$current_page = get_queried_object_id();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1120
		} elseif ( is_singular() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1121
			$queried_object = get_queried_object();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1122
			if ( is_post_type_hierarchical( $queried_object->post_type ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1123
				$current_page = $queried_object->ID;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1124
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1125
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1127
		$output .= walk_page_tree( $pages, $r['depth'], $current_page, $r );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1128
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1129
		if ( $r['title_li'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
			$output .= '</ul></li>';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1131
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1134
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1135
	 * Filter the HTML output of the pages to list.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1136
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1137
	 * @since 1.5.1
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1138
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1139
	 * @see wp_list_pages()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1140
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1141
	 * @param string $output HTML output of the pages list.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1142
	 * @param array  $r      An array of page-listing arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1143
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1144
	$html = apply_filters( 'wp_list_pages', $output, $r );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1146
	if ( $r['echo'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1147
		echo $html;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1148
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1149
		return $html;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1150
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
 * Display or retrieve list of pages with optional home link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
 * The arguments are listed below and part of the arguments are for {@link
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
 * wp_list_pages()} function. Check that function for more info on those
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
 * arguments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1162
 * @param array|string $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1163
 *     Optional. Arguments to generate a page menu. See wp_list_pages() for additional arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1164
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1165
 *     @type string          $sort_column How to short the list of pages. Accepts post column names.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1166
 *                                        Default 'menu_order, post_title'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1167
 *     @type string          $menu_class  Class to use for the div ID containing the page list. Default 'menu'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1168
 *     @type bool            $echo        Whether to echo the list or return it. Accepts true (echo) or false (return).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1169
 *                                        Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1170
 *     @type string          $link_before The HTML or text to prepend to $show_home text. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1171
 *     @type string          $link_after  The HTML or text to append to $show_home text. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1172
 *     @type int|bool|string $show_home   Whether to display the link to the home page. Can just enter the text
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1173
 *                                        you'd like shown for the home link. 1|true defaults to 'Home'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1174
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
 * @return string html menu
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
function wp_page_menu( $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
	$defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
	$args = wp_parse_args( $args, $defaults );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1180
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1181
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1182
	 * Filter the arguments used to generate a page-based menu.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1183
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1184
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1185
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1186
	 * @see wp_page_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1187
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1188
	 * @param array $args An array of page menu arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1189
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
	$args = apply_filters( 'wp_page_menu_args', $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
	$menu = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
	$list_args = $args;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
	// Show Home in the menu
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
	if ( ! empty($args['show_home']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
		if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
			$text = __('Home');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
			$text = $args['show_home'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
		$class = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
		if ( is_front_page() && !is_paged() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
			$class = 'class="current_page_item"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
		$menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
		// If the front page is a page, add it to the exclude list
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
		if (get_option('show_on_front') == 'page') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
			if ( !empty( $list_args['exclude'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
				$list_args['exclude'] .= ',';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
				$list_args['exclude'] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
			$list_args['exclude'] .= get_option('page_on_front');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1217
	$list_args['echo'] = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
	$list_args['title_li'] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
	$menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1221
	if ( $menu )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1222
		$menu = '<ul>' . $menu . '</ul>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1223
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1224
	$menu = '<div class="' . esc_attr($args['menu_class']) . '">' . $menu . "</div>\n";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1225
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1226
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1227
	 * Filter the HTML output of a page-based menu.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1228
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1229
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1230
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1231
	 * @see wp_page_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1232
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1233
	 * @param string $menu The HTML output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1234
	 * @param array  $args An array of arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1235
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1236
	$menu = apply_filters( 'wp_page_menu', $menu, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
	if ( $args['echo'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1238
		echo $menu;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1239
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1240
		return $menu;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1243
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1244
// Page helpers
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
 * Retrieve HTML list content for page list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1249
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
 * @uses Walker_Page to create HTML list content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
 * @see Walker_Page::walk() for parameters and return description.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
function walk_page_tree($pages, $depth, $current_page, $r) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
	if ( empty($r['walker']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
		$walker = new Walker_Page;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
		$walker = $r['walker'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
	foreach ( (array) $pages as $page ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
		if ( $page->post_parent )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
			$r['pages_with_children'][ $page->post_parent ] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1263
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
	$args = array($pages, $depth, $r, $current_page);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
	return call_user_func_array(array($walker, 'walk'), $args);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1268
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1269
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1270
 * Retrieve HTML dropdown (select) content for page list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
 * @uses Walker_PageDropdown to create HTML dropdown content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1273
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
 * @see Walker_PageDropdown::walk() for parameters and return description.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
function walk_page_dropdown_tree() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
	$args = func_get_args();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
	if ( empty($args[2]['walker']) ) // the user's options are the third parameter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
		$walker = new Walker_PageDropdown;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
		$walker = $args[2]['walker'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
	return call_user_func_array(array($walker, 'walk'), $args);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
 * Create HTML list of pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
 * @uses Walker
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
class Walker_Page extends Walker {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1294
	 * @see Walker::$tree_type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1296
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1297
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1298
	public $tree_type = 'page';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1299
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1300
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1301
	 * @see Walker::$db_fields
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
	 * @todo Decouple this.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1304
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1306
	public $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
	 * @see Walker::start_lvl()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
	 * @param string $output Passed by reference. Used to append additional content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
	 * @param int $depth Depth of page. Used for padding.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
	 * @param array $args
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1316
	public function start_lvl( &$output, $depth = 0, $args = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
		$indent = str_repeat("\t", $depth);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
		$output .= "\n$indent<ul class='children'>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
	 * @see Walker::end_lvl()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1323
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1324
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
	 * @param string $output Passed by reference. Used to append additional content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
	 * @param int $depth Depth of page. Used for padding.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
	 * @param array $args
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1329
	public function end_lvl( &$output, $depth = 0, $args = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
		$indent = str_repeat("\t", $depth);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
		$output .= "$indent</ul>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
	 * @see Walker::start_el()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1337
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
	 * @param string $output Passed by reference. Used to append additional content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
	 * @param object $page Page data object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
	 * @param int $depth Depth of page. Used for padding.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
	 * @param int $current_page Page ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
	 * @param array $args
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1344
	public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1345
		if ( $depth ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1346
			$indent = str_repeat( "\t", $depth );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1347
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
			$indent = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1349
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1351
		$css_class = array( 'page_item', 'page-item-' . $page->ID );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1353
		if ( isset( $args['pages_with_children'][ $page->ID ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
			$css_class[] = 'page_item_has_children';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1355
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1357
		if ( ! empty( $current_page ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
			$_current_page = get_post( $current_page );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1359
			if ( $_current_page && in_array( $page->ID, $_current_page->ancestors ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1360
				$css_class[] = 'current_page_ancestor';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1361
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1362
			if ( $page->ID == $current_page ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
				$css_class[] = 'current_page_item';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1364
			} elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
				$css_class[] = 'current_page_parent';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1366
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
		} elseif ( $page->ID == get_option('page_for_posts') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
			$css_class[] = 'current_page_parent';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1371
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1372
		 * Filter the list of CSS classes to include with each page item in the list.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1373
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1374
		 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1375
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1376
		 * @see wp_list_pages()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1377
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1378
		 * @param array   $css_class    An array of CSS classes to be applied
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1379
		 *                             to each list item.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1380
		 * @param WP_Post $page         Page data object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1381
		 * @param int     $depth        Depth of page, used for padding.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1382
		 * @param array   $args         An array of arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1383
		 * @param int     $current_page ID of the current page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1384
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1385
		$css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1386
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1387
		if ( '' === $page->post_title ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1388
			$page->post_title = sprintf( __( '#%d (no title)' ), $page->ID );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1389
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1390
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1391
		$args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1392
		$args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1393
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1394
		/** This filter is documented in wp-includes/post-template.php */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1395
		$output .= $indent . sprintf(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1396
			'<li class="%s"><a href="%s">%s%s%s</a>',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1397
			$css_classes,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1398
			get_permalink( $page->ID ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1399
			$args['link_before'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1400
			apply_filters( 'the_title', $page->post_title, $page->ID ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1401
			$args['link_after']
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1402
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1404
		if ( ! empty( $args['show_date'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1405
			if ( 'modified' == $args['show_date'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1406
				$time = $page->post_modified;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1407
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1408
				$time = $page->post_date;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1409
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1410
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1411
			$date_format = empty( $args['date_format'] ) ? '' : $args['date_format'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1412
			$output .= " " . mysql2date( $date_format, $time );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1413
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1414
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1416
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1417
	 * @see Walker::end_el()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
	 * @param string $output Passed by reference. Used to append additional content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1421
	 * @param object $page Page data object. Not used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
	 * @param int $depth Depth of page. Not Used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1423
	 * @param array $args
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1424
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1425
	public function end_el( &$output, $page, $depth = 0, $args = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1426
		$output .= "</li>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1428
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1429
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1430
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
 * Create HTML dropdown list of pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1433
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1435
 * @uses Walker
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1436
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1437
class Walker_PageDropdown extends Walker {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1438
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
	 * @see Walker::$tree_type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1441
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1442
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1443
	public $tree_type = 'page';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1444
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1445
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1446
	 * @see Walker::$db_fields
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1447
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
	 * @todo Decouple this
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1451
	public $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
	 * @see Walker::start_el()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1455
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1456
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1457
	 * @param string $output Passed by reference. Used to append additional content.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1458
	 * @param object $page   Page data object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1459
	 * @param int    $depth  Depth of page in reference to parent pages. Used for padding.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1460
	 * @param array  $args   Uses 'selected' argument for selected page to set selected HTML attribute for option
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1461
	 *              element. Uses 'value_field' argument to fill "value" attribute. See {@see wp_dropdown_pages()}.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1462
	 * @param int $id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1463
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1464
	public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1465
		$pad = str_repeat('&nbsp;', $depth * 3);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1467
		if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1468
			$args['value_field'] = 'ID';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1469
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1470
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1471
		$output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $page->{$args['value_field']} ) . "\"";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1472
		if ( $page->ID == $args['selected'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1473
			$output .= ' selected="selected"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1474
		$output .= '>';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1475
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1476
		$title = $page->post_title;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1477
		if ( '' === $title ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1478
			$title = sprintf( __( '#%d (no title)' ), $page->ID );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1479
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1480
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1481
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1482
		 * Filter the page title when creating an HTML drop-down list of pages.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1483
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1484
		 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1485
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1486
		 * @param string $title Page title.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1487
		 * @param object $page  Page data object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1488
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1489
		$title = apply_filters( 'list_pages', $title, $page );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1490
		$output .= $pad . esc_html( $title );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1491
		$output .= "</option>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1492
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1493
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1494
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1495
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1496
// Attachments
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1497
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1498
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1499
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1500
 * Display an attachment page link using an image or icon.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1501
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1502
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1503
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1504
 * @param int|WP_Post $id Optional. Post ID or post object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1505
 * @param bool        $fullsize     Optional, default is false. Whether to use full size.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1506
 * @param bool        $deprecated   Deprecated. Not used.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1507
 * @param bool        $permalink    Optional, default is false. Whether to include permalink.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1508
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1509
function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1510
	if ( !empty( $deprecated ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1511
		_deprecated_argument( __FUNCTION__, '2.5' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1512
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1513
	if ( $fullsize )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1514
		echo wp_get_attachment_link($id, 'full', $permalink);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1515
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1516
		echo wp_get_attachment_link($id, 'thumbnail', $permalink);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1517
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1518
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1519
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1520
 * Retrieve an attachment page link using an image or icon, if possible.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1521
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1522
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1523
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1524
 * @param int|WP_Post  $id        Optional. Post ID or post object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1525
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1526
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1527
 * @param bool         $icon      Optional, default is false. Whether to include icon.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1528
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1529
 * @param array|string $attr      Optional. Array or string of attributes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1530
 * @return string HTML content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1531
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1532
function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1533
	$id = intval( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1534
	$_post = get_post( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1535
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1536
	if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1537
		return __( 'Missing Attachment' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1538
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1539
	if ( $permalink )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1540
		$url = get_attachment_link( $_post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1541
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1542
	if ( $text ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1543
		$link_text = $text;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1544
	} elseif ( $size && 'none' != $size ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1545
		$link_text = wp_get_attachment_image( $id, $size, $icon, $attr );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1546
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1547
		$link_text = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1548
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1549
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1550
	if ( trim( $link_text ) == '' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1551
		$link_text = $_post->post_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1552
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1553
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1554
	 * Filter a retrieved attachment page link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1555
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1556
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1557
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1558
	 * @param string      $link_html The page link HTML output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1559
	 * @param int         $id        Post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1560
	 * @param string      $size      Image size. Default 'thumbnail'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1561
	 * @param bool        $permalink Whether to add permalink to image. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1562
	 * @param bool        $icon      Whether to include an icon. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1563
	 * @param string|bool $text      If string, will be link text. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1564
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1565
	return apply_filters( 'wp_get_attachment_link', "<a href='$url'>$link_text</a>", $id, $size, $permalink, $icon, $text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1566
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1567
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1568
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1569
 * Wrap attachment in paragraph tag before content.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1570
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1571
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1572
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1573
 * @param string $content
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1574
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1575
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1576
function prepend_attachment($content) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1577
	$post = get_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1578
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1579
	if ( empty($post->post_type) || $post->post_type != 'attachment' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1580
		return $content;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1581
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1582
	if ( wp_attachment_is( 'video', $post ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1583
		$meta = wp_get_attachment_metadata( get_the_ID() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1584
		$atts = array( 'src' => wp_get_attachment_url() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1585
		if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1586
			$atts['width'] = (int) $meta['width'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1587
			$atts['height'] = (int) $meta['height'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1588
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1589
		if ( has_post_thumbnail() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1590
			$atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1591
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1592
		$p = wp_video_shortcode( $atts );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1593
	} elseif ( wp_attachment_is( 'audio', $post ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1594
		$p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1595
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1596
		$p = '<p class="attachment">';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1597
		// show the medium sized image representation of the attachment if available, and link to the raw file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1598
		$p .= wp_get_attachment_link(0, 'medium', false);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1599
		$p .= '</p>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1600
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1601
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1602
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1603
	 * Filter the attachment markup to be prepended to the post content.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1604
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1605
	 * @since 2.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1606
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1607
	 * @see prepend_attachment()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1608
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1609
	 * @param string $p The attachment HTML output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1610
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1611
	$p = apply_filters( 'prepend_attachment', $p );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1612
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1613
	return "$p\n$content";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1614
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1615
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1616
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1617
// Misc
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1618
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1619
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1620
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1621
 * Retrieve protected post password form content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1622
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1623
 * @since 1.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1624
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1625
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1626
 * @return string HTML content for password form for password protected post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1627
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1628
function get_the_password_form( $post = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1629
	$post = get_post( $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1630
	$label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1631
	$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1632
	<p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1633
	<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>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1634
	';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1635
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1636
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1637
	 * Filter the HTML output for the protected post password form.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1638
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1639
	 * If modifying the password field, please note that the core database schema
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1640
	 * limits the password field to 20 characters regardless of the value of the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1641
	 * size attribute in the form input.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1642
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1643
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1644
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1645
	 * @param string $output The password form HTML output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1646
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1647
	return apply_filters( 'the_password_form', $output );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1648
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1649
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1650
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1651
 * Whether currently in a page template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1652
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1653
 * This template tag allows you to determine if you are in a page template.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1654
 * You can optionally provide a template name or array of template names
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1655
 * and then the check will be specific to that template.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1656
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1657
 * @since 2.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1658
 * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1659
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1660
 * @param string|array $template The specific template name or array of templates to match.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1661
 * @return bool True on success, false on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1662
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1663
function is_page_template( $template = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1664
	if ( ! is_page() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1665
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1666
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1667
	$page_template = get_page_template_slug( get_queried_object_id() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1668
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1669
	if ( empty( $template ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1670
		return (bool) $page_template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1671
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1672
	if ( $template == $page_template )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1674
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1675
	if ( is_array( $template ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1676
		if ( ( in_array( 'default', $template, true ) && ! $page_template )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1677
			|| in_array( $page_template, $template, true )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1678
		) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1679
			return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1680
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1681
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1682
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1683
	if ( 'default' == $template && ! $page_template )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1684
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1685
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1686
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1687
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1688
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1689
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
 * Get the specific template name for a page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1691
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1694
 * @param int $post_id Optional. The page ID to check. Defaults to the current post, when used in the loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1695
 * @return string|bool Page template filename. Returns an empty string when the default page template
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1696
 * 	is in use. Returns false if the post is not a page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1697
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1698
function get_page_template_slug( $post_id = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1699
	$post = get_post( $post_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1700
	if ( ! $post || 'page' != $post->post_type )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1701
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1702
	$template = get_post_meta( $post->ID, '_wp_page_template', true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1703
	if ( ! $template || 'default' == $template )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1704
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1705
	return $template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1706
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1707
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1708
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1709
 * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1710
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1711
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1712
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1713
 * @param int|object $revision Revision ID or revision object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1714
 * @param bool $link Optional, default is true. Link to revisions's page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1715
 * @return string i18n formatted datetimestamp or localized 'Current Revision'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1716
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1717
function wp_post_revision_title( $revision, $link = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1718
	if ( !$revision = get_post( $revision ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1719
		return $revision;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1720
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1721
	if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1722
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1723
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1724
	/* translators: revision date format, see http://php.net/date */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1725
	$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1726
	/* translators: 1: date */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1727
	$autosavef = _x( '%1$s [Autosave]', 'post revision title extra' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1728
	/* translators: 1: date */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1729
	$currentf  = _x( '%1$s [Current Revision]', 'post revision title extra' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1730
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1731
	$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1732
	if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1733
		$date = "<a href='$link'>$date</a>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1734
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1735
	if ( !wp_is_post_revision( $revision ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1736
		$date = sprintf( $currentf, $date );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1737
	elseif ( wp_is_post_autosave( $revision ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1738
		$date = sprintf( $autosavef, $date );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1739
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1740
	return $date;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1741
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1742
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1743
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1744
 * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1745
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1746
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1747
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1748
 * @param int|object $revision Revision ID or revision object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1749
 * @param bool $link Optional, default is true. Link to revisions's page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1750
 * @return string gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1751
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1752
function wp_post_revision_title_expanded( $revision, $link = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1753
	if ( !$revision = get_post( $revision ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1754
		return $revision;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1755
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1756
	if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1757
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1758
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1759
	$author = get_the_author_meta( 'display_name', $revision->post_author );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1760
	/* translators: revision date format, see http://php.net/date */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1761
	$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1762
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1763
	$gravatar = get_avatar( $revision->post_author, 24 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1764
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1765
	$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1766
	if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1767
		$date = "<a href='$link'>$date</a>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1768
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1769
	$revision_date_author = sprintf(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1770
		/* translators: post revision title: 1: author avatar, 2: author name, 3: time ago, 4: date */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1771
		_x( '%1$s %2$s, %3$s ago (%4$s)', 'post revision title' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1772
		$gravatar,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1773
		$author,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1774
		human_time_diff( strtotime( $revision->post_modified ), current_time( 'timestamp' ) ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1775
		$date
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1776
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1777
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1778
	$autosavef = __( '%1$s [Autosave]' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1779
	$currentf  = __( '%1$s [Current Revision]' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1780
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1781
	if ( !wp_is_post_revision( $revision ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1782
		$revision_date_author = sprintf( $currentf, $revision_date_author );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1783
	elseif ( wp_is_post_autosave( $revision ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1784
		$revision_date_author = sprintf( $autosavef, $revision_date_author );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1785
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1786
	return $revision_date_author;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1787
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1788
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1789
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1790
 * Display list of a post's revisions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1791
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1792
 * Can output either a UL with edit links or a TABLE with diff interface, and
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1793
 * restore action links.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1794
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1795
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1796
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1797
 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1798
 * @param string      $type    'all' (default), 'revision' or 'autosave'
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1799
 * @return null
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1800
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1801
function wp_list_post_revisions( $post_id = 0, $type = 'all' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1802
	if ( ! $post = get_post( $post_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1803
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
	// $args array with (parent, format, right, left, type) deprecated since 3.6
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1806
	if ( is_array( $type ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1807
		$type = ! empty( $type['type'] ) ? $type['type']  : $type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1808
		_deprecated_argument( __FUNCTION__, '3.6' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1809
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1810
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1811
	if ( ! $revisions = wp_get_post_revisions( $post->ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1812
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1813
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1814
	$rows = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1815
	foreach ( $revisions as $revision ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1816
		if ( ! current_user_can( 'read_post', $revision->ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1817
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1818
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1819
		$is_autosave = wp_is_post_autosave( $revision );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1820
		if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1821
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1822
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1823
		$rows .= "\t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1824
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1825
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1826
	echo "<div class='hide-if-js'><p>" . __( 'JavaScript must be enabled to use this feature.' ) . "</p></div>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1827
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1828
	echo "<ul class='post-revisions hide-if-no-js'>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1829
	echo $rows;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1830
	echo "</ul>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1831
}