First off I am very new to php so bear with me. I have a javascript (.js) file from a wordpress template that reads the key from var googledockey
. In order to change it I have to manually open the .js file and change that variable. What I would like to do is have the .js file grab the key from where it was saved on a page I made. Here is the code for the admin page that has the textfield for me to enter in a key.
<?php
if($_POST['gdocs2wp_hidden'] == 'Y') {
//Form data sent
$gdkey = $_POST['gdocs2wp_gdkey'];
update_option('gdocs2wp_gdkey', $gdkey);
?>
<div class="updated"><p><strong><?php _e('Options saved.' ); ?></strong></p></div>
<?php
} else {
//Normal page display
$gdkey = get_option('gdocs2wp_gdkey');
}
?>
The key saves and whenver I open the page they key shows up so I know this half is working. This is where I am stumped. Within my .js file which is in a subdirectory of the admin page, the var googledockey
is where I have had to manually save the key which works everytime. I have tried <?php echo $gdkey; ?>
and get_option('gdocs2wp_gdkey');
to try and get the key but I havent had any luck. Can php work within a .js file? Does anyone have any insight to help me along? Thanks
var jqueryNoConflict = jQuery;
//var googledockey = <?php echo $gdkey; ?>
var googledockey = "INSERTmyKEYhere";
// begin main function
jqueryNoConflict(document).ready(function(){
initializeTabletopObject(googledockey);
});