Index: src/wp-includes/general-template.php
===================================================================
--- src/wp-includes/general-template.php (revision 37650)
+++ src/wp-includes/general-template.php (working copy)
@@ -1634,6 +1634,12 @@
* @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'.
* Default 'DESC'.
* @type string $post_type Post type. Default 'post'.
+ * @type string $title List heading. Passing a null or empty value will result in no heading, and the list
+ * will not be wrapped and $title_before and $title_after become useless. Default ''.
+ * @type string $title_before Text or HTML to precede the title. Default ''.
+ * @type string $title_after Text or HTML to follow the title. Default ''.
+ * @type string $list_before Text or HTML to precede the list. Default ''.
+ * @type string $list_after Text or HTML to follow the list. Default ''.
* }
* @return string|void String when retrieving.
*/
@@ -1645,7 +1651,9 @@
'format' => 'html', 'before' => '',
'after' => '', 'show_post_count' => false,
'echo' => 1, 'order' => 'DESC',
- 'post_type' => 'post'
+ 'post_type' => 'post', 'title' => '',
+ 'title_before' => '', 'title_after' => '',
+ 'list_before' => '', 'list_after' => ''
);
$r = wp_parse_args( $args, $defaults );
@@ -1697,6 +1705,14 @@
$output = '';
+ if ( '' != $r['title'] ) {
+ $output .= $r['title_before']. $r['title']. $r['title_after'];
+ }
+
+ if ( $r['list_before'] ) {
+ $output .= $r['list_before'];
+ }
+
$last_changed = wp_cache_get( 'last_changed', 'posts' );
if ( ! $last_changed ) {
$last_changed = microtime();
@@ -1828,6 +1844,11 @@
}
}
}
+
+ if ( $r['list_after'] ) {
+ $output .= $r['list_after'];
+ }
+
if ( $r['echo'] ) {
echo $output;
} else {
Index: src/wp-includes/post-template.php
===================================================================
--- src/wp-includes/post-template.php (revision 37650)
+++ src/wp-includes/post-template.php (working copy)
@@ -1131,6 +1131,8 @@
* @type string $title_li List heading. Passing a null or empty value will result in no heading, and the list
* will not be wrapped with unordered list `
` tags. Default 'Pages'.
* @type Walker $walker Walker instance to use for listing pages. Default empty (Walker_Page).
+ * @type string $before Text or HTML to precede the list of pages. Default -
+ * @type string $after Text or HTML to follow the list of pages. Default
* }
* @return string|void HTML list of pages.
*/
@@ -1142,6 +1144,7 @@
'title_li' => __( 'Pages' ), 'echo' => 1,
'authors' => '', 'sort_column' => 'menu_order, post_title',
'link_before' => '', 'link_after' => '', 'walker' => '',
+ 'before' => '- ', 'after' => '
'
);
$r = wp_parse_args( $args, $defaults );
@@ -1170,7 +1173,7 @@
if ( ! empty( $pages ) ) {
if ( $r['title_li'] ) {
- $output .= '- ' . $r['title_li'] . '
';
+ $output .= $r['before'] . $r['title_li'] . '';
}
global $wp_query;
if ( is_page() || is_attachment() || $wp_query->is_posts_page ) {
@@ -1185,7 +1188,7 @@
$output .= walk_page_tree( $pages, $r['depth'], $current_page, $r );
if ( $r['title_li'] ) {
- $output .= '
';
+ $output .= '
' . $r['after'];
}
}
Index: src/wp-includes/post.php
===================================================================
--- src/wp-includes/post.php (revision 37650)
+++ src/wp-includes/post.php (working copy)
@@ -4326,30 +4326,24 @@
* @return WP_Post|array|void WP_Post on success or null on failure
*/
function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {
- global $wpdb;
- if ( is_array( $post_type ) ) {
- $post_type = esc_sql( $post_type );
- $post_type_in_string = "'" . implode( "','", $post_type ) . "'";
- $sql = $wpdb->prepare( "
- SELECT ID
- FROM $wpdb->posts
- WHERE post_title = %s
- AND post_type IN ($post_type_in_string)
- ", $page_title );
- } else {
- $sql = $wpdb->prepare( "
- SELECT ID
- FROM $wpdb->posts
- WHERE post_title = %s
- AND post_type = %s
- ", $page_title, $post_type );
- }
+ // Make sure that we even query post statuses that are excluded from search
+ $post_status = array_values( get_post_stati( array( 'exclude_from_search' => true ) ) );
- $page = $wpdb->get_var( $sql );
+ $query = new WP_Query(
+ array(
+ 'title' => $page_title,
+ 'post_type' => $post_type,
+ 'posts_per_page' => 1,
+ 'post_status' => array_merge( $post_status, array( 'any' ) ),
+ 'orderby' => 'none',
+ 'fields' => 'ids'
+ )
+ );
+ $posts = $query->get_posts();
- if ( $page ) {
- return get_post( $page, $output );
+ if ( $posts ) {
+ return get_post( $posts[0], $output );
}
}
Index: tests/phpunit/tests/functions/getArchives.php
===================================================================
--- tests/phpunit/tests/functions/getArchives.php (revision 37650)
+++ tests/phpunit/tests/functions/getArchives.php (working copy)
@@ -122,4 +122,41 @@
$archives = wp_get_archives( array( 'echo' => false, 'post_type' => 'taco' ) );
$this->assertEquals( $expected, trim( $archives ) );
}
+
+ /**
+ * @ticket 4969
+ */
+ function test_wp_get_archives_title() {
+ $expected = "Archives Title
\t" . date( 'F Y' ) . "";
+ $result = trim( wp_get_archives(
+ array(
+ 'echo' => false,
+ 'title' => 'Archives Title',
+ 'title_before' => '',
+ 'title_after' => '
',
+ )
+ ) );
+
+ $this->assertEquals( $expected, $result );
+ }
+
+ /**
+ * @ticket 4969
+ */
+ function test_wp_get_archives_before_and_after_list() {
+ $date = date( 'F Y' );
+ $expected = <<\t$date
+
+EOF;
+ $result = trim( wp_get_archives(
+ array(
+ 'echo' => false,
+ 'list_before' => '',
+ )
+ ) );
+
+ $this->assertEquals( $expected, $result );
+ }
}
Index: tests/phpunit/tests/post/listPages.php
===================================================================
--- tests/phpunit/tests/post/listPages.php (revision 37650)
+++ tests/phpunit/tests/post/listPages.php (working copy)
@@ -342,4 +342,43 @@
$actual = wp_list_pages( $args );
$this->AssertEquals( $expected['exclude'], $actual );
}
+
+ /**
+ * @ticket 4969
+ */
+ function test_wp_get_pages_before_and_after() {
+ $expected = '';
+
+ $result = trim( wp_list_pages(
+ array(
+ 'echo' => false,
+ 'before' => '',
+ 'after' => '
',
+ 'title_li' => 'The Pages'
+ )
+ ) );
+
+ $this->assertEquals( $expected, $result );
+ }
}