Update to 5.11.4
This commit is contained in:
parent
5257f76538
commit
7194752c6c
8
acf.php
8
acf.php
|
|
@ -3,7 +3,7 @@
|
||||||
Plugin Name: Advanced Custom Fields PRO
|
Plugin Name: Advanced Custom Fields PRO
|
||||||
Plugin URI: https://www.advancedcustomfields.com
|
Plugin URI: https://www.advancedcustomfields.com
|
||||||
Description: Customize WordPress with powerful, professional and intuitive fields.
|
Description: Customize WordPress with powerful, professional and intuitive fields.
|
||||||
Version: 5.10.2
|
Version: 5.11.4
|
||||||
Author: Delicious Brains
|
Author: Delicious Brains
|
||||||
Author URI: https://www.advancedcustomfields.com
|
Author URI: https://www.advancedcustomfields.com
|
||||||
Text Domain: acf
|
Text Domain: acf
|
||||||
|
|
@ -19,7 +19,7 @@ if ( ! class_exists( 'ACF' ) ) :
|
||||||
class ACF {
|
class ACF {
|
||||||
|
|
||||||
/** @var string The plugin version number. */
|
/** @var string The plugin version number. */
|
||||||
var $version = '5.10.2';
|
var $version = '5.11.4';
|
||||||
|
|
||||||
/** @var array The plugin settings array. */
|
/** @var array The plugin settings array. */
|
||||||
var $settings = array();
|
var $settings = array();
|
||||||
|
|
@ -97,6 +97,9 @@ if ( ! class_exists( 'ACF' ) ) :
|
||||||
'select2_version' => 4,
|
'select2_version' => 4,
|
||||||
'row_index_offset' => 1,
|
'row_index_offset' => 1,
|
||||||
'remove_wp_meta_box' => true,
|
'remove_wp_meta_box' => true,
|
||||||
|
'rest_api_enabled' => true,
|
||||||
|
'rest_api_format' => 'light',
|
||||||
|
'rest_api_embed_links' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Include utility functions.
|
// Include utility functions.
|
||||||
|
|
@ -142,6 +145,7 @@ if ( ! class_exists( 'ACF' ) ) :
|
||||||
acf_include( 'includes/updates.php' );
|
acf_include( 'includes/updates.php' );
|
||||||
acf_include( 'includes/upgrades.php' );
|
acf_include( 'includes/upgrades.php' );
|
||||||
acf_include( 'includes/validation.php' );
|
acf_include( 'includes/validation.php' );
|
||||||
|
acf_include( 'includes/rest-api.php' );
|
||||||
|
|
||||||
// Include ajax.
|
// Include ajax.
|
||||||
acf_include( 'includes/ajax/class-acf-ajax.php' );
|
acf_include( 'includes/ajax/class-acf-ajax.php' );
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
/*!***************************************************************************************************************************************************************************************************************!*\
|
||||||
|
!*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].use[1]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[1].use[2]!./src/advanced-custom-fields-pro/assets/src/sass/acf-dark.scss ***!
|
||||||
|
\***************************************************************************************************************************************************************************************************************/
|
||||||
/*--------------------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Dark mode
|
* Dark mode
|
||||||
|
|
@ -313,4 +316,6 @@
|
||||||
border-color: #191f25;
|
border-color: #191f25;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*# sourceMappingURL=acf-dark.css.map*/
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
/******/ (function() { // webpackBootstrap
|
||||||
|
/******/ "use strict";
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/ })()
|
||||||
|
;
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1,3 +1,6 @@
|
||||||
|
/*!**********************************************************************************************************************************************************************************************************************!*\
|
||||||
|
!*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].use[1]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[1].use[2]!./src/advanced-custom-fields-pro/assets/src/sass/acf-field-group.scss ***!
|
||||||
|
\**********************************************************************************************************************************************************************************************************************/
|
||||||
/*--------------------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Vars
|
* Vars
|
||||||
|
|
@ -478,4 +481,6 @@ td.acf-input {
|
||||||
background: transparent !important;
|
background: transparent !important;
|
||||||
padding-bottom: 0 !important;
|
padding-bottom: 0 !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*# sourceMappingURL=acf-field-group.css.map*/
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
/******/ (function() { // webpackBootstrap
|
||||||
|
/******/ "use strict";
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/ })()
|
||||||
|
;
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,6 @@
|
||||||
@charset "UTF-8";
|
/*!*****************************************************************************************************************************************************************************************************************!*\
|
||||||
|
!*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].use[1]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[1].use[2]!./src/advanced-custom-fields-pro/assets/src/sass/acf-global.scss ***!
|
||||||
|
\*****************************************************************************************************************************************************************************************************************/
|
||||||
/*--------------------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Vars
|
* Vars
|
||||||
|
|
@ -336,89 +338,89 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-plus:before {
|
.acf-icon.-plus:before {
|
||||||
content: "";
|
content: "\f543";
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-minus:before {
|
.acf-icon.-minus:before {
|
||||||
content: "";
|
content: "\f460";
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-cancel:before {
|
.acf-icon.-cancel:before {
|
||||||
content: "";
|
content: "\f335";
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-pencil:before {
|
.acf-icon.-pencil:before {
|
||||||
content: "";
|
content: "\f464";
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-location:before {
|
.acf-icon.-location:before {
|
||||||
content: "";
|
content: "\f230";
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-up:before {
|
.acf-icon.-up:before {
|
||||||
content: "";
|
content: "\f343";
|
||||||
margin-top: -0.1em;
|
margin-top: -0.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-down:before {
|
.acf-icon.-down:before {
|
||||||
content: "";
|
content: "\f347";
|
||||||
margin-top: 0.1em;
|
margin-top: 0.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-left:before {
|
.acf-icon.-left:before {
|
||||||
content: "";
|
content: "\f341";
|
||||||
margin-left: -0.1em;
|
margin-left: -0.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-right:before {
|
.acf-icon.-right:before {
|
||||||
content: "";
|
content: "\f345";
|
||||||
margin-left: 0.1em;
|
margin-left: 0.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-sync:before {
|
.acf-icon.-sync:before {
|
||||||
content: "";
|
content: "\f463";
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-globe:before {
|
.acf-icon.-globe:before {
|
||||||
content: "";
|
content: "\f319";
|
||||||
margin-top: 0.1em;
|
margin-top: 0.1em;
|
||||||
margin-left: 0.1em;
|
margin-left: 0.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-picture:before {
|
.acf-icon.-picture:before {
|
||||||
content: "";
|
content: "\f128";
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-check:before {
|
.acf-icon.-check:before {
|
||||||
content: "";
|
content: "\f147";
|
||||||
margin-left: -0.1em;
|
margin-left: -0.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-dot-3:before {
|
.acf-icon.-dot-3:before {
|
||||||
content: "";
|
content: "\f533";
|
||||||
margin-top: -0.1em;
|
margin-top: -0.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-arrow-combo:before {
|
.acf-icon.-arrow-combo:before {
|
||||||
content: "";
|
content: "\f156";
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-arrow-up:before {
|
.acf-icon.-arrow-up:before {
|
||||||
content: "";
|
content: "\f142";
|
||||||
margin-left: -0.1em;
|
margin-left: -0.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-arrow-down:before {
|
.acf-icon.-arrow-down:before {
|
||||||
content: "";
|
content: "\f140";
|
||||||
margin-left: -0.1em;
|
margin-left: -0.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-search:before {
|
.acf-icon.-search:before {
|
||||||
content: "";
|
content: "\f179";
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-link-ext:before {
|
.acf-icon.-link-ext:before {
|
||||||
content: "";
|
content: "\f504";
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-duplicate {
|
.acf-icon.-duplicate {
|
||||||
|
|
@ -443,12 +445,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.acf-icon.-collapse:before {
|
.acf-icon.-collapse:before {
|
||||||
content: "";
|
content: "\f142";
|
||||||
margin-left: -0.1em;
|
margin-left: -0.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.-collapsed .acf-icon.-collapse:before {
|
.-collapsed .acf-icon.-collapse:before {
|
||||||
content: "";
|
content: "\f140";
|
||||||
margin-left: -0.1em;
|
margin-left: -0.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1659,4 +1661,6 @@ html[dir=rtl] .acf-table > tbody > tr > td.order + td {
|
||||||
background-image: url(../../images/spinner@2x.gif);
|
background-image: url(../../images/spinner@2x.gif);
|
||||||
background-size: 20px 20px;
|
background-size: 20px 20px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*# sourceMappingURL=acf-global.css.map*/
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
/******/ (function() { // webpackBootstrap
|
||||||
|
/******/ "use strict";
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/ })()
|
||||||
|
;
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1,3 +1,6 @@
|
||||||
|
/*!****************************************************************************************************************************************************************************************************************!*\
|
||||||
|
!*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].use[1]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[1].use[2]!./src/advanced-custom-fields-pro/assets/src/sass/acf-input.scss ***!
|
||||||
|
\****************************************************************************************************************************************************************************************************************/
|
||||||
/*--------------------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Vars
|
* Vars
|
||||||
|
|
@ -647,6 +650,9 @@ html[dir=rtl] .select2-container.-acf .select2-choice .select2-arrow {
|
||||||
.select2-container.-acf li {
|
.select2-container.-acf li {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
.select2-container.-acf[data-select2-id^=select2-data] .select2-selection--multiple {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
.select2-container.-acf .select2-selection {
|
.select2-container.-acf .select2-selection {
|
||||||
border-color: #7e8993;
|
border-color: #7e8993;
|
||||||
}
|
}
|
||||||
|
|
@ -662,6 +668,14 @@ html[dir=rtl] .select2-container.-acf .select2-choice .select2-arrow {
|
||||||
.select2-container.-acf .select2-selection--multiple .select2-selection__rendered {
|
.select2-container.-acf .select2-selection--multiple .select2-selection__rendered {
|
||||||
padding-right: 0;
|
padding-right: 0;
|
||||||
}
|
}
|
||||||
|
.select2-container.-acf .select2-selection--multiple .select2-selection__rendered[id^=select2-acf-field] {
|
||||||
|
display: inline;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.select2-container.-acf .select2-selection--multiple .select2-selection__rendered[id^=select2-acf-field] .select2-selection__choice {
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
.select2-container.-acf .select2-selection--multiple .select2-selection__choice {
|
.select2-container.-acf .select2-selection--multiple .select2-selection__choice {
|
||||||
background-color: #f7f7f7;
|
background-color: #f7f7f7;
|
||||||
border-color: #cccccc;
|
border-color: #cccccc;
|
||||||
|
|
@ -679,6 +693,11 @@ html[dir=rtl] .select2-container.-acf .select2-choice .select2-arrow {
|
||||||
.select2-container.-acf .select2-selection--multiple .select2-selection__choice.ui-sortable-helper span {
|
.select2-container.-acf .select2-selection--multiple .select2-selection__choice.ui-sortable-helper span {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
|
.select2-container.-acf .select2-selection--multiple .select2-selection__choice .select2-selection__choice__remove {
|
||||||
|
position: static;
|
||||||
|
border-right: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
.select2-container.-acf .select2-selection--multiple .select2-selection__choice.ui-sortable-placeholder {
|
.select2-container.-acf .select2-selection--multiple .select2-selection__choice.ui-sortable-placeholder {
|
||||||
background-color: #f7f7f7;
|
background-color: #f7f7f7;
|
||||||
border-color: #f7f7f7;
|
border-color: #f7f7f7;
|
||||||
|
|
@ -695,6 +714,10 @@ html[dir=rtl] .select2-container.-acf .select2-choice .select2-arrow {
|
||||||
white-space: normal;
|
white-space: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.select2-dropdown .select2-results__option {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.select2-container .select2-dropdown {
|
.select2-container .select2-dropdown {
|
||||||
z-index: 900000;
|
z-index: 900000;
|
||||||
}
|
}
|
||||||
|
|
@ -2929,4 +2952,6 @@ body.is-dragging-metaboxes #acf_after_title-sortables {
|
||||||
display: flow-root;
|
display: flow-root;
|
||||||
min-height: 60px;
|
min-height: 60px;
|
||||||
margin-bottom: 3px !important;
|
margin-bottom: 3px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*# sourceMappingURL=acf-input.css.map*/
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
/******/ (function() { // webpackBootstrap
|
||||||
|
/******/ "use strict";
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/ })()
|
||||||
|
;
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1,3 +1,6 @@
|
||||||
|
/*!******************************************************************************************************************************************************************************************************************************!*\
|
||||||
|
!*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].use[1]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[1].use[2]!./src/advanced-custom-fields-pro/assets/src/sass/pro/acf-pro-field-group.scss ***!
|
||||||
|
\******************************************************************************************************************************************************************************************************************************/
|
||||||
/*--------------------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Vars
|
* Vars
|
||||||
|
|
@ -64,4 +67,6 @@
|
||||||
.acf-field-object-clone[data-display=seamless] .acf-field-setting-wrapper,
|
.acf-field-object-clone[data-display=seamless] .acf-field-setting-wrapper,
|
||||||
.acf-field-object-clone[data-display=seamless] .acf-field-setting-conditional_logic {
|
.acf-field-object-clone[data-display=seamless] .acf-field-setting-conditional_logic {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*# sourceMappingURL=acf-pro-field-group.css.map*/
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
/******/ (function() { // webpackBootstrap
|
||||||
|
/******/ "use strict";
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/ })()
|
||||||
|
;
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1 +1 @@
|
||||||
.acf-field-setting-fc_layout .acf-fc-meta{margin:0 0 10px;padding:0}.acf-field-setting-fc_layout .acf-fc-meta li{margin:0 0 10px;padding:0}.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-field-setting-fc_layout .acf-fc-meta .acf-fc-meta-display .acf-input-prepend,.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{min-width:60px}.acf-field-setting-fc_layout .acf-fl-actions{visibility:hidden}.acf-field-setting-fc_layout .acf-fl-actions .reorder-layout{cursor:move}.acf-field-setting-fc_layout .acf-fl-actions a{padding:1px 0;font-size:13px;line-height:20px}.acf-field-setting-fc_layout.-hover .acf-fl-actions,.acf-field-setting-fc_layout:hover .acf-fl-actions{visibility:visible}.acf-field-object-clone[data-display=seamless] .acf-field-setting-conditional_logic,.acf-field-object-clone[data-display=seamless] .acf-field-setting-instructions,.acf-field-object-clone[data-display=seamless] .acf-field-setting-layout,.acf-field-object-clone[data-display=seamless] .acf-field-setting-wrapper{display:none}
|
.acf-field-setting-fc_layout .acf-fc-meta{margin:0 0 10px;padding:0}.acf-field-setting-fc_layout .acf-fc-meta li{margin:0 0 10px;padding:0}.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-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:60px}.acf-field-setting-fc_layout .acf-fl-actions{visibility:hidden}.acf-field-setting-fc_layout .acf-fl-actions .reorder-layout{cursor:move}.acf-field-setting-fc_layout .acf-fl-actions a{padding:1px 0;font-size:13px;line-height:20px}.acf-field-setting-fc_layout:hover .acf-fl-actions,.acf-field-setting-fc_layout.-hover .acf-fl-actions{visibility:visible}.acf-field-object-clone[data-display=seamless] .acf-field-setting-instructions,.acf-field-object-clone[data-display=seamless] .acf-field-setting-layout,.acf-field-object-clone[data-display=seamless] .acf-field-setting-wrapper,.acf-field-object-clone[data-display=seamless] .acf-field-setting-conditional_logic{display:none}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
/*!************************************************************************************************************************************************************************************************************************!*\
|
||||||
|
!*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].use[1]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[1].use[2]!./src/advanced-custom-fields-pro/assets/src/sass/pro/acf-pro-input.scss ***!
|
||||||
|
\************************************************************************************************************************************************************************************************************************/
|
||||||
/*--------------------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Vars
|
* Vars
|
||||||
|
|
@ -680,4 +683,6 @@ html[dir=rtl] .acf-block-component .acf-block-fields {
|
||||||
|
|
||||||
.components-panel__body .acf-block-panel {
|
.components-panel__body .acf-block-panel {
|
||||||
margin: 16px -16px -16px;
|
margin: 16px -16px -16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*# sourceMappingURL=acf-pro-input.css.map*/
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
/******/ (function() { // webpackBootstrap
|
||||||
|
/******/ "use strict";
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/ })()
|
||||||
|
;
|
||||||
File diff suppressed because one or more lines are too long
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
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
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
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
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
File diff suppressed because one or more lines are too long
|
|
@ -1,480 +1,516 @@
|
||||||
(function($){
|
/******/ (function() { // webpackBootstrap
|
||||||
|
/******/ var __webpack_modules__ = ({
|
||||||
/*
|
|
||||||
* Repeater
|
/***/ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-clone.js":
|
||||||
*
|
/*!********************************************************************************!*\
|
||||||
* This field type requires some extra logic for its settings
|
!*** ./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-clone.js ***!
|
||||||
*
|
\********************************************************************************/
|
||||||
* @type function
|
/***/ (function() {
|
||||||
* @date 24/10/13
|
|
||||||
* @since 5.0.0
|
(function ($) {
|
||||||
*
|
/**
|
||||||
* @param n/a
|
* CloneDisplayFieldSetting
|
||||||
* @return n/a
|
*
|
||||||
*/
|
* Extra logic for this field setting
|
||||||
|
*
|
||||||
var RepeaterCollapsedFieldSetting = acf.FieldSetting.extend({
|
* @date 18/4/18
|
||||||
type: 'repeater',
|
* @since 5.6.9
|
||||||
name: 'collapsed',
|
*
|
||||||
events: {
|
* @param void
|
||||||
'focus select': 'onFocus',
|
* @return void
|
||||||
},
|
*/
|
||||||
onFocus: function( e, $el ){
|
var CloneDisplayFieldSetting = acf.FieldSetting.extend({
|
||||||
|
type: 'clone',
|
||||||
// vars
|
name: 'display',
|
||||||
var $select = $el;
|
render: function () {
|
||||||
|
// vars
|
||||||
// collapsed
|
var display = this.field.val(); // set data attribute used by CSS to hide/show
|
||||||
var choices = [];
|
|
||||||
|
this.$fieldObject.attr('data-display', display);
|
||||||
// keep 'null' choice
|
}
|
||||||
choices.push({
|
});
|
||||||
label: $select.find('option[value=""]').text(),
|
acf.registerFieldSetting(CloneDisplayFieldSetting);
|
||||||
value: ''
|
/**
|
||||||
});
|
* ClonePrefixLabelFieldSetting
|
||||||
|
*
|
||||||
// find sub fields
|
* Extra logic for this field setting
|
||||||
var $list = this.fieldObject.$('.acf-field-list:first');
|
*
|
||||||
var fields = acf.getFieldObjects({
|
* @date 18/4/18
|
||||||
list: $list
|
* @since 5.6.9
|
||||||
});
|
*
|
||||||
|
* @param void
|
||||||
// loop
|
* @return void
|
||||||
fields.map(function( field ){
|
*/
|
||||||
choices.push({
|
|
||||||
label: field.prop('label'),
|
var ClonePrefixLabelFieldSetting = acf.FieldSetting.extend({
|
||||||
value: field.prop('key')
|
type: 'clone',
|
||||||
});
|
name: 'prefix_label',
|
||||||
});
|
render: function () {
|
||||||
|
// vars
|
||||||
// render
|
var prefix = ''; // if checked
|
||||||
acf.renderSelect( $select, choices );
|
|
||||||
}
|
if (this.field.val()) {
|
||||||
});
|
prefix = this.fieldObject.prop('label') + ' ';
|
||||||
|
} // update HTML
|
||||||
acf.registerFieldSetting( RepeaterCollapsedFieldSetting );
|
|
||||||
|
|
||||||
|
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: 'select2Args'
|
||||||
|
},
|
||||||
|
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 options;
|
||||||
|
},
|
||||||
|
ajaxData: function (data) {
|
||||||
|
// find current fields
|
||||||
|
data.fields = {}; // loop
|
||||||
|
|
||||||
|
acf.getFieldObjects().map(function (fieldObject) {
|
||||||
|
// append
|
||||||
|
data.fields[fieldObject.prop('key')] = {
|
||||||
|
key: fieldObject.prop('key'),
|
||||||
|
type: fieldObject.prop('type'),
|
||||||
|
label: fieldObject.prop('label'),
|
||||||
|
ancestors: fieldObject.getParents().length
|
||||||
|
};
|
||||||
|
}); // append title
|
||||||
|
|
||||||
|
data.title = $('#title').val(); // return
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
});
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
(function($){
|
|
||||||
|
/***/ }),
|
||||||
/**
|
|
||||||
* CloneDisplayFieldSetting
|
/***/ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-flexible-content.js":
|
||||||
*
|
/*!*******************************************************************************************!*\
|
||||||
* Extra logic for this field setting
|
!*** ./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-flexible-content.js ***!
|
||||||
*
|
\*******************************************************************************************/
|
||||||
* @date 18/4/18
|
/***/ (function() {
|
||||||
* @since 5.6.9
|
|
||||||
*
|
(function ($) {
|
||||||
* @param void
|
/**
|
||||||
* @return void
|
* CloneDisplayFieldSetting
|
||||||
*/
|
*
|
||||||
|
* Extra logic for this field setting
|
||||||
var FlexibleContentLayoutFieldSetting = acf.FieldSetting.extend({
|
*
|
||||||
type: 'flexible_content',
|
* @date 18/4/18
|
||||||
name: 'fc_layout',
|
* @since 5.6.9
|
||||||
|
*
|
||||||
events: {
|
* @param void
|
||||||
'blur .layout-label': 'onChangeLabel',
|
* @return void
|
||||||
'click .add-layout': 'onClickAdd',
|
*/
|
||||||
'click .duplicate-layout': 'onClickDuplicate',
|
var FlexibleContentLayoutFieldSetting = acf.FieldSetting.extend({
|
||||||
'click .delete-layout': 'onClickDelete'
|
type: 'flexible_content',
|
||||||
},
|
name: 'fc_layout',
|
||||||
|
events: {
|
||||||
$input: function( name ){
|
'blur .layout-label': 'onChangeLabel',
|
||||||
return $('#' + this.getInputId() + '-' + name);
|
'click .add-layout': 'onClickAdd',
|
||||||
},
|
'click .duplicate-layout': 'onClickDuplicate',
|
||||||
|
'click .delete-layout': 'onClickDelete'
|
||||||
$list: function(){
|
},
|
||||||
return this.$('.acf-field-list:first');
|
$input: function (name) {
|
||||||
},
|
return $('#' + this.getInputId() + '-' + name);
|
||||||
|
},
|
||||||
getInputId: function(){
|
$list: function () {
|
||||||
return this.fieldObject.getInputId() + '-layouts-' + this.field.get('id');
|
return this.$('.acf-field-list:first');
|
||||||
},
|
},
|
||||||
|
getInputId: function () {
|
||||||
// get all sub fields
|
return this.fieldObject.getInputId() + '-layouts-' + this.field.get('id');
|
||||||
getFields: function(){
|
},
|
||||||
return acf.getFieldObjects({ parent: this.$el });
|
// get all sub fields
|
||||||
},
|
getFields: function () {
|
||||||
|
return acf.getFieldObjects({
|
||||||
// get imediate children
|
parent: this.$el
|
||||||
getChildren: function(){
|
});
|
||||||
return acf.getFieldObjects({ list: this.$list() });
|
},
|
||||||
},
|
// get imediate children
|
||||||
|
getChildren: function () {
|
||||||
initialize: function(){
|
return acf.getFieldObjects({
|
||||||
|
list: this.$list()
|
||||||
// add sortable
|
});
|
||||||
var $tbody = this.$el.parent();
|
},
|
||||||
if( !$tbody.hasClass('ui-sortable') ) {
|
initialize: function () {
|
||||||
|
// add sortable
|
||||||
$tbody.sortable({
|
var $tbody = this.$el.parent();
|
||||||
items: '> .acf-field-setting-fc_layout',
|
|
||||||
handle: '.reorder-layout',
|
if (!$tbody.hasClass('ui-sortable')) {
|
||||||
forceHelperSize: true,
|
$tbody.sortable({
|
||||||
forcePlaceholderSize: true,
|
items: '> .acf-field-setting-fc_layout',
|
||||||
scroll: true,
|
handle: '.reorder-layout',
|
||||||
stop: this.proxy(function(event, ui) {
|
forceHelperSize: true,
|
||||||
this.fieldObject.save();
|
forcePlaceholderSize: true,
|
||||||
})
|
scroll: true,
|
||||||
});
|
stop: this.proxy(function (event, ui) {
|
||||||
}
|
this.fieldObject.save();
|
||||||
|
})
|
||||||
// add meta to sub fields
|
});
|
||||||
this.updateFieldLayouts();
|
} // add meta to sub fields
|
||||||
},
|
|
||||||
|
|
||||||
updateFieldLayouts: function(){
|
this.updateFieldLayouts();
|
||||||
this.getChildren().map(this.updateFieldLayout, this);
|
},
|
||||||
},
|
updateFieldLayouts: function () {
|
||||||
|
this.getChildren().map(this.updateFieldLayout, this);
|
||||||
updateFieldLayout: function( field ){
|
},
|
||||||
field.prop('parent_layout', this.get('id'));
|
updateFieldLayout: function (field) {
|
||||||
},
|
field.prop('parent_layout', this.get('id'));
|
||||||
|
},
|
||||||
onChangeLabel: function( e, $el ){
|
onChangeLabel: function (e, $el) {
|
||||||
|
// vars
|
||||||
// vars
|
var label = $el.val();
|
||||||
var label = $el.val();
|
var $name = this.$input('name'); // render name
|
||||||
var $name = this.$input('name');
|
|
||||||
|
if ($name.val() == '') {
|
||||||
// render name
|
acf.val($name, acf.strSanitize(label));
|
||||||
if( $name.val() == '' ) {
|
}
|
||||||
acf.val($name, acf.strSanitize(label));
|
},
|
||||||
}
|
onClickAdd: function (e, $el) {
|
||||||
},
|
// vars
|
||||||
|
var prevKey = this.get('id');
|
||||||
onClickAdd: function( e, $el ){
|
var newKey = acf.uniqid('layout_'); // duplicate
|
||||||
|
|
||||||
// vars
|
$layout = acf.duplicate({
|
||||||
var prevKey = this.get('id');
|
$el: this.$el,
|
||||||
var newKey = acf.uniqid('layout_');
|
search: prevKey,
|
||||||
|
replace: newKey,
|
||||||
// duplicate
|
after: function ($el, $el2) {
|
||||||
$layout = acf.duplicate({
|
// vars
|
||||||
$el: this.$el,
|
var $list = $el2.find('.acf-field-list:first'); // remove sub fields
|
||||||
search: prevKey,
|
|
||||||
replace: newKey,
|
$list.children('.acf-field-object').remove(); // show empty
|
||||||
after: function( $el, $el2 ){
|
|
||||||
|
$list.addClass('-empty'); // reset layout meta values
|
||||||
// vars
|
|
||||||
var $list = $el2.find('.acf-field-list:first');
|
$el2.find('.acf-fc-meta input').val('');
|
||||||
|
}
|
||||||
// remove sub fields
|
}); // get layout
|
||||||
$list.children('.acf-field-object').remove();
|
|
||||||
|
var layout = acf.getFieldSetting($layout); // update hidden input
|
||||||
// show empty
|
|
||||||
$list.addClass('-empty');
|
layout.$input('key').val(newKey); // save
|
||||||
|
|
||||||
// reset layout meta values
|
this.fieldObject.save();
|
||||||
$el2.find('.acf-fc-meta input').val('');
|
},
|
||||||
}
|
onClickDuplicate: function (e, $el) {
|
||||||
});
|
// vars
|
||||||
|
var prevKey = this.get('id');
|
||||||
// get layout
|
var newKey = acf.uniqid('layout_'); // duplicate
|
||||||
var layout = acf.getFieldSetting( $layout );
|
|
||||||
|
$layout = acf.duplicate({
|
||||||
// update hidden input
|
$el: this.$el,
|
||||||
layout.$input('key').val( newKey );
|
search: prevKey,
|
||||||
|
replace: newKey
|
||||||
// save
|
}); // get all fields in new layout similar to fieldManager.onDuplicateField().
|
||||||
this.fieldObject.save();
|
// important to run field.wipe() before making any changes to the "parent_layout" prop
|
||||||
},
|
// to ensure the correct input is modified.
|
||||||
|
|
||||||
onClickDuplicate: function( e, $el ){
|
var children = acf.getFieldObjects({
|
||||||
|
parent: $layout
|
||||||
// vars
|
});
|
||||||
var prevKey = this.get('id');
|
|
||||||
var newKey = acf.uniqid('layout_');
|
if (children.length) {
|
||||||
|
// loop
|
||||||
// duplicate
|
children.map(function (child) {
|
||||||
$layout = acf.duplicate({
|
// wipe field
|
||||||
$el: this.$el,
|
child.wipe(); // update parent
|
||||||
search: prevKey,
|
|
||||||
replace: newKey
|
child.updateParent();
|
||||||
});
|
}); // action
|
||||||
|
|
||||||
// get all fields in new layout similar to fieldManager.onDuplicateField().
|
acf.doAction('duplicate_field_objects', children, this.fieldObject, this.fieldObject);
|
||||||
// important to run field.wipe() before making any changes to the "parent_layout" prop
|
} // get layout
|
||||||
// to ensure the correct input is modified.
|
|
||||||
var children = acf.getFieldObjects({ parent: $layout });
|
|
||||||
if( children.length ) {
|
var layout = acf.getFieldSetting($layout); // update hidden input
|
||||||
|
|
||||||
// loop
|
layout.$input('key').val(newKey); // save
|
||||||
children.map(function( child ){
|
|
||||||
|
this.fieldObject.save();
|
||||||
// wipe field
|
},
|
||||||
child.wipe();
|
onClickDelete: function (e, $el) {
|
||||||
|
// Bypass confirmation when holding down "shift" key.
|
||||||
// update parent
|
if (e.shiftKey) {
|
||||||
child.updateParent();
|
return this.delete();
|
||||||
});
|
} // add class
|
||||||
|
|
||||||
// action
|
|
||||||
acf.doAction('duplicate_field_objects', children, this.fieldObject, this.fieldObject);
|
this.$el.addClass('-hover'); // add tooltip
|
||||||
}
|
|
||||||
|
var tooltip = acf.newTooltip({
|
||||||
// get layout
|
confirmRemove: true,
|
||||||
var layout = acf.getFieldSetting( $layout );
|
target: $el,
|
||||||
|
context: this,
|
||||||
// update hidden input
|
confirm: function () {
|
||||||
layout.$input('key').val( newKey );
|
this.delete();
|
||||||
|
},
|
||||||
// save
|
cancel: function () {
|
||||||
this.fieldObject.save();
|
this.$el.removeClass('-hover');
|
||||||
},
|
}
|
||||||
|
});
|
||||||
onClickDelete: function( e, $el ){
|
},
|
||||||
|
delete: function () {
|
||||||
// Bypass confirmation when holding down "shift" key.
|
// vars
|
||||||
if( e.shiftKey ) {
|
var $siblings = this.$el.siblings('.acf-field-setting-fc_layout'); // validate
|
||||||
return this.delete();
|
|
||||||
}
|
if (!$siblings.length) {
|
||||||
|
alert(acf.__('Flexible Content requires at least 1 layout'));
|
||||||
// add class
|
return false;
|
||||||
this.$el.addClass('-hover');
|
} // delete sub fields
|
||||||
|
|
||||||
// add tooltip
|
|
||||||
var tooltip = acf.newTooltip({
|
this.getFields().map(function (child) {
|
||||||
confirmRemove: true,
|
child.delete({
|
||||||
target: $el,
|
animate: false
|
||||||
context: this,
|
});
|
||||||
confirm: function(){
|
}); // remove tr
|
||||||
this.delete();
|
|
||||||
},
|
acf.remove(this.$el); // save
|
||||||
cancel: function(){
|
|
||||||
this.$el.removeClass('-hover');
|
this.fieldObject.save();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
acf.registerFieldSetting(FlexibleContentLayoutFieldSetting);
|
||||||
|
/**
|
||||||
delete: function(){
|
* flexibleContentHelper
|
||||||
|
*
|
||||||
// vars
|
* description
|
||||||
var $siblings = this.$el.siblings('.acf-field-setting-fc_layout');
|
*
|
||||||
|
* @date 19/4/18
|
||||||
// validate
|
* @since 5.6.9
|
||||||
if( !$siblings.length ) {
|
*
|
||||||
alert( acf.__('Flexible Content requires at least 1 layout') );
|
* @param type $var Description. Default.
|
||||||
return false;
|
* @return type Description.
|
||||||
}
|
*/
|
||||||
|
|
||||||
// delete sub fields
|
var flexibleContentHelper = new acf.Model({
|
||||||
this.getFields().map(function( child ){
|
actions: {
|
||||||
child.delete({
|
sortstop_field_object: 'updateParentLayout',
|
||||||
animate: false
|
change_field_object_parent: 'updateParentLayout'
|
||||||
});
|
},
|
||||||
});
|
updateParentLayout: function (fieldObject) {
|
||||||
|
// vars
|
||||||
// remove tr
|
var parent = fieldObject.getParent(); // delete meta
|
||||||
acf.remove( this.$el );
|
|
||||||
|
if (!parent || parent.prop('type') !== 'flexible_content') {
|
||||||
// save
|
fieldObject.prop('parent_layout', null);
|
||||||
this.fieldObject.save();
|
return;
|
||||||
}
|
} // get layout
|
||||||
|
|
||||||
});
|
|
||||||
|
var $layout = fieldObject.$el.closest('.acf-field-setting-fc_layout');
|
||||||
acf.registerFieldSetting( FlexibleContentLayoutFieldSetting );
|
var layout = acf.getFieldSetting($layout); // 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')) {
|
||||||
* flexibleContentHelper
|
fieldObject.prop('parent_layout', 0);
|
||||||
*
|
} // update meta
|
||||||
* description
|
|
||||||
*
|
|
||||||
* @date 19/4/18
|
fieldObject.prop('parent_layout', layout.get('id'));
|
||||||
* @since 5.6.9
|
}
|
||||||
*
|
});
|
||||||
* @param type $var Description. Default.
|
|
||||||
* @return type Description.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var flexibleContentHelper = new acf.Model({
|
|
||||||
actions: {
|
|
||||||
'sortstop_field_object': 'updateParentLayout',
|
|
||||||
'change_field_object_parent': 'updateParentLayout'
|
|
||||||
},
|
|
||||||
|
|
||||||
updateParentLayout: function( fieldObject ){
|
|
||||||
|
|
||||||
// vars
|
|
||||||
var parent = fieldObject.getParent();
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
// 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 meta
|
|
||||||
fieldObject.prop('parent_layout', layout.get('id'));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
(function($){
|
|
||||||
|
/***/ }),
|
||||||
/**
|
|
||||||
* CloneDisplayFieldSetting
|
/***/ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-repeater.js":
|
||||||
*
|
/*!***********************************************************************************!*\
|
||||||
* Extra logic for this field setting
|
!*** ./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-repeater.js ***!
|
||||||
*
|
\***********************************************************************************/
|
||||||
* @date 18/4/18
|
/***/ (function() {
|
||||||
* @since 5.6.9
|
|
||||||
*
|
(function ($) {
|
||||||
* @param void
|
/*
|
||||||
* @return void
|
* Repeater
|
||||||
*/
|
*
|
||||||
|
* This field type requires some extra logic for its settings
|
||||||
var CloneDisplayFieldSetting = acf.FieldSetting.extend({
|
*
|
||||||
type: 'clone',
|
* @type function
|
||||||
name: 'display',
|
* @date 24/10/13
|
||||||
render: function(){
|
* @since 5.0.0
|
||||||
|
*
|
||||||
// vars
|
* @param n/a
|
||||||
var display = this.field.val();
|
* @return n/a
|
||||||
|
*/
|
||||||
// set data attribute used by CSS to hide/show
|
var RepeaterCollapsedFieldSetting = acf.FieldSetting.extend({
|
||||||
this.$fieldObject.attr('data-display', display);
|
type: 'repeater',
|
||||||
}
|
name: 'collapsed',
|
||||||
});
|
events: {
|
||||||
|
'focus select': 'onFocus'
|
||||||
acf.registerFieldSetting( CloneDisplayFieldSetting );
|
},
|
||||||
|
onFocus: function (e, $el) {
|
||||||
|
// vars
|
||||||
/**
|
var $select = $el; // collapsed
|
||||||
* ClonePrefixLabelFieldSetting
|
|
||||||
*
|
var choices = []; // keep 'null' choice
|
||||||
* Extra logic for this field setting
|
|
||||||
*
|
choices.push({
|
||||||
* @date 18/4/18
|
label: $select.find('option[value=""]').text(),
|
||||||
* @since 5.6.9
|
value: ''
|
||||||
*
|
}); // find sub fields
|
||||||
* @param void
|
|
||||||
* @return void
|
var $list = this.fieldObject.$('.acf-field-list:first');
|
||||||
*/
|
var fields = acf.getFieldObjects({
|
||||||
|
list: $list
|
||||||
var ClonePrefixLabelFieldSetting = acf.FieldSetting.extend({
|
}); // loop
|
||||||
type: 'clone',
|
|
||||||
name: 'prefix_label',
|
fields.map(function (field) {
|
||||||
render: function(){
|
choices.push({
|
||||||
|
label: field.prop('label'),
|
||||||
// vars
|
value: field.prop('key')
|
||||||
var prefix = '';
|
});
|
||||||
|
}); // render
|
||||||
// if checked
|
|
||||||
if( this.field.val() ) {
|
acf.renderSelect($select, choices);
|
||||||
prefix = this.fieldObject.prop('label') + ' ';
|
}
|
||||||
}
|
});
|
||||||
|
acf.registerFieldSetting(RepeaterCollapsedFieldSetting);
|
||||||
// update HTML
|
})(jQuery);
|
||||||
this.$('code').html( prefix + '%field_label%' );
|
|
||||||
}
|
/***/ })
|
||||||
});
|
|
||||||
|
/******/ });
|
||||||
acf.registerFieldSetting( ClonePrefixLabelFieldSetting );
|
/************************************************************************/
|
||||||
|
/******/ // The module cache
|
||||||
|
/******/ var __webpack_module_cache__ = {};
|
||||||
/**
|
/******/
|
||||||
* ClonePrefixNameFieldSetting
|
/******/ // The require function
|
||||||
*
|
/******/ function __webpack_require__(moduleId) {
|
||||||
* Extra logic for this field setting
|
/******/ // Check if module is in cache
|
||||||
*
|
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
||||||
* @date 18/4/18
|
/******/ if (cachedModule !== undefined) {
|
||||||
* @since 5.6.9
|
/******/ return cachedModule.exports;
|
||||||
*
|
/******/ }
|
||||||
* @param void
|
/******/ // Create a new module (and put it into the cache)
|
||||||
* @return void
|
/******/ var module = __webpack_module_cache__[moduleId] = {
|
||||||
*/
|
/******/ // no module.id needed
|
||||||
|
/******/ // no module.loaded needed
|
||||||
var ClonePrefixNameFieldSetting = acf.FieldSetting.extend({
|
/******/ exports: {}
|
||||||
type: 'clone',
|
/******/ };
|
||||||
name: 'prefix_name',
|
/******/
|
||||||
render: function(){
|
/******/ // Execute the module function
|
||||||
|
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
||||||
// vars
|
/******/
|
||||||
var prefix = '';
|
/******/ // Return the exports of the module
|
||||||
|
/******/ return module.exports;
|
||||||
// if checked
|
/******/ }
|
||||||
if( this.field.val() ) {
|
/******/
|
||||||
prefix = this.fieldObject.prop('name') + '_';
|
/************************************************************************/
|
||||||
}
|
/******/ /* webpack/runtime/compat get default export */
|
||||||
|
/******/ !function() {
|
||||||
// update HTML
|
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||||
this.$('code').html( prefix + '%field_name%' );
|
/******/ __webpack_require__.n = function(module) {
|
||||||
}
|
/******/ var getter = module && module.__esModule ?
|
||||||
});
|
/******/ function() { return module['default']; } :
|
||||||
|
/******/ function() { return module; };
|
||||||
acf.registerFieldSetting( ClonePrefixNameFieldSetting );
|
/******/ __webpack_require__.d(getter, { a: getter });
|
||||||
|
/******/ return getter;
|
||||||
|
/******/ };
|
||||||
/**
|
/******/ }();
|
||||||
* cloneFieldSelectHelper
|
/******/
|
||||||
*
|
/******/ /* webpack/runtime/define property getters */
|
||||||
* Customizes the clone field setting Select2 isntance
|
/******/ !function() {
|
||||||
*
|
/******/ // define getter functions for harmony exports
|
||||||
* @date 18/4/18
|
/******/ __webpack_require__.d = function(exports, definition) {
|
||||||
* @since 5.6.9
|
/******/ for(var key in definition) {
|
||||||
*
|
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
||||||
* @param void
|
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
||||||
* @return void
|
/******/ }
|
||||||
*/
|
/******/ }
|
||||||
|
/******/ };
|
||||||
var cloneFieldSelectHelper = new acf.Model({
|
/******/ }();
|
||||||
filters: {
|
/******/
|
||||||
'select2_args': 'select2Args'
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
||||||
},
|
/******/ !function() {
|
||||||
|
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
|
||||||
select2Args: function( options, $select, data, $el, instance ){
|
/******/ }();
|
||||||
|
/******/
|
||||||
// check
|
/******/ /* webpack/runtime/make namespace object */
|
||||||
if( data.ajaxAction == 'acf/fields/clone/query' ) {
|
/******/ !function() {
|
||||||
|
/******/ // define __esModule on exports
|
||||||
// remain open on select
|
/******/ __webpack_require__.r = function(exports) {
|
||||||
options.closeOnSelect = false;
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
||||||
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||||
// customize ajaxData function
|
/******/ }
|
||||||
instance.data.ajaxData = this.ajaxData;
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
}
|
/******/ };
|
||||||
|
/******/ }();
|
||||||
// return
|
/******/
|
||||||
return options;
|
/************************************************************************/
|
||||||
},
|
var __webpack_exports__ = {};
|
||||||
|
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
|
||||||
ajaxData: function( data ){
|
!function() {
|
||||||
|
"use strict";
|
||||||
// find current fields
|
/*!*********************************************************************************!*\
|
||||||
data.fields = {};
|
!*** ./src/advanced-custom-fields-pro/assets/src/js/pro/acf-pro-field-group.js ***!
|
||||||
|
\*********************************************************************************/
|
||||||
// loop
|
__webpack_require__.r(__webpack_exports__);
|
||||||
acf.getFieldObjects().map(function(fieldObject){
|
/* harmony import */ var _acf_setting_repeater_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./_acf-setting-repeater.js */ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-repeater.js");
|
||||||
|
/* harmony import */ var _acf_setting_repeater_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_acf_setting_repeater_js__WEBPACK_IMPORTED_MODULE_0__);
|
||||||
// append
|
/* harmony import */ var _acf_setting_flexible_content_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./_acf-setting-flexible-content.js */ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-flexible-content.js");
|
||||||
data.fields[ fieldObject.prop('key') ] = {
|
/* harmony import */ var _acf_setting_flexible_content_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_acf_setting_flexible_content_js__WEBPACK_IMPORTED_MODULE_1__);
|
||||||
key: fieldObject.prop('key'),
|
/* harmony import */ var _acf_setting_clone_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./_acf-setting-clone.js */ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-clone.js");
|
||||||
type: fieldObject.prop('type'),
|
/* harmony import */ var _acf_setting_clone_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_acf_setting_clone_js__WEBPACK_IMPORTED_MODULE_2__);
|
||||||
label: fieldObject.prop('label'),
|
|
||||||
ancestors: fieldObject.getParents().length
|
|
||||||
};
|
|
||||||
});
|
}();
|
||||||
|
/******/ })()
|
||||||
// append title
|
;
|
||||||
data.title = $('#title').val();
|
//# sourceMappingURL=acf-pro-field-group.js.map
|
||||||
|
|
||||||
// return
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
})(jQuery);
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1 +1 @@
|
||||||
!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:""});t=this.fieldObject.$(".acf-field-list:first");acf.getFieldObjects({list:t}).map(function(e){a.push({label:e.prop("label"),value:e.prop("key")})}),acf.renderSelect(i,a)}});acf.registerFieldSetting(e)}(jQuery),function(t){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 t("#"+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(),t=this.$input("name");""==t.val()&&acf.val(t,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});i=acf.getFieldObjects({parent:$layout});i.length&&(i.map(function(e){e.wipe(),e.updateParent()}),acf.doAction("duplicate_field_objects",i,this.fieldObject,this.fieldObject)),acf.getFieldSetting($layout).$input("key").val(a),this.fieldObject.save()},onClickDelete:function(e,t){if(e.shiftKey)return this.delete();this.$el.addClass("-hover");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);new acf.Model({actions:{sortstop_field_object:"updateParentLayout",change_field_object_parent:"updateParentLayout"},updateParentLayout:function(e){var t=e.getParent();t&&"flexible_content"===t.prop("type")?(t=e.$el.closest(".acf-field-setting-fc_layout"),t=acf.getFieldSetting(t),e.has("parent_layout")||e.prop("parent_layout",0),e.prop("parent_layout",t.get("id"))):e.prop("parent_layout",null)}})}(jQuery),function(e){var t=acf.FieldSetting.extend({type:"clone",name:"display",render:function(){var e=this.field.val();this.$fieldObject.attr("data-display",e)}});acf.registerFieldSetting(t);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);t=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(t);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(t){return t.fields={},acf.getFieldObjects().map(function(e){t.fields[e.prop("key")]={key:e.prop("key"),type:e.prop("type"),label:e.prop("label"),ancestors:e.getParents().length}}),t.title=e("#title").val(),t}})}(jQuery);
|
!function(){var e={436:function(){!function(e){var t=acf.FieldSetting.extend({type:"clone",name:"display",render:function(){var e=this.field.val();this.$fieldObject.attr("data-display",e)}});acf.registerFieldSetting(t);var i=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(i);var a=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(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(t){return t.fields={},acf.getFieldObjects().map((function(e){t.fields[e.prop("key")]={key:e.prop("key"),type:e.prop("type"),label:e.prop("label"),ancestors:e.getParents().length}})),t.title=e("#title").val(),t}})}(jQuery)},309:function(){var e,t;e=jQuery,t=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(t){return e("#"+this.getInputId()+"-"+t)},$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){if(e.shiftKey)return this.delete();this.$el.addClass("-hover"),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(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")){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"))}else e.prop("parent_layout",null)}})},166:function(){var e;jQuery,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)}},t={};function i(a){var l=t[a];if(void 0!==l)return l.exports;var n=t[a]={exports:{}};return e[a](n,n.exports,i),n.exports}i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,{a:t}),t},i.d=function(e,t){for(var a in t)i.o(t,a)&&!i.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){"use strict";i(166),i(309),i(436)}()}();
|
||||||
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 one or more lines are too long
|
|
@ -9,14 +9,16 @@
|
||||||
* Licensed under the GPLv2 license or later.
|
* Licensed under the GPLv2 license or later.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
( function( $, undef ) {
|
( function ( $, undef ) {
|
||||||
|
|
||||||
var wpColorPickerAlpha = {
|
var wpColorPickerAlpha = {
|
||||||
'version' : 300
|
version: 300,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Always try to use the last version of this script.
|
// Always try to use the last version of this script.
|
||||||
if ( 'wpColorPickerAlpha' in window && 'version' in window.wpColorPickerAlpha ) {
|
if (
|
||||||
|
'wpColorPickerAlpha' in window &&
|
||||||
|
'version' in window.wpColorPickerAlpha
|
||||||
|
) {
|
||||||
var version = parseInt( window.wpColorPickerAlpha.version, 10 );
|
var version = parseInt( window.wpColorPickerAlpha.version, 10 );
|
||||||
if ( ! isNaN( version ) && version >= wpColorPickerAlpha.version ) {
|
if ( ! isNaN( version ) && version >= wpColorPickerAlpha.version ) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -29,8 +31,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new method to replace the `Color.toString()` inside the scripts.
|
// Create new method to replace the `Color.toString()` inside the scripts.
|
||||||
Color.fn.to_s = function( type ) {
|
Color.fn.to_s = function ( type ) {
|
||||||
type = ( type || 'hex' );
|
type = type || 'hex';
|
||||||
// Change hex to rgba to return the correct color.
|
// Change hex to rgba to return the correct color.
|
||||||
if ( 'hex' === type && this._alpha < 1 ) {
|
if ( 'hex' === type && this._alpha < 1 ) {
|
||||||
type = 'rgba';
|
type = 'rgba';
|
||||||
|
|
@ -40,16 +42,19 @@
|
||||||
if ( 'hex' === type ) {
|
if ( 'hex' === type ) {
|
||||||
color = this.toString();
|
color = this.toString();
|
||||||
} else if ( ! this.error ) {
|
} else if ( ! this.error ) {
|
||||||
color = this.toCSS( type ).replace( /\(\s+/, '(' ).replace( /\s+\)/, ')' );
|
color = this.toCSS( type )
|
||||||
|
.replace( /\(\s+/, '(' )
|
||||||
|
.replace( /\s+\)/, ')' );
|
||||||
}
|
}
|
||||||
return color;
|
return color;
|
||||||
}
|
};
|
||||||
|
|
||||||
// Register the global variable.
|
// Register the global variable.
|
||||||
window.wpColorPickerAlpha = wpColorPickerAlpha;
|
window.wpColorPickerAlpha = wpColorPickerAlpha;
|
||||||
|
|
||||||
// Background image encoded
|
// Background image encoded
|
||||||
var backgroundImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAAHnlligAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHJJREFUeNpi+P///4EDBxiAGMgCCCAGFB5AADGCRBgYDh48CCRZIJS9vT2QBAggFBkmBiSAogxFBiCAoHogAKIKAlBUYTELAiAmEtABEECk20G6BOmuIl0CIMBQ/IEMkO0myiSSraaaBhZcbkUOs0HuBwDplz5uFJ3Z4gAAAABJRU5ErkJggg==';
|
var backgroundImage =
|
||||||
|
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAAHnlligAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHJJREFUeNpi+P///4EDBxiAGMgCCCAGFB5AADGCRBgYDh48CCRZIJS9vT2QBAggFBkmBiSAogxFBiCAoHogAKIKAlBUYTELAiAmEtABEECk20G6BOmuIl0CIMBQ/IEMkO0myiSSraaaBhZcbkUOs0HuBwDplz5uFJ3Z4gAAAABJRU5ErkJggg==';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iris
|
* Iris
|
||||||
|
|
@ -75,7 +80,7 @@
|
||||||
*
|
*
|
||||||
* @return {string} The element's color.
|
* @return {string} The element's color.
|
||||||
*/
|
*/
|
||||||
_getColor: function( color ) {
|
_getColor: function ( color ) {
|
||||||
if ( color === undef ) {
|
if ( color === undef ) {
|
||||||
color = this._color;
|
color = this._color;
|
||||||
}
|
}
|
||||||
|
|
@ -97,11 +102,13 @@
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
_create: function() {
|
_create: function () {
|
||||||
try {
|
try {
|
||||||
// Try to get the wpColorPicker alpha options.
|
// Try to get the wpColorPicker alpha options.
|
||||||
this.alphaOptions = this.element.wpColorPicker( 'instance' ).alphaOptions;
|
this.alphaOptions = this.element.wpColorPicker(
|
||||||
} catch( e ) {}
|
'instance'
|
||||||
|
).alphaOptions;
|
||||||
|
} catch ( e ) {}
|
||||||
|
|
||||||
// We make sure there are all options
|
// We make sure there are all options
|
||||||
$.extend( {}, this.alphaOptions, {
|
$.extend( {}, this.alphaOptions, {
|
||||||
|
|
@ -122,10 +129,10 @@
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
_addInputListeners: function( input ) {
|
_addInputListeners: function ( input ) {
|
||||||
var self = this,
|
var self = this,
|
||||||
debounceTimeout = 100,
|
debounceTimeout = 100,
|
||||||
callback = function( event ){
|
callback = function ( event ) {
|
||||||
var val = input.val(),
|
var val = input.val(),
|
||||||
color = new Color( val ),
|
color = new Color( val ),
|
||||||
val = val.replace( /^(#|(rgb|hsl)a?)/, '' ),
|
val = val.replace( /^(#|(rgb|hsl)a?)/, '' ),
|
||||||
|
|
@ -135,10 +142,22 @@
|
||||||
|
|
||||||
if ( ! color.error ) {
|
if ( ! color.error ) {
|
||||||
// let's not do this on keyup for hex shortcodes
|
// let's not do this on keyup for hex shortcodes
|
||||||
if ( 'hex' !== type || ! ( event.type === 'keyup' && val.match( /^[0-9a-fA-F]{3}$/ ) ) ) {
|
if (
|
||||||
|
'hex' !== type ||
|
||||||
|
! (
|
||||||
|
event.type === 'keyup' &&
|
||||||
|
val.match( /^[0-9a-fA-F]{3}$/ )
|
||||||
|
)
|
||||||
|
) {
|
||||||
// Compare color ( #AARRGGBB )
|
// Compare color ( #AARRGGBB )
|
||||||
if ( color.toIEOctoHex() !== self._color.toIEOctoHex() ) {
|
if (
|
||||||
self._setOption( 'color', self._getColor( color ) );
|
color.toIEOctoHex() !==
|
||||||
|
self._color.toIEOctoHex()
|
||||||
|
) {
|
||||||
|
self._setOption(
|
||||||
|
'color',
|
||||||
|
self._getColor( color )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ( val !== '' ) {
|
} else if ( val !== '' ) {
|
||||||
|
|
@ -146,13 +165,15 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
input.on( 'change', callback ).on( 'keyup', self._debounce( callback, debounceTimeout ) );
|
input
|
||||||
|
.on( 'change', callback )
|
||||||
|
.on( 'keyup', self._debounce( callback, debounceTimeout ) );
|
||||||
|
|
||||||
// If we initialized hidden, show on first focus. The rest is up to you.
|
// If we initialized hidden, show on first focus. The rest is up to you.
|
||||||
if ( self.options.hide ) {
|
if ( self.options.hide ) {
|
||||||
input.one( 'focus', function() {
|
input.one( 'focus', function () {
|
||||||
self.show();
|
self.show();
|
||||||
});
|
} );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|
@ -163,17 +184,17 @@
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
_initControls: function() {
|
_initControls: function () {
|
||||||
this._super();
|
this._super();
|
||||||
|
|
||||||
if ( this.alphaOptions.alphaEnabled ) {
|
if ( this.alphaOptions.alphaEnabled ) {
|
||||||
// Create Alpha controls
|
// Create Alpha controls
|
||||||
var self = this,
|
var self = this,
|
||||||
stripAlpha = self.controls.strip.clone(false, false),
|
stripAlpha = self.controls.strip.clone( false, false ),
|
||||||
stripAlphaSlider = stripAlpha.find( '.iris-slider-offset' ),
|
stripAlphaSlider = stripAlpha.find( '.iris-slider-offset' ),
|
||||||
controls = {
|
controls = {
|
||||||
stripAlpha : stripAlpha,
|
stripAlpha: stripAlpha,
|
||||||
stripAlphaSlider : stripAlphaSlider
|
stripAlphaSlider: stripAlphaSlider,
|
||||||
};
|
};
|
||||||
|
|
||||||
stripAlpha.addClass( 'iris-strip-alpha' );
|
stripAlpha.addClass( 'iris-strip-alpha' );
|
||||||
|
|
@ -181,23 +202,23 @@
|
||||||
stripAlpha.appendTo( self.picker.find( '.iris-picker-inner' ) );
|
stripAlpha.appendTo( self.picker.find( '.iris-picker-inner' ) );
|
||||||
|
|
||||||
// Push new controls
|
// Push new controls
|
||||||
$.each( controls, function( k, v ) {
|
$.each( controls, function ( k, v ) {
|
||||||
self.controls[k] = v;
|
self.controls[ k ] = v;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Create slider
|
// Create slider
|
||||||
self.controls.stripAlphaSlider.slider( {
|
self.controls.stripAlphaSlider.slider( {
|
||||||
orientation : 'vertical',
|
orientation: 'vertical',
|
||||||
min : 0,
|
min: 0,
|
||||||
max : 100,
|
max: 100,
|
||||||
step : 1,
|
step: 1,
|
||||||
value : parseInt( self._color._alpha * 100 ),
|
value: parseInt( self._color._alpha * 100 ),
|
||||||
slide : function( event, ui ) {
|
slide: function ( event, ui ) {
|
||||||
self.active = 'strip';
|
self.active = 'strip';
|
||||||
// Update alpha value
|
// Update alpha value
|
||||||
self._color._alpha = parseFloat( ui.value / 100 );
|
self._color._alpha = parseFloat( ui.value / 100 );
|
||||||
self._change.apply( self, arguments );
|
self._change.apply( self, arguments );
|
||||||
}
|
},
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -211,7 +232,7 @@
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
_dimensions: function( reset ) {
|
_dimensions: function ( reset ) {
|
||||||
this._super( reset );
|
this._super( reset );
|
||||||
|
|
||||||
if ( this.alphaOptions.alphaEnabled ) {
|
if ( this.alphaOptions.alphaEnabled ) {
|
||||||
|
|
@ -220,7 +241,11 @@
|
||||||
controls = self.controls,
|
controls = self.controls,
|
||||||
square = controls.square,
|
square = controls.square,
|
||||||
strip = self.picker.find( '.iris-strip' ),
|
strip = self.picker.find( '.iris-strip' ),
|
||||||
innerWidth, squareWidth, stripWidth, stripMargin, totalWidth;
|
innerWidth,
|
||||||
|
squareWidth,
|
||||||
|
stripWidth,
|
||||||
|
stripMargin,
|
||||||
|
totalWidth;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* I use Math.round() to avoid possible size errors,
|
* I use Math.round() to avoid possible size errors,
|
||||||
|
|
@ -232,7 +257,9 @@
|
||||||
* 20 for css left and right property
|
* 20 for css left and right property
|
||||||
* 2 for css border
|
* 2 for css border
|
||||||
*/
|
*/
|
||||||
innerWidth = Math.round( self.picker.outerWidth( true ) - ( opts.border ? 22 : 0 ) );
|
innerWidth = Math.round(
|
||||||
|
self.picker.outerWidth( true ) - ( opts.border ? 22 : 0 )
|
||||||
|
);
|
||||||
// The width of the draggable, aka square.
|
// The width of the draggable, aka square.
|
||||||
squareWidth = Math.round( square.outerWidth() );
|
squareWidth = Math.round( square.outerWidth() );
|
||||||
// The width for the sliders
|
// The width for the sliders
|
||||||
|
|
@ -240,18 +267,23 @@
|
||||||
// The margin for the sliders
|
// The margin for the sliders
|
||||||
stripMargin = Math.round( stripWidth / 2 );
|
stripMargin = Math.round( stripWidth / 2 );
|
||||||
// The total width of the elements.
|
// The total width of the elements.
|
||||||
totalWidth = Math.round( squareWidth + ( stripWidth * 2 ) + ( stripMargin * 2 ) );
|
totalWidth = Math.round(
|
||||||
|
squareWidth + stripWidth * 2 + stripMargin * 2
|
||||||
|
);
|
||||||
|
|
||||||
// Check and change if necessary.
|
// Check and change if necessary.
|
||||||
while ( totalWidth > innerWidth ) {
|
while ( totalWidth > innerWidth ) {
|
||||||
stripWidth = Math.round( stripWidth - 2 );
|
stripWidth = Math.round( stripWidth - 2 );
|
||||||
stripMargin = Math.round( stripMargin - 1 );
|
stripMargin = Math.round( stripMargin - 1 );
|
||||||
totalWidth = Math.round( squareWidth + ( stripWidth * 2 ) + ( stripMargin * 2 ) );
|
totalWidth = Math.round(
|
||||||
|
squareWidth + stripWidth * 2 + stripMargin * 2
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
square.css( 'margin', '0' );
|
square.css( 'margin', '0' );
|
||||||
strip.width( stripWidth ).css( 'margin-left', stripMargin + 'px' );
|
strip
|
||||||
|
.width( stripWidth )
|
||||||
|
.css( 'margin-left', stripMargin + 'px' );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|
@ -262,42 +294,67 @@
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
_change: function() {
|
_change: function () {
|
||||||
var self = this,
|
var self = this,
|
||||||
active = self.active;
|
active = self.active;
|
||||||
|
|
||||||
self._super();
|
self._super();
|
||||||
|
|
||||||
if ( self.alphaOptions.alphaEnabled ) {
|
if ( self.alphaOptions.alphaEnabled ) {
|
||||||
var controls = self.controls,
|
var controls = self.controls,
|
||||||
alpha = parseInt( self._color._alpha * 100 ),
|
alpha = parseInt( self._color._alpha * 100 ),
|
||||||
color = self._color.toRgb(),
|
color = self._color.toRgb(),
|
||||||
gradient = [
|
gradient = [
|
||||||
'rgb(' + color.r + ',' + color.g + ',' + color.b + ') 0%',
|
'rgb(' +
|
||||||
'rgba(' + color.r + ',' + color.g + ',' + color.b + ', 0) 100%'
|
color.r +
|
||||||
|
',' +
|
||||||
|
color.g +
|
||||||
|
',' +
|
||||||
|
color.b +
|
||||||
|
') 0%',
|
||||||
|
'rgba(' +
|
||||||
|
color.r +
|
||||||
|
',' +
|
||||||
|
color.g +
|
||||||
|
',' +
|
||||||
|
color.b +
|
||||||
|
', 0) 100%',
|
||||||
],
|
],
|
||||||
target = self.picker.closest( '.wp-picker-container' ).find( '.wp-color-result' );
|
target = self.picker
|
||||||
|
.closest( '.wp-picker-container' )
|
||||||
|
.find( '.wp-color-result' );
|
||||||
|
|
||||||
self.options.color = self._getColor();
|
self.options.color = self._getColor();
|
||||||
// Generate background slider alpha, only for CSS3.
|
// Generate background slider alpha, only for CSS3.
|
||||||
controls.stripAlpha.css( { 'background' : 'linear-gradient(to bottom, ' + gradient.join( ', ' ) + '), url(' + backgroundImage + ')' } );
|
controls.stripAlpha.css( {
|
||||||
|
background:
|
||||||
|
'linear-gradient(to bottom, ' +
|
||||||
|
gradient.join( ', ' ) +
|
||||||
|
'), url(' +
|
||||||
|
backgroundImage +
|
||||||
|
')',
|
||||||
|
} );
|
||||||
// Update alpha value
|
// Update alpha value
|
||||||
if ( active ) {
|
if ( active ) {
|
||||||
controls.stripAlphaSlider.slider( 'value', alpha );
|
controls.stripAlphaSlider.slider( 'value', alpha );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! self._color.error ) {
|
if ( ! self._color.error ) {
|
||||||
self.element.removeClass( 'iris-error' ).val( self.options.color );
|
self.element
|
||||||
|
.removeClass( 'iris-error' )
|
||||||
|
.val( self.options.color );
|
||||||
}
|
}
|
||||||
|
|
||||||
self.picker.find( '.iris-palette-container' ).on( 'click.palette', '.iris-palette', function() {
|
self.picker
|
||||||
var color = $( this ).data( 'color' );
|
.find( '.iris-palette-container' )
|
||||||
if ( self.alphaOptions.alphaReset ) {
|
.on( 'click.palette', '.iris-palette', function () {
|
||||||
self._color._alpha = 1;
|
var color = $( this ).data( 'color' );
|
||||||
color = self._getColor();
|
if ( self.alphaOptions.alphaReset ) {
|
||||||
}
|
self._color._alpha = 1;
|
||||||
self._setOption( 'color', color );
|
color = self._getColor();
|
||||||
} );
|
}
|
||||||
|
self._setOption( 'color', color );
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|
@ -311,7 +368,7 @@
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
_paintDimension: function( origin, control ) {
|
_paintDimension: function ( origin, control ) {
|
||||||
var self = this,
|
var self = this,
|
||||||
color = false;
|
color = false;
|
||||||
|
|
||||||
|
|
@ -339,14 +396,17 @@
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
_setOption: function( key, value ) {
|
_setOption: function ( key, value ) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if ( 'color' === key && self.alphaOptions.alphaEnabled ) {
|
if ( 'color' === key && self.alphaOptions.alphaEnabled ) {
|
||||||
// cast to string in case we have a number
|
// cast to string in case we have a number
|
||||||
value = '' + value;
|
value = '' + value;
|
||||||
newColor = new Color( value ).setHSpace( self.options.mode );
|
newColor = new Color( value ).setHSpace( self.options.mode );
|
||||||
// Check if error && Check the color to prevent callbacks with the same color.
|
// Check if error && Check the color to prevent callbacks with the same color.
|
||||||
if ( ! newColor.error && self._getColor( newColor ) !== self._getColor() ) {
|
if (
|
||||||
|
! newColor.error &&
|
||||||
|
self._getColor( newColor ) !== self._getColor()
|
||||||
|
) {
|
||||||
self._color = newColor;
|
self._color = newColor;
|
||||||
self.options.color = self._getColor();
|
self.options.color = self._getColor();
|
||||||
self.active = 'external';
|
self.active = 'external';
|
||||||
|
|
@ -365,7 +425,7 @@
|
||||||
*
|
*
|
||||||
* @return {string} The element's color.
|
* @return {string} The element's color.
|
||||||
*/
|
*/
|
||||||
color: function( newColor ) {
|
color: function ( newColor ) {
|
||||||
if ( newColor === true ) {
|
if ( newColor === true ) {
|
||||||
return this._color.clone();
|
return this._color.clone();
|
||||||
}
|
}
|
||||||
|
|
@ -398,12 +458,12 @@
|
||||||
*
|
*
|
||||||
* @return {object} The current alpha options.
|
* @return {object} The current alpha options.
|
||||||
*/
|
*/
|
||||||
_getAlphaOptions: function() {
|
_getAlphaOptions: function () {
|
||||||
var el = this.element,
|
var el = this.element,
|
||||||
type = ( el.data( 'type' ) || this.options.type ),
|
type = el.data( 'type' ) || this.options.type,
|
||||||
color = ( el.data( 'defaultColor' ) || el.val() ),
|
color = el.data( 'defaultColor' ) || el.val(),
|
||||||
options = {
|
options = {
|
||||||
alphaEnabled: ( el.data( 'alphaEnabled' ) || false ),
|
alphaEnabled: el.data( 'alphaEnabled' ) || false,
|
||||||
alphaCustomWidth: 130,
|
alphaCustomWidth: 130,
|
||||||
alphaReset: false,
|
alphaReset: false,
|
||||||
alphaColorType: 'rgb',
|
alphaColorType: 'rgb',
|
||||||
|
|
@ -411,21 +471,21 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( options.alphaEnabled ) {
|
if ( options.alphaEnabled ) {
|
||||||
options.alphaEnabled = ( el.is( 'input' ) && 'full' === type );
|
options.alphaEnabled = el.is( 'input' ) && 'full' === type;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! options.alphaEnabled ) {
|
if ( ! options.alphaEnabled ) {
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
options.alphaColorWithSpace = ( color && color.match( /\s/ ) );
|
options.alphaColorWithSpace = color && color.match( /\s/ );
|
||||||
|
|
||||||
$.each( options, function( name, defaultValue ) {
|
$.each( options, function ( name, defaultValue ) {
|
||||||
var value = ( el.data( name ) || defaultValue );
|
var value = el.data( name ) || defaultValue;
|
||||||
switch ( name ) {
|
switch ( name ) {
|
||||||
case 'alphaCustomWidth':
|
case 'alphaCustomWidth':
|
||||||
value = ( value ? parseInt( value, 10 ) : 0 );
|
value = value ? parseInt( value, 10 ) : 0;
|
||||||
value = ( isNaN( value ) ? defaultValue : value );
|
value = isNaN( value ) ? defaultValue : value;
|
||||||
break;
|
break;
|
||||||
case 'alphaColorType':
|
case 'alphaColorType':
|
||||||
if ( ! value.match( /^(hex|(rgb|hsl)a?)$/ ) ) {
|
if ( ! value.match( /^(hex|(rgb|hsl)a?)$/ ) ) {
|
||||||
|
|
@ -439,10 +499,10 @@
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
value = !!value;
|
value = !! value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
options[name] = value;
|
options[ name ] = value;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
|
|
@ -455,7 +515,7 @@
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
_create: function() {
|
_create: function () {
|
||||||
// Return early if Iris support is missing.
|
// Return early if Iris support is missing.
|
||||||
if ( ! $.support.iris ) {
|
if ( ! $.support.iris ) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -475,7 +535,7 @@
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
_addListeners: function() {
|
_addListeners: function () {
|
||||||
if ( ! this.alphaOptions.alphaEnabled ) {
|
if ( ! this.alphaOptions.alphaEnabled ) {
|
||||||
return this._super();
|
return this._super();
|
||||||
}
|
}
|
||||||
|
|
@ -486,12 +546,18 @@
|
||||||
|
|
||||||
this.alphaOptions.defaultWidth = el.width();
|
this.alphaOptions.defaultWidth = el.width();
|
||||||
if ( this.alphaOptions.alphaCustomWidth ) {
|
if ( this.alphaOptions.alphaCustomWidth ) {
|
||||||
el.width( parseInt( this.alphaOptions.defaultWidth + this.alphaOptions.alphaCustomWidth, 10 ) );
|
el.width(
|
||||||
|
parseInt(
|
||||||
|
this.alphaOptions.defaultWidth +
|
||||||
|
this.alphaOptions.alphaCustomWidth,
|
||||||
|
10
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.toggler.css( {
|
self.toggler.css( {
|
||||||
'position': 'relative',
|
position: 'relative',
|
||||||
'background-image' : 'url(' + backgroundImage + ')'
|
'background-image': 'url(' + backgroundImage + ')',
|
||||||
} );
|
} );
|
||||||
|
|
||||||
if ( isDeprecated ) {
|
if ( isDeprecated ) {
|
||||||
|
|
@ -501,29 +567,28 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
self.colorAlpha = self.toggler.find( 'span.color-alpha' ).css( {
|
self.colorAlpha = self.toggler.find( 'span.color-alpha' ).css( {
|
||||||
'width' : '30px',
|
width: '30px',
|
||||||
'height' : '100%',
|
height: '100%',
|
||||||
'position' : 'absolute',
|
position: 'absolute',
|
||||||
'top' : 0,
|
top: 0,
|
||||||
'background-color' : el.val(),
|
'background-color': el.val(),
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Define the correct position for ltr or rtl direction.
|
// Define the correct position for ltr or rtl direction.
|
||||||
if ( 'ltr' === self.colorAlpha.css( 'direction' ) ) {
|
if ( 'ltr' === self.colorAlpha.css( 'direction' ) ) {
|
||||||
self.colorAlpha.css( {
|
self.colorAlpha.css( {
|
||||||
'border-bottom-left-radius' : '2px',
|
'border-bottom-left-radius': '2px',
|
||||||
'border-top-left-radius' : '2px',
|
'border-top-left-radius': '2px',
|
||||||
'left' : 0
|
left: 0,
|
||||||
} );
|
} );
|
||||||
} else {
|
} else {
|
||||||
self.colorAlpha.css( {
|
self.colorAlpha.css( {
|
||||||
'border-bottom-right-radius' : '2px',
|
'border-bottom-right-radius': '2px',
|
||||||
'border-top-right-radius' : '2px',
|
'border-top-right-radius': '2px',
|
||||||
'right' : 0
|
right: 0,
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
el.iris( {
|
el.iris( {
|
||||||
/**
|
/**
|
||||||
* @summary Handles the onChange event if one has been defined in the options.
|
* @summary Handles the onChange event if one has been defined in the options.
|
||||||
|
|
@ -538,17 +603,20 @@
|
||||||
*
|
*
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
change: function( event, ui ) {
|
change: function ( event, ui ) {
|
||||||
self.colorAlpha.css( { 'background-color': ui.color.to_s( self.alphaOptions.alphaColorType ) } );
|
self.colorAlpha.css( {
|
||||||
|
'background-color': ui.color.to_s(
|
||||||
|
self.alphaOptions.alphaColorType
|
||||||
|
),
|
||||||
|
} );
|
||||||
|
|
||||||
// fire change callback if we have one
|
// fire change callback if we have one
|
||||||
if ( $.isFunction( self.options.change ) ) {
|
if ( $.isFunction( self.options.change ) ) {
|
||||||
self.options.change.call( this, event, ui );
|
self.options.change.call( this, event, ui );
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prevent any clicks inside this widget from leaking to the top and closing it.
|
* Prevent any clicks inside this widget from leaking to the top and closing it.
|
||||||
*
|
*
|
||||||
|
|
@ -558,22 +626,22 @@
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
self.wrap.on( 'click.wpcolorpicker', function( event ) {
|
self.wrap.on( 'click.wpcolorpicker', function ( event ) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
});
|
} );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open or close the color picker depending on the class.
|
* Open or close the color picker depending on the class.
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
self.toggler.click( function() {
|
self.toggler.click( function () {
|
||||||
if ( self.toggler.hasClass( 'wp-picker-open' ) ) {
|
if ( self.toggler.hasClass( 'wp-picker-open' ) ) {
|
||||||
self.close();
|
self.close();
|
||||||
} else {
|
} else {
|
||||||
self.open();
|
self.open();
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if value is empty when changing the color in the color picker.
|
* Checks if value is empty when changing the color in the color picker.
|
||||||
|
|
@ -585,10 +653,14 @@
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
el.change( function( event ) {
|
el.change( function ( event ) {
|
||||||
var val = $( this ).val();
|
var val = $( this ).val();
|
||||||
|
|
||||||
if ( el.hasClass( 'iris-error' ) || val === '' || val.match( /^(#|(rgb|hsl)a?)$/ ) ) {
|
if (
|
||||||
|
el.hasClass( 'iris-error' ) ||
|
||||||
|
val === '' ||
|
||||||
|
val.match( /^(#|(rgb|hsl)a?)$/ )
|
||||||
|
) {
|
||||||
if ( isDeprecated ) {
|
if ( isDeprecated ) {
|
||||||
self.toggler.removeAttr( 'style' );
|
self.toggler.removeAttr( 'style' );
|
||||||
}
|
}
|
||||||
|
|
@ -611,7 +683,7 @@
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
self.button.click( function( event ) {
|
self.button.click( function ( event ) {
|
||||||
if ( $( this ).hasClass( 'wp-picker-default' ) ) {
|
if ( $( this ).hasClass( 'wp-picker-default' ) ) {
|
||||||
el.val( self.options.defaultColor ).change();
|
el.val( self.options.defaultColor ).change();
|
||||||
} else if ( $( this ).hasClass( 'wp-picker-clear' ) ) {
|
} else if ( $( this ).hasClass( 'wp-picker-clear' ) ) {
|
||||||
|
|
@ -632,4 +704,4 @@
|
||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
} );
|
} );
|
||||||
} ( jQuery ) );
|
} )( jQuery );
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
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 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
|
|
@ -533,7 +533,7 @@ function acf_prepare_field( $field ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use field prefix to modify input name.
|
// Use field prefix to modify input name.
|
||||||
if ( $field['prefix'] ) {
|
if ( ! empty( $field['prefix'] ) ) {
|
||||||
$field['name'] = "{$field['prefix']}[{$field['name']}]";
|
$field['name'] = "{$field['prefix']}[{$field['name']}]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -223,6 +223,7 @@ function acf_validate_field_group( $field_group = array() ) {
|
||||||
'hide_on_screen' => array(),
|
'hide_on_screen' => array(),
|
||||||
'active' => true,
|
'active' => true,
|
||||||
'description' => '',
|
'description' => '',
|
||||||
|
'show_in_rest' => false,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -316,6 +316,26 @@ function acf_maybe_idval( $value ) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert any numeric strings into their equivalent numeric type. This function will
|
||||||
|
* work with both single values and arrays.
|
||||||
|
*
|
||||||
|
* @param mixed $value Either a single value or an array of values.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function acf_format_numerics( $value ) {
|
||||||
|
if ( is_array( $value ) ) {
|
||||||
|
return array_map(
|
||||||
|
function ( $v ) {
|
||||||
|
return is_numeric( $v ) ? $v + 0 : $v;
|
||||||
|
},
|
||||||
|
$value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return is_numeric( $value ) ? $value + 0 : $value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* acf_numval
|
* acf_numval
|
||||||
*
|
*
|
||||||
|
|
@ -347,8 +367,6 @@ function acf_idify( $str = '' ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* acf_slugify
|
|
||||||
*
|
|
||||||
* Returns a slug friendly string.
|
* Returns a slug friendly string.
|
||||||
*
|
*
|
||||||
* @date 24/12/17
|
* @date 24/12/17
|
||||||
|
|
@ -359,7 +377,20 @@ function acf_idify( $str = '' ) {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function acf_slugify( $str = '', $glue = '-' ) {
|
function acf_slugify( $str = '', $glue = '-' ) {
|
||||||
return str_replace( array( '_', '-', '/', ' ' ), $glue, strtolower( $str ) );
|
$raw = $str;
|
||||||
|
$slug = str_replace( array( '_', '-', '/', ' ' ), $glue, strtolower( remove_accents( $raw ) ) );
|
||||||
|
$slug = preg_replace( "/[^A-Za-z0-9" . preg_quote( $glue ) . "]/", '', $slug );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the slug created by acf_slugify().
|
||||||
|
*
|
||||||
|
* @since 5.11.4
|
||||||
|
*
|
||||||
|
* @param string $slug The newly created slug.
|
||||||
|
* @param string $raw The original string.
|
||||||
|
* @param string $glue The separator used to join the string into a slug.
|
||||||
|
*/
|
||||||
|
return apply_filters( 'acf/slugify', $slug, $raw, $glue );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ function acf_add_action_variations( $action = '', $variations = array(), $index
|
||||||
/**
|
/**
|
||||||
* _acf_apply_hook_variations
|
* _acf_apply_hook_variations
|
||||||
*
|
*
|
||||||
* Applys hook variations during apply_filters() or do_action().
|
* Applies hook variations during apply_filters() or do_action().
|
||||||
*
|
*
|
||||||
* @date 25/1/19
|
* @date 25/1/19
|
||||||
* @since 5.7.11
|
* @since 5.7.11
|
||||||
|
|
@ -84,7 +84,9 @@ function _acf_apply_hook_variations() {
|
||||||
|
|
||||||
// Get variation information.
|
// Get variation information.
|
||||||
$variations = acf_get_store( 'hook-variations' )->get( $filter );
|
$variations = acf_get_store( 'hook-variations' )->get( $filter );
|
||||||
extract( $variations );
|
$index = $variations['index'];
|
||||||
|
$type = $variations['type'];
|
||||||
|
$variations = $variations['variations'];
|
||||||
|
|
||||||
// Find field in args using index.
|
// Find field in args using index.
|
||||||
$field = $args[ $index ];
|
$field = $args[ $index ];
|
||||||
|
|
@ -145,7 +147,7 @@ function acf_add_deprecated_filter( $deprecated, $version, $replacement ) {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add generic handler.
|
// Add generic handler.
|
||||||
// Use a priotiry of 10, and accepted args of 10 (ignored by WP).
|
// Use a priority of 10, and accepted args of 10 (ignored by WP).
|
||||||
add_filter( $replacement, '_acf_apply_deprecated_hook', 10, 10 );
|
add_filter( $replacement, '_acf_apply_deprecated_hook', 10, 10 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,14 +177,12 @@ function acf_add_deprecated_action( $deprecated, $version, $replacement ) {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add generic handler.
|
// Add generic handler.
|
||||||
// Use a priotiry of 10, and accepted args of 10 (ignored by WP).
|
// Use a priority of 10, and accepted args of 10 (ignored by WP).
|
||||||
add_filter( $replacement, '_acf_apply_deprecated_hook', 10, 10 );
|
add_filter( $replacement, '_acf_apply_deprecated_hook', 10, 10 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _acf_apply_deprecated_hook
|
* Applies a deprecated filter during apply_filters() or do_action().
|
||||||
*
|
|
||||||
* Applys a deprecated filter during apply_filters() or do_action().
|
|
||||||
*
|
*
|
||||||
* @date 25/1/19
|
* @date 25/1/19
|
||||||
* @since 5.7.11
|
* @since 5.7.11
|
||||||
|
|
@ -191,35 +191,28 @@ function acf_add_deprecated_action( $deprecated, $version, $replacement ) {
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function _acf_apply_deprecated_hook() {
|
function _acf_apply_deprecated_hook() {
|
||||||
|
|
||||||
// Get current hook.
|
// Get current hook.
|
||||||
$hook = current_filter();
|
$current_hook = current_filter();
|
||||||
|
|
||||||
// Get args provided.
|
// Get args provided.
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
||||||
// Get deprecated items for this hook.
|
// Get deprecated items for this hook.
|
||||||
$items = acf_get_store( 'deprecated-hooks' )->query( array( 'replacement' => $hook ) );
|
$deprecated_hooks = acf_get_store( 'deprecated-hooks' )->query( array( 'replacement' => $current_hook ) );
|
||||||
|
|
||||||
// Loop over results.
|
// Loop over results.
|
||||||
foreach ( $items as $item ) {
|
foreach ( $deprecated_hooks as $hook ) {
|
||||||
|
|
||||||
// Extract data.
|
|
||||||
extract( $item );
|
|
||||||
|
|
||||||
// Check if anyone is hooked into this deprecated hook.
|
// Check if anyone is hooked into this deprecated hook.
|
||||||
if ( has_filter( $deprecated ) ) {
|
if ( isset( $hook['deprecated'] ) && has_filter( $hook['deprecated'] ) ) {
|
||||||
|
|
||||||
// Log warning.
|
// Log warning.
|
||||||
// _deprecated_hook( $deprecated, $version, $hook );
|
// _deprecated_hook( $deprecated, $version, $hook );
|
||||||
|
|
||||||
// Apply filters.
|
// Apply the item/do the action.
|
||||||
if ( $type === 'filter' ) {
|
if ( $hook['type'] === 'filter' ) {
|
||||||
$args[0] = apply_filters_ref_array( $deprecated, $args );
|
$args[0] = apply_filters_ref_array( $hook['deprecated'], $args );
|
||||||
|
|
||||||
// Or do action.
|
|
||||||
} else {
|
} else {
|
||||||
do_action_ref_array( $deprecated, $args );
|
do_action_ref_array( $hook['deprecated'], $args );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* acf_get_meta
|
|
||||||
*
|
|
||||||
* Returns an array of "ACF only" meta for the given post_id.
|
* Returns an array of "ACF only" meta for the given post_id.
|
||||||
*
|
*
|
||||||
* @date 9/10/18
|
* @date 9/10/18
|
||||||
* @since 5.8.0
|
* @since 5.8.0
|
||||||
*
|
*
|
||||||
* @param mixed $post_id The post_id for this data.
|
* @param mixed $post_id The post_id for this data.
|
||||||
* @return array
|
*
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
function acf_get_meta( $post_id = 0 ) {
|
function acf_get_meta( $post_id = 0 ) {
|
||||||
|
|
||||||
|
|
@ -20,15 +19,18 @@ function acf_get_meta( $post_id = 0 ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode $post_id for $type and $id.
|
// Decode $post_id for $type and $id.
|
||||||
extract( acf_decode_post_id( $post_id ) );
|
$decoded = acf_decode_post_id( $post_id );
|
||||||
|
|
||||||
// Determine CRUD function.
|
/**
|
||||||
// - Relies on decoded post_id result to identify option or meta types.
|
* Determine CRUD function.
|
||||||
// - Uses xxx_metadata(type) instead of xxx_type_meta() to bypass additional logic that could alter the ID.
|
*
|
||||||
if ( $type === 'option' ) {
|
* - Relies on decoded post_id result to identify option or meta types.
|
||||||
$allmeta = acf_get_option_meta( $id );
|
* - Uses xxx_metadata(type) instead of xxx_type_meta() to bypass additional logic that could alter the ID.
|
||||||
|
*/
|
||||||
|
if ( $decoded['type'] === 'option' ) {
|
||||||
|
$allmeta = acf_get_option_meta( $decoded['id'] );
|
||||||
} else {
|
} else {
|
||||||
$allmeta = get_metadata( $type, $id, '' );
|
$allmeta = get_metadata( $decoded['type'], $decoded['id'], '' );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop over meta and check that a reference exists for each value.
|
// Loop over meta and check that a reference exists for each value.
|
||||||
|
|
@ -53,8 +55,8 @@ function acf_get_meta( $post_id = 0 ) {
|
||||||
* @date 25/1/19
|
* @date 25/1/19
|
||||||
* @since 5.7.11
|
* @since 5.7.11
|
||||||
*
|
*
|
||||||
* @param array $meta The arary of loaded meta.
|
* @param array $meta The array of loaded meta.
|
||||||
* @param string $post_id The $post_id for this meta.
|
* @param string $post_id The $post_id for this meta.
|
||||||
*/
|
*/
|
||||||
return apply_filters( 'acf/load_meta', $meta, $post_id );
|
return apply_filters( 'acf/load_meta', $meta, $post_id );
|
||||||
}
|
}
|
||||||
|
|
@ -109,20 +111,18 @@ function acf_get_option_meta( $prefix = '' ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* acf_get_metadata
|
|
||||||
*
|
|
||||||
* Retrieves specific metadata from the database.
|
* Retrieves specific metadata from the database.
|
||||||
*
|
*
|
||||||
* @date 16/10/2015
|
* @date 16/10/2015
|
||||||
* @since 5.2.3
|
* @since 5.2.3
|
||||||
*
|
*
|
||||||
* @param (int|string) $post_id The post id.
|
* @param int|string $post_id The post id.
|
||||||
* @param string $name The meta name.
|
* @param string $name The meta name.
|
||||||
* @param bool $hidden If the meta is hidden (starts with an underscore).
|
* @param bool $hidden If the meta is hidden (starts with an underscore).
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function acf_get_metadata( $post_id = 0, $name = '', $hidden = false ) {
|
function acf_get_metadata( $post_id = 0, $name = '', $hidden = false ) {
|
||||||
|
|
||||||
// Allow filter to short-circuit logic.
|
// Allow filter to short-circuit logic.
|
||||||
$null = apply_filters( 'acf/pre_load_metadata', null, $post_id, $name, $hidden );
|
$null = apply_filters( 'acf/pre_load_metadata', null, $post_id, $name, $hidden );
|
||||||
if ( $null !== null ) {
|
if ( $null !== null ) {
|
||||||
|
|
@ -130,7 +130,9 @@ function acf_get_metadata( $post_id = 0, $name = '', $hidden = false ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode $post_id for $type and $id.
|
// Decode $post_id for $type and $id.
|
||||||
extract( acf_decode_post_id( $post_id ) );
|
$decoded = acf_decode_post_id( $post_id );
|
||||||
|
$id = $decoded['id'];
|
||||||
|
$type = $decoded['type'];
|
||||||
|
|
||||||
// Hidden meta uses an underscore prefix.
|
// Hidden meta uses an underscore prefix.
|
||||||
$prefix = $hidden ? '_' : '';
|
$prefix = $hidden ? '_' : '';
|
||||||
|
|
@ -152,21 +154,19 @@ function acf_get_metadata( $post_id = 0, $name = '', $hidden = false ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* acf_update_metadata
|
|
||||||
*
|
|
||||||
* Updates metadata in the database.
|
* Updates metadata in the database.
|
||||||
*
|
*
|
||||||
* @date 16/10/2015
|
* @date 16/10/2015
|
||||||
* @since 5.2.3
|
* @since 5.2.3
|
||||||
*
|
*
|
||||||
* @param (int|string) $post_id The post id.
|
* @param int|string $post_id The post id.
|
||||||
* @param string $name The meta name.
|
* @param string $name The meta name.
|
||||||
* @param mixed $value The meta value.
|
* @param mixed $value The meta value.
|
||||||
* @param bool $hidden If the meta is hidden (starts with an underscore).
|
* @param bool $hidden If the meta is hidden (starts with an underscore).
|
||||||
* @return (int|bool) Meta ID if the key didn't exist, true on successful update, false on failure.
|
*
|
||||||
|
* @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
|
||||||
*/
|
*/
|
||||||
function acf_update_metadata( $post_id = 0, $name = '', $value = '', $hidden = false ) {
|
function acf_update_metadata( $post_id = 0, $name = '', $value = '', $hidden = false ) {
|
||||||
|
|
||||||
// Allow filter to short-circuit logic.
|
// Allow filter to short-circuit logic.
|
||||||
$pre = apply_filters( 'acf/pre_update_metadata', null, $post_id, $name, $value, $hidden );
|
$pre = apply_filters( 'acf/pre_update_metadata', null, $post_id, $name, $value, $hidden );
|
||||||
if ( $pre !== null ) {
|
if ( $pre !== null ) {
|
||||||
|
|
@ -174,7 +174,9 @@ function acf_update_metadata( $post_id = 0, $name = '', $value = '', $hidden = f
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode $post_id for $type and $id.
|
// Decode $post_id for $type and $id.
|
||||||
extract( acf_decode_post_id( $post_id ) );
|
$decoded = acf_decode_post_id( $post_id );
|
||||||
|
$id = $decoded['id'];
|
||||||
|
$type = $decoded['type'];
|
||||||
|
|
||||||
// Hidden meta uses an underscore prefix.
|
// Hidden meta uses an underscore prefix.
|
||||||
$prefix = $hidden ? '_' : '';
|
$prefix = $hidden ? '_' : '';
|
||||||
|
|
@ -197,20 +199,18 @@ function acf_update_metadata( $post_id = 0, $name = '', $value = '', $hidden = f
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* acf_delete_metadata
|
|
||||||
*
|
|
||||||
* Deletes metadata from the database.
|
* Deletes metadata from the database.
|
||||||
*
|
*
|
||||||
* @date 16/10/2015
|
* @date 16/10/2015
|
||||||
* @since 5.2.3
|
* @since 5.2.3
|
||||||
*
|
*
|
||||||
* @param (int|string) $post_id The post id.
|
* @param int|string $post_id The post id.
|
||||||
* @param string $name The meta name.
|
* @param string $name The meta name.
|
||||||
* @param bool $hidden If the meta is hidden (starts with an underscore).
|
* @param bool $hidden If the meta is hidden (starts with an underscore).
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function acf_delete_metadata( $post_id = 0, $name = '', $hidden = false ) {
|
function acf_delete_metadata( $post_id = 0, $name = '', $hidden = false ) {
|
||||||
|
|
||||||
// Allow filter to short-circuit logic.
|
// Allow filter to short-circuit logic.
|
||||||
$pre = apply_filters( 'acf/pre_delete_metadata', null, $post_id, $name, $hidden );
|
$pre = apply_filters( 'acf/pre_delete_metadata', null, $post_id, $name, $hidden );
|
||||||
if ( $pre !== null ) {
|
if ( $pre !== null ) {
|
||||||
|
|
@ -218,7 +218,9 @@ function acf_delete_metadata( $post_id = 0, $name = '', $hidden = false ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode $post_id for $type and $id.
|
// Decode $post_id for $type and $id.
|
||||||
extract( acf_decode_post_id( $post_id ) );
|
$decoded = acf_decode_post_id( $post_id );
|
||||||
|
$id = $decoded['id'];
|
||||||
|
$type = $decoded['type'];
|
||||||
|
|
||||||
// Hidden meta uses an underscore prefix.
|
// Hidden meta uses an underscore prefix.
|
||||||
$prefix = $hidden ? '_' : '';
|
$prefix = $hidden ? '_' : '';
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,18 @@ function acf_get_value( $post_id, $field ) {
|
||||||
// Get field name.
|
// Get field name.
|
||||||
$field_name = $field['name'];
|
$field_name = $field['name'];
|
||||||
|
|
||||||
|
// If we still don't have a proper field array, the field doesn't exist currently.
|
||||||
|
if ( empty( $field['type'] ) && empty( $field['key'] ) ) {
|
||||||
|
// Get field ID & type.
|
||||||
|
$decoded = acf_decode_post_id( $post_id );
|
||||||
|
|
||||||
|
if ( apply_filters( 'acf/prevent_access_to_unknown_fields', false ) || ( 'option' === $decoded['type'] && 'options' !== $decoded['id'] ) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
do_action( 'acf/get_invalid_field_value', $field, __FUNCTION__ );
|
||||||
|
}
|
||||||
|
|
||||||
// Check store.
|
// Check store.
|
||||||
$store = acf_get_store( 'values' );
|
$store = acf_get_store( 'values' );
|
||||||
if ( $store->has( "$post_id:$field_name" ) ) {
|
if ( $store->has( "$post_id:$field_name" ) ) {
|
||||||
|
|
@ -322,3 +334,26 @@ function acf_preview_value( $value, $post_id, $field ) {
|
||||||
|
|
||||||
// Register variation.
|
// Register variation.
|
||||||
acf_add_filter_variations( 'acf/preview_value', array( 'type', 'name', 'key' ), 2 );
|
acf_add_filter_variations( 'acf/preview_value', array( 'type', 'name', 'key' ), 2 );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Potentially log an error if a field doesn't exist when we expect it to.
|
||||||
|
*
|
||||||
|
* @param array $field An array representing the field that a value was requested for.
|
||||||
|
* @param string $function The function that noticed the problem.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function acf_log_invalid_field_notice( $field, $function ) {
|
||||||
|
// If "init" has fired, ACF probably wasn't initialized early.
|
||||||
|
if ( did_action( 'init' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$error_text = sprintf(
|
||||||
|
__( '<strong>%1$s</strong> - We\'ve detected one or more calls to retrieve ACF field values before ACF has been initialized. This is not supported and can result in malformed or missing data. <a href="%2$s" target="_blank">Learn how to fix this</a>.', 'acf' ),
|
||||||
|
acf_get_setting( 'name' ),
|
||||||
|
'https://www.advancedcustomfields.com/resources/acf-field-functions/'
|
||||||
|
);
|
||||||
|
_doing_it_wrong( $function, $error_text, '5.11.1' );
|
||||||
|
}
|
||||||
|
add_action( 'acf/get_invalid_field_value', 'acf_log_invalid_field_notice', 10, 2 );
|
||||||
|
|
|
||||||
|
|
@ -178,6 +178,7 @@ function acf_decode_post_id( $post_id = 0 ) {
|
||||||
$id = absint( $id );
|
$id = absint( $id );
|
||||||
break;
|
break;
|
||||||
case 'block_%s':
|
case 'block_%s':
|
||||||
|
case 'block_%d':
|
||||||
$type = 'block';
|
$type = 'block';
|
||||||
$id = $post_id;
|
$id = $post_id;
|
||||||
break;
|
break;
|
||||||
|
|
@ -216,3 +217,46 @@ function acf_decode_post_id( $post_id = 0 ) {
|
||||||
*/
|
*/
|
||||||
return apply_filters( 'acf/decode_post_id', compact( 'type', 'id' ), $post_id );
|
return apply_filters( 'acf/decode_post_id', compact( 'type', 'id' ), $post_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the REST base for a post type or taxonomy object. Note that this is not intended for use
|
||||||
|
* with term or post objects but is, instead, to be used with the underlying WP_Post_Type and WP_Taxonomy
|
||||||
|
* instances.
|
||||||
|
*
|
||||||
|
* @param WP_Post_Type|WP_Taxonomy $type_object
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
function acf_get_object_type_rest_base( $type_object ) {
|
||||||
|
if ( $type_object instanceof WP_Post_Type || $type_object instanceof WP_Taxonomy ) {
|
||||||
|
return ! empty( $type_object->rest_base ) ? $type_object->rest_base : $type_object->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract the ID of a given object/array. This supports all expected types handled by our update_fields() and
|
||||||
|
* load_fields() callbacks.
|
||||||
|
*
|
||||||
|
* @param WP_Post|WP_User|WP_Term|array $object
|
||||||
|
* @return int|mixed|null
|
||||||
|
*/
|
||||||
|
function acf_get_object_id( $object ) {
|
||||||
|
if ( is_object( $object ) ) {
|
||||||
|
switch ( get_class( $object ) ) {
|
||||||
|
case WP_User::class:
|
||||||
|
case WP_Post::class:
|
||||||
|
return (int) $object->ID;
|
||||||
|
|
||||||
|
case WP_Term::class:
|
||||||
|
return (int) $object->term_id;
|
||||||
|
}
|
||||||
|
} elseif ( isset( $object['id'] ) ) {
|
||||||
|
return (int) $object['id'];
|
||||||
|
|
||||||
|
} elseif ( isset( $object['ID'] ) ) {
|
||||||
|
return (int) $object['ID'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,13 +128,15 @@ add_action( 'admin_notices', 'acf_render_admin_notices', 99 );
|
||||||
*
|
*
|
||||||
* @param string $text The admin notice text.
|
* @param string $text The admin notice text.
|
||||||
* @param string $class The type of notice (warning, error, success, info).
|
* @param string $class The type of notice (warning, error, success, info).
|
||||||
|
* @param string $dismissable Is this notification dismissible (default true) (since 5.11.0)
|
||||||
* @return ACF_Admin_Notice
|
* @return ACF_Admin_Notice
|
||||||
*/
|
*/
|
||||||
function acf_add_admin_notice( $text = '', $type = 'info' ) {
|
function acf_add_admin_notice( $text = '', $type = 'info', $dismissible = true ) {
|
||||||
return acf_new_admin_notice(
|
return acf_new_admin_notice(
|
||||||
array(
|
array(
|
||||||
'text' => $text,
|
'text' => $text,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
|
'dismissible' => $dismissible,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ if ( ! class_exists( 'ACF_Admin' ) ) :
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
|
||||||
// Add actions.
|
// Add actions.
|
||||||
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
||||||
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
||||||
|
|
@ -201,6 +200,7 @@ if ( ! class_exists( 'ACF_Admin' ) ) :
|
||||||
// Use RegExp to append "ACF" after the <a> element allowing translations to read correctly.
|
// Use RegExp to append "ACF" after the <a> element allowing translations to read correctly.
|
||||||
return preg_replace( '/(<a[\S\s]+?\/a>)/', '$1 ' . __( 'and', 'acf' ) . ' <a href="https://www.advancedcustomfields.com" target="_blank">ACF</a>', $text, 1 );
|
return preg_replace( '/(<a[\S\s]+?\/a>)/', '$1 ' . __( 'and', 'acf' ) . ' <a href="https://www.advancedcustomfields.com" target="_blank">ACF</a>', $text, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instantiate.
|
// Instantiate.
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,24 @@ acf_render_field_wrap(
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// Show fields in REST API.
|
||||||
|
if ( acf_get_setting( 'rest_api_enabled' ) ) {
|
||||||
|
acf_render_field_wrap(
|
||||||
|
array(
|
||||||
|
'label' => __( 'Show in REST API', 'acf' ),
|
||||||
|
'instructions' => '',
|
||||||
|
'type' => 'true_false',
|
||||||
|
'name' => 'show_in_rest',
|
||||||
|
'prefix' => 'acf_field_group',
|
||||||
|
'value' => $field_group['show_in_rest'],
|
||||||
|
'ui' => 1,
|
||||||
|
// 'ui_on_text' => __('Active', 'acf'),
|
||||||
|
// 'ui_off_text' => __('Inactive', 'acf'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// style
|
// style
|
||||||
acf_render_field_wrap(
|
acf_render_field_wrap(
|
||||||
array(
|
array(
|
||||||
|
|
|
||||||
|
|
@ -57,12 +57,19 @@ if ( ! class_exists( 'ACF_Ajax_Check_Screen' ) ) :
|
||||||
'key' => $field_group['key'],
|
'key' => $field_group['key'],
|
||||||
'title' => $field_group['title'],
|
'title' => $field_group['title'],
|
||||||
'position' => $field_group['position'],
|
'position' => $field_group['position'],
|
||||||
|
'classes' => postbox_classes( 'acf-' . $field_group['key'], $args['screen'] ),
|
||||||
'style' => $field_group['style'],
|
'style' => $field_group['style'],
|
||||||
'label' => $field_group['label_placement'],
|
'label' => $field_group['label_placement'],
|
||||||
'edit' => acf_get_field_group_edit_link( $field_group['ID'] ),
|
'edit' => acf_get_field_group_edit_link( $field_group['ID'] ),
|
||||||
'html' => '',
|
'html' => '',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$hidden_metaboxes = get_hidden_meta_boxes( $args['screen'] );
|
||||||
|
|
||||||
|
if ( is_array( $hidden_metaboxes ) && in_array( $item['id'], $hidden_metaboxes ) ) {
|
||||||
|
$item['classes'] = trim( $item['classes'] . ' hide-if-js' );
|
||||||
|
}
|
||||||
|
|
||||||
// append html if doesnt already exist on page
|
// append html if doesnt already exist on page
|
||||||
if ( ! in_array( $field_group['key'], $args['exists'] ) ) {
|
if ( ! in_array( $field_group['key'], $args['exists'] ) ) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -419,37 +419,29 @@ function acf_parse_type( $v ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* acf_get_view
|
* This function will load in a file from the 'admin/views' folder and allow variables to be passed through
|
||||||
*
|
*
|
||||||
* This function will load in a file from the 'admin/views' folder and allow variables to be passed through
|
* @date 28/09/13
|
||||||
*
|
* @since 5.0.0
|
||||||
* @type function
|
*
|
||||||
* @date 28/09/13
|
* @param string $view_path
|
||||||
* @since 5.0.0
|
* @param array $view_args
|
||||||
*
|
*
|
||||||
* @param $view_name (string)
|
* @return void
|
||||||
* @param $args (array)
|
*/
|
||||||
* @return n/a
|
function acf_get_view( $view_path = '', $view_args = array() ) {
|
||||||
*/
|
|
||||||
|
|
||||||
function acf_get_view( $path = '', $args = array() ) {
|
|
||||||
|
|
||||||
// allow view file name shortcut
|
// allow view file name shortcut
|
||||||
if ( substr( $path, -4 ) !== '.php' ) {
|
if ( substr( $view_path, -4 ) !== '.php' ) {
|
||||||
|
$view_path = acf_get_path( "includes/admin/views/{$view_path}.php" );
|
||||||
$path = acf_get_path( "includes/admin/views/{$path}.php" );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// include
|
// include
|
||||||
if ( file_exists( $path ) ) {
|
if ( file_exists( $view_path ) ) {
|
||||||
|
// Use `EXTR_SKIP` here to prevent `$view_path` from being accidentally/maliciously overridden.
|
||||||
extract( $args );
|
extract( $view_args, EXTR_SKIP );
|
||||||
include $path;
|
include $view_path;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -4246,7 +4238,7 @@ function acf_remove_array_key_prefix( $array, $prefix ) {
|
||||||
* acf_strip_protocol
|
* acf_strip_protocol
|
||||||
*
|
*
|
||||||
* This function will remove the proticol from a url
|
* This function will remove the proticol from a url
|
||||||
* Used to allow licences to remain active if a site is switched to https
|
* Used to allow licenses to remain active if a site is switched to https
|
||||||
*
|
*
|
||||||
* @type function
|
* @type function
|
||||||
* @date 10/01/2017
|
* @date 10/01/2017
|
||||||
|
|
|
||||||
|
|
@ -86,59 +86,41 @@ function the_field( $selector, $post_id = false, $format_value = true ) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/*
|
* This function will return an array containing all the field data for a given field_name.
|
||||||
* get_field_object()
|
*
|
||||||
*
|
* @since 3.6
|
||||||
* This function will return an array containing all the field data for a given field_name
|
* @date 3/02/13
|
||||||
*
|
*
|
||||||
* @type function
|
* @param string $selector The field name or key.
|
||||||
* @since 3.6
|
* @param mixed $post_id The post_id of which the value is saved against.
|
||||||
* @date 3/02/13
|
* @param bool $format_value Whether to format the field value.
|
||||||
*
|
* @param bool $load_value Whether to load the field value.
|
||||||
* @param $selector (string) the field name or key
|
*
|
||||||
* @param $post_id (mixed) the post_id of which the value is saved against
|
* @return array $field
|
||||||
* @param $format_value (boolean) whether or not to format the field value
|
*/
|
||||||
* @param $load_value (boolean) whether or not to load the field value
|
|
||||||
* @return $field (array)
|
|
||||||
*/
|
|
||||||
|
|
||||||
function get_field_object( $selector, $post_id = false, $format_value = true, $load_value = true ) {
|
function get_field_object( $selector, $post_id = false, $format_value = true, $load_value = true ) {
|
||||||
|
// Compatibility with ACF ~4.
|
||||||
// compatibilty
|
if ( is_array( $format_value ) && isset( $format_value['format_value'] ) ) {
|
||||||
if ( is_array( $format_value ) ) {
|
$format_value = $format_value['format_value'];
|
||||||
extract( $format_value );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get valid post_id
|
|
||||||
$post_id = acf_get_valid_post_id( $post_id );
|
$post_id = acf_get_valid_post_id( $post_id );
|
||||||
|
$field = acf_maybe_get_field( $selector, $post_id );
|
||||||
|
|
||||||
// get field key
|
|
||||||
$field = acf_maybe_get_field( $selector, $post_id );
|
|
||||||
|
|
||||||
// bail early if no field found
|
|
||||||
if ( ! $field ) {
|
if ( ! $field ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// load value
|
|
||||||
if ( $load_value ) {
|
if ( $load_value ) {
|
||||||
|
|
||||||
$field['value'] = acf_get_value( $post_id, $field );
|
$field['value'] = acf_get_value( $post_id, $field );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// format value
|
|
||||||
if ( $format_value ) {
|
if ( $format_value ) {
|
||||||
|
|
||||||
// get value for field
|
|
||||||
$field['value'] = acf_format_value( $field['value'], $post_id, $field );
|
$field['value'] = acf_format_value( $field['value'], $post_id, $field );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return
|
|
||||||
return $field;
|
return $field;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -864,56 +846,55 @@ function get_row_layout() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/*
|
* This function is used to add basic shortcode support for the ACF plugin
|
||||||
* acf_shortcode()
|
* eg. [acf field="heading" post_id="123" format_value="1"]
|
||||||
*
|
*
|
||||||
* This function is used to add basic shortcode support for the ACF plugin
|
* @since 1.1.1
|
||||||
* eg. [acf field="heading" post_id="123" format_value="1"]
|
* @date 29/01/13
|
||||||
*
|
*
|
||||||
* @type function
|
* @param array $atts The shortcode attributes.
|
||||||
* @since 1.1.1
|
*
|
||||||
* @date 29/01/13
|
* @return string
|
||||||
*
|
*/
|
||||||
* @param $field (string) the field name or key
|
|
||||||
* @param $post_id (mixed) the post_id of which the value is saved against
|
|
||||||
* @param $format_value (boolean) whether or not to format the field value
|
|
||||||
* @return (string)
|
|
||||||
*/
|
|
||||||
|
|
||||||
function acf_shortcode( $atts ) {
|
function acf_shortcode( $atts ) {
|
||||||
// Mitigate issue where some AJAX requests can return ACF field data.
|
// Mitigate issue where some AJAX requests can return ACF field data.
|
||||||
if ( wp_doing_ajax() && ! current_user_can( 'edit_posts' ) ) {
|
$capability = apply_filters( 'acf/ajax/shortcode_capability', 'edit_posts' );
|
||||||
|
if ( wp_doing_ajax() && ( $capability !== false ) && ! current_user_can( $capability ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract attributs
|
$atts = shortcode_atts(
|
||||||
extract(
|
array(
|
||||||
shortcode_atts(
|
'field' => '',
|
||||||
array(
|
'post_id' => false,
|
||||||
'field' => '',
|
'format_value' => true,
|
||||||
'post_id' => false,
|
),
|
||||||
'format_value' => true,
|
$atts,
|
||||||
),
|
'acf'
|
||||||
$atts
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// get value and return it
|
$access_already_prevented = apply_filters( 'acf/prevent_access_to_unknown_fields', false );
|
||||||
$value = get_field( $field, $post_id, $format_value );
|
$filter_applied = false;
|
||||||
|
|
||||||
// array
|
|
||||||
if ( is_array( $value ) ) {
|
|
||||||
|
|
||||||
$value = @implode( ', ', $value );
|
|
||||||
|
|
||||||
|
if ( ! $access_already_prevented ) {
|
||||||
|
$filter_applied = true;
|
||||||
|
add_filter( 'acf/prevent_access_to_unknown_fields', '__return_true' );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to get the field value.
|
||||||
|
$value = get_field( $atts['field'], $atts['post_id'], $atts['format_value'] );
|
||||||
|
|
||||||
|
if ( $filter_applied ) {
|
||||||
|
remove_filter( 'acf/prevent_access_to_unknown_fields', '__return_true' );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( is_array( $value ) ) {
|
||||||
|
$value = @implode( ', ', $value );
|
||||||
}
|
}
|
||||||
|
|
||||||
// return
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add_shortcode( 'acf', 'acf_shortcode' );
|
add_shortcode( 'acf', 'acf_shortcode' );
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ if ( ! class_exists( 'acf_field__accordion' ) ) :
|
||||||
|
|
||||||
class acf_field__accordion extends acf_field {
|
class acf_field__accordion extends acf_field {
|
||||||
|
|
||||||
|
public $show_in_rest = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initialize
|
* initialize
|
||||||
|
|
|
||||||
|
|
@ -288,6 +288,40 @@ if ( ! class_exists( 'acf_field_button_group' ) ) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function get_rest_schema( array $field ) {
|
||||||
|
$schema = parent::get_rest_schema( $field );
|
||||||
|
|
||||||
|
if ( isset( $field['default_value'] ) && '' !== $field['default_value'] ) {
|
||||||
|
$schema['default'] = $field['default_value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a user has defined keys for the buttons,
|
||||||
|
* we should use the keys for the available options to POST to,
|
||||||
|
* since they are what is displayed in GET requests.
|
||||||
|
*/
|
||||||
|
$button_keys = array_diff(
|
||||||
|
array_keys( $field['choices'] ),
|
||||||
|
array_values( $field['choices'] )
|
||||||
|
);
|
||||||
|
|
||||||
|
$schema['enum'] = empty( $button_keys ) ? $field['choices'] : $button_keys;
|
||||||
|
$schema['enum'][] = null;
|
||||||
|
|
||||||
|
// Allow null via UI will value to empty string.
|
||||||
|
if ( ! empty( $field['allow_null'] ) ) {
|
||||||
|
$schema['enum'][] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -564,6 +564,45 @@ if ( ! class_exists( 'acf_field_checkbox' ) ) :
|
||||||
return acf_get_field_type( 'select' )->format_value( $value, $post_id, $field );
|
return acf_get_field_type( 'select' )->format_value( $value, $post_id, $field );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = array(
|
||||||
|
'type' => array( 'string', 'array', 'null' ),
|
||||||
|
'required' => isset( $field['required'] ) && $field['required'],
|
||||||
|
'items' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( isset( $field['default_value'] ) && '' !== $field['default_value'] ) {
|
||||||
|
$schema['default'] = $field['default_value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we allow custom values, nothing else to do here.
|
||||||
|
if ( ! empty( $field['allow_custom'] ) ) {
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a user has defined keys for the checkboxes,
|
||||||
|
* we should use the keys for the available options to POST to,
|
||||||
|
* since they are what is displayed in GET requests.
|
||||||
|
*/
|
||||||
|
$checkbox_keys = array_diff(
|
||||||
|
array_keys( $field['choices'] ),
|
||||||
|
array_values( $field['choices'] )
|
||||||
|
);
|
||||||
|
|
||||||
|
$schema['items']['enum'] = empty( $checkbox_keys ) ? $field['choices'] : $checkbox_keys;
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ if ( ! class_exists( 'acf_field_date_picker' ) ) :
|
||||||
'value' => $hidden_value,
|
'value' => $hidden_value,
|
||||||
);
|
);
|
||||||
$text_input = array(
|
$text_input = array(
|
||||||
'class' => 'input',
|
'class' => $field['class'] . ' input',
|
||||||
'value' => $display_value,
|
'value' => $display_value,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -274,6 +274,61 @@ if ( ! class_exists( 'acf_field_date_picker' ) ) :
|
||||||
return acf_format_date( $value, $field['return_format'] );
|
return acf_format_date( $value, $field['return_format'] );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This filter is applied to the $field after it is loaded from the database
|
||||||
|
* and ensures the return and display values are set.
|
||||||
|
*
|
||||||
|
* @type filter
|
||||||
|
* @since 5.11.0
|
||||||
|
* @date 28/09/21
|
||||||
|
*
|
||||||
|
* @param array $field The field array holding all the field options.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function load_field( $field ) {
|
||||||
|
if ( empty( $field['display_format'] ) ) {
|
||||||
|
$field['display_format'] = $this->defaults['display_format'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $field['return_format'] ) ) {
|
||||||
|
$field['return_format'] = $this->defaults['return_format'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $field;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
return array(
|
||||||
|
'type' => array( 'string', 'null' ),
|
||||||
|
'description' => 'A `Ymd` formatted date string.',
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply basic formatting to prepare the value for default REST output.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string|int $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function format_value_for_rest( $value, $post_id, array $field ) {
|
||||||
|
if ( ! $value ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string) $value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ if ( ! class_exists( 'acf_field_date_and_time_picker' ) ) :
|
||||||
'value' => $hidden_value,
|
'value' => $hidden_value,
|
||||||
);
|
);
|
||||||
$text_input = array(
|
$text_input = array(
|
||||||
'class' => 'input',
|
'class' => $field['class'] . ' input',
|
||||||
'value' => $display_value,
|
'value' => $display_value,
|
||||||
);
|
);
|
||||||
foreach ( array( 'readonly', 'disabled' ) as $k ) {
|
foreach ( array( 'readonly', 'disabled' ) as $k ) {
|
||||||
|
|
@ -249,6 +249,45 @@ if ( ! class_exists( 'acf_field_date_and_time_picker' ) ) :
|
||||||
return acf_format_date( $value, $field['return_format'] );
|
return acf_format_date( $value, $field['return_format'] );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This filter is applied to the $field after it is loaded from the database
|
||||||
|
* and ensures the return and display values are set.
|
||||||
|
*
|
||||||
|
* @type filter
|
||||||
|
* @since 5.11.0
|
||||||
|
* @date 28/09/21
|
||||||
|
*
|
||||||
|
* @param array $field The field array holding all the field options.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function load_field( $field ) {
|
||||||
|
if ( empty( $field['display_format'] ) ) {
|
||||||
|
$field['display_format'] = $this->defaults['display_format'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $field['return_format'] ) ) {
|
||||||
|
$field['return_format'] = $this->defaults['return_format'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $field;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
return array(
|
||||||
|
'type' => array( 'string', 'null' ),
|
||||||
|
'description' => 'A `Y-m-d H:i:s` formatted date string.',
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -178,6 +178,19 @@ if ( ! class_exists( 'acf_field_email' ) ) :
|
||||||
return $valid;
|
return $valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = parent::get_rest_schema( $field );
|
||||||
|
$schema['format'] = 'email';
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -393,21 +393,18 @@ if ( ! class_exists( 'acf_field_file' ) ) :
|
||||||
return $attachment_id;
|
return $attachment_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* validate_value
|
||||||
/*
|
*
|
||||||
* validate_value
|
* This function will validate a basic file input
|
||||||
*
|
*
|
||||||
* This function will validate a basic file input
|
* @type function
|
||||||
*
|
* @date 11/02/2014
|
||||||
* @type function
|
* @since 5.0.0
|
||||||
* @date 11/02/2014
|
*
|
||||||
* @since 5.0.0
|
* @param $post_id (int)
|
||||||
*
|
* @return $post_id (int)
|
||||||
* @param $post_id (int)
|
*/
|
||||||
* @return $post_id (int)
|
|
||||||
*/
|
|
||||||
|
|
||||||
function validate_value( $valid, $value, $field, $input ) {
|
function validate_value( $valid, $value, $field, $input ) {
|
||||||
|
|
||||||
// bail early if empty
|
// bail early if empty
|
||||||
|
|
@ -439,14 +436,103 @@ if ( ! class_exists( 'acf_field_file' ) ) :
|
||||||
|
|
||||||
// append error
|
// append error
|
||||||
if ( ! empty( $errors ) ) {
|
if ( ! empty( $errors ) ) {
|
||||||
|
|
||||||
$valid = implode( "\n", $errors );
|
$valid = implode( "\n", $errors );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return
|
// return
|
||||||
return $valid;
|
return $valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates file fields updated via the REST API.
|
||||||
|
*
|
||||||
|
* @param bool $valid
|
||||||
|
* @param int $value
|
||||||
|
* @param array $field
|
||||||
|
*
|
||||||
|
* @return bool|WP_Error
|
||||||
|
*/
|
||||||
|
public function validate_rest_value( $valid, $value, $field ) {
|
||||||
|
/**
|
||||||
|
* A bit of a hack, but we use `wp_prepare_attachment_for_js()` here
|
||||||
|
* since it returns all the data we need to validate the file, and we use this anyways
|
||||||
|
* to validate fields updated via UI.
|
||||||
|
*/
|
||||||
|
$attachment = wp_prepare_attachment_for_js( $value );
|
||||||
|
$param = sprintf( '%s[%s]', $field['prefix'], $field['name'] );
|
||||||
|
$data = array(
|
||||||
|
'param' => $param,
|
||||||
|
'value' => (int) $value,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( ! $attachment ) {
|
||||||
|
$error = sprintf( __( '%s requires a valid attachment ID.', 'acf' ), $param );
|
||||||
|
return new WP_Error( 'rest_invalid_param', $error, $data );
|
||||||
|
}
|
||||||
|
|
||||||
|
$errors = acf_validate_attachment( $attachment, $field, 'prepare' );
|
||||||
|
|
||||||
|
if ( ! empty( $errors ) ) {
|
||||||
|
$error = $param . ' - ' . implode( ' ', $errors );
|
||||||
|
return new WP_Error( 'rest_invalid_param', $error, $data );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = array(
|
||||||
|
'type' => array( 'integer', 'null' ),
|
||||||
|
'required' => isset( $field['required'] ) && $field['required'],
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( ! empty( $field['min_width'] ) ) {
|
||||||
|
$schema['minWidth'] = (int) $field['min_width'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $field['min_height'] ) ) {
|
||||||
|
$schema['minHeight'] = (int) $field['min_height'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $field['min_size'] ) ) {
|
||||||
|
$schema['minSize'] = $field['min_size'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $field['max_width'] ) ) {
|
||||||
|
$schema['maxWidth'] = (int) $field['max_width'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $field['max_height'] ) ) {
|
||||||
|
$schema['maxHeight'] = (int) $field['max_height'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $field['max_size'] ) ) {
|
||||||
|
$schema['maxSize'] = $field['max_size'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $field['mime_types'] ) ) {
|
||||||
|
$schema['mimeTypes'] = $field['mime_types'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply basic formatting to prepare the value for default REST output.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string|int $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function format_value_for_rest( $value, $post_id, array $field ) {
|
||||||
|
return acf_format_numerics( $value );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -301,6 +301,82 @@ if ( ! class_exists( 'acf_field_google_map' ) ) :
|
||||||
// Return default.
|
// Return default.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
return array(
|
||||||
|
'type' => array( 'object', 'null' ),
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
'properties' => array(
|
||||||
|
'address' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
),
|
||||||
|
'lat' => array(
|
||||||
|
'type' => array( 'string', 'float' ),
|
||||||
|
),
|
||||||
|
'lng' => array(
|
||||||
|
'type' => array( 'string', 'float' ),
|
||||||
|
),
|
||||||
|
'zoom' => array(
|
||||||
|
'type' => array( 'string', 'int' ),
|
||||||
|
),
|
||||||
|
'place_id' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
),
|
||||||
|
'name' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
),
|
||||||
|
'street_number' => array(
|
||||||
|
'type' => array( 'string', 'int' ),
|
||||||
|
),
|
||||||
|
'street_name' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
),
|
||||||
|
'street_name_short' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
),
|
||||||
|
'city' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
),
|
||||||
|
'state' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
),
|
||||||
|
'state_short' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
),
|
||||||
|
'post_code' => array(
|
||||||
|
'type' => array( 'string', 'int' ),
|
||||||
|
),
|
||||||
|
'country' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
),
|
||||||
|
'country_short' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply basic formatting to prepare the value for default REST output.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string|int $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function format_value_for_rest( $value, $post_id, array $field ) {
|
||||||
|
if ( ! $value ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return acf_format_numerics( $value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -659,6 +659,56 @@ if ( ! class_exists( 'acf_field__group' ) ) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = array(
|
||||||
|
'type' => array( 'object', 'null' ),
|
||||||
|
'properties' => array(),
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ( $field['sub_fields'] as $sub_field ) {
|
||||||
|
if ( $sub_field_schema = acf_get_field_rest_schema( $sub_field ) ) {
|
||||||
|
$schema['properties'][ $sub_field['name'] ] = $sub_field_schema;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply basic formatting to prepare the value for default REST output.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param int|string $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return array|mixed
|
||||||
|
*/
|
||||||
|
public function format_value_for_rest( $value, $post_id, array $field ) {
|
||||||
|
if ( empty( $value ) || ! is_array( $value ) || empty( $field['sub_fields'] ) ) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through each row and within that, each sub field to process sub fields individually.
|
||||||
|
foreach ( $field['sub_fields'] as $sub_field ) {
|
||||||
|
|
||||||
|
// Extract the sub field 'field_key'=>'value' pair from the $value and format it.
|
||||||
|
$sub_value = acf_extract_var( $value, $sub_field['key'] );
|
||||||
|
$sub_value = acf_format_value_for_rest( $sub_value, $post_id, $sub_field );
|
||||||
|
|
||||||
|
// Add the sub field value back to the $value but mapped to the field name instead
|
||||||
|
// of the key reference.
|
||||||
|
$value[ $sub_field['name'] ] = $sub_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -422,23 +422,55 @@ if ( ! class_exists( 'acf_field_image' ) ) :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* validate_value
|
* validate_value
|
||||||
*
|
*
|
||||||
* This function will validate a basic file input
|
* This function will validate a basic file input
|
||||||
*
|
*
|
||||||
* @type function
|
* @type function
|
||||||
* @date 11/02/2014
|
* @date 11/02/2014
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
*
|
*
|
||||||
* @param $post_id (int)
|
* @param $post_id (int)
|
||||||
* @return $post_id (int)
|
* @return $post_id (int)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function validate_value( $valid, $value, $field, $input ) {
|
function validate_value( $valid, $value, $field, $input ) {
|
||||||
|
|
||||||
return acf_get_field_type( 'file' )->validate_value( $valid, $value, $field, $input );
|
return acf_get_field_type( 'file' )->validate_value( $valid, $value, $field, $input );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional validation for the image field when submitted via REST.
|
||||||
|
*
|
||||||
|
* @param bool $valid
|
||||||
|
* @param int $value
|
||||||
|
* @param array $field
|
||||||
|
*
|
||||||
|
* @return bool|WP_Error
|
||||||
|
*/
|
||||||
|
public function validate_rest_value( $valid, $value, $field ) {
|
||||||
|
return acf_get_field_type( 'file' )->validate_rest_value( $valid, $value, $field );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
return acf_get_field_type( 'file' )->get_rest_schema( $field );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply basic formatting to prepare the value for default REST output.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string|int $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function format_value_for_rest( $value, $post_id, array $field ) {
|
||||||
|
return acf_format_numerics( $value );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -280,6 +280,32 @@ if ( ! class_exists( 'acf_field_link' ) ) :
|
||||||
// return
|
// return
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
return array(
|
||||||
|
'type' => array( 'object', 'null' ),
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
'properties' => array(
|
||||||
|
'title' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
),
|
||||||
|
'url' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
'required' => true,
|
||||||
|
'format' => 'uri',
|
||||||
|
),
|
||||||
|
'target' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ if ( ! class_exists( 'acf_field_message' ) ) :
|
||||||
|
|
||||||
class acf_field_message extends acf_field {
|
class acf_field_message extends acf_field {
|
||||||
|
|
||||||
|
public $show_in_rest = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* __construct
|
* __construct
|
||||||
|
|
|
||||||
|
|
@ -295,6 +295,44 @@ if ( ! class_exists( 'acf_field_number' ) ) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = array(
|
||||||
|
'type' => array( 'number', 'null' ),
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( ! empty( $field['min'] ) ) {
|
||||||
|
$schema['minimum'] = (float) $field['min'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $field['max'] ) ) {
|
||||||
|
$schema['maximum'] = (float) $field['max'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isset( $field['default_value'] ) && is_numeric( $field['default_value'] ) ) {
|
||||||
|
$schema['default'] = (float) $field['default_value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply basic formatting to prepare the value for default REST output.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string|int $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function format_value_for_rest( $value, $post_id, array $field ) {
|
||||||
|
return acf_format_numerics( $value );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -299,24 +299,22 @@ if ( ! class_exists( 'acf_field_oembed' ) ) :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* format_value()
|
* format_value()
|
||||||
*
|
*
|
||||||
* This filter is appied to the $value after it is loaded from the db and before it is returned to the template
|
* This filter is appied to the $value after it is loaded from the db and before it is returned to the template
|
||||||
*
|
*
|
||||||
* @type filter
|
* @type filter
|
||||||
* @since 3.6
|
* @since 3.6
|
||||||
* @date 23/01/13
|
* @date 23/01/13
|
||||||
*
|
*
|
||||||
* @param $value (mixed) the value which was loaded from the database
|
* @param $value (mixed) the value which was loaded from the database
|
||||||
* @param $post_id (mixed) the $post_id from which the value was loaded
|
* @param $post_id (mixed) the $post_id from which the value was loaded
|
||||||
* @param $field (array) the field array holding all the field options
|
* @param $field (array) the field array holding all the field options
|
||||||
*
|
*
|
||||||
* @return $value (mixed) the modified value
|
* @return $value (mixed) the modified value
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function format_value( $value, $post_id, $field ) {
|
function format_value( $value, $post_id, $field ) {
|
||||||
|
|
||||||
// bail early if no value
|
// bail early if no value
|
||||||
if ( empty( $value ) ) {
|
if ( empty( $value ) ) {
|
||||||
return $value;
|
return $value;
|
||||||
|
|
@ -330,9 +328,20 @@ if ( ! class_exists( 'acf_field_oembed' ) ) :
|
||||||
|
|
||||||
// return
|
// return
|
||||||
return $value;
|
return $value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = parent::get_rest_schema( $field );
|
||||||
|
$schema['format'] = 'uri';
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -619,6 +619,91 @@ if ( ! class_exists( 'acf_field_page_link' ) ) :
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates page link fields updated via the REST API.
|
||||||
|
*
|
||||||
|
* @param bool $valid
|
||||||
|
* @param int $value
|
||||||
|
* @param array $field
|
||||||
|
*
|
||||||
|
* @return bool|WP_Error
|
||||||
|
*/
|
||||||
|
public function validate_rest_value( $valid, $value, $field ) {
|
||||||
|
return acf_get_field_type( 'post_object' )->validate_rest_value( $valid, $value, $field );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = array(
|
||||||
|
'type' => array( 'integer', 'array', 'null' ),
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
'items' => array(
|
||||||
|
'type' => array( 'integer' ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( empty( $field['allow_null'] ) ) {
|
||||||
|
$schema['minItems'] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $field['allow_archives'] ) ) {
|
||||||
|
$schema['type'][] = 'string';
|
||||||
|
$schema['items']['type'][] = 'string';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $field['multiple'] ) ) {
|
||||||
|
$schema['maxItems'] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \acf_field::get_rest_links()
|
||||||
|
* @param mixed $value The raw (unformatted) field value.
|
||||||
|
* @param int|string $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_links( $value, $post_id, array $field ) {
|
||||||
|
$links = array();
|
||||||
|
|
||||||
|
if ( empty( $value ) ) {
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( (array) $value as $object_id ) {
|
||||||
|
if ( ! $post_type = get_post_type( $object_id ) or ! $post_type = get_post_type_object( $post_type ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$rest_base = acf_get_object_type_rest_base( $post_type );
|
||||||
|
$links[] = array(
|
||||||
|
'rel' => $post_type->name === 'attachment' ? 'acf:attachment' : 'acf:post',
|
||||||
|
'href' => rest_url( sprintf( '/wp/v2/%s/%s', $rest_base, $object_id ) ),
|
||||||
|
'embeddable' => true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply basic formatting to prepare the value for default REST output.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string|int $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function format_value_for_rest( $value, $post_id, array $field ) {
|
||||||
|
return acf_format_numerics( $value );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -580,6 +580,179 @@ if ( ! class_exists( 'acf_field_post_object' ) ) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates post object fields updated via the REST API.
|
||||||
|
*
|
||||||
|
* @param bool $valid
|
||||||
|
* @param int $value
|
||||||
|
* @param array $field
|
||||||
|
*
|
||||||
|
* @return bool|WP_Error
|
||||||
|
*/
|
||||||
|
public function validate_rest_value( $valid, $value, $field ) {
|
||||||
|
if ( is_null( $value ) ) {
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
$param = sprintf( '%s[%s]', $field['prefix'], $field['name'] );
|
||||||
|
$data = array( 'param' => $param );
|
||||||
|
$value = is_array( $value ) ? $value : array( $value );
|
||||||
|
|
||||||
|
$invalid_posts = array();
|
||||||
|
$post_type_errors = array();
|
||||||
|
$taxonomy_errors = array();
|
||||||
|
|
||||||
|
foreach ( $value as $post_id ) {
|
||||||
|
if ( is_string( $post_id ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$post_type = get_post_type( $post_id );
|
||||||
|
if ( ! $post_type ) {
|
||||||
|
$invalid_posts[] = $post_id;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
is_array( $field['post_type'] ) &&
|
||||||
|
! empty( $field['post_type'] ) &&
|
||||||
|
! in_array( $post_type, $field['post_type'] )
|
||||||
|
) {
|
||||||
|
$post_type_errors[] = $post_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( is_array( $field['taxonomy'] ) && ! empty( $field['taxonomy'] ) ) {
|
||||||
|
$found = false;
|
||||||
|
foreach ( $field['taxonomy'] as $taxonomy_term ) {
|
||||||
|
$decoded = acf_decode_taxonomy_term( $taxonomy_term );
|
||||||
|
if ( $decoded && is_object_in_term( $post_id, $decoded['taxonomy'], $decoded['term'] ) ) {
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! $found ) {
|
||||||
|
$taxonomy_errors[] = $post_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( count( $invalid_posts ) ) {
|
||||||
|
$error = sprintf(
|
||||||
|
__( '%1$s must have a valid post ID.', 'acf' ),
|
||||||
|
$param
|
||||||
|
);
|
||||||
|
$data['value'] = $invalid_posts;
|
||||||
|
return new WP_Error( 'rest_invalid_param', $error, $data );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( count( $post_type_errors ) ) {
|
||||||
|
$error = sprintf(
|
||||||
|
_n(
|
||||||
|
'%1$s must be of post type %2$s.',
|
||||||
|
'%1$s must be of one of the following post types: %2$s',
|
||||||
|
count( $field['post_type'] ),
|
||||||
|
'acf'
|
||||||
|
),
|
||||||
|
$param,
|
||||||
|
count( $field['post_type'] ) > 1 ? implode( ', ', $field['post_type'] ) : $field['post_type'][0]
|
||||||
|
);
|
||||||
|
$data['value'] = $post_type_errors;
|
||||||
|
|
||||||
|
return new WP_Error( 'rest_invalid_param', $error, $data );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( count( $taxonomy_errors ) ) {
|
||||||
|
$error = sprintf(
|
||||||
|
_n(
|
||||||
|
'%1$s must have term %2$s.',
|
||||||
|
'%1$s must have one of the following terms: %2$s',
|
||||||
|
count( $field['taxonomy'] ),
|
||||||
|
'acf'
|
||||||
|
),
|
||||||
|
$param,
|
||||||
|
count( $field['taxonomy'] ) > 1 ? implode( ', ', $field['taxonomy'] ) : $field['taxonomy'][0]
|
||||||
|
);
|
||||||
|
$data['value'] = $taxonomy_errors;
|
||||||
|
|
||||||
|
return new WP_Error( 'rest_invalid_param', $error, $data );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = array(
|
||||||
|
'type' => array( 'integer', 'array', 'null' ),
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
'items' => array(
|
||||||
|
'type' => 'integer',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( empty( $field['allow_null'] ) ) {
|
||||||
|
$schema['minItems'] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $field['multiple'] ) ) {
|
||||||
|
$schema['maxItems'] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \acf_field::get_rest_links()
|
||||||
|
* @param mixed $value The raw (unformatted) field value.
|
||||||
|
* @param int|string $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_links( $value, $post_id, array $field ) {
|
||||||
|
$links = array();
|
||||||
|
|
||||||
|
if ( empty( $value ) ) {
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( (array) $value as $object_id ) {
|
||||||
|
if ( ! $post_type = get_post_type( $object_id ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! $post_type_object = get_post_type_object( $post_type ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rest_base = acf_get_object_type_rest_base( $post_type_object );
|
||||||
|
$links[] = array(
|
||||||
|
'rel' => $post_type_object->name === 'attachment' ? 'acf:attachment' : 'acf:post',
|
||||||
|
'href' => rest_url( sprintf( '/wp/v2/%s/%s', $rest_base, $object_id ) ),
|
||||||
|
'embeddable' => true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply basic formatting to prepare the value for default REST output.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string|int $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function format_value_for_rest( $value, $post_id, array $field ) {
|
||||||
|
return acf_format_numerics( $value );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -443,6 +443,42 @@ if ( ! class_exists( 'acf_field_radio' ) ) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function get_rest_schema( array $field ) {
|
||||||
|
$schema = parent::get_rest_schema( $field );
|
||||||
|
|
||||||
|
if ( isset( $field['default_value'] ) && '' !== $field['default_value'] ) {
|
||||||
|
$schema['default'] = $field['default_value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// If other/custom choices are allowed, nothing else to do here.
|
||||||
|
if ( ! empty( $field['other_choice'] ) ) {
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a user has defined keys for the radio options,
|
||||||
|
* we should use the keys for the available options to POST to,
|
||||||
|
* since they are what is displayed in GET requests.
|
||||||
|
*/
|
||||||
|
$radio_keys = array_diff(
|
||||||
|
array_keys( $field['choices'] ),
|
||||||
|
array_values( $field['choices'] )
|
||||||
|
);
|
||||||
|
|
||||||
|
$schema['enum'] = empty( $radio_keys ) ? $field['choices'] : $radio_keys;
|
||||||
|
if ( ! empty( $field['allow_null'] ) ) {
|
||||||
|
$schema['enum'][] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -227,6 +227,39 @@ if ( ! class_exists( 'acf_field_range' ) ) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = array(
|
||||||
|
'type' => array( 'number', 'null' ),
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
'minimum' => empty( $field['min'] ) ? 0 : (int) $field['min'],
|
||||||
|
'maximum' => empty( $field['max'] ) ? 100 : (int) $field['max'],
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( isset( $field['default_value'] ) && is_numeric( $field['default_value'] ) ) {
|
||||||
|
$schema['default'] = (int) $field['default_value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply basic formatting to prepare the value for default REST output.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string|int $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function format_value_for_rest( $value, $post_id, array $field ) {
|
||||||
|
return acf_format_numerics( $value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -760,24 +760,22 @@ if ( ! class_exists( 'acf_field_relationship' ) ) :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* update_value()
|
* update_value()
|
||||||
*
|
*
|
||||||
* This filter is applied to the $value before it is updated in the db
|
* This filter is applied to the $value before it is updated in the db
|
||||||
*
|
*
|
||||||
* @type filter
|
* @type filter
|
||||||
* @since 3.6
|
* @since 3.6
|
||||||
* @date 23/01/13
|
* @date 23/01/13
|
||||||
*
|
*
|
||||||
* @param $value - the value which will be saved in the database
|
* @param $value - the value which will be saved in the database
|
||||||
* @param $post_id - the $post_id of which the value will be saved
|
* @param $post_id - the $post_id of which the value will be saved
|
||||||
* @param $field - the field array holding all the field options
|
* @param $field - the field array holding all the field options
|
||||||
*
|
*
|
||||||
* @return $value - the modified value
|
* @return $value - the modified value
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function update_value( $value, $post_id, $field ) {
|
function update_value( $value, $post_id, $field ) {
|
||||||
|
|
||||||
// Bail early if no value.
|
// Bail early if no value.
|
||||||
if ( empty( $value ) ) {
|
if ( empty( $value ) ) {
|
||||||
return $value;
|
return $value;
|
||||||
|
|
@ -799,6 +797,90 @@ if ( ! class_exists( 'acf_field_relationship' ) ) :
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates relationship fields updated via the REST API.
|
||||||
|
*
|
||||||
|
* @param bool $valid
|
||||||
|
* @param int $value
|
||||||
|
* @param array $field
|
||||||
|
*
|
||||||
|
* @return bool|WP_Error
|
||||||
|
*/
|
||||||
|
public function validate_rest_value( $valid, $value, $field ) {
|
||||||
|
return acf_get_field_type( 'post_object' )->validate_rest_value( $valid, $value, $field );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = array(
|
||||||
|
'type' => array( 'integer', 'array', 'null' ),
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
'items' => array(
|
||||||
|
'type' => 'integer',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( empty( $field['allow_null'] ) ) {
|
||||||
|
$schema['minItems'] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $field['min'] ) ) {
|
||||||
|
$schema['minItems'] = (int) $field['min'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $field['max'] ) ) {
|
||||||
|
$schema['maxItems'] = (int) $field['max'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \acf_field::get_rest_links()
|
||||||
|
* @param mixed $value The raw (unformatted) field value.
|
||||||
|
* @param int|string $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_links( $value, $post_id, array $field ) {
|
||||||
|
$links = array();
|
||||||
|
|
||||||
|
if ( empty( $value ) ) {
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( (array) $value as $object_id ) {
|
||||||
|
if ( ! $post_type = get_post_type( $object_id ) or ! $post_type = get_post_type_object( $post_type ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$rest_base = acf_get_object_type_rest_base( $post_type );
|
||||||
|
$links[] = array(
|
||||||
|
'rel' => $post_type->name === 'attachment' ? 'acf:attachment' : 'acf:post',
|
||||||
|
'href' => rest_url( sprintf( '/wp/v2/%s/%s', $rest_base, $object_id ) ),
|
||||||
|
'embeddable' => true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply basic formatting to prepare the value for default REST output.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string|int $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function format_value_for_rest( $value, $post_id, array $field ) {
|
||||||
|
return acf_format_numerics( $value );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ if ( ! class_exists( 'acf_field_select' ) ) :
|
||||||
|
|
||||||
function input_admin_enqueue_scripts() {
|
function input_admin_enqueue_scripts() {
|
||||||
|
|
||||||
// bail ealry if no enqueue
|
// bail early if no enqueue
|
||||||
if ( ! acf_get_setting( 'enqueue_select2' ) ) {
|
if ( ! acf_get_setting( 'enqueue_select2' ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -83,7 +83,7 @@ if ( ! class_exists( 'acf_field_select' ) ) :
|
||||||
// v4
|
// v4
|
||||||
if ( $major == 4 ) {
|
if ( $major == 4 ) {
|
||||||
|
|
||||||
$version = '4.0';
|
$version = '4.0.13';
|
||||||
$script = acf_get_url( "assets/inc/select2/4/select2.full{$min}.js" );
|
$script = acf_get_url( "assets/inc/select2/4/select2.full{$min}.js" );
|
||||||
$style = acf_get_url( "assets/inc/select2/4/select2{$min}.css" );
|
$style = acf_get_url( "assets/inc/select2/4/select2{$min}.css" );
|
||||||
|
|
||||||
|
|
@ -324,6 +324,10 @@ if ( ! class_exists( 'acf_field_select' ) ) :
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $field['query_nonce'] ) ) {
|
||||||
|
$select['data-query-nonce'] = $field['query_nonce'];
|
||||||
|
}
|
||||||
|
|
||||||
// append
|
// append
|
||||||
$select['value'] = $value;
|
$select['value'] = $value;
|
||||||
$select['choices'] = $choices;
|
$select['choices'] = $choices;
|
||||||
|
|
@ -627,6 +631,87 @@ if ( ! class_exists( 'acf_field_select' ) ) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates select fields updated via the REST API.
|
||||||
|
*
|
||||||
|
* @param bool $valid
|
||||||
|
* @param int $value
|
||||||
|
* @param array $field
|
||||||
|
*
|
||||||
|
* @return bool|WP_Error
|
||||||
|
*/
|
||||||
|
public function validate_rest_value( $valid, $value, $field ) {
|
||||||
|
// rest_validate_request_arg() handles the other types, we just worry about strings.
|
||||||
|
if ( is_null( $value ) || is_array( $value ) ) {
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
$option_keys = array_diff(
|
||||||
|
array_keys( $field['choices'] ),
|
||||||
|
array_values( $field['choices'] )
|
||||||
|
);
|
||||||
|
|
||||||
|
$allowed = empty( $option_keys ) ? $field['choices'] : $option_keys;
|
||||||
|
|
||||||
|
if ( ! in_array( $value, $allowed ) ) {
|
||||||
|
$param = sprintf( '%s[%s]', $field['prefix'], $field['name'] );
|
||||||
|
$data = array(
|
||||||
|
'param' => $param,
|
||||||
|
'value' => $value,
|
||||||
|
);
|
||||||
|
$error = sprintf(
|
||||||
|
__( '%1$s is not one of %2$s', 'acf' ),
|
||||||
|
$param,
|
||||||
|
implode( ', ', $allowed )
|
||||||
|
);
|
||||||
|
|
||||||
|
return new WP_Error( 'rest_invalid_param', $error, $data );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
/**
|
||||||
|
* If a user has defined keys for the select options,
|
||||||
|
* we should use the keys for the available options to POST to,
|
||||||
|
* since they are what is displayed in GET requests.
|
||||||
|
*/
|
||||||
|
$option_keys = array_diff(
|
||||||
|
array_keys( $field['choices'] ),
|
||||||
|
array_values( $field['choices'] )
|
||||||
|
);
|
||||||
|
|
||||||
|
$schema = array(
|
||||||
|
'type' => array( 'string', 'array', 'null' ),
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
'items' => array(
|
||||||
|
'type' => array( 'string' ),
|
||||||
|
'enum' => empty( $option_keys ) ? $field['choices'] : $option_keys,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( empty( $field['allow_null'] ) ) {
|
||||||
|
$schema['minItems'] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $field['multiple'] ) ) {
|
||||||
|
$schema['maxItems'] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isset( $field['default_value'] ) && '' !== $field['default_value'] ) {
|
||||||
|
$schema['default'] = $field['default_value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ if ( ! class_exists( 'acf_field_tab' ) ) :
|
||||||
|
|
||||||
class acf_field_tab extends acf_field {
|
class acf_field_tab extends acf_field {
|
||||||
|
|
||||||
|
public $show_in_rest = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* __construct
|
* __construct
|
||||||
|
|
|
||||||
|
|
@ -315,7 +315,10 @@ if ( ! class_exists( 'acf_field_taxonomy' ) ) :
|
||||||
if ( $field['load_terms'] ) {
|
if ( $field['load_terms'] ) {
|
||||||
|
|
||||||
// Decode $post_id for $type and $id.
|
// Decode $post_id for $type and $id.
|
||||||
extract( acf_decode_post_id( $post_id ) );
|
$decoded = acf_decode_post_id( $post_id );
|
||||||
|
$type = $decoded['type'];
|
||||||
|
$id = $decoded['id'];
|
||||||
|
|
||||||
if ( $type === 'block' ) {
|
if ( $type === 'block' ) {
|
||||||
// Get parent block...
|
// Get parent block...
|
||||||
}
|
}
|
||||||
|
|
@ -426,30 +429,29 @@ if ( ! class_exists( 'acf_field_taxonomy' ) ) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/*
|
* This function will save any terms in the save_post_terms array
|
||||||
* save_post
|
*
|
||||||
*
|
* @date 26/11/2014
|
||||||
* This function will save any terms in the save_post_terms array
|
* @since 5.0.9
|
||||||
*
|
*
|
||||||
* @type function
|
* @param int $post_id
|
||||||
* @date 26/11/2014
|
*
|
||||||
* @since 5.0.9
|
* @return void
|
||||||
*
|
*/
|
||||||
* @param $post_id (int)
|
|
||||||
* @return n/a
|
|
||||||
*/
|
|
||||||
|
|
||||||
function save_post( $post_id ) {
|
function save_post( $post_id ) {
|
||||||
|
|
||||||
// Check for saved terms.
|
// Check for saved terms.
|
||||||
if ( ! empty( $this->save_post_terms ) ) {
|
if ( ! empty( $this->save_post_terms ) ) {
|
||||||
|
/**
|
||||||
|
* Determine object ID allowing for non "post" $post_id (user, taxonomy, etc).
|
||||||
|
* Although not fully supported by WordPress, non "post" objects may use the term relationships table.
|
||||||
|
* Sharing taxonomies across object types is discouraged, but unique taxonomies work well.
|
||||||
|
* Note: Do not attempt to restrict to "post" only. This has been attempted in 5.8.9 and later reverted.
|
||||||
|
*/
|
||||||
|
$decoded = acf_decode_post_id( $post_id );
|
||||||
|
$type = $decoded['type'];
|
||||||
|
$id = $decoded['id'];
|
||||||
|
|
||||||
// Determine object ID allowing for non "post" $post_id (user, taxonomy, etc).
|
|
||||||
// Although not fully supported by WordPress, non "post" objects may use the term relationships table.
|
|
||||||
// Sharing taxonomies across object types is discoraged, but unique taxonomies work well.
|
|
||||||
// Note: Do not attempt to restrict to "post" only. This has been attempted in 5.8.9 and later reverted.
|
|
||||||
extract( acf_decode_post_id( $post_id ) );
|
|
||||||
if ( $type === 'block' ) {
|
if ( $type === 'block' ) {
|
||||||
// Get parent block...
|
// Get parent block...
|
||||||
}
|
}
|
||||||
|
|
@ -464,7 +466,6 @@ if ( ! class_exists( 'acf_field_taxonomy' ) ) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* format_value()
|
* format_value()
|
||||||
*
|
*
|
||||||
|
|
@ -966,6 +967,67 @@ if ( ! class_exists( 'acf_field_taxonomy' ) ) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = array(
|
||||||
|
'type' => array( 'integer', 'array', 'null' ),
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
'items' => array(
|
||||||
|
'type' => 'integer',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( empty( $field['allow_null'] ) ) {
|
||||||
|
$schema['minItems'] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( in_array( $field['field_type'], array( 'radio', 'select' ) ) ) {
|
||||||
|
$schema['maxItems'] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \acf_field::get_rest_links()
|
||||||
|
* @param mixed $value The raw (unformatted) field value.
|
||||||
|
* @param int|string $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_links( $value, $post_id, array $field ) {
|
||||||
|
$links = array();
|
||||||
|
|
||||||
|
if ( empty( $value ) ) {
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( (array) $value as $object_id ) {
|
||||||
|
$term = get_term( $object_id );
|
||||||
|
if ( ! $term instanceof WP_Term ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rest_base = acf_get_object_type_rest_base( get_taxonomy( $term->taxonomy ) );
|
||||||
|
if ( ! $rest_base ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$links[] = array(
|
||||||
|
'rel' => 'acf:term',
|
||||||
|
'href' => rest_url( sprintf( '/wp/v2/%s/%s', $rest_base, $object_id ) ),
|
||||||
|
'embeddable' => true,
|
||||||
|
'taxonomy' => $term->taxonomy,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,22 @@ if ( ! class_exists( 'acf_field_text' ) ) :
|
||||||
// Return.
|
// Return.
|
||||||
return $valid;
|
return $valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function get_rest_schema( array $field ) {
|
||||||
|
$schema = parent::get_rest_schema( $field );
|
||||||
|
|
||||||
|
if ( ! empty( $field['maxlength'] ) ) {
|
||||||
|
$schema['maxLength'] = (int) $field['maxlength'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -224,6 +224,22 @@ if ( ! class_exists( 'acf_field_textarea' ) ) :
|
||||||
// Return.
|
// Return.
|
||||||
return $valid;
|
return $valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function get_rest_schema( array $field ) {
|
||||||
|
$schema = parent::get_rest_schema( $field );
|
||||||
|
|
||||||
|
if ( ! empty( $field['maxlength'] ) ) {
|
||||||
|
$schema['maxLength'] = (int) $field['maxlength'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ if ( ! class_exists( 'acf_field_time_picker' ) ) :
|
||||||
'value' => $field['value'],
|
'value' => $field['value'],
|
||||||
);
|
);
|
||||||
$text_input = array(
|
$text_input = array(
|
||||||
'class' => 'input',
|
'class' => $field['class'] . ' input',
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
'value' => $display_value,
|
'value' => $display_value,
|
||||||
);
|
);
|
||||||
|
|
@ -166,6 +166,43 @@ if ( ! class_exists( 'acf_field_time_picker' ) ) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This filter is applied to the $field after it is loaded from the database
|
||||||
|
* and ensures the return and display values are set.
|
||||||
|
*
|
||||||
|
* @type filter
|
||||||
|
* @since 5.11.0
|
||||||
|
* @date 28/09/21
|
||||||
|
*
|
||||||
|
* @param array $field The field array holding all the field options.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function load_field( $field ) {
|
||||||
|
if ( empty( $field['display_format'] ) ) {
|
||||||
|
$field['display_format'] = $this->defaults['display_format'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $field['return_format'] ) ) {
|
||||||
|
$field['return_format'] = $this->defaults['return_format'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $field;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
return array(
|
||||||
|
'type' => array( 'string', 'null' ),
|
||||||
|
'description' => 'A `H:i:s` formatted time string.',
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -285,6 +285,37 @@ if ( ! class_exists( 'acf_field_true_false' ) ) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = array(
|
||||||
|
'type' => array( 'boolean', 'null' ),
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( isset( $field['default_value'] ) && '' !== $field['default_value'] ) {
|
||||||
|
$schema['default'] = (bool) $field['default_value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply basic formatting to prepare the value for default REST output.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string|int $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function format_value_for_rest( $value, $post_id, array $field ) {
|
||||||
|
return (bool) $value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,19 @@ if ( ! class_exists( 'acf_field_url' ) ) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = parent::get_rest_schema( $field );
|
||||||
|
$schema['format'] = 'uri';
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,10 +113,11 @@ if ( ! class_exists( 'ACF_Field_User' ) ) :
|
||||||
function render_field( $field ) {
|
function render_field( $field ) {
|
||||||
|
|
||||||
// Change Field into a select.
|
// Change Field into a select.
|
||||||
$field['type'] = 'select';
|
$field['type'] = 'select';
|
||||||
$field['ui'] = 1;
|
$field['ui'] = 1;
|
||||||
$field['ajax'] = 1;
|
$field['ajax'] = 1;
|
||||||
$field['choices'] = array();
|
$field['choices'] = array();
|
||||||
|
$field['query_nonce'] = wp_create_nonce( 'acf/fields/user/query' . $field['key'] );
|
||||||
|
|
||||||
// Populate choices.
|
// Populate choices.
|
||||||
if ( $field['value'] ) {
|
if ( $field['value'] ) {
|
||||||
|
|
@ -344,11 +345,15 @@ if ( ! class_exists( 'ACF_Field_User' ) ) :
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function ajax_query_init( $request, $query ) {
|
function ajax_query_init( $request, $query ) {
|
||||||
|
// Require field and make sure it's a user field.
|
||||||
// Require field.
|
if ( ! $query->field || $query->field['type'] !== $this->name ) {
|
||||||
if ( ! $query->field ) {
|
|
||||||
$query->send( new WP_Error( 'acf_missing_field', __( 'Error loading field.', 'acf' ), array( 'status' => 404 ) ) );
|
$query->send( new WP_Error( 'acf_missing_field', __( 'Error loading field.', 'acf' ), array( 'status' => 404 ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify that this is a legitimate request using a separate nonce from the main AJAX nonce.
|
||||||
|
if ( ! isset( $_REQUEST['user_query_nonce'] ) || ! wp_verify_nonce( $_REQUEST['user_query_nonce'], 'acf/fields/user/query' . $query->field['key']) ) {
|
||||||
|
$query->send( new WP_Error( 'acf_invalid_request', __( 'Invalid request.', 'acf' ), array( 'status' => 404 ) ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -468,6 +473,135 @@ if ( ! class_exists( 'ACF_Field_User' ) ) :
|
||||||
_deprecated_function( __FUNCTION__, '5.8.9' );
|
_deprecated_function( __FUNCTION__, '5.8.9' );
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates user fields updated via the REST API.
|
||||||
|
*
|
||||||
|
* @param bool $valid
|
||||||
|
* @param int $value
|
||||||
|
* @param array $field
|
||||||
|
*
|
||||||
|
* @return bool|WP_Error
|
||||||
|
*/
|
||||||
|
public function validate_rest_value( $valid, $value, $field ) {
|
||||||
|
if ( is_null( $value ) ) {
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
$param = sprintf( '%s[%s]', $field['prefix'], $field['name'] );
|
||||||
|
$data = array( 'param' => $param );
|
||||||
|
$value = is_array( $value ) ? $value : array( $value );
|
||||||
|
|
||||||
|
$invalid_users = array();
|
||||||
|
$insufficient_roles = array();
|
||||||
|
|
||||||
|
foreach ( $value as $user_id ) {
|
||||||
|
$user_data = get_userdata( $user_id );
|
||||||
|
if ( ! $user_data ) {
|
||||||
|
$invalid_users[] = $user_id;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $field['role'] ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$has_roles = count( array_intersect( $field['role'], $user_data->roles ) );
|
||||||
|
if ( ! $has_roles ) {
|
||||||
|
$insufficient_roles[] = $user_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( count( $invalid_users ) ) {
|
||||||
|
$error = sprintf(
|
||||||
|
__( '%1$s must have a valid user ID.', 'acf' ),
|
||||||
|
$param
|
||||||
|
);
|
||||||
|
$data['value'] = $invalid_users;
|
||||||
|
return new WP_Error( 'rest_invalid_param', $error, $data );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( count( $insufficient_roles ) ) {
|
||||||
|
$error = sprintf(
|
||||||
|
_n(
|
||||||
|
'%1$s must have a user with the %2$s role.',
|
||||||
|
'%1$s must have a user with one of the following roles: %2$s',
|
||||||
|
count( $field['role'] ),
|
||||||
|
'acf'
|
||||||
|
),
|
||||||
|
$param,
|
||||||
|
count( $field['role'] ) > 1 ? implode( ', ', $field['role'] ) : $field['role'][0]
|
||||||
|
);
|
||||||
|
$data['value'] = $insufficient_roles;
|
||||||
|
return new WP_Error( 'rest_invalid_param', $error, $data );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = array(
|
||||||
|
'type' => array( 'integer', 'array', 'null' ),
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
'items' => array(
|
||||||
|
'type' => 'integer',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( empty( $field['allow_null'] ) ) {
|
||||||
|
$schema['minItems'] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $field['multiple'] ) ) {
|
||||||
|
$schema['maxItems'] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \acf_field::get_rest_links()
|
||||||
|
* @param mixed $value The raw (unformatted) field value.
|
||||||
|
* @param int|string $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_links( $value, $post_id, array $field ) {
|
||||||
|
$links = array();
|
||||||
|
|
||||||
|
if ( empty( $value ) ) {
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( (array) $value as $object_id ) {
|
||||||
|
$links[] = array(
|
||||||
|
'rel' => 'acf:user',
|
||||||
|
'href' => rest_url( '/wp/v2/users/' . $object_id ),
|
||||||
|
'embeddable' => true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply basic formatting to prepare the value for default REST output.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string|int $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function format_value_for_rest( $value, $post_id, array $field ) {
|
||||||
|
return acf_format_numerics( $value );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -179,18 +179,15 @@ if ( ! class_exists( 'acf_field_wysiwyg' ) ) :
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* render_field()
|
* Create the HTML interface for your field
|
||||||
*
|
*
|
||||||
* Create the HTML interface for your field
|
* @param array $field An array holding all the field's data
|
||||||
*
|
*
|
||||||
* @param $field - an array holding all the field's data
|
* @type action
|
||||||
*
|
* @since 3.6
|
||||||
* @type action
|
* @date 23/01/13
|
||||||
* @since 3.6
|
*/
|
||||||
* @date 23/01/13
|
|
||||||
*/
|
|
||||||
|
|
||||||
function render_field( $field ) {
|
function render_field( $field ) {
|
||||||
|
|
||||||
// enqueue
|
// enqueue
|
||||||
|
|
@ -240,6 +237,8 @@ if ( ! class_exists( 'acf_field_wysiwyg' ) ) :
|
||||||
|
|
||||||
// filter
|
// filter
|
||||||
add_filter( 'acf_the_editor_content', 'format_for_editor', 10, 2 );
|
add_filter( 'acf_the_editor_content', 'format_for_editor', 10, 2 );
|
||||||
|
|
||||||
|
$field['value'] = is_string( $field['value'] ) ? $field['value'] : '';
|
||||||
$field['value'] = apply_filters( 'acf_the_editor_content', $field['value'], $default_editor );
|
$field['value'] = apply_filters( 'acf_the_editor_content', $field['value'], $default_editor );
|
||||||
|
|
||||||
// attr
|
// attr
|
||||||
|
|
@ -403,39 +402,29 @@ if ( ! class_exists( 'acf_field_wysiwyg' ) ) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/*
|
* This filter is applied to the $value after it is loaded from the db, and before it is returned to the template
|
||||||
* format_value()
|
*
|
||||||
*
|
* @type filter
|
||||||
* This filter is appied to the $value after it is loaded from the db and before it is returned to the template
|
* @since 3.6
|
||||||
*
|
* @date 23/01/13
|
||||||
* @type filter
|
*
|
||||||
* @since 3.6
|
* @param mixed $value The value which was loaded from the database
|
||||||
* @date 23/01/13
|
* @param mixed $post_id The $post_id from which the value was loaded
|
||||||
*
|
* @param array $field The field array holding all the field options
|
||||||
* @param $value (mixed) the value which was loaded from the database
|
*
|
||||||
* @param $post_id (mixed) the $post_id from which the value was loaded
|
* @return mixed $value The modified value
|
||||||
* @param $field (array) the field array holding all the field options
|
*/
|
||||||
*
|
|
||||||
* @return $value (mixed) the modified value
|
|
||||||
*/
|
|
||||||
|
|
||||||
function format_value( $value, $post_id, $field ) {
|
function format_value( $value, $post_id, $field ) {
|
||||||
|
// Bail early if no value or not a string.
|
||||||
// bail early if no value
|
if ( empty( $value ) || ! is_string( $value ) ) {
|
||||||
if ( empty( $value ) ) {
|
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply filters
|
|
||||||
$value = apply_filters( 'acf_the_content', $value );
|
$value = apply_filters( 'acf_the_content', $value );
|
||||||
|
|
||||||
// follow the_content function in /wp-includes/post-template.php
|
// Follow the_content function in /wp-includes/post-template.php
|
||||||
$value = str_replace( ']]>', ']]>', $value );
|
return str_replace( ']]>', ']]>', $value );
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ if ( ! class_exists( 'acf_field' ) ) :
|
||||||
$l10n = array(),
|
$l10n = array(),
|
||||||
$public = true;
|
$public = true;
|
||||||
|
|
||||||
|
public $show_in_rest = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* __construct
|
* __construct
|
||||||
|
|
@ -49,6 +50,7 @@ if ( ! class_exists( 'acf_field' ) ) :
|
||||||
$this->add_field_action( 'acf/delete_value', array( $this, 'delete_value' ), 10, 3 );
|
$this->add_field_action( 'acf/delete_value', array( $this, 'delete_value' ), 10, 3 );
|
||||||
|
|
||||||
// field
|
// field
|
||||||
|
$this->add_field_filter( 'acf/validate_rest_value', array( $this, 'validate_rest_value' ), 10, 3 );
|
||||||
$this->add_field_filter( 'acf/validate_field', array( $this, 'validate_field' ), 10, 1 );
|
$this->add_field_filter( 'acf/validate_field', array( $this, 'validate_field' ), 10, 1 );
|
||||||
$this->add_field_filter( 'acf/load_field', array( $this, 'load_field' ), 10, 1 );
|
$this->add_field_filter( 'acf/load_field', array( $this, 'load_field' ), 10, 1 );
|
||||||
$this->add_field_filter( 'acf/update_field', array( $this, 'update_field' ), 10, 1 );
|
$this->add_field_filter( 'acf/update_field', array( $this, 'update_field' ), 10, 1 );
|
||||||
|
|
@ -268,6 +270,79 @@ if ( ! class_exists( 'acf_field' ) ) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add additional validation for fields being updated via the REST API.
|
||||||
|
*
|
||||||
|
* @param bool $valid
|
||||||
|
* @param mixed $value
|
||||||
|
* @param array $field
|
||||||
|
*
|
||||||
|
* @return bool|WP_Error
|
||||||
|
*/
|
||||||
|
public function validate_rest_value( $valid, $value, $field ) {
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema array for the REST API.
|
||||||
|
*
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_schema( array $field ) {
|
||||||
|
$schema = array(
|
||||||
|
'type' => array( 'string', 'null' ),
|
||||||
|
'required' => ! empty( $field['required'] ),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( isset( $field['default_value'] ) && '' !== $field['default_value'] ) {
|
||||||
|
$schema['default'] = $field['default_value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of links for addition to the REST API response. Each link is an array and must have both `rel` and
|
||||||
|
* `href` keys. The `href` key must be a REST API resource URL. If a link is marked as `embeddable`, the `_embed` URL
|
||||||
|
* parameter will trigger WordPress to dispatch an internal sub request and load the object within the same request
|
||||||
|
* under the `_embedded` response property.
|
||||||
|
*
|
||||||
|
* e.g;
|
||||||
|
* [
|
||||||
|
* [
|
||||||
|
* 'rel' => 'acf:post',
|
||||||
|
* 'href' => 'https://example.com/wp-json/wp/v2/posts/497',
|
||||||
|
* 'embeddable' => true,
|
||||||
|
* ],
|
||||||
|
* [
|
||||||
|
* 'rel' => 'acf:user',
|
||||||
|
* 'href' => 'https://example.com/wp-json/wp/v2/users/2',
|
||||||
|
* 'embeddable' => true,
|
||||||
|
* ],
|
||||||
|
* ]
|
||||||
|
*
|
||||||
|
* @param mixed $value The raw (unformatted) field value.
|
||||||
|
* @param string|int $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_rest_links( $value, $post_id, array $field ) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply basic formatting to prepare the value for default REST output.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string|int $post_id
|
||||||
|
* @param array $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function format_value_for_rest( $value, $post_id, array $field ) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
endif; // class_exists check
|
endif; // class_exists check
|
||||||
|
|
|
||||||
|
|
@ -345,7 +345,9 @@ if ( ! class_exists( 'acf_form_nav_menu' ) ) :
|
||||||
(function($) {
|
(function($) {
|
||||||
|
|
||||||
// append html
|
// append html
|
||||||
$('#post-body-content').append( $('#tmpl-acf-menu-settings').html() );
|
var html = $('#tmpl-acf-menu-settings').html();
|
||||||
|
$('#tmpl-acf-menu-settings').remove();
|
||||||
|
$('#post-body-content').append( html );
|
||||||
|
|
||||||
|
|
||||||
// avoid WP over-writing $_POST data
|
// avoid WP over-writing $_POST data
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,10 @@ if ( ! class_exists( 'ACF_Location_User_Form' ) ) :
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function match( $rule, $screen, $field_group ) {
|
public function match( $rule, $screen, $field_group ) {
|
||||||
|
// REST API has no forms, so we should always allow it.
|
||||||
|
if ( ! empty( $screen['rest'] ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Check screen args.
|
// Check screen args.
|
||||||
if ( isset( $screen['user_form'] ) ) {
|
if ( isset( $screen['user_form'] ) ) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
acf_include( 'includes/rest-api/acf-rest-api-functions.php' );
|
||||||
|
acf_include( 'includes/rest-api/class-acf-rest-api.php' );
|
||||||
|
acf_include( 'includes/rest-api/class-acf-rest-embed-links.php' );
|
||||||
|
acf_include( 'includes/rest-api/class-acf-rest-request.php' );
|
||||||
|
|
||||||
|
// Initialize.
|
||||||
|
acf_new_instance( 'ACF_Rest_Api' );
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue