2016-12-21 5 views
2

コードに追加するのではなく、WordPress管理領域のテキストボックスを使用してGoogle APIキーを入力できるように、テキスト文字列に "$ options ['text_string ']」をwp_enqueue_scriptに設定します。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でチェックしたので、テキスト文字列はoptionsテーブルに格納されています。

このスクリプトのこのバージョンは機能します。

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 ); 
} 
+0

は$オプションが動作した後の期間を加算していますか? 'wp_enqueue_script($ this-> plugin_slug。 '-gpstracker-google-maps'、 '//maps.googleapis.com/maps/api/js?libraries=places&key='。$ options ['text_string']。、配列)、self :: VERSION); ' – oompahlumpa

+0

残念ながら、これは構文エラーを引き起こします。 – stpetedesign

答えて

0

それは以下のように二重引用符で単一引用符を置き換えるTYR、問題を引き起こしている可能性のように、あなたはあなたのオプションキーで単一引用符を持っている:

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 ); 
+0

私はこれを試しましたが、まだ動作していません。 – stpetedesign

+0

$ options変数に格納されている値を表示できますか? $ options ["text_string"]は配列ではないことを確認してください。 $ options変数の内容を投稿してください。 – Yamu

+0

こんにちは。さらにそれを調べたところ、$ options ["text_string"]は実際には配列であると信じています。そのような場合は、何か提案がありますか? – stpetedesign

関連する問題