BBP_Walker_Reply_Dropdown

Create HTML dropdown list of bbPress replies.


Description Description


Source Source

File: includes/common/classes.php

class BBP_Walker_Reply_Dropdown extends Walker {

	/**
	 * @see Walker::$tree_type
	 *
	 * @since 2.6.0 bbPress (r5389)
	 *
	 * @var string
	 */
	public $tree_type = 'reply';

	/**
	 * @see Walker::$db_fields
	 *
	 * @since 2.6.0 bbPress (r5389)
	 *
	 * @var array
	 */
	public $db_fields = array(
		'parent' => 'reply_to',
		'id'     => 'ID'
	);

	/** Methods ***************************************************************/

	/**
	 * Confirm the tree_type
	 *
	 * @since 2.6.0 bbPress (r5389)
	 */
	public function __construct() {
		$this->tree_type = bbp_get_reply_post_type();
	}

	/**
	 * @see Walker::start_el()
	 *
	 * @since 2.6.0 bbPress (r5389)
	 *
	 * @param string $output Passed by reference. Used to append additional
	 *                       content.
	 *
	 * @param object $object Post data object.
	 *
	 * @param int    $depth  Depth of post in reference to parent posts. Used
	 *                       for padding.
	 *
	 * @param array  $args   Uses 'selected' argument for selected post to set
	 *                       selected HTML attribute for option element.
	 *
	 * @param int    $current_object_id Not Used
	 */
	public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {

		// Set up reply
		$depth++;

		// Get the reply ID
		if ( isset( $args['exclude'][0] ) ) {
			$reply_id = (int) $args['exclude'][0];
		} else {
			$reply_id = bbp_get_reply_id();
		}

		// Get ancestors to determine which items to disable
		$ancestors = bbp_get_reply_ancestors( $object->ID );
		array_push( $ancestors, $object->ID );

		// Determine the indentation
		$pad = str_repeat( ' ', (int) $depth * 3 );

		// Determine reply title (either post_title, or excerpt of post_content)
		$title = ! empty( $object->post_title ) ? $object->post_title : wp_html_excerpt( $object->post_content, 10 );
		$title   = sprintf( esc_html__( '%1$s - %2$s', 'bbpress' ), (int) $object->ID, $title );
		$title   = apply_filters( 'bbp_walker_dropdown_post_title', $title, $output, $object, $depth, $args );

		// Attributes
		$class = 'level-' . (int) $depth;
		$value = (int) $object->ID;

		// Start an output buffer to make late escaping easier
		ob_start(); ?>

		<option class="<?php echo esc_attr( $class ); ?>" value="<?php echo esc_attr( $value ); ?>"<?php selected( $args['selected'], $object->ID ); ?> <?php disabled( in_array( $reply_id, $ancestors ), true ); ?>><?php echo $pad . esc_html( $title ); ?></option>

		<?php

		// Append the output buffer to the $output variable
		$output .= ob_get_clean();
	}
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.

Top ↑

Methods Methods


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.