Shortcodes Service
The shortcodes service is actually extremely similar to the hooks service described previously. It's a single-handler service with a runnable and a resettable action. It provides the following public methods:
add_shortcode- registers a shortcode with the handlerremove_shortcode- removes a shortcode registered with the handlerremove_all_shortcodes- removes all shortcodes registered with the handler
It accepts any handler implementing the ShortcodesHandlerInterface and, just like the hooks service, comes with a default handler that first stores all registered shortcodes in an array and registers them with WP on the run action.
The similarities don't end there though! All the traits and interfaces mentioned for the hooks service are also available for the shortcodes service:
ShortcodesServiceAwareInterfaceandShortcodesServiceAwareTraitfor a getter/setter pairShortcodesServiceRegisterInterfaceandShortcodesServiceRegisterTraitfor injecting the service externallyInitializeShortcodesTraitfor automagically setting the instance on the objecSetupShortcodesTraitfor automagically calling theregister_shortcodesmethod on setup
Last updated
Was this helpful?