CollectionTaxonomyService.php
1 year ago
StoreTaxonomyService.php
1 year ago
TaxonomyService.php
1 year ago
TaxonomyServiceProvider.php
1 year ago
TaxonomyService.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\WordPress\Taxonomies; |
| 4 | |
| 5 | /** |
| 6 | * Taxonomy Service. |
| 7 | */ |
| 8 | class TaxonomyService { |
| 9 | /** |
| 10 | * Bootstrap the service. |
| 11 | */ |
| 12 | public function bootstrap() { |
| 13 | add_action( 'admin_init', [ $this, 'manageScreen' ] ); |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Removes the posts column from the taxonomy table since this can |
| 18 | * lead them to edit the product post type directly. |
| 19 | */ |
| 20 | public function manageScreen() { |
| 21 | $taxonomies = get_taxonomies( array(), 'names' ); |
| 22 | foreach ( $taxonomies as $taxonomy ) { |
| 23 | $taxonomy_object = get_taxonomy( $taxonomy ); |
| 24 | if ( ! in_array( 'sc_product', (array) $taxonomy_object->object_type, true ) ) { |
| 25 | continue; |
| 26 | } |
| 27 | |
| 28 | add_filter( |
| 29 | "manage_edit-{$taxonomy}_columns", |
| 30 | function ( $columns ) { |
| 31 | unset( $columns['posts'] ); |
| 32 | return $columns; |
| 33 | } |
| 34 | ); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Generate the link to edit a taxonomy. |
| 40 | * |
| 41 | * @param string $taxonomy_name The taxonomy name. |
| 42 | * |
| 43 | * @return string |
| 44 | */ |
| 45 | public function editLink( $taxonomy_name, $post_type = '' ) { |
| 46 | if ( empty( $taxonomy_name ) || ! is_string( $taxonomy_name ) || ! taxonomy_exists( $taxonomy_name ) ) { |
| 47 | return ''; |
| 48 | } |
| 49 | |
| 50 | return add_query_arg( |
| 51 | array_filter( |
| 52 | array( |
| 53 | 'taxonomy' => $taxonomy_name, |
| 54 | 'post_type' => $post_type, |
| 55 | ) |
| 56 | ), |
| 57 | 'edit-tags.php' |
| 58 | ); |
| 59 | } |
| 60 | } |
| 61 |