Skip to content

Commit

Permalink
adds the max_replacements count
Browse files Browse the repository at this point in the history
  • Loading branch information
erikyo committed Nov 17, 2022
1 parent 52fe8df commit 92b297a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions includes/cf7a-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function cf7a_honeypot_add( $form_elements ) {
$html = new DOMDocument( '1.0', 'UTF-8' );
libxml_use_internal_errors( true );
// mb_convert_encoding is needed for non-latin font sets / LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD avoids auto-fixes for corrupted html code
$html->loadHTML( mb_convert_encoding($form_elements, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
$html->loadHTML( mb_convert_encoding( $form_elements, 'HTML-ENTITIES', 'UTF-8' ), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
$xpath = new DOMXpath( $html );
$inputs = $xpath->query( '//input' );

Expand All @@ -74,6 +74,16 @@ public function cf7a_honeypot_add( $form_elements ) {
$options = get_option( 'cf7a_options', array() );
$input_names = get_honeypot_input_names( $options['honeypot_input_names'] );
$input_class = sanitize_html_class( $this->options['cf7a_customizations_class'] );
/**
* Controls the maximum number of honeypots.
*
* @example add_filter( 'cf7a_additional_max_honeypots', function() {return 42});
*
* @returns int $max_replacements - replacement count number
*
* @since 0.4.3
*/
$max_replacements = intval( apply_filters( 'cf7a_additional_max_honeypots', 5 ) );

/* get the inputs data */
if ( $inputs && $inputs->length > 0 ) {
Expand Down Expand Up @@ -102,7 +112,7 @@ public function cf7a_honeypot_add( $form_elements ) {
/* duplicate the inputs into honeypots */
$parent->insertBefore( $clone, $sibling );

if ( $i > 0 ) {
if ( $i > $max_replacements ) {
return $html->saveHTML();
}
}
Expand Down

0 comments on commit 92b297a

Please sign in to comment.