GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-plugin-hooks-acf.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Add Advanced Custom Fields customizations
4  *
5  * @file class-gravityview-plugin-hooks-acf.php
6  * @package GravityView
7  * @license GPL2+
8  * @author GravityView <[email protected]>
9  * @link http://gravityview.co
10  * @copyright Copyright 2015, Katz Web Services, Inc.
11  *
12  * @since 1.16.5
13  */
14 
15 /**
16  * @inheritDoc
17  * @since 1.16.5
18  */
20 
21  /**
22  * @inheritDoc
23  * @since 1.16.5
24  */
25  protected $function_name = 'acf';
26 
27  /**
28  * @since 1.22.2.1
29  */
30  protected $class_name = 'acf';
31 
32  /**
33  * @since 2.2
34  * @var array
35  */
36  protected $style_handles = array( 'acf-global' );
37 
38  /**
39  * @since 1.16.5
40  */
41  protected function add_hooks() {
42  parent::add_hooks();
43 
44  add_filter( 'gravityview/view_collection/from_post/meta_keys', array( $this, 'add_meta_keys_from_post' ), 10, 2 );
45 
46  $this->fix_posted_fields();
47  }
48 
49  /**
50  * @param array $meta_keys Existing meta keys to parse for [gravityview] shortcode
51  * @param \WP_Post $post Current post ID
52  *
53  * @return array
54  */
55  function add_meta_keys_from_post( $meta_keys = array(), $post = null ) {
56 
57  // Can never be too careful: double-check that ACF is active and the function exists
58  if ( ! function_exists( 'get_field_objects' ) ) {
59  return $meta_keys;
60  }
61 
62  $acf_keys = get_field_objects( $post->ID, array( 'load_value' => false ) );
63 
64  if( $acf_keys ) {
65  return array_merge( array_keys( $acf_keys ), $meta_keys );
66  }
67 
68  return $meta_keys;
69  }
70 
71  /**
72  * ACF needs $_POST['fields'] to be an array. GV supports both serialized array and array, so we just process earlier.
73  *
74  * @since 1.16.5
75  *
76  * @return void
77  */
78  private function fix_posted_fields() {
79  if( is_admin() && isset( $_POST['action'] ) && isset( $_POST['post_type'] ) ) {
80  if( 'editpost' === $_POST['action'] && 'gravityview' === $_POST['post_type'] ) {
81  $_POST['fields'] = _gravityview_process_posted_fields();
82  }
83  }
84  }
85 }
86 
add_meta_keys_from_post( $meta_keys=array(), $post=null)
global $post
Definition: delete-entry.php:7
$meta_keys
Define the keys to be parsed by the gravityview/data/parse/meta_keys hook.
fix_posted_fields()
ACF needs $_POST[&#39;fields&#39;] to be an array.
_gravityview_process_posted_fields()
Maybe convert jQuery-serialized fields into array, otherwise return $_POST[&#39;fields&#39;] array...
Abstract class that makes it easy for plugins and themes to register no-conflict scripts and styles...