Making WordPress.org


Ignore:
Timestamp:
06/23/2016 06:59:17 PM (10 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Implement Handbooks table of contents functionality for the "More Information" sections of parsed post types.

Props DrewAPicture.
Fixes #1548.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r3379 r3563  
    13181318            return '';
    13191319        }
    1320         return get_post_field( $field, $explanation, $context );
     1320
     1321        $post_field = get_post_field( $field, $explanation, $context );
     1322
     1323        // If retrieving the explanation content for display, add the TOC if available.
     1324        if ( 'post_content' === $field && 'display' === $context ) {
     1325            if ( class_exists( 'WPorg_Handbook_TOC' ) ) :
     1326                $TOC = new \WPorg_Handbook_TOC( get_parsed_post_types() );
     1327
     1328                add_filter( 'the_content', array( $TOC, 'add_toc' ) );
     1329                $post_field = apply_filters( 'the_content', apply_filters( 'get_the_content', $post_field ) );
     1330                remove_filter( 'the_content', array( $TOC, 'add_toc' ) );
     1331            else :
     1332                $post_field = apply_filters( 'the_content', apply_filters( 'get_the_content', $post_field ) );
     1333            endif;
     1334        }
     1335
     1336        return $post_field;
    13211337    }
    13221338
Note: See TracChangeset for help on using the changeset viewer.