function yith_ypop_wpcf7_get_contact_forms()
 {
     if (!function_exists('wpcf7_contact_form')) {
         return array('' => __('Plugin not activated or not installed', 'ypop'));
     }
     $posts = WPCF7_ContactForm::find();
     foreach ($posts as $post) {
         $array[$post->id()] = $post->title();
     }
     if (empty($array)) {
         return array('' => __('No contact form found', 'ypop'));
     }
     return $array;
 }
function wpcf7_register_post_types()
{
    if (class_exists('WPCF7_ContactForm')) {
        WPCF7_ContactForm::register_post_type();
        return true;
    } else {
        return false;
    }
}
 /**
  * Subscribe from Contact Form 7 Forms
  *
  * @todo improve smart guessing based on selected MailChimp lists
  *
  * @param WPCF7_ContactForm $cf7_form
  * @return bool
  */
 public function process($cf7_form)
 {
     // was sign-up checkbox checked?
     if (!$this->checkbox_was_checked()) {
         return false;
     }
     $parser = new MC4WP_Field_Guesser($this->get_data());
     $data = $parser->combine(array('guessed', 'namespaced'));
     // do nothing if no email was found
     if (empty($data['EMAIL'])) {
         return false;
     }
     return $this->subscribe($data['EMAIL'], $data, $cf7_form->id());
 }
 function prepare_items()
 {
     $current_screen = get_current_screen();
     $per_page = $this->get_items_per_page('cfseven_contact_forms_per_page');
     $this->_column_headers = $this->get_column_info();
     $args = array('posts_per_page' => $per_page, 'orderby' => 'title', 'order' => 'ASC', 'offset' => ($this->get_pagenum() - 1) * $per_page);
     if (!empty($_REQUEST['s'])) {
         $args['s'] = $_REQUEST['s'];
     }
     if (!empty($_REQUEST['orderby'])) {
         if ('title' == $_REQUEST['orderby']) {
             $args['orderby'] = 'title';
         } elseif ('author' == $_REQUEST['orderby']) {
             $args['orderby'] = 'author';
         } elseif ('date' == $_REQUEST['orderby']) {
             $args['orderby'] = 'date';
         }
     }
     if (!empty($_REQUEST['order'])) {
         if ('asc' == strtolower($_REQUEST['order'])) {
             $args['order'] = 'ASC';
         } elseif ('desc' == strtolower($_REQUEST['order'])) {
             $args['order'] = 'DESC';
         }
     }
     $this->items = WPCF7_ContactForm::find($args);
     $total_items = WPCF7_ContactForm::count();
     $total_pages = ceil($total_items / $per_page);
     $this->set_pagination_args(array('total_items' => $total_items, 'total_pages' => $total_pages, 'per_page' => $per_page));
 }
Example #5
0
 public static function get_instance(WPCF7_ContactForm $contact_form = null)
 {
     if (empty(self::$instance)) {
         if (null == $contact_form) {
             return null;
         }
         self::$instance = new self();
         self::$instance->contact_form = $contact_form;
         self::$instance->skip_mail = $contact_form->in_demo_mode();
         self::$instance->setup_posted_data();
         self::$instance->submit();
     } elseif (null != $contact_form) {
         return null;
     }
     return self::$instance;
 }
function cf7bs_get_form_property($property, $form_id = 0)
{
    global $current_form_id, $current_form_properties;
    if ($form_id == 0) {
        if (is_callable(array('WPCF7_ContactForm', 'get_current'))) {
            $current_form = WPCF7_ContactForm::get_current();
            if (is_a($current_form, 'WPCF7_ContactForm') && is_callable(array($current_form, 'id'))) {
                $form_id = $current_form->id();
            }
        }
    }
    if ($form_id == 0) {
        return false;
    }
    if ($current_form_id != $form_id) {
        $current_form_id = $form_id;
        $properties = cf7bs_get_default_form_properties();
        if (is_a($current_form, 'WPCF7_ContactForm') && is_callable(array($current_form, 'additional_setting'))) {
            foreach ($properties as $key => &$value) {
                $setting = $current_form->additional_setting($key);
                if (isset($setting[0])) {
                    $value = $setting[0];
                }
            }
            unset($key);
            unset($value);
        }
        $current_form_properties = apply_filters('cf7bs_form_' . $form_id . '_properties', $properties);
    }
    if (isset($current_form_properties[$property])) {
        return $current_form_properties[$property];
    }
    return false;
}
Example #7
0
function wpcf7_scan_form_tags($cond = null)
{
    $contact_form = WPCF7_ContactForm::get_current();
    if ($contact_form) {
        return $contact_form->scan_form_tags($cond);
    }
    return array();
}
 /**
  * Get dropdown items.
  *
  * @return array
  */
 protected function get_items()
 {
     $forms = WPCF7_ContactForm::find();
     return array_reduce($forms, function ($result, $form) {
         $result[$form->title] = $form->id;
         return $result;
     }, array());
 }
Example #9
0
 public static function get_instance($post)
 {
     $post = get_post($post);
     if (!$post || self::post_type != get_post_type($post)) {
         return false;
     }
     return self::$current = new self($post);
 }
