ID)){ return $ret; } $metadata = CF7DoubleOptIn::getInstance()->getParameter($post->ID); foreach ($metadata as $key => $value) { $metadata['doubleoptin[' . $key . ']'] = $value; } if (isset($metadata[$field_id])) { $ret = $metadata[$field_id]; } return $ret; } /** * Add the styles for the form */ public function addStyles($hook) { wp_enqueue_style('f12-avada-doubleoptin-admin-avada', plugins_url('assets/admin-avada-style.css', __FILE__)); wp_enqueue_script('f12-avada-doubleoptin-templateloader', plugins_url('assets/f12-avada-templateloader.js', __FILE__), array('jquery')); wp_localize_script('f12-avada-doubleoptin-templateloader', 'templateloader', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('f12_doi_templateloader'), 'label_placeholder' => __('Please wait while we load the template...', 'double-opt-in') )); } /** * Add the hooks responsible to handle wordpress functions */ public function addHooks() { add_filter('avada_metabox_tabs', array($this, 'addPanel'), 10, 2); add_filter('f12_cf7_doubleoptin_avada_form_panel', array($this, 'render'), 10, 1); add_action('wpcf7_save_contact_form', array($this, 'save'), 10, 3); } /** * Add a custom panel to the contact form 7 options */ public function addPanel(array $panels, $post_type) { global $post; if($post && $post->post_type == 'fusion_form') { if ($post_type == 'default') { $panels['tabs_names']['f12cf7doubleoptin'] = __('Double-Opt-in', 'double-opt-in'); $panels['requested_tabs'][] = 'f12cf7doubleoptin'; } } return $panels; } /** * On Contact Form save store the information in the database * * @param \WPCF7_ContactForm $contact_form * @param $args * @param $context */ public function save($postID) { if(!class_exists('\Fusion_Data_PostMeta')){ return; } if (!isset($_POST[\Fusion_Data_PostMeta::ROOT]) || !isset($_POST[\Fusion_Data_PostMeta::ROOT]['doubleoptin'])) { // phpcs:ignore WordPress.Security.NonceVerification return; } $parameter = CF7DoubleOptIn::getInstance()->sanitize_array($_POST[\Fusion_Data_PostMeta::ROOT]['doubleoptin']); $parameter = array_merge($parameter, CF7DoubleOptIn::getInstance()->sanitize_array($_POST[\Fusion_Data_PostMeta::ROOT]['_doubleoptin'])); // load the default parameter $metadata = CF7DoubleOptIn::getInstance()->getParameter($postID); // validated all parameter defined in the default parameter options and sanitize them. foreach ($metadata as $key => $value) { if (isset($parameter[$key])) { if ($key == 'body') { $metadata[$key] = $parameter[$key]; } else if ($key == 'sender') { $metadata[$key] = $parameter[$key]; } else if ($key == 'page' || $key == 'enable') { $metadata[$key] = (int)$parameter[$key]; } else { $metadata[$key] = sanitize_text_field($parameter[$key]); } } else if ($key == 'enable') { $metadata[$key] = 0; } } $metadata = apply_filters('f12_cf7_doubleoptin_save_form', $metadata); update_post_meta($postID, 'f12-cf7-doubleoptin', $metadata); } /** * @return array */ private function getPages() { $value = array(); $pages = get_pages(); foreach ($pages as $page) { $value[$page->ID] = $page->post_title; } return $value; } /** * @return array */ private function getCategories() { $atts = array( 'perPage' => -1, 'orderBy' => 'name', 'order' => 'ASC' ); $listOfCategories = Category::get_list($atts, $numberOfPages); $value = array( 0 => '---' ); foreach ($listOfCategories as $Category /** @var Category $Category */) { $value[$Category->get_id()] = $Category->get_name(); } return $value; } /** * Show the backend double opt in options * * @param array $tab_data * @return array */ public function render($tab_data) { global $post; $metadata = CF7DoubleOptIn::getInstance()->getParameter($post->ID); $checked = ''; if($metadata['enable'] == 1){ $checked = 'checked="checked"'; } $TemplateList = new HTMLSelect('_fusion[doubleoptin][template]', array( 'blank' => 'blank', 'newsletter_en' => 'newsletter_en', 'newsletter_en_2' => 'newsletter_en_2', 'newsletter_en_3' => 'newsletter_en_3' ), array( 'class' => array('f12-cf7-templateloader'), 'style' => array('display:none;') )); $TemplateList->setOptionSelectedByKey($metadata['template']); $tab_data['f12cf7doubleoptin']['fields'] = [ [ 'id' => 'doubleoptin[enable]', 'label' => __('Enable', 'double-opt-in'), 'value' => [1 => __('Enable', 'double-opt-in')], 'description' => __('Enable this checkox to activate the Double-Opt-In Mail for this formular.', 'double-opt-in').'

', 'default' => 0, 'dependency' => '', 'type' => 'custom' ], [ 'id' => 'doubleoptin[category]', 'label' => __('Category', 'double-opt-in'), 'choices' => $this->getCategories(), 'description' => __('Select the category for the Opt-In.', 'double-opt-in'), 'default' => 0, 'dependency' => '', 'type' => 'select' ], [ 'id' => 'doubleoptin[page]', 'label' => __('Confirmation Page', 'double-opt-in'), 'choices' => $this->getPages(), 'description' => __('Select the page that should be displayed after the user clicks on the confirmation link', 'double-opt-in'), 'default' => 0, 'dependency' => '', 'type' => 'select' ], [ 'id' => 'doubleoptin[recipient]', 'label' => __('To', 'double-opt-in'), 'description' => __('This field defines who will receive the Double-Opt-In mail. Use the "Field Name" defined for the User E-Mail.', 'double-opt-in'), 'default' => '', 'dependency' => '', 'type' => 'text' ], [ 'id' => 'doubleoptin[sender]', 'label' => __('From', 'double-opt-in'), 'choices' => $metadata['sender'], 'description' => __('This field defines who will sent the mail. You can either enter the e-Mail (e.g.: your-email@yourdomain.de) or use a placeholder (e.g.: [_site_admin_email]).', 'double-opt-in'), 'default' => '', 'dependency' => '', 'type' => 'text' ], [ 'id' => 'doubleoptin[subject]', 'label' => __('Subject', 'double-opt-in'), 'choices' => $metadata['subject'], 'description' => __('Enter a custom subject for the Double-Opt-In mail (e.g.: Please confirm your registration).', 'double-opt-in'), 'default' => '', 'dependency' => '', 'type' => 'text' ], [ 'id' => 'doubleoptin[template]', 'label' => __('Template', 'double-opt-in'), 'description' => __('Pick the Template for your double opt in Mail.', 'double-opt-in').'

'.$TemplateList->get(), 'default' => 0, 'dependency' => '', 'type' => 'custom' ], /*[ 'id' => 'doubleoptin[template]', 'label' => __('Template', 'double-opt-in'), 'choices' => [ 'blank' => 'Custom', 'newsletter_en' => 'Newsletter 1', 'newsletter_en_2' => 'Newsletter 2', 'newsletter_en_3' => 'Newsletter 3' ], 'description' => __('Pick the Template for your double opt in Mail.', 'double-opt-in'), 'default' => 'blank', 'dependency' => '', 'type' => 'select' ],*/ [ 'id' => 'doubleoptin[body]', 'label' => __('Message body', 'double-opt-in'), 'choices' => $metadata['body'], 'description' => __('Enter the Message you want to sent to your customer. Do not forget to add the Double-Opt-In tag ([doubleoptinlink]) e.g.:

<a href="[doubleoptinlink]">Confirm the registration</a>
', 'double-opt-in'), 'default' => '', 'dependency' => '', 'type' => 'textarea' ], ]; return $tab_data; } } } /** * Extra Function to use the Avada From Options */ namespace { function avada_page_options_tab_f12cf7doubleoptin() { return apply_filters('f12_cf7_doubleoptin_avada_form_panel', []); } }