Changeset 782825
- Timestamp:
- 10/05/2013 12:56:51 AM (13 years ago)
- Location:
- proper-contact-form/trunk
- Files:
-
- 2 added
- 3 deleted
- 4 edited
-
css/admin.css (deleted)
-
inc/FormBuilder.php (modified) (4 diffs)
-
inc/docs.html (deleted)
-
inc/helpers.php (modified) (1 diff)
-
inc/settings.php (added)
-
inc/widget.php (added)
-
proper-contact-form.php (modified) (2 diffs)
-
readme.txt (modified) (4 diffs)
-
settings.php (deleted)
Legend:
- Unmodified
- Added
- Removed
-
proper-contact-form/trunk/inc/FormBuilder.php
r687822 r782825 1 1 <?php 2 2 3 // v 0.8. 13 // v 0.8.2 4 4 5 5 class ThatFormBuilder { 6 6 7 7 // Stores all form inputs 8 private $inputs = array(); 9 8 private $inputs = array(); 9 10 10 // Stores all form attributes 11 private $form = array(); 12 11 private $form = array(); 12 13 13 // Make sure a submit button is output 14 private $has_submit = FALSE;15 14 private $has_submit = false; 15 16 16 // Constructor to set basic form attributes 17 function __construct( $action = '', $args = FALSE) {18 17 function __construct( $action = '', $args = false ) { 18 19 19 $defaults = array( 20 'action' => $action, 21 'method' => 'post', 22 'enctype' => 'application/x-www-form-urlencoded', 23 'class' => array(), 24 'id' => '', 25 'markup' => 'html', 26 'novalidate' => FALSE, 27 'add_nonce' => FALSE, 28 'add_honeypot' => TRUE, 29 'submit_text' => 'Submit' 20 'action' => $action, 21 'method' => 'post', 22 'enctype' => 'application/x-www-form-urlencoded', 23 'class' => array(), 24 'id' => '', 25 'markup' => 'html', 26 'novalidate' => false, 27 'add_nonce' => false, 28 'add_honeypot' => true, 30 29 ); 31 32 if ( $args) $settings = array_merge($defaults, $args);30 31 if ( $args ) $settings = array_merge( $defaults, $args ); 33 32 else $settings = $defaults; 34 35 foreach ( $settings as $key => $val) :33 34 foreach ( $settings as $key => $val ) : 36 35 // Try setting with user-passed setting 37 36 // If not, try the default with the same key name 38 if ( !$this->set_att($key, $val)) $this->set_att($key, $defaults[$key]);39 endforeach; 40 41 } 42 37 if ( ! $this->set_att( $key, $val ) ) $this->set_att( $key, $defaults[$key] ); 38 endforeach; 39 40 } 41 43 42 // Set attributes for the form and special fields 44 function set_att( $key, $val) {45 46 switch ( $key) :47 43 function set_att( $key, $val ) { 44 45 switch ( $key ) : 46 48 47 case 'method': 49 if ( ! in_array($val, array('post', 'get'))) return FALSE;50 break; 51 48 if ( ! in_array( $val, array( 'post', 'get' ) ) ) return false; 49 break; 50 52 51 case 'enctype': 53 if ( ! in_array($val, array('application/x-www-form-urlencoded', 'multipart/form-data'))) return FALSE;54 break; 55 52 if ( ! in_array( $val, array( 'application/x-www-form-urlencoded', 'multipart/form-data' ) ) ) return false; 53 break; 54 56 55 case 'markup': 57 if ( ! in_array($val, array('html', 'xhtml'))) return FALSE;58 break; 59 56 if ( ! in_array( $val, array( 'html', 'xhtml' ) ) ) return false; 57 break; 58 60 59 case 'class': 61 60 case 'id': 62 if ( ! $this->_check_valid_attr($val)) return FALSE;63 break; 64 61 if ( ! $this->_check_valid_attr( $val ) ) return false; 62 break; 63 65 64 case 'novalidate': 66 65 case 'add_honeypot': 67 if ( ! is_bool($val)) return FALSE;68 break; 69 66 if ( ! is_bool( $val ) ) return false; 67 break; 68 70 69 case 'add_nonce': 71 if ( ! is_string($val) && !is_bool($val)) return FALSE;72 break; 73 74 default: 75 return FALSE;76 70 if ( ! is_string( $val ) && ! is_bool( $val ) ) return false; 71 break; 72 73 default: 74 return false; 75 77 76 endswitch; 78 77 79 78 $this->form[$key] = $val; 80 81 return TRUE;82 83 } 84 79 80 return true; 81 82 } 83 85 84 // Add an input to the queue 86 function add_input( $label, $args = '', $slug = '') {87 88 if ( empty($args)) $args = array();85 function add_input( $label, $args = '', $slug = '' ) { 86 87 if ( empty( $args ) ) $args = array(); 89 88 // Create slug 90 if ( empty($slug)) $slug = $this->_make_slug($label);91 89 if ( empty( $slug ) ) $slug = $this->_make_slug( $label ); 90 92 91 $defaults = array( 93 'type' => 'text',94 'name' => $slug,95 'id' => $slug,96 'label' => $label,97 'value' => '',92 'type' => 'text', 93 'name' => $slug, 94 'id' => $slug, 95 'label' => $label, 96 'value' => '', 98 97 'placeholder' => '', 99 'class' => array(), 100 'min' => '', 101 'max' => '', 102 'step' => '', 103 'autofocus' => FALSE, 104 'checked' => FALSE, 105 'required' => FALSE, 106 'add_label' => TRUE, 107 'options' => array(), 108 'wrap_tag' => 'div', 109 'wrap_class' => array('form_field_wrap'), 110 'wrap_id' => '', 111 'wrap_style' => '' 112 98 'class' => array(), 99 'min' => '', 100 'max' => '', 101 'step' => '', 102 'autofocus' => false, 103 'checked' => false, 104 'required' => false, 105 'add_label' => true, 106 'options' => array(), 107 'wrap_tag' => 'div', 108 'wrap_class' => array( 'form_field_wrap' ), 109 'wrap_id' => '', 110 'wrap_style' => '', 111 'use_request' => true 112 113 113 ); 114 114 115 115 // Combined defaults and arguments 116 116 // Arguments override defaults 117 $args = array_merge( $defaults, $args);118 117 $args = array_merge( $defaults, $args ); 118 119 119 $this->inputs[$slug] = $args; 120 121 } 122 120 121 } 122 123 123 // Add multiple inputs to the queue 124 function add_inputs($arr) { 125 126 if (!is_array($arr)) return FALSE; 127 128 foreach ($arr as $field) : 129 $this->add_input($field[0], isset($field[1]) ? $field[1] : '', isset($field[2]) ? $field[2] : ''); 130 endforeach; 131 132 } 133 124 function add_inputs( $arr ) { 125 126 if ( ! is_array( $arr ) ) { 127 return false; 128 } 129 130 foreach ( $arr as $field ) : 131 $this->add_input( $field[0], isset( $field[1] ) ? $field[1] : '', isset( $field[2] ) ? $field[2] : '' ); 132 endforeach; 133 134 } 135 134 136 // Parse the inputs and build the form HTML 135 function build_form( $echo = TRUE) {136 137 function build_form( $echo = true ) { 138 137 139 $output = ' 138 140 <form method="' . $this->form['method'] . '"'; 139 140 if (!empty($this->form['enctype'])) $output .= ' enctype="' . $this->form['enctype'] . '"'; 141 142 if (!empty($this->form['action'])) $output .= ' action="' . $this->form['action'] . '"'; 143 144 if (!empty($this->form['id'])) $output .= ' id="' . $this->form['id'] . '"'; 145 146 if (count($this->form['class']) > 0) $output .= $this->_output_classes($this->form['class']); 147 148 if ($this->form['novalidate']) $output .= ' novalidate'; 149 141 142 if ( ! empty( $this->form['enctype'] ) ) { 143 $output .= ' enctype="' . $this->form['enctype'] . '"'; 144 } 145 146 if ( ! empty( $this->form['action'] ) ) { 147 $output .= ' action="' . $this->form['action'] . '"'; 148 } 149 150 if ( ! empty( $this->form['id'] ) ) { 151 $output .= ' id="' . $this->form['id'] . '"'; 152 } 153 154 if ( count( $this->form['class'] ) > 0 ) { 155 $output .= $this->_output_classes( $this->form['class'] ); 156 } 157 158 if ( $this->form['novalidate'] ) { 159 $output .= ' novalidate'; 160 } 161 150 162 $output .= '>'; 151 152 if ( $this->form['add_honeypot'])153 $this->add_input( 'Leave blank to submit', array(154 'name' => 'honeypot',155 'slug' => 'honeypot',156 'id' => 'form_honeypot',157 'wrap_tag' => 'div',158 'wrap_class' => array( 'form_field_wrap', 'hidden'),159 'wrap_id' => '',163 164 if ( $this->form['add_honeypot'] ) { 165 $this->add_input( 'Leave blank to submit', array( 166 'name' => 'honeypot', 167 'slug' => 'honeypot', 168 'id' => 'form_honeypot', 169 'wrap_tag' => 'div', 170 'wrap_class' => array( 'form_field_wrap', 'hidden' ), 171 'wrap_id' => '', 160 172 'wrap_style' => 'display: none' 161 )); 162 163 if ($this->form['add_nonce'] && function_exists('wp_create_nonce')) 164 $this->add_input('WordPress nonce', array( 165 'value' => wp_create_nonce($this->form['add_nonce']), 166 'add_label' => FALSE, 167 'type' => 'hidden' 168 )); 169 170 foreach ($this->inputs as $key => $val) : 171 173 ) ); 174 } 175 176 if ( $this->form['add_nonce'] && function_exists( 'wp_create_nonce' ) ) { 177 $this->add_input( 'WordPress nonce', array( 178 'value' => wp_create_nonce( $this->form['add_nonce'] ), 179 'add_label' => false, 180 'type' => 'hidden' 181 ) ); 182 } 183 184 foreach ( $this->inputs as $key => $val ) : 185 172 186 $min_max_range = $element = $end = $attr = $field = $label_html = ''; 173 187 174 188 // Set the field value to incoming 175 $val['value'] = isset($_REQUEST[$val['name']]) && !empty($_REQUEST[$val['name']]) ? 176 $_REQUEST[$val['name']] : 177 $val['value']; 178 179 switch ($val['type']) : 180 181 case 'html': 182 $element = ''; 183 $end = $val['label']; 184 break; 185 189 if ( isset( $_REQUEST[$val['name']] ) && ! empty( $_REQUEST[$val['name']] ) && $val['use_request'] ) { 190 $val['value'] = $_REQUEST[$val['name']]; 191 } 192 193 switch ( $val['type'] ) : 194 186 195 case 'title': 187 196 $element = ''; 188 $end = '197 $end = ' 189 198 <h3>' . $val['label'] . '</h3>'; 190 199 break; 191 200 192 201 case 'textarea': 193 202 $element = 'textarea'; 194 $end = '>' . $val['value'] . '</textarea>';203 $end = '>' . $val['value'] . '</textarea>'; 195 204 break; 196 205 197 206 case 'select': 198 207 $element = 'select'; 199 $end = '>' . $this->_output_options_select($val['options']) . '208 $end = '>' . $this->_output_options_select( $val['options'], $val['value'] ) . ' 200 209 </select>'; 201 210 break; 202 211 203 212 case 'checkbox': 204 if ( count($val['options']) > 0) :205 $element = '';206 $end = $this->_output_options_checkbox($val['options'], $val['name']);213 if ( count( $val['options'] ) > 0 ) : 214 $element = ''; 215 $end = $this->_output_options_checkbox( $val['options'], $val['name'] ); 207 216 $label_html = '<p class="checkbox_header">' . $val['label'] . '</p>'; 208 217 break; 209 218 endif; 210 219 211 220 case 'radio': 212 if ( count($val['options']) > 0) :213 $element = '';214 $end = $this->_output_options_radios($val['options'], $val['name']);221 if ( count( $val['options'] ) > 0 ) : 222 $element = ''; 223 $end = $this->_output_options_radios( $val['options'], $val['name'] ); 215 224 $label_html = '<p class="checkbox_header">' . $val['label'] . '</p>'; 216 225 break; 217 226 endif; 218 227 219 228 case 'range': 220 229 case 'number': 221 $min_max_range .= ! empty($val['min']) ? ' min="' . $val['min'] . '"' : '';222 $min_max_range .= ! empty($val['max']) ? ' max="' . $val['max'] . '"' : '';223 $min_max_range .= ! empty($val['step']) ? ' step="' . $val['step'] . '"' : '';224 230 $min_max_range .= ! empty( $val['min'] ) ? ' min="' . $val['min'] . '"' : ''; 231 $min_max_range .= ! empty( $val['max'] ) ? ' max="' . $val['max'] . '"' : ''; 232 $min_max_range .= ! empty( $val['step'] ) ? ' step="' . $val['step'] . '"' : ''; 233 225 234 case 'submit': 226 $this->has_submit = TRUE;227 $val['value'] = $val['label'];228 235 $this->has_submit = true; 236 $val['value'] = $val['label']; 237 229 238 default : 230 239 $element = 'input'; … … 233 242 $end .= $this->field_close(); 234 243 break; 235 244 236 245 endswitch; 237 238 $id = !empty($val['id']) ? ' id="' . $val['id'] . '"' : '';239 $class = count( $val['class']) ? ' class="' . $this->_output_classes($val['class']) . '"' : '';240 $attr = $val['autofocus'] ? ' autofocus' : '';241 $attr = $val['checked'] ? ' checked' : '';242 $attr = $val['required'] ? ' required' : '';243 246 247 $id = ! empty( $val['id'] ) ? ' id="' . $val['id'] . '"' : ''; 248 $class = count( $val['class'] ) ? ' class="' . $this->_output_classes( $val['class'] ) . '"' : ''; 249 $attr = $val['autofocus'] ? ' autofocus' : ''; 250 $attr = $val['checked'] ? ' checked' : ''; 251 $attr = $val['required'] ? ' required' : ''; 252 244 253 // Build the label 245 if ( !empty($label_html)) :254 if ( ! empty( $label_html ) ) : 246 255 $field .= $label_html; 247 elseif ( $val['add_label'] && $val['type'] != 'hidden' && $val['type'] != 'submit' && $val['type'] != 'title' && $val['type'] != 'html') :256 elseif ( $val['add_label'] && $val['type'] != 'hidden' && $val['type'] != 'submit' ) : 248 257 $val['label'] .= $val['required'] ? ' <strong>*</strong>' : ''; 249 258 $field .= ' 250 259 <label for="' . $val['id'] . '">' . $val['label'] . '</label>'; 251 260 endif; 252 253 if ( !empty($element))261 262 if ( ! empty( $element ) ) 254 263 $field .= ' 255 264 <' . $element . $id . ' name="' . $val['name'] . '"' . $min_max_range . $attr . $end; 256 else 265 else 257 266 $field .= $end; 258 267 259 268 // Parse and create wrap, if needed 260 if ( $val['type'] != 'hidden' && $val['type'] != 'html' && !empty($val['wrap_tag'])) :261 269 if ( $val['type'] != 'hidden' && ! empty( $val['wrap_tag'] ) ) : 270 262 271 $wrap_before = ' 263 272 <' . $val['wrap_tag']; 264 $wrap_before .= count( $val['wrap_class']) > 0 ? $this->_output_classes($val['wrap_class']) : '';265 $wrap_before .= ! empty($val['wrap_style']) ? ' style="' . $val['wrap_style'] . '"' : '';266 $wrap_before .= ! empty($val['wrap_id']) ? ' id="' . $val['wrap_id'] . '"' : '';273 $wrap_before .= count( $val['wrap_class'] ) > 0 ? $this->_output_classes( $val['wrap_class'] ) : ''; 274 $wrap_before .= ! empty( $val['wrap_style'] ) ? ' style="' . $val['wrap_style'] . '"' : ''; 275 $wrap_before .= ! empty( $val['wrap_id'] ) ? ' id="' . $val['wrap_id'] . '"' : ''; 267 276 $wrap_before .= '>'; 268 277 269 278 $wrap_after = ' 270 279 </' . $val['wrap_tag'] . '>'; 271 280 272 281 $output .= $wrap_before . $field . $wrap_after; 273 else : 282 else : 274 283 $output .= $field; 275 284 endif; 276 277 endforeach; 278 279 if ( ! $this->has_submit) $output .= '285 286 endforeach; 287 288 if ( ! $this->has_submit ) $output .= ' 280 289 <div class="form_field_wrap"> 281 290 <input type="submit" value="Submit" name="submit"> 282 291 </div>'; 283 292 284 293 $output .= ' 285 294 </form>'; 286 287 if ( $echo) echo $output;295 296 if ( $echo ) echo $output; 288 297 else return $output; 289 290 } 291 298 299 } 300 292 301 // :FIXIT: Add validation for classes and ids 293 private function _check_valid_attr( $string) {294 295 $result = TRUE;296 302 private function _check_valid_attr( $string ) { 303 304 $result = true; 305 297 306 // Check $name for correct characters 298 307 // "^[a-zA-Z0-9_-]*$" 299 308 300 309 return $result; 301 302 } 303 310 311 } 312 304 313 // Easy way to auto-close fields, if necessary 305 314 function field_close() { 306 307 return $this->form['markup'] === 'xhtml' ? ' />' : '>';308 309 } 310 311 315 316 return $this->form['markup'] === 'xhtml' ? ' />' : '>'; 317 318 } 319 320 312 321 // Create a slug from a label name 313 private function _make_slug( $string) {314 322 private function _make_slug( $string ) { 323 315 324 $result = ''; 316 317 $result = str_replace( '"', '', $string);318 $result = str_replace( "'", '', $result);319 $result = str_replace( '_', '-', $result);320 $result = preg_replace( '~[\W\s]~', '-', $result);321 322 $result = strtolower( $result);323 325 326 $result = str_replace( '"', '', $string ); 327 $result = str_replace( "'", '', $result ); 328 $result = str_replace( '_', '-', $result ); 329 $result = preg_replace( '~[\W\s]~', '-', $result ); 330 331 $result = strtolower( $result ); 332 324 333 return $result; 325 326 } 327 334 335 } 336 328 337 // Parses and builds the classes in multiple places 329 private function _output_classes( $arr) {330 338 private function _output_classes( $arr ) { 339 331 340 $output = ''; 332 333 if ( count($arr) > 0) :341 342 if ( count( $arr ) > 0 ) : 334 343 $output .= ' class="'; 335 foreach ( $arr as $class) :344 foreach ( $arr as $class ) : 336 345 $output .= $class . ' '; 337 346 endforeach; 338 347 $output .= '"'; 339 348 endif; 340 349 341 350 return $output; 342 343 } 344 351 352 } 353 345 354 // Builds the select input output 346 private function _output_options_select( $arr) {355 private function _output_options_select( $arr, $value ) { 347 356 $output = ''; 348 foreach ($arr as $val => $opt) : 349 $output .= ' 350 <option value="' . $val . '">' . $opt . '</option>'; 357 foreach ( $arr as $val => $opt ) : 358 $selected = $value == $val ? ' selected' : ''; 359 $output .= ' 360 <option value="' . $val . '"' . $selected . '>' . $opt . '</option>'; 351 361 endforeach; 352 362 return $output; 353 363 } 354 364 355 365 // Builds the radio button output 356 private function _output_options_radios( $arr, $name) {366 private function _output_options_radios( $arr, $name ) { 357 367 $output = ''; 358 foreach ( $arr as $val => $opt) :359 $slug = $this->_make_slug( $opt);368 foreach ( $arr as $val => $opt ) : 369 $slug = $this->_make_slug( $opt ); 360 370 $output .= ' 361 371 <input type="radio" name="' . $name . '[]" value="' . $val . '" id="' . $slug . '"'; … … 366 376 return $output; 367 377 } 368 378 369 379 // Builds the multiple checkbox output 370 private function _output_options_checkbox( $arr, $name) {380 private function _output_options_checkbox( $arr, $name ) { 371 381 $output = ''; 372 foreach ( $arr as $val => $opt) :373 $slug = $this->_make_slug( $opt);382 foreach ( $arr as $val => $opt ) : 383 $slug = $this->_make_slug( $opt ); 374 384 $output .= ' 375 385 <input type="checkbox" name="' . $name . '[]" value="' . $val . '" id="' . $slug . '"'; … … 380 390 return $output; 381 391 } 382 392 383 393 } -
proper-contact-form/trunk/inc/helpers.php
r646683 r782825 1 1 <?php 2 2 3 if (! function_exists('proper_get_content_array')) { 4 function proper_get_content_array($type = 'page') { 5 6 $content = array( 7 '' => 'None' 8 ); 3 if ( ! function_exists( 'proper_get_content_array' ) ) { 4 function proper_get_content_array( $type = 'page' ) { 9 5 10 $items = get_posts(array( 11 'post_type' => $type, 12 'numberposts' => -1 13 )); 14 15 16 if (!empty($items)) : 17 foreach ($items as $item) : 18 $content[$item->ID] = $item->post_title; 19 endforeach; 20 endif; 21 22 return $content; 23 24 } 6 $content = array( 7 '' => 'None' 8 ); 9 10 $items = get_posts( array( 11 'post_type' => $type, 12 'numberposts' => - 1 13 ) ); 14 15 16 if ( ! empty( $items ) ) : 17 foreach ( $items as $item ) : 18 $content[$item->ID] = $item->post_title; 19 endforeach; 20 endif; 21 22 return $content; 23 24 } 25 25 } 26 26 27 if ( ! function_exists('proper_get_textarea_opts')) {28 function proper_get_textarea_opts($txt) {29 30 $opts = array();31 32 if (empty($txt)) return $opts;33 34 $txt = str_replace("\r", "\n", $txt);35 $txt_arr = explode("\n", $txt);36 37 foreach ($txt_arr as $opt) :38 39 $opt = trim($opt);40 if (empty($opt)) continue;41 42 $opts[$opt] = $opt;43 44 endforeach;45 46 return $opts;47 48 }27 if ( ! function_exists( 'proper_get_textarea_opts' ) ) { 28 function proper_get_textarea_opts( $txt ) { 29 30 $opts = array(); 31 32 if ( empty( $txt ) ) return $opts; 33 34 $txt = str_replace( "\r", "\n", $txt ); 35 $txt_arr = explode( "\n", $txt ); 36 37 foreach ( $txt_arr as $opt ) : 38 39 $opt = trim( $opt ); 40 if ( empty( $opt ) ) continue; 41 42 $opts[stripslashes( $opt )] = stripslashes( $opt ); 43 44 endforeach; 45 46 return $opts; 47 48 } 49 49 } 50 50 51 if (! function_exists('proper_display_errors')) { 52 function proper_display_errors($errs) { 53 $output = ' 51 // Display formatted error listing 52 if ( ! function_exists( 'proper_display_errors' ) ) { 53 function proper_display_errors( $errs ) { 54 $output = ' 54 55 <div class="proper_error_box"> 55 56 <h6>Please correct the following errors:</h6> 56 57 <ul>'; 57 58 foreach ($errs as $err) :59 $output .= "58 59 foreach ( $errs as $err ) : 60 $output .= " 60 61 <li>$err</li>"; 61 endforeach;62 63 $output .= '62 endforeach; 63 64 $output .= ' 64 65 </ul> 65 66 </div>'; 66 67 return $output; 67 68 return $output; 69 } 68 70 } 71 72 // Get blacklist IPs and emails from the Discussion settings 73 if ( ! function_exists( 'proper_get_blacklist' ) ) { 74 function proper_get_blacklist() { 75 $final_blocked_arr = array(); 76 77 $blocked = get_option( 'blacklist_keys' ); 78 $blocked = str_replace( "\r", "\n", $blocked ); 79 80 $blocked_arr = explode( "\n", $blocked ); 81 $blocked_arr = array_map( 'trim', $blocked_arr ); 82 83 foreach ( $blocked_arr as $ip_or_email ) { 84 $ip_or_email = trim( $ip_or_email ); 85 if ( 86 filter_var( $ip_or_email, FILTER_VALIDATE_IP ) || 87 filter_var( $ip_or_email, FILTER_VALIDATE_EMAIL ) 88 ) { 89 $final_blocked_arr[] = $ip_or_email; 90 } 91 } 92 93 return $final_blocked_arr; 94 } 69 95 } -
proper-contact-form/trunk/proper-contact-form.php
r694646 r782825 1 1 <?php 2 3 2 /* 4 3 Plugin Name: PROPER Contact Form 5 4 Plugin URI: http://theproperweb.com/shipped/wp/proper-contact-form 6 5 Description: A better contact form processor 7 Version: 0.9. 5.16 Version: 0.9.6 8 7 Author: PROPER Development 9 8 Author URI: http://theproperweb.com … … 11 10 */ 12 11 13 // Help functions 14 require_once(WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__)) . '/inc/helpers.php'); 15 16 function proper_contact_form($atts, $content = NULL) { 17 18 if ( 19 isset($_SESSION['propercfp_sent']) && 20 $_SESSION['propercfp_sent'] === 'yes' 21 ) : 22 unset($_SESSION['propercfp_sent']); 12 13 // Make sure we don't expose any info if called directly 14 // Thanks Akismet! 15 if ( ! function_exists( 'add_action' ) ) { 16 die( 'Nothing to do...' ); 17 } 18 19 // Important constants 20 define( 'PROPER_CONTACT_VERSION', '0.9.6' ); 21 define( 'PROPER_CONTACT_URL', plugin_dir_url( __FILE__ ) ); 22 23 // Required helper functions 24 include_once( dirname( __FILE__ ) . '/inc/helpers.php' ); 25 include_once( dirname( __FILE__ ) . '/inc/settings.php' ); 26 include_once( dirname( __FILE__ ) . '/inc/widget.php' ); 27 28 /** 29 * Outputs the contact form or a confirmation message is submitted 30 * 31 * @param $atts 32 * @param null $content 33 * 34 * @return string 35 */ 36 37 add_shortcode( 'proper_contact_form', 'proper_contact_form' ); 38 function proper_contact_form( $atts, $content = NULL ) { 39 40 // Looking for a submitted form if not redirect 41 if ( isset( $_SESSION['propercfp_sent'] ) && $_SESSION['propercfp_sent'] === 'yes' ) { 42 unset( $_SESSION['propercfp_sent'] ); 23 43 return ' 24 44 <div class="proper_contact_form_wrap"> 25 <h2>' . proper_contact_get_key('propercfp_label_submit') . '</h2>45 <h2>' . sanitize_text_field( proper_contact_get_key( 'propercfp_label_submit' ) ) . '</h2> 26 46 </div>'; 27 endif;47 } 28 48 29 49 // FormBuilder 30 require_once(plugin_dir_path( __FILE__ ) . '/inc/FormBuilder.php');31 50 // https://github.com/joshcanhelp/php-form-builder 51 require_once( dirname( __FILE__ ) . '/inc/FormBuilder.php' ); 32 52 $form = new ThatFormBuilder; 33 53 34 $form->set_att('id', 'proper_contact_form_' . get_the_id());35 $form->set_att( 'class', array('proper_contact_form'));36 $form->set_att( 'add_nonce', get_bloginfo('admin_email'));37 if (proper_contact_get_key('propercfp_html5_no_validate') === '') {38 $form->set_att('novalidate', TRUE);39 }40 54 // TODO: make a better ID system 55 $form->set_att( 'id', 'proper_contact_form_' . ( get_the_id() ? get_the_id() : 1 ) ); 56 $form->set_att( 'class', array( 'proper_contact_form' ) ); 57 $form->set_att( 'add_nonce', get_bloginfo( 'admin_email' ) ); 58 if ( ! proper_contact_get_key( 'propercfp_html5_no_validate' ) ) { 59 $form->set_att( 'novalidate', TRUE ); 60 } 41 61 42 62 // Add name field if selected on the settings page 43 if( proper_contact_get_key('propercfp_name_field') ) : 44 $required = proper_contact_get_key('propercfp_name_field') === 'req' ? TRUE : FALSE; 45 $form->add_input(stripslashes(proper_contact_get_key('propercfp_label_name')), array( 46 'required' => $required, 47 'wrap_class' => isset($_SESSION['cfp_contact_errors']['contact-name']) 48 ? array('form_field_wrap', 'error') 49 : array('form_field_wrap') 50 ), 'contact-name'); 51 endif; 63 $propercfp_name_field = proper_contact_get_key( 'propercfp_name_field' ); 64 if ( $propercfp_name_field ) { 65 $required = $propercfp_name_field === 'req' ? TRUE : FALSE; 66 $wrap_classes = array( 'form_field_wrap', 'contact_name_wrap' ); 67 68 // If this field was submitted with invalid data 69 if ( isset( $_SESSION['cfp_contact_errors']['contact-name'] ) ) { 70 $wrap_classes[] = 'error'; 71 } 72 73 // Build the input with the correct label, options, and name 74 $form->add_input( 75 stripslashes( sanitize_text_field( proper_contact_get_key( 'propercfp_label_name' ) ) ), 76 array( 77 'required' => $required, 78 'wrap_class' => $wrap_classes 79 ), 80 'contact-name' 81 ); 82 83 } 52 84 53 85 // Add email field if selected on the settings page 54 if( proper_contact_get_key('propercfp_email_field') ) : 55 $required = proper_contact_get_key('propercfp_email_field') === 'req' ? TRUE : FALSE; 56 $form->add_input(stripslashes(proper_contact_get_key('propercfp_label_email')), array( 57 'required' => $required, 58 'type' => 'email', 59 'wrap_class' => isset($_SESSION['cfp_contact_errors']['contact-email']) 60 ? array('form_field_wrap', 'error') 61 : array('form_field_wrap') 62 ), 'contact-email'); 63 endif; 86 $propercfp_email_field = proper_contact_get_key( 'propercfp_email_field' ); 87 if ( $propercfp_email_field ) { 88 $required = $propercfp_email_field === 'req' ? TRUE : FALSE; 89 $wrap_classes = array( 'form_field_wrap', 'contact_email_wrap' ); 90 91 // If this field was submitted with invalid data 92 if ( isset( $_SESSION['cfp_contact_errors']['contact-email'] ) ) { 93 $wrap_classes[] = 'error'; 94 } 95 96 // Build the input with the correct label, options, and name 97 $form->add_input( 98 stripslashes( sanitize_text_field( proper_contact_get_key( 'propercfp_label_email' ) ) ), 99 array( 100 'required' => $required, 101 'type' => 'email', 102 'wrap_class' => $wrap_classes 103 ), 104 'contact-email' 105 ); 106 107 } 64 108 65 109 // Add phone field if selected on the settings page 66 if( proper_contact_get_key('propercfp_phone_field') ) : 67 $required = proper_contact_get_key('propercfp_phone_field') === 'req' ? TRUE : FALSE; 68 $form->add_input(stripslashes(proper_contact_get_key('propercfp_label_phone')), array( 69 'required' => $required, 70 'wrap_class' => isset( $_SESSION['cfp_contact_errors']['contact-phone'] ) 71 ? array ( 'form_field_wrap', 'error' ) 72 : array ( 'form_field_wrap' ) 73 ), 'contact-phone'); 74 endif; 75 76 // Add reasons drop-down 77 $reasons = trim(proper_contact_get_key('propercfp_reason')); 78 $options = proper_get_textarea_opts( $reasons ); 79 if (!empty($options)) { 80 array_unshift($options, 'Select one...'); 81 $form->add_input(stripslashes(proper_contact_get_key('propercfp_label_reason')), array( 82 'type' => 'select', 83 'options' => $options 84 ), 'contact-reasons'); 85 } 86 87 88 // Comment field 89 $form->add_input(stripslashes(proper_contact_get_key('propercfp_label_comment')), array( 90 'required' => TRUE, 91 'type' => 'textarea', 92 'wrap_class' => isset($_SESSION['cfp_contact_errors']['question-or-comment']) ? 93 array('form_field_wrap', 'error') : 94 array('form_field_wrap') 95 ), 'question-or-comment'); 110 $propercfp_phone_field = proper_contact_get_key( 'propercfp_phone_field' ); 111 if ( $propercfp_phone_field ) { 112 $required = $propercfp_phone_field === 'req' ? TRUE : FALSE; 113 $wrap_classes = array( 'form_field_wrap', 'contact_phone_wrap' ); 114 115 // If this field was submitted with invalid data 116 if ( isset( $_SESSION['cfp_contact_errors']['contact-phone'] ) ) { 117 $wrap_classes[] = 'error'; 118 } 119 120 // Build the input with the correct label, options, and name 121 $form->add_input( 122 stripslashes( sanitize_text_field( proper_contact_get_key( 'propercfp_label_phone' ) ) ), 123 array( 124 'required' => $required, 125 'wrap_class' => $wrap_classes 126 ), 127 'contact-phone' 128 ); 129 } 130 131 // Add reasons drop-down if any have been entered 132 $options = proper_get_textarea_opts( trim( proper_contact_get_key( 'propercfp_reason' ) ) ); 133 if ( ! empty( $options ) ) { 134 135 // Prepare the options array 136 $options = array_map( 'trim', $options ); 137 $options = array_map( 'sanitize_text_field', $options ); 138 array_unshift( $options, 'Select one...' ); 139 140 // Build the select with the correct label, options, and name 141 $form->add_input( 142 stripslashes( sanitize_text_field( proper_contact_get_key( 'propercfp_label_reason' ) ) ), 143 array( 144 'type' => 'select', 145 'wrap_class' => array( 146 'form_field_wrap', 147 'contact_reasons_wrap' 148 ), 149 'options' => $options 150 ), 151 'contact-reasons' 152 ); 153 } 154 155 // Comment field, required to be displayed 156 $wrap_classes = array( 'form_field_wrap', 'question_or_comment_wrap' ); 157 if ( isset( $_SESSION['cfp_contact_errors']['question-or-comment'] ) ) { 158 $wrap_classes[] = 'error'; 159 } 160 $form->add_input( 161 stripslashes( proper_contact_get_key( 'propercfp_label_comment' ) ), 162 array( 163 'required' => TRUE, 164 'type' => 'textarea', 165 'wrap_class' => $wrap_classes 166 ), 167 'question-or-comment' 168 ); 169 170 // Add a math CAPTCHA, if desired 171 if ( proper_contact_get_key( 'propercfp_captcha_field' ) ) { 172 173 $wrap_classes = array( 'form_field_wrap', 'math_captcha_wrap' ); 174 175 // If this field was submitted with invalid data 176 if ( isset( $_SESSION['cfp_contact_errors']['math-captcha'] ) ) { 177 $wrap_classes[] = 'error'; 178 } 179 180 $num_1 = mt_rand( 1, 10 ); 181 $num_2 = mt_rand( 1, 10 ); 182 $sum = $num_1 + $num_2; 183 184 // Build the input with the correct label, options, and name 185 $form->add_input( 186 stripslashes( sanitize_text_field( proper_contact_get_key( 'propercfp_label_math' ) ) ) . " $num_1 + $num_2", 187 array( 188 'required' => TRUE, 189 'wrap_class' => $wrap_classes, 190 'use_request' => false 191 ), 192 'math-captcha' 193 ); 194 195 $form->add_input( 196 'Math CAPTCHA sum', 197 array( 198 'type' => 'hidden', 199 'value' => $sum, 200 'use_request' => FALSE 201 ), 202 'math-captcha-sum' 203 ); 204 205 } 96 206 97 207 // Submit button 98 $form->add_input( proper_contact_get_key( 'propercfp_label_submit_btn' ), array( 99 'type' => 'submit' 100 ), 'submit'); 101 102 // Referring site 103 $form->add_input('Contact Referrer', array( 104 'type' => 'hidden', 105 'value' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '' 106 )); 107 108 // Referring page 109 if (isset($_REQUEST['src']) || isset($_REQUEST['ref'])) : 110 $form->add_input('Referring page', array( 111 'type' => 'hidden', 112 'value' => isset($_REQUEST['src']) ? $_REQUEST['src'] : $_REQUEST['ref'] 113 )); 114 endif; 115 208 $form->add_input( 209 stripslashes( sanitize_text_field( proper_contact_get_key( 'propercfp_label_submit_btn' ) ) ), 210 array( 211 'type' => 'submit', 212 'wrap_class' => array( 213 'form_field_wrap', 'submit_wrap' 214 ) 215 ), 216 'submit' 217 ); 218 219 // Referring site or page, if any 220 if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) { 221 $form->add_input( 222 'Contact Referrer', 223 array( 224 'type' => 'hidden', 225 'value' => $_SERVER['HTTP_REFERER'] 226 ) 227 ); 228 } 229 230 // Referring page, if sent via URL query 231 if ( ! empty( $_REQUEST['src'] ) || ! empty( $_REQUEST['ref'] ) ) { 232 $form->add_input( 233 'Referring page', array( 234 'type' => 'hidden', 235 'value' => ! empty( $_REQUEST['src'] ) ? $_REQUEST['src'] : $_REQUEST['ref'] 236 ) 237 ); 238 } 239 240 // Are there any submission errors? 116 241 $errors = ''; 117 if (isset($_SESSION['cfp_contact_errors']) && !empty($_SESSION['cfp_contact_errors'])) : 118 $errors = proper_display_errors($_SESSION['cfp_contact_errors']); 119 unset($_SESSION['cfp_contact_errors']); 120 endif; 121 242 if ( ! empty( $_SESSION['cfp_contact_errors'] ) ) { 243 $errors = proper_display_errors( $_SESSION['cfp_contact_errors'] ); 244 unset( $_SESSION['cfp_contact_errors'] ); 245 } 246 247 // Display that beautiful form! 122 248 return ' 123 249 <div class="proper_contact_form_wrap"> 124 ' . $errors . $form->build_form(FALSE) . ' 250 ' . $errors . ' 251 ' . $form->build_form( FALSE ) . ' 125 252 </div>'; 126 253 127 254 } 128 add_shortcode( 'proper_contact_form', 'proper_contact_form' ); 129 255 256 /** 257 * Process the incoming contact form data, if any 258 */ 259 add_action( 'template_redirect', 'cfp_process_contact' ); 130 260 function cfp_process_contact() { 131 261 132 // If POST, nonce and honeypot are not set, escape 133 if (empty($_POST)) return; 134 if (! isset($_POST['wordpress-nonce'])) return; 135 if (! isset($_POST['honeypot'])) return; 262 // If POST, nonce and honeypot are not set, beat it 263 if ( 264 empty( $_POST ) || 265 empty( $_POST['wordpress-nonce'] ) || 266 ! isset( $_POST['honeypot'] ) 267 ) { 268 return false; 269 } 136 270 137 271 // Session variable for form errors 138 272 $_SESSION['cfp_contact_errors'] = array(); 139 273 140 // If nonce is not passed or honeypot is not empty, escape 141 if (! wp_verify_nonce($_POST['wordpress-nonce'], get_bloginfo('admin_email'))) { 142 $_SESSION['cfp_contact_errors']['nonce'] = 'Nonce failed!'; 143 } 144 145 if (! empty($_POST['honeypot'])) { 146 $_SESSION['cfp_contact_errors']['honeypot'] = 'Form submission failed!'; 147 } 148 274 // If nonce is not valid, beat it 275 if ( ! wp_verify_nonce( $_POST['wordpress-nonce'], get_bloginfo( 'admin_email' ) ) ) { 276 $_SESSION['cfp_contact_errors']['nonce'] = __( 'Nonce failed!', 'proper-contact' ); 277 return false; 278 } 279 280 // If the honeypot caught a bear, beat it 281 if ( ! empty( $_POST['honeypot'] ) ) { 282 $_SESSION['cfp_contact_errors']['honeypot'] = __( 'Form submission failed!', 'proper-contact' ); 283 return false; 284 } 285 286 // Start the body of the contact email 149 287 $body = " 150 *** Contact form submission on " . get_bloginfo('name') . " (" . site_url() . ") *** \n\n";288 *** " . __( 'Contact form submission on', 'proper-contact' ) . " " . get_bloginfo( 'name' ) . " (" . site_url() . ") *** \n\n"; 151 289 152 290 // Sanitize and validate name 153 $contact_name = isset($_POST['contact-name']) ? sanitize_text_field(trim($_POST['contact-name'])) : ''; 154 if (proper_contact_get_key('propercfp_name_field') === 'req' && empty($contact_name)) { 155 $_SESSION['cfp_contact_errors']['contact-name'] = proper_contact_get_key('propercfp_label_err_name'); 156 } elseif ( !empty( $contact_name ) ) { 291 $contact_name = isset( $_POST['contact-name'] ) ? 292 sanitize_text_field( trim( $_POST['contact-name'] ) ) : 293 ''; 294 295 // Do we require an email address? 296 if ( proper_contact_get_key( 'propercfp_name_field' ) === 'req' && empty( $contact_name ) ) { 297 $_SESSION['cfp_contact_errors']['contact-name'] = proper_contact_get_key( 'propercfp_label_err_name' ); 298 // If not required and empty, leave it out 299 } 300 elseif ( ! empty( $contact_name ) ) { 157 301 $body .= stripslashes( proper_contact_get_key( 'propercfp_label_name' ) ) . ": $contact_name \r"; 158 302 } 159 303 160 304 // Sanitize and validate email 161 $contact_email = isset($_POST['contact-email']) ? sanitize_email($_POST['contact-email']) : ''; 162 if (proper_contact_get_key('propercfp_email_field') === 'req' && ! filter_var($contact_email, FILTER_VALIDATE_EMAIL) ) { 163 $_SESSION['cfp_contact_errors']['contact-email'] = proper_contact_get_key('propercfp_label_err_email'); 164 } elseif (!empty($contact_email)) { 165 $body .= stripslashes( proper_contact_get_key( 'propercfp_label_email' ) ) . ": $contact_email \r 166 Google: https://www.google.com/#q=$contact_email \r"; 305 $contact_email = isset( $_POST['contact-email'] ) ? 306 sanitize_email( $_POST['contact-email'] ) : 307 ''; 308 309 // If required, is it valid? 310 if ( 311 proper_contact_get_key( 'propercfp_email_field' ) === 'req' && 312 ! filter_var( $contact_email, FILTER_VALIDATE_EMAIL ) 313 ) { 314 $_SESSION['cfp_contact_errors']['contact-email'] = proper_contact_get_key( 'propercfp_label_err_email' ); 315 // If not required and empty, leave it out 316 } 317 elseif ( ! empty( $contact_email ) ) { 318 $body .= stripslashes( proper_contact_get_key( 'propercfp_label_email' ) ) 319 . ": $contact_email \r" 320 . __( 'Google it', 'proper-contact' ) 321 . ": https://www.google.com/#q=$contact_email \r"; 167 322 } 168 323 169 324 // Sanitize phone number 170 $contact_phone = isset($_POST['contact-phone']) ? sanitize_text_field($_POST['contact-phone']) : ''; 171 if (proper_contact_get_key('propercfp_phone_field') === 'req' && empty($contact_phone) ) { 172 $_SESSION['cfp_contact_errors']['contact-phone'] = proper_contact_get_key('propercfp_label_err_phone'); 173 } elseif (!empty($contact_phone)) { 174 $body .= stripslashes( proper_contact_get_key( 'propercfp_label_phone' ) ) . ": $contact_phone \r"; 325 $contact_phone = isset( $_POST['contact-phone'] ) ? 326 sanitize_text_field( $_POST['contact-phone'] ) : 327 ''; 328 329 // Do we require a phone number? 330 if ( proper_contact_get_key( 'propercfp_phone_field' ) === 'req' && empty( $contact_phone ) ) { 331 $_SESSION['cfp_contact_errors']['contact-phone'] = proper_contact_get_key( 'propercfp_label_err_phone' ); 332 // If not required and empty, leave it out 333 } 334 elseif ( ! empty( $contact_phone ) ) { 335 $body .= stripslashes( proper_contact_get_key( 'propercfp_label_phone' ) ) 336 . ": $contact_phone \r" 337 . __( 'Google it', 'proper-contact' ) 338 . ": https://www.google.com/#q=$contact_phone\r"; 175 339 } 176 340 177 341 // Sanitize contact reason 178 $contact_reason = isset($_POST['contact-reasons']) ? sanitize_text_field($_POST['contact-reasons']) : ''; 179 if (!empty($contact_reason)) { 342 $contact_reason = isset( $_POST['contact-reasons'] ) ? 343 sanitize_text_field( $_POST['contact-reasons'] ) : 344 ''; 345 346 // If empty, leave it out 347 if ( ! empty( $contact_reason ) ) { 348 $contact_reason = stripslashes( $contact_reason ); 180 349 $body .= stripslashes( proper_contact_get_key( 'propercfp_label_reason' ) ) . ": $contact_reason \r"; 181 350 } 182 351 183 352 // Sanitize and validate comments 184 $contact_comment = filter_var((trim($_POST['question-or-comment'])), FILTER_SANITIZE_STRING); 185 if (empty($contact_comment)) { 186 $_SESSION['cfp_contact_errors']['question-or-comment'] = proper_contact_get_key('propercfp_label_err_no_content'); 187 } else { 188 $body .= "\n\n" . stripslashes( proper_contact_get_key( 'propercfp_label_comment' ) ) . ": " . stripslashes($contact_comment) . " \n\n"; 353 $contact_comment = sanitize_text_field( trim( $_POST['question-or-comment'] ) ); 354 if ( empty( $contact_comment ) ) { 355 $_SESSION['cfp_contact_errors']['question-or-comment'] = 356 sanitize_text_field( proper_contact_get_key( 'propercfp_label_err_no_content' ) ); 357 } 358 else { 359 $body .= "\n\n" . stripslashes( proper_contact_get_key( 'propercfp_label_comment' ) ) 360 . ": " . stripslashes( $contact_comment ) . " \n\n"; 361 } 362 363 // Check the math CAPTCHA, if present 364 if ( proper_contact_get_key( 'propercfp_captcha_field' ) ) { 365 $captcha_sum = isset( $_POST['math-captcha'] ) ? intval( $_POST['math-captcha'] ) : 0; 366 if ( $captcha_sum != (int) $_POST['math-captcha-sum'] ) { 367 $_SESSION['cfp_contact_errors']['math-captcha'] = 368 sanitize_text_field( proper_contact_get_key( 'propercfp_label_err_captcha' ) ); 369 } 189 370 } 190 371 191 372 // Sanitize and validate IP 192 $contact_ip = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP); 193 if (!empty($contact_ip)) { 373 $contact_ip = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP ); 374 375 // If valid and present, create a link to an IP search 376 if ( ! empty( $contact_ip ) ) { 194 377 $body .= "IP address: $contact_ip \r 195 378 IP search: http://whatismyipaddress.com/ip/$contact_ip \n\n"; 196 379 } 197 380 198 // Sanitize and prepare referrer 199 $contact_referrer = sanitize_text_field($_POST['contact-referrer']); 200 if (!empty($contact_referrer)) { 201 $body .= "Came from: $contact_referrer \r"; 202 } 203 204 $body .= 'Sent from page: ' . get_permalink(get_the_id()); 205 206 if (empty($_SESSION['cfp_contact_errors'])) : 207 208 $site_email = proper_contact_get_key('propercfp_email'); 209 $site_name = get_bloginfo('name'); 210 381 // Sanitize and prepare referrer; 382 if ( ! empty( $_POST['contact-referrer'] ) ) { 383 $body .= "Came from: " . sanitize_text_field( $_POST['contact-referrer'] ) . " \r"; 384 } 385 386 // Show the page this contact form was submitted on 387 $body .= 'Sent from page: ' . get_permalink( get_the_id() ); 388 389 // Check the blacklist 390 $blocked = proper_get_blacklist(); 391 if ( ! empty( $blocked ) ) { 392 if ( 393 in_array( $contact_email, $blocked ) || 394 in_array( $contact_ip, $blocked ) 395 ) { 396 $_SESSION['cfp_contact_errors']['blacklist-blocked'] = 'Form submission blocked!'; 397 return false; 398 } 399 } 400 401 // No errors? Go ahead and process the contact 402 if ( empty( $_SESSION['cfp_contact_errors'] ) ) { 403 404 $site_email = proper_contact_get_key( 'propercfp_email' ); 405 $site_name = get_bloginfo( 'name' ); 406 407 // No name? Use the email address, if one is present 211 408 if ( empty( $contact_name ) ) { 212 $contact_name = !empty( $contact_email ) ? $contact_email : '[None given]'; 213 } 214 409 $contact_name = ! empty( $contact_email ) ? $contact_email : '[None given]'; 410 } 411 412 // Need an email address for the email notification 215 413 if ( empty( $contact_email ) ) { 216 414 $contact_email = $site_email; 217 415 } 218 416 219 $headers = array(); 417 // Sent an email notification to the correct address 418 $headers = array(); 220 419 $headers[] = "From: $contact_name <$contact_email>"; 221 420 $headers[] = "Reply-To: $contact_email"; 222 223 wp_mail($site_email, 'Contact on ' . $site_name, $body, $headers); 421 wp_mail( 422 $site_email, 423 'Contact on ' . $site_name, 424 $body, 425 $headers 426 ); 224 427 225 428 // Should a confirm email be sent? 226 $confirm_body = stripslashes( trim(proper_contact_get_key('propercfp_confirm_email')));227 if ( !empty($confirm_body) && !empty( $contact_email ) ) :228 $headers = array();429 $confirm_body = stripslashes( trim( proper_contact_get_key( 'propercfp_confirm_email' ) ) ); 430 if ( ! empty( $confirm_body ) && ! empty( $contact_email ) ) { 431 $headers = array(); 229 432 $headers[] = "From: $site_name <$site_email>"; 230 433 $headers[] = "Reply-To: $site_email"; 231 wp_mail($contact_email, proper_contact_get_key( 'propercfp_label_submit' ) . ' - ' . get_bloginfo('name'), $confirm_body, $headers); 232 endif; 434 wp_mail( 435 $contact_email, 436 proper_contact_get_key( 'propercfp_label_submit' ) . ' - ' . get_bloginfo( 'name' ), 437 $confirm_body, 438 $headers 439 ); 440 } 233 441 234 442 // Should the entry be stored in the DB? 235 if (proper_contact_get_key('propercfp_store') === 'yes') : 236 $new_post_id = wp_insert_post(array( 237 'post_type' => 'proper_contact', 238 'post_title' => date('l, M j, Y', time()) . ( empty( $contact_name ) ? '' : ' by "' . $contact_name . '"'), 239 'post_content' => $body, 240 'post_author' => 1, 241 'post_status' => 'private' 242 )); 243 if (isset($contact_email) && !empty($contact_email)) { 244 add_post_meta($new_post_id, 'Contact email', $contact_email); 443 if ( proper_contact_get_key( 'propercfp_store' ) === 'yes' ) { 444 $new_post_id = wp_insert_post( 445 array( 446 'post_type' => 'proper_contact', 447 'post_title' => date( 'l, M j, Y', time() ) . ' by "' . $contact_name . '"', 448 'post_content' => $body, 449 'post_author' => 1, 450 'post_status' => 'private' 451 ) 452 ); 453 454 if ( isset( $contact_email ) && ! empty( $contact_email ) ) { 455 add_post_meta( $new_post_id, 'Contact email', $contact_email ); 245 456 } 246 endif;457 } 247 458 248 459 // Should the user get redirected? 249 if( proper_contact_get_key('propercfp_result_url')) : 250 $redirect_id = proper_contact_get_key('propercfp_result_url'); 251 $redirect = get_permalink($redirect_id); 252 wp_redirect($redirect); 253 else : 460 if ( proper_contact_get_key( 'propercfp_result_url' ) ) { 461 $redirect_id = proper_contact_get_key( 'propercfp_result_url' ); 462 $redirect = get_permalink( $redirect_id ); 463 wp_redirect( $redirect ); 464 } 465 else { 254 466 $_SESSION['propercfp_sent'] = 'yes'; 255 endif;256 257 endif;467 } 468 469 } 258 470 259 471 } 260 add_action('template_redirect', 'cfp_process_contact'); 261 262 263 // Custom plugin settings 264 global $propercfp_options; 265 $propercfp_options = get_option('propercfp_settings_array'); 266 267 include('settings.php'); 268 269 function proper_contact_get_key($id) { 270 global $propercfp_options, $plugin_options; 271 return isset( $propercfp_options[$id] ) ? $propercfp_options[$id] : $plugin_options[$id][4]; 472 473 // Get a settings value 474 function proper_contact_get_key( $id ) { 475 $propercfp_options = get_option( 'propercfp_settings_array' ); 476 return isset( $propercfp_options[$id] ) ? $propercfp_options[$id] : ''; 272 477 } 273 478 274 275 /* 276 Add CSS 277 */ 278 function proper_contact_styles() { 279 wp_register_style( 'proper_contact_styles', plugins_url('css/front.css', __FILE__)); 280 wp_enqueue_style( 'proper_contact_styles' ); 479 // If styles should be added, do that 480 if ( proper_contact_get_key( 'propercfp_css' ) === 'yes' ) { 481 482 add_action( 'wp_enqueue_scripts', 'proper_contact_styles' ); 483 function proper_contact_styles() { 484 wp_register_style( 'proper_contact_styles', plugins_url( 'css/front.css', __FILE__ ) ); 485 wp_enqueue_style( 'proper_contact_styles' ); 486 } 487 281 488 } 282 489 283 if (proper_contact_get_key('propercfp_css') === 'yes') 284 add_action('wp_enqueue_scripts', 'proper_contact_styles'); 285 286 287 /* 288 Store submissions in the DB 289 */ 290 291 function proper_contact_content_type() { 292 $labels = array( 293 'name' => _x('Contacts', 'post type general name'), 294 'singular_name' => _x('Contact', 'post type singular name'), 295 'add_new' => _x('Add Contact', 'proper_contact'), 296 'add_new_item' => __('Add New Contact'), 297 'edit_item' => __('Edit Contact'), 298 'new_item' => __('New Contact'), 299 'all_items' => __('All Contacts'), 300 'view_item' => __('View Contact'), 301 'not_found' => __('No Contacts found'), 302 'not_found_in_trash' => __('No Contacts found in Trash'), 303 'parent_item_colon' => '', 304 'menu_name' => 'Contacts' 305 306 ); 307 $args = array( 308 'labels' => $labels, 309 'public' => FALSE, 310 'publicly_queryable' => FALSE, 311 'show_ui' => TRUE, 312 'show_in_menu' => TRUE, 313 'has_archive' => 'string', 314 'hierarchical' => FALSE, 315 'menu_position' => 27, 316 'menu_icon' => plugin_dir_url(__FILE__) . '/images/person.png', 317 'supports' => array( 'title', 'editor', 'custom-fields') 318 ); 319 register_post_type('proper_contact',$args); 490 // If submissions should be stored in the DB, create the CPT 491 if ( proper_contact_get_key( 'propercfp_store' ) === 'yes' ) { 492 493 add_action( 'init', 'proper_contact_content_type' ); 494 function proper_contact_content_type() { 495 $labels = array( 496 'name' => __( 'Contacts', 'proper-contact' ), 'post type general name', 497 'singular_name' => __( 'Contact', 'proper-contact' ), 'post type singular name', 498 'add_new' => __( 'Add Contact', 'proper-contact' ), 'proper_contact', 499 'add_new_item' => __( 'Add New Contact', 'proper-contact' ), 500 'edit_item' => __( 'Edit Contact', 'proper-contact' ), 501 'new_item' => __( 'New Contact', 'proper-contact' ), 502 'all_items' => __( 'All Contacts', 'proper-contact' ), 503 'view_item' => __( 'View Contact', 'proper-contact' ), 504 'not_found' => __( 'No Contacts found', 'proper-contact' ), 505 'not_found_in_trash' => __( 'No Contacts found in Trash', 'proper-contact' ), 506 'menu_name' => __( 'Contacts', 'proper-contact' ) 507 ); 508 $args = array( 509 'labels' => $labels, 510 'public' => FALSE, 511 'show_ui' => TRUE, 512 'show_in_menu' => TRUE, 513 'hierarchical' => FALSE, 514 'menu_position' => 27, 515 'menu_icon' => PROPER_CONTACT_URL . '/images/person.png', 516 'supports' => array( 'title', 'editor', 'custom-fields' ) 517 ); 518 register_post_type( 'proper_contact', $args ); 519 } 520 320 521 } 321 322 if (proper_contact_get_key('propercfp_store') === 'yes')323 add_action( 'init', 'proper_contact_content_type' );324 -
proper-contact-form/trunk/readme.txt
r694646 r782825 1 === P roperContact Form ===1 === PROPER Contact Form === 2 2 Contributors: properwp, joshcanhelp 3 Donate link: 4 Tags: contact, contact form 3 Donate link: http://www.theproperweb.com/code/wp/proper-contact-form/ 4 Tags: contact, contact form, contact form widget 5 5 Requires at least: 3.0 6 Tested up to: 3. 5.17 Stable tag: 0.9. 5.16 Tested up to: 3.6 7 Stable tag: 0.9.6 8 8 9 9 Creates a flexible, secure contact form on your WP site … … 11 11 == Description == 12 12 13 A well-coded, secure, and flexible WordPress plugin that makes creating contact (and other) forms very simple. This is meant to be a simple tool for both savvy WordPress users and seasoned WordPress developers.13 A well-coded, secure, and flexible WordPress plugin that makes creating a contact form very simple. This is meant to be a simple tool for both both savvy and novice WordPress users alike. 14 14 15 15 At the moment, this plugins creates a contact form with the shortcode `[proper_contact_form]` that works on any page. Users have the option to: … … 24 24 25 25 - Additional style options 26 - Complete internationalization27 26 - Ability to add custom fields to the form 28 27 … … 50 49 == Changelog == 51 50 51 = 0.9.6 = 52 * Contact form widget 53 * Math CAPTCHA 54 * Added ability to block the form using the comment blacklist 55 * Improved sanitization and escaping of data 56 * Better and more complete internationalization 57 * More standard styles for the settings page 58 52 59 = 0.9.5.1 = 53 60 * Improved field handling
Note: See TracChangeset
for help on using the changeset viewer.