function send_mail_for_form($cf7_posted_data)
{
    $wpcf7 = WPCF7_ContactForm::get_current();
    if ($wpcf7->id() == 596) {
        $wpcf7->skip_mail = false;
    }
    return $cf7_posted_data;
}
Example #11
0
 /**
  * Handler for wpcf7_submit hook.
  *
  * @param \WPCF7_ContactForm $contactform
  */
 public function submitForm($contactform)
 {
     if ($contactform->in_demo_mode()) {
         return;
     }
     $submission = \WPCF7_Submission::get_instance();
     $posted = $submission->get_posted_data();
     $groovehq_copy_email = $contactform->additional_setting("groovehq_copy_email");
     $groovehq_tags = $contactform->additional_setting("groovehq_tags");
     $groovehq_inbox = $contactform->additional_setting("groovehq_inbox");
     if (!$submission || !$posted) {
         return;
     }
     if (!isset($posted['your-email'])) {
         $sender = get_option('admin_email');
     } else {
         $sender = $posted['your-email'];
     }
     $ticket = array('state' => 'pending', 'to' => $sender, 'subject' => sprintf('%s: %s', $contactform->title(), $sender), 'from' => $this->getOption("inbox", "Inbox"), 'note' => true, 'body' => $this->getMessage($posted, $contactform->prop('form')));
     if (!is_null($groovehq_tags)) {
         $ticket = array_merge($ticket, array("tags" => explode(",", $groovehq_tags[0])));
     }
     if (!is_null($groovehq_inbox)) {
         $ticket["from"] = $groovehq_inbox[0];
     }
     if (!is_null($groovehq_copy_email)) {
         add_filter('wp_mail_content_type', array(&$this, "set_html_content_type"));
         wp_mail($groovehq_copy_email[0], $ticket["subject"], $ticket["body"]);
         remove_filter('wp_mail_content_type', array(&$this, "set_html_content_type"));
     }
     $res = $this->postAPI("/tickets", $ticket);
     if ($res && $this->getOption("to_pending", false)) {
         $this->setPendingTicket($res->ticket->number);
     }
 }
 public static function get_instance($post)
 {
     $post = get_post($post);
     if (!$post || self::post_type != get_post_type($post)) {
         return false;
     }
     self::$current = $contact_form = new self($post);
     return $contact_form;
 }
Example #13
0
/**
 * Set up the contact form 7 plugin.
 * Set up the default contact form with the user's e-mail address, and create a
 * contact page to contain the form.
 * @global type $gd_quicksetup_plugin
 * @return null
 */
function gd_quicksetup_setup_contact_form_7()
{
    global $gd_quicksetup_plugin;
    $options = $gd_quicksetup_plugin->get_current_plugin_options();
    // Get email address
    $email = '';
    foreach ((array) $_POST['type'] as $k => $v) {
        if (!$_POST['enabled'][$k] || 'false' === $_POST['enabled'][$k]) {
            continue;
        }
        if ('contact' === $v) {
            $email = sanitize_email(stripslashes_deep($_POST['contact_email'][$k]));
            break;
        }
    }
    if (empty($email)) {
        return;
    }
    // Update the contact form
    $post_content = '';
    $posts = get_posts(array('post_type' => 'wpcf7_contact_form', 'numberposts' => 1));
    if (class_exists('WPCF7_ContactForm') && is_array($posts) && !empty($posts[0]) && $posts[0] instanceof WP_Post) {
        // Use Contact Form 7's API
        $post = $posts[0];
        $contact_form = new WPCF7_ContactForm($post);
        // Add CAPTCHA
        $search = '[textarea your-message] </p>';
        $cid = rand(0, 1000);
        $contact_form->form = str_replace($search, $search . "\n\n<p>Please enter the text below<br />\n    [captchac captcha-{$cid}]<br />\n    [captchar captcha-{$cid}]<br /></p>", $contact_form->form);
        // Change title
        $contact_form->title = isset($options['page_title']) ? $options['page_title'] : __('Contact', 'gd_quicksetup');
        if (!empty($email)) {
            $contact_form->mail['recipient'] = $email;
        }
        // Save
        $contact_form->save();
        // New tag for the contact page
        $post_content = '[contact-form-7 id="' . $post->ID . '" title="' . $post->post_title . '"]';
    }
    // Create a Contact page
    wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_content' => $post_content, 'post_name' => 'contact', 'post_title' => isset($options['page_title']) ? $options['page_title'] : __('Contact Us', 'gd_quicksetup'), 'post_type' => 'page', 'post_status' => 'publish', 'menu_order' => 800));
}
 /**
  * Takes the body of the mail, evaluates it and sets it back.
  * 
  * @param [Object] The $WPCF7_ContactForm object.
  * @return void
  */
 public function prepare_body($cf7)
 {
     // Get the object.
     $wpcf = WPCF7_ContactForm::get_current();
     // Now we get the mail body and evaluate it.
     $mail = $wpcf->prop('mail');
     $mail['body'] = $this->evaluate($mail['body']);
     // Set the new body.
     $wpcf->set_properties(array('mail' => $mail));
     return $wpcf;
 }
 public static function find($args = '')
 {
     $defaults = array('post_status' => 'any', 'posts_per_page' => -1, 'offset' => 0, 'orderby' => 'ID', 'order' => 'ASC');
     $args = wp_parse_args($args, $defaults);
     $args['post_type'] = self::post_type;
     $q = new WP_Query();
     $posts = $q->query($args);
     self::$found_items = $q->found_posts;
     $objs = array();
     foreach ((array) $posts as $post) {
         $objs[] = new self($post);
     }
     return $objs;
 }
 public function render($atts)
 {
     extract($atts);
     $shortcode = '';
     // Hookup the shortcode
     if ($this->is_active()) {
         $items = WPCF7_ContactForm::find(array('p' => $form_id));
     }
     if (!empty($items)) {
         $item = $items[0];
         $shortcode = sprintf('[contact-form-7 id="%1$d" title="%2$s"]', $item->id(), $item->title());
     }
     return $shortcode;
 }
