将文本字符串附加到wp_enqueue_script

时间:2016-12-21 23:23:12

标签: php wordpress

因此,我可以使用WordPress管理区域中的文本框输入我的Google API密钥,而不是将其添加到代码中,我尝试附加文本字符串" $ options [' text_string& #39;]"到wp_enqueue_script;

wp_enqueue_script( $this->plugin_slug . '-gpstracker-google-maps', '//maps.googleapis.com/maps/api/js?libraries=places&key=' . $options['text_string'] , array(), self::VERSION  );

不幸的是我没有运气。文本字符串存储在选项表中,因为我已经使用PHP Myadmin检查了它。

此版本的脚本有效;

wp_enqueue_script( $this->plugin_slug . '-gpstracker-google-maps', '//maps.googleapis.com/maps/api/js?libraries=places&key=MyGoogleAPIKey', array(), self::VERSION );

感谢所有帮助。

更新

目前我正在尝试这仍然无效;

public function enqueue_scripts() { 
$gpl_key = get_option('gps_plotter_options');
wp_enqueue_script( $this->plugin_slug . '-gpstracker-google-maps', 'https://maps.googleapis.com/maps/api/js?' . $gpl_key . 'libraries=places', array(), self::VERSION  ); 
}  

1 个答案:

答案 0 :(得分:0)

您的选项密钥中有单引号可能导致问题,请用双引号替换单引号,如下所示:

import PouchDB from 'pouchdb-browser';
import PouchDBFind from 'pouchdb-find';
PouchDB.plugin(PouchDBFind);