wp/wp-includes/general-template.php
author ymh <ymh.work@gmail.com>
Thu, 07 Nov 2013 00:08:07 +0000
changeset 1 f6eb5a861d2f
parent 0 d970ebf37754
child 5 5e2f62d02dcd
permissions -rw-r--r--
remove unnessary files. Make timthumb work
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
 * General template tags that can go anywhere in a template.
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
 * Load header template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * Includes the header template for a theme or if a name is specified then a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * specialised header will be included.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * For the parameter, if the file is called "header-special.php" then specify
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * "special".
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 * @uses locate_template()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 * @uses do_action() Calls 'get_header' action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
 * @param string $name The name of the specialised header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
function get_header( $name = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
	do_action( 'get_header', $name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	$name = (string) $name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	if ( '' !== $name )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
		$templates[] = "header-{$name}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	$templates[] = 'header.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	// Backward compat code will be removed in a future release
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	if ('' == locate_template($templates, true))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
		load_template( ABSPATH . WPINC . '/theme-compat/header.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
 * Load footer template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
 * Includes the footer template for a theme or if a name is specified then a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
 * specialised footer will be included.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
 * For the parameter, if the file is called "footer-special.php" then specify
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
 * "special".
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
 * @uses locate_template()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
 * @uses do_action() Calls 'get_footer' action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
 * @param string $name The name of the specialised footer.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
function get_footer( $name = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	do_action( 'get_footer', $name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	$name = (string) $name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	if ( '' !== $name )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
		$templates[] = "footer-{$name}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	$templates[] = 'footer.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	// Backward compat code will be removed in a future release
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	if ('' == locate_template($templates, true))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
		load_template( ABSPATH . WPINC . '/theme-compat/footer.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
 * Load sidebar template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
 * Includes the sidebar template for a theme or if a name is specified then a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
 * specialised sidebar will be included.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
 * For the parameter, if the file is called "sidebar-special.php" then specify
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
 * "special".
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
 * @uses locate_template()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
 * @uses do_action() Calls 'get_sidebar' action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
 * @param string $name The name of the specialised sidebar.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
function get_sidebar( $name = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
	do_action( 'get_sidebar', $name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	$name = (string) $name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	if ( '' !== $name )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
		$templates[] = "sidebar-{$name}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	$templates[] = 'sidebar.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
	// Backward compat code will be removed in a future release
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
	if ('' == locate_template($templates, true))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
		load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
 * Load a template part into a template
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
 * Makes it easy for a theme to reuse sections of code in a easy to overload way
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
 * for child themes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
 * Includes the named template part for a theme or if a name is specified then a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
 * specialised part will be included. If the theme contains no {slug}.php file
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
 * then no template will be included.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
 * The template is included using require, not require_once, so you may include the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
 * same template part multiple times.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
 * For the $name parameter, if the file is called "{slug}-special.php" then specify
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
 * "special".
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
 * @uses locate_template()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
 * @uses do_action() Calls 'get_template_part_{$slug}' action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
 * @param string $slug The slug name for the generic template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
 * @param string $name The name of the specialised template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
function get_template_part( $slug, $name = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
	do_action( "get_template_part_{$slug}", $slug, $name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	$name = (string) $name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
	if ( '' !== $name )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
		$templates[] = "{$slug}-{$name}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
	$templates[] = "{$slug}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
	locate_template($templates, true, 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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
 * Display search form.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
 * Will first attempt to locate the searchform.php file in either the child or
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
 * the parent, then load it. If it doesn't exist, then the default search form
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
 * will be displayed. The default search form is HTML, which will be displayed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
 * There is a filter applied to the search form HTML in order to edit or replace
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
 * it. The filter is 'get_search_form'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
 * This function is primarily used by themes which want to hardcode the search
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
 * form into the sidebar and also by the search widget in WordPress.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
 * There is also an action that is called whenever the function is run called,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
 * 'pre_get_search_form'. This can be useful for outputting JavaScript that the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
 * search relies on or various formatting that applies to the beginning of the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
 * search. To give a few examples of what it can be used for.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
 * @uses apply_filters() Calls 'search_form_format' filter to determine which type to use for the search field.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
 *  If set to 'html5', it changes to search input type and adds placeholder text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
 * @param boolean $echo Default to echo and not return the form.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
 * @return string|null String when retrieving, null when displaying or if searchform.php exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
function get_search_form( $echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
	do_action( 'pre_get_search_form' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
	$format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
	$format = apply_filters( 'search_form_format', $format );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
	$search_form_template = locate_template( 'searchform.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
	if ( '' != $search_form_template ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
		ob_start();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
		require( $search_form_template );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
		$form = ob_get_clean();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
		if ( 'html5' == $format ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
			$form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
				<label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
					<span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
					<input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search &hellip;', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" title="' . esc_attr_x( 'Search for:', 'label' ) . '" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
				</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
				<input type="submit" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
			</form>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
			$form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
				<div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
					<label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
					<input type="text" value="' . get_search_query() . '" name="s" id="s" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
					<input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
				</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
			</form>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
	$result = apply_filters( 'get_search_form', $form );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
	if ( null === $result )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
		$result = $form;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
	if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
		echo $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
		return $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
 * Display the Log In/Out link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
 * Displays a link, which allows users to navigate to the Log In page to log in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
 * or log out depending on whether they are currently logged in.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
 * @uses apply_filters() Calls 'loginout' hook on HTML link content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
 * @param string $redirect Optional path to redirect to on login/logout.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
 * @param boolean $echo Default to echo and not return the link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
 * @return string|null String when retrieving, null when displaying.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
function wp_loginout($redirect = '', $echo = true) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
	if ( ! is_user_logged_in() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
		$link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
		$link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
	if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
		echo apply_filters('loginout', $link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
		return apply_filters('loginout', $link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
 * Returns the Log Out URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
 * Returns the URL that allows the user to log out of the site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
 * @uses wp_nonce_url() To protect against CSRF.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
 * @uses site_url() To generate the log out URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
 * @uses apply_filters() calls 'logout_url' hook on final logout URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
 * @param string $redirect Path to redirect to on logout.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
 * @return string A log out URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
function wp_logout_url($redirect = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
	$args = array( 'action' => 'logout' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
	if ( !empty($redirect) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
		$args['redirect_to'] = urlencode( $redirect );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
	$logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
	$logout_url = wp_nonce_url( $logout_url, 'log-out' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
	return apply_filters('logout_url', $logout_url, $redirect);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
 * Returns the Log In URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
 * Returns the URL that allows the user to log in to the site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
 * @uses site_url() To generate the log in URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
 * @uses apply_filters() calls 'login_url' hook on final login URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
 * @param string $redirect Path to redirect to on login.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
 * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
 * @return string A log in URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
function wp_login_url($redirect = '', $force_reauth = false) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
	$login_url = site_url('wp-login.php', 'login');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
	if ( !empty($redirect) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
		$login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
	if ( $force_reauth )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
		$login_url = add_query_arg('reauth', '1', $login_url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
	return apply_filters('login_url', $login_url, $redirect);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
 * Returns the user registration URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
 * Returns the URL that allows the user to register on the site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
 * @uses site_url() To generate the registration URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
 * @uses apply_filters() calls 'register_url' hook on final URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
function wp_registration_url() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
	return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
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
 * Provides a simple login form for use anywhere within WordPress. By default, it echoes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
 * the HTML immediately. Pass array('echo'=>false) to return the string instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
 * @param array $args Configuration options to modify the form output.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
 * @return string|null String when retrieving, null when displaying.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
function wp_login_form( $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
		'echo' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
		'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // Default redirect is back to the current page
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
		'form_id' => 'loginform',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
		'label_username' => __( 'Username' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
		'label_password' => __( 'Password' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
		'label_remember' => __( 'Remember Me' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
		'label_log_in' => __( 'Log In' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
		'id_username' => 'user_login',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
		'id_password' => 'user_pass',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
		'id_remember' => 'rememberme',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
		'id_submit' => 'wp-submit',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
		'remember' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
		'value_username' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
		'value_remember' => false, // Set this to true to default the "Remember me" checkbox to checked
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
	$args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
	$form = '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
		<form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
			' . apply_filters( 'login_form_top', '', $args ) . '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
			<p class="login-username">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
				<label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
				<input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
			</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
			<p class="login-password">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
				<label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
				<input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
			</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
			' . apply_filters( 'login_form_middle', '', $args ) . '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
			' . ( $args['remember'] ? '<p class="login-remember"><label><input name="rememberme" type="checkbox" id="' . esc_attr( $args['id_remember'] ) . '" value="forever"' . ( $args['value_remember'] ? ' checked="checked"' : '' ) . ' /> ' . esc_html( $args['label_remember'] ) . '</label></p>' : '' ) . '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
			<p class="login-submit">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
				<input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
				<input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
			</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
			' . apply_filters( 'login_form_bottom', '', $args ) . '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
		</form>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
	if ( $args['echo'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
		echo $form;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
		return $form;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
 * Returns the Lost Password URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
 * Returns the URL that allows the user to retrieve the lost password
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
 * @uses site_url() To generate the lost password URL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
 * @uses apply_filters() calls 'lostpassword_url' hook on the lostpassword url
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
 * @param string $redirect Path to redirect to on login.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
 * @return string Lost password URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
function wp_lostpassword_url( $redirect = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
	$args = array( 'action' => 'lostpassword' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
	if ( !empty($redirect) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
		$args['redirect_to'] = $redirect;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
	$lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
	return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
 * Display the Registration or Admin link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
 * Display a link which allows the user to navigate to the registration page if
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
 * not logged in and registration is enabled or to the dashboard if logged in.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
 * @uses apply_filters() Calls 'register' hook on register / admin link content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
 * @param string $before Text to output before the link (defaults to <li>).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
 * @param string $after Text to output after the link (defaults to </li>).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
 * @param boolean $echo Default to echo and not return the link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
 * @return string|null String when retrieving, null when displaying.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
	if ( ! is_user_logged_in() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
		if ( get_option('users_can_register') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
			$link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register') . '</a>' . $after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
			$link = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
		$link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
	if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
		echo apply_filters('register', $link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
		return apply_filters('register', $link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
 * Theme container function for the 'wp_meta' action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
 * The 'wp_meta' action can have several purposes, depending on how you use it,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
 * but one purpose might have been to allow for theme switching.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
 * @link http://trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
 * @uses do_action() Calls 'wp_meta' hook.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
function wp_meta() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
	do_action('wp_meta');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
 * Display information about the blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
 * @see get_bloginfo() For possible values for the parameter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
 * @param string $show What to display.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
function bloginfo( $show='' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
	echo get_bloginfo( $show, 'display' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
 * Retrieve information about the blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
 * Some show parameter values are deprecated and will be removed in future
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
 * versions. These options will trigger the _deprecated_argument() function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
 * The deprecated blog info options are listed in the function contents.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
 * The possible values for the 'show' parameter are listed below.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
 * <ol>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
 * <li><strong>url</strong> - Blog URI to homepage.</li>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
 * <li><strong>wpurl</strong> - Blog URI path to WordPress.</li>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
 * <li><strong>description</strong> - Secondary title</li>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
 * </ol>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
 * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
 * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
 * comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
 * feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
 * @param string $show Blog info to retrieve.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
 * @param string $filter How to filter what is retrieved.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
 * @return string Mostly string values, might be empty.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
function get_bloginfo( $show = '', $filter = 'raw' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	switch( $show ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
		case 'home' : // DEPRECATED
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
		case 'siteurl' : // DEPRECATED
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
			_deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The <code>%s</code> option is deprecated for the family of <code>bloginfo()</code> functions.' ), $show ) . ' ' . sprintf( __( 'Use the <code>%s</code> option instead.' ), 'url'  ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
		case 'url' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
			$output = home_url();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
		case 'wpurl' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
			$output = site_url();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
		case 'description':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
			$output = get_option('blogdescription');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
		case 'rdf_url':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
			$output = get_feed_link('rdf');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
		case 'rss_url':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
			$output = get_feed_link('rss');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
		case 'rss2_url':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
			$output = get_feed_link('rss2');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
		case 'atom_url':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
			$output = get_feed_link('atom');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
		case 'comments_atom_url':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
			$output = get_feed_link('comments_atom');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
		case 'comments_rss2_url':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
			$output = get_feed_link('comments_rss2');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
		case 'pingback_url':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
			$output = site_url( 'xmlrpc.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
		case 'stylesheet_url':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
			$output = get_stylesheet_uri();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
		case 'stylesheet_directory':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
			$output = get_stylesheet_directory_uri();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
		case 'template_directory':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
		case 'template_url':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
			$output = get_template_directory_uri();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
		case 'admin_email':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
			$output = get_option('admin_email');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
		case 'charset':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
			$output = get_option('blog_charset');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
			if ('' == $output) $output = 'UTF-8';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
		case 'html_type' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
			$output = get_option('html_type');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
		case 'version':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
			global $wp_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
			$output = $wp_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
		case 'language':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
			$output = get_locale();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
			$output = str_replace('_', '-', $output);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
		case 'text_direction':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
			//_deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The <code>%s</code> option is deprecated for the family of <code>bloginfo()</code> functions.' ), $show ) . ' ' . sprintf( __( 'Use the <code>%s</code> function instead.' ), 'is_rtl()'  ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
			if ( function_exists( 'is_rtl' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
				$output = is_rtl() ? 'rtl' : 'ltr';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
				$output = 'ltr';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
		case 'name':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
		default:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
			$output = get_option('blogname');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
	$url = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	if (strpos($show, 'url') === false &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
		strpos($show, 'directory') === false &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
		strpos($show, 'home') === false)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
		$url = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
	if ( 'display' == $filter ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
		if ( $url )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
			$output = apply_filters('bloginfo_url', $output, $show);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
			$output = apply_filters('bloginfo', $output, $show);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
	return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
}
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
 * Display or retrieve page title for all areas of blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
 * By default, the page title will display the separator before the page title,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
 * so that the blog title will be before the page title. This is not good for
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
 * title display, since the blog title shows up on most tabs and not what is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
 * important, which is the page that the user is looking at.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
 * There are also SEO benefits to having the blog title after or to the 'right'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
 * or the page title. However, it is mostly common sense to have the blog title
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
 * to the right with most browsers supporting tabs. You can achieve this by
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
 * using the seplocation parameter and setting the value to 'right'. This change
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
 * was introduced around 2.5.0, in case backwards compatibility of themes is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
 * important.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
 * @param string $sep Optional, default is '&raquo;'. How to separate the various items within the page title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
 * @param bool $display Optional, default is true. Whether to display or retrieve title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
 * @param string $seplocation Optional. Direction to display title, 'right'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
 * @return string|null String on retrieve, null when displaying.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
	global $wpdb, $wp_locale;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
	$m = get_query_var('m');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
	$year = get_query_var('year');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
	$monthnum = get_query_var('monthnum');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
	$day = get_query_var('day');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
	$search = get_query_var('s');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
	$title = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
	$t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
	// If there is a post
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
	if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
		$title = single_post_title( '', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
	// If there's a post type archive
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
	if ( is_post_type_archive() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
		$post_type = get_query_var( 'post_type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
		if ( is_array( $post_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
			$post_type = reset( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
		$post_type_object = get_post_type_object( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
		if ( ! $post_type_object->has_archive )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
			$title = post_type_archive_title( '', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
	// If there's a category or tag
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
	if ( is_category() || is_tag() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
		$title = single_term_title( '', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
	// If there's a taxonomy
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
	if ( is_tax() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
		$term = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
		if ( $term ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
			$tax = get_taxonomy( $term->taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
			$title = single_term_title( $tax->labels->name . $t_sep, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
	// If there's an author
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
	if ( is_author() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
		$author = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
		if ( $author )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
			$title = $author->display_name;
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
	// Post type archives with has_archive should override terms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
	if ( is_post_type_archive() && $post_type_object->has_archive )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
		$title = post_type_archive_title( '', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
	// If there's a month
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
	if ( is_archive() && !empty($m) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
		$my_year = substr($m, 0, 4);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
		$my_month = $wp_locale->get_month(substr($m, 4, 2));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
		$my_day = intval(substr($m, 6, 2));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
		$title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
	// If there's a year
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
	if ( is_archive() && !empty($year) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
		$title = $year;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
		if ( !empty($monthnum) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
			$title .= $t_sep . $wp_locale->get_month($monthnum);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
		if ( !empty($day) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
			$title .= $t_sep . zeroise($day, 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
	// If it's a search
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
	if ( is_search() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
		/* translators: 1: separator, 2: search phrase */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
		$title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
	// If it's a 404 page
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
	if ( is_404() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
		$title = __('Page not found');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
	$prefix = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
	if ( !empty($title) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
		$prefix = " $sep ";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
 	// Determines position of the separator and direction of the breadcrumb
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
	if ( 'right' == $seplocation ) { // sep on right, so reverse the order
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
		$title_array = explode( $t_sep, $title );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
		$title_array = array_reverse( $title_array );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
		$title = implode( " $sep ", $title_array ) . $prefix;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
		$title_array = explode( $t_sep, $title );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
		$title = $prefix . implode( " $sep ", $title_array );
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
	$title = apply_filters('wp_title', $title, $sep, $seplocation);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
	// Send it out
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
	if ( $display )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
		echo $title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
		return $title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
 * Display or retrieve page title for 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
 * This is optimized for single.php template file for displaying the post title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
 * It does not support placing the separator after the title, but by leaving the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
 * prefix parameter empty, you can set the title separator manually. The prefix
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
 * does not automatically place a space between the prefix, so if there should
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
 * be a space, the parameter value will need to have it at the end.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
 * @param string $prefix Optional. What to display before the title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
 * @param bool $display Optional, default is true. Whether to display or retrieve title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
 * @return string|null Title when retrieving, null when displaying or failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
function single_post_title($prefix = '', $display = true) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
	$_post = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
	if ( !isset($_post->post_title) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
	$title = apply_filters('single_post_title', $_post->post_title, $_post);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
	if ( $display )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
		echo $prefix . $title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
		return $prefix . $title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
 * Display or retrieve title for a post type archive.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
 * This is optimized for archive.php and archive-{$post_type}.php template files
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
 * for displaying the title of the post type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
 * @param string $prefix Optional. What to display before the title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
 * @param bool $display Optional, default is true. Whether to display or retrieve title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
 * @return string|null Title when retrieving, null when displaying or failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
function post_type_archive_title( $prefix = '', $display = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
	if ( ! is_post_type_archive() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
	$post_type = get_query_var( 'post_type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
	if ( is_array( $post_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
		$post_type = reset( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
	$post_type_obj = get_post_type_object( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
	$title = apply_filters('post_type_archive_title', $post_type_obj->labels->name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
	if ( $display )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
		echo $prefix . $title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
		return $prefix . $title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
 * Display or retrieve page title for category archive.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
 * This is useful for category template file or files, because it is optimized
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
 * for category page title and with less overhead than {@link wp_title()}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
 * It does not support placing the separator after the title, but by leaving the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
 * prefix parameter empty, you can set the title separator manually. The prefix
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
 * does not automatically place a space between the prefix, so if there should
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
 * be a space, the parameter value will need to have it at the end.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
 * @param string $prefix Optional. What to display before the title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
 * @param bool $display Optional, default is true. Whether to display or retrieve title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
 * @return string|null Title when retrieving, null when displaying or failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
function single_cat_title( $prefix = '', $display = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
	return single_term_title( $prefix, $display );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
}
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
 * Display or retrieve page title for tag post archive.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
 * Useful for tag template files for displaying the tag page title. It has less
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
 * overhead than {@link wp_title()}, because of its limited implementation.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
 * It does not support placing the separator after the title, but by leaving the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
 * prefix parameter empty, you can set the title separator manually. The prefix
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
 * does not automatically place a space between the prefix, so if there should
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
 * be a space, the parameter value will need to have it at the end.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
 * @param string $prefix Optional. What to display before the title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
 * @param bool $display Optional, default is true. Whether to display or retrieve title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
 * @return string|null Title when retrieving, null when displaying or failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
function single_tag_title( $prefix = '', $display = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
	return single_term_title( $prefix, $display );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
 * Display or retrieve page title for taxonomy term archive.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
 * Useful for taxonomy term template files for displaying the taxonomy term page title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
 * It has less overhead than {@link wp_title()}, because of its limited implementation.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
 * It does not support placing the separator after the title, but by leaving the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
 * prefix parameter empty, you can set the title separator manually. The prefix
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
 * does not automatically place a space between the prefix, so if there should
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
 * be a space, the parameter value will need to have it at the end.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
 * @param string $prefix Optional. What to display before the title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
 * @param bool $display Optional, default is true. Whether to display or retrieve title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
 * @return string|null Title when retrieving, null when displaying or failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
function single_term_title( $prefix = '', $display = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
	$term = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
	if ( !$term )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
	if ( is_category() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
		$term_name = apply_filters( 'single_cat_title', $term->name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
	elseif ( is_tag() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
		$term_name = apply_filters( 'single_tag_title', $term->name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
	elseif ( is_tax() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
		$term_name = apply_filters( 'single_term_title', $term->name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
	if ( empty( $term_name ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
	if ( $display )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
		echo $prefix . $term_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
		return $prefix . $term_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
 * Display or retrieve page title for post archive based on date.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
 * Useful for when the template only needs to display the month and year, if
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
 * either are available. Optimized for just this purpose, so if it is all that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
 * is needed, should be better than {@link wp_title()}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
 * It does not support placing the separator after the title, but by leaving the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
 * prefix parameter empty, you can set the title separator manually. The prefix
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
 * does not automatically place a space between the prefix, so if there should
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
 * be a space, the parameter value will need to have it at the end.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
 * @param string $prefix Optional. What to display before the title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
 * @param bool $display Optional, default is true. Whether to display or retrieve title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
 * @return string|null Title when retrieving, null when displaying or failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
function single_month_title($prefix = '', $display = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
	global $wp_locale;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
	$m = get_query_var('m');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
	$year = get_query_var('year');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
	$monthnum = get_query_var('monthnum');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
	if ( !empty($monthnum) && !empty($year) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
		$my_year = $year;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
		$my_month = $wp_locale->get_month($monthnum);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
	} elseif ( !empty($m) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
		$my_year = substr($m, 0, 4);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
		$my_month = $wp_locale->get_month(substr($m, 4, 2));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
	if ( empty($my_month) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
	$result = $prefix . $my_month . $prefix . $my_year;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
	if ( !$display )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
		return $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
	echo $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
 * Retrieve archive link content based on predefined or custom code.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
 * The format can be one of four styles. The 'link' for head element, 'option'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
 * for use in the select element, 'html' for use in list (either ol or ul HTML
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
 * elements). Custom content is also supported using the before and after
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
 * parameters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
 * The 'link' format uses the link HTML element with the <em>archives</em>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
 * relationship. The before and after parameters are not used. The text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
 * parameter is used to describe the link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
 * The 'option' format uses the option HTML element for use in select element.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
 * The value is the url parameter and the before and after parameters are used
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
 * between the text description.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
 * The 'html' format, which is the default, uses the li HTML element for use in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
 * the list HTML elements. The before parameter is before the link and the after
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
 * parameter is after the closing link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
 * The custom format uses the before parameter before the link ('a' HTML
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
 * element) and the after parameter after the closing link tag. If the above
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
 * three values for the format are not used, then custom format is assumed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
 * @param string $url URL to archive.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
 * @param string $text Archive text description.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
 * @param string $before Optional.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
 * @param string $after Optional.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
 * @return string HTML link content for archive.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
	$text = wptexturize($text);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
	$url = esc_url($url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
	if ('link' == $format)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
		$link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
	elseif ('option' == $format)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
		$link_html = "\t<option value='$url'>$before $text $after</option>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
	elseif ('html' == $format)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
		$link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
	else // custom
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
		$link_html = "\t$before<a href='$url'>$text</a>$after\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
	$link_html = apply_filters( 'get_archives_link', $link_html );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
	return $link_html;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
 * Display archive links based on type and format.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
 * The 'type' argument offers a few choices and by default will display monthly
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
 * archive links. The other options for values are 'daily', 'weekly', 'monthly',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
 * 'yearly', 'postbypost' or 'alpha'. Both 'postbypost' and 'alpha' display the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
 * same archive link list, the difference between the two is that 'alpha'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
 * will order by post title and 'postbypost' will order by post date.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
 * The date archives will logically display dates with links to the archive post
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
 * page. The 'postbypost' and 'alpha' values for 'type' argument will display
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
 * the post titles.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
 * The 'limit' argument will only display a limited amount of links, specified
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
 * by the 'limit' integer value. By default, there is no limit. The
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
 * 'show_post_count' argument will show how many posts are within the archive.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
 * By default, the 'show_post_count' argument is set to false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
 * For the 'format', 'before', and 'after' arguments, see {@link
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
 * get_archives_link()}. The values of these arguments have to do with that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
 * function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
 * @param string|array $args Optional. Override defaults.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
 * @return string|null String when retrieving, null when displaying.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
function wp_get_archives($args = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
	global $wpdb, $wp_locale;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
		'type' => 'monthly', 'limit' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
		'format' => 'html', 'before' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
		'after' => '', 'show_post_count' => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
		'echo' => 1, 'order' => 'DESC',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
	$r = wp_parse_args( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
	extract( $r, EXTR_SKIP );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
	if ( '' == $type )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
		$type = 'monthly';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
	if ( '' != $limit ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
		$limit = absint($limit);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
		$limit = ' LIMIT '.$limit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
	$order = strtoupper( $order );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
	if ( $order !== 'ASC' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
		$order = 'DESC';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
	// this is what will separate dates on weekly archive links
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
	$archive_week_separator = '&#8211;';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
	// over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
	$archive_date_format_over_ride = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
	// options for daily archive (only if you over-ride the general date format)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
	$archive_day_date_format = 'Y/m/d';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
	// options for weekly archive (only if you over-ride the general date format)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
	$archive_week_start_date_format = 'Y/m/d';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
	$archive_week_end_date_format	= 'Y/m/d';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
	if ( !$archive_date_format_over_ride ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
		$archive_day_date_format = get_option('date_format');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
		$archive_week_start_date_format = get_option('date_format');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
		$archive_week_end_date_format = get_option('date_format');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
	$where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
	$join = apply_filters( 'getarchives_join', '', $r );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
	$output = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
	$last_changed = wp_cache_get( 'last_changed', 'posts' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
	if ( ! $last_changed ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
		$last_changed = microtime();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
		wp_cache_set( 'last_changed', $last_changed, 'posts' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
	if ( 'monthly' == $type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
		$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
		$key = md5( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
		$key = "wp_get_archives:$key:$last_changed";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
		if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
			$results = $wpdb->get_results( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
			wp_cache_set( $key, $results, 'posts' );
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 ( $results ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
			$afterafter = $after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
			foreach ( (array) $results as $result ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
				$url = get_month_link( $result->year, $result->month );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
				/* translators: 1: month name, 2: 4-digit year */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
				$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
				if ( $show_post_count )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
					$after = '&nbsp;('.$result->posts.')' . $afterafter;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
				$output .= get_archives_link($url, $text, $format, $before, $after);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
	} elseif ('yearly' == $type) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
		$query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
		$key = md5( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
		$key = "wp_get_archives:$key:$last_changed";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
		if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
			$results = $wpdb->get_results( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
			wp_cache_set( $key, $results, 'posts' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
		if ( $results ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
			$afterafter = $after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
			foreach ( (array) $results as $result) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
				$url = get_year_link($result->year);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
				$text = sprintf('%d', $result->year);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
				if ($show_post_count)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
					$after = '&nbsp;('.$result->posts.')' . $afterafter;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
				$output .= get_archives_link($url, $text, $format, $before, $after);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
	} elseif ( 'daily' == $type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
		$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
		$key = md5( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
		$key = "wp_get_archives:$key:$last_changed";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
		if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
			$results = $wpdb->get_results( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
			$cache[ $key ] = $results;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
			wp_cache_set( $key, $results, 'posts' );
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 ( $results ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
			$afterafter = $after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
			foreach ( (array) $results as $result ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
				$url	= get_day_link($result->year, $result->month, $result->dayofmonth);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
				$date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
				$text = mysql2date($archive_day_date_format, $date);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
				if ($show_post_count)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
					$after = '&nbsp;('.$result->posts.')'.$afterafter;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
				$output .= get_archives_link($url, $text, $format, $before, $after);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1039
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
	} elseif ( 'weekly' == $type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1042
		$week = _wp_mysql_week( '`post_date`' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
		$query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1044
		$key = md5( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
		$key = "wp_get_archives:$key:$last_changed";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
		if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
			$results = $wpdb->get_results( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
			wp_cache_set( $key, $results, 'posts' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1049
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1050
		$arc_w_last = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1051
		$afterafter = $after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
		if ( $results ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
				foreach ( (array) $results as $result ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
					if ( $result->week != $arc_w_last ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1055
						$arc_year = $result->yr;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
						$arc_w_last = $result->week;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
						$arc_week = get_weekstartend($result->yyyymmdd, get_option('start_of_week'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
						$arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
						$arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
						$url  = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&amp;', '=', $result->week);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
						$text = $arc_week_start . $archive_week_separator . $arc_week_end;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
						if ($show_post_count)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
							$after = '&nbsp;('.$result->posts.')'.$afterafter;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1064
						$output .= get_archives_link($url, $text, $format, $before, $after);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1066
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1067
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
	} elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
		$orderby = ('alpha' == $type) ? 'post_title ASC ' : 'post_date DESC ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
		$query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1071
		$key = md5( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
		$key = "wp_get_archives:$key:$last_changed";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
		if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
			$results = $wpdb->get_results( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
			wp_cache_set( $key, $results, 'posts' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1076
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
		if ( $results ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
			foreach ( (array) $results as $result ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
				if ( $result->post_date != '0000-00-00 00:00:00' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
					$url  = get_permalink( $result );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
					if ( $result->post_title ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
						/** This filter is documented in wp-includes/post-template.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
						$text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
					} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
						$text = $result->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1087
					$output .= get_archives_link($url, $text, $format, $before, $after);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
	if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
		echo $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1094
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1095
		return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1097
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1098
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
 * Get number of days since the start of the week.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
 * @param int $num Number of day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
 * @return int Days since the start of the week.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1106
function calendar_week_mod($num) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
	$base = 7;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
	return ($num - $base*floor($num/$base));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1110
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1111
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1112
 * Display calendar with days that have posts as links.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1113
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1114
 * The calendar is cached, which will be retrieved, if it exists. If there are
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
 * no posts for the month, then it will not be displayed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
 * @uses calendar_week_mod()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
 * @param bool $initial Optional, default is true. Use initial calendar names.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
 * @param bool $echo Optional, default is true. Set to false for return.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
 * @return string|null String when retrieving, null when displaying.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1123
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1124
function get_calendar($initial = true, $echo = true) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
	global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
	$cache = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
	$key = md5( $m . $monthnum . $year );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
	if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
		if ( is_array($cache) && isset( $cache[ $key ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
			if ( $echo ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
				echo apply_filters( 'get_calendar',  $cache[$key] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
				return apply_filters( 'get_calendar',  $cache[$key] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1138
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1140
	if ( !is_array($cache) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
		$cache = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
	// Quick check. If we have no posts at all, abort!
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1144
	if ( !$posts ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
		$gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1146
		if ( !$gotsome ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1147
			$cache[ $key ] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1148
			wp_cache_set( 'get_calendar', $cache, 'calendar' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1149
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
	if ( isset($_GET['w']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
		$w = ''.intval($_GET['w']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
	// week_begins = 0 stands for Sunday
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
	$week_begins = intval(get_option('start_of_week'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
	// Let's figure out when we are
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
	if ( !empty($monthnum) && !empty($year) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
		$thismonth = ''.zeroise(intval($monthnum), 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
		$thisyear = ''.intval($year);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
	} elseif ( !empty($w) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
		// We need to get the month from MySQL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
		$thisyear = ''.intval(substr($m, 0, 4));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
		$d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
		$thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
	} elseif ( !empty($m) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
		$thisyear = ''.intval(substr($m, 0, 4));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
		if ( strlen($m) < 6 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
				$thismonth = '01';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
				$thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
		$thisyear = gmdate('Y', current_time('timestamp'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
		$thismonth = gmdate('m', current_time('timestamp'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
	$unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
	$last_day = date('t', $unixmonth);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
	// Get the next and previous month and year with at least one post
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1183
	$previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
		FROM $wpdb->posts
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
		WHERE post_date < '$thisyear-$thismonth-01'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
		AND post_type = 'post' AND post_status = 'publish'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
			ORDER BY post_date DESC
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1188
			LIMIT 1");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
	$next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
		FROM $wpdb->posts
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
		WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
		AND post_type = 'post' AND post_status = 'publish'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
			ORDER BY post_date ASC
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
			LIMIT 1");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
	/* translators: Calendar caption: 1: month name, 2: 4-digit year */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
	$calendar_caption = _x('%1$s %2$s', 'calendar caption');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
	$calendar_output = '<table id="wp-calendar">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
	<caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
	<thead>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
	<tr>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
	$myweek = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
	for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
		$myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
	foreach ( $myweek as $wd ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
		$day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
		$wd = esc_attr($wd);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
		$calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
	$calendar_output .= '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
	</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1217
	</thead>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
	<tfoot>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
	<tr>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1221
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1222
	if ( $previous ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1223
		$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1224
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1225
		$calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1226
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1227
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1228
	$calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1229
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1230
	if ( $next ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
		$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1232
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1233
		$calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1235
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1236
	$calendar_output .= '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
	</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1238
	</tfoot>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1239
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1240
	<tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
	<tr>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1243
	// Get days with posts
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1244
	$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
		FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
		AND post_type = 'post' AND post_status = 'publish'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
		AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
	if ( $dayswithposts ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1249
		foreach ( (array) $dayswithposts as $daywith ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
			$daywithpost[] = $daywith[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
		$daywithpost = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
	if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
		$ak_title_separator = "\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
		$ak_title_separator = ', ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
	$ak_titles_for_day = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
	$ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1263
		."FROM $wpdb->posts "
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
		."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
		."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
		."AND post_type = 'post' AND post_status = 'publish'"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1268
	if ( $ak_post_titles ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1269
		foreach ( (array) $ak_post_titles as $ak_post_title ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1270
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
				/** This filter is documented in wp-includes/post-template.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
				$post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1273
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
				if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
					$ak_titles_for_day['day_'.$ak_post_title->dom] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
				if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
					$ak_titles_for_day["$ak_post_title->dom"] = $post_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
					$ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
	// See how much we should pad in the beginning
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
	$pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
	if ( 0 != $pad )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
		$calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
	$daysinmonth = intval(date('t', $unixmonth));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
	for ( $day = 1; $day <= $daysinmonth; ++$day ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
		if ( isset($newrow) && $newrow )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
			$calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
		$newrow = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1294
		if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
			$calendar_output .= '<td id="today">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1296
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1297
			$calendar_output .= '<td>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1298
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1299
		if ( in_array($day, $daywithpost) ) // any posts today?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1300
				$calendar_output .= '<a href="' . get_day_link( $thisyear, $thismonth, $day ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1301
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
			$calendar_output .= $day;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
		$calendar_output .= '</td>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1304
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
		if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1306
			$newrow = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
	$pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
	if ( $pad != 0 && $pad != 7 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
		$calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
	$calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
	$cache[ $key ] = $calendar_output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
	wp_cache_set( 'get_calendar', $cache, 'calendar' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
	if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
		echo apply_filters( 'get_calendar',  $calendar_output );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
		return apply_filters( 'get_calendar',  $calendar_output );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1323
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1324
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
 * Purge the cached results of get_calendar.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
 * @see get_calendar
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1329
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
function delete_get_calendar_cache() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
	wp_cache_delete( 'get_calendar', 'calendar' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
add_action( 'save_post', 'delete_get_calendar_cache' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
add_action( 'delete_post', 'delete_get_calendar_cache' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1337
add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
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 all of the allowed tags in HTML format with attributes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
 * This is useful for displaying in the comment area, which elements and
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
 * attributes are supported. As well as any plugins which want to display it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
 * @since 1.0.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
 * @uses $allowedtags
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
 * @return string HTML allowed tags entity encoded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
function allowed_tags() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
	global $allowedtags;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
	$allowed = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
	foreach ( (array) $allowedtags as $tag => $attributes ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
		$allowed .= '<'.$tag;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
		if ( 0 < count($attributes) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
			foreach ( $attributes as $attribute => $limits ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
				$allowed .= ' '.$attribute.'=""';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1360
		$allowed .= '> ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
	return htmlentities($allowed);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
/***** Date/Time tags *****/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
 * Outputs the date in iso8601 format for xml files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
function the_date_xml() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
	echo mysql2date( 'Y-m-d', get_post()->post_date, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
 * Display or Retrieve the date the current $post was written (once per date)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1378
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1379
 * Will only output the date if the current post's date is different from the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1380
 * previous one output.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1381
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1383
 * function is called several times for each post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1385
 * HTML output can be filtered with 'the_date'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1386
 * Date string output can be filtered with 'get_the_date'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1387
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1388
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1389
 * @uses get_the_date()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1390
 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1391
 * @param string $before Optional. Output before the date.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1392
 * @param string $after Optional. Output after the date.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1393
 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1394
 * @return string|null Null if displaying, string if retrieving.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1395
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1396
function the_date( $d = '', $before = '', $after = '', $echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1397
	global $currentday, $previousday;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1398
	$the_date = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1399
	if ( $currentday != $previousday ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1400
		$the_date .= $before;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1401
		$the_date .= get_the_date( $d );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1402
		$the_date .= $after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
		$previousday = $currentday;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1404
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1405
		$the_date = apply_filters('the_date', $the_date, $d, $before, $after);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1406
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1407
		if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1408
			echo $the_date;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1409
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1410
			return $the_date;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1411
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1412
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1413
	return null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1414
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1416
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1417
 * Retrieve the date the current $post was written.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
 * Unlike the_date() this function will always return the date.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
 * Modify output with 'get_the_date' filter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1421
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1423
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1424
 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1425
 * @return string|null Null if displaying, string if retrieving.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1426
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
function get_the_date( $d = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1428
	$post = get_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1429
	$the_date = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1430
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
	if ( '' == $d )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
		$the_date .= mysql2date(get_option('date_format'), $post->post_date);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1433
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
		$the_date .= mysql2date($d, $post->post_date);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1435
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1436
	return apply_filters('get_the_date', $the_date, $d);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1437
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1438
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
 * Display the date on which the post was last modified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1441
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1442
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1443
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1444
 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1445
 * @param string $before Optional. Output before the date.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1446
 * @param string $after Optional. Output after the date.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1447
 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
 * @return string|null Null if displaying, string if retrieving.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
function the_modified_date($d = '', $before='', $after='', $echo = true) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1451
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
	$the_modified_date = $before . get_the_modified_date($d) . $after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
	$the_modified_date = apply_filters('the_modified_date', $the_modified_date, $d, $before, $after);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1455
	if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1456
		echo $the_modified_date;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1457
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1458
		return $the_modified_date;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1459
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1460
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1461
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1462
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1463
 * Retrieve the date on which the post was last modified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1464
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1465
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1467
 * @param string $d Optional. PHP date format. Defaults to the "date_format" option
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1469
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1470
function get_the_modified_date($d = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1471
	if ( '' == $d )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1472
		$the_time = get_post_modified_time(get_option('date_format'), null, null, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1473
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1474
		$the_time = get_post_modified_time($d, null, null, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1475
	return apply_filters('get_the_modified_date', $the_time, $d);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1476
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1477
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1478
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1479
 * Display the time at which the post was written.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1480
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1481
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1482
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1483
 * @param string $d Either 'G', 'U', or php date format.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1484
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1485
function the_time( $d = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1486
	echo apply_filters('the_time', get_the_time( $d ), $d);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1487
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1488
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1489
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1490
 * Retrieve the time at which the post was written.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1491
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1492
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1493
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1494
 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1495
 * @param int|object $post Optional post ID or object. Default is global $post object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1496
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1497
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1498
function get_the_time( $d = '', $post = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1499
	$post = get_post($post);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1500
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1501
	if ( '' == $d )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1502
		$the_time = get_post_time(get_option('time_format'), false, $post, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1503
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1504
		$the_time = get_post_time($d, false, $post, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1505
	return apply_filters('get_the_time', $the_time, $d, $post);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1506
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1507
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1508
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1509
 * Retrieve the time at which the post was written.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1510
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1511
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1512
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1513
 * @param string $d Optional Either 'G', 'U', or php date format.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1514
 * @param bool $gmt Optional, default is false. Whether to return the gmt time.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1515
 * @param int|object $post Optional post ID or object. Default is global $post object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1516
 * @param bool $translate Whether to translate the time string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1517
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1518
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1519
function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) { // returns timestamp
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1520
	$post = get_post($post);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1521
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1522
	if ( $gmt )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1523
		$time = $post->post_date_gmt;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1524
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1525
		$time = $post->post_date;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1526
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1527
	$time = mysql2date($d, $time, $translate);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1528
	return apply_filters('get_post_time', $time, $d, $gmt);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1529
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1530
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1531
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1532
 * Display the time at which the post was last modified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1533
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1534
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1535
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1536
 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1537
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1538
function the_modified_time($d = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1539
	echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1540
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1541
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1542
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1543
 * Retrieve the time at which the post was last modified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1544
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1545
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1546
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1547
 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1548
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1549
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1550
function get_the_modified_time($d = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1551
	if ( '' == $d )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1552
		$the_time = get_post_modified_time(get_option('time_format'), null, null, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1553
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1554
		$the_time = get_post_modified_time($d, null, null, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1555
	return apply_filters('get_the_modified_time', $the_time, $d);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1556
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1557
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1558
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1559
 * Retrieve the time at which the post was last modified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1560
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1561
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1562
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1563
 * @param string $d Optional, default is 'U'. Either 'G', 'U', or php date format.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1564
 * @param bool $gmt Optional, default is false. Whether to return the gmt time.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1565
 * @param int|object $post Optional, default is global post object. A post_id or post object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1566
 * @param bool $translate Optional, default is false. Whether to translate the result
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1567
 * @return string Returns timestamp
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1568
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1569
function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1570
	$post = get_post($post);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1571
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1572
	if ( $gmt )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1573
		$time = $post->post_modified_gmt;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1574
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1575
		$time = $post->post_modified;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1576
	$time = mysql2date($d, $time, $translate);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1577
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1578
	return apply_filters('get_post_modified_time', $time, $d, $gmt);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1579
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1580
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1581
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1582
 * Display the weekday on which the post was written.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1583
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1584
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1585
 * @uses $wp_locale
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1586
 * @uses $post
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1587
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1588
function the_weekday() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1589
	global $wp_locale;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1590
	$the_weekday = $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1591
	$the_weekday = apply_filters('the_weekday', $the_weekday);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1592
	echo $the_weekday;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1593
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1594
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1595
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1596
 * Display the weekday on which the post was written.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1597
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1598
 * Will only output the weekday if the current post's weekday is different from
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1599
 * the previous one output.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1600
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1601
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1602
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1603
 * @param string $before Optional Output before the date.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1604
 * @param string $after Optional Output after the date.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1605
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1606
function the_weekday_date($before='',$after='') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1607
	global $wp_locale, $currentday, $previousweekday;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1608
	$the_weekday_date = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1609
	if ( $currentday != $previousweekday ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1610
		$the_weekday_date .= $before;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1611
		$the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1612
		$the_weekday_date .= $after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1613
		$previousweekday = $currentday;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1614
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1615
	$the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1616
	echo $the_weekday_date;
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
 * Fire the wp_head action
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1621
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1622
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1623
 * @uses do_action() Calls 'wp_head' hook.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1624
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1625
function wp_head() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1626
	do_action('wp_head');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1627
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1628
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1629
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1630
 * Fire the wp_footer action
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1631
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1632
 * @since 1.5.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1633
 * @uses do_action() Calls 'wp_footer' hook.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1634
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1635
function wp_footer() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1636
	do_action('wp_footer');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1637
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1638
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1639
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1640
 * Display the links to the general feeds.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1641
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1642
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1643
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1644
 * @param array $args Optional arguments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1645
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1646
function feed_links( $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1647
	if ( !current_theme_supports('automatic-feed-links') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1648
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1649
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1650
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1651
		/* translators: Separator between blog name and feed type in feed links */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1652
		'separator'	=> _x('&raquo;', 'feed link'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1653
		/* translators: 1: blog title, 2: separator (raquo) */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1654
		'feedtitle'	=> __('%1$s %2$s Feed'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1655
		/* translators: 1: blog title, 2: separator (raquo) */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1656
		'comstitle'	=> __('%1$s %2$s Comments Feed'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1657
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1658
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1659
	$args = wp_parse_args( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1660
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1661
	echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['feedtitle'], get_bloginfo('name'), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link() ) . "\" />\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1662
	echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link( 'comments_' . get_default_feed() ) ) . "\" />\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1663
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1664
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1665
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1666
 * Display the links to the extra feeds such as category feeds.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1667
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1668
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1669
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1670
 * @param array $args Optional arguments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1671
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1672
function feed_links_extra( $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1674
		/* translators: Separator between blog name and feed type in feed links */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1675
		'separator'   => _x('&raquo;', 'feed link'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1676
		/* translators: 1: blog name, 2: separator(raquo), 3: post title */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1677
		'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1678
		/* translators: 1: blog name, 2: separator(raquo), 3: category name */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1679
		'cattitle'    => __('%1$s %2$s %3$s Category Feed'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1680
		/* translators: 1: blog name, 2: separator(raquo), 3: tag name */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1681
		'tagtitle'    => __('%1$s %2$s %3$s Tag Feed'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1682
		/* translators: 1: blog name, 2: separator(raquo), 3: author name  */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1683
		'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1684
		/* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1685
		'searchtitle' => __('%1$s %2$s Search Results for &#8220;%3$s&#8221; Feed'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1686
		/* translators: 1: blog name, 2: separator(raquo), 3: post type name */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1687
		'posttypetitle' => __('%1$s %2$s %3$s Feed'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1688
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1689
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
	$args = wp_parse_args( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1691
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
	if ( is_singular() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
		$id = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1694
		$post = get_post( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1695
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1696
		if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1697
			$title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], esc_html( get_the_title() ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1698
			$href = get_post_comments_feed_link( $post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1699
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1700
	} elseif ( is_post_type_archive() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1701
		$post_type = get_query_var( 'post_type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1702
		if ( is_array( $post_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1703
			$post_type = reset( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1704
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1705
		$post_type_obj = get_post_type_object( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1706
		$title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1707
		$href = get_post_type_archive_feed_link( $post_type_obj->name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1708
	} elseif ( is_category() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1709
		$term = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1710
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1711
		if ( $term ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1712
			$title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1713
			$href = get_category_feed_link( $term->term_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1714
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1715
	} elseif ( is_tag() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1716
		$term = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1717
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1718
		if ( $term ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1719
			$title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1720
			$href = get_tag_feed_link( $term->term_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1721
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1722
	} elseif ( is_author() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1723
		$author_id = intval( get_query_var('author') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1724
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1725
		$title = sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1726
		$href = get_author_feed_link( $author_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1727
	} elseif ( is_search() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1728
		$title = sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1729
		$href = get_search_feed_link();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1730
	} elseif ( is_post_type_archive() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1731
		$title = sprintf( $args['posttypetitle'], get_bloginfo('name'), $args['separator'], post_type_archive_title( '', false ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1732
		$post_type_obj = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1733
		if ( $post_type_obj )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1734
			$href = get_post_type_archive_feed_link( $post_type_obj->name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1735
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1736
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1737
	if ( isset($title) && isset($href) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1738
		echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1739
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1740
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1741
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1742
 * Display the link to the Really Simple Discovery service endpoint.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1743
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1744
 * @link http://archipelago.phrasewise.com/rsd
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1745
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1746
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1747
function rsd_link() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1748
	echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1749
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1750
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1751
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1752
 * Display the link to the Windows Live Writer manifest file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1753
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1754
 * @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1755
 * @since 2.3.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1756
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1757
function wlwmanifest_link() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1758
	echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1759
		. get_bloginfo('wpurl') . '/wp-includes/wlwmanifest.xml" /> ' . "\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1760
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1761
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1762
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1763
 * Display a noindex meta tag if required by the blog configuration.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1764
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1765
 * If a blog is marked as not being public then the noindex meta tag will be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1766
 * output to tell web robots not to index the page content. Add this to the wp_head action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1767
 * Typical usage is as a wp_head callback. add_action( 'wp_head', 'noindex' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1768
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1769
 * @see wp_no_robots
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1770
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1771
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1772
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1773
function noindex() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1774
	// If the blog is not public, tell robots to go away.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1775
	if ( '0' == get_option('blog_public') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1776
		wp_no_robots();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1777
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1778
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1779
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1780
 * Display a noindex meta tag.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1781
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1782
 * Outputs a noindex meta tag that tells web robots not to index the page content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1783
 * Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_no_robots' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1784
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1785
 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1786
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1787
function wp_no_robots() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1788
	echo "<meta name='robots' content='noindex,nofollow' />\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1789
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1790
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1791
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1792
 * Determine if TinyMCE is available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1793
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1794
 * Checks to see if the user has deleted the tinymce files to slim down there WordPress install.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1795
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1796
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1797
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1798
 * @return bool Whether TinyMCE exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1799
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1800
function rich_edit_exists() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1801
	global $wp_rich_edit_exists;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1802
	if ( !isset($wp_rich_edit_exists) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1803
		$wp_rich_edit_exists = file_exists(ABSPATH . WPINC . '/js/tinymce/tiny_mce.js');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
	return $wp_rich_edit_exists;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1806
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1807
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1808
 * Whether the user should have a WYSIWIG editor.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1809
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1810
 * Checks that the user requires a WYSIWIG editor and that the editor is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1811
 * supported in the users browser.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1812
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1813
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1814
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1815
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1816
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1817
function user_can_richedit() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1818
	global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1819
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1820
	if ( !isset($wp_rich_edit) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1821
		$wp_rich_edit = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1822
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1823
		if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1824
			if ( $is_safari ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1825
				$wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1826
			} elseif ( $is_gecko || $is_chrome || $is_IE || ( $is_opera && !wp_is_mobile() ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1827
				$wp_rich_edit = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1828
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1829
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1830
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1831
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1832
	return apply_filters('user_can_richedit', $wp_rich_edit);
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1836
 * Find out which editor should be displayed by default.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1837
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1838
 * Works out which of the two editors to display as the current editor for a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1839
 * user. The 'html' setting is for the "Text" editor tab.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1840
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1841
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1842
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1843
 * @return string Either 'tinymce', or 'html', or 'test'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1844
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1845
function wp_default_editor() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1846
	$r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1847
	if ( $user = wp_get_current_user() ) { // look for cookie
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1848
		$ed = get_user_setting('editor', 'tinymce');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1849
		$r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1850
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1851
	return apply_filters( 'wp_default_editor', $r ); // filter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1852
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1853
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1854
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1855
 * Renders an editor.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1856
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1857
 * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1858
 * _WP_Editors should not be used directly. See http://core.trac.wordpress.org/ticket/17144.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1859
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1860
 * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1861
 * running wp_editor() inside of a metabox is not a good idea unless only Quicktags is used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1862
 * On the post edit screen several actions can be used to include additional editors
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1863
 * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1864
 * See http://core.trac.wordpress.org/ticket/19173 for more information.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1865
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1866
 * @see wp-includes/class-wp-editor.php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1867
 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1868
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1869
 * @param string $content Initial content for the editor.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1870
 * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1871
 * @param array $settings See _WP_Editors::editor().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1872
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1873
function wp_editor( $content, $editor_id, $settings = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1874
	if ( ! class_exists( '_WP_Editors' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1875
		require( ABSPATH . WPINC . '/class-wp-editor.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1876
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1877
	_WP_Editors::editor($content, $editor_id, $settings);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1878
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1879
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1880
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1881
 * Retrieve the contents of the search WordPress query variable.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1882
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1883
 * The search query string is passed through {@link esc_attr()}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1884
 * to ensure that it is safe for placing in an html attribute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1885
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1886
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1887
 * @uses esc_attr()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1888
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1889
 * @param bool $escaped Whether the result is escaped. Default true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1890
 * 	Only use when you are later escaping it. Do not use unescaped.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1891
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1892
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1893
function get_search_query( $escaped = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1894
	$query = apply_filters( 'get_search_query', get_query_var( 's' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1895
	if ( $escaped )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1896
		$query = esc_attr( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1897
	return $query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1898
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1899
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1900
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1901
 * Display the contents of the search query variable.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1902
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1903
 * The search query string is passed through {@link esc_attr()}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1904
 * to ensure that it is safe for placing in an html attribute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1905
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1906
 * @uses esc_attr()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1907
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1908
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1909
function the_search_query() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1910
	echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
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 the language attributes for the html tag.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1915
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1916
 * Builds up a set of html attributes containing the text direction and language
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1917
 * information for the page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1918
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1919
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1920
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1921
 * @param string $doctype The type of html document (xhtml|html).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1922
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1923
function language_attributes($doctype = 'html') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1924
	$attributes = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1925
	$output = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1926
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1927
	if ( function_exists( 'is_rtl' ) && is_rtl() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1928
		$attributes[] = 'dir="rtl"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1929
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1930
	if ( $lang = get_bloginfo('language') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1931
		if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1932
			$attributes[] = "lang=\"$lang\"";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1933
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1934
		if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1935
			$attributes[] = "xml:lang=\"$lang\"";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1936
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1937
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1938
	$output = implode(' ', $attributes);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1939
	$output = apply_filters('language_attributes', $output);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1940
	echo $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1941
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1942
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1943
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1944
 * Retrieve paginated link for archive post pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1945
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1946
 * Technically, the function can be used to create paginated link list for any
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1947
 * area. The 'base' argument is used to reference the url, which will be used to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1948
 * create the paginated links. The 'format' argument is then used for replacing
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1949
 * the page number. It is however, most likely and by default, to be used on the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1950
 * archive post pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1951
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1952
 * The 'type' argument controls format of the returned value. The default is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1953
 * 'plain', which is just a string with the links separated by a newline
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1954
 * character. The other possible values are either 'array' or 'list'. The
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1955
 * 'array' value will return an array of the paginated link list to offer full
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1956
 * control of display. The 'list' value will place all of the paginated links in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1957
 * an unordered HTML list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1958
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1959
 * The 'total' argument is the total amount of pages and is an integer. The
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1960
 * 'current' argument is the current page number and is also an integer.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1961
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1962
 * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1963
 * and the '%_%' is required. The '%_%' will be replaced by the contents of in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1964
 * the 'format' argument. An example for the 'format' argument is "?page=%#%"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1965
 * and the '%#%' is also required. The '%#%' will be replaced with the page
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1966
 * number.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1967
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1968
 * You can include the previous and next links in the list by setting the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1969
 * 'prev_next' argument to true, which it is by default. You can set the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1970
 * previous text, by using the 'prev_text' argument. You can set the next text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1971
 * by setting the 'next_text' argument.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1972
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1973
 * If the 'show_all' argument is set to true, then it will show all of the pages
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1974
 * instead of a short list of the pages near the current page. By default, the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1975
 * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1976
 * arguments. The 'end_size' argument is how many numbers on either the start
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1977
 * and the end list edges, by default is 1. The 'mid_size' argument is how many
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1978
 * numbers to either side of current page, but not including current page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1979
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1980
 * It is possible to add query vars to the link by using the 'add_args' argument
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1981
 * and see {@link add_query_arg()} for more information.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1982
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1983
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1984
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1985
 * @param string|array $args Optional. Override defaults.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1986
 * @return array|string String of page links or array of page links.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1987
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1988
function paginate_links( $args = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1989
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1990
		'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1991
		'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1992
		'total' => 1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1993
		'current' => 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1994
		'show_all' => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1995
		'prev_next' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1996
		'prev_text' => __('&laquo; Previous'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1997
		'next_text' => __('Next &raquo;'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1998
		'end_size' => 1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1999
		'mid_size' => 2,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2000
		'type' => 'plain',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2001
		'add_args' => false, // array of query args to add
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2002
		'add_fragment' => ''
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
	$args = wp_parse_args( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2006
	extract($args, EXTR_SKIP);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2007
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2008
	// Who knows what else people pass in $args
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2009
	$total = (int) $total;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2010
	if ( $total < 2 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2011
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2012
	$current  = (int) $current;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2013
	$end_size = 0  < (int) $end_size ? (int) $end_size : 1; // Out of bounds?  Make it the default.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2014
	$mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2015
	$add_args = is_array($add_args) ? $add_args : false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2016
	$r = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2017
	$page_links = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2018
	$n = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2019
	$dots = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2020
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2021
	if ( $prev_next && $current && 1 < $current ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2022
		$link = str_replace('%_%', 2 == $current ? '' : $format, $base);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2023
		$link = str_replace('%#%', $current - 1, $link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2024
		if ( $add_args )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2025
			$link = add_query_arg( $add_args, $link );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2026
		$link .= $add_fragment;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2027
		$page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $prev_text . '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2028
	endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2029
	for ( $n = 1; $n <= $total; $n++ ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2030
		$n_display = number_format_i18n($n);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2031
		if ( $n == $current ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2032
			$page_links[] = "<span class='page-numbers current'>$n_display</span>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2033
			$dots = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2034
		else :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2035
			if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2036
				$link = str_replace('%_%', 1 == $n ? '' : $format, $base);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2037
				$link = str_replace('%#%', $n, $link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2038
				if ( $add_args )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2039
					$link = add_query_arg( $add_args, $link );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2040
				$link .= $add_fragment;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2041
				$page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$n_display</a>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2042
				$dots = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2043
			elseif ( $dots && !$show_all ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2044
				$page_links[] = '<span class="page-numbers dots">' . __( '&hellip;' ) . '</span>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2045
				$dots = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2046
			endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2047
		endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2048
	endfor;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2049
	if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2050
		$link = str_replace('%_%', $format, $base);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2051
		$link = str_replace('%#%', $current + 1, $link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2052
		if ( $add_args )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2053
			$link = add_query_arg( $add_args, $link );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2054
		$link .= $add_fragment;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2055
		$page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $next_text . '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2056
	endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2057
	switch ( $type ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2058
		case 'array' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2059
			return $page_links;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2060
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2061
		case 'list' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2062
			$r .= "<ul class='page-numbers'>\n\t<li>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2063
			$r .= join("</li>\n\t<li>", $page_links);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2064
			$r .= "</li>\n</ul>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2065
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2066
		default :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2067
			$r = join("\n", $page_links);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2068
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2069
	endswitch;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2070
	return $r;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2071
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2072
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2073
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2074
 * Registers an admin colour scheme css file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2075
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2076
 * Allows a plugin to register a new admin colour scheme. For example:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2077
 * <code>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2078
 * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2079
 * array('#07273E', '#14568A', '#D54E21', '#2683AE'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2080
 * </code>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2081
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2082
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2083
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2084
 * @param string $key The unique key for this theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2085
 * @param string $name The name of the theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2086
 * @param string $url The url of the css file containing the colour scheme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2087
 * @param array $colors Optional An array of CSS color definitions which are used to give the user a feel for the theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2088
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2089
function wp_admin_css_color($key, $name, $url, $colors = array()) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2090
	global $_wp_admin_css_colors;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2091
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2092
	if ( !isset($_wp_admin_css_colors) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2093
		$_wp_admin_css_colors = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2094
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2095
	$_wp_admin_css_colors[$key] = (object) array('name' => $name, 'url' => $url, 'colors' => $colors);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2096
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2097
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2098
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2099
 * Registers the default Admin color schemes
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 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2102
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2103
function register_admin_color_schemes() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2104
	wp_admin_css_color( 'classic', _x( 'Blue', 'admin color scheme' ), admin_url( 'css/colors-classic.min.css' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2105
		array( '#5589aa', '#cfdfe9', '#d1e5ee', '#eff8ff' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2106
	wp_admin_css_color( 'fresh', _x( 'Gray', 'admin color scheme' ), admin_url( 'css/colors-fresh.min.css' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2107
		array( '#555', '#a0a0a0', '#ccc', '#f1f1f1' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2108
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2109
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2110
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2111
 * Display the URL of a WordPress admin CSS file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2112
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2113
 * @see WP_Styles::_css_href and its style_loader_src filter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2114
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2115
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2116
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2117
 * @param string $file file relative to wp-admin/ without its ".css" extension.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2118
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2119
function wp_admin_css_uri( $file = 'wp-admin' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2120
	if ( defined('WP_INSTALLING') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2121
		$_file = "./$file.css";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2122
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2123
		$_file = admin_url("$file.css");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2124
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2125
	$_file = add_query_arg( 'version', get_bloginfo( 'version' ),  $_file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2126
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2127
	return apply_filters( 'wp_admin_css_uri', $_file, $file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2128
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2129
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2130
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2131
 * Enqueues or directly prints a stylesheet link to the specified CSS file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2132
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2133
 * "Intelligently" decides to enqueue or to print the CSS file. If the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2134
 * 'wp_print_styles' action has *not* yet been called, the CSS file will be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2135
 * enqueued. If the wp_print_styles action *has* been called, the CSS link will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2136
 * be printed. Printing may be forced by passing true as the $force_echo
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2137
 * (second) parameter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2138
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2139
 * For backward compatibility with WordPress 2.3 calling method: If the $file
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2140
 * (first) parameter does not correspond to a registered CSS file, we assume
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2141
 * $file is a file relative to wp-admin/ without its ".css" extension. A
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2142
 * stylesheet link to that generated URL is printed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2143
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2144
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2145
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2146
 * @uses $wp_styles WordPress Styles Object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2147
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2148
 * @param string $file Optional. Style handle name or file name (without ".css" extension) relative
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2149
 * 	 to wp-admin/. Defaults to 'wp-admin'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2150
 * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2151
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2152
function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2153
	global $wp_styles;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2154
	if ( !is_a($wp_styles, 'WP_Styles') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2155
		$wp_styles = new WP_Styles();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2156
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2157
	// For backward compatibility
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2158
	$handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2159
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2160
	if ( $wp_styles->query( $handle ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2161
		if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2162
			wp_print_styles( $handle );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2163
		else // Add to style queue
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2164
			wp_enqueue_style( $handle );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2165
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2166
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2167
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2168
	echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2169
	if ( function_exists( 'is_rtl' ) && is_rtl() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2170
		echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2171
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2172
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2173
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2174
 * Enqueues the default ThickBox js and css.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2175
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2176
 * If any of the settings need to be changed, this can be done with another js
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2177
 * file similar to media-upload.js. That file should
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2178
 * require array('thickbox') to ensure it is loaded after.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2179
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2180
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2181
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2182
function add_thickbox() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2183
	wp_enqueue_script( 'thickbox' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2184
	wp_enqueue_style( 'thickbox' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2185
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2186
	if ( is_network_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2187
		add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2188
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2189
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2190
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2191
 * Display the XHTML generator that is generated on the wp_head hook.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2192
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2193
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2194
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2195
function wp_generator() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2196
	the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2197
}
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
 * Display the generator XML or Comment for RSS, ATOM, etc.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2201
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2202
 * Returns the correct generator type for the requested output format. Allows
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2203
 * for a plugin to filter generators overall the the_generator filter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2204
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2205
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2206
 * @uses apply_filters() Calls 'the_generator' hook.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2207
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2208
 * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2209
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2210
function the_generator( $type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2211
	echo apply_filters('the_generator', get_the_generator($type), $type) . "\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2212
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2213
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2214
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2215
 * Creates the generator XML or Comment for RSS, ATOM, etc.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2216
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2217
 * Returns the correct generator type for the requested output format. Allows
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2218
 * for a plugin to filter generators on an individual basis using the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2219
 * 'get_the_generator_{$type}' filter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2220
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2221
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2222
 * @uses apply_filters() Calls 'get_the_generator_$type' hook.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2223
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2224
 * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2225
 * @return string The HTML content for the generator.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2226
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2227
function get_the_generator( $type = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2228
	if ( empty( $type ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2229
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2230
		$current_filter = current_filter();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2231
		if ( empty( $current_filter ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2232
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2233
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2234
		switch ( $current_filter ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2235
			case 'rss2_head' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2236
			case 'commentsrss2_head' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2237
				$type = 'rss2';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2238
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2239
			case 'rss_head' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2240
			case 'opml_head' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2241
				$type = 'comment';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2242
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2243
			case 'rdf_header' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2244
				$type = 'rdf';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2245
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2246
			case 'atom_head' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2247
			case 'comments_atom_head' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2248
			case 'app_head' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2249
				$type = 'atom';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2250
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2251
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2252
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2253
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2254
	switch ( $type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2255
		case 'html':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2256
			$gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2257
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2258
		case 'xhtml':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2259
			$gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2260
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2261
		case 'atom':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2262
			$gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2263
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2264
		case 'rss2':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2265
			$gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2266
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2267
		case 'rdf':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2268
			$gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2269
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2270
		case 'comment':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2271
			$gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2272
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2273
		case 'export':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2274
			$gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '" -->';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2275
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2276
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2277
	return apply_filters( "get_the_generator_{$type}", $gen, $type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2278
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2279
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2280
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2281
 * Outputs the html checked attribute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2282
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2283
 * Compares the first two arguments and if identical marks as checked
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2284
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2285
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2286
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2287
 * @param mixed $checked One of the values to compare
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2288
 * @param mixed $current (true) The other value to compare if not just true
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2289
 * @param bool $echo Whether to echo or just return the string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2290
 * @return string html attribute or empty string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2291
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2292
function checked( $checked, $current = true, $echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2293
	return __checked_selected_helper( $checked, $current, $echo, 'checked' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2294
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2295
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2296
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2297
 * Outputs the html selected attribute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2298
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2299
 * Compares the first two arguments and if identical marks as selected
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2300
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2301
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2302
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2303
 * @param mixed $selected One of the values to compare
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2304
 * @param mixed $current (true) The other value to compare if not just true
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2305
 * @param bool $echo Whether to echo or just return the string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2306
 * @return string html attribute or empty string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2307
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2308
function selected( $selected, $current = true, $echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2309
	return __checked_selected_helper( $selected, $current, $echo, 'selected' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2310
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2311
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2312
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2313
 * Outputs the html disabled attribute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2314
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2315
 * Compares the first two arguments and if identical marks as disabled
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2316
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2317
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2318
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2319
 * @param mixed $disabled One of the values to compare
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2320
 * @param mixed $current (true) The other value to compare if not just true
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2321
 * @param bool $echo Whether to echo or just return the string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2322
 * @return string html attribute or empty string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2323
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2324
function disabled( $disabled, $current = true, $echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2325
	return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2326
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2327
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2328
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2329
 * Private helper function for checked, selected, and disabled.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2330
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2331
 * Compares the first two arguments and if identical marks as $type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2332
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2333
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2334
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2335
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2336
 * @param mixed $helper One of the values to compare
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2337
 * @param mixed $current (true) The other value to compare if not just true
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2338
 * @param bool $echo Whether to echo or just return the string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2339
 * @param string $type The type of checked|selected|disabled we are doing
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2340
 * @return string html attribute or empty string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2341
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2342
function __checked_selected_helper( $helper, $current, $echo, $type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2343
	if ( (string) $helper === (string) $current )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2344
		$result = " $type='$type'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2345
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2346
		$result = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2347
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2348
	if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2349
		echo $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2350
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2351
	return $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2352
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2353
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2354
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2355
 * Default settings for heartbeat
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2356
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2357
 * Outputs the nonce used in the heartbeat XHR
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2358
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2359
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2360
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2361
 * @param array $settings
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2362
 * @return array $settings
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2363
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2364
function wp_heartbeat_settings( $settings ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2365
	if ( ! is_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2366
		$settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2367
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2368
	if ( is_user_logged_in() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2369
		$settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2370
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2371
	return $settings;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2372
}