Does wordpress ignore foreign php code? I’m attempting to throw a function call in an external class below this line on root index.php of wordpress
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
Here is my function call
require_once($_SERVER['DOCUMENT_ROOT']."/modules/Site-Traffic/Site-Traffic.php");
//Create traffic object for tracking who is hitting this page
$site_traffic = new Site_Traffic();
$site_traffic->SetTrafficLog();
Here is what happens within this function.
- Sets the correct database, table, user name, password
- Checks the querystrings parameters for special cases to track in the function
- If the function sees a special parameter case it inserts it into a site-traffic table by creating a sql statement and then calling my
mysqliconnection library - The library then takes the sql statement, the database, table, username and password and inserts the site-traffic call into the
corresponding table.
I use this on all my pages outside of wordpress and it works fine and yet on the index.php page it does not work at all.
I’m able to echo out the sql statement, database, table, username and password from the wordpress index.php page so I know it is getting to that point.
EDITED: Made the issue more apparent and specific
Put this into a custom plugin or your theme’s functions.php.
Here’s how I’d go about it:
Create the following file (including directory): /your-wp-root/wp-content/plugins/wpse-site-traffic/wpse-site-traffic.php