I am trying to: only 1 code - migrate code from functions.php to toolset inbuilt settings. Also the code does not seem to work anyways.
The code is this
<?php
/*
* Add your own functions here. You can also copy some of the theme functions into this file.
* WordPress will use those functions instead of the original functions then.
*/
/*
* NOT WORKING - ANY PERSON CAN UPLOAD IMAGE OF ANY DIMENTIONS
*/
add_filter('cred_form_ajax_upload_validate','my_validation',10,2);
function my_validation($error_fields, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$error_fields;
//validate if specific form
if ($form_data['id']==434)
{
//check if featured image exists o
if (isset($fields['wpcf-imagez']))
{
list($width, $height, $type, $attr) = getimagesize($fields['wpcf-imagez']['field_data']['tmp_name']);
if ($width != 200 && $height != 280) {
//set error message for featured image
$errors['Image-size-error'] = 'Image size must be 280 (height) * 200 (width), your image dimensions are '.$height.' * '.$width;
}
}
}
//return result
return array($fields,$errors);
}
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==434)
{
if (!isset($_POST['wpcf-imagez']))//Change "my_custom_field" to your wpcf-field
{
// since $_POST['my_custom_field'] is not set (!isset())
update_post_meta($post_id, 'wpcf-imagez', 'hidden link');
}
}
}
/*
* I THINK THE FOLLOWING HAS ALREADY BEEN ADDED
*/
add_action( 'before_delete_post', 'count_total_children_delete' );
function count_total_children_delete($post_id)
{
if ( get_post_type( $post_id ) == 'lawyer-review' ) {
$parent_id = get_post_meta( $post_id, '_wpcf_belongs_lawyer_id', true );
if($parent_id != '')
{
$childargs = array(
'post_type' => 'lawyer-review',
'numberposts' => -1,
'meta_key' => '_wpcf_belongs_lawyer_id',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(array('key' => '_wpcf_belongs_lawyer_id', 'value' => $parent_id))
);
$totalChildCount = count(get_posts($childargs));
update_post_meta( $parent_id, 'wpcf-child-count', $totalChildCount);
}
}
}
add_action( 'save_post', 'count_total_children',20,2);
function count_total_children($post_id){
if ( get_post_type( $post_id ) == 'lawyer' ) {
$count=get_post_meta( $post_id, 'wpcf-child-count', true );
if($count == ''){
add_post_meta($post_id, 'wpcf-child-count',0);
}
}
if ( get_post_type( $post_id ) == 'lawyer-review' ) {
$parent_id = get_post_meta( $post_id, '_wpcf_belongs_lawyer_id', true );
if($parent_id != '')
{
$childargs = array(
'post_type' => 'lawyer-review',
'numberposts' => -1,
'meta_key' => '_wpcf_belongs_lawyer_id',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(array('key' => '_wpcf_belongs_lawyer_id', 'value' => $parent_id))
);
$totalChildCount = count(get_posts($childargs));
if( $totalChildCount != $oldChildCount ){
update_post_meta( $parent_id, 'wpcf-child-count', $totalChildCount );
}
}
}
}