Example #17
0
 public function __construct(WPCF7_ContactForm $contact_form)
 {
     $this->contact_form = $contact_form;
     $config_errors = get_post_meta($contact_form->id(), '_config_errors', true);
     foreach ((array) $config_errors as $section => $errors) {
         if (empty($errors)) {
             continue;
         }
         if (!is_array($errors)) {
             // for back-compat
             $code = $errors;
             $this->add_error($section, $code);
         } else {
             foreach ((array) $errors as $error) {
                 if (!empty($error['code'])) {
                     $code = $error['code'];
                     $args = isset($error['args']) ? $error['args'] : '';
                     $this->add_error($section, $code, $args);
                 }
             }
         }
     }
 }
Example #18
0
function wpcf7_install()
{
    if ($opt = get_option('wpcf7')) {
        return;
    }
    wpcf7_load_textdomain();
    wpcf7_register_post_types();
    wpcf7_upgrade();
    if (get_posts(array('post_type' => 'wpcf7_contact_form'))) {
        return;
    }
    $contact_form = WPCF7_ContactForm::get_template(array('title' => sprintf(__('Contact form %d', 'contact-form-7'), 1)));
    $contact_form->save();
}
function wpcf7gpg_encrypt_mail($wpcf7gpg_mailcomponents)
{
    $wpcf7gpg_contactform = WPCF7_ContactForm::get_current();
    $wpcf7gpg_publickey = $wpcf7gpg_contactform->additional_setting('wpcf7gpg_publickey');
    if ($wpcf7gpg_publickey) {
        // A public key has been defined (element 0 in array), sanitize as required by GPG library
        $wpcf7gpg_publickey = str_replace('|', "\n", $wpcf7gpg_publickey[0]);
        // Replace body of mail with encrypted body text
        $wpcf7gpg_mailcomponents['body'] = wpcf7gpg_encrypt_text($wpcf7gpg_mailcomponents['body'], $wpcf7gpg_publickey);
    } else {
        // No public key has been defined, we can skip encryption
    }
    return $wpcf7gpg_mailcomponents;
}
Example #20
0
/**
 * Outputs the CF7 options metabox in action box edit screen
 * @param  object $post the current post
 * @return html
 */
function mab_cf7_meta_box($post)
{
    $MabBase = MAB();
    $MabButton = MAB('button');
    $data['meta'] = $MabBase->get_mab_meta($post->ID);
    $type = $MabBase->get_action_box_type($post->ID);
    //Get contact form 7 stuff
    $args = array('orderby' => 'title', 'order' => 'ASC');
    $cf7_list = WPCF7_ContactForm::find($args);
    $data['cf7-list'] = is_array($cf7_list) ? $cf7_list : array();
    $data['buttons'] = $MabButton->getConfiguredButtons();
    $filename = 'metabox/cf7-settings.php';
    $box = mab_cf7_get_view($filename, $data);
    echo $box;
}
 public function dynamic_shortcode_handler($tag)
 {
     // generates html for form field
     if (!is_array($tag)) {
         return '';
     }
     $name = $tag['name'];
     if (empty($name)) {
         return '';
     }
     $wpcf7_contact_form = WPCF7_ContactForm::get_current();
     // most attributes not really needed, not included
     $name_att = $name;
     $filter = '';
     $filter_args = array();
     $filter_string = '';
     $values = $tag['values'];
     if (isset($values[0])) {
         $filter_string = $values[0];
     }
     //echo $filter_string;
     if ($filter_string != '') {
         $filter_parts = explode(' ', $filter_string);
         $filter = trim($filter_parts[0]);
         $count = count($filter_parts);
         for ($i = 1; $i < $count; $i++) {
             if (trim($filter_parts[$i]) != '') {
                 $arg_parts = explode('=', $filter_parts[$i]);
                 if (count($arg_parts) == 2) {
                     $filter_args[trim($arg_parts[0])] = trim($arg_parts[1], ' \'');
                 } else {
                     $filter_args[] = trim($arg_parts[0], ' \'');
                 }
             }
             // end if filter part
         }
         // end for
     }
     // end if filter string
     $value = '';
     if ($filter != '') {
         $value = apply_filters($filter, $value, $filter_args);
     }
     $atts = ' name="' . $name . '" value="' . $value . '" autocomplete="off"';
     $html = '<input type="hidden"' . $atts . ' />';
     return $html;
 }
