Skip to content

Commit d3cac4b

Browse files
GaryJonesclaude
andcommitted
fix(story-budget): respect ef_story_budget_taxonomy_used filter in dropdown
The ef_story_budget_taxonomy_used filter was correctly applied to the postboxes (term sections) but the filter dropdown was hardcoded to use the 'category' taxonomy. Changes: - Use $this->taxonomy_used instead of hardcoded 'category' check - Pass taxonomy parameter to wp_dropdown_categories() - Use dynamic labels from taxonomy object - Respect taxonomy's hierarchical setting Fixes #679 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 6dbf3ee commit d3cac4b

File tree

2 files changed

+67
-64
lines changed

2 files changed

+67
-64
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
88

99
### Fixed
1010

11+
* fix(story-budget): respect `ef_story_budget_taxonomy_used` filter in dropdown by @GaryJones in [#861](https://github.com/Automattic/Edit-Flow/pull/861)
1112
* fix: prevent spurious "Leave site?" warning on new posts with custom statuses by @GaryJones in [#860](https://github.com/Automattic/Edit-Flow/pull/860)
1213
* fix: scope module asset loading to relevant pages only by @GaryJones in [#858](https://github.com/Automattic/Edit-Flow/pull/858)
1314
* fix: allow text selection in calendar overlay without triggering drag by @GaryJones in [#857](https://github.com/Automattic/Edit-Flow/pull/857)

modules/story-budget/story-budget.php

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ public function __construct() {
4343

4444
$this->module_url = $this->get_module_url( __FILE__ );
4545
// Register the module with Edit Flow
46-
$args = array(
47-
'title' => __( 'Story Budget', 'edit-flow' ),
46+
$args = array(
47+
'title' => __( 'Story Budget', 'edit-flow' ),
4848
// translators: %s is a link to the story budget page
49-
'short_description' => sprintf( __( 'View the status of all your content <a href="%s">at a glance</a>.', 'edit-flow' ), admin_url( 'index.php?page=story-budget' ) ),
49+
'short_description' => sprintf( __( 'View the status of all your content <a href="%s">at a glance</a>.', 'edit-flow' ), admin_url( 'index.php?page=story-budget' ) ),
5050
'extended_description' => __( 'Use the story budget to see how content on your site is progressing. Filter by specific categories or date ranges to see details about each post in progress.', 'edit-flow' ),
51-
'module_url' => $this->module_url,
52-
'img_url' => $this->module_url . 'lib/story_budget_s128.png',
53-
'slug' => 'story-budget',
54-
'default_options' => array(
51+
'module_url' => $this->module_url,
52+
'img_url' => $this->module_url . 'lib/story_budget_s128.png',
53+
'slug' => 'story-budget',
54+
'default_options' => array(
5555
'enabled' => 'on',
5656
),
57-
'configure_page_cb' => false,
58-
'autoload' => false,
57+
'configure_page_cb' => false,
58+
'autoload' => false,
5959
);
6060
$this->module = EditFlow()->register_module( 'story_budget', $args );
6161
}
@@ -70,10 +70,10 @@ public function init() {
7070
return;
7171
}
7272

73-
$this->num_columns = $this->get_num_columns();
74-
$this->show_excerpts = $this->get_show_excerpts();
75-
$this->hide_empty_terms = $this->get_hide_empty_terms();
76-
$this->max_num_columns = apply_filters( 'ef_story_budget_max_num_columns', 3 );
73+
$this->num_columns = $this->get_num_columns();
74+
$this->show_excerpts = $this->get_show_excerpts();
75+
$this->hide_empty_terms = $this->get_hide_empty_terms();
76+
$this->max_num_columns = apply_filters( 'ef_story_budget_max_num_columns', 3 );
7777

7878
// Filter to allow users to pick a taxonomy other than 'category' for sorting their posts
7979
$this->taxonomy_used = apply_filters( 'ef_story_budget_taxonomy_used', $this->taxonomy_used );
@@ -100,9 +100,9 @@ public function install() {
100100

101101
$story_budget_roles = array(
102102
'administrator' => array( 'ef_view_story_budget' ),
103-
'editor' => array( 'ef_view_story_budget' ),
104-
'author' => array( 'ef_view_story_budget' ),
105-
'contributor' => array( 'ef_view_story_budget' ),
103+
'editor' => array( 'ef_view_story_budget' ),
104+
'author' => array( 'ef_view_story_budget' ),
105+
'contributor' => array( 'ef_view_story_budget' ),
106106
);
107107
foreach ( $story_budget_roles as $role => $caps ) {
108108
$this->add_caps_to_role( $role, $caps );
@@ -184,14 +184,14 @@ public function action_enqueue_admin_styles() {
184184
public function register_term_columns() {
185185

186186
$term_columns = array(
187-
'title' => __( 'Title', 'edit-flow' ),
188-
'status' => __( 'Status', 'edit-flow' ),
189-
'author' => __( 'Author', 'edit-flow' ),
190-
'post_date' => __( 'Post Date', 'edit-flow' ),
187+
'title' => __( 'Title', 'edit-flow' ),
188+
'status' => __( 'Status', 'edit-flow' ),
189+
'author' => __( 'Author', 'edit-flow' ),
190+
'post_date' => __( 'Post Date', 'edit-flow' ),
191191
'post_modified' => __( 'Last Modified', 'edit-flow' ),
192192
);
193193

194-
$term_columns = apply_filters( 'ef_story_budget_term_columns', $term_columns );
194+
$term_columns = apply_filters( 'ef_story_budget_term_columns', $term_columns );
195195
$this->term_columns = $term_columns;
196196
}
197197

@@ -394,16 +394,16 @@ public function story_budget() {
394394
$this->user_filters = $this->update_user_filters();
395395

396396
if ( ! empty( $this->user_filters[ $this->taxonomy_used ] ) ) {
397-
$terms = array();
397+
$terms = array();
398398
$terms[] = get_term( $this->user_filters[ $this->taxonomy_used ], $this->taxonomy_used );
399399
} else {
400400
// Get all of the terms from the taxonomy, regardless whether there are published posts
401401
$terms = get_terms( array(
402402
'taxonomy' => $this->taxonomy_used,
403-
'orderby' => 'name',
404-
'order' => 'asc',
403+
'orderby' => 'name',
404+
'order' => 'asc',
405405
'hide_empty' => 0,
406-
'parent' => 0,
406+
'parent' => 0,
407407
));
408408
}
409409
$this->terms = apply_filters( 'ef_story_budget_filter_terms', $terms ); // allow for reordering or any other filtering of terms
@@ -486,30 +486,30 @@ public function story_budget_time_range() {
486486
public function get_posts_for_term( $term, $args = null ) {
487487

488488
$defaults = array(
489-
'post_status' => null,
490-
'author' => null,
489+
'post_status' => null,
490+
'author' => null,
491491
'posts_per_page' => apply_filters( 'ef_story_budget_max_query', 200 ),
492492
);
493-
$args = array_merge( $defaults, $args );
493+
$args = array_merge( $defaults, $args );
494494

495495
// Filter to the term and any children if it's hierarchical
496-
$arg_terms = array(
496+
$arg_terms = array(
497497
$term->term_id,
498498
);
499-
$arg_terms = array_merge( $arg_terms, get_term_children( $term->term_id, $this->taxonomy_used ) );
499+
$arg_terms = array_merge( $arg_terms, get_term_children( $term->term_id, $this->taxonomy_used ) );
500500
$args['tax_query'] = array(
501501
array(
502502
'taxonomy' => $this->taxonomy_used,
503-
'field' => 'id',
504-
'terms' => $arg_terms,
503+
'field' => 'id',
504+
'terms' => $arg_terms,
505505
'operator' => 'IN',
506506
),
507507
);
508508

509509
// Unpublished as a status is just an array of everything but 'publish'.
510510
if ( 'unpublish' == $args['post_status'] ) {
511511
$args['post_status'] = '';
512-
$post_stati = wp_filter_object_list( $this->get_budget_post_stati(), array( 'name' => 'publish' ), 'not' );
512+
$post_stati = wp_filter_object_list( $this->get_budget_post_stati(), array( 'name' => 'publish' ), 'not' );
513513

514514
if ( ! apply_filters( 'ef_show_scheduled_as_unpublished', false ) ) {
515515
$post_stati = wp_filter_object_list( $post_stati, array( 'name' => 'future' ), 'not' );
@@ -524,8 +524,8 @@ public function get_posts_for_term( $term, $args = null ) {
524524
}
525525

526526
$beginning_date = strtotime( $this->user_filters['start_date'] );
527-
$days_to_show = $this->user_filters['number_days'];
528-
$ending_date = $beginning_date + ( $days_to_show * DAY_IN_SECONDS );
527+
$days_to_show = $this->user_filters['number_days'];
528+
$ending_date = $beginning_date + ( $days_to_show * DAY_IN_SECONDS );
529529

530530
$args['date_query'] = array(
531531
'after' => date( 'Y-m-d', $beginning_date ),
@@ -684,7 +684,7 @@ public function term_column_title( $post, $parent_term ) {
684684
$post_title = _draft_or_post_title( $post->ID );
685685

686686
$post_type_object = get_post_type_object( $post->post_type );
687-
$can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
687+
$can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
688688
if ( $can_edit_post ) {
689689
$output = '<strong><a href="' . get_edit_post_link( $post->ID ) . '">' . esc_html( $post_title ) . '</a></strong>';
690690
} else {
@@ -707,7 +707,7 @@ public function term_column_title( $post, $parent_term ) {
707707
$output .= '</div>';
708708

709709
// Edit or Trash or View
710-
$output .= '<div class="row-actions">';
710+
$output .= '<div class="row-actions">';
711711
$item_actions = array();
712712
if ( $can_edit_post ) {
713713
$item_actions['edit'] = '<a title="' . __( 'Edit this post', 'edit-flow' ) . '" href="' . get_edit_post_link( $post->ID ) . '">' . __( 'Edit', 'edit-flow' ) . '</a>';
@@ -720,15 +720,15 @@ public function term_column_title( $post, $parent_term ) {
720720
if ( in_array( $post->post_status, array( 'publish' ) ) ) {
721721
// translators: %s is the post title
722722
$item_actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'edit-flow' ), $post_title ) ) . '" rel="permalink">' . __( 'View', 'edit-flow' ) . '</a>';
723-
} else if ( $can_edit_post ) {
723+
} elseif ( $can_edit_post ) {
724724
// translators: %s is the post title
725725
$item_actions['previewpost'] = '<a href="' . esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ), $post ) ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;', 'edit-flow' ), $post_title ) ) . '" rel="permalink">' . __( 'Preview', 'edit-flow' ) . '</a>';
726726
}
727727

728728
$item_actions = apply_filters( 'ef_story_budget_item_actions', $item_actions, $post->ID );
729729
if ( count( $item_actions ) ) {
730730
$output .= '<div class="row-actions">';
731-
$html = '';
731+
$html = '';
732732
foreach ( $item_actions as $class => $item_action ) {
733733
$html .= '<span class="' . esc_attr( $class ) . '">' . $item_action . '</span> | ';
734734
}
@@ -747,7 +747,6 @@ public function print_messages() {
747747

748748
<?php
749749
if ( isset( $_GET['trashed'] ) || isset( $_GET['untrashed'] ) ) {
750-
751750
echo '<div id="trashed-message" class="updated"><p>';
752751

753752
// Following mostly stolen from edit.php
@@ -810,11 +809,11 @@ public function update_user_filters() {
810809
$current_user = wp_get_current_user();
811810

812811
$user_filters = array(
813-
'post_status' => $this->filter_get_param( 'post_status' ),
814-
'cat' => $this->filter_get_param( 'cat' ),
815-
'author' => $this->filter_get_param( 'author' ),
816-
'start_date' => $this->filter_get_param( 'start_date' ),
817-
'number_days' => $this->filter_get_param( 'number_days' ),
812+
'post_status' => $this->filter_get_param( 'post_status' ),
813+
'cat' => $this->filter_get_param( 'cat' ),
814+
'author' => $this->filter_get_param( 'author' ),
815+
'start_date' => $this->filter_get_param( 'start_date' ),
816+
'number_days' => $this->filter_get_param( 'number_days' ),
818817
);
819818

820819
$current_user_filters = array();
@@ -870,7 +869,7 @@ public function filter_get_param( $param ) {
870869
// Sure, this could be done in one line. But we're cooler than that: let's make it more readable!
871870
if ( ! isset( $_GET[ $param ] ) ) {
872871
return null;
873-
} else if ( empty( $_GET[ $param ] ) ) {
872+
} elseif ( empty( $_GET[ $param ] ) ) {
874873
return '';
875874
}
876875

@@ -881,8 +880,8 @@ public function story_budget_filters() {
881880
$select_filter_names = array();
882881

883882
$select_filter_names['post_status'] = 'post_status';
884-
$select_filter_names['cat'] = 'cat';
885-
$select_filter_names['author'] = 'author';
883+
$select_filter_names['cat'] = 'cat';
884+
$select_filter_names['author'] = 'author';
886885

887886
return apply_filters( 'ef_story_budget_filter_names', $select_filter_names );
888887
}
@@ -907,19 +906,22 @@ public function story_budget_filter_options( $select_id, $select_name, $filters
907906
<?php
908907
break;
909908
case 'cat':
910-
// Borrowed from wp-admin/edit.php
911-
if ( taxonomy_exists( 'category' ) ) {
909+
if ( taxonomy_exists( $this->taxonomy_used ) ) {
910+
$taxonomy_obj = get_taxonomy( $this->taxonomy_used );
912911
echo '<label for="cat">';
913-
echo '<span class="screen-reader-text">' . esc_html__( 'Filter by category', 'edit-flow' ) . '</span>';
914-
$category_dropdown_args = array(
915-
'show_option_all' => __( 'View all categories', 'edit-flow' ),
916-
'hide_empty' => 0,
917-
'hierarchical' => 1,
918-
'show_count' => 0,
919-
'orderby' => 'name',
920-
'selected' => $this->user_filters['cat'],
912+
// translators: %s is the taxonomy name (e.g., "category", "tag")
913+
echo '<span class="screen-reader-text">' . esc_html( sprintf( __( 'Filter by %s', 'edit-flow' ), $taxonomy_obj->labels->singular_name ) ) . '</span>';
914+
$dropdown_args = array(
915+
// translators: %s is the taxonomy name (e.g., "categories", "tags")
916+
'show_option_all' => sprintf( __( 'View all %s', 'edit-flow' ), strtolower( $taxonomy_obj->labels->name ) ),
917+
'hide_empty' => 0,
918+
'hierarchical' => $taxonomy_obj->hierarchical,
919+
'show_count' => 0,
920+
'orderby' => 'name',
921+
'selected' => $this->user_filters['cat'],
922+
'taxonomy' => $this->taxonomy_used,
921923
);
922-
wp_dropdown_categories( $category_dropdown_args );
924+
wp_dropdown_categories( $dropdown_args );
923925
echo '</label>';
924926
}
925927
break;
@@ -928,9 +930,9 @@ public function story_budget_filter_options( $select_id, $select_name, $filters
928930
echo '<span class="screen-reader-text">' . esc_html__( 'Filter by author', 'edit-flow' ) . '</span>';
929931
$users_dropdown_args = array(
930932
'show_option_all' => __( 'View all users', 'edit-flow' ),
931-
'name' => 'author',
932-
'selected' => $this->user_filters['author'],
933-
'who' => 'authors',
933+
'name' => 'author',
934+
'selected' => $this->user_filters['author'],
935+
'who' => 'authors',
934936
);
935937
$users_dropdown_args = apply_filters( 'ef_story_budget_users_dropdown_args', $users_dropdown_args );
936938
wp_dropdown_users( $users_dropdown_args );
@@ -948,8 +950,8 @@ public function story_budget_filter_options( $select_id, $select_name, $filters
948950
* @return array An array of StdClass objects representing statuses
949951
*/
950952
public function get_budget_post_stati() {
951-
$post_stati = get_post_stati( array(), 'object' );
952-
$custom_status_slugs = wp_list_pluck( $this->get_post_statuses(), 'slug' );
953+
$post_stati = get_post_stati( array(), 'object' );
954+
$custom_status_slugs = wp_list_pluck( $this->get_post_statuses(), 'slug' );
953955
$custom_status_slugs[] = 'future';
954956
$custom_status_slugs[] = 'publish';
955957

0 commit comments

Comments
 (0)