diff --git a/acf.php b/acf.php index c6063f4..a3978f3 100644 --- a/acf.php +++ b/acf.php @@ -3,7 +3,7 @@ Plugin Name: Advanced Custom Fields PRO Plugin URI: https://www.advancedcustomfields.com/ Description: Customise WordPress with powerful, professional and intuitive fields. -Version: 5.6.2 +Version: 5.6.3 Author: Elliot Condon Author URI: http://www.elliotcondon.com/ Copyright: Elliot Condon @@ -17,8 +17,12 @@ if( ! class_exists('acf') ) : class acf { - // vars - var $version = '5.6.2'; + /** @var string The plugin version number */ + var $version = '5.6.3'; + + + /** @var array The plugin settings array */ + var $settings = array(); /* @@ -234,29 +238,35 @@ class acf { acf_include('includes/fields/class-acf-field-text.php'); acf_include('includes/fields/class-acf-field-textarea.php'); acf_include('includes/fields/class-acf-field-number.php'); + acf_include('includes/fields/class-acf-field-range.php'); acf_include('includes/fields/class-acf-field-email.php'); acf_include('includes/fields/class-acf-field-url.php'); acf_include('includes/fields/class-acf-field-password.php'); + + acf_include('includes/fields/class-acf-field-image.php'); + acf_include('includes/fields/class-acf-field-file.php'); acf_include('includes/fields/class-acf-field-wysiwyg.php'); acf_include('includes/fields/class-acf-field-oembed.php'); - acf_include('includes/fields/class-acf-field-image.php'); - acf_include('includes/fields/class-acf-field-link.php'); - acf_include('includes/fields/class-acf-field-file.php'); + acf_include('includes/fields/class-acf-field-select.php'); acf_include('includes/fields/class-acf-field-checkbox.php'); acf_include('includes/fields/class-acf-field-radio.php'); - acf_include('includes/fields/class-acf-field-range.php'); + acf_include('includes/fields/class-acf-field-button-group.php'); acf_include('includes/fields/class-acf-field-true_false.php'); + + acf_include('includes/fields/class-acf-field-link.php'); acf_include('includes/fields/class-acf-field-post_object.php'); acf_include('includes/fields/class-acf-field-page_link.php'); acf_include('includes/fields/class-acf-field-relationship.php'); acf_include('includes/fields/class-acf-field-taxonomy.php'); acf_include('includes/fields/class-acf-field-user.php'); + acf_include('includes/fields/class-acf-field-google-map.php'); acf_include('includes/fields/class-acf-field-date_picker.php'); acf_include('includes/fields/class-acf-field-date_time_picker.php'); acf_include('includes/fields/class-acf-field-time_picker.php'); acf_include('includes/fields/class-acf-field-color_picker.php'); + acf_include('includes/fields/class-acf-field-message.php'); //acf_include('includes/fields/class-acf-field-separator.php'); acf_include('includes/fields/class-acf-field-tab.php'); diff --git a/assets/css/acf-input.css b/assets/css/acf-input.css index 92a884a..c20a936 100644 --- a/assets/css/acf-input.css +++ b/assets/css/acf-input.css @@ -466,6 +466,15 @@ html[dir="rtl"] input.acf-is-prepended.acf-is-appended { } /*--------------------------------------------------------------------------------------------- * +* Color Picker +* +*---------------------------------------------------------------------------------------------*/ +.acf-color-picker .wp-picker-active { + position: relative; + z-index: 1; +} +/*--------------------------------------------------------------------------------------------- +* * Url * *---------------------------------------------------------------------------------------------*/ @@ -728,6 +737,10 @@ ul.acf-radio-list li span, ul.acf-checkbox-list li span { float: none; } +ul.acf-radio-list li i, +ul.acf-checkbox-list li i { + vertical-align: middle; +} ul.acf-radio-list.acf-hl li, ul.acf-checkbox-list.acf-hl li { margin-right: 20px; @@ -742,6 +755,76 @@ html[dir="rtl"] ul.acf-checkbox-list input[type="radio"] { } /*--------------------------------------------------------------------------------------------- * +* Button Group +* +*---------------------------------------------------------------------------------------------*/ +.acf-button-group { + display: inline-block; + /* default (horizontal) */ + padding-left: 1px; + display: inline-flex; + flex-direction: row; + flex-wrap: nowrap; + /* vertical */ +} +.acf-button-group label { + display: inline-block; + border: #ccc solid 1px; + position: relative; + z-index: 1; + padding: 5px 10px; + background: #fff; +} +.acf-button-group label:hover { + border-color: #999999; + z-index: 2; +} +.acf-button-group label.selected { + border-color: #2b9af3; + background: #309cf3; + color: #fff; + z-index: 2; +} +.acf-button-group label.selected:hover { + background: #48a8f4; +} +.acf-button-group input { + display: none; +} +.acf-button-group label { + margin: 0 0 0 -1px; + flex: 1; + text-align: center; + white-space: nowrap; +} +.acf-button-group label:first-child { + border-radius: 3px 0 0 3px; +} +.acf-button-group label:last-child { + border-radius: 0 3px 3px 0; +} +.acf-button-group label:only-child { + border-radius: 3px; +} +.acf-button-group.-vertical { + padding-left: 0; + padding-top: 1px; + flex-direction: column; +} +.acf-button-group.-vertical label { + margin: -1px 0 0 0; +} +.acf-button-group.-vertical label:first-child { + border-radius: 3px 3px 0 0; +} +.acf-button-group.-vertical label:last-child { + border-radius: 0 0 3px 3px; +} +.acf-button-group.-vertical label:only-child { + border-radius: 3px; +} +/*--------------------------------------------------------------------------------------------- +* * Checkbox * *---------------------------------------------------------------------------------------------*/ @@ -758,10 +841,10 @@ html[dir="rtl"] ul.acf-checkbox-list input[type="radio"] { border-radius: 5px; cursor: pointer; position: relative; - background: #f1f1f1; + background: #f8f8f8; height: 30px; vertical-align: middle; - box-shadow: inset 0 0 1px rgba(0, 0, 0, 0.1); + border: #ccc solid 1px; -webkit-transition: background 0.25s ease; -moz-transition: background 0.25s ease; -o-transition: background 0.25s ease; @@ -789,9 +872,9 @@ html[dir="rtl"] ul.acf-checkbox-list input[type="radio"] { } .acf-switch .acf-switch-slider { position: absolute; - top: 3px; - left: 3px; - bottom: 3px; + top: 2px; + left: 2px; + bottom: 2px; right: 50%; z-index: 1; background: #fff; @@ -801,17 +884,23 @@ html[dir="rtl"] ul.acf-checkbox-list input[type="radio"] { -moz-transition: all 0.25s ease; -o-transition: all 0.25s ease; transition: all 0.25s ease; + transition-property: left, right; } -.acf-switch:hover { - background: #eeeeee; +.acf-switch:hover .acf-switch-slider { + border-color: #b3b3b3; } .acf-switch.-on { - background: #2a9bd9; + background: #309cf3; + border-color: #2b9af3; + /* hover */ } .acf-switch.-on .acf-switch-slider { left: 50%; - right: 3px; - border-color: #1f7db1; + right: 2px; + border-color: #0d84e3; +} +.acf-switch.-on:hover { + background: #48a8f4; } .acf-switch.-focus .acf-switch-slider { border-color: #5b9dd9; @@ -830,6 +919,12 @@ html[dir="rtl"] ul.acf-checkbox-list input[type="radio"] { position: absolute; margin: 0; } +/* in media modal */ +.compat-item .acf-true-false .message { + float: none; + padding: 0; + vertical-align: middle; +} /*-------------------------------------------------------------------------- * * Google Map @@ -1789,7 +1884,7 @@ html[dir="rtl"] .acf-file-uploader .file-info { } .acf-range-wrap input[type="number"] { display: inline-block; - width: 50px; + min-width: 3em; margin-left: 10px; vertical-align: middle; } diff --git a/assets/js/acf-field-group.js b/assets/js/acf-field-group.js index bb032ad..085bd5d 100644 --- a/assets/js/acf-field-group.js +++ b/assets/js/acf-field-group.js @@ -1652,17 +1652,17 @@ // vars - var key = $field.attr('data-key'), - $ancestors = $field.parents('.acf-field-list'), - $tr = $field.find('.acf-field[data-name="conditional_logic"]:last'); + var key = $field.attr('data-key'); + var $lists = $field.parents('.acf-field-list'); + var $tr = $field.find('.acf-field-setting-conditional_logic:last'); // choices var choices = []; - // loop over ancestors - $.each( $ancestors, function( i ){ + // loop over ancestor lists + $.each( $lists, function( i ){ // vars var group = (i == 0) ? acf._e('sibling_fields') : acf._e('parent_fields'); @@ -1679,7 +1679,7 @@ // validate - if( $.inArray(this_type, ['select', 'checkbox', 'true_false', 'radio']) === -1 ) { + if( $.inArray(this_type, ['select', 'checkbox', 'true_false', 'radio', 'button_group']) === -1 ) { return; @@ -1766,7 +1766,7 @@ }); // select - } else if( field_type == "select" || field_type == "checkbox" || field_type == "radio" ) { + } else if( field_type == "select" || field_type == "checkbox" || field_type == "radio" || field_type == "button_group" ) { // vars var lines = $field.find('.acf-field[data-name="choices"] textarea').val().split("\n"); @@ -2179,22 +2179,58 @@ $field: null, $settings: null, + tag: function( tag ) { + + // vars + var type = this.type; + + + // explode, add 'field' and implode + // - open => open_field + // - change_type => change_field_type + var tags = tag.split('_'); + tags.splice(1, 0, 'field'); + tag = tags.join('_'); + + + // add type + if( type ) { + tag += '/type=' + type; + } + + + // return + return tag; + + }, + + selector: function(){ + + // vars + var selector = '.acf-field-object'; + var type = this.type; + + + // add type + if( type ) { + selector += '-' + type; + selector = acf.str_replace('_', '-', selector); + } + + + // return + return selector; + + }, + _add_action: function( name, callback ) { // vars var model = this; - // name - // - open => open_field/type=x - // - change_type => change_field_type/type=x - var names = name.split('_'); - names.splice(1, 0, 'field'); - name = names.join('_') + '/type=' + model.type; - - // add action - acf.add_action(name, function( $field ){ + acf.add_action( this.tag(name), function( $field ){ // focus model.set('$field', $field); @@ -2213,16 +2249,8 @@ var model = this; - // name - // - open => open_field/type=x - // - change_type => change_field_type/type=x - var names = name.split('_'); - names.splice(1, 0, 'field'); - name = names.join('_') + '/type=' + model.type; - - // add action - acf.add_filter(name, function( $field ){ + acf.add_filter( this.tag(name), function( $field ){ // focus model.set('$field', $field); @@ -2238,10 +2266,10 @@ _add_event: function( name, callback ) { // vars - var model = this, - event = name.substr(0,name.indexOf(' ')), - selector = name.substr(name.indexOf(' ')+1), - context = acf.field_group.get_selector(model.type); + var model = this; + var event = name.substr(0,name.indexOf(' ')); + var selector = name.substr(name.indexOf(' ')+1); + var context = this.selector(); // add event diff --git a/assets/js/acf-field-group.min.js b/assets/js/acf-field-group.min.js index c84edd7..1342363 100644 --- a/assets/js/acf-field-group.min.js +++ b/assets/js/acf-field-group.min.js @@ -1 +1 @@ -!function($){acf.field_group=acf.model.extend({$fields:null,$locations:null,$options:null,actions:{ready:"init"},events:{"submit #post":"submit",'click a[href="#"]':"preventDefault","click .submitdelete":"trash","mouseenter .acf-field-list":"sortable"},init:function(){this.$fields=$("#acf-field-group-fields"),this.$locations=$("#acf-field-group-locations"),this.$options=$("#acf-field-group-options"),acf.validation.active=0},sortable:function(e){if(!e.$el.hasClass("ui-sortable")){var t=this;e.$el.sortable({handle:".acf-sortable-handle",connectWith:".acf-field-list",update:function(e,i){var a=i.item;t.render_fields(),acf.do_action("sortstop",a)}})}},preventDefault:function(e){e.preventDefault()},get_selector:function(e){e=e||"";var t=".acf-field-object";return e&&(t+="-"+e,t=t.split("_").join("-")),t},render_fields:function(){var e=this;$(".acf-field-list").each(function(){var t=$(this).children(".acf-field-object");t.each(function(t){e.update_field_meta($(this),"menu_order",t),$(this).children(".handle").find(".acf-icon").html(t+1)}),t.exists()?$(this).children(".no-fields-message").hide():$(this).children(".no-fields-message").show()})},get_field_meta:function(e,t){var i=e.find("> .meta > .input-"+t);return!!i.exists()&&i.val()},update_field_meta:function(e,t,i){var a=e.find("> .meta > .input-"+t);if(!a.exists()){var d=e.find("> .meta > .input-ID").outerHTML();d=acf.str_replace("ID",t,d),a=$(d),a.val(i),e.children(".meta").append(a)}a.val()!=i&&(a.val(i),"save"!=t&&this.save_field(e,"meta"))},delete_field_meta:function(e,t){var i=e.find("> .meta > .input-"+t);i.exists()&&(i.remove(),this.save_field(e,"meta"))},save_field:function(e,t){t=t||"settings";var i=this.get_field_meta(e,"save");"settings"!=i&&i!=t&&(this.update_field_meta(e,"save",t),acf.do_action("save_field",e,t))},submit:function(e){var t=this,i=$("#titlewrap #title");i.val()||(e.preventDefault(),acf.validation.toggle(e.$el,"unlock"),alert(acf._e("title_is_required")),i.focus()),$(".acf-field-object").each(function(){var e=t.get_field_meta($(this),"save"),i=t.get_field_meta($(this),"ID"),a=$(this).hasClass("open");a&&t.close_field($(this)),"settings"==e||("meta"==e?$(this).children(".settings").find('[name^="acf_fields['+i+']"]').remove():$(this).find('[name^="acf_fields['+i+']"]').remove())})},trash:function(e){var t=confirm(acf._e("move_to_trash"));t||e.preventDefault()},render_field:function(e){var t=e.find(".field-label:first").val(),i=e.find(".field-name:first").val(),a=e.find(".field-type:first option:selected").text(),d=e.find(".field-required:first").prop("checked"),n=e.children(".handle");n.find(".li-field-label strong a").text(t),n.find(".li-field-label .acf-required").remove(),d&&n.find(".li-field-label strong").append('*'),n.find(".li-field-name").text(i),n.find(".li-field-type").text(a),acf.do_action("render_field_handle",e,n)},edit_field:function(e){e.hasClass("open")?this.close_field(e):this.open_field(e)},open_field:function(e){return!e.hasClass("open")&&(e.addClass("open"),acf.do_action("open_field",e),void e.children(".settings").animate({height:"toggle"},250))},close_field:function(e){return!!e.hasClass("open")&&(e.removeClass("open"),acf.do_action("close_field",e),void e.children(".settings").animate({height:"toggle"},250))},wipe_field:function(e){var t=e.attr("data-id"),i=e.attr("data-key"),a=acf.get_uniqid(),d="field_"+a;e.attr("data-id",a),e.attr("data-key",d),e.attr("data-orig",i),this.update_field_meta(e,"ID",""),this.update_field_meta(e,"key",d),e.find('[id*="'+t+'"]').each(function(){$(this).attr("id",$(this).attr("id").replace(t,a))}),e.find('[name*="'+t+'"]').each(function(){$(this).attr("name",$(this).attr("name").replace(t,a))}),e.find("> .handle .pre-field-key").text(d),e.find(".ui-sortable").removeClass("ui-sortable"),acf.do_action("wipe_field",e)},add_field:function(e){var t=$($("#tmpl-acf-field").html()),i=t.find(".field-label:first"),a=t.find(".field-name:first");this.wipe_field(t),e.append(t),i.val(""),a.val(""),setTimeout(function(){i.focus()},251),this.render_fields(),acf.do_action("append",t),this.edit_field(t),acf.do_action("add_field",t)},duplicate_field:function(e){acf.do_action("before_duplicate",e);var t=e.clone(),i=t.find(".field-label:first"),a=t.find(".field-name:first");acf.do_action("remove",t),this.wipe_field(t),acf.do_action("after_duplicate",e,t),e.after(t),acf.do_action("append",t),setTimeout(function(){i.focus()},251),this.render_fields(),e.hasClass("open")?this.close_field(e):this.open_field(t);var d=i.val(),n=a.val(),l=n.split("_").pop(),f=acf._e("copy");if(0===l.indexOf(f)){var c=1*l.replace(f,"");c=c?c+1:2,d=d.replace(l,f+c),n=n.replace(l,f+c)}else d+=" ("+f+")",n+="_"+f;return i.val(d),a.val(n),this.save_field(t),this.render_field(t),acf.do_action("duplicate_field",t),t},move_field:function(e){var t=this,i=acf.prepare_for_ajax({action:"acf/field_group/move_field",field_id:this.get_field_meta(e,"ID")}),a=!1;return i.field_id?"settings"==this.get_field_meta(e,"save")?a=!0:e.find(".acf-field-object").each(function(){return t.get_field_meta($(this),"ID")?void("settings"==t.get_field_meta($(this),"save")&&(a=!0)):(a=!0,!1)}):a=!0,a?void alert(acf._e("move_field_warning")):(acf.open_popup({title:acf._e("move_field"),loading:!0,height:145}),void $.ajax({url:acf.get("ajaxurl"),data:i,type:"post",dataType:"html",success:function(i){t.move_field_confirm(e,i)}}))},move_field_confirm:function(e,t){var i=this;acf.update_popup({content:t});var a=acf.prepare_for_ajax({action:"acf/field_group/move_field",field_id:this.get_field_meta(e,"ID"),field_group_id:0});$("#acf-move-field-form").on("submit",function(){return a.field_group_id=$(this).find("select").val(),$.ajax({url:acf.get("ajaxurl"),data:a,type:"post",dataType:"html",success:function(t){acf.update_popup({content:t}),i.remove_field(e)}}),!1})},delete_field:function(e,t){t=t||!0;var i=this.get_field_meta(e,"ID");if(i){var a=$("#_acf_delete_fields");a.val(a.val()+"|"+i)}acf.do_action("delete_field",e),t&&this.remove_field(e)},remove_field:function(e){var t=this,i=e.closest(".acf-field-list");e.css({height:e.height(),width:e.width(),position:"absolute"}),e.wrap('
'),e.animate({opacity:0},250);var a=0,d=!1;i.children(".acf-field-object").length||(d=i.children(".no-fields-message"),a=d.outerHeight()),e.parent(".temp-field-wrap").animate({height:a},250,function(){d&&d.show(),acf.do_action("remove",$(this)),$(this).remove(),t.render_fields()})},change_field_type:function(e){var t=e.closest("tbody"),i=t.closest(".acf-field-object"),a=i.parent().closest(".acf-field-object"),d=i.attr("data-key"),n=i.attr("data-type"),l=e.val();i.removeClass("acf-field-object-"+acf.str_replace("_","-",n)),i.addClass("acf-field-object-"+acf.str_replace("_","-",l)),i.attr("data-type",l),i.data("type",l),i.data("xhr")&&i.data("xhr").abort();var f=t.children('.acf-field[data-setting="'+n+'"]'),c="";if(f.each(function(){c+=$(this).outerHTML()}),f.remove(),acf.update(d+"_settings_"+n,c),this.render_field(i),c=acf.get(d+"_settings_"+l))return t.children('.acf-field[data-name="conditional_logic"]').before(c),acf.update(d+"_settings_"+l,""),void acf.do_action("change_field_type",i);var r=$(''+acf._e("relationship","loading")+"
");var a=$.ajax({url:acf.get("ajaxurl"),dataType:"json",type:"post",data:i,success:function(i){e.set("$field",t).render(i)}});this.$el.data("xhr",a)},render:function(e){if(this.$el.removeClass("is-loading is-empty"),this.$choices.find("p").remove(),!e||!e.results||!e.results.length)return this.$el.addClass("is-empty"),void(1==this.o.paged&&this.$choices.children(".list").append(""+acf._e("relationship","empty")+"
"));var t=$(this.walker(e.results));this.$values.find(".acf-rel-item").each(function(){t.find('.acf-rel-item[data-id="'+$(this).data("id")+'"]').addClass("disabled")}),this.$choices.children(".list").append(t);var i="",a=null;this.$choices.find(".acf-rel-label").each(function(){return $(this).text()==i?(a.append($(this).siblings("ul").html()),void $(this).parent().remove()):(i=$(this).text(),void(a=$(this).siblings("ul")))})},walker:function(e){var t="";if($.isArray(e))for(var i in e)t+=this.walker(e[i]);else $.isPlainObject(e)&&(void 0!==e.children?(t+=''+acf._e("relationship","loading")+"
");var a=$.ajax({url:acf.get("ajaxurl"),dataType:"json",type:"post",data:i,success:function(i){e.set("$field",t).render(i)}});this.$el.data("xhr",a)},render:function(e){if(this.$el.removeClass("is-loading is-empty"),this.$choices.find("p").remove(),!e||!e.results||!e.results.length)return this.$el.addClass("is-empty"),void(1==this.o.paged&&this.$choices.children(".list").append(""+acf._e("relationship","empty")+"
"));var t=$(this.walker(e.results));this.$values.find(".acf-rel-item").each(function(){t.find('.acf-rel-item[data-id="'+$(this).data("id")+'"]').addClass("disabled")}),this.$choices.children(".list").append(t);var i="",a=null;this.$choices.find(".acf-rel-label").each(function(){return $(this).text()==i?(a.append($(this).siblings("ul").html()),void $(this).parent().remove()):(i=$(this).text(),void(a=$(this).siblings("ul")))})},walker:function(e){var t="";if($.isArray(e))for(var i in e)t+=this.walker(e[i]);else $.isPlainObject(e)&&(void 0!==e.children?(t+='__('This is the name which will appear on the EDIT page','acf'), 'name' => 'label', 'type' => 'text', - 'required' => 1, 'class' => 'field-label' ), true); @@ -79,7 +78,6 @@ $atts['class'] = str_replace('_', '-', $atts['class']); 'instructions' => __('Single word, no spaces. Underscores and dashes allowed','acf'), 'name' => 'name', 'type' => 'text', - 'required' => 1, 'class' => 'field-name' ), true); @@ -88,7 +86,6 @@ $atts['class'] = str_replace('_', '-', $atts['class']); acf_render_field_setting($field, array( 'label' => __('Field Type','acf'), 'instructions' => '', - 'required' => 1, 'type' => 'select', 'name' => 'type', 'choices' => acf_get_field_types(), diff --git a/includes/api/api-field.php b/includes/api/api-field.php index 700a149..7c1ed32 100644 --- a/includes/api/api-field.php +++ b/includes/api/api-field.php @@ -284,7 +284,10 @@ function acf_get_field_label( $field ) { $label = $field['label']; - if( $field['required'] ) $label .= ' *'; + // required + if( $field['required'] ) { + $label .= ' *'; + } // filter for 3rd party customization @@ -413,23 +416,21 @@ function acf_render_field_wrap( $field, $el = 'div', $instruction = 'label' ) { if( !$field ) return; - // el - $elements = apply_filters('acf/render_field_wrap/elements', array( + // elements + $elements = array( 'div' => 'div', 'tr' => 'td', 'ul' => 'li', 'ol' => 'li', 'dl' => 'dt', 'td' => 'div' // special case for sub field! - )); + ); - // validate $el - if( !array_key_exists($el, $elements) ) { - - $el = 'div'; - - } + // vars + $el = isset($elements[ $el ]) ? $el : 'div'; + $el2 = $elements[ $el ]; + $show_label = ($el !== 'td') ? true : false; // wrapper @@ -446,9 +447,7 @@ function acf_render_field_wrap( $field, $el = 'div', $instruction = 'label' ) { // add required if( $field['required'] ) { - $wrapper['data-required'] = 1; - } @@ -493,7 +492,7 @@ function acf_render_field_wrap( $field, $el = 'div', $instruction = 'label' ) { if( $el == 'tr' || $el == 'td' ) { - $width = 0; + // do nothing } elseif( $width > 0 && $width < 100 ) { @@ -504,43 +503,87 @@ function acf_render_field_wrap( $field, $el = 'div', $instruction = 'label' ) { // remove empty attributes - foreach( $wrapper as $k => $v ) { + $wrapper = array_filter($wrapper); + + + // html + ?> +< > + + < class="acf-label"> + + + > + + < class="acf-input"> + + + + + + > +> +' . acf_esc_html($label) . ''; } +} + + +/** +* acf_render_field_wrap_description +* +* This function will maybe output the field's instructions +* +* @date 19/9/17 +* @since 5.6.3 +* +* @param array $field +* @return n/a +*/ + +function acf_the_field_wrap_instructions( $field ) { // vars - $show_label = ($el !== 'td') ? true : false; + $instructions = $field['instructions']; -?>< > - - < class="acf-label"> - - -
- - > - - < class="acf-input"> - - - - - > - - - -> -' . acf_esc_html($instructions) . ''; + + } } @@ -1243,7 +1286,7 @@ function acf_update_field( $field = false, $specific = false ) { // allow fields to contain the same name - add_filter( 'wp_unique_post_slug', 'acf_update_field_wp_unique_post_slug', 100, 6 ); + add_filter( 'wp_unique_post_slug', 'acf_update_field_wp_unique_post_slug', 999, 6 ); // slash data @@ -1691,7 +1734,7 @@ function acf_prepare_fields_for_import( $fields = false ) { // allow multiple fields to be returned ($field + $sub_fields) - if( acf_is_sequential_array($field) ) { + if( !isset($field['key']) && isset($field[0]) ) { // merge in $field (1 or more fields) array_splice($fields, $i, 1, $field); diff --git a/includes/api/api-helpers.php b/includes/api/api-helpers.php index 9197fee..998422f 100644 --- a/includes/api/api-helpers.php +++ b/includes/api/api-helpers.php @@ -538,7 +538,7 @@ function acf_nonce_input( $nonce = '' ) { function acf_extract_var( &$array, $key, $default = null ) { // check if exists - if( is_array($array) && array_key_exists($key, $array) ) { + if( is_array($array) && isset($array[ $key ]) ) { // store value $v = $array[ $key ]; diff --git a/includes/api/api-input.php b/includes/api/api-input.php index 73fd0a2..f7fd5de 100644 --- a/includes/api/api-input.php +++ b/includes/api/api-input.php @@ -30,6 +30,75 @@ function acf_esc_html( $string = '' ) { } +/** +* acf_clean_atts +* +* This function will remove empty attributes +* +* @date 3/10/17 +* @since 5.6.3 +* +* @param array $atts +* @return array +*/ + +function acf_clean_atts( $atts = array() ) { + + // loop + foreach( $atts as $k => $v ) { + if( $v === '' ) unset( $atts[ $k ] ); + } + + + // return + return $atts; +} + + +/** +* acf_get_atts +* +* This function will return an array of HTML attributes +* +* @date 2/10/17 +* @since 5.6.3 +* +* @param n/a +* @return n/a +*/ + +/* +function acf_get_atts( $array, $keys ) { + + // vars + $atts = array(); + + + // append attributes + foreach( $keys as $k ) { + if( isset($array[ $k ]) ) $atts[ $k ] = $array[ $k ]; + } + + + // modify special attributes + foreach( array('readonly', 'disabled', 'required') as $k ) { + $atts[ $k ] = $atts[ $k ] ? $k : ''; + } + + + // clean up blank attributes + foreach( $atts as $k => $v ) { + if( $v === '' ) unset( $atts[ $k ] ); + } + + + // return + return $atts; + +} +*/ + + /* * acf_esc_atts * @@ -241,8 +310,9 @@ function acf_textarea_input( $atts = array() ) { function acf_get_checkbox_input( $atts = array() ) { $label = acf_extract_var( $atts, 'label', '' ); + $checked = acf_maybe_get( $atts, 'checked', '' ); $atts['type'] = acf_maybe_get( $atts, 'type', 'checkbox' ); - return ''; + return ''; } diff --git a/includes/api/api-template.php b/includes/api/api-template.php index 5db2eda..8ec0a8d 100644 --- a/includes/api/api-template.php +++ b/includes/api/api-template.php @@ -313,12 +313,8 @@ function get_field_objects( $post_id = false, $format_value = true, $load_value // populate vars foreach( $meta as $k => $v ) { - // Hopefuly improve efficiency: bail early if $k does start with an '_' - if( $k[0] === '_' ) continue; - - // does a field key exist for this value? - if( !array_key_exists("_{$k}", $meta) ) continue; + if( !isset($meta["_{$k}"]) ) continue; // get field diff --git a/includes/fields/class-acf-field-button-group.php b/includes/fields/class-acf-field-button-group.php new file mode 100644 index 0000000..db1dd95 --- /dev/null +++ b/includes/fields/class-acf-field-button-group.php @@ -0,0 +1,292 @@ +name = 'button_group'; + $this->label = __("Button Group",'acf'); + $this->category = 'choice'; + $this->defaults = array( + 'choices' => array(), + 'default_value' => '', + 'allow_null' => 0, + 'return_format' => 'value', + 'layout' => 'horizontal', + ); + + } + + + /** + * render_field() + * + * Creates the field's input HTML + * + * @date 18/9/17 + * @since 5.6.3 + * + * @param array $field The field settings array + * @return n/a + */ + + function render_field( $field ) { + + // vars + $html = ''; + $selected = null; + $buttons = array(); + $value = esc_attr( $field['value'] ); + + + // bail ealrly if no choices + if( empty($field['choices']) ) return; + + + // buttons + foreach( $field['choices'] as $_value => $_label ) { + + // checked + $checked = ( $value === esc_attr($_value) ); + if( $checked ) $selected = true; + + + // append + $buttons[] = array( + 'name' => $field['name'], + 'value' => $_value, + 'label' => $_label, + 'checked' => $checked + ); + + } + + + // maybe select initial value + if( !$field['allow_null'] && $selected === null ) { + $buttons[0]['checked'] = true; + } + + + // div + $div = array( 'class' => 'acf-button-group' ); + + if( $field['layout'] == 'vertical' ) { $div['class'] .= ' -vertical'; } + if( $field['class'] ) { $div['class'] .= ' ' . $field['class']; } + if( $field['allow_null'] ) { $div['data-allow_null'] = 1; } + + + // hdden input + $html .= acf_get_hidden_input( array('name' => $field['name']) ); + + + // open + $html .= '