Skip Navigation

[Gelöst] Minimum Image size on upload

This support ticket is created vor 7 Jahre, 11 Monate. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Dieses Thema enthält 6 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von paulw-2 vor 7 Jahre, 11 Monate.

Assistiert von: Shane.

Author
Artikel
#407123

Hi there,

We tried to implement the code for having a check for minimum upload size from this post:
https://toolset.com/forums/topic/set-the-minimum-resolution-of-image-upload/

This works fine for our create form but when we want to duplicate the code for the edit form as well it is causing a bug.

How can we use it to have the field 'logo-image' checked in both forms?

Thanks,

Paul

#407205

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Paul,

Thank you for contacting our support forum.

Let me see how best I can assist you with this issue.

Could you let me know what exactly the issue is that you are experiencing ?

Also could you let me see the code that you are using for this ?

Thanks,
Shane

#407350

Hi Shane,

We used the code from the topic and adjusted it for our cred form for creating content:
https://toolset.com/forums/topic/set-the-minimum-resolution-of-image-upload/

When i duplicate this code for the cred-form to edit content (i only replaced the form id, the field name is the same in both forms) and place in my functions.php i get a white screen.

The way we placed the code:
Image size CE form - Create

add_filter('cred_form_validate_4483', 'cred_image_resolution_validation',10,2);
function cred_image_resolution_validation( $field_data, $form_data ) {
// Field data are field values and errors
	list( $fields, $errors ) = $field_data;
//Run the rest of code for this CRED ONLY and IF the file is upload type and size are set.
	if ( ( 4483 == $form_data['id'] ) && ( isset( $_FILES['wpcf-ce-logo']['tmp_name'] ) ) ) {
		$check = getimagesize( $_FILES['wpcf-ce-logo']['tmp_name'] );

		if ( $check !== false ) {
			$awidth  = $check[0];
			$aheight = $check[1];
			if ( ($width < 300) && ($height < 300) ) {
				$errors['ce-logo'] = 'Sorry, too small image.';
			}
		} else {
			$errors['ce-logo'] = 'Sorry this is not a valid image file.';
		}
	}

	return array( $fields, $errors );
}
>>

Image size CE form - Edit

add_filter('cred_form_validate_4459', 'cred_image_resolution_validation',10,2);
function cred_image_resolution_validation( $field_data, $form_data ) {
// Field data are field values and errors
	list( $fields, $errors ) = $field_data;
//Run the rest of code for this CRED ONLY and IF the file is upload type and size are set.
	if ( ( 4459 == $form_data['id'] ) && ( isset( $_FILES['wpcf-ce-logo']['tmp_name'] ) ) ) {
		$check = getimagesize( $_FILES["wpcf-ce-logo"]["tmp_name"] );

		if ( $check !== false ) {
			$width  = $check[0];
			$height = $check[1];

			if ( $width < 300 && $height < 300 ) {
				$errors['ce-logo'] = 'Sorry, too small image.';
			}
		} else {
			$errors['ce-logo'] = 'Sorry this is not a valid image file.';
		}
	}

	return array( $fields, $errors );
}
>>

Hope this makes it more clear.
Thanks,

Paul

#407499

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Paul,

Thanks for sharing the code.

However I see that you say you are getting a white screen, in this case I would like for you to enable the wordpress debugging in order for us to see the error reports of what is causing the white screen.
versteckter Link

Once you have done this please let me know the error that is being displayed.

Thanks,
Shane

#407512

Error code:
Fatal error: Cannot redeclare cred_image_resolution_validation() (previously declared in /var/www/vhosts/creativematter.nl/httpdocs/projects/c2m/wp-content/themes/dt-the73/functions.php:61) in /var/www/vhosts/creativematter.nl/httpdocs/projects/c2m/wp-content/themes/dt-the73/functions.php on line 97

functions.php:

 
/**
 * Vogue theme.
 *
 * @since 1.0.0
 */

// File Security Check
if ( ! defined( 'ABSPATH' ) ) { exit; }

/**
 * Set the content width based on the theme's design and stylesheet.
 *
 * @since 1.0.0
 */
if ( ! isset( $content_width ) ) {
	$content_width = 1200; /* pixels */
}

/**
 * Initialize theme.
 *
 * @since 1.0.0
 */
