Since those custom images fields only exists in post form "Formulário para Editar Anúncio PODE"( ID 1355), so I am using this post form for example, please try these:
1) Create a custom field group with two fields:
enlace oculto
- Date field "last-modify-date", we can use it to store the last image changed date
- Numeric field "count", store the count number
I have done above step in your website, you need to do below steps manually.
2) Edit your theme file "functions.php", add below codes:
// Check images changed
add_action('cred_before_save_data', function($form_data){
if($form_data['id'] == 1355){
$post_id = $_POST['_cred_cred_prefix_post_id'];
$pre_image['wpcf-foto-perfil'] = get_post_meta($post_id, 'wpcf-foto-perfil', true);
$pre_image['wpcf-fotos-para-anuncio'] = get_post_meta($post_id, 'wpcf-fotos-para-anuncio');
$new_image['wpcf-foto-perfil'] = $_POST['wpcf-foto-perfil']?$_POST['wpcf-foto-perfil']:$pre_image['wpcf-foto-perfil'];
$new_image['wpcf-fotos-para-anuncio'] = $_POST['wpcf-fotos-para-anuncio']?$_POST['wpcf-fotos-para-anuncio']:$pre_image['wpcf-fotos-para-anuncio'];
$changed = 0;
if($pre_image != $new_image){
$changed = 1;
}
$_POST['changed'] = $changed;
}
}, 10, 1);
// Update change date and count
add_action('cred_save_data', function($post_id, $form_data){
if($form_data['id'] == 1355){
$changed = isset($_POST['changed'])?$_POST['changed']:0;
if($changed == '1'){
$count = get_post_meta( $post_id, 'wpcf-count', true );
if ( ! $count ) {
$count = 0; // if the meta value isn't set, use 0 as a default
}
$count++;
update_post_meta($post_id, 'wpcf-count', $count );
update_post_meta($post_id, 'wpcf-last-modify-date', current_time( 'timestamp'));
}
}
}, 10, 2);
// Check if user can change images shortcode
add_shortcode('can_change_images', function($atts, $content){
$post_id = isset($_GET['f_editar'])?$_GET['f_editar']:0; // URL parameter f_editar
if($post_id){
$current_month = current_time( 'Y-m');
$last_modify_month = types_render_field('last-modify-date', array('format' => 'Y-m', 'post_id' => $post_id));
$count = types_render_field('count', array('post_id' => $post_id));
$res = 1;
if($count >=2 && $current_month == $last_modify_month){
$res = 0;
}
return $res;
}
});
3) Dashboard-> Toolset-> Settings-> Front-end Content
in option "Third-party shortcode arguments", add above shortcode name: can_change_images
4) Edit post form "Formulário para Editar Anúncio PODE":
enlace oculto
in section "Form editor", line 121 ~ 130, wrap those two image field with below shortcodes, like this:
[wpv-conditional if="( '[can_change_images]' eq '1' )"]<div class="row">
<div class="form-group col-sm-6 profile-photo">
<label>Imagem de Perfil (de capa, de rosto, tamanho max de 1MB) Melhor foto é de 300 x 300</label>
[cred_field field="foto-perfil" force_type="field" class="form-control" output="bootstrap"]
</div>
<div class="form-group col-sm-6 limit-to-6 reptive-photos">
<label>Fotos para Anúncio (Max de 3 fotos sozinhas(os) e Max de 3 fotos fazendo massagem,tamanho max de 1MB)</label>
[cred_field field='fotos-para-anuncio' force_type='field' class='form-control limit-to-6' output='bootstrap']
</div>
</div>[/wpv-conditional]
And test again
More help:
https://toolset.com/documentation/programmer-reference/cred-api/