Skip to content

Commit 2f377f7

Browse files
committed
gw-require-alt-text-description-post-image.php: Added snippet for requiring Alt Text and Description in Post Image Field.
1 parent 0390f25 commit 2f377f7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Gravity Wiz // Gravity Forms // Required Alt Text & Description for Post Image Field
4+
* https://gravitywiz.com/
5+
*
6+
* Ensures the Alt Text and Description for the Post Image field are required if the field is marked as required.
7+
*
8+
* Instruction Video: https://www.loom.com/share/6d0e70da14c64f5ea40d0aa0f918684d
9+
*
10+
* Plugin Name: Gravity Forms - Required Alt Text & Description for Post Image Field
11+
* Plugin URI: https://gravitywiz.com/
12+
* Description: Ensures the Alt Text and Description for the Post Image field are required if the field is marked as required.
13+
* Author: Gravity Wiz
14+
* Version: 1.0
15+
* Author URI: https://gravitywiz.com/
16+
*/
17+
add_filter( 'gform_field_validation', function ( $result, $value, $form, $field ) {
18+
if ( $field->type == 'post_image' && $field->displayAlt && $field->displayDescription && $field->wasRequired ) {
19+
20+
$alt_text = $value[ $field->id . '.2' ];
21+
$description = $value[ $field->id . '.7' ];
22+
23+
if ( ! $alt_text && ! $description ) {
24+
$result['is_valid'] = false;
25+
$result['message'] = 'Check Post Image. Please enter Alt Text and Description.';
26+
} elseif ( ! $alt_text ) {
27+
$result['is_valid'] = false;
28+
$result['message'] = 'Check Post Image. Please enter Alt Text.';
29+
} elseif ( ! $description ) {
30+
$result['is_valid'] = false;
31+
$result['message'] = 'Check Post Image. Please enter Description.';
32+
}
33+
34+
}
35+
return $result;
36+
}, 10, 4 );

0 commit comments

Comments
 (0)