tag)) { $this->options = $options; } if (is_admin()) { 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 admin_menu() { add_options_page($this->name, $this->name, 8, $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($args); $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 ), $atts)); if ($type == 'form') { return $this->form(); } return contact_detail($type, false, false, false); } function form() { 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) { $form[$key] = ($key == 'email' ? sanitize_email($value) : $this->sanitize($value)); } if (strlen($form['name']) < 1) { $this->messages['error'][] = __('Please enter your name.'); } if (!is_email($form['email'])) { $this->messages['error'][] = __('Please enter a valid email address.'); } if (strlen($form['message']) < 1) { $this->messages['error'][] = __('Please enter a message.'); } if (count($this->messages['error']) == 0) { $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'), $form['name'].(strlen($form['phone']) > 0 ? ' ('.$form['phone'].')' : '').' '.__('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.'); } } } include('form.php'); $form = ob_get_contents(); ob_end_clean(); return $form; } function sanitize($value) { return stripslashes(trim(strip_tags($value))); } } $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 )); } } }