tag)) { $this->options = $options; } if (is_admin()) { register_activation_hook(__FILE__, array(&$this, 'activate')); add_action('admin_menu', array(&$this, 'admin_menu')); add_action('admin_init', array(&$this, 'admin_init')); add_filter('plugin_row_meta', array(&$this, 'plugin_row_meta'), 10, 2); } else { add_shortcode('contact', array(&$this, 'shortcode')); add_filter('contact_detail', array(&$this, 'build'), 1); } } function activate() { if (!$this->options) { update_option($this->tag, array( 'email' => get_option('admin_email') )); } } function admin_menu() { add_options_page( $this->name, $this->name, 'manage_options', $this->tag, array(&$this, 'settings') ); } function admin_init() { register_setting($this->tag.'_options', $this->tag); } function settings() { include_once('settings.php'); } function plugin_row_meta($links, $file) { $plugin = plugin_basename(__FILE__); if ($file == $plugin) { return array_merge( $links, array(sprintf( '%s', $this->tag, __('Edit Details') )) ); } return $links; } function build($args) { extract(shortcode_atts(array( 'type' => false, 'before' => '', 'after' => '', 'echo' => true ), $atts)); $value = $this->value($type); if (strlen($value) == 0) { return; } $detail = $before.$value.$after; if ($echo) { echo $detail; } else { return $detail; } } function value($type=false) { if ($type != false && array_key_exists($type, $this->options)) { return ($type == 'address' ? nl2br($this->options[$type]) : $this->options[$type]); } return null; } function shortcode($atts) { extract(shortcode_atts(array( 'type' => false, 'include' => false ), $atts)); if ($type == 'form') { return $this->form($include); } return contact_detail($type, false, false, false); } function form($include = false) { ob_start(); if (!isset($this->options['email']) || !is_email($this->options['email'])) { return __('You must define an email address on the options page in order to display the contact form.'); } if (isset($_POST['contact'])) { $this->messages['error'] = array(); $form = $_POST['contact']; foreach ($form AS $key => $value) { switch ($key) { case 'name': $value = sanitize_text_field($value); if (strlen($value) < 1) { $this->messages['error'][] = __('Please enter your name.'); } break; case 'email': $value = sanitize_email($value); if (!is_email($value)) { $this->messages['error'][] = __('Please enter a valid email address.'); } break; case 'message': $value = sanitize_text_field($value); if (strlen($value) < 1) { $this->messages['error'][] = __('Please enter a message.'); } break; default: $value = sanitize_text_field($value); } $form[$key] = $value; } if (count($this->messages['error']) == 0) { if (wp_blacklist_check( $form['name'], $form['email'], false, // Website URL $form['message'], preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']), substr($_SERVER['HTTP_USER_AGENT'], 0, 254) )) { $this->messages['error'][] = __( 'Sorry, your comment failed the blacklist check and could not be sent.' ); } else { $headers = array( 'From: '.get_bloginfo('name').' <'.$this->options['email'].'>', 'Reply-To: '.$form['name'].' <'.$form['email'].'>' ); if (wp_mail( $this->options['email'], '['.get_bloginfo('name').'] '.__('Contact form'), (isset($form['phone']) && strlen($form['phone']) > 0 ? 'Phone: '.$form['phone']."\r\n\r\n" : ''). (isset($form['website']) && strlen($form['website']) > 0 ? 'Website: '.$form['website']."\r\n\r\n" : ''). $form['name'].' '.__('wrote'). ": \r\n\r\n".$form['message'], implode("\r\n", $headers) )) { $this->messages['ok'] = __('Your message has been sent.'); unset($_POST['contact']); } else { $this->messages['error'][] = __('Sorry, we were unable to send your message.'); } } } } if ($include == false) { include('form.php'); } else { include(TEMPLATEPATH.'/'.basename($include)); } $form = ob_get_contents(); ob_end_clean(); return $form; } } $contactDetails = new ContactDetails(); if (isset($contactDetails)) { function contact_detail($t=false,$b='',$a='',$e=true){ return apply_filters('contact_detail', array( 'type'=>$t, 'before'=>$b, 'after'=>$a, 'echo'=>$e )); } } }