Skip to content

Commit

Permalink
When filtering doc permalinks, rebuild URL to cut off all parent slugs
Browse files Browse the repository at this point in the history
The previous code for generating canonical Doc URLs attempted to slice off
the slug of $post->post_parent when it was found. But this did not work for
Docs that were nested more than one level deep.

The new code enforces a totally flat URL structure by rebuilding the URL based
on the Docs archive link.

Fixes #308
  • Loading branch information
boonebgorges committed May 27, 2013
1 parent feee587 commit 92d1174
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions includes/component.php
Expand Up @@ -892,8 +892,9 @@ public function delete_doc_activity( $new_status, $old_status, $post ) {
* This function filters 'post_type_link', which in turn powers get_permalink() and related
* functions.
*
* As of 1.2, the only role of this function is to ensure that child
* Doc permalinks are returned correctly (without the parent slug)
* BuddyPress Docs has a completely flat architecture for URLs, where
* parent slugs never appear in the URL (as they do in the case of WP
* pages). So we reconstruct the link completely.
*
* @package BuddyPress Docs
* @since 1.1.8
Expand All @@ -905,9 +906,8 @@ public function delete_doc_activity( $new_status, $old_status, $post ) {
* @return str $link The filtered permalink
*/
function filter_permalinks( $link, $post, $leavename, $sample ) {
if ( bp_docs_get_post_type_name() == $post->post_type && ! empty( $post->post_parent ) ) {
$parent = get_post( $post->post_parent );
$link = str_replace( '/' . $parent->post_name, '', $link );
if ( bp_docs_get_post_type_name() == $post->post_type ) {
$link = trailingslashit( bp_docs_get_archive_link() . $post->post_name );
}

return html_entity_decode( $link );
Expand Down

0 comments on commit 92d1174

Please sign in to comment.