acf_qtranslate_acf_4

The Advanced Custom Fields: qTranslate acf qtranslate 4 class.

Defined (1)

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

/src/acf_4/acf.php  
  1. class acf_qtranslate_acf_4 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_for_api', array($this, 'format_value_for_api')); 
  18. add_action('acf/register_fields', array($this, 'register_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 register_fields() { 
  25. require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_4/fields/file.php'; 
  26. require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_4/fields/image.php'; 
  27. require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_4/fields/text.php'; 
  28. require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_4/fields/textarea.php'; 
  29. require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_4/fields/wysiwyg.php'; 
  30.  
  31. new acf_qtranslate_acf_4_text($this->plugin); 
  32. new acf_qtranslate_acf_4_textarea($this->plugin); 
  33. new acf_qtranslate_acf_4_wysiwyg($this->plugin); 
  34. new acf_qtranslate_acf_4_image($this->plugin); 
  35. new acf_qtranslate_acf_4_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_4/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_for_api($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() { 
  57. $visible_fields = array(); 
  58.  
  59. // build field group filters required for current screen 
  60. $filter = $this->get_acf_field_group_filters(); 
  61. if (count($filter) === 0) { 
  62. return $visible_fields; 
  63.  
  64. $supported_field_types = array( 
  65. 'email',  
  66. 'text',  
  67. 'textarea',  
  68. 'repeater',  
  69. 'flexible_content',  
  70. 'qtranslate_file',  
  71. 'qtranslate_image',  
  72. 'qtranslate_text',  
  73. 'qtranslate_textarea',  
  74. 'qtranslate_wysiwyg' 
  75. ); 
  76.  
  77. $visible_field_groups = apply_filters('acf/location/match_field_groups', array(), $filter); 
  78.  
  79. foreach (apply_filters('acf/get_field_groups', array()) as $field_group) { 
  80. if (in_array($field_group['id'], $visible_field_groups)) { 
  81. $fields = apply_filters('acf/field_group/get_fields', array(), $field_group['id']); 
  82. foreach ($fields as $field) { 
  83. if (in_array($field['type'], $supported_field_types)) { 
  84. $visible_fields[] = array('id' => $field['id']); 
  85.  
  86. return $visible_fields; 
  87.  
  88. /** 
  89. * Get field group filters based on active screen. 
  90. */ 
  91. public function get_acf_field_group_filters() { 
  92. global $post, $pagenow, $typenow, $plugin_page; 
  93.  
  94. $filter = array(); 
  95. if ($pagenow === 'post.php' || $pagenow === 'post-new.php') { 
  96. if ($typenow !== 'acf') { 
  97. $filter['post_id'] = apply_filters('acf/get_post_id', false); 
  98. $filter['post_type'] = $typenow; 
  99. elseif ($pagenow === 'admin.php' && isset($plugin_page)) { 
  100. if ($this->acf_get_options_page($plugin_page)) { 
  101. $filter['post_id'] = apply_filters('acf/get_post_id', false); 
  102. elseif ($pagenow === 'edit-tags.php' && isset($_GET['taxonomy'])) { 
  103. $filter['ef_taxonomy'] = filter_var($_GET['taxonomy'], FILTER_SANITIZE_STRING); 
  104. elseif ($pagenow === 'profile.php') { 
  105. $filter['ef_user'] = get_current_user_id(); 
  106. elseif ($pagenow === 'user-edit.php' && isset($_GET['user_id'])) { 
  107. $filter['ef_user'] = filter_var($_GET['user_id'], FILTER_SANITIZE_NUMBER_INT); 
  108. elseif ($pagenow === 'user-new.php') { 
  109. $filter['ef_user'] = 'all'; 
  110. elseif ($pagenow === 'media.php' || $pagenow === 'upload.php') { 
  111. $filter['post_type'] = 'attachment'; 
  112.  
  113. return $filter; 
  114.  
  115. /** 
  116. * Get details about ACF Options page. 
  117. */ 
  118. public function acf_get_options_page($slug) { 
  119. global $acf_options_page; 
  120.  
  121. if (!is_object($acf_options_page) || !is_array($acf_options_page->settings)) { 
  122. return false; 
  123.  
  124. if ($acf_options_page->settings['slug'] === $slug) { 
  125. return array( 
  126. 'title' => $acf_options_page->settings['title'],  
  127. 'menu' => $acf_options_page->settings['menu'],  
  128. 'slug' => $acf_options_page->settings['slug'],  
  129. 'capability' => $acf_options_page->settings['capability'],  
  130. 'show_parent' => $acf_options_page->settings['show_parent'],  
  131. ); 
  132.  
  133. foreach ($acf_options_page->settings['pages'] as $page) { 
  134. if ($page['slug'] === $slug) { 
  135. return $page; 
  136.