acf_qtranslate_acf_5

The Advanced Custom Fields: qTranslate acf qtranslate 5 class.

Defined (1)

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

/src/acf_5/acf.php  
  1. class acf_qtranslate_acf_5 implements acf_qtranslate_acf_interface { 
  2.  
  3. /** 
  4. * The plugin instance. 
  5. * @var \acf_qtranslate_plugin 
  6. */ 
  7. protected $plugin; 
  8.  
  9.  
  10. /** 
  11. * Create an instance. 
  12. * @return void 
  13. */ 
  14. public function __construct($plugin) { 
  15. $this->plugin = $plugin; 
  16.  
  17. add_filter('acf/format_value', array($this, 'format_value')); 
  18. add_action('acf/include_fields', array($this, 'include_fields')); 
  19. add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); 
  20.  
  21. /** 
  22. * Load javascript and stylesheets on admin pages. 
  23. */ 
  24. public function include_fields() { 
  25. require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/file.php'; 
  26. require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/image.php'; 
  27. require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/text.php'; 
  28. require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/textarea.php'; 
  29. require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/wysiwyg.php'; 
  30.  
  31. new acf_qtranslate_acf_5_text($this->plugin); 
  32. new acf_qtranslate_acf_5_textarea($this->plugin); 
  33. new acf_qtranslate_acf_5_wysiwyg($this->plugin); 
  34. new acf_qtranslate_acf_5_image($this->plugin); 
  35. new acf_qtranslate_acf_5_file($this->plugin); 
  36.  
  37. /** 
  38. * Load javascript and stylesheets on admin pages. 
  39. */ 
  40. public function admin_enqueue_scripts() { 
  41. wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/acf_5/main.js', ACF_QTRANSLATE_PLUGIN), array('acf-input', 'underscore')); 
  42.  
  43. /** 
  44. * This filter is applied to the $value after it is loaded from the db and 
  45. * before it is returned to the template via functions such as get_field(). 
  46. */ 
  47. public function format_value($value) { 
  48. if (is_string($value)) { 
  49. $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value); 
  50. return $value; 
  51.  
  52. /** 
  53. * Get the visible ACF fields. 
  54. * @return array 
  55. */ 
  56. public function get_visible_acf_fields($widget_id = null) { 
  57. global $wp_registered_widgets; 
  58.  
  59. $visible_fields = array(); 
  60.  
  61. // build field group filters required for current screen 
  62. $filter = $this->get_acf_field_group_filters(); 
  63. if (count($filter) === 0) { 
  64. return $visible_fields; 
  65.  
  66. // widgets need some special handling since they 
  67. // require multiple acf_get_field_group_visibility() 
  68. // calls in order to return all the visible fields 
  69. if (acf_is_screen('widgets') || acf_is_screen('customize')) { 
  70. if ($widget_id) { 
  71. $filter['widget'] = _get_widget_id_base($widget_id); 
  72. else { 
  73. // process each widget form individually for any visible fields 
  74. foreach ($wp_registered_widgets as $widget) { 
  75. $visible_fields += $this->get_visible_acf_fields($widget['id']); 
  76. return $visible_fields; 
  77.  
  78. $supported_field_types = array( 
  79. 'email',  
  80. 'text',  
  81. 'textarea',  
  82. 'repeater',  
  83. 'flexible_content',  
  84. 'qtranslate_file',  
  85. 'qtranslate_image',  
  86. 'qtranslate_text',  
  87. 'qtranslate_textarea',  
  88. 'qtranslate_wysiwyg' 
  89. ); 
  90.  
  91. foreach (acf_get_field_groups($filter) as $field_group) { 
  92. $fields = acf_get_fields($field_group); 
  93. foreach ($fields as $field) { 
  94. if (in_array($field['type'], $supported_field_types)) { 
  95. $visible_fields[] = array('id' => 'acf-' . $field['key']); 
  96.  
  97. return $visible_fields; 
  98.  
  99. /** 
  100. * Get field group filters based on active screen. 
  101. */ 
  102. public function get_acf_field_group_filters() { 
  103. global $post, $pagenow, $typenow, $plugin_page; 
  104.  
  105. $filter = array(); 
  106. if ($pagenow === 'post.php' || $pagenow === 'post-new.php') { 
  107. if ($typenow !== 'acf') { 
  108. $filter['post_id'] = $post->ID; 
  109. $filter['post_type'] = $typenow; 
  110. elseif ($pagenow === 'admin.php' && isset($plugin_page)) { 
  111. if (acf_get_options_page($plugin_page)) { 
  112. $filter['post_id'] = acf_get_valid_post_id('options'); 
  113. elseif ($pagenow === 'edit-tags.php' && isset($_GET['taxonomy'])) { 
  114. $filter['taxonomy'] = filter_var($_GET['taxonomy'], FILTER_SANITIZE_STRING); 
  115. elseif ($pagenow === 'profile.php') { 
  116. $filter['user_id'] = get_current_user_id(); 
  117. $filter['user_form'] = 'edit'; 
  118. elseif ($pagenow === 'user-edit.php' && isset($_GET['user_id'])) { 
  119. $filter['user_id'] = filter_var($_GET['user_id'], FILTER_SANITIZE_NUMBER_INT); 
  120. $filter['user_form'] = 'edit'; 
  121. elseif ($pagenow === 'user-new.php') { 
  122. $filter['user_id'] = 'new'; 
  123. $filter['user_form'] = 'edit'; 
  124. elseif ($pagenow === 'media.php' || $pagenow === 'upload.php') { 
  125. $filter['attachment'] = 'All'; 
  126. elseif (acf_is_screen('widgets') || acf_is_screen('customize')) { 
  127. $filter['widget'] = 'all'; 
  128.  
  129. return $filter; 
  130.