The Site Tree's Action Hooks
Whenever the Site Tree is rebuilt, there are four main Action Hooks that are triggered:
tpc_will_build_site_tree
: triggered before the Site Tree is built.tpc_will_build_single_list
: triggered before a hyper-list of the Site Tree is built.tpc_did_build_single_list
: triggered after a hyper-list of the Site Tree has been built.tpc_did_build_site_tree
: triggered after the whole Site Tree has been built.
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( 'tpc_will_build_single_list', 'insert_paragraph_before_book_list' );
The $siteTreeBuilder
parameter is a reference to the object of class ThePermalinksCascade\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 1.0
* @return string
*/
public function listID();
/**
* Returns the type of the content that is being processed.
* Possible values: post, taxonomy, author.
*
* @since 2.0
* @return string
*/
public function getContentTypeFamily();
/**
* Returns 'true' or 'false' according to whether or not the builder
* is generating an hyper-list as a result of either a "shortcode call",
* a "Gutenberg Block call" or a "Template Tag call".
*
* @since 2.0
* @return bool
*/
public function isDoingHyperlist();
/**
* Returns 'true' or 'false' according to whether or not the builder
* is generating an hyper-list starting from a set of Block attributes
* associated to a Block Type registered by the plugin.
*
* @since 1.0
* @return bool
*/
public function isDoingBlock();
/**
* 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 2.0
* @return bool
*/
public function isDoingShortcode();
/**
* @since 1.0
* @param string $string
*/
public function addContent( $string );
}