Register your model into Simply
After creating all of your models you have to register the models into Simply.
Why ?
To inject automatically the good model with ModelFactory. The ModelFactory allows you to return the correct model according to the injecting object.
Like when you use hook you don't know which post type is the current object queried.
<?php
global $post;
// $post->post_type is project
$project = ModelFactory::create($post);
// $project will be an instance of Project model after registered into Simply
How ?
By create a Simply framework extension
After creating your simply extension add the interface RegisterModelInterface to your extension class.
- Use the method
registerModelto register your post type model and erase old configuration. - Use the method
addPostModelto register your post type model. - Use the method
registerTermModelto register your taxonomy model and erase old configuration. - Use the method
addTermModelto register your taxonomy model.
<?php
class ThemePlugin implements PluginInterface, RegisterModelInterface {
public function build(ContainerBuilder $container): void {}
public function registerModel(ModelFactory $factory): void {
$factory->registerPostModel([MyPostTypeClass::class, Post::class]);
$factory->registerTermModel([MyTaxonomyClass::class]);
}
}
Deprecated method
With the good filter provides by Simply :
- Post type
- Taxonomy
add_filter('simply/model/post_type_mapping', function(array $mapping) {
$mapping[] = Project::class;
return $mapping;
});
// Add model for project tag
add_filter('simply/model/term_mapping', function(array $mapping) {
$mapping[] = ProjectTag::class;
return $mapping;
});
The $mapping array has basic object for post and category and tag. You can remove or replace it.