Changeset 2132610
- Timestamp:
- 08/02/2019 08:35:03 AM (6 years ago)
- Location:
- template-dictionary/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (3 diffs)
-
template-dictionary.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
template-dictionary/trunk/readme.txt
r2115677 r2132610 4 4 Requires at least: 4.5 5 5 Tested up to: 5.2.2 6 Stable tag: 1. 56 Stable tag: 1.6 7 7 License: GPL2 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 51 51 If your site is not multilingual, there is only one available language – the default language. 52 52 53 = Use JS object = 54 To generate JavaScript dictionary object, you need to define `TMPL_DICT_JS_VAR_NAME` constant. Add to `wp_config.php`: 55 56 `define( 'TMPL_DICT_JS_VAR_NAME', 'dict' );` 57 58 Then you can use it in JS: 59 60 `$('#some-element').text( dict.the_code );` 61 53 62 == Screenshots == 54 63 … … 61 70 62 71 == Changelog == 72 = 1.6 = 73 * Added method to get whole dictionary array. 74 * Added JS dictionary object. 63 75 64 76 = 1.5 = -
template-dictionary/trunk/template-dictionary.php
r1830393 r2132610 3 3 * Plugin Name: Template Dictionary 4 4 * Description: A plugin for developers which provides template variables dictionary editable in backend. 5 * Version: 1. 55 * Version: 1.6 6 6 * Author: Radovan Kneblík 7 7 * License: GPL2 … … 24 24 * @var string 25 25 */ 26 private $version = '1. 4';26 private $version = '1.6'; 27 27 28 28 /** … … 122 122 add_action( 'plugins_loaded', array( $this, 'load_language' ), 5 ); 123 123 add_action( 'plugins_loaded', array( $this, 'load' ), 9 ); 124 if( defined( 'TMPL_DICT_JS_VAR_NAME' ) ){ 125 add_action( 'wp_head', array( $this, 'js_dictionary' ) ); 126 } 124 127 125 128 add_shortcode( 'tmpl_dict', array( $this, 'shortcode' ) ); … … 196 199 * Get the plugin's database table(s). 197 200 * @param string|null $key 198 * @return string 201 * @return string|array 199 202 */ 200 203 public function db_tables( $key = null ){ … … 337 340 338 341 /** 342 * Get the whole dictionary array. 343 * @return array 344 */ 345 public function get_dictionary(){ 346 return $this->dictionary; 347 } 348 349 /** 339 350 * The shortcode function. 340 351 */ … … 365 376 return $value; 366 377 } 378 } 379 380 /** 381 * Create JS object. 382 */ 383 public function js_dictionary(){ ?> 384 <script type="text/javascript"> 385 /* <![CDATA[ */ 386 var <?php echo TMPL_DICT_JS_VAR_NAME; ?> = <?php echo json_encode( $this->get_dictionary() ); ?>; 387 /* ]]> */ 388 </script><?php 367 389 } 368 390
Note: See TracChangeset
for help on using the changeset viewer.