Hi @wootimes, this function is most appropriate for what you need to do 🙂
It covers all fields without having to specify one by one.
function my_kses_post( $value ) {
// is array
if( is_array($value) ) {
return array_map('my_kses_post', $value);
}
// return
return wp_kses_post( $value );
}
add_filter('acf/update_value', 'my_kses_post', 10, 1);
Thanks, elliot added honeypot validation. I will be available to all in the next release.
I created custom post type ‘RSVP’
it works all right, no problem. The system includes a form via frontend with the function acf_form for confirmation from the guests who will be attending the wedding. Since ACF has captcha default (and I do not really like) I wanted to integrate the technique honeypot to prevent spam as possible. Or add a blank field to my form, and snap the mistake of spam in this case is filled by a bot.
I can block the sending of the form, but also creates an entry in the db with the title and empty fields.
From what I understand, the data that are entered are ignored (in fact, all the fields are empty acf) but I do not want that item is created. Why is spam! I will not fill the db RSVP empty.
I do not think the problem is the theme or plugin, as plugin (except ACF) I have not, and the subject does not create conflicts (the custom made).
I think the error is in the use of as healthy control spam in my functions.php file
My file template for acf_form is this:
acf_form(array(
'post_id' => 'new_post',
'field_groups' => array(
'group_56ab8c95249f9'
),
'new_post' => array(
'post_type' => 'rsvp',
'post_status' => 'pending'
),
'html_after_fields' => '<input class="form-control col-xs-12 guest_user_form" tabindex="-1" type="text" id="guest_user" name="guest_user_rsvp" autocomplete="off">',
'fields' => array(
'field_56ab8cbab11f5',
'field_56ad313d73887',
'field_56ad0de452c1c',
'field_56ad06220e59f',
'field_56ad1215d1217',
'field_56ad2e342039d',
'field_56ad34274f7ee',
'field_56ad34a34f7f0',
'field_56ad34ce4f7f1'
),
'return' => '#rsvp_success',
'field_el' => 'div',
'uploader' => 'basic',
'submit_value' => __('SUBMIT','italian-wedding-day'),
));
my functions.php
// CHECK PRE SAVE POST ACF
function honeypot( $post_id ) {
if(!empty($_POST['guest_user_rsvp'])){
die("You spammer!");
}
}
add_filter('acf/pre_save_post' , 'honeypot', 10, 1 );
or tried to use even the action pre_save but my proble persists
// CHECK PRE SAVE POST ACF
function honeypot( $post_id ) {
if(!empty($_POST['guest_user_rsvp'])){
die("You spammer!");
}
}
add_action('acf/save_post' , 'honeypot', 1 );
Hi @tsmulugeta in acf_form add this arguments line:
'html_after_fields' => '<input type="text" id="honeypot" name="honeypot" autocomplete="off">',
in file functions.php, this code:
// CHECK PRE SAVE POST ACF
function honeypot( $post_id ) {
if($_POST['honeypot'] != ''){
die("You spammer!");
}
}
add_filter('acf/pre_save_post' , 'honeypot', 10, 1 );
in your css style:
#honeypot {display:none;}
Thank you very much @hube2
Thank you @hube2, last question.Since I often use combinations combined with fields acf which often are repeated in various parts of the template (such as the name of the couple, and if this alternative is shown as an example), what do you think the use of functions like this?
function my_function(){
$biography_groom = get_field('field','option');
if(!empty($biography_groom)){
echo $biography_groom;
} else {
_e('Here to tell a brief description of the bride. You can put whatever you like, even your intentions towards the groom.','italian-wedding-day');
}
}
No matter the fields you have, are equally sanitized and hassle. The function that Elliot updated serves precisely to both types of fields: normal and repeatable. 🙂
http://www.advancedcustomfields.com/resources/acf_form/#security
If your form provides repeatable fields, add this in your functions.php
https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-form-kses.php
and replace default filter from:
add_filter('acf/update_value', 'wp_kses_post', 10, 1);
to:
add_filter('acf/update_value', 'acf_wp_kses_post', 10, 1);
Elliot now allows sanitization of the code by adding this filter. I tested it and it works great. This should remove a lot of headaches at all 🙂
http://www.advancedcustomfields.com/resources/acf_form/#security
You’re right, I was wrong. I thank you for the great help
Ok, I have find a solution 😀
This is the code (file functions.php theme master) that you must use if you want to include in a theme acf and expect the opportunity to create a child theme:
/*ACF*/
// 1. customize ACF path
add_filter('acf/settings/path', 'my_acf_settings_path');
function my_acf_settings_path( $path ) {
$path = get_template_directory() . '/acf/';
return $path;
}
// 2. customize ACF dir
add_filter('acf/settings/dir', 'my_acf_settings_dir');
function my_acf_settings_dir( $dir ) {
$dir = get_template_directory_uri() . '/acf/';
return $dir;
}
// 3. Hide ACF field group menu item
if ( ! has_filter( 'acf/settings/show_admin' ) ) {
add_filter('acf/settings/show_admin', '__return_false');
}
// 4. Include ACF
include_once( get_template_directory() . '/acf/acf.php' );
If you want to show the Options menu ACF in child theme, use the following filter (file functions.php theme child):
add_filter('acf/settings/show_admin', '__return_true');
I hope this can be helpful as it was for me 🙂
Unfortunately not, the options pages are managed and saved all together. If I for example I have 4 options pages, these pages will be saved and analyzed simultaneously.
Are there some people able to help me?
Can I have your contact email? I have some questions I would like to ask you about ACF, of course paying the disturbance. Is available?
thank you very much 🙂
sorry for my answer, but this:
delete_transient('advert_main_transient1');
delete_transient('advert_main_transient2');
delete_transient('advert_main_transient3');
What call?
I have a many option page. For example i have the:
Product Page
Service Page
Theme Option Page
With many fields. Is possible applicate your code in my specific case?
solved my problem!
#map_canvas img {
max-width: none!important;
}
Thank you very much 🙂
sorry, now working perfect. My Error 🙂
Yes, this is a bug in version 5.1.3.
I exported my fields in a php file and conditional logic no longer work. Please let us know news. thanks Elliot
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.