| Conditions | 3 |
| Paths | 2 |
| Total Lines | 116 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 116 | protected function compile_args( Taxonomy $taxonomy ): array { |
||
| 117 | // Create the labels. |
||
| 118 | $base_labels = array( |
||
| 119 | 'name' => $taxonomy->plural, |
||
| 120 | 'singular_name' => $taxonomy->singular, |
||
| 121 | 'menu_name' => \ucfirst( \esc_attr( $taxonomy->plural ?? '' ) ), |
||
| 122 | /* translators: %s: Taxonomy plural name */ |
||
| 123 | 'search_items' => wp_sprintf( _x( 'Search %s', 'Label for searching plural items. Default is ‘Search {taxonomy plural name}’.', 'pinkcrab' ), \esc_attr( $taxonomy->plural ?? '' ) ), |
||
| 124 | /* translators: %s: Taxonomy plural name */ |
||
| 125 | 'popular_items' => wp_sprintf( _x( 'Popular %s', 'Label for the popular terms', 'pinkcrab' ), \esc_attr( $taxonomy->plural ?? '' ) ), |
||
| 126 | /* translators: %s: Taxonomy singular name */ |
||
| 127 | 'edit_item' => wp_sprintf( _x( 'Edit %s', 'Label for editing a singular item. Default is ‘Edit {taxonomy singular name}’.', 'pinkcrab' ), \esc_attr( $taxonomy->singular ?? '' ) ), |
||
| 128 | /* translators: %s: Taxonomy singular name */ |
||
| 129 | 'view_item' => wp_sprintf( _x( 'View %s', 'Label for viewing a singular item. Default is ‘View {taxonomy singular name}’.', 'pinkcrab' ), \esc_attr( $taxonomy->singular ?? '' ) ), |
||
| 130 | /* translators: %s: Taxonomy singular name */ |
||
| 131 | 'update_item' => wp_sprintf( _x( 'Update %s', 'Label for editing a singular item. Default is ‘Edit {taxonomy singular name}’.', 'pinkcrab' ), \esc_attr( $taxonomy->singular ?? '' ) ), |
||
| 132 | /* translators: %s: Taxonomy singular name */ |
||
| 133 | 'add_new_item' => wp_sprintf( _x( 'Add New %s', 'Label for adding a new singular item. Default is ‘Add New {taxonomy singular name}’.', 'pinkcrab' ), \esc_attr( $taxonomy->singular ?? '' ) ), |
||
| 134 | /* translators: %s: Taxonomy singular name */ |
||
| 135 | 'new_item_name' => wp_sprintf( _x( 'New %s', 'Label for the new item page title. Default is ‘New {taxonomy singular name}’.', 'pinkcrab' ), \esc_attr( $taxonomy->singular ?? '' ) ), |
||
| 136 | /* translators: %s: Taxonomy plural name */ |
||
| 137 | 'not_found' => wp_sprintf( _x( 'No %s found', 'Label used when no items are found. Default is ‘No {taxonomy plural name} found’.', 'pinkcrab' ), \esc_attr( $taxonomy->plural ?? '' ) ), |
||
| 138 | /* translators: %s: Taxonomy plural name */ |
||
| 139 | 'items_list' => wp_sprintf( _x( '%s list', 'Label for the table hidden heading. Default is ‘{taxonomy plural name} list’.', 'pinkcrab' ), \ucfirst( \esc_attr( $taxonomy->plural ?? '' ) ) ), |
||
| 140 | /* translators: %s: Taxonomy plural name */ |
||
| 141 | 'items_list_navigation' => wp_sprintf( _x( '%s list navigation', 'Label for the pagination hidden heading. Default is ‘{taxonomy plural name} list’.', 'pinkcrab' ), \ucfirst( \esc_attr( $taxonomy->plural ?? '' ) ) ), |
||
| 142 | /* translators: %s: Taxonomy plural name */ |
||
| 143 | 'all_items' => wp_sprintf( _x( 'All %s', 'Label for the pagination hidden heading. Default is ‘{taxonomy plural name} list’.', 'pinkcrab' ), \ucfirst( \esc_attr( $taxonomy->plural ?? '' ) ) ), |
||
| 144 | 'most_used' => _x( 'Most Used', 'Title for the Most Used tab. Default \'Most Used\'.', 'pinkcrab' ), |
||
| 145 | /* translators: %s: Taxonomy plural name */ |
||
| 146 | 'back_to_items' => wp_sprintf( _x( '← Back to %s', 'Label for the pagination hidden heading. Default is ‘{taxonomy plural name} list’.', 'pinkcrab' ), \ucfirst( \esc_attr( $taxonomy->plural ?? '' ) ) ), |
||
| 147 | /* translators: %s: Taxonomy singular name */ |
||
| 148 | 'item_link' => wp_sprintf( _x( '%s Link', 'Title for a navigation link block variation. Default is ‘{taxonomy singular name} Link’.', 'pinkcrab' ), \ucfirst( \esc_attr( $taxonomy->singular ?? '' ) ) ), |
||
| 149 | /* translators: %s: Taxonomy singular name */ |
||
| 150 | 'item_link_description' => wp_sprintf( _x( 'A link to a %s', 'Description for a navigation link block variation. Default is ‘A link to a {taxonomy singular name}’.', 'pinkcrab' ), \esc_attr( $taxonomy->singular ?? '' ) ), |
||
| 151 | ); |
||
| 152 | |||
| 153 | $tag_labels = array( |
||
| 154 | /* translators: %s: Taxonomy plural name */ |
||
| 155 | 'separate_items_with_commas' => wp_sprintf( _x( 'Separate %s with commas', 'This label is only used for non-hierarchical taxonomies. Default \'Separate {taxonomy plural name} with commas\', used in the meta box.’.', 'pinkcrab' ), \esc_attr( $taxonomy->plural ?? '' ) ), |
||
| 156 | /* translators: %s: Taxonomy plural name */ |
||
| 157 | 'add_or_remove_items' => wp_sprintf( _x( 'Add or remove %s', 'This label is only used for non-hierarchical taxonomies. Default \'Add or remove {taxonomy plural name}\', used in the meta box when JavaScript is disabled.', 'pinkcrab' ), \esc_attr( $taxonomy->plural ?? '' ) ), |
||
| 158 | /* translators: %s: Taxonomy plural name */ |
||
| 159 | 'choose_from_most_used' => wp_sprintf( _x( 'Add or remove %s', 'This label is only used on non-hierarchical taxonomies. Default\'Choose from the most used {taxonomy plural name}\', used in the meta box.', 'pinkcrab' ), \esc_attr( $taxonomy->plural ?? '' ) ), |
||
| 160 | ); |
||
| 161 | |||
| 162 | $hierarchical_labels = array( |
||
| 163 | /* translators: %s: Taxonomy singular name */ |
||
| 164 | 'parent_item_colon' => wp_sprintf( _x( 'Parent %s:', 'Label used to prefix parents of hierarchical items. Not used on non-hierarchical taxonomys. Default is ‘Parent {taxonomy plural name}:’.', 'pinkcrab' ), \esc_attr( $taxonomy->singular ?? '' ) ), |
||
| 165 | /* translators: %s: Taxonomy singular name */ |
||
| 166 | 'parent_item' => wp_sprintf( _x( 'Parent %s', 'Label for the parent term', 'pinkcrab' ), \esc_attr( $taxonomy->singular ?? '' ) ), |
||
| 167 | /* translators: %s: Taxonomy singular name */ |
||
| 168 | 'filter_by_item' => wp_sprintf( _x( 'Filter by %s', 'This label is only used for hierarchical taxonomies. Default \'Filter by {taxonomy singular name}\', used in the posts list table.', 'pinkcrab' ), \esc_attr( $taxonomy->singular ?? '' ) ), |
||
| 169 | ); |
||
| 170 | |||
| 171 | $labels = array_merge( |
||
| 172 | $base_labels, |
||
| 173 | $taxonomy->hierarchical ? $hierarchical_labels : $tag_labels |
||
| 174 | ); |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Allow 3rd party plugins to filter the labels also. |
||
| 178 | * |
||
| 179 | * @filter_handle PinkCrab/Registerable/taxonomy_labels |
||
| 180 | * @param array<string, string> $labels |
||
| 181 | * @param Taxonomy $taxonomy |
||
| 182 | * @return array<string, string> |
||
| 183 | */ |
||
| 184 | $labels = apply_filters( Registerable_Hooks::TAXONOMY_LABELS, $taxonomy->filter_labels( $labels ), $taxonomy ); |
||
| 185 | |||
| 186 | // Compose args. |
||
| 187 | $args = array( |
||
| 188 | 'labels' => $labels, |
||
| 189 | 'publicly_queryable' => $taxonomy->publicly_queryable, |
||
| 190 | 'show_ui' => $taxonomy->show_ui, |
||
| 191 | 'show_in_menu' => $taxonomy->show_in_menu, |
||
| 192 | 'show_in_nav_menus' => $taxonomy->public, |
||
| 193 | 'show_in_rest' => $taxonomy->show_in_rest, |
||
| 194 | 'rest_base' => $taxonomy->rest_base ?? $taxonomy->slug, |
||
| 195 | 'rest_controller_class' => $taxonomy->rest_controller_class, |
||
| 196 | 'show_tagcloud' => $taxonomy->show_tagcloud, |
||
| 197 | 'show_in_quick_edit' => $taxonomy->show_in_quick_edit, |
||
| 198 | 'show_admin_column' => $taxonomy->show_admin_column, |
||
| 199 | 'sort' => $taxonomy->sort, |
||
| 200 | 'description' => $taxonomy->description, |
||
| 201 | 'rewrite' => $taxonomy->slug, |
||
| 202 | 'label' => $taxonomy->label ?? $taxonomy->plural, |
||
| 203 | 'query_var' => $taxonomy->query_var, |
||
| 204 | 'hierarchical' => $taxonomy->hierarchical, |
||
| 205 | 'update_count_callback' => $taxonomy->update_count_callback ?? '_update_post_term_count', |
||
| 206 | 'meta_box_cb' => $taxonomy->meta_box_cb ?? |
||
| 207 | $taxonomy->hierarchical ? 'post_categories_meta_box' : 'post_tags_meta_box', |
||
| 208 | 'default_term' => $taxonomy->default_term, |
||
| 209 | ); |
||
| 210 | |||
| 211 | // Merge existing capabilities with the new ones. |
||
| 212 | $args['capabilities'] = array_merge( |
||
| 213 | array( |
||
| 214 | 'manage_terms' => 'manage_categories', |
||
| 215 | 'edit_terms' => 'manage_categories', |
||
| 216 | 'delete_terms' => 'manage_categories', |
||
| 217 | 'assign_terms' => 'edit_posts', |
||
| 218 | ), |
||
| 219 | $taxonomy->capabilities ?? array() |
||
| 220 | ); |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Allow 3rd party plugins to filter this also. |
||
| 224 | * |
||
| 225 | * @filter_handle PinkCrab/Registerable/taxonomy_args |
||
| 226 | * @param array<string, string|bool|int|null|array<string, string>> $args |
||
| 227 | * @param Taxonomy $taxonomy |
||
| 228 | * @return array<string, string|bool|int|null|array<string, string>> |
||
| 229 | */ |
||
| 230 | /* @phpstan-ignore-next-line, this is due to apply_filters type hints being wrong. */ |
||
| 231 | return apply_filters( Registerable_Hooks::TAXONOMY_ARGS, $taxonomy->filter_args( $args ), $taxonomy ); |
||
| 232 | } |
||
| 234 |