Skip to content

Commit

Permalink
Added compatibility with Contact Form 7 v6.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Nov 3, 2024
1 parent 14b1004 commit 8d9d0c3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 54 deletions.
2 changes: 2 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

<!-- What to scan -->
<file>.</file>
<!-- Exclude all dirs except needed -->
<exclude-pattern>^(?!.*/hcaptcha-wordpress-plugin).*</exclude-pattern>
<exclude-pattern>*/\.codeception/*</exclude-pattern>
<exclude-pattern>*/\.github/*</exclude-pattern>
<exclude-pattern>*/\.php-scoper/vendor/*</exclude-pattern>
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ Instructions for popular native integrations are below:

= 4.7.0 =
* Added compatibility with WordPress Recovery Mode.
* Added compatibility with Contact Form 7 v6.0.
* Added compatibility with Akismet tag in Contact Form 7.
* Added activation and deactivation of plugins network wide if hCaptcha is set network wide.
* Added ability to use shortcode in the Mailchimp for WP form.
Expand Down
90 changes: 36 additions & 54 deletions src/php/CF7/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use HCaptcha\Helpers\Pages;
use WPCF7_TagGenerator;
use WPCF7_TagGeneratorGenerator;

/**
* Class Admin.
Expand Down Expand Up @@ -159,76 +160,57 @@ public function add_tag_generator_hcaptcha(): void {
$tag_generator->add(
'cf7-hcaptcha',
__( 'hCaptcha', 'hcaptcha-for-forms-and-more' ),
[ $this, 'tag_generator_hcaptcha' ]
[ $this, 'tag_generator_hcaptcha' ],
[ 'version' => '2' ]
);
}

/**
* Show tag generator.
*
* @param mixed $contact_form Contact form.
* @param array|string $args Arguments.
* @param array|string $options Options.
*
* @return void
* @noinspection PhpUnusedParameterInspection
*/
public function tag_generator_hcaptcha( $contact_form, $args = '' ): void {
$args = wp_parse_args( $args );
$type = $args['id'];
$description = __( 'Generate a form-tag for a hCaptcha field.', 'hcaptcha-for-forms-and-more' );
public function tag_generator_hcaptcha( $contact_form, $options = '' ): void {
$field = [
'display_name' => __( 'hCaptcha field', 'hcaptcha-for-forms-and-more' ),
'heading' => __( 'hCaptcha field form-tag generator', 'hcaptcha-for-forms-and-more' ),
'description' => __( 'Generate a form-tag for a hCaptcha field.', 'hcaptcha-for-forms-and-more' ),
];

$tgg = new WPCF7_TagGeneratorGenerator( $options['content'] );

?>
<header class="description-box">
<h3><?php echo esc_html( $field['heading'] ); ?></h3>
<p><?php echo esc_html( $field['description'] ); ?></p>
</header>

<div class="control-box">
<fieldset>
<legend><?php echo esc_html( $description ); ?></legend>

<table class="form-table">
<tbody>

<tr>
<th scope="row">
<label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>">
<?php echo esc_html( __( 'Id attribute', 'hcaptcha-for-forms-and-more' ) ); ?>
</label>
</th>
<td>
<input
type="text" name="id" class="idvalue oneline option"
id="<?php echo esc_attr( $args['content'] . '-id' ); ?>"/>
</td>
</tr>

<tr>
<th scope="row">
<label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>">
<?php echo esc_html( __( 'Class attribute', 'hcaptcha-for-forms-and-more' ) ); ?>
</label>
</th>
<td>
<input
type="text" name="class" class="classvalue oneline option"
id="<?php echo esc_attr( $args['content'] . '-class' ); ?>"/>
</td>
</tr>

</tbody>
</table>
</fieldset>
<?php
$tgg->print(
'field_type',
[
'with_required' => true,
'select_options' => [
'cf7-hcaptcha' => $field['display_name'],
],
]
);
$tgg->print( 'field_name' );
$tgg->print( 'class_attr' );
?>
</div>

<div class="insert-box">
<label>
<input
type="text" name="<?php echo esc_attr( $type ); ?>" class="tag code" readonly="readonly"
onfocus="this.select()"/>
</label>

<div class="submitbox">
<input
type="button" class="button button-primary insert-tag"
value="<?php echo esc_attr( __( 'Insert Tag', 'hcaptcha-for-forms-and-more' ) ); ?>"/>
</div>
</div>
<footer class="insert-box">
<?php
$tgg->print( 'insert_box_content' );
$tgg->print( 'mail_tag_tip' );
?>
</footer>
<?php
}

Expand Down

0 comments on commit 8d9d0c3

Please sign in to comment.