function sandwich_contact_form_7()
{
    // Check if Shortcake exists
    if (!function_exists('shortcode_ui_register_for_shortcode')) {
        return;
    }
    if (!is_admin()) {
        return;
    }
    if (!class_exists('WPCF7_ContactForm')) {
        return;
    }
    $options = array('0' => sprintf('— %s —', __('Select', 'pbsandwich')));
    $forms = WPCF7_ContactForm::find();
    foreach ($forms as $form) {
        $options[$form->id()] = $form->title();
    }
    // Register Shortcake UI
    shortcode_ui_register_for_shortcode('contact-form-7', array('label' => __('Contact Form 7', 'contact-form-7'), 'listItemImage' => 'dashicons-email', 'attrs' => array(array('label' => __('Select a contact form', 'pbsandwich'), 'attr' => 'id', 'type' => 'select', 'options' => $options), array('label' => __('Title', 'pbsandwich'), 'attr' => 'title', 'type' => 'text', 'value' => ''))));
}
Example #23
0
function wpcf7_prepend_underscore($new_ver, $old_ver)
{
    if (version_compare($old_ver, '3.0-dev', '<')) {
        return;
    }
    if (!version_compare($old_ver, '3.3-dev', '<')) {
        return;
    }
    $posts = WPCF7_ContactForm::find(array('post_status' => 'any', 'posts_per_page' => -1));
    foreach ($posts as $post) {
        $props = $post->get_properties();
        foreach ($props as $prop => $value) {
            if (metadata_exists('post', $post->id, '_' . $prop)) {
                continue;
            }
            update_post_meta($post->id, '_' . $prop, $value);
            delete_post_meta($post->id, $prop);
        }
    }
}
Example #24
0
 /**
  * Get all forms running on the site
  *
  * @since 1.0.0
  *
  * @param $form_list
  *
  * @return mixed
  */
 public function get_forms($form_list)
 {
     if (class_exists('Caldera_Forms')) {
         $forms = \Caldera_Forms::get_forms();
         $form_list['caldera'] = array('name' => __('Caldera Forms', 'caldera-forms'), 'forms' => array());
         foreach ($forms as $form) {
             $form_list['caldera']['forms'][$form['ID']] = $form['name'];
         }
     }
     if (class_exists('RGFormsModel')) {
         $forms = \RGFormsModel::get_forms(null, 'title');
         $form_list['gform'] = array('name' => __('Gravity Forms', 'gravityforms'), 'forms' => array());
         foreach ($forms as $form) {
             $form_list['gform']['forms'][$form->id] = $form->title;
         }
     }
     if (class_exists('NF_Forms')) {
         $nforms = new \NF_Forms();
         $nforms = $nforms->get_all();
         $form_list['ninja'] = array('name' => __('Ninja Forms', 'ninja-forms'), 'forms' => array());
         foreach ($nforms as $form) {
             $form_list['ninja']['forms'][$form] = Ninja_Forms()->form($form)->get_setting('form_title');
         }
     }
     if (class_exists('WPCF7_ContactForm')) {
         $cforms = \WPCF7_ContactForm::find(array('posts_per_page' => -1));
         $form_list['cf7'] = array('name' => __('Contact Form 7', 'contact-form-7'), 'forms' => array());
         foreach ($cforms as $form) {
             $form_list['cf7']['forms'][$form->id()] = $form->title();
         }
     }
     if (class_exists('FrmForm')) {
         $fforms = \FrmForm::getAll();
         $form_list['frmid'] = array('name' => __('Formidable', 'formidable'), 'forms' => array());
         foreach ($fforms as $form) {
             if (!empty($form->is_template)) {
                 continue;
             }
             $form_list['frmid']['forms'][$form->id] = $form->name;
         }
     }
     // jetpack
     if (function_exists('grunion_display_form_view')) {
         global $wpdb;
         $shortcodes = $wpdb->get_results("SELECT `post_id` FROM `" . $wpdb->postmeta . "` WHERE `meta_key` = '_g_feedback_shortcode';", ARRAY_A);
         if (!empty($shortcodes)) {
             $form_list['jp'] = array('name' => __('Jetpack Contact Form', 'jetpack'), 'forms' => array());
             foreach ($shortcodes as $post_id) {
                 $form = get_post($post_id['post_id']);
                 $form_list['jp']['forms'][$post_id['post_id']] = $form->post_title;
             }
         }
     }
     return $form_list;
 }
