From 2ba6e3e3074792169ee08c4eebb97d8696bf0f24 Mon Sep 17 00:00:00 2001 From: usame-algan Date: Sun, 28 Jun 2020 23:09:28 +0200 Subject: [PATCH] displays questions from zoom, cleanup --- README.md | 1 + admin/class-cf7-zwr-admin.php | 37 ++++++++++++++++++++++++++++------ includes/class-cf7-zwr-api.php | 23 ++++++++++++++++++++- includes/class-cf7-zwr.php | 4 ++-- 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a7581a2..be06498 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/admin/class-cf7-zwr-admin.php b/admin/class-cf7-zwr-admin.php index 0808d05..58b3614 100644 --- a/admin/class-cf7-zwr-admin.php +++ b/admin/class-cf7-zwr-admin.php @@ -61,24 +61,49 @@ public function display_api_secret_field() { '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); ?>
- +
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) { ?> +

+ + + + + + + + + + + + + + + +
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") { @@ -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; + } + } diff --git a/includes/class-cf7-zwr.php b/includes/class-cf7-zwr.php index e9b9636..373414b 100644 --- a/includes/class-cf7-zwr.php +++ b/includes/class-cf7-zwr.php @@ -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() {