acf_qtranslate_qtranslatex

The Advanced Custom Fields: qTranslate acf qtranslate qtranslatex class.

Defined (1)

The class is defined in the following location(s).

/src/qtranslatex.php  
  1. class acf_qtranslate_qtranslatex { 
  2.  
  3. /** 
  4. * An ACF instance. 
  5. * @var \acf_qtranslate_acf_interface 
  6. */ 
  7. protected $acf; 
  8.  
  9. /** 
  10. * The plugin instance. 
  11. * @var \acf_qtranslate_plugin 
  12. */ 
  13. protected $plugin; 
  14.  
  15.  
  16. /** 
  17. * Create an instance. 
  18. * @return void 
  19. */ 
  20. public function __construct(acf_qtranslate_plugin $plugin, acf_qtranslate_acf_interface $acf) { 
  21. $this->acf = $acf; 
  22. $this->plugin = $plugin; 
  23.  
  24. // include compatibility functions 
  25. require_once ACF_QTRANSLATE_PLUGIN_DIR . 'compatibility/qtranslatex.php'; 
  26.  
  27. add_action('admin_head', array($this, 'admin_head')); 
  28. add_filter('qtranslate_custom_admin_js', array($this, 'qtranslate_custom_admin_js')); 
  29. add_filter('acf_qtranslate_get_active_language', array($this, 'get_active_language')); 
  30. add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); 
  31.  
  32. /** 
  33. * Add additional styles and scripts to head. 
  34. */ 
  35. public function admin_head() { 
  36. // Hide the language tabs if they shouldn't be displayed 
  37. $show_language_tabs = $this->plugin->get_plugin_setting('show_language_tabs'); 
  38. if (!$show_language_tabs) { 
  39. ?> 
  40. <style> 
  41. .multi-language-field {margin-top:0!important;} 
  42. .multi-language-field .wp-switch-editor[data-language] {display:none!important;} 
  43. </style> 
  44. <?php 
  45.  
  46. // Enable translation of standard field types 
  47. $translate_standard_field_types = $this->plugin->get_plugin_setting('translate_standard_field_types'); 
  48. if ($translate_standard_field_types) { 
  49. ?> 
  50. <script> 
  51. var acf_qtranslate_translate_standard_field_types = <?= json_encode($translate_standard_field_types) ?>; 
  52. </script> 
  53. <?php 
  54.  
  55. /** 
  56. * Load javascript and stylesheets on admin pages. 
  57. */ 
  58. public function admin_enqueue_scripts() { 
  59. $version = $this->plugin->acf_major_version(); 
  60. wp_enqueue_script('acf_qtranslatex', plugins_url("/assets/acf_{$version}/qtranslatex.js", ACF_QTRANSLATE_PLUGIN), array('acf_qtranslate_common')); 
  61.  
  62. /** 
  63. * Use the edit-post script on admin pages. 
  64. * @return string 
  65. */ 
  66. public function qtranslate_custom_admin_js() { 
  67. global $pagenow, $plugin_page; 
  68.  
  69. if ($pagenow === 'admin.php' && isset($plugin_page)) { 
  70. return 'admin/js/edit-post'; 
  71.  
  72. /** 
  73. * Get the active language. 
  74. */ 
  75. public function get_active_language($language) { 
  76. if (empty($_COOKIE['qtrans_edit_language']) === false) { 
  77. $enabledLanguages = qtrans_getSortedLanguages(); 
  78. if (in_array($_COOKIE['qtrans_edit_language'], $enabledLanguages)) { 
  79. $language = $_COOKIE['qtrans_edit_language']; 
  80. return $language; 
  81.