Skip to content

Commit

Permalink
displays questions from zoom, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan committed Jun 28, 2020
1 parent 3b0ac86 commit 2ba6e3e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ If you find any Bugs please feel free to [open an issue here](https://github.com

#### [1.0.2] - 2020-06-28
- Added custom field for the webinar id
- Now displays selected questions from Zoom once the webinar id has been set

## Credits

Expand Down
37 changes: 31 additions & 6 deletions admin/class-cf7-zwr-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,49 @@ public function display_api_secret_field() {
<input type="password" value="<?php echo esc_attr($settings['api_secret']); ?>" name="cf7_zwr[api_secret]" /><?php
}

public function initialize_cf7zwr_settings($panels) {
public function initialize_settings_panel($panels) {
$panels['cf7zwr-custom-fields'] = array(
'title' => 'Zoom',
'callback' => array($this, 'cf7zwr_custom_fields'),
'callback' => array($this, 'display_custom_fields'),
);

return $panels;
}

public function cf7zwr_custom_fields($contactform) {
$value = get_post_meta($contactform->id(), 'cf7zwr-webinar_id', true); ?>
public function display_custom_fields($contactform) {
$webinar_id = get_post_meta($contactform->id(), 'cf7zwr-webinar_id', true); ?>
<fieldset>
<label for="wpcf7-custom-field"><?php _e('Webinar-ID', 'cf7-zwr'); ?></label>
<input type="text" id="wpcf7-custom-field" name="cf7_zwr_webinar_id" value="<?php echo $value ?>" />
<input type="text" id="wpcf7-custom-field" name="cf7_zwr_webinar_id" value="<?php echo $webinar_id ?>" />
</fieldset><?php
$api = new CF7_ZWR_Api($this->plugin_name, $this->version);
if ($webinar_id) {
$webinar_fields = $api->get_webinar_questions($webinar_id);
$this->display_webinar_questions($webinar_fields);
}
}

public function display_webinar_questions($webinar_fields) { ?>
<p><?php _e('Fields found for this webinar', 'cf7-zwr'); ?></p>
<table class="widefat striped">
<thead>
<tr>
<td><?php _e('Field name', 'cf7-zwr'); ?></td>
<td><?php _e('Required', 'cf7-zwr'); ?></td>
</tr>
</thead>
<tbody>
<?php foreach($webinar_fields as $field) : ?>
<tr>
<td><?php echo $field['field_name']; ?></td>
<td><?php echo $field['required'] ? "true" : "false" ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table><?php
}

public function save_cf7zwr_custom_fields($contactform) {
public function save_custom_fields($contactform) {
if (array_key_exists('cf7_zwr_webinar_id', $_POST)) {
$webinarId = str_replace(" ", "", $_POST['cf7_zwr_webinar_id']);
update_post_meta(
Expand Down
23 changes: 22 additions & 1 deletion includes/class-cf7-zwr-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class CF7_ZWR_Api {
private $version;

protected $api_url = 'https://api.zoom.us/v2';
protected $webinar_identifier = 'webinar_id:';
protected $required_questions;

protected $token = '';
protected $method;
protected $url;
Expand All @@ -28,6 +29,17 @@ class CF7_ZWR_Api {
public function __construct($plugin_name, $version) {
$this->plugin_name = $plugin_name;
$this->version = $version;

$this->required_questions = array(
array(
"field_name" => "first_name",
"required" => true
),
array(
"field_name" => "email",
"required" => true
),
);
}

public function build($url, $arguments = array(), $method = "GET") {
Expand Down Expand Up @@ -76,4 +88,13 @@ public function send_registration($contactform, &$abort, $submission) {
return $wpcf;
}

public function get_webinar_questions($webinar_id) {
$this->build($this->api_url . '/webinars/' . $webinar_id . '/registrants/questions', array(), 'GET');
$this->run($this->token);

$combined_questions = array_merge($this->required_questions, json_decode($this->body, true)["questions"]);

return $combined_questions;
}

}
4 changes: 2 additions & 2 deletions includes/class-cf7-zwr.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ private function define_admin_hooks() {

$this->loader->add_action( 'admin_menu', $cf7_zwr_admin, 'add_setting_page' );
$this->loader->add_action( 'admin_init', $cf7_zwr_admin, 'initialize_settings' );
$this->loader->add_action( 'wpcf7_save_contact_form', $cf7_zwr_admin, 'save_cf7zwr_custom_fields');
$this->loader->add_filter( 'wpcf7_editor_panels', $cf7_zwr_admin, 'initialize_cf7zwr_settings');
$this->loader->add_action( 'wpcf7_save_contact_form', $cf7_zwr_admin, 'save_custom_fields');
$this->loader->add_filter( 'wpcf7_editor_panels', $cf7_zwr_admin, 'initialize_settings_panel');
}

private function define_public_hooks() {
Expand Down

0 comments on commit 2ba6e3e

Please sign in to comment.