wp/wp-includes/link-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 Link 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
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Template
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * Display the permalink for the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
function the_permalink() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
	 * Filter the display of the permalink for the current post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    20
	 * @param string $permalink The permalink for the current post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	echo esc_url( apply_filters( 'the_permalink', get_permalink() ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
 * Retrieve trailing slash string, if blog set for adding trailing slashes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
 * Conditionally adds a trailing slash if the permalink structure has a trailing
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
 * slash, strips the trailing slash if not. The string is passed through the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
 * 'user_trailingslashit' filter. Will remove trailing slash from string, if
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
 * blog is not set to have them.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
 * @uses $wp_rewrite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
 * @param string $string URL with or without a trailing slash.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
 * @param string $type_of_url The type of URL being considered (e.g. single, category, etc) for use in the filter.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    38
 * @return string The URL with the trailing slash appended or stripped.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
function user_trailingslashit($string, $type_of_url = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	if ( $wp_rewrite->use_trailing_slashes )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
		$string = trailingslashit($string);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
		$string = untrailingslashit($string);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
	 * Filter the trailing slashed string, depending on whether the site is set
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    49
	 * to use training slashes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    50
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    51
	 * @since 2.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
	 * @param string $string      URL with or without a trailing slash.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    54
	 * @param string $type_of_url The type of URL being considered. Accepts 'single', 'single_trackback',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
	 *                            'single_feed', 'single_paged', 'feed', 'category', 'page', 'year',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    56
	 *                            'month', 'day', 'paged', 'post_type_archive'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    57
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    58
	$string = apply_filters( 'user_trailingslashit', $string, $type_of_url );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	return $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
 * Display permalink anchor for current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
 * The permalink mode title will use the post title for the 'a' element 'id'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
 * attribute. The id mode uses 'post-' with the post ID for the 'id' attribute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
 * @param string $mode Permalink mode can be either 'title', 'id', or default, which is 'id'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
function permalink_anchor( $mode = 'id' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
	$post = get_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
	switch ( strtolower( $mode ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
		case 'title':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
			$title = sanitize_title( $post->post_title ) . '-' . $post->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
			echo '<a id="'.$title.'"></a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
		case 'id':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
		default:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
			echo '<a id="post-' . $post->ID . '"></a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
 * Retrieve full permalink for current post or post ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
 * This function is an alias for get_permalink().
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    90
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    91
 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    92
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
 * @see get_permalink()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
 * @param int|WP_Post $id        Optional. Post ID or post object. Default is the current post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
 * @param bool        $leavename Optional. Whether to keep post name or page name. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    97
 * @return string|bool The permalink URL or false if post does not exist.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
function get_the_permalink( $id = 0, $leavename = false ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
	return get_permalink( $id, $leavename );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
 * Retrieve full permalink for current post or post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   105
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   108
 * @param int|WP_Post $id        Optional. Post ID or post object. Default current post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   109
 * @param bool        $leavename Optional. Whether to keep post name or page name. Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
 * @return string|bool The permalink URL or false if post does not exist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
function get_permalink( $id = 0, $leavename = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
	$rewritecode = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
		'%year%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
		'%monthnum%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
		'%day%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		'%hour%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
		'%minute%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
		'%second%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
		$leavename? '' : '%postname%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
		'%post_id%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
		'%category%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
		'%author%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
		$leavename? '' : '%pagename%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
	if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
		$post = $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
		$sample = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
		$post = get_post($id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
		$sample = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
	if ( empty($post->ID) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
	if ( $post->post_type == 'page' )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
		return get_page_link($post, $leavename, $sample);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
	elseif ( $post->post_type == 'attachment' )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
		return get_attachment_link( $post, $leavename );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
	elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   143
		return get_post_permalink($post, $leavename, $sample);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
	$permalink = get_option('permalink_structure');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   147
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
	 * Filter the permalink structure for a post before token replacement occurs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
	 * Only applies to posts with post_type of 'post'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
	 * @param string  $permalink The site's permalink structure.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
	 * @param WP_Post $post      The post in question.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
	 * @param bool    $leavename Whether to keep the post name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   157
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
	$permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   160
	if ( '' != $permalink && !in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
		$unixtime = strtotime($post->post_date);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
		$category = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
		if ( strpos($permalink, '%category%') !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
			$cats = get_the_category($post->ID);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
			if ( $cats ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
				usort($cats, '_usort_terms_by_ID'); // order by ID
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   168
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   169
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
				 * Filter the category that gets used in the %category% permalink token.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   171
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
				 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
				 * @param stdClass $cat  The category to use in the permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
				 * @param array    $cats Array of all categories associated with the post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
				 * @param WP_Post  $post The post in question.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
				 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
				$category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
				$category_object = get_term( $category_object, 'category' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
				$category = $category_object->slug;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
				if ( $parent = $category_object->parent )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
					$category = get_category_parents($parent, false, '/', true) . $category;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
			// show default category in permalinks, without
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
			// having to assign it explicitly
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
			if ( empty($category) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
				$default_category = get_term( get_option( 'default_category' ), 'category' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
				$category = is_wp_error( $default_category ) ? '' : $default_category->slug;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
		$author = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
		if ( strpos($permalink, '%author%') !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
			$authordata = get_userdata($post->post_author);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
			$author = $authordata->user_nicename;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
		$date = explode(" ",date('Y m d H i s', $unixtime));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
		$rewritereplace =
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
		array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
			$date[0],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
			$date[1],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
			$date[2],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
			$date[3],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
			$date[4],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
			$date[5],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
			$post->post_name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
			$post->ID,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
			$category,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
			$author,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
			$post->post_name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
		$permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
		$permalink = user_trailingslashit($permalink, 'single');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
	} else { // if they're not using the fancy permalink option
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
		$permalink = home_url('?p=' . $post->ID);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   219
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   220
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   221
	 * Filter the permalink for a post.
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
	 * Only applies to posts with post_type of 'post'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   224
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   225
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   226
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
	 * @param string  $permalink The post's permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   228
	 * @param WP_Post $post      The post in question.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   229
	 * @param bool    $leavename Whether to keep the post name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   230
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   231
	return apply_filters( 'post_link', $permalink, $post, $leavename );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
}
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
 * Retrieve the permalink for a post with a custom post type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
 * @param int $id Optional. Post ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
 * @param bool $leavename Optional, defaults to false. Whether to keep post name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
 * @param bool $sample Optional, defaults to false. Is it a sample permalink.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
 * @return string The post permalink.
0
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_post_permalink( $id = 0, $leavename = false, $sample = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
	global $wp_rewrite;
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($id);
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 ( is_wp_error( $post ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
		return $post;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
	$post_link = $wp_rewrite->get_extra_permastruct($post->post_type);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
	$slug = $post->post_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   256
	$draft_or_pending = isset( $post->post_status ) && in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
	$post_type = get_post_type_object($post->post_type);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   260
	if ( $post_type->hierarchical ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
		$slug = get_page_uri( $id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   262
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
	if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
		if ( ! $leavename ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
			$post_link = str_replace("%$post->post_type%", $slug, $post_link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
		$post_link = home_url( user_trailingslashit($post_link) );
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
		if ( $post_type->query_var && ( isset($post->post_status) && !$draft_or_pending ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
			$post_link = add_query_arg($post_type->query_var, $slug, '');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
			$post_link = add_query_arg(array('post_type' => $post->post_type, 'p' => $post->ID), '');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
		$post_link = home_url($post_link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   277
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
	 * Filter the permalink for a post with a custom post type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   280
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   281
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   282
	 * @param string  $post_link The post's permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   283
	 * @param WP_Post $post      The post in question.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   284
	 * @param bool    $leavename Whether to keep the post name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   285
	 * @param bool    $sample    Is it a sample permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   286
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   287
	return apply_filters( 'post_type_link', $post_link, $post, $leavename, $sample );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
 * Retrieve permalink from post ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
 * @param mixed $deprecated Not used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
function post_permalink( $post_id = 0, $deprecated = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
	if ( !empty( $deprecated ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
		_deprecated_argument( __FUNCTION__, '1.3' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
	return get_permalink($post_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
 * Retrieve the permalink for current page or page ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
 * Respects page_on_front. Use this one.
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 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
 * @param int|object $post Optional. Post ID or object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
 * @param bool $leavename Optional, defaults to false. Whether to keep page name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
 * @param bool $sample Optional, defaults to false. Is it a sample permalink.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
 * @return string The page permalink.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
function get_page_link( $post = false, $leavename = false, $sample = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
	$post = get_post( $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
	if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
		$link = home_url('/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
		$link = _get_page_link( $post, $leavename, $sample );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
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
	 * Filter the permalink for a page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
	 * @param string $link    The page's permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
	 * @param int    $post_id The ID of the page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
	 * @param bool   $sample  Is it a sample permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   334
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
	return apply_filters( 'page_link', $link, $post->ID, $sample );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
}
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
 * Retrieve the page permalink.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
 * Ignores page_on_front. Internal use only.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
 * @param int|object $post Optional. Post ID or object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
 * @param bool $leavename Optional. Leave name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
 * @param bool $sample Optional. Sample permalink.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   349
 * @return string The page permalink.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
function _get_page_link( $post = false, $leavename = false, $sample = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
	$post = get_post( $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
	$draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
	$link = $wp_rewrite->get_page_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
	if ( !empty($link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
		if ( ! $leavename ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
			$link = str_replace('%pagename%', get_page_uri( $post ), $link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
		$link = home_url($link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
		$link = user_trailingslashit($link, 'page');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
		$link = home_url( '?page_id=' . $post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   371
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   372
	 * Filter the permalink for a non-page_on_front page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   373
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
	 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
	 * @param string $link    The page's permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   377
	 * @param int    $post_id The ID of the page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   378
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
	return apply_filters( '_get_page_link', $link, $post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
}
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
 * Retrieve permalink for attachment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
 * This can be used in the WordPress Loop or outside of it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
 * @param int|object $post Optional. Post ID or object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
 * @param bool $leavename Optional. Leave name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   391
 * @return string The attachment permalink.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
function get_attachment_link( $post = null, $leavename = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
	$link = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
	$post = get_post( $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
	$parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
	if ( $wp_rewrite->using_permalinks() && $parent ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
		if ( 'page' == $parent->post_type )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
			$parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
			$parentlink = get_permalink( $post->post_parent );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
		if ( is_numeric($post->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
			$name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
			$name = $post->post_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
		if ( strpos($parentlink, '?') === false )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
			$link = user_trailingslashit( trailingslashit($parentlink) . '%postname%' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
		if ( ! $leavename )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
			$link = str_replace( '%postname%', $name, $link );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
	if ( ! $link )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
		$link = home_url( '/?attachment_id=' . $post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   422
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   423
	 * Filter the permalink for an attachment.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   424
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   425
	 * @since 2.0.0
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
	 * @param string $link    The attachment's permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
	 * @param int    $post_id Attachment ID.
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
	return apply_filters( 'attachment_link', $link, $post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
 * Retrieve the permalink for the year archives.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
 * @param int|bool $year False for current year or year for permalink.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   439
 * @return string The permalink for the specified year archive.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
function get_year_link($year) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	if ( !$year )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
		$year = gmdate('Y', current_time('timestamp'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
	$yearlink = $wp_rewrite->get_year_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
	if ( !empty($yearlink) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
		$yearlink = str_replace('%year%', $year, $yearlink);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
		$yearlink = home_url( user_trailingslashit( $yearlink, 'year' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   450
		$yearlink = home_url( '?m=' . $year );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   452
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   453
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   454
	 * Filter the year archive permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   455
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   456
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   457
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   458
	 * @param string $yearlink Permalink for the year archive.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
	 * @param int    $year     Year for the archive.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   461
	return apply_filters( 'year_link', $yearlink, $year );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
 * Retrieve the permalink for the month archives with year.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
 * @param bool|int $year False for current year. Integer of year.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
 * @param bool|int $month False for current month. Integer of month.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
 * @return string The permalink for the specified month and year archive.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
function get_month_link($year, $month) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
	if ( !$year )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
		$year = gmdate('Y', current_time('timestamp'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
	if ( !$month )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
		$month = gmdate('m', current_time('timestamp'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
	$monthlink = $wp_rewrite->get_month_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
	if ( !empty($monthlink) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
		$monthlink = str_replace('%year%', $year, $monthlink);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
		$monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
		$monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
	} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
		$monthlink = home_url( '?m=' . $year . zeroise( $month, 2 ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   488
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   489
	 * Filter the month archive permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   492
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   493
	 * @param string $monthlink Permalink for the month archive.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
	 * @param int    $year      Year for the archive.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
	 * @param int    $month     The month for the archive.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   497
	return apply_filters( 'month_link', $monthlink, $year, $month );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
 * Retrieve the permalink for the day archives with year and month.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
 * @param bool|int $year False for current year. Integer of year.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
 * @param bool|int $month False for current month. Integer of month.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
 * @param bool|int $day False for current day. Integer of day.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   508
 * @return string The permalink for the specified day, month, and year archive.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
function get_day_link($year, $month, $day) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
	if ( !$year )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
		$year = gmdate('Y', current_time('timestamp'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
	if ( !$month )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
		$month = gmdate('m', current_time('timestamp'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
	if ( !$day )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
		$day = gmdate('j', current_time('timestamp'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
	$daylink = $wp_rewrite->get_day_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
	if ( !empty($daylink) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
		$daylink = str_replace('%year%', $year, $daylink);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
		$daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
		$daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   524
		$daylink = home_url( user_trailingslashit( $daylink, 'day' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
	} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   526
		$daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   528
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   529
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   530
	 * Filter the day archive permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   531
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   532
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   533
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   534
	 * @param string $daylink Permalink for the day archive.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   535
	 * @param int    $year    Year for the archive.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   536
	 * @param int    $month   Month for the archive.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   537
	 * @param int    $day     The day for the archive.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   538
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   539
	return apply_filters( 'day_link', $daylink, $year, $month, $day );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
 * Display the permalink for the feed type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
 * @param string $anchor The link's anchor text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
 * @param string $feed Optional, defaults to default feed. Feed type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
function the_feed_link( $anchor, $feed = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
	$link = '<a href="' . esc_url( get_feed_link( $feed ) ) . '">' . $anchor . '</a>';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   552
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   553
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   554
	 * Filter the feed link anchor tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   555
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   556
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   557
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   558
	 * @param string $link The complete anchor tag for a feed link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   559
	 * @param string $feed The feed type, or an empty string for the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   560
	 *                     default feed type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   561
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
	echo apply_filters( 'the_feed_link', $link, $feed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
 * Retrieve the permalink for the feed type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
 * @param string $feed Optional, defaults to default feed. Feed type.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   571
 * @return string The feed permalink.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
function get_feed_link($feed = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
	$permalink = $wp_rewrite->get_feed_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
	if ( '' != $permalink ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
		if ( false !== strpos($feed, 'comments_') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
			$feed = str_replace('comments_', '', $feed);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
			$permalink = $wp_rewrite->get_comment_feed_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
		if ( get_default_feed() == $feed )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
			$feed = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
		$permalink = str_replace('%feed%', $feed, $permalink);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
		$permalink = preg_replace('#/+#', '/', "/$permalink");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
		$output =  home_url( user_trailingslashit($permalink, 'feed') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
		if ( empty($feed) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
			$feed = get_default_feed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
		if ( false !== strpos($feed, 'comments_') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
			$feed = str_replace('comments_', 'comments-', $feed);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
		$output = home_url("?feed={$feed}");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   599
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   600
	 * Filter the feed type permalink.
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
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   603
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   604
	 * @param string $output The feed permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   605
	 * @param string $feed   Feed type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   606
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   607
	return apply_filters( 'feed_link', $output, $feed );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
 * Retrieve the permalink for the post comments feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
 * @param int $post_id Optional. Post ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
 * @param string $feed Optional. Feed type.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   617
 * @return string The permalink for the comments feed for the given post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
function get_post_comments_feed_link($post_id = 0, $feed = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
	$post_id = absint( $post_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
	if ( ! $post_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
		$post_id = get_the_ID();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
	if ( empty( $feed ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
		$feed = get_default_feed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
	if ( '' != get_option('permalink_structure') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
		if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
			$url = _get_page_link( $post_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
			$url = get_permalink($post_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
		$url = trailingslashit($url) . 'feed';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
		if ( $feed != get_default_feed() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
			$url .= "/$feed";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
		$url = user_trailingslashit($url, 'single_feed');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
		$type = get_post_field('post_type', $post_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
		if ( 'page' == $type )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
			$url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id ), home_url( '/' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
			$url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id ), home_url( '/' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   646
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   647
	 * Filter the post comments feed permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   648
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   649
	 * @since 1.5.1
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
	 * @param string $url Post comments feed permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   652
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   653
	return apply_filters( 'post_comments_feed_link', $url );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
 * Display the comment feed link for a post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
 * Prints out the comment feed link for a post. Link text is placed in the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
 * anchor. If no link text is specified, default text is used. If no post ID is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
 * specified, the current post is used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
 * @param string $link_text Descriptive text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
 * @param int $post_id Optional post ID. Default to current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
 * @param string $feed Optional. Feed format.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
 * @return string Link to the comment feed for the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
	$url = esc_url( get_post_comments_feed_link( $post_id, $feed ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
	if ( empty($link_text) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
		$link_text = __('Comments Feed');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   675
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   676
	 * Filter the post comment feed link anchor tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   677
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   678
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   679
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   680
	 * @param string $link    The complete anchor tag for the comment feed link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   681
	 * @param int    $post_id Post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   682
	 * @param string $feed    The feed type, or an empty string for the default feed type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   683
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
	echo apply_filters( 'post_comments_feed_link_html', "<a href='$url'>$link_text</a>", $post_id, $feed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
 * Retrieve the feed link for a given author.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
 * Returns a link to the feed for all posts by a given author. A specific feed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
 * can be requested or left blank to get the default feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
 * @param int $author_id ID of an author.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
 * @param string $feed Optional. Feed type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
 * @return string Link to the feed for the author specified by $author_id.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
function get_author_feed_link( $author_id, $feed = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
	$author_id = (int) $author_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
	$permalink_structure = get_option('permalink_structure');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
	if ( empty($feed) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
		$feed = get_default_feed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
	if ( '' == $permalink_structure ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
		$link = home_url("?feed=$feed&amp;author=" . $author_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
		$link = get_author_posts_url($author_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
		if ( $feed == get_default_feed() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
			$feed_link = 'feed';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
			$feed_link = "feed/$feed";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
		$link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
5
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
	 * Filter the feed link for a given author.
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
	 * @since 1.5.1
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   722
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   723
	 * @param string $link The author feed link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   724
	 * @param string $feed Feed type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   725
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   726
	$link = apply_filters( 'author_feed_link', $link, $feed );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
	return $link;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
 * Retrieve the feed link for a category.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
 * Returns a link to the feed for all posts in a given category. A specific feed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
 * can be requested or left blank to get the default feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
 * @param int $cat_id ID of a category.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
 * @param string $feed Optional. Feed type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
 * @return string Link to the feed for the category specified by $cat_id.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
function get_category_feed_link($cat_id, $feed = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
	return get_term_feed_link($cat_id, 'category', $feed);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
 * Retrieve the feed link for a term.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
 * Returns a link to the feed for all posts in a given term. A specific feed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
 * can be requested or left blank to get the default feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   753
 * @since 3.0.0
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
 * @param int $term_id ID of a category.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
 * @param string $taxonomy Optional. Taxonomy of $term_id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
 * @param string $feed Optional. Feed type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
 * @return string Link to the feed for the term specified by $term_id and $taxonomy.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
	$term_id = ( int ) $term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
	$term = get_term( $term_id, $taxonomy  );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
	if ( empty( $term ) || is_wp_error( $term ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
	if ( empty( $feed ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
		$feed = get_default_feed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
	$permalink_structure = get_option( 'permalink_structure' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
	if ( '' == $permalink_structure ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
		if ( 'category' == $taxonomy ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
			$link = home_url("?feed=$feed&amp;cat=$term_id");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
		elseif ( 'post_tag' == $taxonomy ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
			$link = home_url("?feed=$feed&amp;tag=$term->slug");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
			$t = get_taxonomy( $taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
			$link = home_url("?feed=$feed&amp;$t->query_var=$term->slug");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
		$link = get_term_link( $term_id, $term->taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
		if ( $feed == get_default_feed() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
			$feed_link = 'feed';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
			$feed_link = "feed/$feed";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
		$link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   793
	if ( 'category' == $taxonomy ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   794
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   795
		 * Filter the category feed link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   796
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   797
		 * @since 1.5.1
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   798
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   799
		 * @param string $link The category feed link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   800
		 * @param string $feed Feed type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   801
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
		$link = apply_filters( 'category_feed_link', $link, $feed );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   803
	} elseif ( 'post_tag' == $taxonomy ) {
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
		 * Filter the post tag feed link.
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
		 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   808
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   809
		 * @param string $link The tag feed link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   810
		 * @param string $feed Feed type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   811
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
		$link = apply_filters( 'tag_feed_link', $link, $feed );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   813
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   814
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   815
		 * Filter the feed link for a taxonomy other than 'category' or 'post_tag'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   816
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   817
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   818
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   819
		 * @param string $link The taxonomy feed link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   820
		 * @param string $feed Feed type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   821
		 * @param string $feed The taxonomy name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   822
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
		$link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   824
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
	return $link;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
 * Retrieve permalink for feed of tag.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
 * @param int $tag_id Tag ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
 * @param string $feed Optional. Feed type.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   836
 * @return string The feed permalink for the given tag.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
function get_tag_feed_link($tag_id, $feed = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
	return get_term_feed_link($tag_id, 'post_tag', $feed);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
 * Retrieve edit tag link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
 * @param int $tag_id Tag ID
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
 * @param string $taxonomy Taxonomy
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   849
 * @return string The edit tag link URL for the given tag.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
function get_edit_tag_link( $tag_id, $taxonomy = 'post_tag' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   852
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   853
	 * Filter the edit link for a tag (or term in another taxonomy).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   854
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   855
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   856
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   857
	 * @param string $link The term edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   858
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
	return apply_filters( 'get_edit_tag_link', get_edit_term_link( $tag_id, $taxonomy ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
 * Display or retrieve edit tag link with formatting.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
 * @param string $link Optional. Anchor text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
 * @param string $before Optional. Display before edit link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
 * @param string $after Optional. Display after edit link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
 * @param object $tag Tag object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
 * @return string HTML content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
	$link = edit_term_link( $link, '', '', $tag, false );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   875
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   876
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   877
	 * Filter the anchor tag for the edit link for a tag (or term in another taxonomy).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   878
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   879
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   880
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   881
	 * @param string $link The anchor tag for the edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   882
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
	echo $before . apply_filters( 'edit_tag_link', $link ) . $after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
 * Retrieve edit term url.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   891
 * @param int    $term_id     Term ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   892
 * @param string $taxonomy    Taxonomy.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   893
 * @param string $object_type The object type. Used to highlight the proper post type menu on the linked page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   894
 *                            Defaults to the first object_type associated with the taxonomy.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   895
 * @return string The edit term link URL for the given term.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
	$tax = get_taxonomy( $taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
	if ( !current_user_can( $tax->cap->edit_terms ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
	$term = get_term( $term_id, $taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
	$args = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
		'action' => 'edit',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
		'taxonomy' => $taxonomy,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
		'tag_ID' => $term->term_id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   910
	if ( $object_type ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
		$args['post_type'] = $object_type;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   912
	} else if ( ! empty( $tax->object_type ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   913
		$args['post_type'] = reset( $tax->object_type );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   914
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
	$location = add_query_arg( $args, admin_url( 'edit-tags.php' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   918
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   919
	 * Filter the edit link for a term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   920
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   921
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   922
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   923
	 * @param string $location    The edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   924
	 * @param int    $term_id     Term ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   925
	 * @param string $taxonomy    Taxonomy name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   926
	 * @param string $object_type The object type (eg. the post type).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   927
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
	return apply_filters( 'get_edit_term_link', $location, $term_id, $taxonomy, $object_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
 * Display or retrieve edit term link with formatting.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
 * @param string $link Optional. Anchor text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
 * @param string $before Optional. Display before edit link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
 * @param string $after Optional. Display after edit link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
 * @param object $term Term object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
 * @return string HTML content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
	if ( is_null( $term ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
		$term = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
	if ( ! $term )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
	$tax = get_taxonomy( $term->taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
	if ( ! current_user_can( $tax->cap->edit_terms ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
	if ( empty( $link ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
		$link = __('Edit This');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
	$link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '">' . $link . '</a>';
5
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
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   959
	 * Filter the anchor tag for the edit link of a term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   960
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   961
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   962
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   963
	 * @param string $link    The anchor tag for the edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   964
	 * @param int    $term_id Term ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   965
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
	$link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
	if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
		echo $link;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
		return $link;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   975
 * Retrieve permalink for search.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   976
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   977
 * @since  3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   978
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   979
 * @param string $query Optional. The query string to use. If empty the current query is used.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   980
 * @return string The search permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   981
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
function get_search_link( $query = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
	if ( empty($query) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
		$search = get_search_query( false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
		$search = stripslashes($query);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
	$permastruct = $wp_rewrite->get_search_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
	if ( empty( $permastruct ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
		$link = home_url('?s=' . urlencode($search) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
		$search = urlencode($search);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
		$search = str_replace('%2F', '/', $search); // %2F(/) is not valid within a URL, send it unencoded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
		$link = str_replace( '%search%', $search, $permastruct );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
		$link = home_url( user_trailingslashit( $link, 'search' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1001
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1002
	 * Filter the search permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1003
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1004
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1005
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1006
	 * @param string $link   Search permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1007
	 * @param string $search The URL-encoded search term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1008
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
	return apply_filters( 'search_link', $link, $search );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
 * Retrieve the permalink for the feed of the search results.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
 * @param string $search_query Optional. Search query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
 * @param string $feed Optional. Feed type.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1019
 * @return string The search results feed permalink.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
function get_search_feed_link($search_query = '', $feed = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
	$link = get_search_link($search_query);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
	if ( empty($feed) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
		$feed = get_default_feed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
	$permastruct = $wp_rewrite->get_search_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
	if ( empty($permastruct) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
		$link = add_query_arg('feed', $feed, $link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
		$link = trailingslashit($link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
		$link .= "feed/$feed/";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1037
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1038
	 * Filter the search feed link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1039
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1040
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1041
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1042
	 * @param string $link Search feed link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1043
	 * @param string $feed Feed type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1044
	 * @param string $type The search type. One of 'posts' or 'comments'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1045
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1046
	$link = apply_filters( 'search_feed_link', $link, $feed, 'posts' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
	return $link;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1049
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1050
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1051
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
 * Retrieve the permalink for the comments feed of the search results.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1055
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
 * @param string $search_query Optional. Search query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
 * @param string $feed Optional. Feed type.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1058
 * @return string The comments feed search results permalink.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
function get_search_comments_feed_link($search_query = '', $feed = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
	if ( empty($feed) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1064
		$feed = get_default_feed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1066
	$link = get_search_feed_link($search_query, $feed);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1067
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
	$permastruct = $wp_rewrite->get_search_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
	if ( empty($permastruct) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1071
		$link = add_query_arg('feed', 'comments-' . $feed, $link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
		$link = add_query_arg('withcomments', 1, $link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1075
	/** This filter is documented in wp-includes/link-template.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1076
	$link = apply_filters('search_feed_link', $link, $feed, 'comments');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
	return $link;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
 * Retrieve the permalink for a post type archive.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
 * @param string $post_type Post type
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1087
 * @return string The post type archive permalink.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
function get_post_type_archive_link( $post_type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
	if ( ! $post_type_obj = get_post_type_object( $post_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1094
	if ( ! $post_type_obj->has_archive )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1095
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1097
	if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1098
		$struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
		if ( $post_type_obj->rewrite['with_front'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
			$struct = $wp_rewrite->front . $struct;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
			$struct = $wp_rewrite->root . $struct;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
		$link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
		$link = home_url( '?post_type=' . $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1106
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1108
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1109
	 * Filter the post type archive permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1110
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1111
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1112
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1113
	 * @param string $link      The post type archive permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1114
	 * @param string $post_type Post type name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1115
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
	return apply_filters( 'post_type_archive_link', $link, $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
 * Retrieve the permalink for a post type archive feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1123
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1124
 * @param string $post_type Post type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
 * @param string $feed Optional. Feed type
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1126
 * @return string The post type feed permalink.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
function get_post_type_archive_feed_link( $post_type, $feed = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
	$default_feed = get_default_feed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
	if ( empty( $feed ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
		$feed = $default_feed;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
	if ( ! $link = get_post_type_archive_link( $post_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
	$post_type_obj = get_post_type_object( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
	if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['feeds'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1138
		$link = trailingslashit( $link );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
		$link .= 'feed/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1140
		if ( $feed != $default_feed )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
			$link .= "$feed/";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
		$link = add_query_arg( 'feed', $feed, $link );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1144
	}
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
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1147
	 * Filter the post type archive feed link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1148
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1149
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1150
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1151
	 * @param string $link The post type archive feed link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1152
	 * @param string $feed Feed type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1153
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
	return apply_filters( 'post_type_archive_feed_link', $link, $feed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
 * Retrieve edit posts link for post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
 * Can be used within the WordPress loop or outside of it. Can be used with
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
 * pages, posts, attachments, and revisions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
 * @param int $id Optional. Post ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
 * @param string $context Optional, defaults to display. How to write the '&', defaults to '&amp;'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1167
 * @return string The edit post link for the given post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
function get_edit_post_link( $id = 0, $context = 'display' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
	if ( ! $post = get_post( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
	if ( 'revision' === $post->post_type )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
		$action = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
	elseif ( 'display' == $context )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
		$action = '&amp;action=edit';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
		$action = '&action=edit';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
	$post_type_object = get_post_type_object( $post->post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
	if ( !$post_type_object )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1183
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
	if ( !current_user_can( 'edit_post', $post->ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
5
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
	 * Filter the post edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1189
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1190
	 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1191
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1192
	 * @param string $link    The edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1193
	 * @param int    $post_id Post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1194
	 * @param string $context The link context. If set to 'display' then ampersands
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1195
	 *                        are encoded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1196
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1197
	return apply_filters( 'get_edit_post_link', admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) ), $post->ID, $context );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
 * Display edit post link for post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1205
 * @param string $text Optional. Anchor text.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
 * @param string $before Optional. Display before edit link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
 * @param string $after Optional. Display after edit link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
 * @param int $id Optional. Post ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1210
function edit_post_link( $text = null, $before = '', $after = '', $id = 0 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1211
	if ( ! $post = get_post( $id ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
		return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1213
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1214
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1215
	if ( ! $url = get_edit_post_link( $post->ID ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
		return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1217
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1218
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1219
	if ( null === $text ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1220
		$text = __( 'Edit This' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1221
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1222
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1223
	$link = '<a class="post-edit-link" href="' . $url . '">' . $text . '</a>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1224
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
	 * Filter the post edit link anchor tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1227
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1228
	 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1229
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1230
	 * @param string $link    Anchor tag for the edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1231
	 * @param int    $post_id Post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1232
	 * @param string $text    Anchor text.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1233
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1234
	echo $before . apply_filters( 'edit_post_link', $link, $post->ID, $text ) . $after;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1235
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1236
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1238
 * Retrieve delete posts link for post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1239
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1240
 * Can be used within the WordPress loop or outside of it, with any post type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1243
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1244
 * @param int $id Optional. Post ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
 * @param string $deprecated Not used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
 * @param bool $force_delete Whether to bypass trash and force deletion. Default is false.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1247
 * @return string The delete post link URL for the given post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1249
function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
	if ( ! empty( $deprecated ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
		_deprecated_argument( __FUNCTION__, '3.0' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
	if ( !$post = get_post( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
	$post_type_object = get_post_type_object( $post->post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
	if ( !$post_type_object )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
	if ( !current_user_can( 'delete_post', $post->ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1263
	$action = ( $force_delete || !EMPTY_TRASH_DAYS ) ? 'delete' : 'trash';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
	$delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1267
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1268
	 * Filter the post delete link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1269
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1270
	 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1271
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1272
	 * @param string $link         The delete link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1273
	 * @param int    $post_id      Post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1274
	 * @param bool   $force_delete Whether to bypass the trash and force deletion. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1275
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
	return apply_filters( 'get_delete_post_link', wp_nonce_url( $delete_link, "$action-post_{$post->ID}" ), $post->ID, $force_delete );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
 * Retrieve edit comment link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
 * @param int $comment_id Optional. Comment ID.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1285
 * @return string The edit comment link URL for the given comment.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
function get_edit_comment_link( $comment_id = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
	$comment = get_comment( $comment_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
	if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
	$location = admin_url('comment.php?action=editcomment&amp;c=') . $comment->comment_ID;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1294
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1295
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1296
	 * Filter the comment edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1297
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1298
	 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1299
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1300
	 * @param string $location The edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1301
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
	return apply_filters( 'get_edit_comment_link', $location );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1304
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
 * Display edit comment link with formatting.
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
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1310
 * @param string $text Optional. Anchor text.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
 * @param string $before Optional. Display before edit link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
 * @param string $after Optional. Display after edit link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1314
function edit_comment_link( $text = null, $before = '', $after = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
	global $comment;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1317
	if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
		return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1319
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1320
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1321
	if ( null === $text ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1322
		$text = __( 'Edit This' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1323
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1324
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1325
	$link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '">' . $text . '</a>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1326
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1327
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1328
	 * Filter the comment edit link anchor tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1329
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1330
	 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1331
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1332
	 * @param string $link       Anchor tag for the edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1333
	 * @param int    $comment_id Comment ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1334
	 * @param string $text       Anchor text.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1335
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1336
	echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID, $text ) . $after;
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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
 * Display edit bookmark (literally a URL external to blog) link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
 * @since 2.7.0
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
 * @param int|stdClass $link Optional. Bookmark ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1345
 * @return string The edit bookmark link URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
function get_edit_bookmark_link( $link = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
	$link = get_bookmark( $link );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
	if ( !current_user_can('manage_links') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
	$location = admin_url('link.php?action=edit&amp;link_id=') . $link->link_id;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1354
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1355
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1356
	 * Filter the bookmark (link) edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1357
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1358
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1359
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1360
	 * @param string $location The edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1361
	 * @param int    $link_id  Bookmark ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1362
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
	return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
 * Display edit bookmark (literally a URL external to blog) link anchor content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
 * @param string $link Optional. Anchor text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
 * @param string $before Optional. Display before edit link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
 * @param string $after Optional. Display after edit link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
 * @param int $bookmark Optional. Bookmark ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
	$bookmark = get_bookmark($bookmark);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1378
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1379
	if ( !current_user_can('manage_links') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1380
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1381
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
	if ( empty($link) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1383
		$link = __('Edit This');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1385
	$link = '<a href="' . get_edit_bookmark_link( $bookmark ) . '">' . $link . '</a>';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1386
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1387
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1388
	 * Filter the bookmark edit link anchor tag.
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
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1391
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1392
	 * @param string $link    Anchor tag for the edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1393
	 * @param int    $link_id Bookmark ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1394
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1395
	echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1396
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1397
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1398
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1399
 * Retrieve edit user link
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1400
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1401
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1402
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
 * @param int $user_id Optional. User ID. Defaults to the current user.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1404
 * @return string URL to edit user page or empty string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1405
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1406
function get_edit_user_link( $user_id = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1407
	if ( ! $user_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1408
		$user_id = get_current_user_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1409
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1410
	if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1411
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1412
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1413
	$user = get_userdata( $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1414
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
	if ( ! $user )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1416
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1417
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
	if ( get_current_user_id() == $user->ID )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
		$link = get_edit_profile_url( $user->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1421
		$link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1423
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1424
	 * Filter the user edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1425
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1426
	 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1427
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1428
	 * @param string $link    The edit link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1429
	 * @param int    $user_id User ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1430
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
	return apply_filters( 'get_edit_user_link', $link, $user->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1433
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
// Navigation links
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1435
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1436
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1437
 * Retrieve previous post that is adjacent to current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1438
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1441
 * @param bool         $in_same_term   Optional. Whether post should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1442
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1443
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1444
 * @return mixed       Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1445
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1446
function get_previous_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1447
	return get_adjacent_post( $in_same_term, $excluded_terms, true, $taxonomy );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1451
 * Retrieve next post that is adjacent to current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1455
 * @param bool         $in_same_term   Optional. Whether post should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1456
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1457
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1458
 * @return mixed       Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1459
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1460
function get_next_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1461
	return get_adjacent_post( $in_same_term, $excluded_terms, false, $taxonomy );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1462
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1463
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1464
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1465
 * Retrieve adjacent post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1467
 * Can either be next or previous post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1469
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1470
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1471
 * @param bool         $in_same_term   Optional. Whether post should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1472
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1473
 * @param bool         $previous       Optional. Whether to retrieve previous post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1474
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1475
 * @return mixed       Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1476
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1477
function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1478
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1479
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1480
	if ( ( ! $post = get_post() ) || ! taxonomy_exists( $taxonomy ) )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1481
		return null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1482
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1483
	$current_post_date = $post->post_date;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1484
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1485
	$join = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1486
	$where = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1487
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1488
	if ( $in_same_term || ! empty( $excluded_terms ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1489
		$join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1490
		$where = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1491
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1492
		if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1493
			// back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1494
			if ( false !== strpos( $excluded_terms, ' and ' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1495
				_deprecated_argument( __FUNCTION__, '3.3', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1496
				$excluded_terms = explode( ' and ', $excluded_terms );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1497
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1498
				$excluded_terms = explode( ',', $excluded_terms );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1499
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1500
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1501
			$excluded_terms = array_map( 'intval', $excluded_terms );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1502
		}
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
		if ( $in_same_term ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1505
			if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1506
				return '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1507
			$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1508
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1509
			// Remove any exclusions from the term array to include.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1510
			$term_array = array_diff( $term_array, (array) $excluded_terms );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1511
			$term_array = array_map( 'intval', $term_array );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1512
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1513
			if ( ! $term_array || is_wp_error( $term_array ) )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1514
				return '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1515
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1516
			$where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1517
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1518
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1519
		if ( ! empty( $excluded_terms ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1520
			$where .= " AND p.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships tr LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.term_id IN (" . implode( $excluded_terms, ',' ) . ') )';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1521
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1522
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1523
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1524
	// 'post_status' clause depends on the current user.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1525
	if ( is_user_logged_in() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1526
		$user_id = get_current_user_id();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1527
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1528
		$post_type_object = get_post_type_object( $post->post_type );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1529
		if ( empty( $post_type_object ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1530
			$post_type_cap    = $post->post_type;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1531
			$read_private_cap = 'read_private_' . $post_type_cap . 's';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1532
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1533
			$read_private_cap = $post_type_object->cap->read_private_posts;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1534
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1535
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1536
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1537
		 * Results should include private posts belonging to the current user, or private posts where the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1538
		 * current user has the 'read_private_posts' cap.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1539
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1540
		$private_states = get_post_stati( array( 'private' => true ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1541
		$where .= " AND ( p.post_status = 'publish'";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1542
		foreach ( (array) $private_states as $state ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1543
			if ( current_user_can( $read_private_cap ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1544
				$where .= $wpdb->prepare( " OR p.post_status = %s", $state );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1545
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1546
				$where .= $wpdb->prepare( " OR (p.post_author = %d AND p.post_status = %s)", $user_id, $state );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1547
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1548
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1549
		$where .= " )";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1550
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1551
		$where .= " AND p.post_status = 'publish'";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1552
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1553
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1554
	$adjacent = $previous ? 'previous' : 'next';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1555
	$op = $previous ? '<' : '>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1556
	$order = $previous ? 'DESC' : 'ASC';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1557
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1558
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1559
	 * Filter the JOIN clause in the SQL for an adjacent post query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1560
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1561
	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1562
	 * of adjacency, 'next' or 'previous'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1563
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1564
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1565
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1566
	 * @param string $join           The JOIN clause in the SQL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1567
	 * @param bool   $in_same_term   Whether post should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1568
	 * @param array  $excluded_terms Array of excluded term IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1569
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1570
	$join  = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_term, $excluded_terms );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1571
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1572
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1573
	 * Filter the WHERE clause in the SQL for an adjacent post query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1574
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1575
	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1576
	 * of adjacency, 'next' or 'previous'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1577
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1578
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1579
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1580
	 * @param string $where          The `WHERE` clause in the SQL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1581
	 * @param bool   $in_same_term   Whether post should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1582
	 * @param array  $excluded_terms Array of excluded term IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1583
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1584
	$where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare( "WHERE p.post_date $op %s AND p.post_type = %s $where", $current_post_date, $post->post_type ), $in_same_term, $excluded_terms );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1585
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1586
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1587
	 * Filter the ORDER BY clause in the SQL for an adjacent post query.
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
	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1590
	 * of adjacency, 'next' or 'previous'.
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
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1593
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1594
	 * @param string $order_by The `ORDER BY` clause in the SQL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1595
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1596
	$sort  = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1597
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1598
	$query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1599
	$query_key = 'adjacent_post_' . md5( $query );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1600
	$result = wp_cache_get( $query_key, 'counts' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1601
	if ( false !== $result ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1602
		if ( $result )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1603
			$result = get_post( $result );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1604
		return $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1605
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1606
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1607
	$result = $wpdb->get_var( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1608
	if ( null === $result )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1609
		$result = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1610
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1611
	wp_cache_set( $query_key, $result, 'counts' );
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
	if ( $result )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1614
		$result = get_post( $result );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1615
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1616
	return $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1617
}
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
 * Get adjacent post relational link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1621
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1622
 * Can either be next or previous post relational link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1623
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1624
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1625
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1626
 * @param string       $title          Optional. Link title format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1627
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1628
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1629
 * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1630
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1631
 * @return string The adjacent post relational link URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1632
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1633
function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1634
	if ( $previous && is_attachment() && $post = get_post() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1635
		$post = get_post( $post->post_parent );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1636
	else
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1637
		$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
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 ( empty( $post ) )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1640
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1641
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1642
	$post_title = the_title_attribute( array( 'echo' => false, 'post' => $post ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1643
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1644
	if ( empty( $post_title ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1645
		$post_title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1646
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1647
	$date = mysql2date( get_option( 'date_format' ), $post->post_date );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1648
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1649
	$title = str_replace( '%title', $post_title, $title );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1650
	$title = str_replace( '%date', $date, $title );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1651
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1652
	$link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1653
	$link .= esc_attr( $title );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1654
	$link .= "' href='" . get_permalink( $post ) . "' />\n";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1655
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1656
	$adjacent = $previous ? 'previous' : 'next';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1657
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1658
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1659
	 * Filter the adjacent post relational link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1660
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1661
	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1662
	 * of adjacency, 'next' or 'previous'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1663
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1664
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1665
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1666
	 * @param string $link The relational link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1667
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1668
	return apply_filters( "{$adjacent}_post_rel_link", $link );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1669
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1670
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1671
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1672
 * Display relational links for the posts adjacent to the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1674
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1675
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1676
 * @param string       $title          Optional. Link title format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1677
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1678
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1679
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1680
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1681
function adjacent_posts_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1682
	echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1683
	echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1684
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1685
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1686
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1687
 * Display relational links for the posts adjacent to the current post for single post pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1688
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1689
 * This is meant to be attached to actions like 'wp_head'. Do not call this directly in plugins or theme templates.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1691
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
function adjacent_posts_rel_link_wp_head() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1694
	if ( ! is_single() || is_attachment() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1695
		return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1696
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1697
	adjacent_posts_rel_link();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1698
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1699
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1700
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1701
 * Display relational link for the next post adjacent to the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1702
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1703
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1704
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1705
 * @param string       $title          Optional. Link title format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1706
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1707
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1708
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1709
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1710
function next_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1711
	echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1714
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1715
 * Display relational link for the previous post adjacent to the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1716
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1717
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1718
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1719
 * @param string       $title          Optional. Link title format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1720
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1721
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1722
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1723
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1724
function prev_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1725
	echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1726
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1727
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1728
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1729
 * Retrieve boundary post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1730
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1731
 * Boundary being either the first or last post by publish date within the constraints specified
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1732
 * by $in_same_term or $excluded_terms.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1733
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1734
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1735
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1736
 * @param bool         $in_same_term   Optional. Whether returned post should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1737
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1738
 * @param bool         $start          Optional. Whether to retrieve first or last post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1739
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1740
 * @return mixed Array containing the boundary post object if successful, null otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1741
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1742
function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1743
	$post = get_post();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1744
	if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1745
		return null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1746
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1747
	$query_args = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1748
		'posts_per_page' => 1,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1749
		'order' => $start ? 'ASC' : 'DESC',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1750
		'update_post_term_cache' => false,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1751
		'update_post_meta_cache' => false
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1752
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1753
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1754
	$term_array = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1755
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1756
	if ( ! is_array( $excluded_terms ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1757
		if ( ! empty( $excluded_terms ) )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1758
			$excluded_terms = explode( ',', $excluded_terms );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1759
		else
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1760
			$excluded_terms = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1761
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1762
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1763
	if ( $in_same_term || ! empty( $excluded_terms ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1764
		if ( $in_same_term )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1765
			$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1766
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1767
		if ( ! empty( $excluded_terms ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1768
			$excluded_terms = array_map( 'intval', $excluded_terms );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1769
			$excluded_terms = array_diff( $excluded_terms, $term_array );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1770
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1771
			$inverse_terms = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1772
			foreach ( $excluded_terms as $excluded_term )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1773
				$inverse_terms[] = $excluded_term * -1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1774
			$excluded_terms = $inverse_terms;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1775
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1776
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1777
		$query_args[ 'tax_query' ] = array( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1778
			'taxonomy' => $taxonomy,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1779
			'terms' => array_merge( $term_array, $excluded_terms )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1780
		) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1781
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1782
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1783
	return get_posts( $query_args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1784
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1785
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1786
/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1787
 * Get previous post link that is adjacent to the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1788
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1789
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1790
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1791
 * @param string       $format         Optional. Link anchor format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1792
 * @param string       $link           Optional. Link permalink format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1793
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1794
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1795
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1796
 * @return string The link URL of the previous post in relation to the current post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1797
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1798
function get_previous_post_link( $format = '&laquo; %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1799
	return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, true, $taxonomy );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1800
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1801
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1802
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1803
 * Display previous post link that is adjacent to the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
 * @since 1.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1806
 * @see get_previous_post_link()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1807
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1808
 * @param string       $format         Optional. Link anchor format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1809
 * @param string       $link           Optional. Link permalink format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1810
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1811
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1812
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1813
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1814
function previous_post_link( $format = '&laquo; %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1815
	echo get_previous_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1816
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1817
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1818
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1819
 * Get next post link that is adjacent to the current post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1820
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1821
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1822
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1823
 * @param string       $format         Optional. Link anchor format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1824
 * @param string       $link           Optional. Link permalink format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1825
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1826
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1827
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1828
 * @return string The link URL of the next post in relation to the current post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1829
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1830
function get_next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1831
	return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, false, $taxonomy );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1832
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1833
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1834
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1835
 * Display next post link that is adjacent to the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1836
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1837
 * @since 1.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1838
 * @see get_next_post_link()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1839
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1840
 * @param string       $format         Optional. Link anchor format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1841
 * @param string       $link           Optional. Link permalink format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1842
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1843
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1844
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1845
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1846
function next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1847
	 echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1848
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1849
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1850
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1851
 * Get adjacent post link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1852
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1853
 * Can be either next post link or previous.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1854
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1855
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1856
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1857
 * @param string       $format         Link anchor format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1858
 * @param string       $link           Link permalink format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1859
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1860
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded terms IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1861
 * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1862
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1863
 * @return string The link URL of the previous or next post in relation to the current post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1864
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1865
function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1866
	if ( $previous && is_attachment() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1867
		$post = get_post( get_post()->post_parent );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1868
	else
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1869
		$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1870
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1871
	if ( ! $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1872
		$output = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1873
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1874
		$title = $post->post_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1875
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1876
		if ( empty( $post->post_title ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1877
			$title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1878
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1879
		/** This filter is documented in wp-includes/post-template.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1880
		$title = apply_filters( 'the_title', $title, $post->ID );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1881
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1882
		$date = mysql2date( get_option( 'date_format' ), $post->post_date );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1883
		$rel = $previous ? 'prev' : 'next';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1884
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1885
		$string = '<a href="' . get_permalink( $post ) . '" rel="'.$rel.'">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1886
		$inlink = str_replace( '%title', $title, $link );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1887
		$inlink = str_replace( '%date', $date, $inlink );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1888
		$inlink = $string . $inlink . '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1889
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1890
		$output = str_replace( '%link', $inlink, $format );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1891
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1892
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1893
	$adjacent = $previous ? 'previous' : 'next';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1894
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1895
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1896
	 * Filter the adjacent post link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1897
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1898
	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1899
	 * of adjacency, 'next' or 'previous'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1900
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1901
	 * @since 2.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1902
	 * @since 4.2.0 Added the `$adjacent` parameter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1903
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1904
	 * @param string  $output   The adjacent post link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1905
	 * @param string  $format   Link anchor format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1906
	 * @param string  $link     Link permalink format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1907
	 * @param WP_Post $post     The adjacent post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1908
	 * @param string  $adjacent Whether the post is previous or next.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1909
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1910
	return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post, $adjacent );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1911
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1912
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1913
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1914
 * Display adjacent post link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1915
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1916
 * Can be either next post link or previous.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1917
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1918
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1919
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1920
 * @param string       $format         Link anchor format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1921
 * @param string       $link           Link permalink format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1922
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1923
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1924
 * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1925
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1926
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1927
function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1928
	echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1929
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1930
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1931
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1932
 * Retrieve links for page numbers.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1933
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1934
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1935
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1936
 * @param int $pagenum Optional. Page ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1937
 * @param bool $escape Optional. Whether to escape the URL for display, with esc_url(). Defaults to true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1938
* 	Otherwise, prepares the URL with esc_url_raw().
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1939
 * @return string The link URL for the given page number.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1940
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1941
function get_pagenum_link($pagenum = 1, $escape = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1942
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1943
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1944
	$pagenum = (int) $pagenum;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1945
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1946
	$request = remove_query_arg( 'paged' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1947
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1948
	$home_root = parse_url(home_url());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1949
	$home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1950
	$home_root = preg_quote( $home_root, '|' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1951
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1952
	$request = preg_replace('|^'. $home_root . '|i', '', $request);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1953
	$request = preg_replace('|^/+|', '', $request);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1954
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1955
	if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1956
		$base = trailingslashit( get_bloginfo( 'url' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1957
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1958
		if ( $pagenum > 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1959
			$result = add_query_arg( 'paged', $pagenum, $base . $request );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1960
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1961
			$result = $base . $request;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1962
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1963
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1964
		$qs_regex = '|\?.*?$|';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1965
		preg_match( $qs_regex, $request, $qs_match );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1966
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1967
		if ( !empty( $qs_match[0] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1968
			$query_string = $qs_match[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1969
			$request = preg_replace( $qs_regex, '', $request );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1970
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1971
			$query_string = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1972
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1973
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1974
		$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1975
		$request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1976
		$request = ltrim($request, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1977
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1978
		$base = trailingslashit( get_bloginfo( 'url' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1979
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1980
		if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1981
			$base .= $wp_rewrite->index . '/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1982
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1983
		if ( $pagenum > 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1984
			$request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . "/" . $pagenum, 'paged' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1985
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1986
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1987
		$result = $base . $request . $query_string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1988
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1989
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1990
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1991
	 * Filter the page number link for the current request.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1992
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1993
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1994
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1995
	 * @param string $result The page number link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1996
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1997
	$result = apply_filters( 'get_pagenum_link', $result );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1998
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1999
	if ( $escape )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2000
		return esc_url( $result );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2001
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2002
		return esc_url_raw( $result );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2003
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2004
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2005
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2006
 * Retrieve next posts page link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2007
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2008
 * Backported from 2.1.3 to 2.0.10.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2009
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2010
 * @since 2.0.10
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2011
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2012
 * @param int $max_page Optional. Max pages.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2013
 * @return string The link URL for next posts page.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2014
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2015
function get_next_posts_page_link($max_page = 0) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2016
	global $paged;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2017
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2018
	if ( !is_single() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2019
		if ( !$paged )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2020
			$paged = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2021
		$nextpage = intval($paged) + 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2022
		if ( !$max_page || $max_page >= $nextpage )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2023
			return get_pagenum_link($nextpage);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2024
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2025
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2026
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2027
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2028
 * Display or return the next posts page link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2029
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2030
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2031
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2032
 * @param int $max_page Optional. Max pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2033
 * @param boolean $echo Optional. Echo or return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2034
 * @return string The link URL for next posts page if `$echo = false`.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2035
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2036
function next_posts( $max_page = 0, $echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2037
	$output = esc_url( get_next_posts_page_link( $max_page ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2038
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2039
	if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2040
		echo $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2041
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2042
		return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2043
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2044
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2045
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2046
 * Return the next posts page link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2047
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2048
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2049
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2050
 * @param string $label Content for link text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2051
 * @param int $max_page Optional. Max pages.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2052
 * @return string|null HTML-formatted next posts page link.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2053
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2054
function get_next_posts_link( $label = null, $max_page = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2055
	global $paged, $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2056
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2057
	if ( !$max_page )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2058
		$max_page = $wp_query->max_num_pages;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2059
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2060
	if ( !$paged )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2061
		$paged = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2062
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2063
	$nextpage = intval($paged) + 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2064
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2065
	if ( null === $label )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2066
		$label = __( 'Next Page &raquo;' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2067
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2068
	if ( !is_single() && ( $nextpage <= $max_page ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2069
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2070
		 * Filter the anchor tag attributes for the next posts page link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2071
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2072
		 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2073
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2074
		 * @param string $attributes Attributes for the anchor tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2075
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2076
		$attr = apply_filters( 'next_posts_link_attributes', '' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2077
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2078
		return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) . '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2079
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2080
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2081
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2082
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2083
 * Display the next posts page link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2084
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2085
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2086
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2087
 * @param string $label Content for link text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2088
 * @param int $max_page Optional. Max pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2089
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2090
function next_posts_link( $label = null, $max_page = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2091
	echo get_next_posts_link( $label, $max_page );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2092
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2093
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2094
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2095
 * Retrieve previous posts page link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2096
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2097
 * Will only return string, if not on a single page or post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2098
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2099
 * Backported to 2.0.10 from 2.1.3.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2100
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2101
 * @since 2.0.10
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2102
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2103
 * @return string|null The link for the previous posts page.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2104
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2105
function get_previous_posts_page_link() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2106
	global $paged;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2107
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2108
	if ( !is_single() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2109
		$nextpage = intval($paged) - 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2110
		if ( $nextpage < 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2111
			$nextpage = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2112
		return get_pagenum_link($nextpage);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2113
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2114
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2115
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2116
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2117
 * Display or return the previous posts page link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2118
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2119
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2120
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2121
 * @param boolean $echo Optional. Echo or return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2122
 * @return string The previous posts page link if `$echo = false`.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2123
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2124
function previous_posts( $echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2125
	$output = esc_url( get_previous_posts_page_link() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2126
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2127
	if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2128
		echo $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2129
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2130
		return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2131
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2132
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2133
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2134
 * Return the previous posts page link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2135
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2136
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2137
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2138
 * @param string $label Optional. Previous page link text.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2139
 * @return string|null HTML-formatted previous page link.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2140
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2141
function get_previous_posts_link( $label = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2142
	global $paged;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2143
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2144
	if ( null === $label )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2145
		$label = __( '&laquo; Previous Page' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2146
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2147
	if ( !is_single() && $paged > 1 ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2148
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2149
		 * Filter the anchor tag attributes for the previous posts page link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2150
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2151
		 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2152
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2153
		 * @param string $attributes Attributes for the anchor tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2154
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2155
		$attr = apply_filters( 'previous_posts_link_attributes', '' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2156
		return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) .'</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2157
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2158
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2159
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2160
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2161
 * Display the previous posts page link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2162
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2163
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2164
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2165
 * @param string $label Optional. Previous page link text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2166
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2167
function previous_posts_link( $label = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2168
	echo get_previous_posts_link( $label );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2169
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2170
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2171
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2172
 * Return post pages link navigation for previous and next pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2173
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2174
 * @since 2.8.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2175
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2176
 * @param string|array $args Optional args.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2177
 * @return string The posts link navigation.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2178
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2179
function get_posts_nav_link( $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2180
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2181
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2182
	$return = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2183
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2184
	if ( !is_singular() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2185
		$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2186
			'sep' => ' &#8212; ',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2187
			'prelabel' => __('&laquo; Previous Page'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2188
			'nxtlabel' => __('Next Page &raquo;'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2189
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2190
		$args = wp_parse_args( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2191
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2192
		$max_num_pages = $wp_query->max_num_pages;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2193
		$paged = get_query_var('paged');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2194
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2195
		//only have sep if there's both prev and next results
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2196
		if ($paged < 2 || $paged >= $max_num_pages) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2197
			$args['sep'] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2198
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2199
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2200
		if ( $max_num_pages > 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2201
			$return = get_previous_posts_link($args['prelabel']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2202
			$return .= preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $args['sep']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2203
			$return .= get_next_posts_link($args['nxtlabel']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2204
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2205
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2206
	return $return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2207
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2208
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2209
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2210
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2211
 * Display post pages link navigation for previous and next pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2212
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2213
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2214
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2215
 * @param string $sep Optional. Separator for posts navigation links.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2216
 * @param string $prelabel Optional. Label for previous pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2217
 * @param string $nxtlabel Optional Label for next pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2218
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2219
function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2220
	$args = array_filter( compact('sep', 'prelabel', 'nxtlabel') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2221
	echo get_posts_nav_link($args);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2222
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2223
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2224
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2225
 * Return navigation to next/previous post when applicable.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2226
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2227
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2228
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2229
 * @param array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2230
 *     Optional. Default post navigation arguments. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2231
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2232
 *     @type string $prev_text          Anchor text to display in the previous post link. Default `%title`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2233
 *     @type string $next_text          Anchor text to display in the next post link. Default `%title`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2234
 *     @type string $screen_reader_text Screen reader text for nav element. Default 'Post navigation'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2235
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2236
 * @return string Markup for post links.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2237
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2238
function get_the_post_navigation( $args = array() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2239
	$args = wp_parse_args( $args, array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2240
		'prev_text'          => '%title',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2241
		'next_text'          => '%title',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2242
		'screen_reader_text' => __( 'Post navigation' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2243
	) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2244
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2245
	$navigation = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2246
	$previous   = get_previous_post_link( '<div class="nav-previous">%link</div>', $args['prev_text'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2247
	$next       = get_next_post_link( '<div class="nav-next">%link</div>', $args['next_text'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2248
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2249
	// Only add markup if there's somewhere to navigate to.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2250
	if ( $previous || $next ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2251
		$navigation = _navigation_markup( $previous . $next, 'post-navigation', $args['screen_reader_text'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2252
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2253
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2254
	return $navigation;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2255
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2256
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2257
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2258
 * Display navigation to next/previous post when applicable.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2259
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2260
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2261
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2262
 * @param array $args Optional. See {@see get_the_post_navigation()} for available
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2263
 *                    arguments. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2264
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2265
function the_post_navigation( $args = array() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2266
	echo get_the_post_navigation( $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2267
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2268
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2269
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2270
 * Return navigation to next/previous set of posts when applicable.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2271
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2272
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2273
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2274
 * @global WP_Query $wp_query WordPress Query object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2275
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2276
 * @param array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2277
 *     Optional. Default posts navigation arguments. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2278
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2279
 *     @type string $prev_text          Anchor text to display in the previous posts link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2280
 *                                      Default 'Older posts'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2281
 *     @type string $next_text          Anchor text to display in the next posts link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2282
 *                                      Default 'Newer posts'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2283
 *     @type string $screen_reader_text Screen reader text for nav element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2284
 *                                      Default 'Posts navigation'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2285
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2286
 * @return string Markup for posts links.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2287
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2288
function get_the_posts_navigation( $args = array() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2289
	$navigation = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2290
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2291
	// Don't print empty markup if there's only one page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2292
	if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2293
		$args = wp_parse_args( $args, array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2294
			'prev_text'          => __( 'Older posts' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2295
			'next_text'          => __( 'Newer posts' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2296
			'screen_reader_text' => __( 'Posts navigation' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2297
		) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2298
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2299
		$next_link = get_previous_posts_link( $args['next_text'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2300
		$prev_link = get_next_posts_link( $args['prev_text'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2301
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2302
		if ( $prev_link ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2303
			$navigation .= '<div class="nav-previous">' . $prev_link . '</div>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2304
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2305
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2306
		if ( $next_link ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2307
			$navigation .= '<div class="nav-next">' . $next_link . '</div>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2308
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2309
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2310
		$navigation = _navigation_markup( $navigation, 'posts-navigation', $args['screen_reader_text'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2311
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2312
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2313
	return $navigation;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2314
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2315
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2316
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2317
 * Display navigation to next/previous set of posts when applicable.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2318
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2319
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2320
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2321
 * @param array $args Optional. See {@see get_the_posts_navigation()} for available
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2322
 *                    arguments. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2323
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2324
function the_posts_navigation( $args = array() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2325
	echo get_the_posts_navigation( $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2326
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2327
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2328
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2329
 * Return a paginated navigation to next/previous set of posts,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2330
 * when applicable.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2331
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2332
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2333
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2334
 * @param array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2335
 *     Optional. Default pagination arguments, {@see paginate_links()}.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2336
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2337
 *     @type string $screen_reader_text Screen reader text for navigation element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2338
 *                                      Default 'Posts navigation'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2339
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2340
 * @return string Markup for pagination links.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2341
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2342
function get_the_posts_pagination( $args = array() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2343
	$navigation = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2344
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2345
	// Don't print empty markup if there's only one page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2346
	if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2347
		$args = wp_parse_args( $args, array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2348
			'mid_size'           => 1,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2349
			'prev_text'          => _x( 'Previous', 'previous post' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2350
			'next_text'          => _x( 'Next', 'next post' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2351
			'screen_reader_text' => __( 'Posts navigation' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2352
		) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2353
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2354
		// Make sure we get a string back. Plain is the next best thing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2355
		if ( isset( $args['type'] ) && 'array' == $args['type'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2356
			$args['type'] = 'plain';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2357
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2358
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2359
		// Set up paginated links.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2360
		$links = paginate_links( $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2361
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2362
		if ( $links ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2363
			$navigation = _navigation_markup( $links, 'pagination', $args['screen_reader_text'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2364
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2365
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2366
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2367
	return $navigation;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2368
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2369
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2370
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2371
 * Display a paginated navigation to next/previous set of posts,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2372
 * when applicable.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2373
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2374
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2375
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2376
 * @param array $args Optional. See {@see get_the_posts_pagination()} for available arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2377
 *                    Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2378
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2379
function the_posts_pagination( $args = array() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2380
	echo get_the_posts_pagination( $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2381
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2382
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2383
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2384
 * Wraps passed links in navigational markup.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2385
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2386
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2387
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2388
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2389
 * @param string $links              Navigational links.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2390
 * @param string $class              Optional. Custom class for nav element. Default: 'posts-navigation'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2391
 * @param string $screen_reader_text Optional. Screen reader text for nav element. Default: 'Posts navigation'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2392
 * @return string Navigation template tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2393
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2394
function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2395
	if ( empty( $screen_reader_text ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2396
		$screen_reader_text = __( 'Posts navigation' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2397
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2398
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2399
	$template = '
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2400
	<nav class="navigation %1$s" role="navigation">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2401
		<h2 class="screen-reader-text">%2$s</h2>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2402
		<div class="nav-links">%3$s</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2403
	</nav>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2404
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2405
	return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2406
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2407
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2408
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2409
 * Retrieve comments page number link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2410
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2411
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2412
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2413
 * @param int $pagenum Optional. Page number.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2414
 * @param int $max_page Optional. The maximum number of comment pages.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2415
 * @return string The comments page number link URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2416
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2417
function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2418
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2419
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2420
	$pagenum = (int) $pagenum;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2421
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2422
	$result = get_permalink();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2423
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2424
	if ( 'newest' == get_option('default_comments_page') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2425
		if ( $pagenum != $max_page ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2426
			if ( $wp_rewrite->using_permalinks() )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2427
				$result = user_trailingslashit( trailingslashit($result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2428
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2429
				$result = add_query_arg( 'cpage', $pagenum, $result );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2430
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2431
	} elseif ( $pagenum > 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2432
		if ( $wp_rewrite->using_permalinks() )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2433
			$result = user_trailingslashit( trailingslashit($result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2434
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2435
			$result = add_query_arg( 'cpage', $pagenum, $result );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2436
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2437
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2438
	$result .= '#comments';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2439
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2440
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2441
	 * Filter the comments page number link for the current request.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2442
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2443
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2444
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2445
	 * @param string $result The comments page number link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2446
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2447
	$result = apply_filters( 'get_comments_pagenum_link', $result );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2449
	return $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2450
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2451
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2452
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2453
 * Return the link to next comments page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2454
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2455
 * @since 2.7.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2456
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2457
 * @param string $label Optional. Label for link text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2458
 * @param int $max_page Optional. Max page.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2459
 * @return string|null HTML-formatted link for the next page of comments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2460
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2461
function get_next_comments_link( $label = '', $max_page = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2462
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2463
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2464
	if ( !is_singular() || !get_option('page_comments') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2465
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2466
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2467
	$page = get_query_var('cpage');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2468
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2469
	if ( ! $page ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2470
		$page = 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2471
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2472
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2473
	$nextpage = intval($page) + 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2474
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2475
	if ( empty($max_page) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2476
		$max_page = $wp_query->max_num_comment_pages;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2477
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2478
	if ( empty($max_page) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2479
		$max_page = get_comment_pages_count();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2480
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2481
	if ( $nextpage > $max_page )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2482
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2483
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2484
	if ( empty($label) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2485
		$label = __('Newer Comments &raquo;');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2486
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2487
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2488
	 * Filter the anchor tag attributes for the next comments page link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2489
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2490
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2491
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2492
	 * @param string $attributes Attributes for the anchor tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2493
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2494
	return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>'. preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) .'</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2495
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2496
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2497
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2498
 * Display the link to next comments page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2499
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2500
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2501
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2502
 * @param string $label Optional. Label for link text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2503
 * @param int $max_page Optional. Max page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2504
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2505
function next_comments_link( $label = '', $max_page = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2506
	echo get_next_comments_link( $label, $max_page );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2507
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2508
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2509
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2510
 * Return the previous comments page link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2511
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2512
 * @since 2.7.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2513
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2514
 * @param string $label Optional. Label for comments link text.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2515
 * @return string|null HTML-formatted link for the previous page of comments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2516
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2517
function get_previous_comments_link( $label = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2518
	if ( !is_singular() || !get_option('page_comments') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2519
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2520
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2521
	$page = get_query_var('cpage');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2522
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2523
	if ( intval($page) <= 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2524
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2525
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2526
	$prevpage = intval($page) - 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2527
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2528
	if ( empty($label) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2529
		$label = __('&laquo; Older Comments');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2530
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2531
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2532
	 * Filter the anchor tag attributes for the previous comments page link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2533
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2534
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2535
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2536
	 * @param string $attributes Attributes for the anchor tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2537
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2538
	return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) .'</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2539
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2540
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2541
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2542
 * Display the previous comments page link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2543
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2544
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2545
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2546
 * @param string $label Optional. Label for comments link text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2547
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2548
function previous_comments_link( $label = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2549
	echo get_previous_comments_link( $label );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2550
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2551
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2552
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2553
 * Create pagination links for the comments on the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2554
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2555
 * @see paginate_links()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2556
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2557
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2558
 * @param string|array $args Optional args. See paginate_links().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2559
 * @return string Markup for pagination links.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2560
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2561
function paginate_comments_links($args = array()) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2562
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2563
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2564
	if ( !is_singular() || !get_option('page_comments') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2565
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2566
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2567
	$page = get_query_var('cpage');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2568
	if ( !$page )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2569
		$page = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2570
	$max_page = get_comment_pages_count();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2571
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2572
		'base' => add_query_arg( 'cpage', '%#%' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2573
		'format' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2574
		'total' => $max_page,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2575
		'current' => $page,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2576
		'echo' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2577
		'add_fragment' => '#comments'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2578
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2579
	if ( $wp_rewrite->using_permalinks() )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2580
		$defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2581
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2582
	$args = wp_parse_args( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2583
	$page_links = paginate_links( $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2584
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2585
	if ( $args['echo'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2586
		echo $page_links;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2587
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2588
		return $page_links;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2589
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2590
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2591
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2592
 * Retrieve the Press This bookmarklet link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2593
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2594
 * Use this in 'a' element 'href' attribute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2595
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2596
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2597
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2598
 * @return string The Press This bookmarklet link URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2599
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2600
function get_shortcut_link() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2601
	global $is_IE, $wp_version;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2602
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2603
	include_once( ABSPATH . 'wp-admin/includes/class-wp-press-this.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2604
	$bookmarklet_version = $GLOBALS['wp_press_this']->version;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2605
	$link = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2606
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2607
	if ( $is_IE ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2608
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2609
		 * Return the old/shorter bookmarklet code for MSIE 8 and lower,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2610
		 * since they only support a max length of ~2000 characters for
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2611
		 * bookmark[let] URLs, which is way to small for our smarter one.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2612
		 * Do update the version number so users do not get the "upgrade your
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2613
		 * bookmarklet" notice when using PT in those browsers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2614
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2615
		$ua = $_SERVER['HTTP_USER_AGENT'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2616
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2617
		if ( ! empty( $ua ) && preg_match( '/\bMSIE (\d)/', $ua, $matches ) && (int) $matches[1] <= 8 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2618
			$url = wp_json_encode( admin_url( 'press-this.php' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2619
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2620
			$link = 'javascript:var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,' .
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2621
				's=(e?e():(k)?k():(x?x.createRange().text:0)),f=' . $url . ',l=d.location,e=encodeURIComponent,' .
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2622
				'u=f+"?u="+e(l.href)+"&t="+e(d.title)+"&s="+e(s)+"&v=' . $bookmarklet_version . '";' .
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2623
				'a=function(){if(!w.open(u,"t","toolbar=0,resizable=1,scrollbars=1,status=1,width=600,height=700"))l.href=u;};' .
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2624
				'if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else a();void(0)';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2625
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2626
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2627
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2628
	if ( empty( $link ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2629
		$src = @file_get_contents( ABSPATH . 'wp-admin/js/bookmarklet.min.js' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2630
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2631
		if ( $src ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2632
			$url = wp_json_encode( admin_url( 'press-this.php' ) . '?v=' . $bookmarklet_version );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2633
			$link = 'javascript:' . str_replace( 'window.pt_url', $url, $src );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2634
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2635
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2636
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2637
	$link = str_replace( array( "\r", "\n", "\t" ),  '', $link );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2638
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2639
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2640
	 * Filter the Press This bookmarklet link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2641
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2642
	 * @since 2.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2643
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2644
	 * @param string $link The Press This bookmarklet link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2645
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2646
	return apply_filters( 'shortcut_link', $link );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2647
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2648
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2649
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2650
 * Retrieve the home url for the current site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2651
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2652
 * Returns the 'home' option with the appropriate protocol, 'https' if
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2653
 * {@see is_ssl()} and 'http' otherwise. If `$scheme` is 'http' or 'https',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2654
 * `is_ssl()` is overridden.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2655
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2656
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2657
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2658
 * @param  string $path   Optional. Path relative to the home url. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2659
 * @param  string $scheme Optional. Scheme to give the home url context. Accepts
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2660
 *                        'http', 'https', or 'relative'. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2661
 * @return string Home url link with optional path appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2662
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2663
function home_url( $path = '', $scheme = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2664
	return get_home_url( null, $path, $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2665
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2666
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2667
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2668
 * Retrieve the home url for a given site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2669
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2670
 * Returns the 'home' option with the appropriate protocol, 'https' if
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2671
 * {@see is_ssl()} and 'http' otherwise. If `$scheme` is 'http' or 'https',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2672
 * `is_ssl()` is
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2673
 * overridden.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2674
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2675
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2676
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2677
 * @param  int         $blog_id     Optional. Blog ID. Default null (current blog).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2678
 * @param  string      $path        Optional. Path relative to the home URL. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2679
 * @param  string|null $orig_scheme Optional. Scheme to give the home URL context. Accepts
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2680
 *                                  'http', 'https', 'relative', or null. Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2681
 * @return string Home URL link with optional path appended.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2682
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2683
function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2684
	$orig_scheme = $scheme;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2685
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2686
	if ( empty( $blog_id ) || !is_multisite() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2687
		$url = get_option( 'home' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2688
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2689
		switch_to_blog( $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2690
		$url = get_option( 'home' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2691
		restore_current_blog();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2692
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2693
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2694
	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2695
		if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $GLOBALS['pagenow'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2696
			$scheme = 'https';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2697
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2698
			$scheme = parse_url( $url, PHP_URL_SCHEME );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2699
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2700
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2701
	$url = set_url_scheme( $url, $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2702
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2703
	if ( $path && is_string( $path ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2704
		$url .= '/' . ltrim( $path, '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2705
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2706
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2707
	 * Filter the home URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2708
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2709
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2710
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2711
	 * @param string      $url         The complete home URL including scheme and path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2712
	 * @param string      $path        Path relative to the home URL. Blank string if no path is specified.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2713
	 * @param string|null $orig_scheme Scheme to give the home URL context. Accepts 'http', 'https', 'relative' or null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2714
	 * @param int|null    $blog_id     Blog ID, or null for the current blog.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2715
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2716
	return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2717
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2718
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2719
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2720
 * Retrieve the site url for the current site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2721
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2722
 * Returns the 'site_url' option with the appropriate protocol, 'https' if
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2723
 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2724
 * overridden.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2725
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2726
 * @since 3.0.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2727
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2728
 * @param string $path Optional. Path relative to the site url.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2729
 * @param string $scheme Optional. Scheme to give the site url context. See set_url_scheme().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2730
 * @return string Site url link with optional path appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2731
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2732
function site_url( $path = '', $scheme = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2733
	return get_site_url( null, $path, $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2734
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2735
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2736
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2737
 * Retrieve the site url for a given site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2738
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2739
 * Returns the 'site_url' option with the appropriate protocol, 'https' if
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2740
 * {@see is_ssl()} and 'http' otherwise. If `$scheme` is 'http' or 'https',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2741
 * `is_ssl()` is overridden.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2742
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2743
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2744
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2745
 * @param int    $blog_id Optional. Blog ID. Default null (current site).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2746
 * @param string $path    Optional. Path relative to the site url. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2747
 * @param string $scheme  Optional. Scheme to give the site url context. Accepts
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2748
 *                        'http', 'https', 'login', 'login_post', 'admin', or
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2749
 *                        'relative'. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2750
 * @return string Site url link with optional path appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2751
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2752
function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2753
	if ( empty( $blog_id ) || !is_multisite() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2754
		$url = get_option( 'siteurl' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2755
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2756
		switch_to_blog( $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2757
		$url = get_option( 'siteurl' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2758
		restore_current_blog();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2759
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2760
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2761
	$url = set_url_scheme( $url, $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2762
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2763
	if ( $path && is_string( $path ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2764
		$url .= '/' . ltrim( $path, '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2765
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2766
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2767
	 * Filter the site URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2768
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2769
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2770
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2771
	 * @param string      $url     The complete site URL including scheme and path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2772
	 * @param string      $path    Path relative to the site URL. Blank string if no path is specified.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2773
	 * @param string|null $scheme  Scheme to give the site URL context. Accepts 'http', 'https', 'login',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2774
	 *                             'login_post', 'admin', 'relative' or null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2775
	 * @param int|null    $blog_id Blog ID, or null for the current blog.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2776
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2777
	return apply_filters( 'site_url', $url, $path, $scheme, $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2778
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2779
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2780
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2781
 * Retrieve the url to the admin area for the current site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2782
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2783
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2784
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2785
 * @param string $path Optional path relative to the admin url.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2786
 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2787
 * @return string Admin url link with optional path appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2788
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2789
function admin_url( $path = '', $scheme = 'admin' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2790
	return get_admin_url( null, $path, $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2791
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2792
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2793
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2794
 * Retrieves the url to the admin area for a given site.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2795
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2796
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2797
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2798
 * @param int    $blog_id Optional. Blog ID. Default null (current site).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2799
 * @param string $path    Optional. Path relative to the admin url. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2800
 * @param string $scheme  Optional. The scheme to use. Accepts 'http' or 'https',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2801
 *                        to force those schemes. Default 'admin', which obeys
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2802
 *                        {@see force_ssl_admin()} and {@see is_ssl()}.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2803
 * @return string Admin url link with optional path appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2804
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2805
function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2806
	$url = get_site_url($blog_id, 'wp-admin/', $scheme);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2807
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2808
	if ( $path && is_string( $path ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2809
		$url .= ltrim( $path, '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2810
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2811
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2812
	 * Filter the admin area URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2813
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2814
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2815
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2816
	 * @param string   $url     The complete admin area URL including scheme and path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2817
	 * @param string   $path    Path relative to the admin area URL. Blank string if no path is specified.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2818
	 * @param int|null $blog_id Blog ID, or null for the current blog.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2819
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2820
	return apply_filters( 'admin_url', $url, $path, $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2821
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2822
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2823
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2824
 * Retrieve the url to the includes directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2825
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2826
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2827
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2828
 * @param string $path Optional. Path relative to the includes url.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2829
 * @param string $scheme Optional. Scheme to give the includes url context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2830
 * @return string Includes url link with optional path appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2831
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2832
function includes_url( $path = '', $scheme = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2833
	$url = site_url( '/' . WPINC . '/', $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2834
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2835
	if ( $path && is_string( $path ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2836
		$url .= ltrim($path, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2837
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2838
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2839
	 * Filter the URL to the includes directory.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2840
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2841
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2842
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2843
	 * @param string $url  The complete URL to the includes directory including scheme and path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2844
	 * @param string $path Path relative to the URL to the wp-includes directory. Blank string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2845
	 *                     if no path is specified.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2846
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2847
	return apply_filters( 'includes_url', $url, $path );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2848
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2849
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2850
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2851
 * Retrieve the url to the content directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2852
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2853
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2854
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2855
 * @param string $path Optional. Path relative to the content url.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2856
 * @return string Content url link with optional path appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2857
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2858
function content_url($path = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2859
	$url = set_url_scheme( WP_CONTENT_URL );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2860
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2861
	if ( $path && is_string( $path ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2862
		$url .= '/' . ltrim($path, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2863
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2864
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2865
	 * Filter the URL to the content directory.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2866
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2867
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2868
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2869
	 * @param string $url  The complete URL to the content directory including scheme and path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2870
	 * @param string $path Path relative to the URL to the content directory. Blank string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2871
	 *                     if no path is specified.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2872
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2873
	return apply_filters( 'content_url', $url, $path);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2874
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2875
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2876
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2877
 * Retrieve a URL within the plugins or mu-plugins directory.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2878
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2879
 * Defaults to the plugins directory URL if no arguments are supplied.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2880
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2881
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2882
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2883
 * @param  string $path   Optional. Extra path appended to the end of the URL, including
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2884
 *                        the relative directory if $plugin is supplied. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2885
 * @param  string $plugin Optional. A full path to a file inside a plugin or mu-plugin.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2886
 *                        The URL will be relative to its directory. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2887
 *                        Typically this is done by passing `__FILE__` as the argument.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2888
 * @return string Plugins URL link with optional paths appended.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2889
*/
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2890
function plugins_url( $path = '', $plugin = '' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2891
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2892
	$path = wp_normalize_path( $path );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2893
	$plugin = wp_normalize_path( $plugin );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2894
	$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2895
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2896
	if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2897
		$url = WPMU_PLUGIN_URL;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2898
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2899
		$url = WP_PLUGIN_URL;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2900
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2901
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2902
	$url = set_url_scheme( $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2903
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2904
	if ( !empty($plugin) && is_string($plugin) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2905
		$folder = dirname(plugin_basename($plugin));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2906
		if ( '.' != $folder )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2907
			$url .= '/' . ltrim($folder, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2908
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2909
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2910
	if ( $path && is_string( $path ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2911
		$url .= '/' . ltrim($path, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2912
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2913
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2914
	 * Filter the URL to the plugins directory.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2915
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2916
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2917
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2918
	 * @param string $url    The complete URL to the plugins directory including scheme and path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2919
	 * @param string $path   Path relative to the URL to the plugins directory. Blank string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2920
	 *                       if no path is specified.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2921
	 * @param string $plugin The plugin file path to be relative to. Blank string if no plugin
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2922
	 *                       is specified.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2923
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2924
	return apply_filters( 'plugins_url', $url, $path, $plugin );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2925
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2926
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2927
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2928
 * Retrieve the site url for the current network.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2929
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2930
 * Returns the site url with the appropriate protocol, 'https' if
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2931
 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2932
 * overridden.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2933
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2934
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2935
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2936
 * @param string $path Optional. Path relative to the site url.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2937
 * @param string $scheme Optional. Scheme to give the site url context. See set_url_scheme().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2938
 * @return string Site url link with optional path appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2939
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2940
function network_site_url( $path = '', $scheme = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2941
	if ( ! is_multisite() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2942
		return site_url($path, $scheme);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2943
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2944
	$current_site = get_current_site();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2945
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2946
	if ( 'relative' == $scheme )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2947
		$url = $current_site->path;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2948
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2949
		$url = set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2950
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2951
	if ( $path && is_string( $path ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2952
		$url .= ltrim( $path, '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2953
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2954
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2955
	 * Filter the network site URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2956
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2957
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2958
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2959
	 * @param string      $url    The complete network site URL including scheme and path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2960
	 * @param string      $path   Path relative to the network site URL. Blank string if
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2961
	 *                            no path is specified.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2962
	 * @param string|null $scheme Scheme to give the URL context. Accepts 'http', 'https',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2963
	 *                            'relative' or null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2964
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2965
	return apply_filters( 'network_site_url', $url, $path, $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2966
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2967
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2968
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2969
 * Retrieves the home url for the current network.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2970
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2971
 * Returns the home url with the appropriate protocol, 'https' {@see is_ssl()}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2972
 * and 'http' otherwise. If `$scheme` is 'http' or 'https', `is_ssl()` is
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2973
 * overridden.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2974
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2975
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2976
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2977
 * @param  string $path   Optional. Path relative to the home url. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2978
 * @param  string $scheme Optional. Scheme to give the home url context. Accepts
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2979
 *                        'http', 'https', or 'relative'. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2980
 * @return string Home url link with optional path appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2981
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2982
function network_home_url( $path = '', $scheme = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2983
	if ( ! is_multisite() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2984
		return home_url($path, $scheme);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2985
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2986
	$current_site = get_current_site();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2987
	$orig_scheme = $scheme;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2988
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2989
	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2990
		$scheme = is_ssl() && ! is_admin() ? 'https' : 'http';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2991
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2992
	if ( 'relative' == $scheme )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2993
		$url = $current_site->path;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2994
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2995
		$url = set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2996
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2997
	if ( $path && is_string( $path ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2998
		$url .= ltrim( $path, '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2999
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3000
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3001
	 * Filter the network home URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3002
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3003
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3004
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3005
	 * @param string      $url         The complete network home URL including scheme and path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3006
	 * @param string      $path        Path relative to the network home URL. Blank string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3007
	 *                                 if no path is specified.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3008
	 * @param string|null $orig_scheme Scheme to give the URL context. Accepts 'http', 'https',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3009
	 *                                 'relative' or null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3010
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3011
	return apply_filters( 'network_home_url', $url, $path, $orig_scheme);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3012
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3013
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3014
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3015
 * Retrieve the url to the admin area for the network.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3016
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3017
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3018
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3019
 * @param string $path Optional path relative to the admin url.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3020
 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3021
 * @return string Admin url link with optional path appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3022
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3023
function network_admin_url( $path = '', $scheme = 'admin' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3024
	if ( ! is_multisite() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3025
		return admin_url( $path, $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3026
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3027
	$url = network_site_url('wp-admin/network/', $scheme);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3028
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3029
	if ( $path && is_string( $path ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3030
		$url .= ltrim($path, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3031
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3032
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3033
	 * Filter the network admin URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3034
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3035
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3036
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3037
	 * @param string $url  The complete network admin URL including scheme and path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3038
	 * @param string $path Path relative to the network admin URL. Blank string if
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3039
	 *                     no path is specified.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3040
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3041
	return apply_filters( 'network_admin_url', $url, $path );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3042
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3043
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3044
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3045
 * Retrieve the url to the admin area for the current user.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3046
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3047
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3048
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3049
 * @param string $path Optional path relative to the admin url.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3050
 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3051
 * @return string Admin url link with optional path appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3052
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3053
function user_admin_url( $path = '', $scheme = 'admin' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3054
	$url = network_site_url('wp-admin/user/', $scheme);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3055
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3056
	if ( $path && is_string( $path ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3057
		$url .= ltrim($path, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3058
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3059
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3060
	 * Filter the user admin URL for the current user.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3061
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3062
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3063
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3064
	 * @param string $url  The complete URL including scheme and path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3065
	 * @param string $path Path relative to the URL. Blank string if
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3066
	 *                     no path is specified.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3067
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3068
	return apply_filters( 'user_admin_url', $url, $path );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3069
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3070
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3071
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3072
 * Retrieve the url to the admin area for either the current blog or the network depending on context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3073
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3074
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3075
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3076
 * @param string $path Optional path relative to the admin url.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3077
 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3078
 * @return string Admin url link with optional path appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3079
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3080
function self_admin_url($path = '', $scheme = 'admin') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3081
	if ( is_network_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3082
		return network_admin_url($path, $scheme);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3083
	elseif ( is_user_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3084
		return user_admin_url($path, $scheme);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3085
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3086
		return admin_url($path, $scheme);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3087
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3088
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3089
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3090
 * Set the scheme for a URL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3091
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3092
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3093
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3094
 * @param string $url Absolute url that includes a scheme
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3095
 * @param string $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3096
 * @return string $url URL with chosen scheme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3097
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3098
function set_url_scheme( $url, $scheme = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3099
	$orig_scheme = $scheme;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3100
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3101
	if ( ! $scheme ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3102
		$scheme = is_ssl() ? 'https' : 'http';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3103
	} elseif ( $scheme === 'admin' || $scheme === 'login' || $scheme === 'login_post' || $scheme === 'rpc' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3104
		$scheme = is_ssl() || force_ssl_admin() ? 'https' : 'http';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3105
	} elseif ( $scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3106
		$scheme = is_ssl() ? 'https' : 'http';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3107
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3108
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3109
	$url = trim( $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3110
	if ( substr( $url, 0, 2 ) === '//' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3111
		$url = 'http:' . $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3112
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3113
	if ( 'relative' == $scheme ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3114
		$url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3115
		if ( $url !== '' && $url[0] === '/' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3116
			$url = '/' . ltrim($url , "/ \t\n\r\0\x0B" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3117
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3118
		$url = preg_replace( '#^\w+://#', $scheme . '://', $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3119
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3120
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3121
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3122
	 * Filter the resulting URL after setting the scheme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3123
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3124
	 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3125
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3126
	 * @param string $url         The complete URL including scheme and path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3127
	 * @param string $scheme      Scheme applied to the URL. One of 'http', 'https', or 'relative'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3128
	 * @param string $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3129
	 *                            'login_post', 'admin', 'rpc', or 'relative'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3130
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3131
	return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3132
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3133
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3134
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3135
 * Get the URL to the user's dashboard.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3136
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3137
 * If a user does not belong to any site, the global user dashboard is used. If the user belongs to the current site,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3138
 * the dashboard for the current site is returned. If the user cannot edit the current site, the dashboard to the user's
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3139
 * primary blog is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3140
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3141
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3142
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3143
 * @param int $user_id Optional. User ID. Defaults to current user.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3144
 * @param string $path Optional path relative to the dashboard. Use only paths known to both blog and user admins.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3145
 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3146
 * @return string Dashboard url link with optional path appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3147
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3148
function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3149
	$user_id = $user_id ? (int) $user_id : get_current_user_id();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3150
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3151
	$blogs = get_blogs_of_user( $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3152
	if ( ! is_super_admin() && empty($blogs) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3153
		$url = user_admin_url( $path, $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3154
	} elseif ( ! is_multisite() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3155
		$url = admin_url( $path, $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3156
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3157
		$current_blog = get_current_blog_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3158
		if ( $current_blog  && ( is_super_admin( $user_id ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3159
			$url = admin_url( $path, $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3160
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3161
			$active = get_active_blog_for_user( $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3162
			if ( $active )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3163
				$url = get_admin_url( $active->blog_id, $path, $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3164
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3165
				$url = user_admin_url( $path, $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3166
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3167
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3168
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3169
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3170
	 * Filter the dashboard URL for a user.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3171
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3172
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3173
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3174
	 * @param string $url     The complete URL including scheme and path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3175
	 * @param int    $user_id The user ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3176
	 * @param string $path    Path relative to the URL. Blank string if no path is specified.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3177
	 * @param string $scheme  Scheme to give the URL context. Accepts 'http', 'https', 'login',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3178
	 *                        'login_post', 'admin', 'relative' or null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3179
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3180
	return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3181
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3182
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3183
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3184
 * Get the URL to the user's profile editor.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3185
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3186
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3187
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3188
 * @param int    $user_id Optional. User ID. Defaults to current user.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3189
 * @param string $scheme  The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl().
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3190
 *                        'http' or 'https' can be passed to force those schemes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3191
 * @return string Dashboard url link with optional path appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3192
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3193
function get_edit_profile_url( $user_id = 0, $scheme = 'admin' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3194
	$user_id = $user_id ? (int) $user_id : get_current_user_id();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3195
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3196
	if ( is_user_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3197
		$url = user_admin_url( 'profile.php', $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3198
	elseif ( is_network_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3199
		$url = network_admin_url( 'profile.php', $scheme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3200
	else
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3201
		$url = get_dashboard_url( $user_id, 'profile.php', $scheme );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3202
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3203
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3204
	 * Filter the URL for a user's profile editor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3205
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3206
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3207
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3208
	 * @param string $url     The complete URL including scheme and path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3209
	 * @param int    $user_id The user ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3210
	 * @param string $scheme  Scheme to give the URL context. Accepts 'http', 'https', 'login',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3211
	 *                        'login_post', 'admin', 'relative' or null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3212
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3213
	return apply_filters( 'edit_profile_url', $url, $user_id, $scheme);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3214
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3215
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3216
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3217
 * Output rel=canonical for singular queries.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3218
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3219
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3220
*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3221
function rel_canonical() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3222
	if ( !is_singular() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3223
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3224
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3225
	global $wp_the_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3226
	if ( !$id = $wp_the_query->get_queried_object_id() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3227
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3228
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3229
	$link = get_permalink( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3231
	if ( $page = get_query_var('cpage') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3232
		$link = get_comments_pagenum_link( $page );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3233
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3234
	echo "<link rel='canonical' href='$link' />\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3235
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3236
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3237
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3238
 * Return a shortlink for a post, page, attachment, or blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3239
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3240
 * This function exists to provide a shortlink tag that all themes and plugins can target. A plugin must hook in to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3241
 * provide the actual shortlinks. Default shortlink support is limited to providing ?p= style links for posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3242
 * Plugins can short-circuit this function via the pre_get_shortlink filter or filter the output
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3243
 * via the get_shortlink filter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3244
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3245
 * @since 3.0.0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3246
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3247
 * @param int $id A post or blog id. Default is 0, which means the current post or blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3248
 * @param string $context Whether the id is a 'blog' id, 'post' id, or 'media' id. If 'post', the post_type of the post is consulted. If 'query', the current query is consulted to determine the id and context. Default is 'post'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3249
 * @param bool $allow_slugs Whether to allow post slugs in the shortlink. It is up to the plugin how and whether to honor this.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3250
 * @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks are not enabled.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3251
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3252
function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3253
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3254
	 * Filter whether to preempt generating a shortlink for the given post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3255
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3256
	 * Passing a truthy value to the filter will effectively short-circuit the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3257
	 * shortlink-generation process, returning that value instead.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3258
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3259
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3260
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3261
	 * @param bool|string $return      Short-circuit return value. Either false or a URL string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3262
	 * @param int         $id          Post ID, or 0 for the current post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3263
	 * @param string      $context     The context for the link. One of 'post' or 'query',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3264
	 * @param bool        $allow_slugs Whether to allow post slugs in the shortlink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3265
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3266
	$shortlink = apply_filters( 'pre_get_shortlink', false, $id, $context, $allow_slugs );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3267
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3268
	if ( false !== $shortlink )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3269
		return $shortlink;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3270
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3271
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3272
	$post_id = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3273
	if ( 'query' == $context && is_singular() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3274
		$post_id = $wp_query->get_queried_object_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3275
		$post = get_post( $post_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3276
	} elseif ( 'post' == $context ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3277
		$post = get_post( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3278
		if ( ! empty( $post->ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3279
			$post_id = $post->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3280
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3281
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3282
	$shortlink = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3283
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3284
	// Return p= link for all public post types.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3285
	if ( ! empty( $post_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3286
		$post_type = get_post_type_object( $post->post_type );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3287
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3288
		if ( 'page' === $post->post_type && $post->ID == get_option( 'page_on_front' ) && 'page' == get_option( 'show_on_front' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3289
			$shortlink = home_url( '/' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3290
		} elseif ( $post_type->public ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3291
			$shortlink = home_url( '?p=' . $post_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3292
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3293
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3294
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3295
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3296
	 * Filter the shortlink for a post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3297
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3298
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3299
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3300
	 * @param string $shortlink   Shortlink URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3301
	 * @param int    $id          Post ID, or 0 for the current post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3302
	 * @param string $context     The context for the link. One of 'post' or 'query',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3303
	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink. Not used by default.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3304
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3305
	return apply_filters( 'get_shortlink', $shortlink, $id, $context, $allow_slugs );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3306
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3307
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3308
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3309
 *  Inject rel=shortlink into head if a shortlink is defined for the current page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3310
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3311
 *  Attached to the wp_head action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3312
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3313
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3314
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3315
function wp_shortlink_wp_head() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3316
	$shortlink = wp_get_shortlink( 0, 'query' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3317
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3318
	if ( empty( $shortlink ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3319
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3320
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3321
	echo "<link rel='shortlink' href='" . esc_url( $shortlink ) . "' />\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3322
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3323
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3324
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3325
 * Send a Link: rel=shortlink header if a shortlink is defined for the current page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3326
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3327
 * Attached to the wp action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3328
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3329
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3330
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3331
function wp_shortlink_header() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3332
	if ( headers_sent() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3333
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3334
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3335
	$shortlink = wp_get_shortlink(0, 'query');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3336
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3337
	if ( empty($shortlink) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3338
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3339
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3340
	header('Link: <' . $shortlink . '>; rel=shortlink', false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3341
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3342
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3343
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3344
 * Display the Short Link for a Post
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3345
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3346
 * Must be called from inside "The Loop"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3347
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3348
 * Call like the_shortlink(__('Shortlinkage FTW'))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3349
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3350
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3351
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3352
 * @param string $text Optional The link text or HTML to be displayed. Defaults to 'This is the short link.'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3353
 * @param string $title Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3354
 * @param string $before Optional HTML to display before the link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3355
 * @param string $after Optional HTML to display after the link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3356
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3357
function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3358
	$post = get_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3359
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3360
	if ( empty( $text ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3361
		$text = __('This is the short link.');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3362
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3363
	if ( empty( $title ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3364
		$title = the_title_attribute( array( 'echo' => false ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3365
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3366
	$shortlink = wp_get_shortlink( $post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3367
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3368
	if ( !empty( $shortlink ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3369
		$link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3370
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3371
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3372
		 * Filter the shortlink anchor tag for a post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3373
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3374
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3375
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3376
		 * @param string $link      Shortlink anchor tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3377
		 * @param string $shortlink Shortlink URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3378
		 * @param string $text      Shortlink's text.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3379
		 * @param string $title     Shortlink's title attribute.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3380
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3381
		$link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3382
		echo $before, $link, $after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3383
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3384
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3385
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3386
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3387
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3388
 * Retrieve the avatar URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3389
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3390
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3391
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3392
 * @param mixed $id_or_email The Gravatar to retrieve a URL for. Accepts a user_id, gravatar md5 hash,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3393
 *                           user email, WP_User object, WP_Post object, or comment object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3394
 * @param array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3395
 *     Optional. Arguments to return instead of the default arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3396
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3397
 *     @type int    $size           Height and width of the avatar in pixels. Default 96.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3398
 *     @type string $default        URL for the default image or a default type. Accepts '404' (return
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3399
 *                                  a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3400
 *                                  'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3401
 *                                  or 'mysterman' (The Oyster Man), 'blank' (transparent GIF), or
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3402
 *                                  'gravatar_default' (the Gravatar logo). Default is the value of the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3403
 *                                  'avatar_default' option, with a fallback of 'mystery'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3404
 *     @type bool   $force_default  Whether to always show the default image, never the Gravatar. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3405
 *     @type string $rating         What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3406
 *                                  judged in that order. Default is the value of the 'avatar_rating' option.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3407
 *     @type string $scheme         URL scheme to use. See set_url_scheme() for accepted values.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3408
 *                                  Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3409
 *     @type array  $processed_args When the function returns, the value will be the processed/sanitized $args
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3410
 *                                  plus a "found_avatar" guess. Pass as a reference. Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3411
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3412
 * @return false|string The URL of the avatar we found, or false if we couldn't find an avatar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3413
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3414
function get_avatar_url( $id_or_email, $args = null ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3415
	$args = get_avatar_data( $id_or_email, $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3416
	return $args['url'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3417
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3418
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3419
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3420
 * Retrieve default data about the avatar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3421
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3422
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3423
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3424
 * @param mixed $id_or_email The Gravatar to check the data against. Accepts a user_id, gravatar md5 hash,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3425
 *                           user email, WP_User object, WP_Post object, or comment object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3426
 * @param array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3427
 *     Optional. Arguments to return instead of the default arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3428
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3429
 *     @type int    $size           Height and width of the avatar image file in pixels. Default 96.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3430
 *     @type int    $height         Display height of the avatar in pixels. Defaults to $size.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3431
 *     @type int    $width          Display width of the avatar in pixels. Defaults to $size.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3432
 *     @type string $default        URL for the default image or a default type. Accepts '404' (return
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3433
 *                                  a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3434
 *                                  'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3435
 *                                  or 'mysterman' (The Oyster Man), 'blank' (transparent GIF), or
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3436
 *                                  'gravatar_default' (the Gravatar logo). Default is the value of the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3437
 *                                  'avatar_default' option, with a fallback of 'mystery'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3438
 *     @type bool   $force_default  Whether to always show the default image, never the Gravatar. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3439
 *     @type string $rating         What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3440
 *                                  judged in that order. Default is the value of the 'avatar_rating' option.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3441
 *     @type string $scheme         URL scheme to use. See set_url_scheme() for accepted values.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3442
 *                                  Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3443
 *     @type array  $processed_args When the function returns, the value will be the processed/sanitized $args
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3444
 *                                  plus a "found_avatar" guess. Pass as a reference. Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3445
 *     @type string $extra_attr     HTML attributes to insert in the IMG element. Is not sanitized. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3446
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3447
 * @return array $processed_args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3448
 *     Along with the arguments passed in `$args`, this will contain a couple of extra arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3449
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3450
 *     @type bool   $found_avatar True if we were able to find an avatar for this user,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3451
 *                                false or not set if we couldn't.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3452
 *     @type string $url          The URL of the avatar we found.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3453
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3454
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3455
function get_avatar_data( $id_or_email, $args = null ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3456
	$args = wp_parse_args( $args, array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3457
		'size'           => 96,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3458
		'height'         => null,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3459
		'width'          => null,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3460
		'default'        => get_option( 'avatar_default', 'mystery' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3461
		'force_default'  => false,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3462
		'rating'         => get_option( 'avatar_rating' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3463
		'scheme'         => null,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3464
		'processed_args' => null, // if used, should be a reference
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3465
		'extra_attr'     => '',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3466
	) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3467
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3468
	if ( is_numeric( $args['size'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3469
		$args['size'] = absint( $args['size'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3470
		if ( ! $args['size'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3471
			$args['size'] = 96;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3472
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3473
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3474
		$args['size'] = 96;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3475
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3476
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3477
	if ( is_numeric( $args['height'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3478
		$args['height'] = absint( $args['height'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3479
		if ( ! $args['height'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3480
			$args['height'] = $args['size'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3481
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3482
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3483
		$args['height'] = $args['size'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3484
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3485
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3486
	if ( is_numeric( $args['width'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3487
		$args['width'] = absint( $args['width'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3488
		if ( ! $args['width'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3489
			$args['width'] = $args['size'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3490
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3491
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3492
		$args['width'] = $args['size'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3493
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3494
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3495
	if ( empty( $args['default'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3496
		$args['default'] = get_option( 'avatar_default', 'mystery' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3497
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3498
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3499
	switch ( $args['default'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3500
		case 'mm' :
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3501
		case 'mystery' :
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3502
		case 'mysteryman' :
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3503
			$args['default'] = 'mm';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3504
			break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3505
		case 'gravatar_default' :
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3506
			$args['default'] = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3507
			break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3508
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3509
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3510
	$args['force_default'] = (bool) $args['force_default'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3511
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3512
	$args['rating'] = strtolower( $args['rating'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3513
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3514
	$args['found_avatar'] = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3515
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3516
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3517
	 * Filter whether to retrieve the avatar URL early.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3518
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3519
	 * Passing a non-null value in the 'url' member of the return array will
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3520
	 * effectively short circuit get_avatar_data(), passing the value through
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3521
	 * the {@see 'get_avatar_data'} filter and returning early.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3522
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3523
	 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3524
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3525
	 * @param array             $args          Arguments passed to get_avatar_data(), after processing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3526
	 * @param int|object|string $id_or_email   A user ID, email address, or comment object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3527
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3528
	$args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3529
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3530
	if ( isset( $args['url'] ) && ! is_null( $args['url'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3531
		/** This filter is documented in wp-includes/link-template.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3532
		return apply_filters( 'get_avatar_data', $args, $id_or_email );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3533
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3534
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3535
	$email_hash = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3536
	$user = $email = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3537
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3538
	// Process the user identifier.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3539
	if ( is_numeric( $id_or_email ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3540
		$user = get_user_by( 'id', absint( $id_or_email ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3541
	} elseif ( is_string( $id_or_email ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3542
		if ( strpos( $id_or_email, '@md5.gravatar.com' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3543
			// md5 hash
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3544
			list( $email_hash ) = explode( '@', $id_or_email );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3545
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3546
			// email address
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3547
			$email = $id_or_email;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3548
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3549
	} elseif ( $id_or_email instanceof WP_User ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3550
		// User Object
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3551
		$user = $id_or_email;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3552
	} elseif ( $id_or_email instanceof WP_Post ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3553
		// Post Object
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3554
		$user = get_user_by( 'id', (int) $id_or_email->post_author );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3555
	} elseif ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3556
		// Comment Object
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3557
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3558
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3559
		 * Filter the list of allowed comment types for retrieving avatars.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3560
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3561
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3562
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3563
		 * @param array $types An array of content types. Default only contains 'comment'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3564
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3565
		$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3566
		if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3567
			$args['url'] = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3568
			/** This filter is documented in wp-includes/link-template.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3569
			return apply_filters( 'get_avatar_data', $args, $id_or_email );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3570
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3571
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3572
		if ( ! empty( $id_or_email->user_id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3573
			$user = get_user_by( 'id', (int) $id_or_email->user_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3574
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3575
		if ( ( ! $user || is_wp_error( $user ) ) && ! empty( $id_or_email->comment_author_email ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3576
			$email = $id_or_email->comment_author_email;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3577
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3578
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3579
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3580
	if ( ! $email_hash ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3581
		if ( $user ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3582
			$email = $user->user_email;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3583
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3584
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3585
		if ( $email ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3586
			$email_hash = md5( strtolower( trim( $email ) ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3587
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3588
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3589
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3590
	if ( $email_hash ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3591
		$args['found_avatar'] = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3592
		$gravatar_server = hexdec( $email_hash[0] ) % 3;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3593
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3594
		$gravatar_server = rand( 0, 2 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3595
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3596
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3597
	$url_args = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3598
		's' => $args['size'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3599
		'd' => $args['default'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3600
		'f' => $args['force_default'] ? 'y' : false,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3601
		'r' => $args['rating'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3602
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3603
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3604
	$url = sprintf( 'http://%d.gravatar.com/avatar/%s', $gravatar_server, $email_hash );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3605
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3606
	$url = add_query_arg(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3607
		rawurlencode_deep( array_filter( $url_args ) ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3608
		set_url_scheme( $url, $args['scheme'] )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3609
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3610
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3611
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3612
	 * Filter the avatar URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3613
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3614
	 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3615
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3616
	 * @param string            $url         The URL of the avatar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3617
	 * @param int|object|string $id_or_email A user ID, email address, or comment object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3618
	 * @param array             $args        Arguments passed to get_avatar_data(), after processing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3619
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3620
	$args['url'] = apply_filters( 'get_avatar_url', $url, $id_or_email, $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3621
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3622
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3623
	 * Filter the avatar data.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3624
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3625
	 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3626
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3627
	 * @param array             $args        Arguments passed to get_avatar_data(), after processing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3628
	 * @param int|object|string $id_or_email A user ID, email address, or comment object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3629
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3630
	return apply_filters( 'get_avatar_data', $args, $id_or_email );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3631
}