PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.9.19.4
Pods – Custom Content Types and Fields v2.9.19.4
2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / components / Templates / includes / functions-pod_reference.php
pods / components / Templates / includes Last commit date
auto-template 2 weeks ago element-pod_reference.php 2 weeks ago element-view_template.php 2 weeks ago functions-pod_reference.php 2 weeks ago functions-view_template.php 2 weeks ago
functions-pod_reference.php
129 lines
1 <?php
2
3 add_action( 'wp_ajax_pq_loadpod', 'pq_loadpod' );
4
5 /**
6 * @param bool $podname
7 *
8 * @return array
9 */
10 function pq_loadpod( $podname = false ) {
11 if ( doing_action( 'wp_ajax_pq_loadpod' ) ) {
12 // This is the AJAX entry point; pq_loadpod() is also called server-side (see element-pod_reference-content.php).
13 check_ajax_referer( 'pods_pq_loadpod', 'nonce' );
14 }
15
16 if ( ! pods_is_admin() ) {
17 return pods_error( __( 'Unauthorized request', 'pods' ) );
18 }
19 if ( ! empty( $_POST['pod_reference']['pod'] ) ) {
20 $podname = $_POST['pod_reference']['pod'];
21 }
22 if ( ! empty( $_POST['pod'] ) ) {
23 $podname = $_POST['pod'];
24 }
25 $fields = array( __( 'No reference Pod selected', 'pods' ) );
26
27 if ( ! empty( $podname ) ) {
28 $fields = pq_recurse_pod_fields( $podname );
29 }
30 if ( ! empty( $_POST['pod_reference']['pod'] ) || ! empty( $_POST['pod'] ) ) {
31 header( 'Content-Type:application/json' );
32 echo json_encode( $fields );
33 die;
34 }
35
36 return $fields;
37 }
38
39 /**
40 * @param $pod_name
41 * @param string $prefix
42 * @param array $pods_visited
43 *
44 * @return array
45 */
46 function pq_recurse_pod_fields( $pod_name, $prefix = '', &$pods_visited = array() ) {
47
48 $fields = array();
49 if ( empty( $pod_name ) ) {
50 return $fields;
51 }
52
53 $pod = pods_get_instance( $pod_name );
54
55 if ( empty( $pod ) || ! $pod->valid() ) {
56 return $fields;
57 }
58
59 $recurse_queue = array();
60
61 $image_sizes = get_intermediate_image_sizes();
62 $media_fields = [
63 'title',
64 'caption',
65 'description',
66 'alt_text',
67 'width',
68 'height',
69 'filesize',
70 'filename',
71 'extension',
72 'mime_type',
73 ];
74
75 if ( post_type_supports( $pod_name, 'thumbnail' ) ) {
76 $fields[] = "{$prefix}post_thumbnail";
77 $fields[] = "{$prefix}post_thumbnail_url";
78
79 foreach ( $media_fields as $media_field ) {
80 $fields[] = "{$prefix}post_thumbnail.{$media_field}";
81 }
82
83 foreach ( $image_sizes as $image_size ) {
84 $fields[] = "{$prefix}post_thumbnail.{$image_size}";
85 $fields[] = "{$prefix}post_thumbnail_url.{$image_size}";
86 }
87 }
88
89 $pod_fields = $pod->fields();
90
91 foreach ( $pod_fields as $name => $field ) {
92 // Add base field name
93 $fields[] = $prefix . $name;
94
95 // Field type specific handling
96 if ( 'file' === $field['type'] && 'attachment' === $field['options']['file_uploader'] ) {
97 $fields[] = $prefix . $name . '._src';
98 $fields[] = $prefix . $name . '._img';
99
100 foreach ( $media_fields as $media_field ) {
101 $fields[] = "{$prefix}{$name}._img.{$media_field}";
102 }
103
104 foreach ( $image_sizes as $image_size ) {
105 $fields[] = "{$prefix}{$name}._src.{$image_size}";
106
107 if ( 'multi' !== $field['options']['file_format_type'] ) {
108 $fields[] = "{$prefix}{$name}._src_relative.{$image_size}";
109 $fields[] = "{$prefix}{$name}._src_schemeless.{$image_size}";
110 }
111
112 $fields[] = "{$prefix}{$name}._img.{$image_size}";
113 }
114 } elseif ( ! empty( $field['table_info'] ) && ! empty( $field['table_info']['pod'] ) ) {
115 $linked_pod = $field['table_info']['pod']['name'];
116 if ( ! isset( $pods_visited[ $linked_pod ] ) || ! in_array( $name, $pods_visited[ $linked_pod ], true ) ) {
117 $pods_visited[ $linked_pod ][] = $name;
118 $recurse_queue[ $linked_pod ] = "{$prefix}{$name}.";
119 }
120 }//end if
121 }//end foreach
122 foreach ( $recurse_queue as $recurse_name => $recurse_prefix ) {
123 $fields = array_merge( $fields, pq_recurse_pod_fields( $recurse_name, $recurse_prefix, $pods_visited ) );
124 }
125
126 return $fields;
127 }
128
129