Changeset 13471 for trunk/src/bp-core/bp-core-filters.php
- Timestamp:
- 05/07/2023 11:36:50 AM (3 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-core/bp-core-filters.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-filters.php
r13436 r13471 948 948 949 949 /** 950 * Eventually append BuddyPress directories to WP Dropdown's pages control. 951 * 952 * @since 12.0.0 953 * 954 * @param WP_Post[] $pages Array of page objects. 955 * @param array $args Array of get_pages() arguments. 956 * @return WP_Post[] Array of page objects, potentially including BP directories. 957 */ 958 function bp_core_include_directory_on_front( $pages = array(), $args = array() ) { 959 $is_page_on_front_dropdown = false; 960 961 if ( isset( $args['name'] ) ) { 962 $is_page_on_front_dropdown = 'page_on_front' === $args['name']; 963 964 if ( is_customize_preview() ) { 965 $is_page_on_front_dropdown = '_customize-dropdown-pages-page_on_front' === $args['name']; 966 } 967 } 968 969 if ( $is_page_on_front_dropdown ) { 970 $directories = bp_core_get_directory_pages(); 971 $null = '0000-00-00 00:00:00'; 972 973 foreach ( (array) $directories as $component => $directory ) { 974 if ( 'activate' === $component || 'register' === $component ) { 975 continue; 976 } 977 978 $post = (object) array( 979 'ID' => $directory->id, 980 'post_author' => 0, 981 'post_date' => $null, 982 'post_date_gmt' => $null, 983 'post_content' => '', 984 'post_title' => $directory->title, 985 'post_excerpt' => '', 986 'post_status' => 'publish', 987 'comment_status' => 'closed', 988 'ping_status' => 'closed', 989 'post_password' => '', 990 'post_name' => $directory->slug, 991 'pinged' => '', 992 'to_ping' => '', 993 'post_modified' => $null, 994 'post_modified_gmt' => $null, 995 'post_content_filtered' => '', 996 'post_parent' => 0, 997 'guid' => bp_rewrites_get_url( 998 array( 999 'component_id' => $component, 1000 ) 1001 ), 1002 'menu_order' => 0, 1003 'post_type' => 'buddypress', 1004 'post_mime_type' => '', 1005 'comment_count' => 0, 1006 'filter' => 'raw', 1007 ); 1008 1009 $pages[] = get_post( $post ); 1010 } 1011 1012 $pages = bp_alpha_sort_by_key( $pages, 'post_title' ); 1013 } 1014 1015 return $pages; 1016 } 1017 add_filter( 'get_pages', 'bp_core_include_directory_on_front', 10, 2 ); 1018 1019 /** 950 1020 * Filter SQL query strings to swap out the 'meta_id' column. 951 1021 * … … 1336 1406 } 1337 1407 add_filter( 'subdirectory_reserved_names', 'bp_core_components_subdirectory_reserved_names' ); 1408 1409 /** 1410 * Make sure `buddypress` post type links are built using BP Rewrites. 1411 * 1412 * @since 12.0.0 1413 * 1414 * @param string $link The post type link. 1415 * @param WP_Post|null $post The post type object. 1416 * @return string The post type link. 1417 */ 1418 function bp_get_post_type_link( $link = '', $post = null ) { 1419 if ( 'rewrites' === bp_core_get_query_parser() && 'buddypress' === get_post_type( $post ) ) { 1420 $bp_pages = (array) buddypress()->pages; 1421 1422 $bp_current_page = wp_list_filter( $bp_pages, array( 'id' => $post->ID ) ); 1423 if ( $bp_current_page ) { 1424 $args = array( 1425 'component_id' => key( $bp_current_page ), 1426 ); 1427 1428 if ( 'register' === $args['component_id'] || 'activate' === $args['component_id'] ) { 1429 $key_action = 'member_' . $args['component_id']; 1430 $args['component_id'] = 'members'; 1431 $args[ $key_action ] = 1; 1432 } 1433 1434 $link = bp_rewrites_get_url( $args ); 1435 } 1436 } 1437 1438 return $link; 1439 } 1440 add_filter( 'post_type_link', 'bp_get_post_type_link', 10, 2 );
Note: See TracChangeset
for help on using the changeset viewer.