position = $position; $this->group = a_z_listing_is_truthy( $group ); add_filter( 'a-z-listing-alphabet', array( $this, 'add_to_alphabet' ) ); add_filter( 'the-a-z-letter-title', array( $this, 'title' ) ); } } /** * Remove the numbers filters we added previously * * @since 2.0.0 */ public function teardown() { remove_filter( 'a-z-listing-alphabet', array( $this, 'add_to_alphabet' ) ); remove_filter( 'the-a-z-letter-title', array( $this, 'title' ) ); } /** * Add numbers to the alphabet * * @since 2.0.0 * @param string $alphabet The alphabet to add numbers into. * @return string The alphabet with numbers either prepended or appended */ public function add_to_alphabet( $alphabet ) { if ( 'hide' === $this->position ) { return $alphabet; } if ( true === $this->group ) { $numbers = '0123456789'; } else { $numbers = '0,1,2,3,4,5,6,7,8,9'; } if ( 'before' === $this->position ) { return join( ',', array( $numbers, $alphabet ) ); } return join( ',', array( $alphabet, $numbers ) ); } /** * Override the group title for grouped numbers * * @since 2.0.0 * @param string $letter The original title of the group. * @return string The new title for the group */ public function title( $letter ) { if ( '0' === $letter && true === $this->group ) { return '0-9'; } return $letter; } } /** * Returns a function for use in the `a_z_listing_alphabet` filter * * @since 1.7.0 * @since 1.8.0 Add $group parameter and functionality to group numbers into a single collection. * * @param string $position set to before to place the numbers first. Any other value will place them last. * @param bool $group group the numbers in a single collection rather than individually. * * @return A_Z_Listing_Numbers */ function add_a_z_numbers( $position = 'after', $group = false ) { return new A_Z_Listing_Numbers( $position, $group ); }