This commit is contained in:
Elliot Condon 2018-07-19 12:11:52 +02:00 committed by Remco Tolsma
parent 4850443a50
commit 759c7207d5
79 changed files with 26526 additions and 25762 deletions

43
acf.php
View File

@ -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.10
Version: 5.7.0
Author: Elliot Condon
Author URI: http://www.elliotcondon.com/
Copyright: Elliot Condon
@ -18,7 +18,7 @@ if( ! class_exists('ACF') ) :
class ACF {
/** @var string The plugin version number */
var $version = '5.6.10';
var $version = '5.7.0';
/** @var array The plugin settings array */
var $settings = array();
@ -140,11 +140,12 @@ class ACF {
// core
acf_include('includes/assets.php');
acf_include('includes/ajax.php');
acf_include('includes/cache.php');
acf_include('includes/compatibility.php');
acf_include('includes/deprecated.php');
acf_include('includes/input.php');
acf_include('includes/form.php');
acf_include('includes/json.php');
acf_include('includes/local.php');
acf_include('includes/loop.php');
@ -194,7 +195,6 @@ class ACF {
add_action('init', array($this, 'init'), 5);
add_action('init', array($this, 'register_post_types'), 5);
add_action('init', array($this, 'register_post_status'), 5);
add_action('init', array($this, 'register_assets'), 5);
// filters
@ -475,39 +475,6 @@ class ACF {
}
/*
* register_assets
*
* This function will register scripts and styles
*
* @type function
* @date 22/10/2015
* @since 5.3.2
*
* @param n/a
* @return n/a
*/
function register_assets() {
// vars
$version = acf_get_setting('version');
$min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
// scripts
wp_register_script('acf-input', acf_get_url("assets/js/acf-input{$min}.js"), array('jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-resizable'), $version );
wp_register_script('acf-field-group', acf_get_url("assets/js/acf-field-group{$min}.js"), array('acf-input'), $version );
// styles
wp_register_style('acf-global', acf_get_url('assets/css/acf-global.css'), array(), $version );
wp_register_style('acf-input', acf_get_url('assets/css/acf-input.css'), array('acf-global'), $version );
wp_register_style('acf-field-group', acf_get_url('assets/css/acf-field-group.css'), array('acf-input'), $version );
}
/*
* posts_where
*
@ -737,4 +704,4 @@ acf();
endif; // class_exists check
?>
?>

View File

@ -58,7 +58,6 @@
box-shadow: none;
/* metabox */
/* links */
/* no fields */
/* table header */
/* show keys */
/* fields */
@ -75,10 +74,6 @@
outline: none;
box-shadow: none;
}
#acf-field-group-fields .no-fields-message {
padding: 15px 15px;
background: #fff;
}
#acf-field-group-fields .li-field-order {
width: 20%;
}
@ -109,6 +104,16 @@
#acf-field-group-fields .acf-field-list {
background: #F9F9F9;
margin-top: -1px;
/* no fields */
/* empty */
}
#acf-field-group-fields .acf-field-list .no-fields-message {
padding: 15px 15px;
background: #fff;
display: none;
}
#acf-field-group-fields .acf-field-list.-empty .no-fields-message {
display: block;
}
/* field object */
.acf-field-object {
@ -118,6 +123,20 @@
/* meta */
/* handle */
/* open */
/*
// debug
&[data-save="meta"] {
> .handle {
border-left: #ffb700 solid 5px !important;
}
}
&[data-save="settings"] {
> .handle {
border-left: #0ec563 solid 5px !important;
}
}
*/
/* hover */
/* settings */
/* conditional logic */
@ -207,7 +226,8 @@
.acf-field-object.open > .handle .acf-required {
color: #fff;
}
.acf-field-object:hover > .handle .row-options {
.acf-field-object:hover > .handle .row-options,
.acf-field-object.-hover > .handle .row-options {
visibility: visible;
}
.acf-field-object > .settings {
@ -230,6 +250,7 @@
}
.rule-groups .rule-group {
margin: 0 0 5px;
/* Don't allow user to delete the first field group */
}
.rule-groups .rule-group h4 {
margin: 0 0 3px;
@ -246,15 +267,19 @@
.rule-groups .rule-group td.remove {
width: 28px;
vertical-align: middle;
}
.rule-groups .rule-group td.remove a {
visibility: hidden;
}
.rule-groups .rule-group tr:hover td.remove {
.rule-groups .rule-group tr:hover td.remove a {
visibility: visible;
}
/* Don't allow user to delete the first field group */
.rule-groups .rule-group:first-child tr:first-child td.remove {
.rule-groups .rule-group:first-child tr:first-child td.remove a {
visibility: hidden !important;
}
.rule-groups .rule-group select:empty {
background: #f8f8f8;
}
/*---------------------------------------------------------------------------------------------
*
* Options

View File

@ -16,14 +16,6 @@
* General
*
*--------------------------------------------------------------------------------------------*/
/* box-sizing */
/*
[class^="acf-"] {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
*/
/* Horizontal List */
.acf-hl {
padding: 0;
@ -71,18 +63,15 @@
padding: 0;
float: none;
}
/* Full width */
img.acf-fw {
width: 100%;
}
/* Browser */
.acf-visible {
display: block;
visibility: visible;
}
/* Visibility */
.acf-hidden {
display: none;
visibility: visible;
display: none !important;
}
.acf-empty {
display: table-cell !important;
}
.acf-empty * {
display: none !important;
}
/* Float */
.acf-fl {
@ -178,6 +167,7 @@ img.acf-fw {
padding: 5px 10px;
position: absolute;
font-size: 12px;
line-height: 1.4em;
z-index: 900000;
/* tip */
/* positions */
@ -229,6 +219,9 @@ img.acf-fw {
border-left-color: #2F353E;
border-right-width: 0;
}
.acf-tooltip .acf-overlay {
z-index: -1;
}
/* confirm */
.acf-tooltip.-confirm {
z-index: 900001;
@ -240,9 +233,42 @@ img.acf-fw {
.acf-tooltip.-confirm a:hover {
text-decoration: underline;
}
.acf-tooltip.-confirm a.-red {
.acf-tooltip.-confirm a[data-event="confirm"] {
color: #F55E4F;
}
.acf-overlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
cursor: default;
}
.acf-tooltip-target {
position: relative;
z-index: 900002;
}
/*---------------------------------------------------------------------------------------------
*
* loading
*
*---------------------------------------------------------------------------------------------*/
.acf-loading-overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
cursor: default;
z-index: 99;
background: rgba(249, 249, 249, 0.5);
}
.acf-loading-overlay i {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
/*---------------------------------------------------------------------------------------------
*
* callout
@ -614,48 +640,52 @@ a.acf-icon.-cancel.grey:hover {
.acf-box .footer p {
margin: 0;
}
/* error */
.acf-error-message {
/*--------------------------------------------------------------------------------------------
*
* acf-notice
*
*--------------------------------------------------------------------------------------------*/
.acf-notice {
position: relative;
display: block;
background: #F55E4F;
color: #fff;
margin: 5px 0 15px;
padding: 1px 12px;
min-height: 0px;
border-left: #dd4232 solid 4px;
padding: 3px 12px;
background: #2a9bd9;
border-left: #2183b9 solid 4px;
}
.acf-error-message p {
font-size: 13px !important;
.acf-notice p {
font-size: 13px;
line-height: 1.5;
margin: 0.5em 0;
padding: 2px;
text-shadow: none;
color: #fff;
color: inherit;
}
.acf-error-message .acf-icon {
.acf-notice a.acf-notice-dismiss {
position: absolute;
border-color: transparent;
top: 9px;
right: 12px;
background-color: #dd4232;
border-color: transparent;
color: #fff;
background: rgba(0, 0, 0, 0.1);
}
/* important to include .-cancel to override .acf-icon.-cancel class */
.acf-error-message .acf-icon.-cancel:hover {
background-color: #191e23;
color: #F55E4F;
.acf-notice a.acf-notice-dismiss:hover {
background: rgba(0, 0, 0, 0.2);
}
/* success */
.acf-error-message.-success {
background-color: #46b450;
border-color: #32973b;
.acf-notice.-dismiss {
padding-right: 40px;
}
.acf-error-message.-success .acf-icon {
background-color: #32973b;
.acf-notice.-error {
background: #F55E4F;
border-color: #f33b28;
}
.acf-error-message.-success .acf-icon.-cancel:hover {
background-color: #191e23;
color: #46b450;
.acf-notice.-success {
background: #46b450;
border-color: #3b9743;
}
.acf-notice.-warning {
background: #fd8d3b;
border-color: #fd7613;
}
/*--------------------------------------------------------------------------------------------
*
@ -955,6 +985,7 @@ html[dir="rtl"] .acf-columns-2 .acf-column-2 {
left: 0;
right: 0;
bottom: 0;
text-align: center;
}
#acf-popup .bg {
position: absolute;
@ -965,59 +996,69 @@ html[dir="rtl"] .acf-columns-2 .acf-column-2 {
z-index: 0;
background: rgba(0, 0, 0, 0.25);
}
#acf-popup .acf-popup-box {
position: absolute;
z-index: 1;
width: 300px;
height: 300px;
left: 50%;
top: 50%;
margin: -150px 0 0 -150px;
border-color: #aaaaaa;
#acf-popup:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
}
#acf-popup .title .acf-icon {
#acf-popup .acf-popup-box {
display: inline-block;
vertical-align: middle;
z-index: 1;
min-width: 300px;
min-height: 160px;
border-color: #aaaaaa;
box-shadow: 0 5px 30px -5px rgba(0, 0, 0, 0.25);
text-align: left;
}
html[dir="rtl"] #acf-popup .acf-popup-box {
text-align: right;
}
#acf-popup .acf-popup-box .title {
min-height: 15px;
line-height: 15px;
}
#acf-popup .acf-popup-box .title .acf-icon {
position: absolute;
top: 10px;
right: 10px;
}
html[dir="rtl"] #acf-popup .title .acf-icon {
html[dir="rtl"] #acf-popup .acf-popup-box .title .acf-icon {
right: auto;
left: 10px;
}
#acf-popup .acf-popup-box .inner,
#acf-popup .acf-popup-box .inner {
min-height: 50px;
padding: 0;
margin: 15px;
}
#acf-popup .acf-popup-box .loading {
position: absolute;
top: 44px;
top: 45px;
left: 0;
right: 0;
bottom: 0;
z-index: 1;
}
#acf-popup .acf-popup-box .loading {
background: rgba(0, 0, 0, 0.1);
z-index: 2;
border-top: #DDDDDD solid 1px;
background: rgba(0, 0, 0, 0.1);
display: none;
}
#acf-popup .acf-popup-box .loading .acf-loading {
#acf-popup .acf-popup-box .loading i {
position: absolute;
top: 50%;
left: 50%;
margin: -10px 0 0 -10px;
transform: translate(-50%, -50%);
}
#acf-popup .inner > *:first-child {
margin-top: 0;
}
/* submit p */
.acf-submit {
margin-bottom: 0;
line-height: 28px;
}
.acf-submit span {
float: right;
color: #999;
}
.acf-submit .acf-loading {
display: none;
.acf-submit span.-error {
color: #dd4232;
}
.acf-submit .button {
margin-right: 5px;
@ -1129,7 +1170,7 @@ html[dir="rtl"] #acf-popup .title .acf-icon {
width: 25%;
}
/* mobile */
@media screen and (max-width: 782px) {
@media screen and (max-width: 640px) {
.acf-hl[data-cols] {
margin-left: 0;
margin-right: 0;

View File

@ -52,24 +52,33 @@
.acf-field .acf-input > p.description {
margin-top: 5px;
}
.acf-field .acf-error-message {
background: #F55E4F;
color: #fff;
margin: 0 0 10px;
display: inline-block;
border-radius: 3px;
border-left: none;
.acf-field .acf-notice {
margin: 0 0 15px;
background: #edf2ff;
color: #2183b9;
border: none;
}
.acf-field .acf-error-message:after {
content: "";
display: block;
width: 0;
height: 0;
border: transparent 5px solid;
border-top-color: #F55E4F;
position: absolute;
bottom: -10px;
left: 10px;
.acf-field .acf-notice .acf-notice-dismiss {
background: transparent;
color: inherit;
}
.acf-field .acf-notice .acf-notice-dismiss:hover {
background: #fff;
}
.acf-field .acf-notice.-dismiss {
padding-right: 40px;
}
.acf-field .acf-notice.-error {
background: #ffe6e6;
color: #d12626;
}
.acf-field .acf-notice.-success {
background: #eefbe8;
color: #32a23b;
}
.acf-field .acf-notice.-warning {
background: #fff3e6;
color: #d16226;
}
.acf-fieldtd,
.acf-fieldtr {
@ -216,7 +225,7 @@ html[dir="rtl"] .acf-fields.-left > .acf-field > .acf-label {
html[dir="rtl"] .acf-fields.-left > .acf-field > .acf-input {
float: right;
}
@media screen and (max-width: 782px) {
@media screen and (max-width: 640px) {
.acf-fields.-left > .acf-field:before {
display: none;
}
@ -265,9 +274,6 @@ html[dir="rtl"] .acf-fields.-left > .acf-field > .acf-input {
*--------------------------------------------------------------------------------------------*/
.acf-postbox {
position: relative;
/* position high */
/* inside */
/* hndle */
}
#acf_after_title-sortables .acf-postbox {
margin: 20px 0 0;
@ -293,8 +299,7 @@ html[dir="rtl"] .acf-fields.-left > .acf-field > .acf-input {
.acf-postbox > .hndle .acf-hndle-cog:hover {
color: #777777;
}
.acf-postbox > .hndle:hover .acf-hndle-cog,
.acf-postbox > .hndle.hover .acf-hndle-cog {
.acf-postbox:hover > .hndle .acf-hndle-cog {
display: block;
}
.acf-postbox .acf-replace-with-fields {
@ -777,7 +782,7 @@ html[dir="rtl"] ul.acf-checkbox-list input[type="radio"] {
background: #48a8f4;
}
.acf-button-group input {
display: none;
display: none !important;
}
.acf-button-group label {
margin: 0 0 0 -1px;
@ -1291,6 +1296,9 @@ html[dir="rtl"] .acf-relationship .selection .values .acf-icon {
outline: none;
box-shadow: none;
}
.acf-tab-group li a:empty {
display: none;
}
html[dir="rtl"] .acf-tab-group li {
margin: 0 0 0 0.5em;
}
@ -1329,7 +1337,7 @@ html[dir="rtl"] .acf-tab-group li {
/* mobile */
/* rtl */
}
@media screen and (max-width: 782px) {
@media screen and (max-width: 640px) {
.acf-fields.-left > .acf-tab-wrap .acf-tab-group {
padding-left: 10px;
}
@ -1571,8 +1579,7 @@ html[dir="rtl"] .form-table > tbody > tr.acf-tab-wrap .acf-tab-group {
border-bottom: #DFDFDF solid 1px;
padding: 5px 10px;
}
.acf-oembed .title h4,
.acf-oembed .title input[type="text"] {
.acf-oembed .title .input-search {
margin: 0;
font-size: 14px;
line-height: 30px;
@ -1584,16 +1591,9 @@ html[dir="rtl"] .form-table > tbody > tr.acf-tab-wrap .acf-tab-group {
font-family: inherit;
cursor: text;
}
.acf-oembed .title .search {
height: auto;
border: 0 none;
}
.acf-oembed .title .acf-actions {
padding: 6px;
}
.acf-oembed .title:hover .acf-actions {
display: block;
}
.acf-oembed .canvas {
position: relative;
min-height: 250px;
@ -1613,28 +1613,15 @@ html[dir="rtl"] .form-table > tbody > tr.acf-tab-wrap .acf-tab-group {
position: absolute;
top: 50%;
left: 50%;
margin: -21px 0 0 -21px;
transform: translate(-50%, -50%);
z-index: 0;
height: 42px;
width: 42px;
font-size: 42px;
color: #999;
}
.acf-oembed .canvas .canvas-loading {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
.acf-oembed .canvas .acf-loading-overlay {
background: rgba(255, 255, 255, 0.9);
display: none;
z-index: 2;
}
.acf-oembed .canvas .canvas-loading i {
position: absolute;
top: 50%;
left: 50%;
margin: -10px 0 0 -10px;
}
.acf-oembed .canvas .canvas-error {
position: absolute;
@ -1651,42 +1638,14 @@ html[dir="rtl"] .form-table > tbody > tr.acf-tab-wrap .acf-tab-group {
display: inline;
}
.acf-oembed.has-value .canvas {
min-height: 0;
min-height: 50;
}
/* states */
.acf-oembed .title-value {
display: none;
.acf-oembed.has-value .input-search {
font-weight: bold;
}
.acf-oembed .title-search {
.acf-oembed.has-value .title:hover .acf-actions {
display: block;
}
.acf-oembed.has-value .title-value {
display: block;
}
.acf-oembed.has-value .title-search {
display: none;
}
.acf-oembed.has-value .canvas .acf-icon {
display: none;
}
.acf-oembed.is-editing .title-value {
display: none;
}
.acf-oembed.is-editing .title-search {
display: block;
}
.acf-oembed.is-loading .canvas-loading {
display: block;
}
.acf-oembed.is-loading .title .acf-icon {
display: none;
}
.acf-oembed.has-error .canvas-error {
display: block;
}
.acf-oembed.has-error .canvas .acf-icon {
display: none;
}
/*--------------------------------------------------------------------------------------------
*
* Image
@ -1871,7 +1830,7 @@ html[dir="rtl"] .acf-file-uploader .file-info {
.acf-taxonomy-field:hover .acf-actions {
display: block;
}
.acf-taxonomy-field[data-type="select"] .acf-actions {
.acf-taxonomy-field[data-ftype="select"] .acf-actions {
padding: 0;
margin: -9px;
}
@ -2193,7 +2152,6 @@ tr.acf-accordion + tr.acf-accordion {
/* misc */
.media-modal {
/* compat-item */
/* fix % margin which causes .acf-uploadedTo to drop down below select */
/* allow line breaks in upload error */
/* fix required span */
/* sidebar */
@ -2203,18 +2161,6 @@ tr.acf-accordion + tr.acf-accordion {
.media-modal .compat-field-acf-blank {
display: none !important;
}
.media-modal select.attachment-filters {
margin-right: 6px !important;
vertical-align: middle;
}
.media-modal .acf-uploadedTo {
line-height: 28px;
height: 28px;
display: inline-block;
position: relative;
margin: 11px 6px 0 0;
vertical-align: middle;
}
.media-modal .upload-error-message {
white-space: pre-wrap;
}
@ -2262,6 +2208,7 @@ tr.acf-accordion + tr.acf-accordion {
line-height: 18px;
color: #AAAAAA;
font-size: 12px;
/* mobile sm */
}
.media-modal .acf-expand-details:focus,
.media-modal .acf-expand-details:active {
@ -2288,6 +2235,11 @@ tr.acf-accordion + tr.acf-accordion {
.media-modal .acf-expand-details .is-closed {
display: block;
}
@media (max-width: 640px) {
.media-modal .acf-expand-details {
display: none;
}
}
/* expanded */
.media-modal.acf-expanded {
/* toggle */
@ -2371,6 +2323,18 @@ tr.acf-accordion + tr.acf-accordion {
.acf-media-modal .media-embed .setting.link-to {
display: none;
}
@media screen and (min-width: 1024px) {
.acf-media-modal .media-modal-content .media-frame .media-toolbar-secondary {
max-width: none;
}
.acf-media-modal .media-modal-content .media-frame .media-toolbar-secondary select.attachment-filters {
width: auto;
min-width: 150px;
max-width: none;
margin: 11px 6px 0 0;
vertical-align: middle;
}
}
/*---------------------------------------------------------------------------------------------
*
* ACF Media Model (Select Mode)
@ -2390,7 +2354,6 @@ tr.acf-accordion + tr.acf-accordion {
/* hide elements */
/* full width */
/* tidy up incorrect distance */
/* WP4 */
/* title box shadow (to match media grid) */
/* sidebar */
/* mobile md */
@ -2411,9 +2374,6 @@ tr.acf-accordion + tr.acf-accordion {
right: 0;
}
.acf-media-modal.-edit .media-frame-content {
top: 56px;
}
body.major-4 .acf-media-modal.-edit .media-frame-content {
top: 50px;
}
.acf-media-modal.-edit .media-frame-title {
@ -2499,7 +2459,7 @@ body.major-4 .acf-media-modal.-edit .media-frame-content {
}
.form-table > tbody > .acf-field > .acf-label {
padding: 20px 10px 20px 0;
width: 200px;
width: 210px;
/* rtl */
}
html[dir="rtl"] .form-table > tbody > .acf-field > .acf-label {
@ -2526,6 +2486,62 @@ html[dir="rtl"] .form-table > tbody > .acf-tab-wrap td {
.form-table > tbody .form-table th.acf-th {
width: auto;
}
#your-profile,
#createuser {
/* override for user css */
/* allow sub fields to display correctly */
}
#your-profile .acf-field input[type="text"],
#createuser .acf-field input[type="text"],
#your-profile .acf-field input[type="password"],
#createuser .acf-field input[type="password"],
#your-profile .acf-field input[type="number"],
#createuser .acf-field input[type="number"],
#your-profile .acf-field input[type="search"],
#createuser .acf-field input[type="search"],
#your-profile .acf-field input[type="email"],
#createuser .acf-field input[type="email"],
#your-profile .acf-field input[type="url"],
#createuser .acf-field input[type="url"],
#your-profile .acf-field select,
#createuser .acf-field select {
max-width: 25em;
}
#your-profile .acf-field textarea,
#createuser .acf-field textarea {
max-width: 500px;
}
#your-profile .acf-field .acf-field input[type="text"],
#createuser .acf-field .acf-field input[type="text"],
#your-profile .acf-field .acf-field input[type="password"],
#createuser .acf-field .acf-field input[type="password"],
#your-profile .acf-field .acf-field input[type="number"],
#createuser .acf-field .acf-field input[type="number"],
#your-profile .acf-field .acf-field input[type="search"],
#createuser .acf-field .acf-field input[type="search"],
#your-profile .acf-field .acf-field input[type="email"],
#createuser .acf-field .acf-field input[type="email"],
#your-profile .acf-field .acf-field input[type="url"],
#createuser .acf-field .acf-field input[type="url"],
#your-profile .acf-field .acf-field textarea,
#createuser .acf-field .acf-field textarea,
#your-profile .acf-field .acf-field select,
#createuser .acf-field .acf-field select {
max-width: none;
}
#registerform h2 {
margin: 1em 0;
}
#registerform .acf-field .acf-label {
margin-bottom: 0;
}
#registerform .acf-field .acf-label label {
font-weight: normal;
font-size: 14px;
}
#registerform p.submit {
text-align: right;
}
/*--------------------------------------------------------------------------------------------
*
* Term
@ -2592,9 +2608,6 @@ p.submit .acf-spinner {
font-weight: normal;
margin: 0;
}
.widget form > .acf-error-message {
margin-top: 15px;
}
/*--------------------------------------------------------------------------------------------
*
* Nav Menu

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -120,7 +120,6 @@ class acf_admin_field_group {
// filters
add_filter('acf/input/admin_l10n', array($this, 'admin_l10n'));
}
@ -149,6 +148,27 @@ class acf_admin_field_group {
wp_enqueue_script('acf-field-group');
// localize text
acf_localize_text(array(
'The string "field_" may not be used at the start of a field name' => __('The string "field_" may not be used at the start of a field name', 'acf'),
'This field cannot be moved until its changes have been saved' => __('This field cannot be moved until its changes have been saved', 'acf'),
'Field group title is required' => __('Field group title is required', 'acf'),
'Move to trash. Are you sure?' => __('Move to trash. Are you sure?', 'acf'),
'No toggle fields available' => __('No toggle fields available', 'acf'),
'Move Custom Field' => __('Move Custom Field', 'acf'),
'Checked' => __('Checked', 'acf'),
'(no label)' => __('(no label)', 'acf'),
'(this field)' => __('(this field)', 'acf'),
'copy' => __('copy', 'acf'),
'or' => __('or', 'acf'),
'Null' => __('Null', 'acf'),
));
// localize data
acf_localize_data(array(
'fieldTypes' => acf_get_field_types_info()
));
// 3rd party hook
do_action('acf/field_group/admin_enqueue_scripts');
@ -221,7 +241,8 @@ class acf_admin_field_group {
acf_form_data(array(
'screen' => 'field_group',
'post_id' => $post->ID,
'delete_fields' => 0
'delete_fields' => 0,
'validation' => 0
));
}
@ -262,33 +283,7 @@ class acf_admin_field_group {
*/
function admin_l10n( $l10n ) {
// merge in new strings
$l10n = array_merge($l10n, array(
'move_to_trash' => __("Move to trash. Are you sure?",'acf'),
'checked' => __("checked",'acf'),
'no_fields' => __("No toggle fields available",'acf'),
'title_is_required' => __("Field group title is required",'acf'),
'copy' => __("copy",'acf'),
'or' => __("or",'acf'),
'fields' => __("Fields",'acf'),
'parent_fields' => __("Parent fields",'acf'),
'sibling_fields' => __("Sibling fields",'acf'),
'move_field' => __("Move Custom Field",'acf'),
'move_field_warning' => __("This field cannot be moved until its changes have been saved",'acf'),
'null' => __("Null",'acf'),
'unload' => __('The changes you made will be lost if you navigate away from this page','acf'),
'field_name_start' => __('The string "field_" may not be used at the start of a field name','acf'),
));
// 3rd party hook
$l10n = apply_filters('acf/field_group/admin_l10n', $l10n);
// return
return $l10n;
return apply_filters('acf/field_group/admin_l10n', $l10n);
}
@ -427,43 +422,31 @@ class acf_admin_field_group {
// do not save if this is an auto save routine
if( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
return $post_id;
}
// bail early if not acf-field-group
if( $post->post_type !== 'acf-field-group' ) {
return $post_id;
}
// only save once! WordPress save's a revision as well.
if( wp_is_post_revision($post_id) ) {
return $post_id;
}
// verify nonce
if( !acf_verify_nonce('field_group') ) {
return $post_id;
}
// disable filters to ensure ACF loads raw data from DB
acf_disable_filters();
// save fields
if( !empty($_POST['acf_fields']) ) {
if( !empty($_POST['acf_fields']) ) {
// loop
foreach( $_POST['acf_fields'] as $field ) {
// vars
@ -473,28 +456,21 @@ class acf_admin_field_group {
// only saved field if has changed
if( $save == 'meta' ) {
$specific = array(
'menu_order',
'post_parent',
);
}
// set field parent
if( empty($field['parent']) ) {
// set parent
if( !$field['parent'] ) {
$field['parent'] = $post_id;
}
// save field
acf_update_field( $field, $specific );
}
}
@ -695,51 +671,25 @@ class acf_admin_field_group {
function ajax_render_field_settings() {
// validate
if( !acf_verify_ajax() ) die();
// vars
$options = array(
'nonce' => '',
'parent' => 0,
'field_group' => 0,
'prefix' => '',
'type' => '',
);
$field = acf_maybe_get_POST('field');
// check
if( !$field ) die();
// load post options
$options = wp_parse_args($_POST, $options);
// verify nonce
if( !wp_verify_nonce($options['nonce'], 'acf_nonce') ) {
die(0);
}
// required
if( !$options['type'] ) {
die(0);
}
// render options
$field = acf_get_valid_field(array(
'type' => $options['type'],
'name' => 'temp',
'prefix' => $options['prefix'],
'parent' => $options['parent'],
'field_group' => $options['field_group'],
));
// set prefix
$field['prefix'] = acf_maybe_get_POST('prefix');
// validate
$field = acf_get_valid_field( $field );
// render
do_action("acf/render_field_settings/type={$field['type']}", $field);
// die
// return
die();
}

View File

@ -177,7 +177,7 @@ class acf_admin {
}
?>
<div class="notice is-dismissible <?php echo esc_attr($notice['class']); ?> acf-notice"><?php echo $open . $notice['text'] . $close; ?></div>
<div class="acf-admin-notice notice is-dismissible <?php echo esc_attr($notice['class']); ?>"><?php echo $open . $notice['text'] . $close; ?></div>
<?php
}

View File

@ -479,7 +479,11 @@ class ACF_Admin_Tool_Export extends ACF_Admin_Tool {
// tooltip
acf.tooltip.temp('Copied', $a);
acf.newTooltip({
text: "<?php _e('Copied', 'acf' ); ?>",
timeout: 250,
target: $(this),
});
} catch (err) {

View File

@ -15,15 +15,12 @@ if( empty($field['conditional_logic']) ) {
// rule 0
array()
)
);
}
?>
<tr class="acf-field acf-field-true-false acf-field-setting-conditional_logic" data_type="true_false" data-name="conditional_logic">
<tr class="acf-field acf-field-true-false acf-field-setting-conditional_logic" data-type="true_false" data-name="conditional_logic">
<td class="acf-label">
<label><?php _e("Conditional Logic",'acf'); ?></label>
</td>
@ -36,7 +33,7 @@ if( empty($field['conditional_logic']) ) {
'prefix' => $field['prefix'],
'value' => $disabled ? 0 : 1,
'ui' => 1,
'class' => 'conditional-toggle',
'class' => 'conditions-toggle',
));
?>
@ -65,7 +62,7 @@ if( empty($field['conditional_logic']) ) {
// valid rule
$rule = wp_parse_args( $rule, array(
'field' => '',
'operator' => '==',
'operator' => '',
'value' => '',
));
@ -75,23 +72,29 @@ if( empty($field['conditional_logic']) ) {
$rule_id = "rule_{$rule_id}";
$prefix = "{$field['prefix']}[conditional_logic][{$group_id}][{$rule_id}]";
// data attributes
$attributes = array(
'data-id' => $rule_id,
'data-field' => $rule['field'],
'data-operator' => $rule['operator'],
'data-value' => $rule['value']
);
?>
<tr class="rule" data-id="<?php echo $rule_id; ?>">
<tr class="rule" <?php acf_esc_attr_e($attributes); ?>>
<td class="param">
<?php
$choices = array();
$choices[ $rule['field'] ] = $rule['field'];
// create field
acf_render_field(array(
'type' => 'select',
'prefix' => $prefix,
'name' => 'field',
'value' => $rule['field'],
'choices' => $choices,
'class' => 'conditional-rule-param',
'class' => 'condition-rule-field',
'disabled' => $disabled,
'value' => $rule['field'],
'choices' => array(
$rule['field'] => $rule['field']
)
));
?>
@ -99,40 +102,34 @@ if( empty($field['conditional_logic']) ) {
<td class="operator">
<?php
$choices = array(
'==' => __("is equal to",'acf'),
'!=' => __("is not equal to",'acf'),
);
// create field
acf_render_field(array(
'type' => 'select',
'prefix' => $prefix,
'name' => 'operator',
'value' => $rule['operator'],
'choices' => $choices,
'class' => 'conditional-rule-operator',
'class' => 'condition-rule-operator',
'disabled' => $disabled,
'value' => $rule['operator'],
'choices' => array(
$rule['operator'] => $rule['operator']
)
));
?>
</td>
<td class="value">
<?php
$choices = array();
$choices[ $rule['value'] ] = $rule['value'];
// create field
acf_render_field(array(
'type' => 'select',
'prefix' => $prefix,
'name' => 'value',
'value' => $rule['value'],
'choices' => $choices,
'class' => 'conditional-rule-value',
'class' => 'condition-rule-value',
'disabled' => $disabled,
'value' => $rule['value'],
'choices' => array(
$rule['value'] => $rule['value']
)
));
?>

View File

@ -1,12 +1,15 @@
<?php
// add prefix
$field['prefix'] = "acf_fields[{$field['ID']}]";
// vars
$atts = array(
'class' => "acf-field-object acf-field-object-{$field['type']}",
$prefix = 'acf_fields[' . $field['ID'] . ']';
$id = acf_idify( $prefix );
// add prefix
$field['prefix'] = $prefix;
// div
$div = array(
'class' => 'acf-field-object acf-field-object-' . acf_slugify($field['type']),
'data-id' => $field['ID'],
'data-key' => $field['key'],
'data-type' => $field['type'],
@ -16,22 +19,16 @@ $meta = array(
'ID' => $field['ID'],
'key' => $field['key'],
'parent' => $field['parent'],
'menu_order' => $field['menu_order'],
'save' => '',
'menu_order' => $i,
'save' => ''
);
// class
$atts['class'] = str_replace('_', '-', $atts['class']);
?>
<div <?php echo acf_esc_attr( $atts ); ?>>
<div <?php echo acf_esc_attr( $div ); ?>>
<div class="meta">
<?php foreach( $meta as $k => $v ):
acf_hidden_input(array( 'class' => "input-{$k}", 'name' => "{$field['prefix']}[{$k}]", 'value' => $v ));
acf_hidden_input(array( 'name' => $prefix . '[' . $k . ']', 'value' => $v, 'id' => $id . '-' . $k ));
endforeach; ?>
</div>
@ -42,7 +39,7 @@ $atts['class'] = str_replace('_', '-', $atts['class']);
</li>
<li class="li-field-label">
<strong>
<a class="edit-field" title="<?php _e("Edit field",'acf'); ?>" href="#"><?php echo acf_get_field_label($field); ?></a>
<a class="edit-field" title="<?php _e("Edit field",'acf'); ?>" href="#"><?php echo acf_get_field_label($field, 'admin'); ?></a>
</strong>
<div class="row-options">
<a class="edit-field" title="<?php _e("Edit field",'acf'); ?>" href="#"><?php _e("Edit",'acf'); ?></a>
@ -60,7 +57,7 @@ $atts['class'] = str_replace('_', '-', $atts['class']);
<div class="settings">
<table class="acf-table">
<tbody>
<tbody class="acf-field-settings">
<?php
// label
@ -89,7 +86,7 @@ $atts['class'] = str_replace('_', '-', $atts['class']);
'instructions' => '',
'type' => 'select',
'name' => 'type',
'choices' => acf_get_field_types(),
'choices' => acf_get_grouped_field_types(),
'class' => 'field-type'
), true);

View File

@ -8,9 +8,9 @@
<li class="li-field-type"><?php _e('Type','acf'); ?></li>
</ul>
<div class="acf-field-list">
<div class="acf-field-list<?php if( !$fields ){ echo ' -empty'; } ?>">
<div class="no-fields-message" <?php if( $fields ){ echo 'style="display:none;"'; } ?>>
<div class="no-fields-message">
<?php _e("No fields. Click the <strong>+ Add Field</strong> button to create your first field.",'acf'); ?>
</div>

View File

@ -36,7 +36,7 @@ global $field_group;
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
acf.postbox.render({
acf.newPostbox({
'id': 'acf-field-group-locations',
'label': 'left'
});

View File

@ -103,6 +103,27 @@ acf_render_field_wrap(array(
// hide on screen
$choices = array(
'permalink' => __("Permalink", 'acf'),
'the_content' => __("Content Editor",'acf'),
'excerpt' => __("Excerpt", 'acf'),
'custom_fields' => __("Custom Fields", 'acf'),
'discussion' => __("Discussion", 'acf'),
'comments' => __("Comments", 'acf'),
'revisions' => __("Revisions", 'acf'),
'slug' => __("Slug", 'acf'),
'author' => __("Author", 'acf'),
'format' => __("Format", 'acf'),
'page_attributes' => __("Page Attributes", 'acf'),
'featured_image' => __("Featured Image", 'acf'),
'categories' => __("Categories", 'acf'),
'tags' => __("Tags", 'acf'),
'send-trackbacks' => __("Send Trackbacks", 'acf'),
);
if( acf_get_setting('remove_wp_meta_box') ) {
unset( $choices['custom_fields'] );
}
acf_render_field_wrap(array(
'label' => __('Hide on screen','acf'),
'instructions' => __('<b>Select</b> items to <b>hide</b> them from the edit screen.','acf') . '<br /><br />' . __("If multiple field groups appear on an edit screen, the first field group's options will be used (the one with the lowest order number)",'acf'),
@ -111,23 +132,7 @@ acf_render_field_wrap(array(
'prefix' => 'acf_field_group',
'value' => $field_group['hide_on_screen'],
'toggle' => true,
'choices' => array(
'permalink' => __("Permalink", 'acf'),
'the_content' => __("Content Editor",'acf'),
'excerpt' => __("Excerpt", 'acf'),
'custom_fields' => __("Custom Fields", 'acf'),
'discussion' => __("Discussion", 'acf'),
'comments' => __("Comments", 'acf'),
'revisions' => __("Revisions", 'acf'),
'slug' => __("Slug", 'acf'),
'author' => __("Author", 'acf'),
'format' => __("Format", 'acf'),
'page_attributes' => __("Page Attributes", 'acf'),
'featured_image' => __("Featured Image", 'acf'),
'categories' => __("Categories", 'acf'),
'tags' => __("Tags", 'acf'),
'send-trackbacks' => __("Send Trackbacks", 'acf'),
)
'choices' => $choices
));
@ -141,7 +146,7 @@ do_action('acf/render_field_group_settings', $field_group);
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
acf.postbox.render({
acf.newPostbox({
'id': 'acf-field-group-options',
'label': 'left'
});

View File

@ -178,22 +178,20 @@ $button = __('Upgrade Sites');
$input.prop('checked', false);
$input.remove();
// vars
var message = acf.get_ajax_message(json);
var response = '';
// bail early if no message text
if( !message.text ) {
return;
// success
if( acf.isAjaxSuccess(json) ) {
response = acf.getAjaxMessage(json);
} else {
response = acf.getAjaxError(json);
}
// update text
text = '<pre>' + message.text + '</pre>';
if( response ) {
text = '<pre>' + response + '</pre>';
}
},
complete: function(){

View File

@ -65,20 +65,19 @@
success: function( json ){
// vars
var message = acf.get_ajax_message(json);
var response = '';
// bail early if no message text
if( !message.text ) {
return;
// success
if( acf.isAjaxSuccess(json) ) {
response = acf.getAjaxMessage(json);
} else {
response = acf.getAjaxError(json);
}
// show message
$('.show-on-ajax').html( message.text );
// bail early if no message text
if( response ) {
$('.show-on-ajax').html( response );
}
},
complete: function( json ){

View File

@ -227,7 +227,7 @@ function acf_prepare_field( $field ) {
// id attr is generated from name
$field['id'] = str_replace(array('][', '[', ']'), array('-', '-', ''), $field['name']);
$field['id'] = acf_idify( $field['name'] );
// return
@ -278,12 +278,18 @@ function acf_is_sub_field( $field ) {
* @return $label (string)
*/
function acf_get_field_label( $field ) {
function acf_get_field_label( $field, $context = '' ) {
// vars
$label = $field['label'];
// show (no label) when editing field
if( $context == 'admin' && $label === '' ) {
$label = __('(no label)', 'acf');
}
// required
if( $field['required'] ) {
$label .= ' <span class="acf-required">*</span>';
@ -512,6 +518,17 @@ function acf_render_field_wrap( $field, $el = 'div', $instruction = 'label' ) {
$wrapper = array_filter($wrapper);
// conditional logic
if( !empty($field['conditional_logic']) ) {
$field['conditions'] = $field['conditional_logic'];
}
// conditions
if( !empty($field['conditions']) ) {
$wrapper['data-conditions'] = $field['conditions'];
}
// html
?>
<<?php echo $el; ?> <?php acf_esc_attr_e($wrapper); ?>>
@ -527,13 +544,6 @@ function acf_render_field_wrap( $field, $el = 'div', $instruction = 'label' ) {
<<?php echo $el2; ?> class="acf-input">
<?php acf_render_field( $field ); ?>
<?php if( $instruction == 'field' ) acf_render_field_instructions( $field ); ?>
<?php if( !empty($field['conditional_logic']) ): ?>
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
acf.conditional_logic.add( '<?php echo esc_js($field['key']); ?>', <?php echo wp_json_encode( $field['conditional_logic'] ); ?> );
}
</script>
<?php endif; ?>
</<?php echo $el2; ?>>
</<?php echo $el; ?>>
<?php
@ -624,52 +634,38 @@ function acf_render_field_setting( $field, $setting, $global = false ) {
// validate
$setting = acf_get_valid_field( $setting );
// specific
if( !$global ) {
$setting['wrapper']['data-setting'] = $field['type'];
}
// class
// custom key and class
$setting['wrapper']['data-key'] = $setting['name'];
$setting['wrapper']['class'] .= ' acf-field-setting-' . $setting['name'];
// context
if( !$global ) {
$setting['wrapper']['data-setting'] = $field['type'];
}
// copy across prefix
$setting['prefix'] = $field['prefix'];
// attempt find value
if( $setting['value'] === null ) {
// name
if( isset($field[ $setting['name'] ]) ) {
$setting['value'] = $field[ $setting['name'] ];
// default
} elseif( isset($setting['default_value']) ) {
$setting['value'] = $setting['default_value'];
}
}
// append (used by JS to join settings)
if( isset($setting['_append']) ) {
$setting['wrapper']['data-append'] = $setting['_append'];
}
// render
acf_render_field_wrap( $setting, 'tr', 'label' );
}

View File

@ -39,6 +39,37 @@ function acf_is_empty( $value ) {
}
/**
* acf_idify
*
* Returns an id friendly string
*
* @date 24/12/17
* @since 5.6.5
*
* @param type $var Description. Default.
* @return type Description.
*/
function acf_idify( $str = '' ) {
return str_replace(array('][', '[', ']'), array('-', '-', ''), strtolower($str));
}
/**
* acf_slugify
*
* Returns a slug friendly string
*
* @date 24/12/17
* @since 5.6.5
*
* @param type $var Description. Default.
* @return type Description.
*/
function acf_slugify( $str = '' ) {
return str_replace('_', '-', strtolower($str));
}
/**
* acf_has_setting
@ -3160,6 +3191,9 @@ function acf_get_post_id_info( $post_id = 0 ) {
//acf_set_cache($cache_key, $info);
// filter
$info = apply_filters("acf/get_post_id_info", $info, $post_id);
// return
return $info;
@ -3386,8 +3420,7 @@ function acf_upload_file( $uploaded_file ) {
$object = array(
'post_title' => $filename,
'post_mime_type' => $type,
'guid' => $url,
'context' => 'acf-upload'
'guid' => $url
);
// Save the data
@ -3466,20 +3499,25 @@ function acf_update_nested_array( &$array, $ancestors, $value ) {
function acf_is_screen( $id = '' ) {
// bail early if not defined
if( !function_exists('get_current_screen') ) return false;
if( !function_exists('get_current_screen') ) {
return false;
}
// vars
$current_screen = get_current_screen();
// no screen
if( !$current_screen ) {
return false;
// bail early if no screen
if( !$current_screen ) return false;
// return
return ($id === $current_screen->id);
// array
} elseif( is_array($id) ) {
return in_array($current_screen->id, $id);
// string
} else {
return ($id === $current_screen->id);
}
}

View File

@ -401,7 +401,7 @@ function acf_get_select_input( $atts = array() ) {
// html
$html = '';
$html .= '<select ' . acf_esc_atts( $atts ) . '>' . "\n";
$html .= '<select ' . acf_esc_atts( $atts ) . '>';
$html .= acf_walk_select_input( $choices, $value );
$html .= '</select>' . "\n";
@ -447,7 +447,7 @@ function acf_walk_select_input( $choices = array(), $values = array(), $depth =
// optgroup
if( is_array($label) ){
$html .= '<optgroup label="' . esc_attr($value) . '">' . "\n";
$html .= '<optgroup label="' . esc_attr($value) . '">';
$html .= acf_walk_select_input( $label, $values, $depth+1 );
$html .= '</optgroup>';
@ -467,7 +467,7 @@ function acf_walk_select_input( $choices = array(), $values = array(), $depth =
// append
$html .= '<option ' . acf_esc_attr($atts) . '>' . esc_html($label) . '</option>' . "\n";
$html .= '<option ' . acf_esc_attr($atts) . '>' . esc_html($label) . '</option>';
}

477
includes/assets.php Normal file
View File

@ -0,0 +1,477 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('ACF_Assets') ) :
class ACF_Assets {
/** @var array Storage for translations */
var $text = array();
/** @var array Storage for data */
var $data = array();
/**
* __construct
*
* description
*
* @date 10/4/18
* @since 5.6.9
*
* @param void
* @return void
*/
function __construct() {
// actions
add_action('init', array($this, 'register_scripts'));
}
/**
* add_text
*
* description
*
* @date 13/4/18
* @since 5.6.9
*
* @param type $var Description. Default.
* @return type Description.
*/
function add_text( $text ) {
foreach( (array) $text as $k => $v ) {
$this->text[ $k ] = $v;
}
}
/**
* add_data
*
* description
*
* @date 13/4/18
* @since 5.6.9
*
* @param type $var Description. Default.
* @return type Description.
*/
function add_data( $data ) {
foreach( (array) $data as $k => $v ) {
$this->data[ $k ] = $v;
}
}
/**
* register_scripts
*
* description
*
* @date 13/4/18
* @since 5.6.9
*
* @param type $var Description. Default.
* @return type Description.
*/
function register_scripts() {
// vars
$version = acf_get_setting('version');
$min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
// scripts
wp_register_script('acf-input', acf_get_url("assets/js/acf-input{$min}.js"), array('jquery', 'jquery-ui-sortable', 'jquery-ui-resizable'), $version );
wp_register_script('acf-field-group', acf_get_url("assets/js/acf-field-group{$min}.js"), array('acf-input'), $version );
// styles
wp_register_style('acf-global', acf_get_url('assets/css/acf-global.css'), array(), $version );
wp_register_style('acf-input', acf_get_url('assets/css/acf-input.css'), array('acf-global'), $version );
wp_register_style('acf-field-group', acf_get_url('assets/css/acf-field-group.css'), array('acf-input'), $version );
// action
do_action('acf/register_scripts', $version, $min);
}
/**
* enqueue_scripts
*
* Enqueue scripts for input
*
* @date 13/4/18
* @since 5.6.9
*
* @param type $var Description. Default.
* @return type Description.
*/
function enqueue_scripts( $args = array() ) {
// run only once
if( acf_has_done('enqueue_scripts') ) {
return;
}
// defaults
$args = wp_parse_args($args, array(
// force tinymce editor to be enqueued
'uploader' => false,
// priority used for action callbacks, defaults to 20 which runs after defaults
'priority' => 20,
// action prefix
'context' => is_admin() ? 'admin' : 'wp'
));
// define actions
$actions = array(
'admin_enqueue_scripts' => $args['context'] . '_enqueue_scripts',
'admin_print_scripts' => $args['context'] . '_print_scripts',
'admin_head' => $args['context'] . '_head',
'admin_footer' => $args['context'] . '_footer',
'admin_print_footer_scripts' => $args['context'] . '_print_footer_scripts',
);
// fix customizer actions where head and footer are not available
if( $args['context'] == 'customize_controls' ) {
$actions['admin_head'] = $actions['admin_print_scripts'];
$actions['admin_footer'] = $actions['admin_print_footer_scripts'];
}
// add actions
foreach( $actions as $function => $action ) {
acf_maybe_add_action( $action, array($this, $function), $args['priority'] );
}
// enqueue uploader
// WP requires a lot of JS + inline scripes to create the media modal and should be avoioded when possible.
// - priority must be less than 10 to allow WP to enqueue
if( $args['uploader'] ) {
add_action($actions['admin_footer'], 'acf_enqueue_uploader', 5);
}
// enqueue
wp_enqueue_script('acf-input');
wp_enqueue_style('acf-input');
// localize text
acf_localize_text(array(
// unload
'The changes you made will be lost if you navigate away from this page' => __('The changes you made will be lost if you navigate away from this page', 'acf'),
// media
'Select.verb' => _x('Select', 'verb', 'acf'),
'Edit.verb' => _x('Edit', 'verb', 'acf'),
'Update.verb' => _x('Update', 'verb', 'acf'),
'Uploaded to this post' => __('Uploaded to this post', 'acf'),
'Expand Details' => __('Expand Details', 'acf'),
'Collapse Details' => __('Collapse Details', 'acf'),
'Restricted' => __('Restricted', 'acf'),
'All images' => __('All images', 'acf'),
// validation
'Validation successful' => __('Validation successful', 'acf'),
'Validation failed' => __('Validation failed', 'acf'),
'1 field requires attention' => __('1 field requires attention', 'acf'),
'%d fields require attention' => __('%d fields require attention', 'acf'),
// tooltip
'Are you sure?' => __('Are you sure?','acf'),
'Yes' => __('Yes','acf'),
'No' => __('No','acf'),
'Remove' => __('Remove','acf'),
'Cancel' => __('Cancel','acf'),
// conditions
'Has any value' => __('Has any value', 'acf'),
'Has no value' => __('Has no value', 'acf'),
'Value is equal to' => __('Value is equal to', 'acf'),
'Value is not equal to' => __('Value is not equal to', 'acf'),
'Value matches pattern' => __('Value matches pattern', 'acf'),
'Value contains' => __('Value contains', 'acf'),
'Value is greater than' => __('Value is greater than', 'acf'),
'Value is less than' => __('Value is less than', 'acf'),
'Selection is greater than' => __('Selection is greater than', 'acf'),
'Selection is less than' => __('Selection is less than', 'acf'),
));
// action
do_action('acf/enqueue_scripts');
}
/**
* admin_enqueue_scripts
*
* description
*
* @date 16/4/18
* @since 5.6.9
*
* @param type $var Description. Default.
* @return type Description.
*/
function admin_enqueue_scripts() {
// vars
$text = array();
// actions
do_action('acf/admin_enqueue_scripts');
do_action('acf/input/admin_enqueue_scripts');
// only include translated strings
foreach( $this->text as $k => $v ) {
if( str_replace('.verb', '', $k) !== $v ) {
$text[ $k ] = $v;
}
}
// localize text
if( $text ) {
wp_localize_script( 'acf-input', 'acfL10n', $text );
}
}
/**
* admin_print_scripts
*
* description
*
* @date 18/4/18
* @since 5.6.9
*
* @param type $var Description. Default.
* @return type Description.
*/
function admin_print_scripts() {
do_action('acf/admin_print_scripts');
}
/**
* admin_head
*
* description
*
* @date 16/4/18
* @since 5.6.9
*
* @param type $var Description. Default.
* @return type Description.
*/
function admin_head() {
// actions
do_action('acf/admin_head');
do_action('acf/input/admin_head');
}
/**
* admin_footer
*
* description
*
* @date 16/4/18
* @since 5.6.9
*
* @param type $var Description. Default.
* @return type Description.
*/
function admin_footer() {
// global
global $wp_version;
// get data
$data = wp_parse_args($this->data, array(
'screen' => acf_get_form_data('screen'),
'post_id' => acf_get_form_data('post_id'),
'nonce' => wp_create_nonce( 'acf_nonce' ),
'admin_url' => admin_url(),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'validation' => acf_get_form_data('validation'),
'wp_version' => $wp_version,
'acf_version' => acf_get_setting('version'),
'browser' => acf_get_browser(),
'locale' => acf_get_locale(),
'rtl' => is_rtl()
));
// get l10n (old)
$l10n = apply_filters( 'acf/input/admin_l10n', array() );
// todo: force 'acf-input' script enqueue if not yet included
// - fixes potential timing issue if acf_enqueue_assest() was called during body
// localize data
?>
<script type="text/javascript">
acf.data = <?php echo wp_json_encode($data); ?>;
acf.l10n = <?php echo wp_json_encode($l10n); ?>;
</script>
<?php
// actions
do_action('acf/admin_footer');
do_action('acf/input/admin_footer');
// trigger prepare
?>
<script type="text/javascript">
acf.doAction('prepare');
</script>
<?php
}
/**
* admin_print_footer_scripts
*
* description
*
* @date 18/4/18
* @since 5.6.9
*
* @param type $var Description. Default.
* @return type Description.
*/
function admin_print_footer_scripts() {
do_action('acf/admin_print_footer_scripts');
}
/*
* enqueue_uploader
*
* This function will render a WP WYSIWYG and enqueue media
*
* @type function
* @date 27/10/2014
* @since 5.0.9
*
* @param n/a
* @return n/a
*/
function enqueue_uploader() {
// run only once
if( acf_has_done('enqueue_uploader') ) {
return;
}
// bail early if doing ajax
if( acf_is_ajax() ) {
return;
}
// enqueue media if user can upload
if( current_user_can('upload_files') ) {
wp_enqueue_media();
}
// create dummy editor
?>
<div id="acf-hidden-wp-editor" class="acf-hidden">
<?php wp_editor( '', 'acf_content' ); ?>
</div>
<?php
}
}
// instantiate
acf_new_instance('ACF_Assets');
endif; // class_exists check
/**
* acf_localize_text
*
* description
*
* @date 13/4/18
* @since 5.6.9
*
* @param type $var Description. Default.
* @return type Description.
*/
function acf_localize_text( $text ) {
return acf_get_instance('ACF_Assets')->add_text( $text );
}
/**
* acf_localize_data
*
* description
*
* @date 13/4/18
* @since 5.6.9
*
* @param type $var Description. Default.
* @return type Description.
*/
function acf_localize_data( $data ) {
return acf_get_instance('ACF_Assets')->add_data( $data );
}
/*
* acf_enqueue_scripts
*
*
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_enqueue_scripts( $args = array() ) {
return acf_get_instance('ACF_Assets')->enqueue_scripts( $args );
}
/*
* acf_enqueue_uploader
*
* This function will render a WP WYSIWYG and enqueue media
*
* @type function
* @date 27/10/2014
* @since 5.0.9
*
* @param n/a
* @return n/a
*/
function acf_enqueue_uploader() {
return acf_get_instance('ACF_Assets')->enqueue_uploader();
}
?>

View File

@ -279,23 +279,18 @@ class acf_compatibility {
if( !empty($field['date_format']) ) {
// extract vars
$date_format = acf_extract_var( $field, 'date_format' );
$display_format = acf_extract_var( $field, 'display_format' );
$date_format = $field['date_format'];
$display_format = $field['display_format'];
// convert from js to php
//$date_format = acf_convert_date_to_php( $date_format );
$display_format = acf_convert_date_to_php( $display_format );
// bail early if already matches 'Ymd'
if( $date_format === 'yymmdd' ) return $field;
// append settings
$field['display_format'] = $display_format;
$field['save_format'] = $date_format;
// clean up
unset($field['date_format']);
}

View File

@ -6,7 +6,6 @@ if( ! class_exists('acf_fields') ) :
class acf_fields {
/** @var array Contains an array of field type instances */
var $types = array();
@ -25,16 +24,14 @@ class acf_fields {
*/
function __construct() {
/* do nothing */
}
/*
* register_field_type
*
* This function will store a field type class
* This function will register a field type instance
*
* @type function
* @date 6/07/2016
@ -46,24 +43,22 @@ class acf_fields {
function register_field_type( $class ) {
// allow instance
if( $class instanceOf acf_field ) {
$this->types[ $class->name ] = $class;
// allow class name
} else {
$instance = new $class();
$this->types[ $instance->name ] = $instance;
}
}
/*
* get_field_type
*
* This function will return a field type class
* This function will return a field type instance
*
* @type function
* @date 6/07/2016
@ -74,9 +69,7 @@ class acf_fields {
*/
function get_field_type( $name ) {
return isset( $this->types[$name] ) ? $this->types[$name] : null;
}
@ -94,9 +87,7 @@ class acf_fields {
*/
function is_field_type( $name ) {
return isset( $this->types[$name] );
}
@ -104,7 +95,7 @@ class acf_fields {
* register_field_type_info
*
* This function will store a basic array of info about the field type
* to later be overriden by the avbove register_field_type function
* to later be overriden by the above register_field_type function
*
* @type function
* @date 29/5/17
@ -119,14 +110,13 @@ class acf_fields {
// convert to object
$instance = (object) $info;
$this->types[ $instance->name ] = $instance;
}
}
/*
* get_field_types
*
* This function will return an array of all field type infos
* This function will return an array of all field types
*
* @type function
* @date 6/07/2016
@ -137,46 +127,8 @@ class acf_fields {
*/
function get_field_types() {
// vars
$groups = array();
$l10n = array(
'basic' => __('Basic', 'acf'),
'content' => __('Content', 'acf'),
'choice' => __('Choice', 'acf'),
'relational' => __('Relational', 'acf'),
'jquery' => __('jQuery', 'acf'),
'layout' => __('Layout', 'acf'),
);
// loop
foreach( $this->types as $type ) {
// bail ealry if not public
if( !$type->public ) continue;
// translate
$cat = $type->category;
$cat = isset( $l10n[$cat] ) ? $l10n[$cat] : $cat;
// append
$groups[ $cat ][ $type->name ] = $type->label;
}
// filter
$groups = apply_filters('acf/get_field_types', $groups);
// return
return $groups;
return $this->types;
}
}
@ -200,29 +152,7 @@ endif; // class_exists check
*/
function acf_register_field_type( $class ) {
return acf()->fields->register_field_type( $class );
}
/*
* acf_get_field_type
*
* alias of acf()->fields->get_field_type()
*
* @type function
* @date 31/5/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_get_field_type( $name ) {
return acf()->fields->get_field_type( $name );
}
@ -240,9 +170,25 @@ function acf_get_field_type( $name ) {
*/
function acf_register_field_type_info( $info ) {
return acf()->fields->register_field_type_info( $info );
}
/*
* acf_get_field_type
*
* alias of acf()->fields->get_field_type()
*
* @type function
* @date 31/5/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_get_field_type( $name ) {
return acf()->fields->get_field_type( $name );
}
@ -259,10 +205,51 @@ function acf_register_field_type_info( $info ) {
* @return n/a
*/
function acf_get_field_types() {
function acf_get_field_types( $args = array() ) {
return acf()->fields->get_field_types();
// default
$args = wp_parse_args($args, array(
'public' => true, // true, false
));
// get field types
$field_types = acf()->fields->get_field_types();
// filter
return wp_filter_object_list( $field_types, $args );
}
/**
* acf_get_field_types_info
*
* Returns an array containing information about each field type
*
* @date 18/6/18
* @since 5.6.9
*
* @param type $var Description. Default.
* @return type Description.
*/
function acf_get_field_types_info( $args = array() ) {
// vars
$data = array();
$field_types = acf_get_field_types();
// loop
foreach( $field_types as $type ) {
$data[ $type->name ] = array(
'label' => $type->label,
'name' => $type->name,
'category' => $type->category,
'public' => $type->public
);
}
// return
return $data;
}
@ -280,9 +267,7 @@ function acf_get_field_types() {
*/
function acf_is_field_type( $name = '' ) {
return acf()->fields->is_field_type( $name );
}
@ -300,10 +285,8 @@ function acf_is_field_type( $name = '' ) {
*/
function acf_get_field_type_prop( $name = '', $prop = '' ) {
$type = acf_get_field_type( $name );
return ($type && isset($type->$prop)) ? $type->$prop : null;
}
@ -321,10 +304,8 @@ function acf_get_field_type_prop( $name = '', $prop = '' ) {
*/
function acf_get_field_type_label( $name = '' ) {
$type = acf_get_field_type( $name );
return $type ? $type->label : '<span class="acf-tooltip-js" title="'.__('Field type does not exist', 'acf').'">'.__('Unknown', 'acf').'</span>';
$label = acf_get_field_type_prop( $name, 'label' );
return $label ? $label : '<span class="acf-tooltip-js" title="'.__('Field type does not exist', 'acf').'">'.__('Unknown', 'acf').'</span>';
}
@ -347,9 +328,9 @@ function acf_field_type_exists( $type = '' ) {
/*
* acf_get_grouped_field_types (deprecated)
* acf_get_grouped_field_types
*
* deprecated in favour of acf_get_field_types()
* Returns an multi-dimentional array of field types "name => label" grouped by category
*
* @type function
* @date 1/10/13
@ -360,7 +341,38 @@ function acf_field_type_exists( $type = '' ) {
*/
function acf_get_grouped_field_types() {
return acf_get_field_types();
// vars
$types = acf_get_field_types();
$groups = array();
$l10n = array(
'basic' => __('Basic', 'acf'),
'content' => __('Content', 'acf'),
'choice' => __('Choice', 'acf'),
'relational' => __('Relational', 'acf'),
'jquery' => __('jQuery', 'acf'),
'layout' => __('Layout', 'acf'),
);
// loop
foreach( $types as $type ) {
// translate
$cat = $type->category;
$cat = isset( $l10n[$cat] ) ? $l10n[$cat] : $cat;
// append
$groups[ $cat ][ $type->name ] = $type->label;
}
// filter
$groups = apply_filters('acf/get_field_types', $groups);
// return
return $groups;
}
?>

View File

@ -366,7 +366,12 @@ class acf_field_checkbox extends acf_field {
'name' => 'save_custom',
'type' => 'true_false',
'ui' => 1,
'message' => __("Save 'custom' values to the field's choices", 'acf')
'message' => __("Save 'custom' values to the field's choices", 'acf'),
'conditions' => array(
'field' => 'allow_custom',
'operator' => '==',
'value' => 1
)
));

View File

@ -29,49 +29,6 @@ class acf_field_date_picker extends acf_field {
'return_format' => 'd/m/Y',
'first_day' => 1
);
$this->l10n = array(
'closeText' => _x('Done', 'Date Picker JS closeText', 'acf'),
'currentText' => _x('Today', 'Date Picker JS currentText', 'acf'),
'nextText' => _x('Next', 'Date Picker JS nextText', 'acf'),
'prevText' => _x('Prev', 'Date Picker JS prevText', 'acf'),
'weekHeader' => _x('Wk', 'Date Picker JS weekHeader', 'acf'),
);
// actions
add_action('init', array($this, 'init'));
}
/*
* init
*
* This function is run on the 'init' action to set the field's $l10n data. Before the init action,
* access to the $wp_locale variable is not possible.
*
* @type action (init)
* @date 3/09/13
*
* @param n/a
* @return n/a
*/
function init() {
// globals
global $wp_locale;
// append
$this->l10n = array_merge($this->l10n, array(
'monthNames' => array_values( $wp_locale->month ),
'monthNamesShort' => array_values( $wp_locale->month_abbrev ),
'dayNames' => array_values( $wp_locale->weekday ),
'dayNamesMin' => array_values( $wp_locale->weekday_initial ),
'dayNamesShort' => array_values( $wp_locale->weekday_abbrev )
));
}
@ -91,16 +48,32 @@ class acf_field_date_picker extends acf_field {
function input_admin_enqueue_scripts() {
// bail ealry if no enqueue
if( !acf_get_setting('enqueue_datepicker') ) return;
if( !acf_get_setting('enqueue_datepicker') ) {
return;
}
// localize
global $wp_locale;
acf_localize_data(array(
'datePickerL10n' => array(
'closeText' => _x('Done', 'Date Picker JS closeText', 'acf'),
'currentText' => _x('Today', 'Date Picker JS currentText', 'acf'),
'nextText' => _x('Next', 'Date Picker JS nextText', 'acf'),
'prevText' => _x('Prev', 'Date Picker JS prevText', 'acf'),
'weekHeader' => _x('Wk', 'Date Picker JS weekHeader', 'acf'),
'monthNames' => array_values( $wp_locale->month ),
'monthNamesShort' => array_values( $wp_locale->month_abbrev ),
'dayNames' => array_values( $wp_locale->weekday ),
'dayNamesMin' => array_values( $wp_locale->weekday_initial ),
'dayNamesShort' => array_values( $wp_locale->weekday_abbrev )
)
));
// script
wp_enqueue_script('jquery-ui-datepicker');
// style
wp_enqueue_style('acf-datepicker', acf_get_url('assets/inc/datepicker/jquery-ui.min.css'), '', '1.11.4' );
wp_enqueue_style('acf-datepicker', acf_get_url('assets/inc/datepicker/jquery-ui.min.css'), array(), '1.11.4' );
}

View File

@ -29,28 +29,6 @@ class acf_field_date_and_time_picker extends acf_field {
'return_format' => 'd/m/Y g:i a',
'first_day' => 1
);
$this->l10n = array(
'timeOnlyTitle' => _x('Choose Time', 'Date Time Picker JS timeOnlyTitle', 'acf'),
'timeText' => _x('Time', 'Date Time Picker JS timeText', 'acf'),
'hourText' => _x('Hour', 'Date Time Picker JS hourText', 'acf'),
'minuteText' => _x('Minute', 'Date Time Picker JS minuteText', 'acf'),
'secondText' => _x('Second', 'Date Time Picker JS secondText', 'acf'),
'millisecText' => _x('Millisecond', 'Date Time Picker JS millisecText', 'acf'),
'microsecText' => _x('Microsecond', 'Date Time Picker JS microsecText', 'acf'),
'timezoneText' => _x('Time Zone', 'Date Time Picker JS timezoneText', 'acf'),
'currentText' => _x('Now', 'Date Time Picker JS currentText', 'acf'),
'closeText' => _x('Done', 'Date Time Picker JS closeText', 'acf'),
'selectText' => _x('Select', 'Date Time Picker JS selectText', 'acf'),
'amNames' => array(
_x('AM', 'Date Time Picker JS amText', 'acf'),
_x('A', 'Date Time Picker JS amTextShort', 'acf'),
),
'pmNames' => array(
_x('PM', 'Date Time Picker JS pmText', 'acf'),
_x('P', 'Date Time Picker JS pmTextShort', 'acf'),
)
);
}
@ -84,6 +62,30 @@ class acf_field_date_and_time_picker extends acf_field {
// style
wp_enqueue_style('acf-timepicker', acf_get_url('assets/inc/timepicker/jquery-ui-timepicker-addon.min.css'), '', $version);
// localize
acf_localize_data(array(
'dateTimePickerL10n' => array(
'timeOnlyTitle' => _x('Choose Time', 'Date Time Picker JS timeOnlyTitle', 'acf'),
'timeText' => _x('Time', 'Date Time Picker JS timeText', 'acf'),
'hourText' => _x('Hour', 'Date Time Picker JS hourText', 'acf'),
'minuteText' => _x('Minute', 'Date Time Picker JS minuteText', 'acf'),
'secondText' => _x('Second', 'Date Time Picker JS secondText', 'acf'),
'millisecText' => _x('Millisecond', 'Date Time Picker JS millisecText', 'acf'),
'microsecText' => _x('Microsecond', 'Date Time Picker JS microsecText', 'acf'),
'timezoneText' => _x('Time Zone', 'Date Time Picker JS timezoneText', 'acf'),
'currentText' => _x('Now', 'Date Time Picker JS currentText', 'acf'),
'closeText' => _x('Done', 'Date Time Picker JS closeText', 'acf'),
'selectText' => _x('Select', 'Date Time Picker JS selectText', 'acf'),
'amNames' => array(
_x('AM', 'Date Time Picker JS amText', 'acf'),
_x('A', 'Date Time Picker JS amTextShort', 'acf'),
),
'pmNames' => array(
_x('PM', 'Date Time Picker JS pmText', 'acf'),
_x('P', 'Date Time Picker JS pmTextShort', 'acf'),
)
)
));
}

View File

@ -31,17 +31,33 @@ class acf_field_file extends acf_field {
'max_size' => 0,
'mime_types' => ''
);
$this->l10n = array(
'select' => __("Select File",'acf'),
'edit' => __("Edit File",'acf'),
'update' => __("Update File",'acf'),
'uploadedTo' => __("Uploaded to this post",'acf'),
);
// filters
add_filter('get_media_item_args', array($this, 'get_media_item_args'));
add_filter('get_media_item_args', array($this, 'get_media_item_args'));
}
/*
* input_admin_enqueue_scripts
*
* description
*
* @type function
* @date 16/12/2015
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_enqueue_scripts() {
// localize
acf_localize_text(array(
'Select File' => __('Select File', 'acf'),
'Edit File' => __('Edit File', 'acf'),
'Update File' => __('Update File', 'acf'),
));
}

View File

@ -36,11 +36,63 @@ class acf_field_google_map extends acf_field {
'center_lng' => '144.96328',
'zoom' => '14'
);
$this->l10n = array(
'locating' => __("Locating",'acf'),
'browser_support' => __("Sorry, this browser does not support geolocation",'acf'),
);
}
/*
* input_admin_enqueue_scripts
*
* description
*
* @type function
* @date 16/12/2015
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_enqueue_scripts() {
// localize
acf_localize_text(array(
'Sorry, this browser does not support geolocation' => __('Sorry, this browser does not support geolocation', 'acf'),
));
// bail ealry if no enqueue
if( !acf_get_setting('enqueue_google_maps') ) {
return;
}
// vars
$api = array(
'key' => acf_get_setting('google_api_key'),
'client' => acf_get_setting('google_api_client'),
'libraries' => 'places',
'ver' => 3,
'callback' => ''
);
// filter
$api = apply_filters('acf/fields/google_map/api', $api);
// remove empty
if( empty($api['key']) ) unset($api['key']);
if( empty($api['client']) ) unset($api['client']);
// construct url
$url = add_query_arg($api, 'https://maps.googleapis.com/maps/api/js');
// localize
acf_localize_data(array(
'google_map_api' => $url
));
}
@ -102,7 +154,7 @@ class acf_field_google_map extends acf_field {
<div class="acf-hidden">
<?php foreach( $field['value'] as $k => $v ):
acf_hidden_input(array( 'name' => $field['name'].'['.$k.']', 'value' => $v, 'class' => 'input-'.$k ));
acf_hidden_input(array( 'name' => $field['name'].'['.$k.']', 'value' => $v, 'data-name' => $k ));
endforeach; ?>
</div>
@ -252,56 +304,6 @@ class acf_field_google_map extends acf_field {
// return
return $value;
}
/*
* input_admin_footer
*
* description
*
* @type function
* @date 6/03/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_footer() {
// bail ealry if no qneueu
if( !acf_get_setting('enqueue_google_maps') ) return;
// vars
$api = array(
'key' => acf_get_setting('google_api_key'),
'client' => acf_get_setting('google_api_client'),
'libraries' => 'places',
'ver' => 3,
'callback' => ''
);
// filter
$api = apply_filters('acf/fields/google_map/api', $api);
// remove empty
if( empty($api['key']) ) unset($api['key']);
if( empty($api['client']) ) unset($api['client']);
// construct url
$url = add_query_arg($api, 'https://maps.googleapis.com/maps/api/js');
?>
<script type="text/javascript">
if( acf ) acf.fields.google_map.url = '<?php echo $url; ?>';
</script>
<?php
}
}

View File

@ -36,14 +36,6 @@ class acf_field_image extends acf_field {
'max_size' => 0,
'mime_types' => ''
);
$this->l10n = array(
'select' => __("Select Image",'acf'),
'edit' => __("Edit Image",'acf'),
'update' => __("Update Image",'acf'),
'uploadedTo' => __("Uploaded to this post",'acf'),
'all' => __("All images",'acf'),
);
// filters
add_filter('get_media_item_args', array($this, 'get_media_item_args'));
@ -51,6 +43,31 @@ class acf_field_image extends acf_field {
}
/*
* input_admin_enqueue_scripts
*
* description
*
* @type function
* @date 16/12/2015
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_enqueue_scripts() {
// localize
acf_localize_text(array(
'Select Image' => __('Select Image', 'acf'),
'Edit Image' => __('Edit Image', 'acf'),
'Update Image' => __('Update Image', 'acf'),
'All images' => __('All images', 'acf'),
));
}
/*
* render_field()

View File

@ -202,45 +202,32 @@ class acf_field_oembed extends acf_field {
'class' => 'acf-oembed',
);
// <strong><?php _e("Error.", 'acf'); </strong> _e("No embed found for the given URL.", 'acf');
// value
if( $field['value'] ) $atts['class'] .= ' has-value';
?>
<div <?php acf_esc_attr_e($atts) ?>>
<?php acf_hidden_input(array( 'name' => $field['name'], 'value' => $field['value'], 'data-name' => 'value-input' )); ?>
<?php acf_hidden_input(array( 'class' => 'input-value', 'name' => $field['name'], 'value' => $field['value'] )); ?>
<div class="title">
<div class="title-value">
<h4 data-name="value-title"><?php echo esc_html( $field['value'] ); ?></h4>
</div>
<div class="title-search">
<input data-name="search-input" type="text" placeholder="<?php _e("Enter URL", 'acf'); ?>" autocomplete="off" />
</div>
<?php acf_text_input(array( 'class' => 'input-search', 'value' => $field['value'], 'placeholder' => __("Enter URL", 'acf'), 'autocomplete' => 'off' )); ?>
<div class="acf-actions -hover">
<a data-name="clear-button" href="#" class="acf-icon -cancel grey"></a>
</div>
</div>
<div class="canvas">
<div class="canvas-loading">
<i class="acf-loading"></i>
<div class="canvas-media">
<?php if( $field['value'] ) {
echo $this->wp_oembed_get($field['value'], $field['width'], $field['height']);
} ?>
</div>
<div class="canvas-error">
<p><strong><?php _e("Error.", 'acf'); ?></strong> <?php _e("No embed found for the given URL.", 'acf'); ?></p>
</div>
<div class="canvas-media" data-name="value-embed">
<?php if( $field['value'] ) echo $this->wp_oembed_get($field['value'], $field['width'], $field['height']); ?>
</div>
<i class="acf-icon -picture hide-if-value"></i>
</div>
</div>
<?php

View File

@ -267,7 +267,12 @@ class acf_field_radio extends acf_field {
'name' => 'save_other_choice',
'type' => 'true_false',
'ui' => 1,
'message' => __("Save 'other' values to the field's choices", 'acf')
'message' => __("Save 'other' values to the field's choices", 'acf'),
'conditions' => array(
'field' => 'other_choice',
'operator' => '==',
'value' => 1
)
));

View File

@ -33,13 +33,6 @@ class acf_field_relationship extends acf_field {
'elements' => array(),
'return_format' => 'object'
);
$this->l10n = array(
'min' => __("Minimum values reached ( {min} values )",'acf'),
'max' => __("Maximum values reached ( {max} values )",'acf'),
'loading' => __('Loading','acf'),
'empty' => __('No matches found','acf'),
);
// extra
add_action('wp_ajax_acf/fields/relationship/query', array($this, 'ajax_query'));
@ -48,6 +41,31 @@ class acf_field_relationship extends acf_field {
}
/*
* input_admin_enqueue_scripts
*
* description
*
* @type function
* @date 16/12/2015
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_enqueue_scripts() {
// localize
acf_localize_text(array(
//'Minimum values reached ( {min} values )' => __('Minimum values reached ( {min} values )', 'acf'),
'Maximum values reached ( {max} values )' => __('Maximum values reached ( {max} values )', 'acf'),
'Loading' => __('Loading', 'acf'),
'No matches found' => __('No matches found', 'acf'),
));
}
/*
* ajax_query
*
@ -565,10 +583,10 @@ class acf_field_relationship extends acf_field {
<div class="selection">
<div class="choices">
<ul class="acf-bl list"></ul>
<ul class="acf-bl list choices-list"></ul>
</div>
<div class="values">
<ul class="acf-bl list">
<ul class="acf-bl list values-list">
<?php if( !empty($field['value']) ):
// get posts

View File

@ -34,20 +34,6 @@ class acf_field_select extends acf_field {
'placeholder' => '',
'return_format' => 'value'
);
$this->l10n = array(
'matches_1' => _x('One result is available, press enter to select it.', 'Select2 JS matches_1', 'acf'),
'matches_n' => _x('%d results are available, use up and down arrow keys to navigate.', 'Select2 JS matches_n', 'acf'),
'matches_0' => _x('No matches found', 'Select2 JS matches_0', 'acf'),
'input_too_short_1' => _x('Please enter 1 or more characters', 'Select2 JS input_too_short_1', 'acf' ),
'input_too_short_n' => _x('Please enter %d or more characters', 'Select2 JS input_too_short_n', 'acf' ),
'input_too_long_1' => _x('Please delete 1 character', 'Select2 JS input_too_long_1', 'acf' ),
'input_too_long_n' => _x('Please delete %d characters', 'Select2 JS input_too_long_n', 'acf' ),
'selection_too_long_1' => _x('You can only select 1 item', 'Select2 JS selection_too_long_1', 'acf' ),
'selection_too_long_n' => _x('You can only select %d items', 'Select2 JS selection_too_long_n', 'acf' ),
'load_more' => _x('Loading more results&hellip;', 'Select2 JS load_more', 'acf' ),
'searching' => _x('Searching&hellip;', 'Select2 JS searching', 'acf' ),
'load_fail' => _x('Loading failed', 'Select2 JS load_fail', 'acf' ),
);
// ajax
@ -118,6 +104,24 @@ class acf_field_select extends acf_field {
wp_enqueue_script('select2', $script, array('jquery'), $version );
wp_enqueue_style('select2', $style, '', $version );
// localize
acf_localize_data(array(
'select2L10n' => array(
'matches_1' => _x('One result is available, press enter to select it.', 'Select2 JS matches_1', 'acf'),
'matches_n' => _x('%d results are available, use up and down arrow keys to navigate.', 'Select2 JS matches_n', 'acf'),
'matches_0' => _x('No matches found', 'Select2 JS matches_0', 'acf'),
'input_too_short_1' => _x('Please enter 1 or more characters', 'Select2 JS input_too_short_1', 'acf' ),
'input_too_short_n' => _x('Please enter %d or more characters', 'Select2 JS input_too_short_n', 'acf' ),
'input_too_long_1' => _x('Please delete 1 character', 'Select2 JS input_too_long_1', 'acf' ),
'input_too_long_n' => _x('Please delete %d characters', 'Select2 JS input_too_long_n', 'acf' ),
'selection_too_long_1' => _x('You can only select 1 item', 'Select2 JS selection_too_long_1', 'acf' ),
'selection_too_long_n' => _x('You can only select %d items', 'Select2 JS selection_too_long_n', 'acf' ),
'load_more' => _x('Loading more results&hellip;', 'Select2 JS load_more', 'acf' ),
'searching' => _x('Searching&hellip;', 'Select2 JS searching', 'acf' ),
'load_fail' => _x('Loading failed', 'Select2 JS load_fail', 'acf' ),
)
));
}
@ -262,13 +266,34 @@ class acf_field_select extends acf_field {
}
// prepend empty choice for single inputs
$prepend = false;
if( !$field['multiple'] ) {
// allow null or ajax
if( $field['allow_null'] || $field['ajax'] ) {
$prepend = true;
}
}
// allow null
// - have tried array_merge but this causes keys to re-index if is numeric (post ID's)
if( $field['allow_null'] && !$field['multiple'] ) {
$prepend = array('' => '- ' . $field['placeholder'] . ' -');
$choices = $prepend + $choices;
if( $prepend ) {
$placeholder = '- ' . $field['placeholder'] . ' -';
$choices = array( '' => $placeholder ) + $choices;
}
// clean up choices if using ajax
if( $field['ajax'] ) {
$minimal = array();
foreach( $value as $key ) {
if( isset($choices[ $key ]) ) {
$minimal[ $key ] = $choices[ $key ];
}
}
$choices = $minimal;
}
@ -287,11 +312,10 @@ class acf_field_select extends acf_field {
// multiple
if( $field['multiple'] ) {
$select['multiple'] = 'multiple';
$select['size'] = 5;
$select['name'] .= '[]';
}
@ -301,34 +325,12 @@ class acf_field_select extends acf_field {
if( !empty($field['ajax_action']) ) $select['data-ajax_action'] = $field['ajax_action'];
// hidden input
if( $field['ui'] ) {
$v = $value;
if( $field['multiple'] ) {
$v = implode('||', $v);
} else {
$v = acf_maybe_get($v, 0, '');
}
acf_hidden_input(array(
'id' => $field['id'] . '-input',
'name' => $field['name'],
'value' => $v
));
} elseif( $field['multiple'] ) {
// hidden input is needed to allow validation to see <select> element with no selected value
if( $field['multiple'] || $field['ui'] ) {
acf_hidden_input(array(
'id' => $field['id'] . '-input',
'name' => $field['name']
));
}
@ -418,6 +420,11 @@ class acf_field_select extends acf_field {
'name' => 'ajax',
'type' => 'true_false',
'ui' => 1,
'conditions' => array(
'field' => 'ui',
'operator' => '==',
'value' => 1
)
));

View File

@ -568,8 +568,9 @@ class acf_field_taxonomy extends acf_field {
$div = array(
'class' => 'acf-taxonomy-field',
'data-save' => $field['save_terms'],
'data-type' => $field['field_type'],
'data-taxonomy' => $field['taxonomy']
'data-ftype' => $field['field_type'],
'data-taxonomy' => $field['taxonomy'],
'data-allow_null' => $field['allow_null']
);
@ -722,23 +723,13 @@ class acf_field_taxonomy extends acf_field {
$args = apply_filters('acf/fields/taxonomy/wp_list_categories/name=' . $field['_name'], $args, $field);
$args = apply_filters('acf/fields/taxonomy/wp_list_categories/key=' . $field['key'], $args, $field);
?><div class="categorychecklist-holder">
<ul class="acf-checkbox-list acf-bl">
<?php if( $field['field_type'] == 'radio' && $field['allow_null'] ): ?>
<li>
<label class="selectit">
<input type="radio" name="<?php echo esc_attr($field['name']); ?>" value="" /> <?php _e("None", 'acf'); ?>
</label>
</li>
<?php endif; ?>
<?php wp_list_categories( $args ); ?>
</ul>
</div><?php
?>
<div class="categorychecklist-holder">
<ul class="acf-checkbox-list acf-bl">
<?php wp_list_categories( $args ); ?>
</ul>
</div>
<?php
}
@ -795,6 +786,11 @@ class acf_field_taxonomy extends acf_field {
'name' => 'allow_null',
'type' => 'true_false',
'ui' => 1,
'conditions' => array(
'field' => 'field_type',
'operator' => '!=',
'value' => 'checkbox'
)
));
@ -994,7 +990,10 @@ class acf_field_taxonomy extends acf_field {
}
?><p class="acf-submit"><button class="acf-button button button-primary" type="submit"><?php _e("Add", 'acf'); ?></button><i class="acf-spinner"></i><span></span></p></form><?php
?><p class="acf-submit">
<button class="acf-submit-button button button-primary" type="submit"><?php _e("Add", 'acf'); ?></button>
</p>
</form><?php
// die

View File

@ -156,7 +156,12 @@ class acf_field_true_false extends acf_field {
'instructions' => __('Text shown when active','acf'),
'type' => 'text',
'name' => 'ui_on_text',
'placeholder' => __('Yes', 'acf')
'placeholder' => __('Yes', 'acf'),
'conditions' => array(
'field' => 'ui',
'operator' => '==',
'value' => 1
)
));
@ -166,7 +171,12 @@ class acf_field_true_false extends acf_field {
'instructions' => __('Text shown when inactive','acf'),
'type' => 'text',
'name' => 'ui_off_text',
'placeholder' => __('No', 'acf')
'placeholder' => __('No', 'acf'),
'conditions' => array(
'field' => 'ui',
'operator' => '==',
'value' => 1
)
));
}

View File

@ -35,7 +35,6 @@ class acf_field_wysiwyg extends acf_field {
// add acf_the_content filters
$this->add_filters();
}
@ -166,67 +165,55 @@ class acf_field_wysiwyg extends acf_field {
/*
* input_admin_footer
*
* description
*
* @type function
* @date 6/03/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_footer() {
// vars
$json = array();
* input_admin_enqueue_scripts
*
* description
*
* @type function
* @date 16/12/2015
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_enqueue_scripts() {
// vars
$data = array();
$toolbars = $this->get_toolbars();
// bail ealry if no toolbars
if( empty($toolbars) ) {
return;
}
// loop through toolbars
// loop
foreach( $toolbars as $label => $rows ) {
// vars
$label = sanitize_title( $label );
$label = str_replace('-', '_', $label);
$key = $label;
$key = sanitize_title( $key );
$key = str_replace('-', '_', $key);
// append to $json
$json[ $label ] = array();
// append
$data[ $key ] = array();
// convert to strings
if( !empty($rows) ) {
if( $rows ) {
foreach( $rows as $i => $row ) {
$json[ $label ][ $i ] = implode(',', $row);
$data[ $key ][ $i ] = implode(',', $row);
}
}
}
?>
<script type="text/javascript">
if( acf ) acf.tinymce.toolbars = <?php echo wp_json_encode($json); ?>;
</script>
<?php
}
// localize
acf_localize_data(array(
'toolbars' => $data
));
}
/*
* render_field()
@ -434,7 +421,12 @@ class acf_field_wysiwyg extends acf_field {
'instructions' => '',
'type' => 'select',
'name' => 'toolbar',
'choices' => $choices
'choices' => $choices,
'conditions' => array(
'field' => 'tabs',
'operator' => '!=',
'value' => 'text'
)
));
@ -455,6 +447,11 @@ class acf_field_wysiwyg extends acf_field {
'name' => 'delay',
'type' => 'true_false',
'ui' => 1,
'conditions' => array(
'field' => 'tabs',
'operator' => '!=',
'value' => 'text'
)
));
}

277
includes/form.php Normal file
View File

@ -0,0 +1,277 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('ACF_Form') ) :
class ACF_Form {
/** @var array Storage for data */
var $data = array();
/*
* __construct
*
* This function will setup the class functionality.
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param void
* @return void
*/
function __construct() {
// actions
add_action('acf/save_post', array($this, '_save_post'), 10, 1);
}
/*
* set_data
*
* Sets data.
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param array $data An array of data.
* @return array
*/
function set_data( $data = array() ) {
// defaults
$data = wp_parse_args($data, array(
'screen' => 'post', // Current screen loaded (post, user, taxonomy, etc)
'post_id' => 0, // ID of current post being edited
'nonce' => '', // nonce used for $_POST validation (defaults to screen)
'validation' => 1, // enables form validation
'changed' => 0, // used by revisions and unload to detect change
));
// crete nonce
$data['nonce'] = wp_create_nonce($data['screen']);
// update
$this->data = $data;
// return
return $data;
}
/*
* get_data
*
* Returns data.
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param string $name The data anme.
* @return mixed The data.
*/
function get_data( $name = false ) {
return isset($this->data[ $name ]) ? $this->data[ $name ] : null;
}
/**
* render_data
*
* Renders the <div id="acf-form-data"> element with hidden "form data" inputs
*
* @date 17/4/18
* @since 5.6.9
*
* @param array $data An array of data.
* @return void
*/
function render_data( $data = array() ) {
// set form data
$data = $this->set_data( $data );
?>
<div id="acf-form-data" class="acf-hidden">
<?php
// loop
foreach( $data as $name => $value ) {
// input
acf_hidden_input(array(
'id' => '_acf_' . $name,
'name' => '_acf_' . $name,
'value' => $value
));
}
// actions
do_action('acf/form_data', $data);
do_action('acf/input/form_data', $data);
?>
</div>
<?php
}
/**
* save_post
*
* Calls the 'acf/save_post' action allowing $_POST data to be saved
*
* @date 17/4/18
* @since 5.6.9
*
* @param mixed $post_id The $post_id used to save data to the DB
* @param array $values Optional. An optional array of data to be saved (modifies $_POST['acf'])
* @return boolean Returns true on success.
*/
function save_post( $post_id = 0, $values = null ) {
// override $_POST
if( $values !== null ) {
$_POST['acf'] = $values;
}
// bail early if no values
if( empty($_POST['acf']) ) {
return false;
}
// set form data
$this->set_data(array(
'post_id' => $post_id
));
// action
do_action('acf/save_post', $post_id);
// return
return true;
}
/**
* _save_post
*
* Saves the actual $_POST['acf'] data.
* Performing this logic within an action allows developers to hook in before and after data is saved.
*
* @date 24/10/2014
* @since 5.0.9
*
* @param mixed $post_id The $post_id used to save data to the DB
* @return void.
*/
function _save_post( $post_id ) {
// bail early if empty
// - post data may have be modified
if( empty($_POST['acf']) ) {
return;
}
// loop
foreach( $_POST['acf'] as $key => $value ) {
// get field
$field = acf_get_field( $key );
// update
if( $field ) {
acf_update_value( $value, $post_id, $field );
}
}
}
}
// instantiate
acf_new_instance('ACF_Form');
endif; // class_exists check
/*
* acf_get_form_data
*
* alias of acf()->form->get_data()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_get_form_data( $name = '' ) {
return acf_get_instance('ACF_Form')->get_data( $name );
}
/*
* acf_set_form_data
*
* alias of acf()->form->set_data()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_set_form_data( $data = array() ) {
return acf_get_instance('ACF_Form')->set_data( $data );
}
/*
* acf_form_data
*
* description
*
* @type function
* @date 15/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_form_data( $data = array() ) {
return acf_get_instance('ACF_Form')->render_data( $data );
}
/*
* acf_save_post
*
* description
*
* @type function
* @date 15/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_save_post( $post_id = 0, $values = null ) {
return acf_get_instance('ACF_Form')->save_post( $post_id, $values );
}
?>

View File

@ -14,7 +14,6 @@ if( ! class_exists('acf_form_attachment') ) :
class acf_form_attachment {
/*
* __construct
*
@ -44,48 +43,6 @@ class acf_form_attachment {
}
/*
* validate_page
*
* This function will check if the current page is for a post/page edit form
*
* @type function
* @date 23/06/12
* @since 3.1.8
*
* @param n/a
* @return (boolean)
*/
function validate_page() {
// global
global $pagenow, $typenow, $wp_version;
// validate page
if( $pagenow === 'post.php' && $typenow === 'attachment' ) {
return true;
}
// validate page
if( $pagenow === 'upload.php' && version_compare($wp_version, '4.0', '>=') ) {
add_action('admin_footer', array($this, 'admin_footer'), 0);
return true;
}
// return
return false;
}
/*
* admin_enqueue_scripts
*
@ -102,17 +59,20 @@ class acf_form_attachment {
function admin_enqueue_scripts() {
// bail early if not valid page
if( !$this->validate_page() ) {
// bail early if not valid screen
if( !acf_is_screen(array('attachment', 'upload')) ) {
return;
}
// load acf scripts
acf_enqueue_scripts();
// load acf scripts
acf_enqueue_scripts(array(
'uploader' => true,
));
// actions
if( acf_is_screen('upload') ) {
add_action('admin_footer', array($this, 'admin_footer'), 0);
}
}
@ -135,7 +95,6 @@ class acf_form_attachment {
acf_form_data(array(
'screen' => 'attachment',
'post_id' => 0,
'ajax' => 1
));
?>
@ -166,7 +125,7 @@ acf.unload.active = 0;
function edit_attachment( $form_fields, $post ) {
// vars
$is_page = $this->validate_page();
$is_page = acf_is_screen('attachment');
$post_id = $post->ID;
$el = 'tr';
$args = array(

View File

@ -183,7 +183,7 @@ class acf_form_comment {
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
acf.postbox.render(<?php echo json_encode($o); ?>);
acf.newPostbox(<?php echo json_encode($o); ?>);
}
</script>
@ -231,6 +231,10 @@ class acf_form_comment {
if( !$field_groups ) return $html;
// enqueue scripts
acf_enqueue_scripts();
// ob
ob_start();

View File

@ -29,7 +29,7 @@ class acf_form_customizer {
// actions
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('customize_controls_init', array($this, 'customize_controls_init'));
add_action('customize_preview_init', array($this, 'customize_preview_init'), 1, 1);
add_action('customize_save', array($this, 'customize_save'), 1, 1);
@ -54,14 +54,12 @@ class acf_form_customizer {
* @return N/A
*/
function admin_enqueue_scripts() {
// validate screen
if( !acf_is_screen('customize') ) return;
function customize_controls_init() {
// load acf scripts
acf_enqueue_scripts();
acf_enqueue_scripts(array(
'context' => 'customize_controls'
));
// actions

View File

@ -83,7 +83,7 @@ class ACF_Form_Post {
// update vars
if( !empty($post) ) {
$this->post_id = $post->ID;
$this->post_id = (int) $post->ID;
$this->typenow = $typenow;
}
@ -134,7 +134,9 @@ class ACF_Form_Post {
// load acf scripts
acf_enqueue_scripts();
acf_enqueue_scripts(array(
'uploader' => true,
));
// actions
@ -299,8 +301,8 @@ class ACF_Form_Post {
'key' => $field_group['key'],
'style' => $field_group['style'],
'label' => $field_group['label_placement'],
'edit_url' => '',
'edit_title' => __('Edit field group', 'acf'),
'editLink' => '',
'editTitle' => __('Edit field group', 'acf'),
'visibility' => $visibility
);
@ -308,7 +310,7 @@ class ACF_Form_Post {
// edit_url
if( $field_group['ID'] && acf_current_user_can_admin() ) {
$o['edit_url'] = admin_url('post.php?post=' . $field_group['ID'] . '&action=edit');
$o['editLink'] = admin_url('post.php?post=' . $field_group['ID'] . '&action=edit');
}
@ -334,7 +336,7 @@ class ACF_Form_Post {
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
acf.postbox.render(<?php echo json_encode($o); ?>);
acf.newPostbox(<?php echo json_encode($o); ?>);
}
</script>

View File

@ -14,7 +14,7 @@ if( ! class_exists('acf_form_taxonomy') ) :
class acf_form_taxonomy {
var $form = '#addtag';
var $view = 'add';
/*
@ -140,7 +140,7 @@ class acf_form_taxonomy {
// update vars
$this->form = '#addtag';
$this->view = 'add';
// get field groups
@ -195,7 +195,7 @@ class acf_form_taxonomy {
// update vars
$this->form = '#edittag';
$this->view = 'edit';
// get field groups
@ -252,66 +252,42 @@ class acf_form_taxonomy {
(function($) {
// vars
var $spinner = $('<?php echo $this->form; ?> p.submit .spinner');
var view = '<?php echo $this->view; ?>';
// create spinner if not exists (may exist in future WP versions)
if( !$spinner.exists() ) {
// create spinner
$spinner = $('<span class="spinner"></span>');
// append
$('<?php echo $this->form; ?> p.submit').append( $spinner );
// add missing spinners
var $submit = $('input.button-primary');
if( !$submit.next('.spinner').length ) {
$submit.after('<span class="spinner"></span>');
}
<?php
// update acf validation class
acf.validation.error_class = 'form-invalid';
<?php if( $this->form == '#addtag' ): ?>
// store origional HTML
var $el = $('#acf-term-fields');
var html = $el.html();
// add view
if( $this->view == 'add' ): ?>
// events
$('#submit').on('click', function( e ){
// vars
var $form = $('#addtag');
var $fields = $('#acf-term-fields');
var html = $fields.html();
// bail early if not active
if( !acf.validation.active ) {
return true;
// WP triggers click as primary action
$submit.on('click', function( e ){
// validate
var valid = acf.validateForm({
form: $form,
event: e,
lock: false
});
// if not valid, stop event and allow validation to continue
if( !valid ) {
e.preventDefault();
e.stopImmediatePropagation();
}
// ignore validation (only ignore once)
if( acf.validation.ignore ) {
acf.validation.ignore = 0;
return true;
}
// bail early if this form does not contain ACF data
if( !$('#acf-form-data').exists() ) {
return true;
}
// stop WP JS validation
e.stopImmediatePropagation();
// store submit trigger so it will be clicked if validation is passed
acf.validation.$trigger = $(this);
// run validation
acf.validation.fetch( $('#addtag') );
// stop all other click events on this input
return false;
});
// listen to AJAX add-tag complete
$(document).ajaxComplete(function(event, xhr, settings) {
// bail early if is other ajax call
@ -319,26 +295,22 @@ class acf_form_taxonomy {
return;
}
// unlock form
acf.validation.toggle( $('#addtag'), 'unlock' );
// bail early if response contains error
if( xhr.responseText.indexOf('wp_error') !== -1 ) {
return;
}
// action for 3rd party customization
acf.do_action('remove', $el);
acf.doAction('remove', $fields);
// restore html
$el.html( html );
// reset unload
acf.unload.off();
// reset HTML
$fields.html( html );
// action for 3rd party customization
acf.do_action('append', $el);
acf.doAction('append', $fields);
// reset unload
acf.unload.reset();
});
<?php endif; ?>
@ -433,4 +405,4 @@ new acf_form_taxonomy();
endif;
?>
?>

View File

@ -1,20 +1,13 @@
<?php
<?php
/*
* ACF User Form Class
*
* All the logic for adding fields to users
*
* @class acf_form_user
* @package ACF
* @subpackage Forms
*/
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_form_user') ) :
if( ! class_exists('ACF_Form_User') ) :
class acf_form_user {
class ACF_Form_User {
var $form = '#createuser';
/** @var string The current view (new, edit, register) */
var $view = '';
/*
@ -32,138 +25,117 @@ class acf_form_user {
function __construct() {
// actions
// enqueue
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('login_form_register', array($this, 'admin_enqueue_scripts'));
add_action('login_form_register', array($this, 'login_form_register'));
// render
add_action('show_user_profile', array($this, 'edit_user'));
add_action('edit_user_profile', array($this, 'edit_user'));
add_action('user_new_form', array($this, 'user_new_form'));
add_action('register_form', array($this, 'register_user'));
add_action('show_user_profile', array($this, 'render_edit'));
add_action('edit_user_profile', array($this, 'render_edit'));
add_action('user_new_form', array($this, 'render_new'));
add_action('register_form', array($this, 'render_register'));
// save
//add_action('edit_user_profile_update', array($this, 'save_user'));
//add_action('personal_options_update', array($this, 'save_user'));
add_action('user_register', array($this, 'save_user'));
add_action('profile_update', array($this, 'save_user'));
}
/*
* validate_page
*
* This function will check if the current page is for a post/page edit form
*
* @type function
* @date 23/06/12
* @since 3.1.8
*
* @param N/A
* @return (boolean)
*/
function validate_page() {
// global
global $pagenow;
// validate page
if( in_array( $pagenow, array('profile.php', 'user-edit.php', 'user-new.php', 'wp-login.php') ) ) {
return true;
}
// return
return false;
}
/*
/**
* admin_enqueue_scripts
*
* This action is run after post query but before any admin script / head actions.
* It is a good place to register all actions.
* Checks current screen and enqueues scripts
*
* @type action (admin_enqueue_scripts)
* @date 26/01/13
* @since 3.6.0
* @date 17/4/18
* @since 5.6.9
*
* @param N/A
* @return N/A
* @param void
* @return void
*/
function admin_enqueue_scripts() {
// validate page
if( ! $this->validate_page() ) {
// bail early if not valid screen
if( !acf_is_screen(array('profile', 'user', 'user-edit')) ) {
return;
}
// load acf scripts
// enqueue
acf_enqueue_scripts();
}
/**
* login_form_register
*
* Customizes and enqueues scripts
*
* @date 17/4/18
* @since 5.6.9
*
* @param void
* @return void
*/
function login_form_register() {
// actions
add_action('acf/input/admin_footer', array($this, 'admin_footer'), 10, 1);
// customize action prefix so that "admin_head" = "login_head"
acf_enqueue_scripts(array(
'context' => 'login'
));
}
/*
* register_user
*
* description
* Called during the user register form
*
* @type function
* @date 8/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
* @param void
* @return void
*/
function register_user() {
// update vars
$this->form = '#registerform';
function render_register() {
// render
$this->render( 0, 'register', 'div' );
$this->render(array(
'user_id' => 0,
'view' => 'register',
'el' => 'div'
));
}
/*
* edit_user
* render_edit
*
* description
* Called during the user edit form
*
* @type function
* @date 8/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
* @param void
* @return void
*/
function edit_user( $user ) {
// update vars
$this->form = '#your-profile';
function render_edit( $user ) {
// add compatibility with front-end user profile edit forms such as bbPress
if( !is_admin() ) {
acf_enqueue_scripts();
}
// render
$this->render( $user->ID, 'edit', 'tr' );
$this->render(array(
'user_id' => $user->ID,
'view' => 'edit',
'el' => 'tr'
));
}
@ -180,15 +152,14 @@ class acf_form_user {
* @return $post_id (int)
*/
function user_new_form() {
// update vars
$this->form = '#createuser';
function render_new() {
// render
$this->render( 0, 'add', 'tr' );
$this->render(array(
'user_id' => 0,
'view' => 'new',
'el' => 'tr'
));
}
@ -207,36 +178,44 @@ class acf_form_user {
* @return n/a
*/
function render( $user_id, $user_form, $el = 'tr' ) {
function render( $args = array() ) {
// defaults
$args = wp_parse_args($args, array(
'user_id' => 0,
'view' => 'edit',
'el' => 'tr',
));
// vars
$post_id = "user_{$user_id}";
$show_title = true;
// args
$args = array(
'user_id' => 'new',
'user_form' => $user_form
);
if( $user_id ) $args['user_id'] = $user_id;
$post_id = 'user_' . $args['user_id'];
// get field groups
$field_groups = acf_get_field_groups( $args );
$field_groups = acf_get_field_groups(array(
'user_id' => $args['user_id'] ? $args['user_id'] : 'new',
'user_form' => $args['view']
));
// bail early if no field groups
if( empty($field_groups) ) return;
if( empty($field_groups) ) {
return;
}
// form data
acf_form_data(array(
'screen' => 'user',
'post_id' => $post_id,
'screen' => 'user',
'post_id' => $post_id,
'validation' => ($args['view'] == 'register') ? 0 : 1
));
// elements
$before = '<table class="form-table"><tbody>';
$after = '</tbody></table>';
if( $args['el'] == 'div') {
$before = '<div class="acf-user-' . $args['view'] . '-fields acf-fields -clear">';
$after = '</div>';
}
// loop
foreach( $field_groups as $field_group ) {
@ -244,35 +223,19 @@ class acf_form_user {
// vars
$fields = acf_get_fields( $field_group );
// title
if( $show_title && $field_group['style'] === 'default' ) {
if( $field_group['style'] === 'default' ) {
echo '<h2>' . $field_group['title'] . '</h2>';
}
// table start
if( $el == 'tr' ) {
echo '<table class="form-table"><tbody>';
} else {
echo '<div class="acf-user-register-fields acf-fields -clear">';
}
// render fields
acf_render_fields( $fields, $post_id, $el, $field_group['instruction_placement'] );
// table end
if( $el == 'tr' ) {
echo '</tbody></table>';
} else {
echo '</div>';
}
// render
echo $before;
acf_render_fields( $fields, $post_id, $args['el'], $field_group['instruction_placement'] );
echo $after;
}
// actions
add_action('acf/input/admin_footer', array($this, 'admin_footer'), 10, 1);
}
@ -290,79 +253,19 @@ class acf_form_user {
*/
function admin_footer() {
?>
<style type="text/css">
<?php if( is_admin() ): ?>
/* override for user css */
.acf-field input[type="text"],
.acf-field input[type="password"],
.acf-field input[type="number"],
.acf-field input[type="search"],
.acf-field input[type="email"],
.acf-field input[type="url"],
.acf-field select {
max-width: 25em;
}
.acf-field textarea {
max-width: 500px;
}
/* allow sub fields to display correctly */
.acf-field .acf-field input[type="text"],
.acf-field .acf-field input[type="password"],
.acf-field .acf-field input[type="number"],
.acf-field .acf-field input[type="search"],
.acf-field .acf-field input[type="email"],
.acf-field .acf-field input[type="url"],
.acf-field .acf-field textarea,
.acf-field .acf-field select {
max-width: none;
}
<?php else: ?>
#registerform h2 {
margin: 1em 0;
}
#registerform .acf-field .acf-label {
margin-bottom: 0;
}
#registerform .acf-field .acf-label label {
font-weight: normal;
font-size: 14px;
}
#registerform p.submit {
text-align: right;
}
<?php endif; ?>
</style>
// script
?>
<script type="text/javascript">
(function($) {
// vars
var $spinner = $('<?php echo $this->form; ?> p.submit .spinner');
var view = '<?php echo $this->view; ?>';
// create spinner if not exists (may exist in future WP versions)
if( !$spinner.exists() ) {
// create spinner (use .acf-spinner becuase .spinner CSS not included on register page)
$spinner = $('<span class="acf-spinner"></span>');
// append
$('<?php echo $this->form; ?> p.submit').append( $spinner );
// add missing spinners
var $submit = $('input.button-primary');
if( !$submit.next('.spinner').length ) {
$submit.after('<span class="spinner"></span>');
}
})(jQuery);
@ -387,27 +290,21 @@ class acf_form_user {
function save_user( $user_id ) {
// verify and remove nonce
if( ! acf_verify_nonce('user') ) {
// verify nonce
if( !acf_verify_nonce('user') ) {
return $user_id;
}
// save data
// save
if( acf_validate_save_post(true) ) {
acf_save_post( "user_{$user_id}" );
acf_save_post( "user_$user_id" );
}
}
}
}
new acf_form_user();
// instantiate
acf_new_instance('ACF_Form_User');
endif;
endif; // class_exists check
?>

View File

@ -199,7 +199,7 @@ class acf_form_widget {
<script type="text/javascript">
(function($) {
acf.do_action('append', $('[id^="widget"][id$="<?php echo $widget->id; ?>"]') );
acf.doAction('append', $('[id^="widget"][id$="<?php echo $widget->id; ?>"]') );
})(jQuery);
</script>
@ -262,119 +262,68 @@ class acf_form_widget {
(function($) {
// vars
acf.update('post_id', 'widgets');
acf.set('post_id', 'widgets');
// restrict get fields
acf.add_filter('get_fields', function( $fields ){
// widgets
$fields = $fields.not('#available-widgets .acf-field');
// customizer
$fields = $fields.not('.widget-tpl .acf-field');
acf.addFilter('find_fields_args', function( args ){
// add parent
if( !args.parent ) {
args.parent = $('#widgets-right');
}
// return
return $fields;
return args;
});
// on publish
$('#widgets-right').on('click', '.widget-control-save', function( e ){
// vars
var $form = $(this).closest('form');
var $button = $(this);
var $form = $button.closest('form');
// validate
var valid = acf.validateForm({
form: $form,
event: e,
lock: false
});
// bail early if not active
if( !acf.validation.active ) {
return true;
// if not valid, stop event and allow validation to continue
if( !valid ) {
e.preventDefault();
e.stopImmediatePropagation();
}
// ignore validation (only ignore once)
if( acf.validation.ignore ) {
acf.validation.ignore = 0;
return true;
}
// bail early if this form does not contain ACF data
if( !$form.find('#acf-form-data').exists() ) {
return true;
}
// stop WP JS validation
e.stopImmediatePropagation();
// store submit trigger so it will be clicked if validation is passed
acf.validation.$trigger = $(this);
// run validation
acf.validation.fetch( $form );
// stop all other click events on this input
return false;
});
$(document).on('click', '.widget-top', function(){
var $el = $(this).parent().children('.widget-inside');
setTimeout(function(){
acf.get_fields('', $el).each(function(){
acf.do_action('show_field', $(this));
});
}, 250);
// show
$('#widgets-right').on('click', '.widget-top', function(){
var $widget = $(this).parent();
if( $widget.hasClass('open') ) {
acf.doAction('hide', $widget);
} else {
acf.doAction('show', $widget);
}
});
$(document).on('widget-added', function( e, $widget ){
// - use delay to avoid rendering issues with customizer (ensures div is visible)
setTimeout(function(){
acf.do_action('append', $widget );
acf.doAction('append', $widget );
}, 100);
});
$(document).on('widget-saved widget-updated', function( e, $widget ){
// unlock form
acf.validation.toggle( $widget, 'unlock' );
});
})(jQuery);
</script>
<?php
}
}
new acf_form_widget();
endif;
?>
?>

View File

@ -1,522 +0,0 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_input') ) :
class acf_input {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// vars
$this->admin_enqueue_scripts = 'admin_enqueue_scripts';
$this->admin_head = 'admin_head';
$this->admin_footer = 'admin_footer';
$this->enqueued = false;
$this->data = array();
// actions
add_action('acf/save_post', array($this, 'save_post'), 10, 1);
}
/*
* get_data
*
* This function will return form data
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param $key (mixed)
* @return (mixed)
*/
function get_data( $key = false ) {
// vars
$data = $this->data;
// key
if( $key && isset($data[ $key ]) ) {
$data = $data[ $key ];
}
// return
return $data;
}
/*
* set_data
*
* This function will se the form data
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param $data (array)
* @return (array)
*/
function set_data( $data ) {
// defaults
$data = acf_parse_args($data, array(
'screen' => 'post', // Current screen loaded (post, user, taxonomy, etc)
'post_id' => 0, // ID of current post being edited
'nonce' => '', // nonce used for $_POST validation (defaults to screen)
'validation' => 1, // runs AJAX validation
'ajax' => 0, // if screen uses ajax to append new HTML (enqueue all assets)
'changed' => 0, // used to detect change and prompt unload
));
// nonce
if( !$data['nonce'] ) {
$data['nonce'] = $data['screen'];
}
// enqueue uploader if page allows AJAX fields to appear
// priority must be less than 10 to allow WP to enqueue
if( $data['ajax'] ) {
add_action($this->admin_footer, 'acf_enqueue_uploader', 5);
}
// update
$this->data = $data;
// return
return $data;
}
/*
* enqueue
*
* This function will determin the actions to use for different pages
*
* @type function
* @date 13/01/2016
* @since 5.3.2
*
* @param n/a
* @return n/a
*/
function enqueue() {
// bail ealry if already enqueued
if( $this->enqueued ) return;
// update setting
$this->enqueued = true;
// global
global $pagenow;
// determine action hooks
if( $pagenow == 'customize.php' ) {
$this->admin_head = 'customize_controls_print_scripts';
$this->admin_footer = 'customize_controls_print_footer_scripts';
} elseif( $pagenow == 'wp-login.php' ) {
$this->admin_enqueue_scripts = 'login_enqueue_scripts';
$this->admin_head = 'login_head';
$this->admin_footer = 'login_footer';
} elseif( !is_admin() ) {
$this->admin_enqueue_scripts = 'wp_enqueue_scripts';
$this->admin_head = 'wp_head';
$this->admin_footer = 'wp_footer';
}
// actions
acf_maybe_add_action($this->admin_enqueue_scripts, array($this, 'admin_enqueue_scripts'), 20 );
acf_maybe_add_action($this->admin_head, array($this, 'admin_head'), 20 );
acf_maybe_add_action($this->admin_footer, array($this, 'admin_footer'), 20 );
}
/*
* admin_enqueue_scripts
*
* The acf input screen admin_enqueue_scripts
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param n/a
* @return n/a
*/
function admin_enqueue_scripts() {
// scripts
wp_enqueue_script('acf-input');
// styles
wp_enqueue_style('acf-input');
// do action
do_action('acf/input/admin_enqueue_scripts');
}
/*
* admin_head
*
* The acf input screen admin_head
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param n/a
* @return n/a
*/
function admin_head() {
// do action
do_action('acf/input/admin_head');
}
/*
* admin_footer
*
* The acf input screen admin_footer
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param n/a
* @return n/a
*/
function admin_footer() {
// global
global $wp_version;
// options
$o = array(
'screen' => acf_get_form_data('screen'),
'post_id' => acf_get_form_data('post_id'),
'nonce' => wp_create_nonce( 'acf_nonce' ),
'admin_url' => admin_url(),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'ajax' => acf_get_form_data('ajax'),
'validation' => acf_get_form_data('validation'),
'wp_version' => $wp_version,
'acf_version' => acf_get_setting('version'),
'browser' => acf_get_browser(),
'locale' => get_locale(),
'rtl' => is_rtl()
);
// l10n
$l10n = apply_filters( 'acf/input/admin_l10n', array(
'unload' => __('The changes you made will be lost if you navigate away from this page','acf'),
'expand_details' => __('Expand Details','acf'),
'collapse_details' => __('Collapse Details','acf'),
'validation_successful' => __('Validation successful', 'acf'),
'validation_failed' => __('Validation failed', 'acf'),
'validation_failed_1' => __('1 field requires attention', 'acf'),
'validation_failed_2' => __('%d fields require attention', 'acf'),
'restricted' => __('Restricted','acf'),
'are_you_sure' => __('Are you sure?','acf'),
'yes' => __('Yes','acf'),
'no' => __('No','acf'),
'remove' => __('Remove','acf'),
'cancel' => __('Cancel','acf')
));
?>
<script type="text/javascript">
var acf = acf || null;
if( acf ) {
acf.o = <?php echo json_encode($o); ?>;
acf.l10n = <?php echo json_encode($l10n); ?>;
<?php do_action('acf/input/admin_footer_js'); ?>
}
</script>
<?php
do_action('acf/input/admin_footer');
?>
<script type="text/javascript">
if( acf ) acf.do_action('prepare');
</script>
<?php
}
/*
* save_post
*
* This function will save the $_POST data
*
* @type function
* @date 24/10/2014
* @since 5.0.9
*
* @param $post_id (int)
* @return n/a
*/
function save_post( $post_id ) {
// bail early if empty
// - post data may have be modified
if( empty($_POST['acf']) ) return;
// loop
foreach( $_POST['acf'] as $k => $v ) {
// get field
$field = acf_get_field( $k );
// continue if no field
if( !$field ) continue;
// update
acf_update_value( $v, $post_id, $field );
}
}
}
// initialize
acf()->input = new acf_input();
endif; // class_exists check
/*
* acf_enqueue_scripts
*
* alias of acf()->form->enqueue()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_enqueue_scripts() {
return acf()->input->enqueue();
}
/*
* acf_get_form_data
*
* alias of acf()->form->get_data()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_get_form_data( $key = false ) {
return acf()->input->get_data( $key );
}
/*
* acf_set_form_data
*
* alias of acf()->form->set_data()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_set_form_data( $data = array() ) {
return acf()->input->set_data( $data );
}
/*
* acf_enqueue_uploader
*
* This function will render a WP WYSIWYG and enqueue media
*
* @type function
* @date 27/10/2014
* @since 5.0.9
*
* @param n/a
* @return n/a
*/
function acf_enqueue_uploader() {
// bail early if doing ajax
if( acf_is_ajax() ) return;
// bail ealry if already run
if( acf_has_done('enqueue_uploader') ) return;
// enqueue media if user can upload
if( current_user_can('upload_files') ) {
wp_enqueue_media();
}
// create dummy editor
?><div id="acf-hidden-wp-editor" class="acf-hidden"><?php wp_editor( '', 'acf_content' ); ?></div><?php
}
/*
* acf_form_data
*
* description
*
* @type function
* @date 15/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_form_data( $args = array() ) {
// make sure scripts and styles have been included
// case: front end bbPress edit user
acf_enqueue_scripts();
// set form data
$args = acf_set_form_data( $args );
// hidden inputs
$inputs = $args;
$inputs['nonce'] = wp_create_nonce($inputs['nonce']);
?>
<div id="acf-form-data" class="acf-hidden">
<?php foreach( $inputs as $k => $v ): ?>
<input type="hidden" id="_acf_<?php echo esc_attr($k); ?>" name="_acf_<?php echo esc_attr($k); ?>" value="<?php echo esc_attr($v); ?>" />
<?php endforeach; ?>
<?php do_action('acf/input/form_data', $args); ?>
</div>
<?php
}
/*
* acf_save_post
*
* description
*
* @type function
* @date 8/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_save_post( $post_id = 0, $values = null ) {
// override $_POST
if( $values !== null ) {
$_POST['acf'] = $values;
}
// bail early if no values
if( empty($_POST['acf']) ) return false;
// set form data
acf_set_form_data(array(
'post_id' => $post_id
));
// hook for 3rd party customization
do_action('acf/save_post', $post_id);
// return
return true;
}

View File

@ -1,6 +1,10 @@
<?php
class acf_media {
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('ACF_Media') ) :
class ACF_Media {
/*
@ -19,51 +23,40 @@ class acf_media {
function __construct() {
// actions
add_action('acf/enqueue_scripts', array($this, 'enqueue_scripts'));
add_action('acf/save_post', array($this, 'save_files'), 5, 1);
add_action('acf/input/admin_footer', array($this, 'admin_footer'));
// filters
add_filter('wp_handle_upload_prefilter', array($this, 'handle_upload_prefilter'), 10, 1);
add_filter('acf/input/admin_l10n', array($this, 'acf_input_admin_l10n'), 10, 1);
// ajax
add_action( 'wp_ajax_query-attachments', array($this, 'wp_ajax_query_attachments'), -1);
add_action('wp_ajax_query-attachments', array($this, 'wp_ajax_query_attachments'), -1);
}
/*
* acf_input_admin_l10n
/**
* enqueue_scripts
*
* This function will append l10n strings for JS use
* Localizes data
*
* @type function
* @date 11/04/2016
* @since 5.3.8
* @date 27/4/18
* @since 5.6.9
*
* @param $post_id (int)
* @return $post_id (int)
* @param void
* @return void
*/
function acf_input_admin_l10n( $l10n ) {
// append
$l10n['media'] = array(
'select' => _x('Select', 'verb', 'acf'),
'edit' => _x('Edit', 'verb', 'acf'),
'update' => _x('Update', 'verb', 'acf'),
'uploadedTo' => __("Uploaded to this post",'acf'),
'default_icon' => wp_mime_type_icon()
);
// return
return $l10n;
function enqueue_scripts(){
// localize
acf_localize_data(array(
'mimeTypeIcon' => wp_mime_type_icon(),
'mimeTypes' => get_allowed_mime_types()
));
}
/*
* handle_upload_prefilter
@ -82,19 +75,14 @@ class acf_media {
// bail early if no acf field
if( empty($_POST['_acfuploader']) ) {
return $file;
}
// load field
$field = acf_get_field( $_POST['_acfuploader'] );
if( !$field ) {
return $file;
}
@ -111,15 +99,12 @@ class acf_media {
// append error
if( !empty($errors) ) {
$file['error'] = implode("\n", $errors);
}
// return
return $file;
}
@ -140,39 +125,12 @@ class acf_media {
// bail early if no $_FILES data
if( empty($_FILES['acf']['name']) ) {
return;
}
// upload files
acf_upload_files();
}
/*
* admin_footer
*
* description
*
* @type function
* @date 19/02/2015
* @since 5.1.5
*
* @param $post_id (int)
* @return $post_id (int)
*/
function admin_footer() {
?>
<script type="text/javascript">
if( acf ) acf.media.mime_types = <?php echo json_encode( get_allowed_mime_types() ); ?>;
</script>
<?php
}
@ -203,19 +161,14 @@ class acf_media {
// bail early if no acf field
if( empty($_POST['query']['_acfuploader']) ) {
return $response;
}
// load field
$field = acf_get_field( $_POST['query']['_acfuploader'] );
if( !$field ) {
return $response;
}
@ -225,21 +178,18 @@ class acf_media {
// append errors
if( !empty($errors) ) {
$response['acf_errors'] = implode('<br />', $errors);
}
// return
return $response;
}
}
// instantiate
acf_new_instance('ACF_Media');
// initialize
new acf_media();
endif; // class_exists check
?>

View File

@ -7,9 +7,9 @@ if( ! class_exists('acf_updates') ) :
class acf_updates {
// vars
var $version = '2.2',
var $version = '2.3',
$plugins = array(),
$updates = false,
$force_check = false,
$dev = 0;
@ -28,13 +28,16 @@ class acf_updates {
function __construct() {
// vars
$this->force_check = !empty($_GET['force-check']);
// append update information to transient
add_filter('pre_set_site_transient_update_plugins', array($this, 'modify_plugins_transient'), 10, 1);
// modify plugin data visible in the 'View details' popup
add_filter('plugins_api', array($this, 'modify_plugin_details'), 10, 3);
}
@ -62,32 +65,16 @@ class acf_updates {
'version' => '',
));
// Check if is_plugin_active() function exists. This is required on the front end of the
// site, since it is in a file that is normally only loaded in the admin.
if( !function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// bail early if not active plugin (included in theme)
if( !is_plugin_active($plugin['basename']) ) return;
// add custom message in plugin update row
// removed: decided this message will have a negative impact on user
// if( is_admin() ) {
//
// add_action('in_plugin_update_message-' . $plugin['basename'], array($this, 'modify_plugin_update_message'), 10, 2 );
//
// }
// append
$this->plugins[ $plugin['basename'] ] = $plugin;
// add if is active plugin (not included in theme)
if( is_plugin_active($plugin['basename']) ) {
$this->plugins[ $plugin['basename'] ] = $plugin;
}
}
@ -110,14 +97,11 @@ class acf_updates {
// vars
$url = 'https://connect.advancedcustomfields.com/' . $query;
// test
if( $this->dev ) $url = 'http://connect/' . $query;
// log
//acf_log('acf connect: '. $url, $body);
// development mode
if( $this->dev ) {
$url = 'http://connect/' . $query;
acf_log('acf connect: '. $url, $body);
}
// post
$raw_response = wp_remote_post( $url, array(
@ -125,35 +109,25 @@ class acf_updates {
'body' => $body
));
// wp error
if( is_wp_error($raw_response) ) {
return $raw_response;
// http error
} elseif( wp_remote_retrieve_response_code($raw_response) != 200 ) {
return new WP_Error( 'server_error', wp_remote_retrieve_response_message($raw_response) );
}
// decode response
$json = json_decode( wp_remote_retrieve_body($raw_response), true );
// allow non json value
if( $json === null ) {
return wp_remote_retrieve_body($raw_response);
}
// return
return $json;
}
@ -173,42 +147,131 @@ class acf_updates {
function get_plugin_info( $id = '' ) {
// var
$transient_name = 'acf_plugin_info_'.$id;
$transient_name = 'acf_plugin_info_' . $id;
// delete transient (force-check is used to refresh)
if( !empty($_GET['force-check']) ) {
delete_transient($transient_name);
// ignore cache (only once)
if( $this->force_check ) {
$this->force_check = false;
// check cache
} else {
$transient = get_transient($transient_name);
if( $transient !== false ) return $transient;
}
// try transient
$transient = get_transient($transient_name);
if( $transient !== false ) return $transient;
// connect
$response = $this->request('v2/plugins/get-info?p='.$id);
// ensure response is expected JSON array (not string)
// convert string (misc error) to WP_Error object
if( is_string($response) ) {
$response = new WP_Error( 'server_error', esc_html($response) );
}
// allow json to include expiration but force minimum and max for safety
$expiration = $this->get_expiration($response, DAY_IN_SECONDS, MONTH_IN_SECONDS);
// update transient
set_transient($transient_name, $response, HOUR_IN_SECONDS );
set_transient($transient_name, $response, $expiration );
// return
return $response;
}
/**
* get_plugin_updates
*
* description
*
* @date 8/7/18
* @since 5.6.9
*
* @param type $var Description. Default.
* @return type Description.
*/
function get_plugin_updates() {
// var
$transient_name = 'acf_plugin_updates';
// ignore cache (only once)
if( $this->force_check ) {
$this->force_check = false;
// check cache
} else {
$transient = get_transient($transient_name);
if( $transient !== false ) return $transient;
}
// vars
$post = array(
'plugins' => wp_json_encode($this->plugins),
'wp' => wp_json_encode(array(
'wp_name' => get_bloginfo('name'),
'wp_url' => home_url(),
'wp_version' => get_bloginfo('version'),
'wp_language' => get_bloginfo('language'),
'wp_timezone' => get_option('timezone_string'),
)),
'acf' => wp_json_encode(array(
'acf_version' => get_option('acf_version'),
'acf_pro' => (defined('ACF_PRO') && ACF_PRO),
)),
);
// request
$response = $this->request('v2/plugins/update-check', $post);
// allow json to include expiration but force minimum and max for safety
$expiration = $this->get_expiration($response, DAY_IN_SECONDS, MONTH_IN_SECONDS);
// update transient
set_transient($transient_name, $response, $expiration );
// return
return $response;
}
/**
* get_expiration
*
* This function safely gets the expiration value from a response
*
* @date 8/7/18
* @since 5.6.9
*
* @param mixed $response The response from the server. Default false.
* @param int $min The minimum expiration limit. Default 0.
* @param int $max The maximum expiration limit. Default 0.
* @return int
*/
function get_expiration( $response = false, $min = 0, $max = 0 ) {
// vars
$expiration = 0;
// check
if( is_array($response) && isset($response['expiration']) ) {
$expiration = (int) $response['expiration'];
}
// min
if( $expiration < $min ) {
return $min;
}
// max
if( $expiration > $max ) {
return $max;
}
// return
return $expiration;
}
/*
* refresh_plugins_transient
*
@ -227,14 +290,12 @@ class acf_updates {
// vars
$transient = get_site_transient('update_plugins');
// bail early if no transient
if( empty($transient) ) return;
// update (will trigger modify function)
$this->force_check = true;
set_site_transient( 'update_plugins', $transient );
}
@ -254,50 +315,22 @@ class acf_updates {
function modify_plugins_transient( $transient ) {
// bail early if no response (error)
if( !isset($transient->response) ) return $transient;
// fetch updates once (this filter is called multiple times during a single page load)
if( !$this->updates ) {
// vars
$post = array(
'plugins' => wp_json_encode($this->plugins),
'wp' => wp_json_encode(array(
'wp_name' => get_bloginfo('name'),
'wp_url' => home_url(),
'wp_version' => get_bloginfo('version'),
'wp_language' => get_bloginfo('language'),
'wp_timezone' => get_option('timezone_string'),
)),
'acf' => wp_json_encode(array(
'acf_version' => get_option('acf_version'),
'acf_pro' => (defined('ACF_PRO') && ACF_PRO),
)),
);
// connect
$this->updates = $this->request('v2/plugins/update-check', $post);
if( !isset($transient->response) ) {
return $transient;
}
// fetch updates (this filter is called multiple times during a single page load)
$updates = $this->get_plugin_updates();
// append
if( is_array($this->updates) ) {
foreach( $this->updates['plugins'] as $basename => $update ) {
if( is_array($updates) ) {
foreach( $updates['plugins'] as $basename => $update ) {
$transient->response[ $basename ] = (object) $update;
}
}
// return
return $transient;
}
@ -375,35 +408,6 @@ class acf_updates {
return $response;
}
/*
* modify_plugin_update_message
*
* Displays an update message for plugin list screens.
* Shows only the version updates from the current until the newest version
*
* @type function
* @date 14/06/2016
* @since 5.3.8
*
* @param $plugin_data (array)
* @param $r (object)
* @return n/a
*/
/*
function modify_plugin_update_message( $plugin_data, $response ) {
// show notice if exists in transient data
if( isset($response->notice) ) {
echo '<div class="acf-plugin-upgrade-notice">' . $response->notice . '</div>';
}
}
*/
}

View File

@ -126,7 +126,7 @@ class ACF_Walker_Nav_Menu_Edit extends Walker_Nav_Menu_Edit {
if( acf_is_ajax('add-menu-item') ): ?>
<script type="text/javascript">
(function($) {
acf.do_action('append', jQuery('#menu-item-settings-<?php echo $post_id; ?>') );
acf.doAction('append', jQuery('#menu-item-settings-<?php echo $post_id; ?>') );
})(jQuery);
</script>
<?php endif;

View File

@ -23,7 +23,7 @@ class ACF_Taxonomy_Field_Walker extends Walker {
// append
$output .= '<li data-id="' . $term->term_id . '"><label><input type="' . $this->field['field_type'] . '" name="' . $this->field['name'] . '" value="' . $term->term_id . '" ' . ($selected ? 'checked="checked"' : '') . ' /> <span>' . $term->name . '</span></label>';
$output .= '<li data-id="' . $term->term_id . '"><label' . ($selected ? ' class="selected"' : '') . '><input type="' . $this->field['field_type'] . '" name="' . $this->field['name'] . '" value="' . $term->term_id . '" ' . ($selected ? 'checked="checked"' : '') . ' /> <span>' . $term->name . '</span></label>';
}

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

BIN
lang/acf-hr_HR.mo Normal file

Binary file not shown.

3293
lang/acf-hr_HR.po Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -304,8 +304,8 @@ class acf_admin_options_page {
'key' => $field_group['key'],
'style' => $field_group['style'],
'label' => $field_group['label_placement'],
'edit_url' => '',
'edit_title' => __('Edit field group', 'acf'),
'editLink' => '',
'editTitle' => __('Edit field group', 'acf'),
'visibility' => true
);
@ -313,7 +313,7 @@ class acf_admin_options_page {
// edit_url
if( $field_group['ID'] && acf_current_user_can_admin() ) {
$o['edit_url'] = admin_url('post.php?post=' . $field_group['ID'] . '&action=edit');
$o['editLink'] = admin_url('post.php?post=' . $field_group['ID'] . '&action=edit');
}
@ -331,7 +331,7 @@ class acf_admin_options_page {
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
acf.postbox.render(<?php echo json_encode($o); ?>);
acf.newPostbox(<?php echo json_encode($o); ?>);
}
</script>

View File

@ -227,7 +227,6 @@ class acf_admin_settings_updates {
// add changelog if the remote version is '>' than the current version
$version = acf_get_setting('version');
// check if remote version is higher than current version
if( version_compare($info['version'], $version, '>') ) {
@ -242,13 +241,42 @@ class acf_admin_settings_updates {
// - avoids new version not available in plugin update list
// - only request if license is active
if( $license ) {
acf_updates()->refresh_plugins_transient();
$this->refresh_plugins_transient();
}
}
}
/**
* refresh_plugins_transient
*
* Checks the site transient 'update_plugins' and compares the cached new_version against the plugin-info version.
* If the cached version is older, a new version is available, and the transient is refreshed.
*
* @date 12/7/18
* @since 5.6.9
*
* @param void
* @return void
*/
function refresh_plugins_transient() {
// vars
$remote_version = $this->view['remote_version'];
$basename = acf_get_setting('basename');
$transient = get_site_transient('update_plugins');
$transient_version = 0;
// get transient version
if( isset($transient->response[ $basename ]->new_version) ) {
$transient_version = $transient->response[ $basename ]->new_version;
}
// return true if a newer $remote_version exists
if( acf_version_compare($remote_version, '>', $transient_version) ) {
acf_updates()->refresh_plugins_transient();
}
}

View File

@ -123,13 +123,8 @@ $readonly = $active ? 1 : 0;
<?php endif; ?>
</tbody>
</table>
</form>
</div>
</div>
</div>
<style type="text/css">
#acf_pro_licence {

View File

@ -3,52 +3,49 @@
* Flexible Content
*
*---------------------------------------------------------------------------------------------*/
.acf-fc-meta {
.acf-field-setting-fc_layout .acf-fc-meta {
margin: 0 0 10px;
padding: 0;
}
.acf-fc-meta li {
.acf-field-setting-fc_layout .acf-fc-meta li {
margin: 0 0 10px;
padding: 0;
}
.acf-fc-meta .acf-fc-meta-key {
display: none;
}
.acf-fc-meta .acf-fc-meta-display,
.acf-fc-meta .acf-fc-meta-min {
.acf-field-setting-fc_layout .acf-fc-meta .acf-fc-meta-display,
.acf-field-setting-fc_layout .acf-fc-meta .acf-fc-meta-min {
float: left;
width: 33%;
padding-right: 10px;
}
.acf-input-wrap.select {
.acf-field-setting-fc_layout .acf-fc-meta .acf-fc-meta-label .acf-input-prepend,
.acf-field-setting-fc_layout .acf-fc-meta .acf-fc-meta-name .acf-input-prepend,
.acf-field-setting-fc_layout .acf-fc-meta .acf-fc-meta-display .acf-input-prepend {
min-width: 45px;
}
.acf-field-setting-fc_layout .acf-input-wrap.select {
border-radius: 0 3px 3px 0 !important;
border: #DFDFDF solid 1px;
}
.acf-input-wrap.select select {
.acf-field-setting-fc_layout .acf-input-wrap.select select {
margin: 0;
border: 0 none;
padding: 3px;
height: 26px;
}
.acf-fc-meta-label .acf-input-prepend,
.acf-fc-meta-name .acf-input-prepend,
.acf-fc-meta-display .acf-input-prepend {
min-width: 45px;
}
.acf-fl-actions {
.acf-field-setting-fc_layout .acf-fl-actions {
visibility: hidden;
}
.acf-field:hover .acf-fl-actions {
visibility: visible;
.acf-field-setting-fc_layout .acf-fl-actions .reorder-layout {
cursor: move;
}
.acf-fl-actions a {
display: block;
line-height: 20px;
.acf-field-setting-fc_layout .acf-fl-actions a {
padding: 1px 0;
font-size: 13px;
line-height: 20px;
}
.acf-fl-actions a.ui-sortable-handle {
cursor: move;
.acf-field-setting-fc_layout:hover .acf-fl-actions,
.acf-field-setting-fc_layout.-hover .acf-fl-actions {
visibility: visible;
}
/*---------------------------------------------------------------------------------------------
*

View File

@ -144,17 +144,18 @@ body.browser-msie .acf-repeater .acf-row-handle .acf-icon.-minus {
.acf-flexible-content {
position: relative;
}
.acf-flexible-content > .no-value-message {
padding: 19px;
border: #ccc dashed 2px;
text-align: center;
}
.acf-flexible-content > .clones {
display: none;
}
.acf-flexible-content > .values {
margin: 0 0 8px;
}
.acf-flexible-content > .values > .ui-sortable-placeholder {
visibility: visible !important;
border: 1px dashed #b4b9be;
box-shadow: none;
background: transparent;
}
.acf-flexible-content .layout {
position: relative;
margin: 20px 0 0;
@ -187,57 +188,50 @@ body.browser-msie .acf-repeater .acf-row-handle .acf-icon.-minus {
font-size: 12px;
color: #666;
}
/* controlls*/
.acf-flexible-content {
/* layout */
html[dir="rtl"] .acf-flexible-content .layout .acf-fc-layout-order {
float: right;
margin-right: 0;
margin-left: 5px;
}
.acf-flexible-content .layout {
/* controlls */
/* hover */
}
.acf-flexible-content .layout .acf-fc-layout-controlls {
.acf-flexible-content .layout .acf-fc-layout-controls {
position: absolute;
top: 8px;
right: 8px;
}
.acf-flexible-content .layout .acf-fc-layout-controlls .acf-icon {
.acf-flexible-content .layout .acf-fc-layout-controls .acf-icon {
display: block;
float: left;
margin: 0 0 0 5px;
}
.acf-flexible-content .layout .acf-fc-layout-controlls .acf-icon.-plus,
.acf-flexible-content .layout .acf-fc-layout-controlls .acf-icon.-minus {
.acf-flexible-content .layout .acf-fc-layout-controls .acf-icon.-plus,
.acf-flexible-content .layout .acf-fc-layout-controls .acf-icon.-minus {
visibility: hidden;
}
.acf-flexible-content .layout .acf-fc-layout-controlls .acf-icon.-collapse {
.acf-flexible-content .layout .acf-fc-layout-controls .acf-icon.-collapse {
color: #72777c;
border-color: transparent;
}
.acf-flexible-content .layout .acf-fc-layout-controlls .acf-icon.-collapse:hover {
.acf-flexible-content .layout .acf-fc-layout-controls .acf-icon.-collapse:hover {
color: #23282d;
background: transparent;
}
.acf-flexible-content .layout:hover .acf-fc-layout-controlls .acf-icon.-plus,
.acf-flexible-content .layout.-open .acf-fc-layout-controlls .acf-icon.-plus,
.acf-flexible-content .layout:hover .acf-fc-layout-controlls .acf-icon.-minus,
.acf-flexible-content .layout.-open .acf-fc-layout-controlls .acf-icon.-minus {
html[dir="rtl"] .acf-flexible-content .layout .acf-fc-layout-controls {
right: auto;
left: 9px;
}
.acf-flexible-content .layout:hover .acf-fc-layout-controls .acf-icon.-plus,
.acf-flexible-content .layout.-hover .acf-fc-layout-controls .acf-icon.-plus,
.acf-flexible-content .layout:hover .acf-fc-layout-controls .acf-icon.-minus,
.acf-flexible-content .layout.-hover .acf-fc-layout-controls .acf-icon.-minus {
visibility: visible;
}
.acf-flexible-content > .values > .ui-sortable-placeholder {
visibility: visible !important;
border: 1px dashed #b4b9be;
box-shadow: none;
background: transparent;
}
/* collapsed */
.acf-flexible-content .layout.-collapsed .acf-fc-layout-handle {
.acf-flexible-content .layout.-collapsed > .acf-fc-layout-handle {
border-bottom-width: 0;
}
.acf-flexible-content .layout.-collapsed > .acf-fields,
.acf-flexible-content .layout.-collapsed > .acf-table {
display: none;
}
/* table */
.acf-flexible-content .layout > .acf-table {
border: 0 none;
box-shadow: none;
@ -248,53 +242,19 @@ body.browser-msie .acf-repeater .acf-row-handle .acf-icon.-minus {
.acf-flexible-content .layout > .acf-table > thead > tr > th {
background: #F9F9F9;
}
/* popup */
.acf-flexible-content .no-value-message {
padding: 19px;
border: #ccc dashed 2px;
text-align: center;
display: none;
}
.acf-flexible-content.-empty > .no-value-message {
display: block;
}
.acf-fc-popup {
background: #2F353E;
border-radius: 5px;
color: #fff;
padding: 7px 0;
position: absolute;
font-size: 13px;
z-index: 900000;
padding: 5px 0;
z-index: 900001;
min-width: 135px;
/* tip */
/* positions */
/* list */
}
.acf-fc-popup:before {
border: solid;
border-color: transparent;
border-width: 6px;
content: "";
position: absolute;
}
.acf-fc-popup.-top {
margin-top: -8px;
}
.acf-fc-popup.-top:before {
top: 100%;
left: 50%;
margin-left: -6px;
border-top-color: #2F353E;
border-bottom-width: 0;
}
.acf-fc-popup.-bottom {
margin-bottom: -8px;
}
.acf-fc-popup.-bottom:before {
bottom: 100%;
left: 50%;
margin-left: -6px;
border-bottom-color: #2F353E;
border-top-width: 0;
}
.acf-fc-popup.-right:before {
left: 18px;
}
.acf-fc-popup.-left:before {
left: auto;
right: 18px;
}
.acf-fc-popup ul,
.acf-fc-popup li {
@ -313,7 +273,7 @@ body.browser-msie .acf-repeater .acf-row-handle .acf-icon.-minus {
border-radius: 8px;
font-size: 9px;
line-height: 15px;
padding: 0 7px;
padding: 0 5px;
background: #d54e21;
text-align: center;
color: #fff;
@ -322,9 +282,7 @@ body.browser-msie .acf-repeater .acf-row-handle .acf-icon.-minus {
}
.acf-fc-popup a {
color: #eee;
font-size: 13px;
line-height: 16px;
padding: 7px 12px;
padding: 5px 10px;
display: block;
text-decoration: none;
position: relative;
@ -337,20 +295,6 @@ body.browser-msie .acf-repeater .acf-row-handle .acf-icon.-minus {
color: #888;
background: transparent;
}
.acf-fc-popup ul li a:hover .status {
border-color: #fff;
color: #fff;
}
/* rtl */
html[dir="rtl"] .acf-flexible-content .layout .acf-fc-layout-order {
float: right;
margin-right: 0;
margin-left: 5px;
}
html[dir="rtl"] .acf-flexible-content .layout .acf-fc-layout-controlls {
right: auto;
left: 9px;
}
/*---------------------------------------------------------------------------------------------
*
* Galery

View File

@ -13,561 +13,470 @@
* @return n/a
*/
var acf_settings_repeater = acf.field_group.field_object.extend({
var RepeaterCollapsedFieldSetting = acf.FieldSetting.extend({
type: 'repeater',
actions: {
'render_settings': 'render'
},
name: 'collapsed',
events: {
'change .acf-field-setting-layout input': '_change_layout',
'focus .acf-field-setting-collapsed select': '_focus_collapsed'
'focus select': 'onFocus',
},
focus: function(){
this.$fields = this.$field.find('.acf-field-list:first');
},
render: function(){
this.render_layout();
this.render_collapsed();
},
render_layout: function(){
onFocus: function( e, $el ){
// vars
var layout = this.setting('layout input:checked').val();
// update data
this.$fields.attr('data-layout', layout);
},
render_collapsed: function(){
// vars
var $select = this.setting('collapsed select');
var $select = $el;
// collapsed
var choices = [];
// keep 'null' choice
choices.push({
'label': $select.find('option[value=""]').text(),
'value': ''
label: $select.find('option[value=""]').text(),
value: ''
});
// find sub fields
var $list = this.fieldObject.$('.acf-field-list:first');
var fields = acf.getFieldObjects({
list: $list
});
// loop
this.$fields.children('.acf-field-object').each(function(){
// vars
var $field = $(this);
// append
fields.map(function( field ){
choices.push({
'label': $field.find('.field-label:first').val(),
'value': $field.attr('data-key')
label: field.prop('label'),
value: field.prop('key')
});
});
});
// render
acf.render_select( $select, choices );
},
_change_layout: function( e ){
this.render_layout();
},
_focus_collapsed: function( e ){
this.render_collapsed();
acf.renderSelect( $select, choices );
}
});
acf.registerFieldSetting( RepeaterCollapsedFieldSetting );
/*
* flexible_content
})(jQuery);
(function($){
/**
* CloneDisplayFieldSetting
*
* description
* Extra logic for this field setting
*
* @type function
* @date 25/09/2015
* @since 5.2.3
* @date 18/4/18
* @since 5.6.9
*
* @param $post_id (int)
* @return $post_id (int)
* @param void
* @return void
*/
var acf_settings_flexible_content = acf.field_group.field_object.extend({
var FlexibleContentLayoutFieldSetting = acf.FieldSetting.extend({
type: 'flexible_content',
name: 'fc_layout',
actions: {
'render_settings': 'render'
events: {
'blur .layout-label': 'onChangeLabel',
'click .add-layout': 'onClickAdd',
'click .duplicate-layout': 'onClickDuplicate',
'click .delete-layout': 'onClickDelete'
},
render: function(){
$input: function( name ){
return $('#' + this.getInputId() + '-' + name);
},
$list: function(){
return this.$('.acf-field-list:first');
},
getInputId: function(){
return this.fieldObject.getInputId() + '-layouts-' + this.field.get('id');
},
// get all sub fields
getFields: function(){
return acf.getFieldObjects({ parent: this.$el });
},
// get imediate children
getChildren: function(){
return acf.getFieldObjects({ list: this.$list() });
},
initialize: function(){
// reference
var self = this,
$field = this.$field;
// sortable
if( ! this.$settings.hasClass('ui-sortable') ) {
// add sortable
var $tbody = this.$el.parent();
if( !$tbody.hasClass('ui-sortable') ) {
// add sortable
this.$settings.sortable({
$tbody.sortable({
items: '> .acf-field-setting-fc_layout',
handle: '[data-name="acf-fc-reorder"]',
handle: '.reorder-layout',
forceHelperSize: true,
forcePlaceholderSize: true,
scroll: true,
stop: function (event, ui) {
// save flexible content (layout order has changed)
acf.field_group.save_field( $field );
}
stop: this.proxy(function(event, ui) {
this.fieldObject.save();
})
});
}
// render layouts
this.$settings.children('.acf-field-setting-fc_layout').each(function(){
self.layout.render( $(this) );
});
// add meta to sub fields
this.updateFieldLayouts();
},
layout: null
});
acf_settings_flexible_content.layout = acf.model.extend({
actions: {
'update_field_parent': 'update_field_parent'
updateFieldLayouts: function(){
this.getChildren().map(this.updateFieldLayout, this);
},
events: {
'change .acf-fc-meta-display select': '_change_display',
'blur .acf-fc-meta-label input': '_blur_label',
'click a[data-name="acf-fc-add"]': '_add',
'click a[data-name="acf-fc-duplicate"]': '_duplicate',
'click a[data-name="acf-fc-delete"]': '_delete'
updateFieldLayout: function( field ){
field.prop('parent_layout', this.get('id'));
},
event: function( e ){
return e.$el.closest('.acf-field-setting-fc_layout');
},
update_meta: function( $field, $layout ){
acf.field_group.update_field_meta( $field, 'parent_layout', $layout.attr('data-id') );
},
delete_meta: function( $field ){
acf.field_group.delete_field_meta( $field, 'parent_layout' );
},
/*
* update_field_parent
*
* this function will update a sub field's 'parent_layout' meta data
*
* @type function
* @date 16/11/16
* @since 5.5.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
update_field_parent: function( $el, $parent ){
onChangeLabel: function( e, $el ){
// vars
var $layout = $el.closest('.acf-field-setting-fc_layout');
var label = $el.val();
var $name = this.$input('name');
// bail early if not a sub field of a flexible content field
// - don't save field as lack of 'parent' will avoid any issues with field's 'parent_layout' setting
if( !$layout.exists() ) {
return this.delete_meta( $el );
}
// update meta
this.update_meta( $el, $layout );
// save field
// - parent_layout meta needs to be saved within the post_content serialized array
acf.field_group.save_field( $el );
},
/*
* render
*
* This function will update the field list class
*
* @type function
* @date 8/04/2014
* @since 5.0.0
*
* @param $field_list
* @return n/a
*/
render: function( $el ){
// reference
var self = this;
// vars
var $key = $el.find('.acf-fc-meta-key:first input'),
$fields = $el.find('.acf-field-list:first'),
display = $el.find('.acf-fc-meta-display:first select').val();
// update key
// - both duplicate and add function need this
$key.val( $el.attr('data-id') );
// update data
$fields.attr('data-layout', display);
// update meta
$fields.children('.acf-field-object').each(function(){
self.update_meta( $(this), $el );
});
},
/*
* events
*
* description
*
* @type function
* @date 25/09/2015
* @since 5.2.3
*
* @param $post_id (int)
* @return $post_id (int)
*/
_change_display: function( $el ){
this.render( $el );
},
_blur_label: function( $el ){
// vars
var $label = $el.find('.acf-fc-meta-label:first input'),
$name = $el.find('.acf-fc-meta-name:first input');
// only if name is empty
// render name
if( $name.val() == '' ) {
// vars
var s = $label.val();
// sanitize
s = acf.str_sanitize(s);
// update name
$name.val( s ).trigger('change');
acf.val($name, acf.strSanitize(label));
}
},
_add: function( $el ){
onClickAdd: function( e, $el ){
// vars
var prevKey = this.get('id');
var newKey = acf.uniqid('layout_');
// duplicate
var $el2 = acf.duplicate({
$el: $el,
$layout = acf.duplicate({
$el: this.$el,
search: prevKey,
replace: newKey,
after: function( $el, $el2 ){
// vars
var $list = $el2.find('.acf-field-list:first');
// remove sub fields
$el2.find('.acf-field-object').remove();
// show add new message
$el2.find('.no-fields-message').show();
$list.children('.acf-field-object').remove();
// show empty
$list.addClass('-empty');
// reset layout meta values
$el2.find('.acf-fc-meta input').val('');
}
});
// get layout
var layout = acf.getFieldSetting( $layout );
// render layout
this.render( $el2 );
// save field
acf.field_group.save_field( $el.closest('.acf-field-object') );
// update hidden input
layout.$input('key').val( newKey );
// save
this.fieldObject.save();
},
_duplicate: function( $el ){
onClickDuplicate: function( e, $el ){
// vars
var prevKey = this.get('id');
var newKey = acf.uniqid('layout_');
// duplicate
$el2 = acf.duplicate( $el );
// fire action 'duplicate_field' and allow acf.pro logic to clean sub fields
acf.do_action('duplicate_field', $el2);
// render layout
this.render( $el2 );
// save field
acf.field_group.save_field( $el.closest('.acf-field-object') );
},
_delete: function( $el ){
// validate
if( $el.siblings('.acf-field-setting-fc_layout').length == 0 ) {
alert( acf._e('flexible_content','layout_warning') );
return false;
}
// delete fields
$el.find('.acf-field-object').each(function(){
// delete without animation
acf.field_group.delete_field( $(this), false );
$layout = acf.duplicate({
$el: this.$el,
search: prevKey,
replace: newKey
});
// get all fields in new layout similar to fieldManager.onDuplicateField().
// important to run field.wipe() before making any changes to the "parent_layout" prop
// to ensure the correct input is modified.
var children = acf.getFieldObjects({ parent: $layout });
if( children.length ) {
// loop
children.map(function( child ){
// wipe field
child.wipe();
// update parent
child.updateParent();
});
// action
acf.doAction('duplicate_field_objects', children, this.fieldObject, this.fieldObject);
}
// get layout
var layout = acf.getFieldSetting( $layout );
// update hidden input
layout.$input('key').val( newKey );
// save
this.fieldObject.save();
},
onClickDelete: function( e, $el ){
// add class
this.$el.addClass('-hover');
// add tooltip
var tooltip = acf.newTooltip({
confirmRemove: true,
target: $el,
context: this,
confirm: function(){
this.delete();
},
cancel: function(){
this.$el.removeClass('-hover');
}
});
},
delete: function(){
// vars
var $siblings = this.$el.siblings('.acf-field-setting-fc_layout');
// validate
if( !$siblings.length ) {
alert( acf.__('Flexible Content requires at least 1 layout') );
return false;
}
// delete sub fields
this.getFields().map(function( child ){
child.delete({
animate: false
});
});
// remove tr
acf.remove_tr( $el );
acf.remove( this.$el );
// save field
acf.field_group.save_field( $el.closest('.acf-field-object') );
// save
this.fieldObject.save();
}
});
acf.registerFieldSetting( FlexibleContentLayoutFieldSetting );
/*
* clone
/**
* flexibleContentHelper
*
* This field type requires some extra logic for its settings
* description
*
* @type function
* @date 24/10/13
* @since 5.0.0
* @date 19/4/18
* @since 5.6.9
*
* @param n/a
* @return n/a
* @param type $var Description. Default.
* @return type Description.
*/
var acf_settings_clone = acf.field_group.field_object.extend({
type: 'clone',
var flexibleContentHelper = new acf.Model({
actions: {
'render_settings': 'render'
'sortstop_field_object': 'updateParentLayout',
'change_field_object_parent': 'updateParentLayout'
},
events: {
'change .acf-field-setting-display select': 'render_display',
'change .acf-field-setting-prefix_label input': 'render_prefix_label',
'change .acf-field-setting-prefix_name input': 'render_prefix_name'
},
render: function(){
// render
this.render_display();
this.render_prefix_label();
this.render_prefix_name();
},
render_display: function(){
updateParentLayout: function( fieldObject ){
// vars
var display = this.setting('display select').val()
var parent = fieldObject.getParent();
// update data
this.$field.attr('data-display', display);
},
render_prefix_label: function(){
// vars
var s = '%field_label%';
// is checked
if( this.setting('prefix_label input[type="checkbox"]').prop('checked') ) {
s = this.setting('label input[type="text"]').val() + ' ' + s;
// delete meta
if( !parent || parent.prop('type') !== 'flexible_content' ) {
fieldObject.prop('parent_layout', null);
return;
}
// get layout
var $layout = fieldObject.$el.closest('.acf-field-setting-fc_layout');
var layout = acf.getFieldSetting($layout);
// update code
this.setting('prefix_label code').html( s );
},
render_prefix_name: function(){
// vars
var s = '%field_name%';
// is checked
if( this.setting('prefix_name input[type="checkbox"]').prop('checked') ) {
s = this.setting('name input[type="text"]').val() + '_' + s;
// check if previous prop exists
// - if not, set prop to allow following code to trigger 'change' and save the field
if( !fieldObject.has('parent_layout') ) {
fieldObject.prop('parent_layout', 0);
}
// update code
this.setting('prefix_name code').html( s );
},
select2: null
// update meta
fieldObject.prop('parent_layout', layout.get('id'));
}
});
acf_settings_clone.select2 = acf.model.extend({
})(jQuery);
(function($){
/**
* CloneDisplayFieldSetting
*
* Extra logic for this field setting
*
* @date 18/4/18
* @since 5.6.9
*
* @param void
* @return void
*/
var CloneDisplayFieldSetting = acf.FieldSetting.extend({
type: 'clone',
name: 'display',
render: function(){
// vars
var display = this.field.val();
// set data attribute used by CSS to hide/show
this.$fieldObject.attr('data-display', display);
}
});
acf.registerFieldSetting( CloneDisplayFieldSetting );
/**
* ClonePrefixLabelFieldSetting
*
* Extra logic for this field setting
*
* @date 18/4/18
* @since 5.6.9
*
* @param void
* @return void
*/
var ClonePrefixLabelFieldSetting = acf.FieldSetting.extend({
type: 'clone',
name: 'prefix_label',
render: function(){
// vars
var prefix = '';
// if checked
if( this.field.val() ) {
prefix = this.fieldObject.prop('label') + ' ';
}
// update HTML
this.$('code').html( prefix + '%field_label%' );
}
});
acf.registerFieldSetting( ClonePrefixLabelFieldSetting );
/**
* ClonePrefixNameFieldSetting
*
* Extra logic for this field setting
*
* @date 18/4/18
* @since 5.6.9
*
* @param void
* @return void
*/
var ClonePrefixNameFieldSetting = acf.FieldSetting.extend({
type: 'clone',
name: 'prefix_name',
render: function(){
// vars
var prefix = '';
// if checked
if( this.field.val() ) {
prefix = this.fieldObject.prop('name') + '_';
}
// update HTML
this.$('code').html( prefix + '%field_name%' );
}
});
acf.registerFieldSetting( ClonePrefixNameFieldSetting );
/**
* cloneFieldSelectHelper
*
* Customizes the clone field setting Select2 isntance
*
* @date 18/4/18
* @since 5.6.9
*
* @param void
* @return void
*/
var cloneFieldSelectHelper = new acf.Model({
filters: {
'select2_args': 'select2_args',
'select2_ajax_data': 'select2_ajax_data'
'select2_args': 'select2Args'
},
select2_args: function( select2_args, $select, args ){
// bail early if not clone
if( args.ajax_action !== 'acf/fields/clone/query' ) return select2_args;
// remain open on select
select2_args.closeOnSelect = false;
select2Args: function( options, $select, data, $el, instance ){
// check
if( data.ajaxAction == 'acf/fields/clone/query' ) {
// remain open on select
options.closeOnSelect = false;
// customize ajaxData function
instance.data.ajaxData = this.ajaxData;
}
// return
return select2_args;
return options;
},
select2_ajax_data: function( data, args, params ){
// bail early if not clone
if( args.ajax_action !== 'acf/fields/clone/query' ) return data;
ajaxData: function( data ){
// find current fields
var fields = {};
data.fields = {};
// loop
$('.acf-field-object').each(function(){
acf.getFieldObjects().map(function(fieldObject){
// vars
var $el = $(this),
key = $el.data('key'),
type = $el.data('type'),
label = $el.find('.field-label:first').val(),
$ancestors = $el.parents('.acf-field-object');
// label
fields[ key ] = {
'key': key,
'type': type,
'label': label,
'ancestors': $ancestors.length
// append
data.fields[ fieldObject.prop('key') ] = {
key: fieldObject.prop('key'),
type: fieldObject.prop('type'),
label: fieldObject.prop('label'),
ancestors: fieldObject.getParents().length
};
});
// append fields
data.fields = fields;
// append title
data.title = $('#title').val();
// return
return data;
}
});
})(jQuery);
// @codekit-prepend "../js/field-group.js";
// @codekit-prepend "../js/acf-setting-repeater.js
// @codekit-prepend "../js/acf-setting-flexible-content.js
// @codekit-prepend "../js/acf-setting-clone.js

View File

@ -1 +1 @@
!function($){var e=acf.field_group.field_object.extend({type:"repeater",actions:{render_settings:"render"},events:{"change .acf-field-setting-layout input":"_change_layout","focus .acf-field-setting-collapsed select":"_focus_collapsed"},focus:function(){this.$fields=this.$field.find(".acf-field-list:first")},render:function(){this.render_layout(),this.render_collapsed()},render_layout:function(){var e=this.setting("layout input:checked").val();this.$fields.attr("data-layout",e)},render_collapsed:function(){var e=this.setting("collapsed select"),t=[];t.push({label:e.find('option[value=""]').text(),value:""}),this.$fields.children(".acf-field-object").each(function(){var e=$(this);t.push({label:e.find(".field-label:first").val(),value:e.attr("data-key")})}),acf.render_select(e,t)},_change_layout:function(e){this.render_layout()},_focus_collapsed:function(e){this.render_collapsed()}});acf.field_group.field_object.extend({type:"flexible_content",actions:{render_settings:"render"},render:function(){var e=this,t=this.$field;this.$settings.hasClass("ui-sortable")||this.$settings.sortable({items:"> .acf-field-setting-fc_layout",handle:'[data-name="acf-fc-reorder"]',forceHelperSize:!0,forcePlaceholderSize:!0,scroll:!0,stop:function(e,a){acf.field_group.save_field(t)}}),this.$settings.children(".acf-field-setting-fc_layout").each(function(){e.layout.render($(this))})},layout:null}).layout=acf.model.extend({actions:{update_field_parent:"update_field_parent"},events:{"change .acf-fc-meta-display select":"_change_display","blur .acf-fc-meta-label input":"_blur_label",'click a[data-name="acf-fc-add"]':"_add",'click a[data-name="acf-fc-duplicate"]':"_duplicate",'click a[data-name="acf-fc-delete"]':"_delete"},event:function(e){return e.$el.closest(".acf-field-setting-fc_layout")},update_meta:function(e,t){acf.field_group.update_field_meta(e,"parent_layout",t.attr("data-id"))},delete_meta:function(e){acf.field_group.delete_field_meta(e,"parent_layout")},update_field_parent:function(e,t){var a=e.closest(".acf-field-setting-fc_layout");if(!a.exists())return this.delete_meta(e);this.update_meta(e,a),acf.field_group.save_field(e)},render:function(e){var t=this,a=e.find(".acf-fc-meta-key:first input"),i=e.find(".acf-field-list:first"),l=e.find(".acf-fc-meta-display:first select").val();a.val(e.attr("data-id")),i.attr("data-layout",l),i.children(".acf-field-object").each(function(){t.update_meta($(this),e)})},_change_display:function(e){this.render(e)},_blur_label:function(e){var t=e.find(".acf-fc-meta-label:first input"),a=e.find(".acf-fc-meta-name:first input");if(""==a.val()){var i=t.val();i=acf.str_sanitize(i),a.val(i).trigger("change")}},_add:function(e){var t=acf.duplicate({$el:e,after:function(e,t){t.find(".acf-field-object").remove(),t.find(".no-fields-message").show(),t.find(".acf-fc-meta input").val("")}});this.render(t),acf.field_group.save_field(e.closest(".acf-field-object"))},_duplicate:function(e){$el2=acf.duplicate(e),acf.do_action("duplicate_field",$el2),this.render($el2),acf.field_group.save_field(e.closest(".acf-field-object"))},_delete:function(e){if(0==e.siblings(".acf-field-setting-fc_layout").length)return alert(acf._e("flexible_content","layout_warning")),!1;e.find(".acf-field-object").each(function(){acf.field_group.delete_field($(this),!1)}),acf.remove_tr(e),acf.field_group.save_field(e.closest(".acf-field-object"))}}),acf.field_group.field_object.extend({type:"clone",actions:{render_settings:"render"},events:{"change .acf-field-setting-display select":"render_display","change .acf-field-setting-prefix_label input":"render_prefix_label","change .acf-field-setting-prefix_name input":"render_prefix_name"},render:function(){this.render_display(),this.render_prefix_label(),this.render_prefix_name()},render_display:function(){var e=this.setting("display select").val();this.$field.attr("data-display",e)},render_prefix_label:function(){var e="%field_label%";this.setting('prefix_label input[type="checkbox"]').prop("checked")&&(e=this.setting('label input[type="text"]').val()+" "+e),this.setting("prefix_label code").html(e)},render_prefix_name:function(){var e="%field_name%";this.setting('prefix_name input[type="checkbox"]').prop("checked")&&(e=this.setting('name input[type="text"]').val()+"_"+e),this.setting("prefix_name code").html(e)},select2:null}).select2=acf.model.extend({filters:{select2_args:"select2_args",select2_ajax_data:"select2_ajax_data"},select2_args:function(e,t,a){return"acf/fields/clone/query"!==a.ajax_action?e:(e.closeOnSelect=!1,e)},select2_ajax_data:function(e,t,a){if("acf/fields/clone/query"!==t.ajax_action)return e;var i={};return $(".acf-field-object").each(function(){var e=$(this),t=e.data("key"),a=e.data("type"),l=e.find(".field-label:first").val(),n=e.parents(".acf-field-object");i[t]={key:t,type:a,label:l,ancestors:n.length}}),e.fields=i,e.title=$("#title").val(),e}})}(jQuery);
!function($){var e=acf.FieldSetting.extend({type:"repeater",name:"collapsed",events:{"focus select":"onFocus"},onFocus:function(e,t){var i=t,a=[];a.push({label:i.find('option[value=""]').text(),value:""});var l=this.fieldObject.$(".acf-field-list:first");acf.getFieldObjects({list:l}).map(function(e){a.push({label:e.prop("label"),value:e.prop("key")})}),acf.renderSelect(i,a)}});acf.registerFieldSetting(e)}(jQuery),function($){var e=acf.FieldSetting.extend({type:"flexible_content",name:"fc_layout",events:{"blur .layout-label":"onChangeLabel","click .add-layout":"onClickAdd","click .duplicate-layout":"onClickDuplicate","click .delete-layout":"onClickDelete"},$input:function(e){return $("#"+this.getInputId()+"-"+e)},$list:function(){return this.$(".acf-field-list:first")},getInputId:function(){return this.fieldObject.getInputId()+"-layouts-"+this.field.get("id")},getFields:function(){return acf.getFieldObjects({parent:this.$el})},getChildren:function(){return acf.getFieldObjects({list:this.$list()})},initialize:function(){var e=this.$el.parent();e.hasClass("ui-sortable")||e.sortable({items:"> .acf-field-setting-fc_layout",handle:".reorder-layout",forceHelperSize:!0,forcePlaceholderSize:!0,scroll:!0,stop:this.proxy(function(e,t){this.fieldObject.save()})}),this.updateFieldLayouts()},updateFieldLayouts:function(){this.getChildren().map(this.updateFieldLayout,this)},updateFieldLayout:function(e){e.prop("parent_layout",this.get("id"))},onChangeLabel:function(e,t){var i=t.val(),a=this.$input("name");""==a.val()&&acf.val(a,acf.strSanitize(i))},onClickAdd:function(e,t){var i=this.get("id"),a=acf.uniqid("layout_");$layout=acf.duplicate({$el:this.$el,search:i,replace:a,after:function(e,t){var i=t.find(".acf-field-list:first");i.children(".acf-field-object").remove(),i.addClass("-empty"),t.find(".acf-fc-meta input").val("")}}),acf.getFieldSetting($layout).$input("key").val(a),this.fieldObject.save()},onClickDuplicate:function(e,t){var i=this.get("id"),a=acf.uniqid("layout_");$layout=acf.duplicate({$el:this.$el,search:i,replace:a});var l=acf.getFieldObjects({parent:$layout});l.length&&(l.map(function(e){e.wipe(),e.updateParent()}),acf.doAction("duplicate_field_objects",l,this.fieldObject,this.fieldObject)),acf.getFieldSetting($layout).$input("key").val(a),this.fieldObject.save()},onClickDelete:function(e,t){this.$el.addClass("-hover");var i=acf.newTooltip({confirmRemove:!0,target:t,context:this,confirm:function(){this.delete()},cancel:function(){this.$el.removeClass("-hover")}})},delete:function(){if(!this.$el.siblings(".acf-field-setting-fc_layout").length)return alert(acf.__("Flexible Content requires at least 1 layout")),!1;this.getFields().map(function(e){e.delete({animate:!1})}),acf.remove(this.$el),this.fieldObject.save()}});acf.registerFieldSetting(e);var t=new acf.Model({actions:{sortstop_field_object:"updateParentLayout",change_field_object_parent:"updateParentLayout"},updateParentLayout:function(e){var t=e.getParent();if(!t||"flexible_content"!==t.prop("type"))return void e.prop("parent_layout",null);var i=e.$el.closest(".acf-field-setting-fc_layout"),a=acf.getFieldSetting(i);e.has("parent_layout")||e.prop("parent_layout",0),e.prop("parent_layout",a.get("id"))}})}(jQuery),function($){var e=acf.FieldSetting.extend({type:"clone",name:"display",render:function(){var e=this.field.val();this.$fieldObject.attr("data-display",e)}});acf.registerFieldSetting(e);var t=acf.FieldSetting.extend({type:"clone",name:"prefix_label",render:function(){var e="";this.field.val()&&(e=this.fieldObject.prop("label")+" "),this.$("code").html(e+"%field_label%")}});acf.registerFieldSetting(t);var i=acf.FieldSetting.extend({type:"clone",name:"prefix_name",render:function(){var e="";this.field.val()&&(e=this.fieldObject.prop("name")+"_"),this.$("code").html(e+"%field_name%")}});acf.registerFieldSetting(i);var a=new acf.Model({filters:{select2_args:"select2Args"},select2Args:function(e,t,i,a,l){return"acf/fields/clone/query"==i.ajaxAction&&(e.closeOnSelect=!1,l.data.ajaxData=this.ajaxData),e},ajaxData:function(e){return e.fields={},acf.getFieldObjects().map(function(t){e.fields[t.prop("key")]={key:t.prop("key"),type:t.prop("type"),label:t.prop("label"),ancestors:t.getParents().length}}),e.title=$("#title").val(),e}})}(jQuery);

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1325,7 +1325,7 @@ class acf_field_clone extends acf_field {
// initialize
acf_register_field_type( new acf_field_clone() );
acf_register_field_type( 'acf_field_clone' );
endif; // class_exists check

View File

@ -30,18 +30,6 @@ class acf_field_flexible_content extends acf_field {
'max' => '',
'button_label' => __("Add Row",'acf'),
);
$this->l10n = array(
'layout' => __("layout", 'acf'),
'layouts' => __("layouts", 'acf'),
'remove' => __("remove {layout}?", 'acf'),
'min' => __("This field requires at least {min} {identifier}",'acf'),
'max' => __("This field has a limit of {max} {identifier}",'acf'),
'min_layout' => __("This field requires at least {min} {label} {identifier}",'acf'),
'max_layout' => __("Maximum {label} limit reached ({max} {identifier})",'acf'),
'available' => __("{available} {label} {identifier} available (max {max})",'acf'),
'required' => __("{required} {label} {identifier} required (min {min})",'acf'),
'layout_warning' => __('Flexible Content requires at least 1 layout','acf')
);
// ajax
@ -63,6 +51,42 @@ class acf_field_flexible_content extends acf_field {
}
/*
* input_admin_enqueue_scripts
*
* description
*
* @type function
* @date 16/12/2015
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_enqueue_scripts() {
// localize
acf_localize_text(array(
// identifiers
'layout' => __('layout', 'acf'),
'layouts' => __('layouts', 'acf'),
// min / max
'This field requires at least {min} {label} {identifier}' => __('This field requires at least {min} {label} {identifier}', 'acf'),
'This field has a limit of {max} {label} {identifier}' => __('This field has a limit of {max} {label} {identifier}', 'acf'),
// popup badge
'{available} {label} {identifier} available (max {max})' => __('{available} {label} {identifier} available (max {max})', 'acf'),
'{required} {label} {identifier} required (min {min})' => __('{required} {label} {identifier} required (min {min})', 'acf'),
// field settings
'Flexible Content requires at least 1 layout' => __('Flexible Content requires at least 1 layout', 'acf')
));
}
/*
* get_valid_layout
*
@ -268,6 +292,11 @@ class acf_field_flexible_content extends acf_field {
'data-max' => $field['max']
);
// empty
if( empty($field['value']) ) {
$div['class'] .= ' -empty';
}
// no value message
$no_value_message = __('Click the "%s" button below to start creating your layout','acf');
@ -278,7 +307,7 @@ class acf_field_flexible_content extends acf_field {
<?php acf_hidden_input(array( 'name' => $field['name'] )); ?>
<div class="no-value-message" <?php if( $field['value'] ){ echo 'style="display:none;"'; } ?>>
<div class="no-value-message">
<?php printf( $no_value_message, $field['button_label'] ); ?>
</div>
@ -310,7 +339,7 @@ class acf_field_flexible_content extends acf_field {
</div>
<script type="text-html" class="tmpl-popup"><?php
?><div class="acf-fc-popup"><ul><?php foreach( $layouts as $layout ):
?><ul><?php foreach( $layouts as $layout ):
$atts = array(
'href' => '#',
@ -321,7 +350,7 @@ class acf_field_flexible_content extends acf_field {
?><li><a <?php acf_esc_attr_e( $atts ); ?>><?php echo $layout['label']; ?></a></li><?php
endforeach; ?></ul></div>
endforeach; ?></ul>
</script>
</div>
@ -359,14 +388,6 @@ class acf_field_flexible_content extends acf_field {
'data-layout' => $layout['name']
);
// collapsed class
if( acf_is_row_collapsed($field['key'], $i) ) {
$div['class'] .= ' -collapsed';
}
// clone
if( is_numeric($i) ) {
@ -402,7 +423,7 @@ class acf_field_flexible_content extends acf_field {
<div class="acf-fc-layout-handle" title="<?php _e('Drag to reorder','acf'); ?>" data-name="collapse-layout"><?php echo $title; ?></div>
<div class="acf-fc-layout-controlls">
<div class="acf-fc-layout-controls">
<a class="acf-icon -plus small light acf-js-tooltip" href="#" data-name="add-layout" title="<?php _e('Add layout','acf'); ?>"></a>
<a class="acf-icon -minus small light acf-js-tooltip" href="#" data-name="remove-layout" title="<?php _e('Remove layout','acf'); ?>"></a>
<a class="acf-icon -collapse small acf-js-tooltip" href="#" data-name="collapse-layout" title="<?php _e('Click to toggle','acf'); ?>"></a>
@ -464,14 +485,6 @@ class acf_field_flexible_content extends acf_field {
// loop though sub fields
foreach( $sub_fields as $sub_field ) {
// prevent repeater field from creating multiple conditional logic items for each row
if( $i !== 'acfcloneindex' ) {
$sub_field['conditional_logic'] = 0;
}
// add value
if( isset($value[ $sub_field['key'] ]) ) {
@ -552,33 +565,32 @@ class acf_field_flexible_content extends acf_field {
?><tr class="acf-field acf-field-setting-fc_layout" data-name="fc_layout" data-setting="flexible_content" data-id="<?php echo $layout['key']; ?>">
<td class="acf-label">
<label><?php _e("Layout",'acf'); ?></label>
<p class="description acf-fl-actions">
<a data-name="acf-fc-reorder" title="<?php _e("Reorder Layout",'acf'); ?>" ><?php _e("Reorder",'acf'); ?></a>
<a data-name="acf-fc-delete" title="<?php _e("Delete Layout",'acf'); ?>" href="#"><?php _e("Delete",'acf'); ?></a>
<a data-name="acf-fc-duplicate" title="<?php _e("Duplicate Layout",'acf'); ?>" href="#"><?php _e("Duplicate",'acf'); ?></a>
<a data-name="acf-fc-add" title="<?php _e("Add New Layout",'acf'); ?>" href="#"><?php _e("Add New",'acf'); ?></a>
</p>
<ul class="acf-bl acf-fl-actions">
<li><a class="reorder-layout" href="#" title="<?php _e("Reorder Layout",'acf'); ?>"><?php _e("Reorder",'acf'); ?></a></li>
<li><a class="delete-layout" href="#" title="<?php _e("Delete Layout",'acf'); ?>"><?php _e("Delete",'acf'); ?></a></li>
<li><a class="duplicate-layout" href="#" title="<?php _e("Duplicate Layout",'acf'); ?>"><?php _e("Duplicate",'acf'); ?></a></li>
<li><a class="add-layout" href="#" title="<?php _e("Add New Layout",'acf'); ?>"><?php _e("Add New",'acf'); ?></a></li>
</ul>
</td>
<td class="acf-input">
<?php
acf_hidden_input(array(
'id' => acf_idify( $layout_prefix . '[key]' ),
'name' => $layout_prefix . '[key]',
'class' => 'layout-key',
'value' => $layout['key']
));
?>
<ul class="acf-fc-meta acf-bl">
<li class="acf-fc-meta-key">
<?php
acf_hidden_input(array(
'name' => "{$layout_prefix}[key]",
'data-name' => 'layout-key',
'value' => $layout['key']
));
?>
</li>
<li class="acf-fc-meta-label">
<?php
acf_render_field(array(
'type' => 'text',
'name' => 'label',
'class' => 'layout-label',
'prefix' => $layout_prefix,
'value' => $layout['label'],
'prepend' => __('Label','acf')
@ -592,6 +604,7 @@ class acf_field_flexible_content extends acf_field {
acf_render_field(array(
'type' => 'text',
'name' => 'name',
'class' => 'layout-name',
'prefix' => $layout_prefix,
'value' => $layout['name'],
'prepend' => __('Name','acf')
@ -893,139 +906,132 @@ class acf_field_flexible_content extends acf_field {
function validate_value( $valid, $value, $field, $input ){
// remove acfcloneindex
if( isset($value['acfcloneindex']) ) {
// vars
$count = 0;
unset($value['acfcloneindex']);
// check if is value (may be empty string)
if( is_array($value) ) {
// remove acfcloneindex
if( isset($value['acfcloneindex']) ) {
unset($value['acfcloneindex']);
}
// count
$count = count($value);
}
// check if no value
if( $field['required'] && empty($value) ) return false;
// validate required
if( $field['required'] && !$count ) {
$valid = false;
}
// vars
$count = 0;
// validate min
$min = (int) $field['min'];
if( $min && $count < $min ) {
// vars
$error = __('This field requires at least {min} {label} {identifier}', 'acf');
$identifier = _n('layout', 'layouts', $min);
// replace
$error = str_replace('{min}', $min, $error);
$error = str_replace('{label}', '', $error);
$error = str_replace('{identifier}', $identifier, $error);
// return
return $error;
}
// find layouts
$layouts = array();
// populate $layouts
foreach( array_keys($field['layouts']) as $i ) {
// vars
$layout = $field['layouts'][ $i ];
// add count
$layout['count'] = 0;
// append
$layouts[ $layout['name'] ] = $layout;
}
// check sub fields
if( !empty($value) ) {
// validate value
if( $count ) {
// set count
$count = count($value);
// loop through rows
// loop rows
foreach( $value as $i => $row ) {
// get layout
$l = $row['acf_fc_layout'];
// bail if layout doesn't exist
if( !isset($layouts[ $l ]) ) continue;
if( !isset($layouts[ $l ]) ) {
continue;
}
// increase count
$layouts[ $l ]['count']++;
// bail if no sub fields
if( empty($layouts[ $l ]['sub_fields']) ) continue;
if( empty($layouts[ $l ]['sub_fields']) ) {
continue;
}
// loop
// loop sub fields
foreach( $layouts[ $l ]['sub_fields'] as $sub_field ) {
// get sub field key
$k = $sub_field['key'];
// bail if no value
if( !isset($value[ $i ][ $k ]) ) continue;
if( !isset($value[ $i ][ $k ]) ) {
continue;
}
// validate
acf_validate_value( $value[ $i ][ $k ], $sub_field, "{$input}[{$i}][{$k}]" );
}
// end loop sub fields
}
}
// validate min / max
$min = (int) $field['min'];
if( $min && $min > $count ) {
// vars
$error = $this->l10n['min'];
$identifier = ($min == 1) ? $this->l10n['layout'] : $this->l10n['layouts'];
// replace
$error = str_replace('{min}', $min, $error);
$error = str_replace('{identifier}', $identifier, $error);
// return
return $error;
// end loop rows
}
// validate layouts
foreach( $layouts as $layout ) {
// validate min / max
$min = (int) $layout['min'];
$count = $layout['count'];
$label = $layout['label'];
if( $min && $min > $count ) {
if( $min && $count < $min ) {
// vars
$error = $this->l10n['min_layout'];
$identifier = ($min == 1) ? $this->l10n['layout'] : $this->l10n['layouts'];
$error = __('This field requires at least {min} {label} {identifier}', 'acf');
$identifier = _n('layout', 'layouts', $min);
// replace
$error = str_replace('{min}', $min, $error);
$error = str_replace('{label}', '"' . $layout['label'] . '"', $error);
$error = str_replace('{label}', '"' . $label . '"', $error);
$error = str_replace('{identifier}', $identifier, $error);
// return
return $error;
return $error;
}
}
// return
return $valid;
}

View File

@ -37,13 +37,6 @@ class acf_field_gallery extends acf_field {
'mime_types' => '',
'insert' => 'append'
);
$this->l10n = array(
'select' => __("Add Image to Gallery",'acf'),
'edit' => __("Edit Image",'acf'),
'update' => __("Update Image",'acf'),
'uploadedTo' => __("Uploaded to this post",'acf'),
'max' => __("Maximum selection reached",'acf')
);
// actions
@ -58,6 +51,28 @@ class acf_field_gallery extends acf_field {
}
/*
* input_admin_enqueue_scripts
*
* description
*
* @type function
* @date 16/12/2015
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_enqueue_scripts() {
// localize
acf_localize_text(array(
'Add Image to Gallery' => __('Add Image to Gallery', 'acf'),
'Maximum selection reached' => __('Maximum selection reached', 'acf'),
));
}
/*
* ajax_get_attachment

View File

@ -32,10 +32,6 @@ class acf_field_repeater extends acf_field {
'button_label' => '',
'collapsed' => ''
);
$this->l10n = array(
'min' => __("Minimum rows reached ({min} rows)",'acf'),
'max' => __("Maximum rows reached ({max} rows)",'acf'),
);
// field filters
@ -47,7 +43,30 @@ class acf_field_repeater extends acf_field {
$this->add_filter('acf/validate_field', array($this, 'validate_any_field'));
}
/*
* input_admin_enqueue_scripts
*
* description
*
* @type function
* @date 16/12/2015
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_enqueue_scripts() {
// localize
acf_localize_text(array(
'Minimum rows reached ({min} rows)' => __('Minimum rows reached ({min} rows)', 'acf'),
'Maximum rows reached ({max} rows)' => __('Maximum rows reached ({max} rows)', 'acf'),
));
}
/*
* load_field()
@ -202,22 +221,15 @@ class acf_field_repeater extends acf_field {
// collapsed
if( $field['collapsed'] ) {
// add target class
foreach( $sub_fields as $i => $sub_field ) {
// bail early if no match
if( $sub_field['key'] !== $field['collapsed'] ) continue;
// class
$sub_field['wrapper']['class'] .= ' -collapsed-target';
// update
$sub_fields[ $i ] = $sub_field;
// loop
foreach( $sub_fields as &$sub_field ) {
// add target class
if( $sub_field['key'] == $field['collapsed'] ) {
$sub_field['wrapper']['class'] .= ' -collapsed-target';
}
}
unset( $sub_field );
}
?>
@ -275,22 +287,8 @@ class acf_field_repeater extends acf_field {
<?php endif; ?>
<tbody>
<?php foreach( $value as $i => $row ):
$row_class = 'acf-row';
if( $i === 'acfcloneindex' ) {
$row_class .= ' acf-clone';
} elseif( $field['collapsed'] && acf_is_row_collapsed($field['key'], $i) ) {
$row_class .= ' -collapsed';
}
?>
<tr class="<?php echo $row_class; ?>" data-id="<?php echo $i; ?>">
<?php foreach( $value as $i => $row ): ?>
<tr class="acf-row<?php if( $i === 'acfcloneindex' ){ echo ' acf-clone'; } ?>" data-id="<?php echo $i; ?>">
<?php if( $show_order ): ?>
<td class="acf-row-handle order" title="<?php _e('Drag to reorder','acf'); ?>">
@ -305,14 +303,6 @@ class acf_field_repeater extends acf_field {
<?php foreach( $sub_fields as $sub_field ):
// prevent repeater field from creating multiple conditional logic items for each row
if( $i !== 'acfcloneindex' ) {
$sub_field['conditional_logic'] = 0;
}
// add value
if( isset($row[ $sub_field['key'] ]) ) {
@ -405,16 +395,19 @@ class acf_field_repeater extends acf_field {
$field['max'] = empty($field['max']) ? '' : $field['max'];
// preview
// collapsed
$choices = array();
if( $field['collapsed'] ) {
$choices[ $field['collapsed'] ] = $field['collapsed'];
// load sub field
$sub_field = acf_get_field($field['collapsed']);
// append choice
if( $sub_field ) {
$choices[ $sub_field['key'] ] = $sub_field['label'];
}
}
acf_render_field_setting( $field, array(
'label' => __('Collapsed','acf'),
'instructions' => __('Select a sub field to show when row is collapsed','acf'),
@ -632,53 +625,75 @@ class acf_field_repeater extends acf_field {
function validate_value( $valid, $value, $field, $input ){
// remove acfcloneindex
if( isset($value['acfcloneindex']) ) {
// vars
$count = 0;
unset($value['acfcloneindex']);
// check if is value (may be empty string)
if( is_array($value) ) {
// remove acfcloneindex
if( isset($value['acfcloneindex']) ) {
unset($value['acfcloneindex']);
}
// count
$count = count($value);
}
// valid
if( $field['required'] && empty($value) ) {
// validate required
if( $field['required'] && !$count ) {
$valid = false;
}
// check sub fields
if( !empty($field['sub_fields']) && !empty($value) ) {
// min
$min = (int) $field['min'];
if( $min && $count < $min ) {
$keys = array_keys($value);
// create error
$error = __('Minimum rows reached ({min} rows)', 'acf');
$error = str_replace('{min}', $min, $error);
// return
return $error;
}
// validate value
if( $count ) {
foreach( $keys as $i ) {
// bail early if no sub fields
if( !$field['sub_fields'] ) {
return $valid;
}
// loop rows
foreach( $value as $i => $row ) {
// loop sub fields
foreach( $field['sub_fields'] as $sub_field ) {
// vars
$k = $sub_field['key'];
// test sub field exists
if( !isset($value[ $i ][ $k ]) ) {
if( !isset($row[ $k ]) ) {
continue;
}
// validate
acf_validate_value( $value[ $i ][ $k ], $sub_field, "{$input}[{$i}][{$k}]" );
acf_validate_value( $row[ $k ], $sub_field, "{$input}[{$i}][{$k}]" );
}
// end loop sub fields
}
// end loop rows
}
return $valid;
// return
return $valid;
}

View File

@ -66,6 +66,20 @@ From your WordPress dashboard
== Changelog ==
= 5.7.0 =
* Core: Major JavaScript updates
* Core: Improved conditional logic with new types and more supported fields
* Core: Improved localization and internationalization
* Repeater field: Improved logic that remembers collapsed row states
* Repeater field: Added support to collapse multiple rows (hold shift)
* API: Improved lookup to find fields without a reference value
* Language: Added Croatian translation - Thanks to Vlado Bosnjak
* Language: Updated Italian translation - thanks to Davide Pantè
* Language: Updated Romanian translation - thanks to Ionut Staicu
* Language: Updated German translation - thanks to Ralf Koller
* Language: Updated Arabic translation - thanks to Karim Ramadan
* Language: Updated Portuguese translation - thanks to Pedro Mendonça
= 5.6.10 =
* Core: Minor fixes and improvements