php - Run code before Wordpress loads and insert data into WP if need be

admin2025-01-07  4

I've done my requisite research and can't seem to find an ELEGANT way to do this.

We have a Wordpress app with some fairly intensive session management requirements and now need to run some old code before even loading Wordpress. I plan on initiating this process on the first line of the WP index.php file.

However, depending on the results of this old code, we may need to pass along a handful of key/value data from this process down to the plugin level in WP. What would be a good way to approach this? Thanks!

UPDATE (2017-01-19):

I just decided to use a local Redis instance to store any k/v data should the request need to proceed onward and load WP.

I've done my requisite research and can't seem to find an ELEGANT way to do this.

We have a Wordpress app with some fairly intensive session management requirements and now need to run some old code before even loading Wordpress. I plan on initiating this process on the first line of the WP index.php file.

However, depending on the results of this old code, we may need to pass along a handful of key/value data from this process down to the plugin level in WP. What would be a good way to approach this? Thanks!

UPDATE (2017-01-19):

I just decided to use a local Redis instance to store any k/v data should the request need to proceed onward and load WP.

Share Improve this question edited Jan 19, 2017 at 19:17 Jim Bailie asked Jan 19, 2017 at 2:33 Jim BailieJim Bailie 11 bronze badge 1
  • Store it in the database then get it back out of the database. – C C Commented Jan 19, 2017 at 2:40
Add a comment  | 

2 Answers 2

Reset to default 1

Unless performance is a huge factor, or you need to change PHP session globals, you don't need to run anything before wordpress, just write a plugin that makes the checks needed on the init hook and die() if needed. This way you can also store the data wherever it is convenient for you.

For sure editing any wordpess core file is a big no-no which amount to forking wordpress with all the responsibilities it requires from you. The only file you may edit is wp-config.php but this should probably be done only if the plugin approach will not work

https://codex.wordpress.org/Plugin_API/Action_Reference

Take a look at this list of hooks and call your function using the hook that you think is appropriate for your need.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736252520a52.html

最新回复(0)