Skip to content

Commit

Permalink
update label and separate filters
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuadavidnelson committed Jan 13, 2024
1 parent 8109559 commit 83ef31e
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions src/archived-post-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function aps_archived_label_string() {
* @param string $label The "Archived" label.
* @return string
*/
return esc_attr( apply_filters( 'aps_archived_label_string', $label ) );
return (string) esc_attr( apply_filters( 'aps_archived_label_string', $label ) );
}

/**
Expand Down Expand Up @@ -157,48 +157,53 @@ function aps_the_title( $title, $post_id = null ) {
&& 'archive' === $post->post_status ) {

/**
* Filter the label / title separator.
*
* Defaults to a colon.
* Filter the label text for archived posts.
*
* @since 0.3.9
* @param string $label_text The label text for archived posts.
* @param int $post_id Optionally passed, the post object.
* @param string $title Optionally passed, the post title.
* @return string
*/
$sep = apply_filters( 'aps_title_separator', ':', $post_id, $title );
$label = (string) apply_filters( 'aps_title_label', aps_archived_label_string(), $post_id );

Check failure on line 168 in src/archived-post-status.php

View workflow job for this annotation

GitHub Actions / Run static analysis

Expected 2 @param tags, found 3.

Check failure on line 168 in src/archived-post-status.php

View workflow job for this annotation

GitHub Actions / Run static analysis

Expected 2 @param tags, found 3.

/**
* Filter the label text for archived posts.
* Change the location of the label text.
*
* @since 0.3.9
* @param string $label_text The label text for archived posts.
* @param int $post_id Optionally passed, the post object.
* @param string $title Optionally passed, the post title.
* @return string
* @param bool $before True to place the before the title,
* false to place it after.
* @param int $post_id Optionally passed, the post object.
* @return bool
*/
$label = apply_filters( 'aps_title_label', aps_archived_label_string(), $post_id, $title );
$before = (bool) apply_filters( 'aps_title_label_before', true, $post_id );

// Set the separator.
$sep = ( true === $before ) ? ': ' : ' - ';

/**
* Change the location of the label text.
* Filter the separator used between the label and title.
*
* Defaults to a colon where before is true, and a dash where
* before is false. Includes spaces as needed.
*
* @since 0.3.9
* @param bool $before True to place the before the title,
* false to place it after.
* @return bool
* @param string $label_text The label text for archived posts.
* @param int $post_id Optionally passed, the post object.
* @return string
*/
$before = (bool) apply_filters( 'aps_title_label_before', true );
$sep = (string) apply_filters( 'aps_title_separator', $sep, $post_id );

// Add label to title.
if ( ! empty( $label ) ) {
if ( $before ) {
$label = esc_attr( $label ) . esc_attr( $sep );
$title = sprintf( '%1$s %2$s', $label, $title );
} else {
$label = esc_attr( $sep ) . esc_attr( $label );
$title = sprintf( '%1$s %2$s', $title, $label );
}

// Sanitize the strings.
$safe_strings = array_filter( [ $label, $sep ], 'esc_attr' );

// Add the strings to the title.
$title = $before ? implode( '', $safe_strings ) . $title : $title . implode( '', array_reverse( $safe_strings ) );

print( $title );
}
}

Expand Down Expand Up @@ -374,8 +379,8 @@ function aps_load_post_screen() {
*
* @filter display_post_states
*
* @param array $post_states
* @param WP_Post $post
* @param array $post_states
* @param WP_Post $post
*
* @return array
*/
Expand Down

0 comments on commit 83ef31e

Please sign in to comment.