",'',""].join("")},render:function(){var t=this.get("title"),e=this.get("content"),i=this.get("loading"),n=this.get("width"),a=this.get("height");this.title(t),this.content(e),n&&this.$(".acf-popup-box").css("width",n),a&&this.$(".acf-popup-box").css("min-height",a),this.loading(i),acf.doAction("append",this.$el)},update:function(t){this.data=acf.parseArgs(t,this.data),this.render()},title:function(t){this.$(".title:first h3").html(t)},content:function(t){this.$(".inner:first").html(t)},loading:function(t){var e=this.$(".loading:first");t?e.show():e.hide()},open:function(){$("body").append(this.$el)},close:function(){this.remove()},onClickClose:function(t,e){t.preventDefault(),this.close()}}),acf.newPopup=function(t){return new acf.models.Popup(t)}}(jQuery),function($,t){acf.unload=new acf.Model({wait:"load",active:!0,changed:!1,actions:{change_field:"startListening",validation_failure:"startListening"},events:{"submit form":"stopListening"},reset:function(){this.stopListening()},startListening:function(){!this.changed&&this.active&&(this.changed=!0,$(window).on("beforeunload",this.onUnload))},stopListening:function(){this.changed=!1,$(window).off("beforeunload",this.onUnload)},onUnload:function(){return acf.__("The changes you made will be lost if you navigate away from this page")}})}(jQuery),function($,t){var e=new acf.Model({events:{"click .acf-panel-title":"onClick"},onClick:function(t,e){t.preventDefault(),this.toggle(e.parent())},isOpen:function(t){return t.hasClass("-open")},toggle:function(t){this.isOpen(t)?this.close(t):this.open(t)},open:function(t){t.addClass("-open"),t.find(".acf-panel-title i").attr("class","dashicons dashicons-arrow-down")},close:function(t){t.removeClass("-open"),t.find(".acf-panel-title i").attr("class","dashicons dashicons-arrow-right")}})}(jQuery),function($,t){var e=acf.Model.extend({data:{text:"",type:"",timeout:0,dismiss:!0,target:!1,close:function(){}},events:{"click .acf-notice-dismiss":"onClickClose"},tmpl:function(){return''},setup:function(t){$.extend(this.data,t),this.$el=$(this.tmpl())},initialize:function(){this.render(),this.show()},render:function(){this.type(this.get("type")),this.html("
",'',""].join("")},render:function(){var t=this.get("title"),e=this.get("content"),i=this.get("loading"),n=this.get("width"),a=this.get("height");this.title(t),this.content(e),n&&this.$(".acf-popup-box").css("width",n),a&&this.$(".acf-popup-box").css("min-height",a),this.loading(i),acf.doAction("append",this.$el)},update:function(t){this.data=acf.parseArgs(t,this.data),this.render()},title:function(t){this.$(".title:first h3").html(t)},content:function(t){this.$(".inner:first").html(t)},loading:function(t){var e=this.$(".loading:first");t?e.show():e.hide()},open:function(){$("body").append(this.$el)},close:function(){this.remove()},onClickClose:function(t,e){t.preventDefault(),this.close()}}),acf.newPopup=function(t){return new acf.models.Popup(t)}}(jQuery),function($,t){acf.unload=new acf.Model({wait:"load",active:!0,changed:!1,actions:{validation_failure:"startListening"},events:{"change .acf-field":"startListening","submit form":"stopListening"},reset:function(){this.stopListening()},startListening:function(){!this.changed&&this.active&&(this.changed=!0,$(window).on("beforeunload",this.onUnload))},stopListening:function(){this.changed=!1,$(window).off("beforeunload",this.onUnload)},onUnload:function(){return acf.__("The changes you made will be lost if you navigate away from this page")}})}(jQuery),function($,t){var e=new acf.Model({events:{"click .acf-panel-title":"onClick"},onClick:function(t,e){t.preventDefault(),this.toggle(e.parent())},isOpen:function(t){return t.hasClass("-open")},toggle:function(t){this.isOpen(t)?this.close(t):this.open(t)},open:function(t){t.addClass("-open"),t.find(".acf-panel-title i").attr("class","dashicons dashicons-arrow-down")},close:function(t){t.removeClass("-open"),t.find(".acf-panel-title i").attr("class","dashicons dashicons-arrow-right")}})}(jQuery),function($,t){var e=acf.Model.extend({data:{text:"",type:"",timeout:0,dismiss:!0,target:!1,close:function(){}},events:{"click .acf-notice-dismiss":"onClickClose"},tmpl:function(){return''},setup:function(t){$.extend(this.data,t),this.$el=$(this.tmpl())},initialize:function(){this.render(),this.show()},render:function(){this.type(this.get("type")),this.html("
Return to network dashboard', 'acf'), network_admin_url() ); ?>
+
+
+
\ No newline at end of file
diff --git a/includes/admin/views/html-admin-page-upgrade.php b/includes/admin/views/html-admin-page-upgrade.php
new file mode 100644
index 0000000..545c0b0
--- /dev/null
+++ b/includes/admin/views/html-admin-page-upgrade.php
@@ -0,0 +1,119 @@
+
+
+
+
+
+
+
+
+
+
+
+
See what\'s new', 'acf' ), admin_url('edit.php?post_type=acf-field-group&page=acf-settings-info') ); ?>
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/includes/admin/views/html-location-group.php b/includes/admin/views/html-location-group.php
index 378f39f..14dc961 100644
--- a/includes/admin/views/html-location-group.php
+++ b/includes/admin/views/html-location-group.php
@@ -6,15 +6,13 @@
$rule ):
- // append id
+ // validate rule
+ $rule = acf_validate_location_rule($rule);
+
+ // append id and group
$rule['id'] = "rule_{$i}";
$rule['group'] = $group_id;
-
- // valid rule
- $rule = acf_get_valid_location_rule($rule);
-
-
// view
acf_get_view('html-location-rule', array(
'rule' => $rule
diff --git a/includes/admin/views/html-location-rule.php b/includes/admin/views/html-location-rule.php
index 1f29fa0..1171133 100644
--- a/includes/admin/views/html-location-rule.php
+++ b/includes/admin/views/html-location-rule.php
@@ -1,3 +1,9 @@
+
+
+
+
\ No newline at end of file
diff --git a/includes/admin/views/install-network.php b/includes/admin/views/install-network.php
deleted file mode 100644
index 666ac85..0000000
--- a/includes/admin/views/install-network.php
+++ /dev/null
@@ -1,233 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $site ): ?>
-
-
class="alternate">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Return to network dashboard', 'acf'), network_admin_url() ); ?>
-
-
-
-
-
-
\ No newline at end of file
diff --git a/includes/admin/views/install-notice.php b/includes/admin/views/install-notice.php
deleted file mode 100644
index f45e1dc..0000000
--- a/includes/admin/views/install-notice.php
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/includes/admin/views/install.php b/includes/admin/views/install.php
deleted file mode 100644
index 6cf9154..0000000
--- a/includes/admin/views/install.php
+++ /dev/null
@@ -1,108 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
See what\'s new', 'acf' ), admin_url('edit.php?post_type=acf-field-group&page=acf-settings-info') ); ?>
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/includes/admin/views/settings-info.php b/includes/admin/views/settings-info.php
index fedd054..1758c42 100644
--- a/includes/admin/views/settings-info.php
+++ b/includes/admin/views/settings-info.php
@@ -2,9 +2,6 @@
-
-
-
$tab_title ): ?>
@@ -14,142 +11,134 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
👋
+
+
+
+
+
Pro version of ACF. With both personal and developer licenses available, premium functionality is more affordable and accessible than ever before!', 'acf'), esc_url('https://www.advancedcustomfields.com/pro')); ?>
+
+
+
+
+
+
ACF PRO features.', 'acf'), esc_url('https://www.advancedcustomfields.com/pro')); ?>
+
+
+
+
+
+
upgrade guide to answer any questions, but if you do have one, please contact our support team via the help desk.', 'acf'), esc_url('https://www.advancedcustomfields.com/resources/upgrade-guide-acf-pro/'), esc_url('https://www.advancedcustomfields.com/support/')); ?>
+
+
+
-
+
-
-
-
-
Pro version of ACF. With both personal and developer licenses available, premium functionality is more affordable and accessible than ever before!', 'acf'), esc_url('https://www.advancedcustomfields.com/pro')); ?>
-
+
-
-
-
-
ACF PRO features.', 'acf'), esc_url('https://www.advancedcustomfields.com/pro')); ?>
-
+
🎉
-
-
-
login to your store account and claim a free copy of ACF PRO!', 'acf'), esc_url('https://www.advancedcustomfields.com/my-account/')); ?>
-
upgrade guide to answer any questions, but if you do have one, please contact our support team via the help desk', 'acf'), esc_url('https://www.advancedcustomfields.com/resources/updates/upgrading-v4-v5/'), esc_url('https://support.advancedcustomfields.com')); ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/includes/ajax/class-acf-ajax-upgrade.php b/includes/ajax/class-acf-ajax-upgrade.php
new file mode 100644
index 0000000..a75ccbb
--- /dev/null
+++ b/includes/ajax/class-acf-ajax-upgrade.php
@@ -0,0 +1,59 @@
+has('blog_id') ) {
+ switch_to_blog( $this->get('blog_id') );
+ }
+
+ // bail early if no upgrade avaiable
+ if( !acf_has_upgrade() ) {
+ return new WP_Error( 'upgrade_error', __('No updates available.', 'acf') );
+ }
+
+ // listen for output
+ ob_start();
+
+ // run upgrades
+ acf_upgrade_all();
+
+ // store output
+ $error = ob_get_clean();
+
+ // return error if output
+ if( $error ) {
+ return new WP_Error( 'upgrade_error', $error );
+ }
+
+ // return
+ return true;
+ }
+}
+
+acf_new_instance('ACF_Ajax_Upgrade');
+
+endif; // class_exists check
+
+?>
\ No newline at end of file
diff --git a/includes/api/api-field.php b/includes/api/api-field.php
index fd14ea2..9b41bfc 100644
--- a/includes/api/api-field.php
+++ b/includes/api/api-field.php
@@ -97,11 +97,18 @@ function acf_get_valid_field( $field = false ) {
$field['_valid'] = 1;
- // field specific defaults
- $field = apply_filters( "acf/validate_field", $field );
+ /**
+ * Filters the $field array to validate settings.
+ *
+ * @date 12/02/2014
+ * @since 5.0.0
+ *
+ * @param array $field The field array.
+ */
$field = apply_filters( "acf/validate_field/type={$field['type']}", $field );
+ $field = apply_filters( "acf/validate_field", $field );
-
+
// translate
$field = acf_translate_field( $field );
@@ -140,10 +147,17 @@ function acf_translate_field( $field ) {
$field['instructions'] = acf_translate( $field['instructions'] );
- // filters
- $field = apply_filters( "acf/translate_field", $field );
+ /**
+ * Filters the $field array to translate strings.
+ *
+ * @date 12/02/2014
+ * @since 5.0.0
+ *
+ * @param array $field The field array.
+ */
$field = apply_filters( "acf/translate_field/type={$field['type']}", $field );
-
+ $field = apply_filters( "acf/translate_field", $field );
+
}
@@ -173,9 +187,17 @@ function acf_clone_field( $field, $clone_field ) {
$field['_clone'] = $clone_field['key'];
- // filters
- $field = apply_filters( "acf/clone_field", $field, $clone_field );
+ /**
+ * Filters the $field array when it is being cloned.
+ *
+ * @date 12/02/2014
+ * @since 5.0.0
+ *
+ * @param array $field The field array.
+ * @param array $clone_field The clone field array.
+ */
$field = apply_filters( "acf/clone_field/type={$field['type']}", $field, $clone_field );
+ $field = apply_filters( "acf/clone_field", $field, $clone_field );
// return
@@ -215,11 +237,20 @@ function acf_prepare_field( $field ) {
$field['_prepare'] = 1;
- // filter to 3rd party customization
- $field = apply_filters( "acf/prepare_field", $field );
- $field = apply_filters( "acf/prepare_field/type={$field['type']}", $field );
- $field = apply_filters( "acf/prepare_field/name={$field['_name']}", $field );
- $field = apply_filters( "acf/prepare_field/key={$field['key']}", $field );
+ /**
+ * Filters the $field array.
+ *
+ * Allows developers to modify field settings or return false to remove field.
+ *
+ * @date 12/02/2014
+ * @since 5.0.0
+ *
+ * @param array $field The field array.
+ */
+ $field = apply_filters( "acf/prepare_field/type={$field['type']}", $field );
+ $field = apply_filters( "acf/prepare_field/name={$field['_name']}", $field );
+ $field = apply_filters( "acf/prepare_field/key={$field['key']}", $field );
+ $field = apply_filters( "acf/prepare_field", $field );
// bail ealry if no field
@@ -391,10 +422,18 @@ function acf_render_field( $field = false ) {
if( !$field ) return;
- // create field specific html
- do_action( "acf/render_field", $field );
- do_action( "acf/render_field/type={$field['type']}", $field );
-
+ /**
+ * Fires when rendering a field.
+ *
+ * @date 12/02/2014
+ * @since 5.0.0
+ *
+ * @param array $field The field array.
+ */
+ do_action( "acf/render_field/type={$field['type']}", $field );
+ do_action( "acf/render_field/name={$field['_name']}", $field );
+ do_action( "acf/render_field/key={$field['key']}", $field );
+ do_action( "acf/render_field", $field );
}
@@ -894,11 +933,18 @@ function acf_get_field( $selector = null, $db_only = false ) {
if( $db_only ) return $field;
- // filter for 3rd party customization
- $field = apply_filters( "acf/load_field", $field);
- $field = apply_filters( "acf/load_field/type={$field['type']}", $field );
- $field = apply_filters( "acf/load_field/name={$field['name']}", $field );
- $field = apply_filters( "acf/load_field/key={$field['key']}", $field );
+ /**
+ * Filters the $field array after it has been loaded.
+ *
+ * @date 12/02/2014
+ * @since 5.0.0
+ *
+ * @param array $field The field array.
+ */
+ $field = apply_filters( "acf/load_field/type={$field['type']}", $field );
+ $field = apply_filters( "acf/load_field/name={$field['_name']}", $field );
+ $field = apply_filters( "acf/load_field/key={$field['key']}", $field );
+ $field = apply_filters( "acf/load_field", $field );
// update cache
@@ -1244,11 +1290,18 @@ function acf_update_field( $field = false, $specific = false ) {
}
- // filter for 3rd party customization
- $field = apply_filters( "acf/update_field", $field);
- $field = apply_filters( "acf/update_field/type={$field['type']}", $field );
- $field = apply_filters( "acf/update_field/name={$field['name']}", $field );
- $field = apply_filters( "acf/update_field/key={$field['key']}", $field );
+ /**
+ * Filters the $field array before it is updated.
+ *
+ * @date 12/02/2014
+ * @since 5.0.0
+ *
+ * @param array $field The field array.
+ */
+ $field = apply_filters( "acf/update_field/type={$field['type']}", $field );
+ $field = apply_filters( "acf/update_field/name={$field['_name']}", $field );
+ $field = apply_filters( "acf/update_field/key={$field['key']}", $field );
+ $field = apply_filters( "acf/update_field", $field );
// store origional field for return
@@ -1506,9 +1559,16 @@ function acf_duplicate_field( $selector = 0, $new_parent = 0 ){
}
- // filter for 3rd party customization
- $field = apply_filters( "acf/duplicate_field", $field);
+ /**
+ * Filters the $field array after it has been duplicated.
+ *
+ * @date 12/02/2014
+ * @since 5.0.0
+ *
+ * @param array $field The field array.
+ */
$field = apply_filters( "acf/duplicate_field/type={$field['type']}", $field );
+ $field = apply_filters( "acf/duplicate_field", $field);
// save
@@ -1548,9 +1608,18 @@ function acf_delete_field( $selector = 0 ) {
wp_delete_post( $field['ID'], true );
- // action for 3rd party customisation
- do_action( "acf/delete_field", $field);
- do_action( "acf/delete_field/type={$field['type']}", $field );
+ /**
+ * Fires immediately after a field has been deleted.
+ *
+ * @date 12/02/2014
+ * @since 5.0.0
+ *
+ * @param array $field The field array.
+ */
+ do_action( "acf/delete_field/type={$field['type']}", $field );
+ do_action( "acf/delete_field/name={$field['_name']}", $field );
+ do_action( "acf/delete_field/key={$field['key']}", $field );
+ do_action( "acf/delete_field", $field );
// clear cache
@@ -1708,9 +1777,16 @@ function acf_prepare_field_for_export( $field ) {
));
- // filter for 3rd party customization
- $field = apply_filters( "acf/prepare_field_for_export", $field );
+ /**
+ * Filters the $field array before being returned to the export tool.
+ *
+ * @date 12/02/2014
+ * @since 5.0.0
+ *
+ * @param array $field The field array.
+ */
$field = apply_filters( "acf/prepare_field_for_export/type={$field['type']}", $field );
+ $field = apply_filters( "acf/prepare_field_for_export", $field );
// return
@@ -1803,9 +1879,16 @@ function acf_prepare_field_for_import( $field ) {
));
- // filter for 3rd party customization
- $field = apply_filters( "acf/prepare_field_for_import", $field );
+ /**
+ * Filters the $field array before being returned to the import tool.
+ *
+ * @date 12/02/2014
+ * @since 5.0.0
+ *
+ * @param array $field The field array.
+ */
$field = apply_filters( "acf/prepare_field_for_import/type={$field['type']}", $field );
+ $field = apply_filters( "acf/prepare_field_for_import", $field );
// return
@@ -1852,9 +1935,18 @@ function acf_get_sub_field( $selector, $field ) {
}
- // filter for 3rd party customization
- $sub_field = apply_filters( "acf/get_sub_field", $sub_field, $selector, $field );
+ /**
+ * Filters the $sub_field found.
+ *
+ * @date 12/02/2014
+ * @since 5.0.0
+ *
+ * @param array $sub_field The found sub field array.
+ * @param string $selector The selector used to search.
+ * @param array $field The parent field array.
+ */
$sub_field = apply_filters( "acf/get_sub_field/type={$field['type']}", $sub_field, $selector, $field );
+ $sub_field = apply_filters( "acf/get_sub_field", $sub_field, $selector, $field );
// return
@@ -2029,4 +2121,57 @@ function acf_prefix_fields( &$fields, $prefix = 'acf' ) {
}
+/**
+* acf_apply_field_filters
+*
+* description
+*
+* @date 11/9/18
+* @since 5.7.6
+*
+* @param type $var Description. Default.
+* @return type Description.
+*/
+/*
+function acf_apply_field_filters( $value ) {
+
+ // get function args
+ $args = func_get_args();
+
+ // find field in $args
+ $field = false;
+ foreach( $args as $arg ) {
+ if( is_array($arg) && isset($arg['key'], $arg['type'], $arg['_name']) ) {
+ $field = $arg;
+ break;
+ }
+ }
+
+ // vars
+ $filter = current_filter();
+
+ // unshift tag to args
+ array_unshift($args, $filter);
+
+ // apply field filters
+ if( $field ) {
+
+ // $filter/type=$type
+ $args[0] = "{$filter}/type={$field['type']}";
+ $value = call_user_func_array('apply_filters', $args);
+
+ // $filter/name=$name
+ $args[0] = "{$filter}/name={$field['_name']}";
+ $value = call_user_func_array('apply_filters', $args);
+
+ // $filter/key=$key
+ $args[0] = "{$filter}/key={$field['key']}";
+ $value = call_user_func_array('apply_filters', $args);
+ }
+
+ // return
+ return $value;
+}
+*/
+
?>
\ No newline at end of file
diff --git a/includes/api/api-helpers.php b/includes/api/api-helpers.php
index 5c77f57..81b2bfd 100644
--- a/includes/api/api-helpers.php
+++ b/includes/api/api-helpers.php
@@ -431,6 +431,24 @@ function acf_include( $file ) {
}
+/**
+* acf_include_once
+*
+* Includes a file one time only.
+*
+* @date 24/8/18
+* @since 5.7.4
+*
+* @param string $file The relative file path.
+* @return void
+*/
+
+function acf_include_once( $file = '' ) {
+ $path = acf_get_path( $file );
+ if( file_exists($path) ) {
+ include_once( $path );
+ }
+}
/*
* acf_get_external_path
@@ -1210,30 +1228,20 @@ function acf_get_locale() {
function acf_get_terms( $args ) {
- // global
- global $wp_version;
-
-
- // vars
- $terms = array();
-
-
- // WP 4.5+
- if( version_compare($wp_version, '4.5', '>=' ) ) {
-
- $terms = get_terms( $args );
-
- // WP < 4.5
- } else {
-
- $terms = get_terms( $args['taxonomy'], $args );
+ // defaults
+ $args = wp_parse_args($args, array(
+ 'taxonomy' => null,
+ 'hide_empty' => false,
+ 'update_term_meta_cache' => false,
+ ));
+ // parameters changed in version 4.5
+ if( acf_version_compare('wp', '<', '4.5') ) {
+ return get_terms( $args['taxonomy'], $args );
}
-
// return
- return $terms;
-
+ return get_terms( $args );
}
@@ -1309,36 +1317,6 @@ function acf_get_taxonomy_terms( $taxonomies = array() ) {
}
-function acf_get_term_title( $term ) {
-
- // title
- $title = $term->name;
-
-
- // empty
- if( $title === '' ) {
-
- $title = __('(no title)', 'acf');
-
- }
-
-
- // ancestors
- if( is_taxonomy_hierarchical($term->taxonomy) ) {
-
- $ancestors = get_ancestors( $term->term_id, $term->taxonomy );
-
- $title = str_repeat('- ', count($ancestors)) . $title;
-
- }
-
-
- // return
- return $title;
-
-}
-
-
/*
* acf_decode_taxonomy_terms
*
@@ -4063,11 +4041,22 @@ function acf_validate_attachment( $attachment, $field, $context = 'prepare' ) {
}
- // filter for 3rd party customization
- $errors = apply_filters("acf/validate_attachment", $errors, $file, $attachment, $field, $context);
- $errors = apply_filters("acf/validate_attachment/type={$field['type']}", $errors, $file, $attachment, $field, $context );
- $errors = apply_filters("acf/validate_attachment/name={$field['name']}", $errors, $file, $attachment, $field, $context );
- $errors = apply_filters("acf/validate_attachment/key={$field['key']}", $errors, $file, $attachment, $field, $context );
+ /**
+ * Filters the errors for a file before it is uploaded or displayed in the media modal.
+ *
+ * @date 3/07/2015
+ * @since 5.2.3
+ *
+ * @param array $errors An array of errors.
+ * @param array $file An array of data for a single file.
+ * @param array $attachment An array of attachment data which differs based on the context.
+ * @param array $field The field array.
+ * @param string $context The curent context (uploading, preparing)
+ */
+ $errors = apply_filters( "acf/validate_attachment/type={$field['type']}", $errors, $file, $attachment, $field, $context );
+ $errors = apply_filters( "acf/validate_attachment/name={$field['_name']}", $errors, $file, $attachment, $field, $context );
+ $errors = apply_filters( "acf/validate_attachment/key={$field['key']}", $errors, $file, $attachment, $field, $context );
+ $errors = apply_filters( "acf/validate_attachment", $errors, $file, $attachment, $field, $context );
// return
@@ -4537,33 +4526,43 @@ function acf_format_date( $value, $format ) {
function acf_log() {
// vars
- $log = '';
$args = func_get_args();
-
// loop
foreach( $args as $i => $arg ) {
+ // array | object
if( is_array($arg) || is_object($arg) ) {
-
$arg = print_r($arg, true);
-
- } elseif( is_bool($arg) ) {
-
- $arg = ( $arg ? 'true' : 'false' ) . ' (bool)';
-
- }
+ // bool
+ } elseif( is_bool($arg) ) {
+ $arg = 'bool(' . ( $arg ? 'true' : 'false' ) . ')';
+ }
// update
$args[ $i ] = $arg;
-
}
-
// log
error_log( implode(' ', $args) );
-
+}
+
+/**
+* acf_dev_log
+*
+* Used to log variables only if ACF_DEV is defined
+*
+* @date 25/8/18
+* @since 5.7.4
+*
+* @param mixed
+* @return void
+*/
+function acf_dev_log() {
+ if( defined('ACF_DEV') && ACF_DEV ) {
+ call_user_func_array('acf_log', func_get_args());
+ }
}
@@ -5267,4 +5266,98 @@ function acf_parse_markdown( $text = '' ) {
return $text;
}
+/**
+* acf_get_sites
+*
+* Returns an array of sites for a network.
+*
+* @date 29/08/2016
+* @since 5.4.0
+*
+* @param void
+* @return array
+*/
+function acf_get_sites() {
+
+ // vars
+ $results = array();
+
+ // function get_sites() was added in WP 4.6
+ if( function_exists('get_sites') ) {
+
+ $_sites = get_sites(array(
+ 'number' => 0
+ ));
+
+ if( $_sites ) {
+ foreach( $_sites as $_site ) {
+ $_site = get_site( $_site );
+ $results[] = $_site->to_array();
+ }}
+
+ // function wp_get_sites() returns in the desired output
+ } else {
+ $results = wp_get_sites(array(
+ 'limit' => 0
+ ));
+ }
+
+ // return
+ return $results;
+}
+
+/**
+* acf_convert_rules_to_groups
+*
+* Converts an array of rules from ACF4 to an array of groups for ACF5
+*
+* @date 25/8/18
+* @since 5.7.4
+*
+* @param array $rules An array of rules.
+* @param string $anyorall The anyorall setting used in ACF4. Defaults to 'any'.
+* @return array
+*/
+function acf_convert_rules_to_groups( $rules, $anyorall = 'any' ) {
+
+ // vars
+ $groups = array();
+ $index = 0;
+
+ // loop
+ foreach( $rules as $rule ) {
+
+ // extract vars
+ $group = acf_extract_var( $rule, 'group_no' );
+ $order = acf_extract_var( $rule, 'order_no' );
+
+ // calculate group if not defined
+ if( $group === null ) {
+ $group = $index;
+
+ // use $anyorall to determine if a new group is needed
+ if( $anyorall == 'any' ) {
+ $index++;
+ }
+ }
+
+ // calculate order if not defined
+ if( $order === null ) {
+ $order = isset($groups[ $group ]) ? count($groups[ $group ]) : 0;
+ }
+
+ // append to group
+ $groups[ $group ][ $order ] = $rule;
+
+ // sort groups
+ ksort( $groups[ $group ] );
+ }
+
+ // sort groups
+ ksort( $groups );
+
+ // return
+ return $groups;
+}
+
?>
\ No newline at end of file
diff --git a/includes/api/api-term.php b/includes/api/api-term.php
index 39db76f..0eef7fd 100644
--- a/includes/api/api-term.php
+++ b/includes/api/api-term.php
@@ -31,6 +31,11 @@ function acf_get_taxonomies( $args = array() ) {
$taxonomies[] = $i;
}
+ // custom post_type arg which does not yet exist in core
+ if( isset($args['post_type']) ) {
+ $taxonomies = acf_get_taxonomies_for_post_type($args['post_type']);
+ }
+
// filter
$taxonomies = apply_filters('acf/get_taxonomies', $taxonomies, $args);
@@ -38,6 +43,37 @@ function acf_get_taxonomies( $args = array() ) {
return $taxonomies;
}
+/**
+* acf_get_taxonomies_for_post_type
+*
+* Returns an array of taxonomies for a given post type(s)
+*
+* @date 7/9/18
+* @since 5.7.5
+*
+* @param string|array $post_types The post types to compare against.
+* @return array
+*/
+function acf_get_taxonomies_for_post_type( $post_types = 'post' ) {
+
+ // vars
+ $taxonomies = array();
+
+ // loop
+ foreach( (array) $post_types as $post_type ) {
+ $object_taxonomies = get_object_taxonomies( $post_type );
+ foreach( (array) $object_taxonomies as $taxonomy ) {
+ $taxonomies[] = $taxonomy;
+ }
+ }
+
+ // remove duplicates
+ $taxonomies = array_unique($taxonomies);
+
+ // return
+ return $taxonomies;
+}
+
/*
* acf_get_taxonomy_labels
*
@@ -89,6 +125,38 @@ function acf_get_taxonomy_labels( $taxonomies = array() ) {
return $data;
}
+/**
+* acf_get_term_title
+*
+* Returns the title for this term object.
+*
+* @date 10/9/18
+* @since 5.0.0
+*
+* @param object $term The WP_Term object.
+* @return string
+*/
+
+function acf_get_term_title( $term ) {
+
+ // set to term name
+ $title = $term->name;
+
+ // allow for empty name
+ if( $title === '' ) {
+ $title = __('(no title)', 'acf');
+ }
+
+ // prepent ancestors indentation
+ if( is_taxonomy_hierarchical($term->taxonomy) ) {
+ $ancestors = get_ancestors( $term->term_id, $term->taxonomy );
+ $title = str_repeat('- ', count($ancestors)) . $title;
+ }
+
+ // return
+ return $title;
+}
+
/**
* acf_get_grouped_terms
*
@@ -108,7 +176,7 @@ function acf_get_grouped_terms( $args ) {
// defaults
$args = wp_parse_args($args, array(
- 'taxonomy' => 'category',
+ 'taxonomy' => null,
'hide_empty' => false,
'update_term_meta_cache' => false,
));
@@ -117,6 +185,9 @@ function acf_get_grouped_terms( $args ) {
$taxonomies = acf_get_taxonomy_labels( acf_get_array($args['taxonomy']) );
$is_single = (count($taxonomies) == 1);
+ // specify exact taxonomies required for _acf_terms_clauses() to work.
+ $args['taxonomy'] = array_keys($taxonomies);
+
// add filter to group results by taxonomy
if( !$is_single ) {
add_filter('terms_clauses', '_acf_terms_clauses', 10, 3);
@@ -241,14 +312,14 @@ function acf_get_pretty_taxonomies( $taxonomies = array() ) {
* @date 19/8/18
* @since 5.7.3
*
-* @param mixed $term_id The term ID or a string of "slug:taxonomy".
+* @param mixed $term_id The term ID or a string of "taxonomy:slug".
* @param string $taxonomy The taxonomyname.
* @return WP_Term
*/
function acf_get_term( $term_id, $taxonomy = '' ) {
- // allow $term_id parameter to be a string of "slug:taxonomy" of "slug:id"
+ // allow $term_id parameter to be a string of "taxonomy:slug" or "taxonomy:id"
if( is_string($term_id) && strpos($term_id, ':') ) {
list( $taxonomy, $term_id ) = explode(':', $term_id);
$term = get_term_by( 'slug', $term_id, $taxonomy );
@@ -259,5 +330,172 @@ function acf_get_term( $term_id, $taxonomy = '' ) {
return get_term( $term_id, $taxonomy );
}
+/**
+* acf_encode_term
+*
+* Returns a "taxonomy:slug" string for a given WP_Term.
+*
+* @date 27/8/18
+* @since 5.7.4
+*
+* @param WP_Term $term The term object.
+* @return string
+*/
+function acf_encode_term( $term ) {
+ return "{$term->taxonomy}:{$term->slug}";
+}
+
+/**
+* acf_decode_term
+*
+* Decodes a "taxonomy:slug" string into an array of taxonomy and slug.
+*
+* @date 27/8/18
+* @since 5.7.4
+*
+* @param WP_Term $term The term object.
+* @return string
+*/
+function acf_decode_term( $string ) {
+ if( is_string($string) && strpos($string, ':') ) {
+ list( $taxonomy, $slug ) = explode(':', $string);
+ return array(
+ 'taxonomy' => $taxonomy,
+ 'slug' => $slug
+ );
+ }
+ return false;
+}
+
+/**
+* acf_get_encoded_terms
+*
+* Returns an array of WP_Term objects from an array of encoded strings
+*
+* @date 9/9/18
+* @since 5.7.5
+*
+* @param array $values The array of encoded strings.
+* @return array
+*/
+function acf_get_encoded_terms( $values ) {
+
+ // vars
+ $terms = array();
+
+ // loop over values
+ foreach( (array) $values as $value ) {
+
+ // find term from string
+ $term = acf_get_term( $value );
+
+ // append
+ if( $term instanceof WP_Term ) {
+ $terms[] = $term;
+ }
+ }
+
+ // return
+ return $terms;
+}
+
+/**
+* acf_get_choices_from_terms
+*
+* Returns an array of choices from the terms provided.
+*
+* @date 8/9/18
+* @since 5.7.5
+*
+* @param array $values and array of WP_Terms objects or encoded strings.
+* @param string $format The value format (term_id, slug).
+* @return array
+*/
+function acf_get_choices_from_terms( $terms, $format = 'term_id' ) {
+
+ // vars
+ $groups = array();
+
+ // get taxonomy lables
+ $labels = acf_get_taxonomy_labels();
+
+ // convert array of encoded strings to terms
+ $term = reset($terms);
+ if( !$term instanceof WP_Term ) {
+ $terms = acf_get_encoded_terms( $terms );
+ }
+
+ // loop over terms
+ foreach( $terms as $term ) {
+ $group = $labels[ $term->taxonomy ];
+ $choice = acf_get_choice_from_term( $term, $format );
+ $groups[ $group ][ $choice['id'] ] = $choice['text'];
+ }
+
+ // return
+ return $groups;
+}
+
+/**
+* acf_get_choices_from_grouped_terms
+*
+* Returns an array of choices from the grouped terms provided.
+*
+* @date 8/9/18
+* @since 5.7.5
+*
+* @param array $value A grouped array of WP_Terms objects.
+* @param string $format The value format (term_id, slug).
+* @return array
+*/
+function acf_get_choices_from_grouped_terms( $value, $format = 'term_id' ) {
+
+ // vars
+ $groups = array();
+
+ // loop over values
+ foreach( $value as $group => $terms ) {
+ $groups[ $group ] = array();
+ foreach( $terms as $term_id => $term ) {
+ $choice = acf_get_choice_from_term( $term, $format );
+ $groups[ $group ][ $choice['id'] ] = $choice['text'];
+ }
+ }
+
+ // return
+ return $groups;
+}
+
+/**
+* acf_get_choice_from_term
+*
+* Returns an array containing the id and text for this item.
+*
+* @date 10/9/18
+* @since 5.7.6
+*
+* @param object $item The item object such as WP_Post or WP_Term.
+* @param string $format The value format (term_id, slug)
+* @return array
+*/
+function acf_get_choice_from_term( $term, $format = 'term_id' ) {
+
+ // vars
+ $id = $term->term_id;
+ $text = acf_get_term_title( $term );
+
+ // return format
+ if( $format == 'slug' ) {
+ $id = acf_encode_term($term);
+ }
+
+ // return
+ return array(
+ 'id' => $id,
+ 'text' => $text
+ );
+}
+
+
?>
\ No newline at end of file
diff --git a/includes/api/api-value.php b/includes/api/api-value.php
index e515084..7754a8d 100644
--- a/includes/api/api-value.php
+++ b/includes/api/api-value.php
@@ -299,12 +299,21 @@ function acf_get_value( $post_id = 0, $field ) {
$value = $field['default_value'];
}
-
- // filter for 3rd party customization
- $value = apply_filters( "acf/load_value", $value, $post_id, $field );
- $value = apply_filters( "acf/load_value/type={$field['type']}", $value, $post_id, $field );
- $value = apply_filters( "acf/load_value/name={$field['_name']}", $value, $post_id, $field );
- $value = apply_filters( "acf/load_value/key={$field['key']}", $value, $post_id, $field );
+
+ /**
+ * Filters the $value after it has been loaded.
+ *
+ * @date 28/09/13
+ * @since 5.0.0
+ *
+ * @param mixed $value The value to preview.
+ * @param string $post_id The post ID for this value.
+ * @param array $field The field array.
+ */
+ $value = apply_filters( "acf/load_value/type={$field['type']}", $value, $post_id, $field );
+ $value = apply_filters( "acf/load_value/name={$field['_name']}", $value, $post_id, $field );
+ $value = apply_filters( "acf/load_value/key={$field['key']}", $value, $post_id, $field );
+ $value = apply_filters( "acf/load_value", $value, $post_id, $field );
// update cache
@@ -345,12 +354,21 @@ function acf_format_value( $value, $post_id, $field ) {
}
-
- // apply filters
- $value = apply_filters( "acf/format_value", $value, $post_id, $field );
- $value = apply_filters( "acf/format_value/type={$field['type']}", $value, $post_id, $field );
- $value = apply_filters( "acf/format_value/name={$field['_name']}", $value, $post_id, $field );
- $value = apply_filters( "acf/format_value/key={$field['key']}", $value, $post_id, $field );
+
+ /**
+ * Filters the $value for use in a template function.
+ *
+ * @date 28/09/13
+ * @since 5.0.0
+ *
+ * @param mixed $value The value to preview.
+ * @param string $post_id The post ID for this value.
+ * @param array $field The field array.
+ */
+ $value = apply_filters( "acf/format_value/type={$field['type']}", $value, $post_id, $field );
+ $value = apply_filters( "acf/format_value/name={$field['_name']}", $value, $post_id, $field );
+ $value = apply_filters( "acf/format_value/key={$field['key']}", $value, $post_id, $field );
+ $value = apply_filters( "acf/format_value", $value, $post_id, $field );
// update cache
@@ -385,18 +403,40 @@ function acf_update_value( $value = null, $post_id = 0, $field ) {
}
- // allow filter to short-circuit update_value logic
+ /**
+ * Allows developers to run a custom update function.
+ *
+ * @date 28/09/13
+ * @since 5.0.0
+ *
+ * @param null $check Return a non null value to prevent default.
+ * @param mixed $value The value to update.
+ * @param string $post_id The post ID for this value.
+ * @param array $field The field array.
+ */
$check = apply_filters( "acf/pre_update_value", null, $value, $post_id, $field );
if( $check !== null ) {
return $check;
}
- // filter for 3rd party customization
- $value = apply_filters( "acf/update_value", $value, $post_id, $field );
- $value = apply_filters( "acf/update_value/type={$field['type']}", $value, $post_id, $field );
- $value = apply_filters( "acf/update_value/name={$field['_name']}", $value, $post_id, $field );
- $value = apply_filters( "acf/update_value/key={$field['key']}", $value, $post_id, $field );
+ /**
+ * Filters the $value before it is saved.
+ *
+ * @date 28/09/13
+ * @since 5.0.0
+ * @since 5.7.6 Added $_value parameter.
+ *
+ * @param mixed $value The value to update.
+ * @param string $post_id The post ID for this value.
+ * @param array $field The field array.
+ * @param mixed $_value The original value before modification.
+ */
+ $_value = $value;
+ $value = apply_filters( "acf/update_value/type={$field['type']}", $value, $post_id, $field, $_value );
+ $value = apply_filters( "acf/update_value/name={$field['_name']}", $value, $post_id, $field, $_value );
+ $value = apply_filters( "acf/update_value/key={$field['key']}", $value, $post_id, $field, $_value );
+ $value = apply_filters( "acf/update_value", $value, $post_id, $field, $_value );
// allow null to delete
@@ -442,11 +482,20 @@ function acf_update_value( $value = null, $post_id = 0, $field ) {
function acf_delete_value( $post_id = 0, $field ) {
- // action for 3rd party customization
- do_action("acf/delete_value", $post_id, $field['name'], $field);
- do_action("acf/delete_value/type={$field['type']}", $post_id, $field['name'], $field);
- do_action("acf/delete_value/name={$field['_name']}", $post_id, $field['name'], $field);
- do_action("acf/delete_value/key={$field['key']}", $post_id, $field['name'], $field);
+ /**
+ * Fires before a value is deleted.
+ *
+ * @date 28/09/13
+ * @since 5.0.0
+ *
+ * @param string $post_id The post ID for this value.
+ * @param mixed $name The meta name.
+ * @param array $field The field array.
+ */
+ do_action( "acf/delete_value/type={$field['type']}", $post_id, $field['name'], $field );
+ do_action( "acf/delete_value/name={$field['_name']}", $post_id, $field['name'], $field );
+ do_action( "acf/delete_value/key={$field['key']}", $post_id, $field['name'], $field );
+ do_action( "acf/delete_value", $post_id, $field['name'], $field );
// delete value
@@ -553,16 +602,23 @@ function acf_copy_postmeta( $from_post_id, $to_post_id ) {
function acf_preview_value( $value, $post_id, $field ) {
- // apply filters
- $value = apply_filters( "acf/preview_value", $value, $post_id, $field );
- $value = apply_filters( "acf/preview_value/type={$field['type']}", $value, $post_id, $field );
- $value = apply_filters( "acf/preview_value/name={$field['_name']}", $value, $post_id, $field );
- $value = apply_filters( "acf/preview_value/key={$field['key']}", $value, $post_id, $field );
-
+ /**
+ * Filters the $value before used in HTML.
+ *
+ * @date 24/10/16
+ * @since 5.5.0
+ *
+ * @param mixed $value The value to preview.
+ * @param string $post_id The post ID for this value.
+ * @param array $field The field array.
+ */
+ $value = apply_filters( "acf/preview_value/type={$field['type']}", $value, $post_id, $field );
+ $value = apply_filters( "acf/preview_value/name={$field['_name']}", $value, $post_id, $field );
+ $value = apply_filters( "acf/preview_value/key={$field['key']}", $value, $post_id, $field );
+ $value = apply_filters( "acf/preview_value", $value, $post_id, $field );
// return
return $value;
-
}
?>
\ No newline at end of file
diff --git a/includes/compatibility.php b/includes/compatibility.php
index 13885c4..f5988eb 100644
--- a/includes/compatibility.php
+++ b/includes/compatibility.php
@@ -1,282 +1,194 @@
- 'post_taxonomy',
+ 'ef_media' => 'attachment',
+ 'ef_taxonomy' => 'taxonomy',
+ 'ef_user' => 'user_role',
+ 'user_type' => 'current_user_role' // 5.2.0
+ );
+
+ // only replace 'taxonomy' rule if is an ACF4 field group
+ if( $version > 4 ) {
+ unset($replace['taxonomy']);
+ }
+
+ // loop over location groups
+ if( $field_group['location'] ) {
+ foreach( $field_group['location'] as $i => $group ) {
- // param changes
- $replace = array(
- 'taxonomy' => 'post_taxonomy',
- 'ef_media' => 'attachment',
- 'ef_taxonomy' => 'taxonomy',
- 'ef_user' => 'user_role',
- 'user_type' => 'current_user_role' // 5.2.0
- );
-
-
- // remove conflicting param
- if( $version == 5 ) {
-
- unset($replace['taxonomy']);
-
- }
-
-
- // loop over location groups
- foreach( $field_group['location'] as $i => $group ) {
+ // loop over group rules
+ if( $group ) {
+ foreach( $group as $j => $rule ) {
- // bail early if group is empty
- if( empty($group) ) continue;
-
-
- // loop over group rules
- foreach( $group as $ii => $rule ) {
-
- // migrate param
- if( isset($replace[ $rule['param'] ]) ) {
-
- $rule['param'] = $replace[ $rule['param'] ];
-
- }
-
-
- // update
- $group[ $ii ] = $rule;
-
+ // migrate param
+ if( isset($replace[ $rule['param'] ]) ) {
+ $field_group['location'][ $i ][ $j ]['param'] = $replace[ $rule['param'] ];
}
-
-
- // update
- $field_group['location'][ $i ] = $group;
-
- }
-
- }
-
+ }}
+ }}
// change layout to style (v5.0.0)
- if( !empty($field_group['layout']) ) {
-
+ if( isset($field_group['layout']) ) {
$field_group['style'] = acf_extract_var($field_group, 'layout');
-
}
-
// change no_box to seamless (v5.0.0)
if( $field_group['style'] === 'no_box' ) {
-
$field_group['style'] = 'seamless';
-
}
-
//return
return $field_group;
+ }
+
+ /**
+ * validate_post_taxonomy_location_rule
+ *
+ * description
+ *
+ * @date 27/8/18
+ * @since 5.7.4
+ *
+ * @param type $var Description. Default.
+ * @return type Description.
+ */
+ function validate_post_taxonomy_location_rule( $rule ) {
+ // previous versions of ACF (v4.4.12) saved value as term_id
+ // convert term_id into "taxonomy:slug" string
+ if( is_numeric($rule['value']) ) {
+ $term = acf_get_term( $rule['value'] );
+ if( $term ) {
+ $rule['value'] = acf_encode_term($term);
+ }
+ }
+
+ // return
+ return $rule;
}
}
-new acf_compatibility();
+acf_new_instance('ACF_Compatibility');
+
+endif; // class_exists check
?>
\ No newline at end of file
diff --git a/includes/deprecated.php b/includes/deprecated.php
index 0dbaec2..b953324 100644
--- a/includes/deprecated.php
+++ b/includes/deprecated.php
@@ -162,8 +162,8 @@ class acf_deprecated {
function acf_validate_field( $field ) {
// 5.5.6 - changed filter name
- $field = apply_filters( "acf/get_valid_field", $field );
$field = apply_filters( "acf/get_valid_field/type={$field['type']}", $field );
+ $field = apply_filters( "acf/get_valid_field", $field );
// return
diff --git a/includes/fields/class-acf-field-post_object.php b/includes/fields/class-acf-field-post_object.php
index e6ae01c..1639add 100644
--- a/includes/fields/class-acf-field-post_object.php
+++ b/includes/fields/class-acf-field-post_object.php
@@ -221,10 +221,9 @@ class acf_field_post_object extends acf_field {
// optgroup or single
- if( count($args['post_type']) == 1 ) {
-
+ $post_type = acf_get_array( $args['post_type'] );
+ if( count($post_type) == 1 ) {
$results = $results[0]['children'];
-
}
diff --git a/includes/fields/class-acf-field-relationship.php b/includes/fields/class-acf-field-relationship.php
index 2982133..d624ff7 100644
--- a/includes/fields/class-acf-field-relationship.php
+++ b/includes/fields/class-acf-field-relationship.php
@@ -194,7 +194,9 @@ class acf_field_relationship extends acf_field {
// append to $args
- $args['tax_query'] = array();
+ $args['tax_query'] = array(
+ 'relation' => 'OR',
+ );
// now create the tax queries
@@ -393,151 +395,69 @@ class acf_field_relationship extends acf_field {
function render_field( $field ) {
// vars
- $values = array();
+ $post_type = acf_get_array( $field['post_type'] );
+ $taxonomy = acf_get_array( $field['taxonomy'] );
+ $filters = acf_get_array( $field['filters'] );
+
+ // filters
+ $filter_count = count($filters);
+ $filter_post_type_choices = array();
+ $filter_taxonomy_choices = array();
+
+ // post_type filter
+ if( in_array('post_type', $filters) ) {
+
+ $filter_post_type_choices = array(
+ '' => __('Select post type', 'acf')
+ ) + acf_get_pretty_post_types( $post_type );
+ }
+
+ // taxonomy filter
+ if( in_array('taxonomy', $filters) ) {
+
+ $term_choices = array();
+ $filter_taxonomy_choices = array(
+ '' => __('Select taxonomy', 'acf')
+ );
+
+ // check for specific taxonomy setting
+ if( $taxonomy ) {
+ $terms = acf_get_encoded_terms( $taxonomy );
+ $term_choices = acf_get_choices_from_terms( $terms, 'slug' );
+
+ // if no terms were specified, find all terms
+ } else {
+
+ // restrict taxonomies by the post_type selected
+ $term_args = array();
+ if( $post_type ) {
+ $term_args['taxonomy'] = acf_get_taxonomies(array(
+ 'post_type' => $post_type
+ ));
+ }
+
+ // get terms
+ $terms = acf_get_grouped_terms( $term_args );
+ $term_choices = acf_get_choices_from_grouped_terms( $terms, 'slug' );
+ }
+
+ // append term choices
+ $filter_taxonomy_choices = $filter_taxonomy_choices + $term_choices;
+
+ }
+
+ // div attributes
$atts = array(
'id' => $field['id'],
'class' => "acf-relationship {$field['class']}",
'data-min' => $field['min'],
'data-max' => $field['max'],
'data-s' => '',
+ 'data-paged' => 1,
'data-post_type' => '',
'data-taxonomy' => '',
- 'data-paged' => 1,
);
-
- // Lang
- if( defined('ICL_LANGUAGE_CODE') ) {
-
- $atts['data-lang'] = ICL_LANGUAGE_CODE;
-
- }
-
-
- // data types
- $field['post_type'] = acf_get_array( $field['post_type'] );
- $field['taxonomy'] = acf_get_array( $field['taxonomy'] );
- $field['filters'] = acf_get_array( $field['filters'] );
-
-
- // filters
- $filters = array(
- 'count' => count($field['filters']),
- 'search' => false,
- 'post_type' => false,
- 'taxonomy' => false
- );
-
- foreach( $field['filters'] as $filter ) {
- $filters[ $filter ] = true;
- }
-
-
- // filter - post_type
- if( $filters['post_type'] ) {
-
- // choices
- $choices = array(
- '' => __('Select post type', 'acf')
- );
-
-
- // get post types
- $post_types = acf_get_pretty_post_types($field['post_type']);
-
-
- // append
- $choices = $choices + $post_types;
-
-
- // set filter
- $filters['post_type'] = $choices;
-
- }
-
-
-
- // taxonomy filter
- if( $filters['taxonomy'] ) {
-
- // vars
- $groups = array();
- $taxonomies = array();
- $choices = array(
- '' => __('Select taxonomy', 'acf')
- );
-
-
- // get taxonomies from setting
- if( !empty($field['taxonomy']) ) {
-
- $term_groups = acf_decode_taxonomy_terms( $field['taxonomy'] );
- $taxonomies = array_keys($term_groups);
-
- // check empty
- $taxonomies = empty($taxonomies) ? false : $taxonomies;
-
- } elseif( !empty($field['post_type']) ) {
-
- // loop
- foreach( $field['post_type'] as $post_type ) {
-
- // get connected taxonomies
- $post_taxonomies = get_object_taxonomies( $post_type );
-
-
- // loop
- foreach( $post_taxonomies as $name ) {
- $taxonomies[ $name ] = 1;
- }
-
- }
-
-
- // convert back to array
- $taxonomies = array_keys($taxonomies);
-
- // check empty
- $taxonomies = empty($taxonomies) ? false : $taxonomies;
-
- }
-
-
- // terms
- if( $taxonomies !== false ) {
- $groups = acf_get_taxonomy_terms( $taxonomies );
- }
-
-
- // update $term_groups with specific terms
- if( !empty($field['taxonomy']) ) {
-
- foreach( $groups as $taxonomy => $terms ) {
-
- foreach( $terms as $slug => $name ) {
-
- if( !in_array($slug, $field['taxonomy']) ) {
-
- unset($groups[ $taxonomy ][ $slug ]);
-
- }
-
- }
-
- }
-
- }
-
-
- // append
- $choices = $choices + $groups;
-
-
- // set filter
- $filters['taxonomy'] = $choices;
-
- }
-
?>