require( trailingslashit( get_template_directory() ) . 'inc/init.php' );



/*** MODS WP_CRED_DELETE BUTTON_REFRESH ***/
add_filter('cred_success_redirect_4918', 'redirect_to_parent_func', 10, 3);
add_filter('cred_success_redirect_5825', 'redirect_to_parent_func', 10, 3);
function redirect_to_parent_func($url, $post_id, $form_data) {
	$parent_id = get_post_meta( $post_id, '_wpcf_belongs_profielen_id', true);
	$url = get_permalink( $parent_id ) . '?cred-edit-form=6013';
	return $url;
}


/*** MODS WP_VIEWS_FILTER_USER_MIJN_GEGEVENS ***/
function get_wp_user_role() {
global $current_user;

$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);

return $user_role;
}
add_shortcode('wpv-post-get-wp-user-role', 'get_wp_user_role');


add_action('init', 'add_mapped_shortcodes_on_init');
function add_mapped_shortcodes_on_init() {
  WPBMap::addAllMappedShortcodes();
}


/*** Min size ce logo ***/
add_filter('cred_form_validate_4844', 'cred_image_resolution_validation',10,2);


function cred_image_resolution_validation($field_data, $form_data)
{
// Field data are field values and errors
list($fields,$errors)=$field_data;

//Run the rest of code for this CRED ONLY and IF the file is upload type and size are set.
if (( 4844 == $form_data['id']) && (isset($_FILES['wpcf-ce-logo']['tmp_name']))) {

$check = getimagesize($_FILES["wpcf-ce-logo"]["tmp_name"]);

if($check !== false) {
$width = $check[0];
$height = $check[1];

if($width < 336 && $height < 280) { $errors['Logo'] = 'Deze afbeelding is te klein! Gebruik minimaal de aangegeven maat: 336x280px. (Een afbeelding met andere verhoudingen wordt bijgesneden)'; } } else { $errors['ce-logo'] = 'Sorry this is not a valid image file.'; } }return array($fields,$errors); }



/*** Min size ce logo - edit ***/
add_filter('cred_form_validate_5794', 'cred_image_resolution_validation',10,2);


function cred_image_resolution_validation($field_data, $form_data)
{
// Field data are field values and errors
list($fields,$errors)=$field_data;

//Run the rest of code for this CRED ONLY and IF the file is upload type and size are set.
if (( 5794 == $form_data['id']) && (isset($_FILES['wpcf-ce-logo']['tmp_name']))) {

$check = getimagesize($_FILES["wpcf-ce-logo"]["tmp_name"]);

if($check !== false) {
$width = $check[0];
$height = $check[1];

if($width < 336 && $height < 280) { $errors['Logo'] = 'Deze afbeelding is te klein! Gebruik minimaal de aangegeven maat: 336x280px. (Een afbeelding met andere verhoudingen wordt bijgesneden)'; } } else { $errors['ce-logo'] = 'Sorry this is not a valid image file.'; } }return array($fields,$errors); }
>>>>
#407516

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Paul,

So the issue is being caused by a duplicate function name.

To fix this all you need to do is change the function name of one of the functions so it can be unique.

/*** Image size CE form - Edit ***/
add_filter('cred_form_validate_4459', 'cred_image_resolution_validation2',10,2);
function cred_image_resolution_validation2($field_data, $form_data)
{
// Field data are field values and errors
list($fields,$errors)=$field_data;
//Run the rest of code for this CRED ONLY and IF the file is upload type and size are set.
if (( 4459 == $form_data['id']) && (isset($_FILES['wpcf-ce-logo']['tmp_name']))) {
$check = getimagesize($_FILES["wpcf-ce-logo"]["tmp_name"]);

if($check !== false) {
$width = $check[0];
$height = $check[1];

if($width < 300 && $height < 300) { $errors['ce-logo'] = 'Sorry, too small image.'; } } else { $errors['ce-logo'] = 'Sorry this is not a valid image file.'; } }return array($fields,$errors); }

/*** END ***/


>>

Please try the code above and it should work.

Thanks,
Shane

#407518

Hi Shane,

Perfect, thank you!!!

Paul

Dieses Ticket ist jetzt geschlossen. Wenn Sie ein Toolset Kunde sind und Hilfe benötigen, eröffnen Sie bitte ein neues Support-Ticket.