Just to clarify. For options page acf/save_post
works as follows:
function my_acf_save_post($post_id) {
var_dump($post_id); // returns: 'options'
var_dump($screen->base); // returns: '[parent-slug]_page_[your-menu-slug]'
exit();
}
add_action('acf/save_post', 'my_acf_save_post', 20);
I see there is no way of customizing existing fields settings, so I made up my own solution which is based on the instructions
content. Here is the code (in case anyone is interested), what it does is limiting a maximum number of words in WYSIWYG field:
// Check if number of words in WYSIWYG is less than max number
// provided inside field instructions. Supported instructions format is (see the regex):
// Max. 300 words
// max 300 words
// max.300 words
add_filter('acf/validate_value/type=wysiwyg', function ( $valid, $value, $field, $input ){
if( !$valid ) {
return $valid;
}
$matches = [];
preg_match('/max[^\d]*(\d+) word/i', $field['instructions'], $matches);
if ( empty( $matches ) || empty( $matches[1] ) ) {
return $valid;
}
$max_words = (int) $matches[1];
// check words number
$words_number = str_word_count( strip_tags( $value ) );
if ( $words_number > $max_words ) {
$valid = "Text is too long ( ${words_number} words ). Max number of words is ${max_words}.";
}
// return
return $valid;
}, 10, 4);
Details about the cause of this (similar) “issue:” https://support.advancedcustomfields.com/forums/topic/acf-repeater-database-query/#post-45116
I’ve managed to “solve” this issue.
The most probable cause is using revisions in the content type which uses repeater field (it was the cause in my case).
The easiest workaround is to remove support for revisions and remove all revisions. Less naive approach is modifying SQL query and eliminate revisions (it should be mentioned in the official guide https://www.advancedcustomfields.com/resources/querying-the-database-for-repeater-sub-field-values/).
Here is how it should be handled, see 4th example on this page: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/
I’ve found a solution a few minutes after posting this question.
In case anyone is also looking for that:
1. create wp-content/languages/plugins/
directory
2. copy selected ACF translation file (.po and .mo) from ACF plugin lang/
folder to created wp-content/languages/plugins/
3. customize the translation with e.g. Poedit or any other program for editing .po files and then generate .mo
This way your translation will be preserved even after plugin update.
For current ACF version (5.4.2) the title customization may look like this:
function my_acf_load_field( $field ) {
$field['label'] = 'Your custom name';
return $field;
}
add_filter('acf/load_field/name=_post_title', 'my_acf_load_field');
The server is administrated by a dedicated company. They told me about this limit while we were troubleshooting other issue connected with the website. I should probably ask them in the first place.
It turns out that the problem was caused by server limitations (of 32MB). So it’s definitely not related to the ACF.
Sorry for wasting your time.
Thanks. You got it right. I need to investigate this issue further as my localhost based tests (with Chrome Dev Tools which limits available upload speed) shows that even 30 minutes long uploads are successful. I’ll try to remember to post here the solution (if I find it).
Anyway, some JS based file upload with progress bar would be a nice field to have, but I didn’t find one either.
Thanks for your assistance but smaller files e.g. 10MB are transferred without any problems so PHP timeout seems to me very reasonable e.g. http://stackoverflow.com/questions/16102809/how-to-upload-large-files-above-500mb-in-php
I was wondering if there is some kind of file upload field which will use chunked upload plugin e.g. plupload (http://www.plupload.com/)?
Thanks. I see this change now but I have no idea how it’s supposed to solve this problem. decode
method still removes all HTML tags by using text()
function.
Thanks for your assistance, but still without monkeypath mentioned earlier I’m unable to get images in Select2 for post_object fields.
Is there any way to view your modifications diff? I’m not sure what has been changed so maybe I should adjust my code somehow.
Thanks. It would be nice to have an option to define which tags are allowed to avoid such problems in the future.
My current solution is to monkey patch the acf.select2
object with the following code:
// Enable markup in ACF options
acf.select2.decode_data = function( data ) {
// bail ealry if no data
if( !data ) return [];
//loop
$.each(data, function(k, v){
// text
data[ k ].text = v.text; // HERE IS THE CHANGE
// children
if( typeof v.children !== 'undefined' ) {
data[ k ].children = acf.select2.decode_data(v.children);
}
});
// return
return data;
};
But I think that there should be some filter for the decode_data
as my solution is not (and can’t be) future proof.
I’ve investigated this further and find out that images are in place in the Ajax response which is returned after clicking on the Select2 control. So it’s probably something with the select2 itself.
EDIT:
The root of this problem is ACF Javascript decode_data
function (inside acf-input.js
file). It usesacf.decode()
which strips all the markup with.text()
function.
No images has to be filtered before by some code. Either ACF or Select2 I’m not sure.
The plugin Location “Nav Menu” For ACF mentioned by @tdmalone seems to be working perfectly. Frontend PHP “documentation” is in the FAQ tab on the plugin page.
Thanks for your solution. For ACF PRO v5.3.2.2 it should be:
;(function($){
var myFieldName = 'my-field';
$(document).ready(function () {
$(document)
.find('[data-type="'+ myFieldName +'"]')
.data('type', 'radio'); // here is the change
});
})(jQuery);
You may check WP filter wp_handle_upload_prefilter
it seems to be what were you looking for. See https://developer.wordpress.org/reference/hooks/wp_handle_upload_prefilter/. As an example of usage you may check this plugin https://wordpress.org/plugins/clean-image-filenames/ which cleans uploaded files names.
I was having the same issue, but the solution was simple. Add acf_form_header()
before any other wp_head related content. Example:
function yourfunction_add_acf_header() {
acf_form_head();
}
add_action( 'wp_head', 'yourfunction_add_acf_header', 0 );
Disabling toggle option of metaboxes is rather WordPress related question than ACF. I’ve just created a script that handles that issue, see http://wordpress.stackexchange.com/questions/31941/disable-collapse-of-admin-meta-boxes/230410#answer-230410 it should be helpful.
Looks similar to https://support.advancedcustomfields.com/forums/topic/conditional-logic-across-field-groups/ see my answer below this topic it should help.
Hi,
I come across same issue as @highkat. I found http://www.elliotcondon.com/conditional-logic-for-advanced-custom-fields/ really helpful. In order to make it work with most recent version of ACF you’ll have to use acf/input/admin_footer
hook instead of acf_head-input
described in the article and use acf.add_action('ready', function() {
instead of $(document).on('acf/setup_fields'...
(see: https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/)
I know that this is an old question but I think that it might be useful for someone.
That solves my problem. Thanks.
OK. Thanks. Am I allowed to use HTML inside ‘label’ key?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.