The Site Tree's Action Hooks

Whenever the Site Tree is rebuilt, there are four main Action Hooks to be triggered:

Adding Content to the Site Tree

The code below places a paragraph on top of a hyper-list of books. A 'Book' Post Type can be added to a WordPress website via the Custom Post Type functionality.

function insert_paragraph_before_book_list( $siteTreeBuilder ) {
    if ( $siteTreeBuilder->listID() == 'book' )
        $siteTreeBuilder->addContent( '<p>A paragraph on the listed books.</p>' );
}

add_action( 'sitetree_will_build_single_list', 'insert_paragraph_before_book_list' );

The $siteTreeBuilder parameter is a reference to the object of class SiteTree\SiteTreeBuilder to which is assigned the task of building the Site Tree. Its class' interface, declared in includes/builders/builders-interfaces.php, is the following:

interface SiteTreeBuilderInterface {
    /**
     * Returns the unique identifier of the list that is being built.
     * For Custom Post Types, it coincides with the Post Type Key.
     *
     * @since 2.0
     * @return string      
     */
    public function listID();

    /**
     * Returns the type of the content that is being processed.
     * Possible values: post, taxonomy, author.
     *
     * @since 6.0
     * @return string
     */
    public function getContentTypeFamily();
    
    /**
     * Returns 'true' or 'false' according to whether or not the builder 
     * is generating a hyper-list starting from a set of options passed 
     * as shortcode attributes.
     *
     * @since 4.5
     * @return bool
     */
    public function isDoingShortcode();

    /**
     * Returns 'true' or 'false' according to whether or not the builder 
     * is generating an hyper-list as a result of either a "shortcode call"
     * or Template Tag call.
     *
     * @since 5.2
     * @return bool
     */
    public function isDoingHyperlist();

    /**
     * @since 2.0
     * @param string $string      
     */
    public function addContent( $string );
}
Last update: