← All changes
|
integrations/advanced-custom-fields/includes/functions.php
+97
-0
5.7.6
→
6.0.3
View file →
| @@ -1,0 +1,97 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Functions | |
| 4 | + * | |
| 5 | + * @package AutomatorWP\Advance_Custom_Fields\Functions | |
| 6 | + * @since 1.0.0 | |
| 7 | + */ | |
| 8 | +// Exit if accessed directly | |
| 9 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * Get acf fields related to posts | |
| 13 | + * | |
| 14 | + * @since 1.0.0 | |
| 15 | + * | |
| 16 | + * @return array | |
| 17 | + */ | |
| 18 | +function automatorwp_advanced_custom_fields_options_cb_fields_posts( ) { | |
| 19 | + | |
| 20 | + $options = array( | |
| 21 | + 'any' => __( 'any field', 'automatorwp-advanced-custom-fields' ), | |
| 22 | + ); | |
| 23 | + | |
| 24 | + // Get all post types | |
| 25 | + $all_post_types = automatorwp_advanced_custom_fields_get_post_types_field_groups( 'post' ); | |
| 26 | + | |
| 27 | + foreach( $all_post_types as $group ) { | |
| 28 | + | |
| 29 | + // Get fields from group | |
| 30 | + $all_acf_fields = acf_get_fields( $group['ID'] ); | |
| 31 | + | |
| 32 | + foreach ( $all_acf_fields as $acf_fields ){ | |
| 33 | + | |
| 34 | + $options[$acf_fields['name']] = $acf_fields['label']; | |
| 35 | + } | |
| 36 | + | |
| 37 | + } | |
| 38 | + | |
| 39 | + return $options; | |
| 40 | + | |
| 41 | +} | |
| 42 | + | |
| 43 | +/** | |
| 44 | +* Get all post field groups | |
| 45 | +* | |
| 46 | +* @return array | |
| 47 | +*/ | |
| 48 | +function automatorwp_advanced_custom_fields_get_post_types_field_groups( $post_type ) { | |
| 49 | + | |
| 50 | + if ( ! function_exists( 'acf_get_field_groups' ) ) { | |
| 51 | + return array(); | |
| 52 | + } | |
| 53 | + | |
| 54 | + $groups_post = array(); | |
| 55 | + | |
| 56 | + switch ( $post_type ){ | |
| 57 | + case 'post': | |
| 58 | + $groups_types = array( | |
| 59 | + 'post_type', | |
| 60 | + 'post_template', | |
| 61 | + 'post_status', | |
| 62 | + 'post_format', | |
| 63 | + 'post_category', | |
| 64 | + 'post_taxonomy', | |
| 65 | + 'post', | |
| 66 | + ); | |
| 67 | + break; | |
| 68 | + } | |
| 69 | + | |
| 70 | + $groups = acf_get_field_groups(); | |
| 71 | + | |
| 72 | + foreach ( $groups as $group ) { | |
| 73 | + | |
| 74 | + if ( ! empty( $group['location'] ) ) { | |
| 75 | + | |
| 76 | + foreach ( $group['location'] as $locations ) { | |
| 77 | + | |
| 78 | + foreach ( $locations as $location ) { | |
| 79 | + | |
| 80 | + if ( ! in_array( $location['param'], $groups_types )) { | |
| 81 | + continue; | |
| 82 | + | |
| 83 | + } else { | |
| 84 | + $groups_post[] = $group; | |
| 85 | + } | |
| 86 | + | |
| 87 | + } | |
| 88 | + | |
| 89 | + } | |
| 90 | + | |
| 91 | + } | |
| 92 | + | |
| 93 | + } | |
| 94 | + | |
| 95 | + return $groups_post; | |
| 96 | + | |
| 97 | +} | |