Add hooks to inject new template types #170
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This refactors the magic link template types (single record and list of sub-assigned contacts) to be initialized using hooks. This will allow developers to create their own template types from other plugins and inject them into the list of available template types.
The current use case that prompted this is to create a template type from my team module plugin. We want to create a template that is all of the contacts that are assigned to the team that I am on. That should be created in the team module plugin, but there isn't a way for that to interact with this plugin at the moment.
Filter:
dt_magic_link_template_types
Creates the list of available template types so that a dev can add the name of their template type to the list in the admin
Action:
dt_magic_link_template_load
Used to instantiate a magic link class that will display the magic link on the front-end.
Following this being merged, we could add a sample of this to the starter template so that it's easy for devs to see how to do this.
For help in reviewing, the two new files in the
templates
folder are direct copies of the originalmagic-link-templates.php
file that held the code for those two templates. Minimal code was changed in there besides adding the hooks at the top and changing someprivate
properties toprotected
so that the list-sub-assigned could inherit the single-record and share code.