Changeset 4928
- Timestamp:
- 05/19/2013 06:29:35 AM (12 years ago)
- Location:
- trunk/includes/search
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/search/functions.php
r4915 r4928 54 54 return apply_filters( 'bbp_get_search_query_args', $retval ); 55 55 } 56 57 /** 58 * Redirect to search results page if needed 59 * 60 * @since bbPress (r4928) 61 * @return If a redirect is not needed 62 */ 63 function bbp_search_template_redirect() { 64 65 // Bail if already on search results page 66 if ( bbp_is_search_results() ) 67 return; 68 69 // Bail if search terms are empty 70 if ( false === bbp_get_search_terms() ) 71 return; 72 73 // Get the redirect URL 74 $redirect_to = bbp_get_search_results_url(); 75 76 // Bail if no redirect URL or may cause infinite loop 77 if ( empty( $redirect_to ) || ( bbp_get_search_url() === $redirect_to ) ) 78 return; 79 80 // Redirect and bail 81 wp_safe_redirect( $redirect_to ); 82 exit(); 83 } -
trunk/includes/search/template-tags.php
r4913 r4928 44 44 /** Defaults **************************************************************/ 45 45 46 // What are the default allowed statuses (based on user caps) 47 if ( bbp_get_view_all( 'edit_others_replies' ) ) { 48 $post_statuses = array( bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id() ); 49 } else { 50 $post_statuses = array( bbp_get_public_status_id(), bbp_get_closed_status_id() ); 51 } 52 53 $default_post_type = array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() ); 54 $default_post_status = implode( ',', $post_statuses ); 46 $default_post_type = array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() ); 55 47 56 48 // Default query args 57 49 $default = array( 58 'post_type' => $default_post_type, // Forums, topics, and replies59 'post _status' => $default_post_status, // Of this status60 'p osts_per_page' => bbp_get_replies_per_page(), // This many61 ' paged' => bbp_get_paged(), // On this page62 'order by' => 'date', // Sorted by date63 ' order' => 'DESC', // Most recent first64 's' => bbp_get_search_terms(), // This is a search50 'post_type' => $default_post_type, // Forums, topics, and replies 51 'posts_per_page' => bbp_get_replies_per_page(), // This many 52 'paged' => bbp_get_paged(), // On this page 53 'orderby' => 'date', // Sorted by date 54 'order' => 'DESC', // Most recent first 55 'ignore_sticky_posts' => true, // Stickies not supported 56 's' => bbp_get_search_terms(), // This is a search 65 57 ); 58 59 // What are the default allowed statuses (based on user caps) 60 if ( bbp_get_view_all() ) { 61 62 // Default view=all statuses 63 $post_statuses = array( 64 bbp_get_public_status_id(), 65 bbp_get_closed_status_id(), 66 bbp_get_spam_status_id(), 67 bbp_get_trash_status_id() 68 ); 69 70 // Add support for private status 71 if ( current_user_can( 'read_private_topics' ) ) { 72 $post_statuses[] = bbp_get_private_status_id(); 73 } 74 75 // Join post statuses together 76 $default['post_status'] = implode( ',', $post_statuses ); 77 78 // Lean on the 'perm' query var value of 'readable' to provide statuses 79 } else { 80 $default['perm'] = 'readable'; 81 } 66 82 67 83 /** Setup *****************************************************************/ … … 94 110 if ( (int) $bbp->search_query->found_posts && (int) $bbp->search_query->posts_per_page ) { 95 111 112 // Array of arguments to add after pagination links 113 $add_args = array(); 114 96 115 // If pretty permalinks are enabled, make our pagination pretty 97 116 if ( $wp_rewrite->using_permalinks() ) { … … 103 122 // Default search location 104 123 } else { 105 $base = trailingslashit( bbp_get_search_url() ); 106 124 $base = trailingslashit( bbp_get_search_results_url() ); 107 125 } 108 126 … … 116 134 117 135 // Add args 118 $add_args = isset( $_GET[bbp_get_search_rewrite_id()] ) ? array( bbp_get_search_rewrite_id() => urlencode( bbp_get_search_terms() ) ) : array(); 119 if ( bbp_get_view_all() ) 136 if ( bbp_get_view_all() ) { 120 137 $add_args['view'] = 'all'; 138 } 121 139 122 140 // Add pagination to query object … … 253 271 // Unpretty permalinks 254 272 } else { 255 $search_terms = bbp_get_search_terms(); 273 $url = add_query_arg( array( 'bbp_search' => '' ), home_url( '/' ) ); 274 } 275 276 return apply_filters( 'bbp_get_search_url', $url ); 277 } 278 279 /** 280 * Output the search results url 281 * 282 * @since bbPress (r4928) 283 * 284 * @uses bbp_get_search_url() To get the search url 285 */ 286 function bbp_search_results_url() { 287 echo bbp_get_search_results_url(); 288 } 289 /** 290 * Return the search url 291 * 292 * @since bbPress (r4928) 293 * 294 * @uses user_trailingslashit() To fix slashes 295 * @uses trailingslashit() To fix slashes 296 * @uses bbp_get_forums_url() To get the root forums url 297 * @uses bbp_get_search_slug() To get the search slug 298 * @uses add_query_arg() To help make unpretty permalinks 299 * @return string Search url 300 */ 301 function bbp_get_search_results_url() { 302 global $wp_rewrite; 303 304 // Get the search terms 305 $search_terms = bbp_get_search_terms(); 306 307 // Pretty permalinks 308 if ( $wp_rewrite->using_permalinks() ) { 309 310 // Root search URL 311 $url = $wp_rewrite->root . bbp_get_search_slug(); 312 313 // Append search terms 314 if ( !empty( $search_terms ) ) { 315 $url = user_trailingslashit( $url ) . user_trailingslashit( urlencode( $search_terms ) ); 316 } 317 318 // Run through home_url() 319 $url = home_url( user_trailingslashit( $url ) ); 320 321 // Unpretty permalinks 322 } else { 256 323 $url = add_query_arg( array( 'bbp_search' => urlencode( $search_terms ) ), home_url( '/' ) ); 257 324 } 258 325 259 return apply_filters( 'bbp_get_search_url', $url ); 260 } 261 326 return apply_filters( 'bbp_get_search_results_url', $url ); 327 } 262 328 263 329 /** … … 297 363 } 298 364 299 // Set explicitly to false if empty 300 if ( empty( $search_terms ) ) { 301 $search_terms = false; 302 } 365 // Trim whitespace and decode, or set explicitly to false if empty 366 $search_terms = !empty( $search_terms ) ? urldecode( trim( $search_terms ) ) : false; 303 367 304 368 return apply_filters( 'bbp_get_search_terms', $search_terms, $passed_terms );
Note: See TracChangeset
for help on using the changeset viewer.