diff --git a/src/api/endpoints/class-tainacan-rest-collections-controller.php b/src/api/endpoints/class-tainacan-rest-collections-controller.php index f8883d683..fd69223de 100644 --- a/src/api/endpoints/class-tainacan-rest-collections-controller.php +++ b/src/api/endpoints/class-tainacan-rest-collections-controller.php @@ -19,10 +19,17 @@ class TAINACAN_REST_Collections_Controller extends WP_REST_Controller { public function __construct(){ $this->namespace = 'tainacan/v2'; $this->rest_base = 'collections'; - $this->collections_repository = new Repositories\Collections(); - $this->collection = new Entities\Collection(); add_action('rest_api_init', array($this, 'register_routes')); + add_action('init', array(&$this, 'init_objects'), 11); + } + + /** + * Initialize objects after post_type register + */ + public function init_objects() { + $this->collections_repository = new Repositories\Collections(); + $this->collection = new Entities\Collection(); } /** diff --git a/src/api/endpoints/class-tainacan-rest-filters-controller.php b/src/api/endpoints/class-tainacan-rest-filters-controller.php index 56bf27ebc..38cfacc0e 100644 --- a/src/api/endpoints/class-tainacan-rest-filters-controller.php +++ b/src/api/endpoints/class-tainacan-rest-filters-controller.php @@ -20,16 +20,22 @@ class TAINACAN_REST_Filters_Controller extends WP_REST_Controller { $this->namespace = '/tainacan/v2'; $this->rest_base = 'filters'; + add_action('rest_api_init', array($this, 'register_routes')); + add_action('init', array(&$this, 'init_objects'), 11); + } + + /** + * Initialize objects after post_type register + */ + public function init_objects() { $this->collection = new Entities\Collection(); $this->collection_repository = new Repositories\Collections(); - + $this->metadata = new Entities\Metadata(); $this->metadata_repository = new Repositories\Metadatas(); - + $this->filter = new Entities\Filter(); $this->filter_repository = new Repositories\Filters(); - - add_action('rest_api_init', array($this, 'register_routes')); } public function register_routes() { diff --git a/src/api/endpoints/class-tainacan-rest-items-controller.php b/src/api/endpoints/class-tainacan-rest-items-controller.php index fa40cbb4a..22ec10b19 100644 --- a/src/api/endpoints/class-tainacan-rest-items-controller.php +++ b/src/api/endpoints/class-tainacan-rest-items-controller.php @@ -21,12 +21,19 @@ class TAINACAN_REST_Items_Controller extends WP_REST_Controller { public function __construct() { $this->namespace = 'tainacan/v2'; $this->rest_base = 'items'; + + add_action('rest_api_init', array($this, 'register_routes')); + add_action('init', array(&$this, 'init_objects'), 11); + } + + /** + * Initialize objects after post_type register + */ + public function init_objects() { $this->items_repository = new Repositories\Items(); $this->item = new Entities\Item(); $this->item_metadata = new Repositories\Item_Metadata(); $this->collections_repository = new Repositories\Collections(); - - add_action('rest_api_init', array($this, 'register_routes')); } /** diff --git a/src/api/endpoints/class-tainacan-rest-metadata-controller.php b/src/api/endpoints/class-tainacan-rest-metadata-controller.php index e0263e7e6..5f3af2672 100644 --- a/src/api/endpoints/class-tainacan-rest-metadata-controller.php +++ b/src/api/endpoints/class-tainacan-rest-metadata-controller.php @@ -14,16 +14,21 @@ class TAINACAN_REST_Metadata_Controller extends WP_REST_Controller { $this->namespace = 'tainacan/v2'; $this->rest_base = 'metadata'; + add_action('rest_api_init', array($this, 'register_routes')); + add_action('init', array(&$this, 'init_objects'), 11); + } + + /** + * Initialize objects after post_type register + */ + public function init_objects() { $this->metadata = new Entities\Metadata(); $this->metadata_repository = new Repositories\Metadatas(); $this->item_metadata_repository = new Repositories\Item_Metadata(); $this->item_repository = new Repositories\Items(); $this->collection_repository = new Repositories\Collections(); - - add_action('rest_api_init', array($this, 'register_routes')); } - /** * If POST on metadata/collection/, then * a metadata will be created in matched collection and all your item will receive this metadata diff --git a/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php b/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php index 240f1a67b..00ae74f5a 100644 --- a/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php +++ b/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php @@ -3,7 +3,7 @@ use Tainacan\Entities; use Tainacan\Repositories; -class TAINACAN_REST_Taxonomies_Controller extends WP_REST_Controller { +class TAINACAN_REST_Taxonomies_Controller extends \WP_REST_Controller { private $taxonomy; private $taxonomy_repository; @@ -14,10 +14,16 @@ class TAINACAN_REST_Taxonomies_Controller extends WP_REST_Controller { $this->namespace = 'tainacan/v2'; $this->rest_base = 'taxonomies'; + add_action('rest_api_init', array($this, 'register_routes')); + add_action('init', array(&$this, 'init_objects'), 11); + } + + /** + * Initialize objects after post_type register + */ + public function init_objects() { $this->taxonomy = new Entities\Taxonomy(); $this->taxonomy_repository = new Repositories\Taxonomies(); - - add_action('rest_api_init', array($this, 'register_routes')); } public function register_routes() { diff --git a/src/api/endpoints/class-tainacan-rest-terms-controller.php b/src/api/endpoints/class-tainacan-rest-terms-controller.php index e7edfc1bd..a3248122c 100644 --- a/src/api/endpoints/class-tainacan-rest-terms-controller.php +++ b/src/api/endpoints/class-tainacan-rest-terms-controller.php @@ -16,12 +16,18 @@ class TAINACAN_REST_Terms_Controller extends WP_REST_Controller { $this->namespace = 'tainacan/v2'; $this->rest_base = 'terms'; + add_action('rest_api_init', array($this, 'register_routes')); + add_action('init', array(&$this, 'init_objects'), 11); + } + + /** + * Initialize objects after post_type register + */ + public function init_objects() { $this->term = new Entities\Term(); $this->terms_repository = new Repositories\Terms(); $this->taxonomy = new Entities\Taxonomy(); $this->taxonomy_repository = new Repositories\Taxonomies(); - - add_action('rest_api_init', array($this, 'register_routes')); } public function register_routes() {