Example #25
0
 /**
  * Initialize the plugin by setting localization, filters, and administration functions.
  *
  * @since 1.0.0
  *
  * @access private
  */
 private function __construct()
 {
     global $formworks_tracker;
     //auto load modules
     $dir = FRMWKS_PATH . 'includes/modules';
     if (is_dir($dir)) {
         if ($dh = opendir($dir)) {
             while (($folder = readdir($dh)) !== false) {
                 if ($folder === '..' || $folder === '.') {
                     continue;
                 }
                 if (file_exists($dir . '/' . $folder . '/handler.php')) {
                     include_once $dir . '/' . $folder . '/handler.php';
                 }
             }
             closedir($dh);
         }
     }
     // Load plugin text domain
     add_action('init', array($this, 'load_plugin_textdomain'));
     //initialize visitor tracker
     if (!is_admin()) {
         add_action('wp', array($this, 'register_visitor_session'));
     }
     // Activate plugin when new blog is added
     add_action('wpmu_new_blog', array($this, 'activate_new_site'));
     // Load admin style sheet and JavaScript.
     add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_stylescripts'));
     // Load front style sheet and JavaScript.
     add_action('wp_enqueue_scripts', array($this, 'enqueue_front_stylescripts'));
     // output tracking code
     add_action('wp_print_footer_scripts', array($this, 'print_front_scripts'));
     // Add partial completions
     add_action('wp_ajax_frmwks_push', array($this, 'tracker_push'));
     add_action('wp_ajax_nopriv_frmwks_push', array($this, 'tracker_push'));
     // open actions
     add_action('formworks_track', array($this, 'handle_track'), 10, 4);
     /**
      * Tracking
      */
     /** Caldera Forms */
     add_action('caldera_forms_submit_complete', function ($form) {
         do_action('formworks_track', 'caldera', $form['ID'], 'submission');
     });
     add_filter('caldera_forms_render_form', function ($html, $form) {
         $selector = array("name" => $form['name'], "selector" => "." . $form['ID'], "prefix" => 'caldera', "id" => $form['ID']);
         do_action('formworks_track', 'caldera', $form['ID'], 'loaded', $selector);
         return $html;
     }, 10, 2);
     /** JETPACK */
     add_filter('grunion_contact_form_success_message', function ($html) {
         if (isset($_GET['contact-form-id'])) {
             $form_id = $_GET['contact-form-id'];
             do_action('formworks_track', 'jp', $form_id, 'submission');
         }
         return $html;
     });
     add_filter('grunion_contact_form_form_action', function ($url, $post, $form) {
         $selector = array("name" => $post->post_title, "selector" => "#contact-form-" . $form);
         do_action('formworks_track', 'jp', $form, 'loaded', $selector);
         return $url;
     }, 15, 3);
     /** Formidable */
     add_action('frm_process_entry', function ($params) {
         do_action('formworks_track', 'frmid', $params['form_id'], 'submission');
     }, 15);
     add_filter('formidable_shortcode_atts', function ($shortcode_atts, $atts) {
         if (class_exists('\\FrmForm')) {
             $form = \FrmForm::getOne($atts['id']);
         }
         $selector = array("name" => $form->name, "selector" => "#form_" . $form->form_key);
         do_action('formworks_track', 'frmid', $form->id, 'loaded', $selector);
     }, 10, 2);
     /** Contact Form 7 */
     add_filter('wpcf7_form_elements', function ($html) {
         if (class_exists('\\WPCF7_ContactForm')) {
             $form = \WPCF7_ContactForm::get_current();
             do_action('formworks_track', 'cf7', $form->id(), 'loaded');
         }
         return $html;
     }, 10, 2);
     add_action('wpcf7_submit', function ($instance, $result) {
         if (isset($result['status']) && 'mail_sent' === $result['status']) {
             do_action('formworks_track', 'cf7', $instance->id(), 'submission');
         }
     }, 20, 2);
     /** Gravity Forms */
     add_filter('gform_get_form_filter', function ($html, $form) {
         $selector = array("name" => $form['title'], "selector" => "#gform_" . $form['id']);
         do_action('formworks_track', 'gform', $form['id'], 'loaded', $selector);
         return $html;
     }, 10, 2);
     add_action('gform_after_submission', function ($form) {
         // do a submission complete
         do_action('formworks_track', 'gform', $form['form_id'], 'submission');
         return;
     });
     /** Ninja Forms */
     add_action('ninja_forms_post_process', function () {
         global $ninja_forms_processing;
         if (is_object($ninja_forms_processing)) {
             do_action('formworks_track', 'ninja', $ninja_forms_processing->get_form_ID(), 'submission');
         }
     });
     //load settings class && licensing in admin
     if (is_admin()) {
         new settings();
         add_action('admin_init', function () {
             $plugin = frmwks_licensing_args();
             new \calderawp\licensing_helper\licensing($plugin);
         }, 0);
     }
 }
