1 | <?php |
||
3 | class ACFTimber { |
||
4 | |||
5 | function __construct() { |
||
|
|||
6 | add_filter( 'timber_post_get_meta', array( $this, 'post_get_meta' ), 10, 2 ); |
||
7 | add_filter( 'timber_post_get_meta_field', array( $this, 'post_get_meta_field' ), 10, 3 ); |
||
8 | add_filter( 'timber_term_get_meta', array( $this, 'term_get_meta' ), 10, 3 ); |
||
9 | add_filter( 'timber_term_get_meta_field', array( $this, 'term_get_meta_field' ), 10, 4 ); |
||
10 | add_filter( 'timber_user_get_meta_field_pre', array( $this, 'user_get_meta_field' ), 10, 3 ); |
||
11 | add_filter( 'timber_term_set_meta', array( $this, 'term_set_meta'), 10, 4 ); |
||
12 | } |
||
13 | |||
14 | function post_get_meta( $customs, $post_id ) { |
||
17 | |||
18 | function post_get_meta_field( $value, $post_id, $field_name ) { |
||
21 | |||
22 | function term_get_meta_field( $value, $term_id, $field_name, $term ) { |
||
26 | |||
27 | function term_set_meta( $value, $field, $term_id, $term ) { |
||
28 | $searcher = $term->taxonomy . "_" . $term->ID; |
||
29 | update_field( $field, $value, $searcher ); |
||
30 | return $value; |
||
31 | } |
||
32 | |||
33 | function term_get_meta( $fields, $term_id, $term ) { |
||
34 | $searcher = $term->taxonomy . "_" . $term->ID; // save to a specific category |
||
35 | $fds = get_fields( $searcher ); |
||
36 | if ( is_array( $fds ) ) { |
||
37 | foreach ( $fds as $key => $value ) { |
||
38 | $key = preg_replace( '/_/', '', $key, 1 ); |
||
39 | $key = str_replace( $searcher, '', $key ); |
||
40 | $key = preg_replace( '/_/', '', $key, 1 ); |
||
41 | $field = get_field( $key, $searcher ); |
||
42 | $fields[$key] = $field; |
||
43 | } |
||
44 | $fields = array_merge( $fields, $fds ); |
||
45 | } |
||
46 | return $fields; |
||
47 | } |
||
48 | |||
49 | function user_get_meta( $fields, $user_id ) { |
||
52 | |||
53 | function user_get_meta_field( $value, $uid, $field ) { |
||
56 | } |
||
57 | |||
58 | |||
59 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.