You won’t be calling stuff directly from the functions.php
file by URL reference.
The functions.php
is loaded in with the WordPress theme and it makes functions available to you from within the theme template files.
Most of your code can be ported directly into the functions.php
but you will have to wrap some sort of interface around it which can be called within a page template.
If I were doing this I would likely put some PHP code in the index.php of the theme, right a the top to have a look at what’s in the $_REQUEST
object, like you do at the start of your PHP code.
Then, rather than execute the PHP you already have, you would call functions that are within your functions.php
file that deal with the actual DB connections and serving the file.
As you mentioned, you’ll have to use the $wpdb
global variable to read the tables and the good news is that because you’re working within the WordPress session, you don’t have to authenticate with the DB so no UN/PW info.
Your JS will be best served in a separate file within your theme and loaded into WordPress properly by using wp_enqueue_script
.