Open martincodes-de opened 2 years ago
Symfony and WordPress are merged together, so yes you can call WordPress actions and filters from Symfony.
Is it possible to do this before Wordpress initialized (which initialize after Symfony) ? Without using services that are triggered by Wordpress events/hooks (https://getsword.com/guide/tutorial/services.html)
I need to call some filters with apply_filters
and get the result before initialize_services()
is called in my child theme. I can't trigger Wordpress Hooks to achieve this because I need to call it when my controller is executed
What do you think of this solution (not tested), assuming you're using a custom Symfony controller that triggers the Wordpress loader:
MyEvent extends Event
MyService extends AbstractWordpressService
, and in the constructor your inject EventDispatcherInterface
and immediately listen to MyEvent
. In the listener you store the event data in a property of MyService
MyEvent
with the data you need, before Wordpress initialization. At this point your data is stored in MyService
but Wordpress isn't initalized yetapply_filters
in MyService->initialize()
, using the data you previously storedHi William.
It's a controller who renders a Twig, so controller is not triggering the Wordpress loader I think
(In my case, Wordpress is only used for back-end as a CMS and I disabled Wordpress front-end, front-end is rendered with Symfony and I directly gather the data via the Wordpress sql database)
Hi Loïc,
From what I understand, you want to make Wordpress render some html or some output in your controller using apply_filters
, then print it in your Twig template.
Some possibilities:
file_get_contents()
before rendering the viewNot sure how to do it otherwise as Wordpress can't be unloaded... So you must find a way to isolate the rendering process.
Hey, is it posible to use action / hooks and filters? To, as example, fire some from the symfony part of the application the to the wordpress part?