Skip to content

Commit

Permalink
Merge pull request #7 from usame-algan/3-register-optionally
Browse files Browse the repository at this point in the history
3 register optionally
  • Loading branch information
usame-algan authored Oct 18, 2020
2 parents a15d530 + 2865a88 commit 81c0d0b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ Allow registrations for your Zoom Webinar through Wordpress Contact Form 7
2. The plugin looks for field names prefixed with `cf7zwr-`. The rest of the field name should be according to the [Zoom API reference](https://marketplace.zoom.us/docs/api-reference/zoom-api/webinars/webinarregistrantcreate). For example if you want to save the first name of a registrant the field should be named `cf7zwr-first_name`
3. The webinar ID can be saved within the form settings inside the `Zoom` panel

## Additional Settings

To register users optionally add a checkbox element named `cf7zwr-confirm` to your form e.g.
`[checkbox cf7zwr-confirm "Register for this webinar"]`

## License

This plugin is licensed under the GPL v3. See `license.txt` for more information.
Expand All @@ -32,6 +37,10 @@ If you find any Bugs please feel free to [open an issue here](https://github.com

## Changelog

#### [1.0.6] - 2020-10-18
- Skips Zoom API Call if there is no webinar id present
- Checks for a field `cf7zwr-confirm` to register users optionally

#### [1.0.5] - 2020-08-07
- Fixes a bug that caused guessed fields to overwrite prefixed fields

Expand Down
4 changes: 2 additions & 2 deletions cf7-zoom-webinar-registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: CF7 Zoom Webinar registration
Plugin URI: https://github.com/usame-algan/cf7-zoom-webinar-registration
Description: Allow registrations for your Zoom Webinar through Wordpress Contact Form 7
Version: 1.0.5
Version: 1.0.6
Author: Usame Algan
Author URI: https://usamealgan.com
Text Domain: cf7-zwr
Expand All @@ -17,7 +17,7 @@
* Plugin constants
*/
if (!defined('CF7_ZWR_VERSION')) {
define('CF7_ZWR_VERSION', '1.0.5' );
define('CF7_ZWR_VERSION', '1.0.6' );
}

if (!defined('CF7_ZWR_PATH')) {
Expand Down
9 changes: 8 additions & 1 deletion includes/class-cf7-zwr-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,17 @@ public function send_registration($contactform, &$abort, $submission) {
$posted_data = $submission->get_posted_data();
$webinar_id = get_post_meta($contactform->id(), 'cf7zwr-webinar_id', true);

if (!$webinar_id) {
return $wpcf;
}

$field_parser = new CF7_ZWR_Field_Finder($posted_data);
$fields = $field_parser->combine(['guessed', 'prefixed']);

if ($webinar_id) {
if (!array_key_exists('cf7zwr-confirm', $posted_data)) {
$this->build($this->api_url . '/webinars/' . $webinar_id . '/registrants', array('body' => wp_json_encode($fields)), 'POST');
$this->run($this->token);
} elseif ($posted_data['cf7zwr-confirm'][0]) {
$this->build($this->api_url . '/webinars/' . $webinar_id . '/registrants', array('body' => wp_json_encode($fields)), 'POST');
$this->run($this->token);
}
Expand Down
4 changes: 2 additions & 2 deletions includes/class-cf7-zwr-field-finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public function prefixed($namespace = 'cf7zwr-') {

foreach($this->fields as $key => $value) {
if(strpos($key, $namespace) === 0) {
$new_key = substr($key, $length);
$fields_with_prefix[$new_key] = $value;
$key_without_prefix = substr($key, $length);
$fields_with_prefix[$key_without_prefix] = $value;
}
}

Expand Down

0 comments on commit 81c0d0b

Please sign in to comment.