Example #26
0
function wpcf7_contact_form($id)
{
    $post = get_post($id);
    if (empty($post) || 'wpcf7_contact_form' != get_post_type($post)) {
        return false;
    }
    $contact_form = new WPCF7_ContactForm();
    $contact_form->id = $post->ID;
    $contact_form->title = $post->post_title;
    $contact_form->form = get_post_meta($post->ID, 'form', true);
    $contact_form->mail = get_post_meta($post->ID, 'mail', true);
    $contact_form->mail_2 = get_post_meta($post->ID, 'mail_2', true);
    $contact_form->messages = get_post_meta($post->ID, 'messages', true);
    $contact_form->additional_settings = get_post_meta($post->ID, 'additional_settings', true);
    $contact_form->upgrade();
    $contact_form = apply_filters_ref_array('wpcf7_contact_form', array(&$contact_form));
    return $contact_form;
}
Example #27
0
function wpcf7_admin_add_pages()
{
    if (isset($_POST['wpcf7-save']) && wpcf7_admin_has_edit_cap()) {
        $id = $_POST['wpcf7-id'];
        check_admin_referer('wpcf7-save_' . $id);
        if (!($contact_form = wpcf7_contact_form($id))) {
            $contact_form = new WPCF7_ContactForm();
            $contact_form->initial = true;
        }
        $title = trim($_POST['wpcf7-title']);
        $form = trim($_POST['wpcf7-form']);
        $mail = array('subject' => trim($_POST['wpcf7-mail-subject']), 'sender' => trim($_POST['wpcf7-mail-sender']), 'body' => trim($_POST['wpcf7-mail-body']), 'recipient' => trim($_POST['wpcf7-mail-recipient']), 'additional_headers' => trim($_POST['wpcf7-mail-additional-headers']), 'attachments' => trim($_POST['wpcf7-mail-attachments']), 'use_html' => isset($_POST['wpcf7-mail-use-html']) && 1 == $_POST['wpcf7-mail-use-html']);
        $mail_2 = array('active' => isset($_POST['wpcf7-mail-2-active']) && 1 == $_POST['wpcf7-mail-2-active'], 'subject' => trim($_POST['wpcf7-mail-2-subject']), 'sender' => trim($_POST['wpcf7-mail-2-sender']), 'body' => trim($_POST['wpcf7-mail-2-body']), 'recipient' => trim($_POST['wpcf7-mail-2-recipient']), 'additional_headers' => trim($_POST['wpcf7-mail-2-additional-headers']), 'attachments' => trim($_POST['wpcf7-mail-2-attachments']), 'use_html' => isset($_POST['wpcf7-mail-2-use-html']) && 1 == $_POST['wpcf7-mail-2-use-html']);
        $messages = $contact_form->messages;
        foreach (wpcf7_messages() as $key => $arr) {
            $field_name = 'wpcf7-message-' . strtr($key, '_', '-');
            if (isset($_POST[$field_name])) {
                $messages[$key] = trim($_POST[$field_name]);
            }
        }
        $additional_settings = trim($_POST['wpcf7-additional-settings']);
        $query = array();
        $query['message'] = $contact_form->initial ? 'created' : 'saved';
        $contact_form->title = $title;
        $contact_form->form = $form;
        $contact_form->mail = $mail;
        $contact_form->mail_2 = $mail_2;
        $contact_form->messages = $messages;
        $contact_form->additional_settings = $additional_settings;
        $contact_form->save();
        $query['contactform'] = $contact_form->id;
        $redirect_to = wpcf7_admin_url($query);
        wp_redirect($redirect_to);
        exit;
    } elseif (isset($_POST['wpcf7-copy']) && wpcf7_admin_has_edit_cap()) {
        $id = $_POST['wpcf7-id'];
        check_admin_referer('wpcf7-copy_' . $id);
        $query = array();
        if ($contact_form = wpcf7_contact_form($id)) {
            $new_contact_form = $contact_form->copy();
            $new_contact_form->save();
            $query['contactform'] = $new_contact_form->id;
            $query['message'] = 'created';
        } else {
            $query['contactform'] = $contact_form->id;
        }
        $redirect_to = wpcf7_admin_url($query);
        wp_redirect($redirect_to);
        exit;
    } elseif (isset($_POST['wpcf7-delete']) && wpcf7_admin_has_edit_cap()) {
        $id = $_POST['wpcf7-id'];
        check_admin_referer('wpcf7-delete_' . $id);
        if ($contact_form = wpcf7_contact_form($id)) {
            $contact_form->delete();
        }
        $redirect_to = wpcf7_admin_url(array('message' => 'deleted'));
        wp_redirect($redirect_to);
        exit;
    } elseif (isset($_GET['wpcf7-create-table'])) {
        check_admin_referer('wpcf7-create-table');
        $query = array();
        if (!wpcf7_table_exists() && current_user_can('activate_plugins')) {
            wpcf7_install();
            if (wpcf7_table_exists()) {
                $query['message'] = 'table_created';
            } else {
                $query['message'] = 'table_not_created';
            }
        }
        wp_redirect(wpcf7_admin_url($query));
        exit;
    }
    add_menu_page(__('Contact Form 7', 'wpcf7'), __('Contact', 'wpcf7'), WPCF7_ADMIN_READ_CAPABILITY, 'wpcf7', 'wpcf7_admin_management_page');
    add_submenu_page('wpcf7', __('Edit Contact Forms', 'wpcf7'), __('Edit', 'wpcf7'), WPCF7_ADMIN_READ_CAPABILITY, 'wpcf7', 'wpcf7_admin_management_page');
}
</option>
					<?php 
}
?>
					</select></td>								
				</tr>
				<tr>
					<td><input type='checkbox' name='use_contactform7'/></td>
					<td><?php 
