bp_core_get_directory_pages

Get names and slugs for BuddyPress component directory pages.

Description

(object) bp_core_get_directory_pages(); 

Returns (object)

Page names, IDs, and slugs.


Usage

  1. if ( !function_exists( 'bp_core_get_directory_pages' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_core_get_directory_pages(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-functions.php  
  1. function bp_core_get_directory_pages() { 
  2. global $wpdb; 
  3.  
  4. // Look in cache first. 
  5. $pages = wp_cache_get( 'directory_pages', 'bp_pages' ); 
  6.  
  7. if ( false === $pages ) { 
  8.  
  9. // Set pages as standard class. 
  10. $pages = new stdClass; 
  11.  
  12. // Get pages and IDs. 
  13. if ( !empty( $page_ids ) ) { 
  14.  
  15. // Always get page data from the root blog, except on multiblog mode, when it comes 
  16. // from the current blog. 
  17. $posts_table_name = bp_is_multiblog_mode() ? $wpdb->posts : $wpdb->get_blog_prefix( bp_get_root_blog_id() ) . 'posts'; 
  18. $page_ids_sql = implode( ', ', wp_parse_id_list( $page_ids ) ); 
  19. $page_names = $wpdb->get_results( "SELECT ID, post_name, post_parent, post_title FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) AND post_status = 'publish' " ); 
  20.  
  21. foreach ( (array) $page_ids as $component_id => $page_id ) { 
  22. foreach ( (array) $page_names as $page_name ) { 
  23. if ( $page_name->ID == $page_id ) { 
  24. if ( !isset( $pages->{$component_id} ) || !is_object( $pages->{$component_id} ) ) { 
  25. $pages->{$component_id} = new stdClass; 
  26.  
  27. $pages->{$component_id}->name = $page_name->post_name; 
  28. $pages->{$component_id}->id = $page_name->ID; 
  29. $pages->{$component_id}->title = $page_name->post_title; 
  30. $slug[] = $page_name->post_name; 
  31.  
  32. // Get the slug. 
  33. while ( $page_name->post_parent != 0 ) { 
  34. $parent = $wpdb->get_results( $wpdb->prepare( "SELECT post_name, post_parent FROM {$posts_table_name} WHERE ID = %d", $page_name->post_parent ) ); 
  35. $slug[] = $parent[0]->post_name; 
  36. $page_name->post_parent = $parent[0]->post_parent; 
  37.  
  38. $pages->{$component_id}->slug = implode( '/', array_reverse( (array) $slug ) ); 
  39.  
  40. unset( $slug ); 
  41.  
  42. wp_cache_set( 'directory_pages', $pages, 'bp_pages' ); 
  43.  
  44. /** 
  45. * Filters the names and slugs for BuddyPress component directory pages. 
  46. * @since 1.5.0 
  47. * @param object $pages Object holding page names and slugs. 
  48. */