acf_qtranslate_acf_5_wysiwyg

The Advanced Custom Fields: qTranslate acf qtranslate 5 wysiwyg class.

Defined (1)

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

/src/acf_5/fields/wysiwyg.php  
  1. class acf_qtranslate_acf_5_wysiwyg extends acf_field_wysiwyg { 
  2.  
  3. /** 
  4. * The plugin instance. 
  5. * @var \acf_qtranslate_plugin 
  6. */ 
  7. protected $plugin; 
  8.  
  9.  
  10. /** 
  11. * __construct 
  12. * This function will setup the field type data 
  13. * @type function 
  14. * @date 5/03/2014 
  15. * @since 5.0.0 
  16. * @param n/a 
  17. * @return n/a 
  18. */ 
  19. function __construct($plugin) { 
  20. $this->plugin = $plugin; 
  21.  
  22. $this->name = 'qtranslate_wysiwyg'; 
  23. $this->label = __("Wysiwyg Editor", 'acf'); 
  24. $this->category = __("qTranslate", 'acf'); 
  25. $this->defaults = array( 
  26. 'tabs' => 'all',  
  27. 'toolbar' => 'full',  
  28. 'media_upload' => 1,  
  29. 'default_value' => '',  
  30. ); 
  31.  
  32. // Create an acf version of the_content filter (acf_the_content) 
  33. if( !empty($GLOBALS['wp_embed']) ) { 
  34. add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 ); 
  35. add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 ); 
  36.  
  37. add_filter( 'acf_the_content', 'capital_P_dangit', 11 ); 
  38. add_filter( 'acf_the_content', 'wptexturize' ); 
  39. add_filter( 'acf_the_content', 'convert_smilies' ); 
  40. add_filter( 'acf_the_content', 'convert_chars' ); 
  41. add_filter( 'acf_the_content', 'wpautop' ); 
  42. add_filter( 'acf_the_content', 'shortcode_unautop' ); 
  43. add_filter( 'acf_the_content', 'prepend_attachment' ); 
  44. add_filter( 'acf_the_content', 'do_shortcode', 11); 
  45.  
  46. // actions 
  47. add_action('acf/input/admin_footer_js', array($this, 'input_admin_footer_js')); 
  48.  
  49. acf_field::__construct(); 
  50.  
  51. /** 
  52. * render_field() 
  53. * Create the HTML interface for your field 
  54. * @param $field - an array holding all the field's data 
  55. * @type action 
  56. * @since 3.6 
  57. * @date 23/01/13 
  58. */ 
  59. function render_field($field) { 
  60.  
  61. // enqueue 
  62. acf_enqueue_uploader(); 
  63.  
  64. // vars 
  65. $id = uniqid('acf-editor-'); 
  66. //$id = $field['id'] . '-' . uniqid(); 
  67. $mode = 'html'; 
  68. $show_tabs = true; 
  69.  
  70. // get height 
  71. $height = acf_get_user_setting('wysiwyg_height', 300); 
  72. $height = max( $height, 300 ); // minimum height is 300 
  73.  
  74. // detect mode 
  75. // case: visual tab only 
  76. if ($field['tabs'] == 'visual') { 
  77. $mode = 'tmce'; 
  78. $show_tabs = false; 
  79. // case: text tab only 
  80. elseif ($field['tabs'] == 'text') { 
  81. $show_tabs = false; 
  82. // case: both tabs 
  83. elseif (wp_default_editor() == 'tinymce') { 
  84. $mode = 'tmce'; 
  85.  
  86. // mode 
  87. $switch_class = $mode . '-active'; 
  88.  
  89. // filter value for editor 
  90. remove_all_filters('acf_the_editor_content'); 
  91.  
  92. if ($mode == 'tmce') { 
  93. add_filter('acf_the_editor_content', 'wp_richedit_pre'); 
  94. else { 
  95. add_filter('acf_the_editor_content', 'wp_htmledit_pre'); 
  96.  
  97. global $q_config, $wp_version; 
  98. $languages = qtrans_getSortedLanguages(true); 
  99. $values = qtrans_split($field['value'], $quicktags = true); 
  100. $currentLanguage = $this->plugin->get_active_language(); 
  101.  
  102. echo '<div class="multi-language-field multi-language-field-wysiwyg">'; 
  103.  
  104. foreach ($languages as $language) { 
  105. $class = ($language === $currentLanguage) ? 'wp-switch-editor current-language' : 'wp-switch-editor'; 
  106. echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>'; 
  107.  
  108. $uid = uniqid('acf-editor-'); 
  109. foreach ($languages as $language): 
  110. $value = apply_filters('acf_the_editor_content', $values[$language]); 
  111. $id = $uid . "-$language"; 
  112. $name = $field['name'] . "[$language]"; 
  113. $class = $switch_class; 
  114. if ($language === $currentLanguage) { 
  115. $class .= ' current-language'; 
  116.  
  117. ?> 
  118. <div id="wp-<?php echo $id; ?>-wrap" class="acf-editor-wrap wp-core-ui wp-editor-wrap <?php echo $class; ?>" data-toolbar="<?php echo $field['toolbar']; ?>" data-upload="<?php echo $field['media_upload']; ?>" data-language="<?php echo $language; ?>"> 
  119. <div id="wp-<?php echo $id; ?>-editor-tools" class="wp-editor-tools hide-if-no-js"> 
  120. <?php if( $field['media_upload'] ): ?> 
  121. <div id="wp-<?php echo $id; ?>-media-buttons" class="wp-media-buttons"> 
  122. <?php do_action( 'media_buttons' ); ?> 
  123. </div> 
  124. <?php endif; ?> 
  125. <?php if( user_can_richedit() && $show_tabs ): ?> 
  126. <div class="wp-editor-tabs"> 
  127. <button id="<?php echo $id; ?>-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);" type="button"><?php echo __('Visual', 'acf'); ?></button> 
  128. <button id="<?php echo $id; ?>-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);" type="button"><?php echo _x( 'Text', 'Name for the Text editor tab (formerly HTML)', 'acf' ); ?></button> 
  129. </div> 
  130. <?php endif; ?> 
  131. </div> 
  132. <div id="wp-<?php echo $id; ?>-editor-container" class="wp-editor-container"> 
  133. <textarea id="<?php echo $id; ?>" class="qtx-wp-editor-area" name="<?php echo $name; ?>" <?php if($height): ?>style="height:<?php echo $height; ?>px;"<?php endif; ?>><?php echo $value; ?></textarea> 
  134. </div> 
  135. </div> 
  136.  
  137. <?php endforeach; 
  138.  
  139. echo '</div>'; 
  140.  
  141. /** 
  142. * update_value() 
  143. * This filter is appied to the $value before it is updated in the db 
  144. * @type filter 
  145. * @since 3.6 
  146. * @date 23/01/13 
  147. * @param $value - the value which will be saved in the database 
  148. * @param $post_id - the $post_id of which the value will be saved 
  149. * @param $field - the field array holding all the field options 
  150. * @return $value - the modified value 
  151. */ 
  152. function update_value($value, $post_id, $field) { 
  153. return qtrans_join($value); 
  154.