_e('Use ContactForm7', 'dvinwcql');
?>
 - <select name='contactform7_form_select' id='contactform7_form_select'>
						<option value=''>Select Form</option>
						<?php 
if (class_exists('WPCF7_ContactForm')) {
    $forms = WPCF7_ContactForm::find();
} else {
    $forms = array();
}
foreach ($forms as $form) {
    ?>
								<option value='<?php 
    echo $form->id();
    ?>
'><?php 
    echo $form->title();
    ?>
</option>
					<?php 
}
?>
Example #29
0
function wpcf7_load_contact_form_admin()
{
    $action = wpcf7_current_action();
    if ('save' == $action) {
        $id = $_POST['post_ID'];
        check_admin_referer('wpcf7-save-contact-form_' . $id);
        if (!current_user_can('wpcf7_edit_contact_form', $id)) {
            wp_die(__('You are not allowed to edit this item.', 'wpcf7'));
        }
        if (!($contact_form = wpcf7_contact_form($id))) {
            $contact_form = new WPCF7_ContactForm();
            $contact_form->initial = true;
        }
        $contact_form->title = trim($_POST['wpcf7-title']);
        $form = trim($_POST['wpcf7-form']);
        $mail = array('subject' => trim($_POST['wpcf7-mail-subject']), 'sender' => trim($_POST['wpcf7-mail-sender']), 'body' => trim($_POST['wpcf7-mail-body']), 'recipient' => trim($_POST['wpcf7-mail-recipient']), 'additional_headers' => trim($_POST['wpcf7-mail-additional-headers']), 'attachments' => trim($_POST['wpcf7-mail-attachments']), 'use_html' => isset($_POST['wpcf7-mail-use-html']) && 1 == $_POST['wpcf7-mail-use-html']);
        $mail_2 = array('active' => isset($_POST['wpcf7-mail-2-active']) && 1 == $_POST['wpcf7-mail-2-active'], 'subject' => trim($_POST['wpcf7-mail-2-subject']), 'sender' => trim($_POST['wpcf7-mail-2-sender']), 'body' => trim($_POST['wpcf7-mail-2-body']), 'recipient' => trim($_POST['wpcf7-mail-2-recipient']), 'additional_headers' => trim($_POST['wpcf7-mail-2-additional-headers']), 'attachments' => trim($_POST['wpcf7-mail-2-attachments']), 'use_html' => isset($_POST['wpcf7-mail-2-use-html']) && 1 == $_POST['wpcf7-mail-2-use-html']);
        $messages = isset($contact_form->messages) ? $contact_form->messages : array();
        foreach (wpcf7_messages() as $key => $arr) {
            $field_name = 'wpcf7-message-' . strtr($key, '_', '-');
            if (isset($_POST[$field_name])) {
                $messages[$key] = trim($_POST[$field_name]);
            }
        }
        $additional_settings = trim($_POST['wpcf7-additional-settings']);
        $props = apply_filters('wpcf7_contact_form_admin_posted_properties', compact('form', 'mail', 'mail_2', 'messages', 'additional_settings'));
        foreach ((array) $props as $key => $prop) {
            $contact_form->{$key} = $prop;
        }
        $query = array();
        $query['message'] = $contact_form->initial ? 'created' : 'saved';
        $contact_form->save();
        $query['post'] = $contact_form->id;
        $redirect_to = add_query_arg($query, menu_page_url('wpcf7', false));
        wp_safe_redirect($redirect_to);
        exit;
    }
    if ('copy' == $action) {
        $id = empty($_POST['post_ID']) ? absint($_REQUEST['post']) : absint($_POST['post_ID']);
        check_admin_referer('wpcf7-copy-contact-form_' . $id);
        if (!current_user_can('wpcf7_edit_contact_form', $id)) {
            wp_die(__('You are not allowed to edit this item.', 'wpcf7'));
        }
        $query = array();
        if ($contact_form = wpcf7_contact_form($id)) {
            $new_contact_form = $contact_form->copy();
            $new_contact_form->save();
            $query['post'] = $new_contact_form->id;
            $query['message'] = 'created';
        } else {
            $query['post'] = $contact_form->id;
        }
        $redirect_to = add_query_arg($query, menu_page_url('wpcf7', false));
        wp_safe_redirect($redirect_to);
        exit;
    }
    if ('delete' == $action) {
        if (!empty($_POST['post_ID'])) {
            check_admin_referer('wpcf7-delete-contact-form_' . $_POST['post_ID']);
        } elseif (!is_array($_REQUEST['post'])) {
            check_admin_referer('wpcf7-delete-contact-form_' . $_REQUEST['post']);
        } else {
            check_admin_referer('bulk-posts');
        }
        $posts = empty($_POST['post_ID']) ? (array) $_REQUEST['post'] : (array) $_POST['post_ID'];
        $deleted = 0;
        foreach ($posts as $post) {
            $post = new WPCF7_ContactForm($post);
            if (empty($post)) {
                continue;
            }
            if (!current_user_can('wpcf7_delete_contact_form', $post->id)) {
                wp_die(__('You are not allowed to delete this item.', 'wpcf7'));
            }
            if (!$post->delete()) {
                wp_die(__('Error in deleting.', 'wpcf7'));
            }
            $deleted += 1;
        }
        $query = array();
        if (!empty($deleted)) {
            $query['message'] = 'deleted';
        }
        $redirect_to = add_query_arg($query, menu_page_url('wpcf7', false));
        wp_safe_redirect($redirect_to);
        exit;
    }
    if (empty($_GET['post'])) {
        $current_screen = get_current_screen();
        if (!class_exists('WPCF7_Contact_Form_List_Table')) {
            require_once WPCF7_PLUGIN_DIR . '/admin/includes/class-contact-forms-list-table.php';
        }
        add_filter('manage_' . $current_screen->id . '_columns', array('WPCF7_Contact_Form_List_Table', 'define_columns'));
        add_screen_option('per_page', array('label' => __('Contact Forms', 'wpcf7'), 'default' => 20, 'option' => 'cfseven_contact_forms_per_page'));
    }
}
Example #30
-1
function wpcf7_admin_init()
{
    if (!wpcf7_admin_has_edit_cap()) {
        return;
    }
    if (isset($_POST['wpcf7-save'])) {
        $id = $_POST['post_ID'];
        check_admin_referer('wpcf7-save_' . $id);
        if (!($contact_form = wpcf7_contact_form($id))) {
            $contact_form = new WPCF7_ContactForm();
            $contact_form->initial = true;
        }
        $contact_form->title = trim($_POST['wpcf7-title']);
        $form = trim($_POST['wpcf7-form']);
        $mail = array('subject' => trim($_POST['wpcf7-mail-subject']), 'sender' => trim($_POST['wpcf7-mail-sender']), 'body' => trim($_POST['wpcf7-mail-body']), 'recipient' => trim($_POST['wpcf7-mail-recipient']), 'additional_headers' => trim($_POST['wpcf7-mail-additional-headers']), 'attachments' => trim($_POST['wpcf7-mail-attachments']), 'use_html' => isset($_POST['wpcf7-mail-use-html']) && 1 == $_POST['wpcf7-mail-use-html']);
        $mail_2 = array('active' => isset($_POST['wpcf7-mail-2-active']) && 1 == $_POST['wpcf7-mail-2-active'], 'subject' => trim($_POST['wpcf7-mail-2-subject']), 'sender' => trim($_POST['wpcf7-mail-2-sender']), 'body' => trim($_POST['wpcf7-mail-2-body']), 'recipient' => trim($_POST['wpcf7-mail-2-recipient']), 'additional_headers' => trim($_POST['wpcf7-mail-2-additional-headers']), 'attachments' => trim($_POST['wpcf7-mail-2-attachments']), 'use_html' => isset($_POST['wpcf7-mail-2-use-html']) && 1 == $_POST['wpcf7-mail-2-use-html']);
        $messages = isset($contact_form->messages) ? $contact_form->messages : array();
        foreach (wpcf7_messages() as $key => $arr) {
            $field_name = 'wpcf7-message-' . strtr($key, '_', '-');
            if (isset($_POST[$field_name])) {
                $messages[$key] = trim($_POST[$field_name]);
            }
        }
        $additional_settings = trim($_POST['wpcf7-additional-settings']);
        $props = apply_filters('wpcf7_contact_form_admin_posted_properties', compact('form', 'mail', 'mail_2', 'messages', 'additional_settings'));
        foreach ((array) $props as $key => $prop) {
            $contact_form->{$key} = $prop;
        }
        $query = array();
        $query['message'] = $contact_form->initial ? 'created' : 'saved';
        $contact_form->save();
        $query['contactform'] = $contact_form->id;
        $redirect_to = wpcf7_admin_url($query);
        wp_safe_redirect($redirect_to);
        exit;
    }
    if (isset($_POST['wpcf7-copy'])) {
        $id = $_POST['post_ID'];
        check_admin_referer('wpcf7-copy_' . $id);
        $query = array();
        if ($contact_form = wpcf7_contact_form($id)) {
            $new_contact_form = $contact_form->copy();
            $new_contact_form->save();
            $query['contactform'] = $new_contact_form->id;
            $query['message'] = 'created';
        } else {
            $query['contactform'] = $contact_form->id;
        }
        $redirect_to = wpcf7_admin_url($query);
        wp_safe_redirect($redirect_to);
        exit;
    }
    if (isset($_POST['wpcf7-delete'])) {
        $id = $_POST['post_ID'];
        check_admin_referer('wpcf7-delete_' . $id);
        if ($contact_form = wpcf7_contact_form($id)) {
            $contact_form->delete();
        }
        $redirect_to = wpcf7_admin_url(array('message' => 'deleted'));
        wp_safe_redirect($redirect_to);
        exit;
    }
}