Skip to content

Commit

Permalink
Allow extending taxonomy
Browse files Browse the repository at this point in the history
  • Loading branch information
nlemoine committed Jun 12, 2024
1 parent 98cddd4 commit 3aefa78
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,14 @@ public function init(): void {
add_filter( 'rewrite_testing_tests', [ $this, 'rewrite_testing_tests' ], 1 );
}

# Register taxonomy:
$this->register_taxonomy();
$existing = get_taxonomy( $this->taxonomy );

if ( empty( $existing ) ) {
# Register taxonomy:
$this->register_taxonomy();
} else {
$this->extend( $existing );

Check failure on line 205 in src/Taxonomy.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 7.4 / PHP / PHP 7.4

Parameter #1 $taxonomy of method ExtCPTs\Taxonomy::extend() expects ExtCPTs\WP_Taxonomy, WP_Taxonomy given.

Check failure on line 205 in src/Taxonomy.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 8.3 / PHP / PHP 8.3

Parameter #1 $taxonomy of method ExtCPTs\Taxonomy::extend() expects ExtCPTs\WP_Taxonomy, WP_Taxonomy given.
}

/**
* Fired when the extended taxonomy instance is set up.
Expand All @@ -209,6 +215,18 @@ public function init(): void {
do_action( "ext-taxos/{$this->taxonomy}/instance", $this );
}

/**
* Extends an existing taxonomy object. Currently only handles labels.
*
* @param WP_Taxonomy $taxonomy A taxonomy object.
*/
public function extend( WP_Taxonomy $taxonomy ) {

Check failure on line 223 in src/Taxonomy.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 7.4 / PHP / PHP 7.4

Method ExtCPTs\Taxonomy::extend() has no return type specified.

Check failure on line 223 in src/Taxonomy.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 7.4 / PHP / PHP 7.4

Parameter $taxonomy of method ExtCPTs\Taxonomy::extend() has invalid type ExtCPTs\WP_Taxonomy.

Check failure on line 223 in src/Taxonomy.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 7.4 / PHP / PHP 7.4

Parameter $taxonomy of method ExtCPTs\Taxonomy::extend() has invalid type ExtCPTs\WP_Taxonomy.

Check failure on line 223 in src/Taxonomy.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 8.3 / PHP / PHP 8.3

Method ExtCPTs\Taxonomy::extend() has no return type specified.

Check failure on line 223 in src/Taxonomy.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 8.3 / PHP / PHP 8.3

Parameter $taxonomy of method ExtCPTs\Taxonomy::extend() has invalid type ExtCPTs\WP_Taxonomy.

Check failure on line 223 in src/Taxonomy.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 8.3 / PHP / PHP 8.3

Parameter $taxonomy of method ExtCPTs\Taxonomy::extend() has invalid type ExtCPTs\WP_Taxonomy.
# Merge core with overridden labels
$this->args['labels'] = array_merge( (array) get_taxonomy_labels( $taxonomy ), $this->args['labels'] );

Check failure on line 225 in src/Taxonomy.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 7.4 / PHP / PHP 7.4

Parameter #1 $tax of function get_taxonomy_labels expects WP_Taxonomy, ExtCPTs\WP_Taxonomy given.

Check failure on line 225 in src/Taxonomy.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 8.3 / PHP / PHP 8.3

Parameter #1 $tax of function get_taxonomy_labels expects WP_Taxonomy, ExtCPTs\WP_Taxonomy given.

$GLOBALS['wp_taxonomies'][ $taxonomy->name ]->labels = (object) $this->args['labels'];

Check failure on line 227 in src/Taxonomy.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 7.4 / PHP / PHP 7.4

Access to property $name on an unknown class ExtCPTs\WP_Taxonomy.

Check failure on line 227 in src/Taxonomy.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 8.3 / PHP / PHP 8.3

Access to property $name on an unknown class ExtCPTs\WP_Taxonomy.
}

/**
* Add our rewrite tests to the Rewrite Rule Testing tests array.
*
Expand Down

0 comments on commit 3aefa78

Please sign in to comment.