Php 将文本字符串追加到wp_enqueue_脚本
为了通过使用WordPress管理区域中的文本框输入我的Google API密钥,而不是将其添加到代码中,我尝试将文本字符串“$options['text\u string']”附加到wp\u enqueue\u脚本中Php 将文本字符串追加到wp_enqueue_脚本,php,wordpress,Php,Wordpress,为了通过使用WordPress管理区域中的文本框输入我的Google API密钥,而不是将其添加到代码中,我尝试将文本字符串“$options['text\u string']”附加到wp\u enqueue\u脚本中 wp_enqueue_script( $this->plugin_slug . '-gpstracker-google-maps', '//maps.googleapis.com/maps/api/js?libraries=places&key=' . $optio
wp_enqueue_script( $this->plugin_slug . '-gpstracker-google-maps', '//maps.googleapis.com/maps/api/js?libraries=places&key=' . $options['text_string'] , 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 );
}
不幸的是,我没有任何运气。文本字符串存储在options表中,因为我已经用PHP Myadmin检查过它
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 );
}
这个版本的剧本很管用
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 );
}
感谢所有的帮助
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 );
}
更新
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 );
}
目前我正在尝试这个仍然不起作用
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 );
}
您的选项键中有单引号,因此可能导致问题,tyr将单引号替换为双引号,如下所示:
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 );
}
wp_enqueue_script( $this->plugin_slug.'-gpstracker-google-maps', '//maps.googleapis.com/maps/api/js?libraries=places&key='.$options["text_string"][0] , array(), self::VERSION );
在$options之后添加句点有效吗<代码>wp_enqueue_脚本($this->plugin_slug.'-gpstracker google maps','//maps.googleapis.com/maps/api/js?libraries=places&key='。$options['text_string',array(),self::VERSION)代码>很遗憾,这会导致语法错误。能否显示$options变量中存储的值??您确定$options[“text_string”]不是字符串数组吗?请发布$options变量的内容。嗨,亚木。进一步研究后,我认为$options[“text_string”]实际上是一个数组。如果是这样的话,您有什么建议吗?我已经编辑了上面的代码以从数组中获取值。(假设数组的第一个元素是所需的文本)。如果不起作用,请发布var_dump($options[“text_string”])值,并相应地更改代码。