Changeset 527123
- Timestamp:
- 04/04/2012 07:16:49 AM (14 years ago)
- Location:
- easy-custom-fields/trunk
- Files:
-
- 1 added
- 2 edited
-
easy-custom-fields.php (modified) (9 diffs)
-
examples.php (added)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
easy-custom-fields/trunk/easy-custom-fields.php
r418693 r527123 3 3 Plugin Name: Easy Custom Fields 4 4 Plugin Script: easy-custom-fields.php 5 Plugin URI: 5 Plugin URI: http://wordpress.org/extend/plugins/easy-custom-fields/ 6 6 Description: A set of extendable classes for easy Custom Field Handling 7 Version: 0. 17 Version: 0.2 8 8 Author: Thorsten Ott 9 9 Author URI: http://automattic.com … … 170 170 return $value; 171 171 } 172 173 /* 174 * Get the ID for the current Post 175 * @return current post ID 176 */ 177 public function get_post_id() { 178 global $post; 179 $post_id = $post->ID; 180 return $post_id; 181 } 172 182 173 183 /* … … 391 401 */ 392 402 public function add_meta_boxes() { 393 foreach( $this->_field_data as $group_id => $group_data ) {403 foreach( (array) $this->_field_data as $group_id => $group_data ) { 394 404 $group_title = ( empty( $group_data['title'] ) ) ? $group_id : $group_data['title']; 395 405 $group_context = ( empty( $group_data['context'] ) ) ? 'advanced' : $group_data['context']; 396 406 $group_pages = ( empty( $group_data['pages'] ) ) ? array( 'post', 'page' ) : $group_data['pages']; 397 foreach( $group_pages as $page ) {407 foreach( (array) $group_pages as $page ) { 398 408 add_meta_box( $group_id, $group_title, array( &$this, 'meta_box_cb' ), $page, $group_context ); 399 409 } … … 415 425 */ 416 426 public function save_post_cb($post_id, $post) { 417 foreach( $this->_used_fields as $box_id => $field_ids ) {427 foreach( (array) $this->_used_fields as $box_id => $field_ids ) { 418 428 if ( ! wp_verify_nonce( $_REQUEST[$this->_plugin_prefix . '_' . $box_id . '_nonce'], $this->_plugin_prefix . '_' . $box_id . '_nonce' ) ) { 419 429 return $post->ID; … … 430 440 431 441 // Is the user allowed to edit the post or page? 432 if ( !current_user_can( $post_type_object->cap->edit_post ) )442 if ( !current_user_can( $post_type_object->cap->edit_posts ) ) 433 443 return $post->ID; 434 444 435 445 // Add values of $my_data as custom fields 436 446 // Let's cycle through the $my_data array! 437 foreach ( $field_ids as $field_id ) {447 foreach ( (array) $field_ids as $field_id ) { 438 448 $value = $_POST[$field_id]; 439 449 if ( !$this->{$field_id}->validate( $value, $post->ID ) ) { … … 483 493 // validate data, make sure to fill $this->_field_data only with validated fields 484 494 485 foreach( $field_data as $group_id => $group_data ) {495 foreach( (array) $field_data as $group_id => $group_data ) { 486 496 // check group_id 487 497 if ( !preg_match( "#^[a-zA-Z0-9_-]+$#msiU", $group_id ) ) { … … 511 521 512 522 // check fields array 513 foreach( $group_data['fields'] as $field_id => $field ) {523 foreach( (array) $group_data['fields'] as $field_id => $field ) { 514 524 515 525 // check field id … … 522 532 } 523 533 524 // check label 525 if ( !empty( $field['label'] ) && !preg_match( "#^[a-zA-Z0-9_-\s:]+$#miU", $field['label'] ) ) { 526 $this->add_admin_notice( sprintf( __( "Field label %s for group %s contains invalid chars use only [a-zA-Z0-9_-\s:]" ), $field['label'], $group_id ) ); 527 continue; 534 foreach($field as $field_name => $field_value){ 535 536 // check label 537 if ( !empty( $field_value ) && $field_name == 'label' && !preg_match( "#^[a-zA-Z0-9_-\s:]+$#miU", $field_value ) ) { 538 $this->add_admin_notice( sprintf( __( "Field label %s for group %s contains invalid chars use only [a-zA-Z0-9_-\s:]" ), $field_value, $group_id ) ); 539 continue; 540 } 541 542 // check hint 543 if ( !empty( $field_value ) && $field_name == 'hint' && !preg_match( "#^[a-zA-Z0-9_-\s:]+$#miU", $field_value ) ) { 544 $this->add_admin_notice( sprintf( __( "Field hint %s for group %s contains invalid chars use only [a-zA-Z0-9_-\s:]" ), $field_value, $group_id ) ); 545 continue; 546 } 547 548 // check error_msg 549 if ( !empty( $field_value ) && $field_name == 'error_msg' && !preg_match( "#^[a-zA-Z0-9_-\s:]+$#miU", $field_value ) ) { 550 $this->add_admin_notice( sprintf( __( "Field error_msg %s for group %s contains invalid chars use only [a-zA-Z0-9_-\s:]" ), $field_value, $group_id ) ); 551 continue; 552 } 553 554 // check class 555 if ( !empty( $field_value ) && $field_name == 'class' && !preg_match( "#^[a-zA-Z0-9_-\s]+$#miU", $field_value ) ) { 556 $this->add_admin_notice( sprintf( __( "Field class %s for group %s contains invalid chars use only [a-zA-Z0-9_-\s]" ), $field_value, $group_id ) ); 557 continue; 558 } 559 560 // check input_class 561 if ( !empty( $field_value ) && $field_name == 'input_class' && !preg_match( "#^[a-zA-Z0-9_-\s]+$#miU", $field_value ) ) { 562 $this->add_admin_notice( sprintf( __( "Field input_class %s for group %s contains invalid chars use only [a-zA-Z0-9_-\s]" ), $field_value, $group_id ) ); 563 continue; 564 } 565 566 // check type 567 if ( !empty( $field_value ) && $field_name == 'type' && !preg_match( "#^[a-zA-Z0-9_]+$#miU", $field_value ) ) { 568 $this->add_admin_notice( sprintf( __( "Field type %s for group %s contains invalid chars use only [a-zA-Z0-9_-]" ), $field_value, $group_id ) ); 569 continue; 570 } 571 572 // check validate 573 if ( !empty( $field_value ) && $field_name == 'validate' && !preg_match( "#^[a-zA-Z0-9_]+$#miU", $field_value ) ) { 574 $this->add_admin_notice( sprintf( __( "Field validator %s for group %s contains invalid chars use only [a-zA-Z0-9_-]" ), $field_value, $group_id ) ); 575 continue; 576 } 577 578 $_fields[$field_id][$field_name] = $field_value; 528 579 } 529 530 // check hint531 if ( !empty( $field['hint'] ) && !preg_match( "#^[a-zA-Z0-9_-\s:]+$#miU", $field['hint'] ) ) {532 $this->add_admin_notice( sprintf( __( "Field hint %s for group %s contains invalid chars use only [a-zA-Z0-9_-\s:]" ), $field['hint'], $group_id ) );533 continue;534 }535 536 // check error_msg537 if ( !empty( $field['error_msg'] ) && !preg_match( "#^[a-zA-Z0-9_-\s:]+$#miU", $field['error_msg'] ) ) {538 $this->add_admin_notice( sprintf( __( "Field error_msg %s for group %s contains invalid chars use only [a-zA-Z0-9_-\s:]" ), $field['error_msg'], $group_id ) );539 continue;540 }541 542 // check class543 if ( !empty( $field['class'] ) && !preg_match( "#^[a-zA-Z0-9_-\s]+$#miU", $field['class'] ) ) {544 $this->add_admin_notice( sprintf( __( "Field class %s for group %s contains invalid chars use only [a-zA-Z0-9_-\s]" ), $field['class'], $group_id ) );545 continue;546 }547 548 // check input_class549 if ( !empty( $field['input_class'] ) && !preg_match( "#^[a-zA-Z0-9_-\s]+$#miU", $field['input_class'] ) ) {550 $this->add_admin_notice( sprintf( __( "Field input_class %s for group %s contains invalid chars use only [a-zA-Z0-9_-\s]" ), $field['input_class'], $group_id ) );551 continue;552 }553 554 // check type555 if ( !empty( $field['type'] ) && !preg_match( "#^[a-zA-Z0-9_]+$#miU", $field['type'] ) ) {556 $this->add_admin_notice( sprintf( __( "Field type %s for group %s contains invalid chars use only [a-zA-Z0-9_-]" ), $field['type'], $group_id ) );557 continue;558 }559 560 // check validate561 if ( !empty( $field['validate'] ) && !preg_match( "#^[a-zA-Z0-9_]+$#miU", $field['validate'] ) ) {562 $this->add_admin_notice( sprintf( __( "Field validator %s for group %s contains invalid chars use only [a-zA-Z0-9_-]" ), $field['validate'], $group_id ) );563 continue;564 }565 566 $_fields[$field_id] = array( 'id' => $field_id, 'label' => $field['label'], 'hint' => $field['hint'], 'class' => $field['class'], 'type' => $field['type'], 'validate' => $field['validate'], 'error_msg' => $field['error_msg'], 'input_class' => $field['input_class'] );567 580 } 568 581 569 582 $this->_field_data[$group_id] = array( 570 'title' => $group_data['title'], 571 'class' => $group_data['class'], 572 'fields' => $_fields, 583 'title' => ( ! empty( $group_data['title'] ) ) ? $group_data['title'] : null, 584 'class' => ( ! empty( $group_data['class'] ) ) ? $group_data['title'] : null, 585 'fields' => $_fields, 586 'pages' => ( ! empty( $group_data['pages'] ) ) ? $group_data['pages'] : null, 587 'context' => ( ! empty( $group_data['context'] ) ) ? $group_data['context'] : null, 573 588 ); 574 589 } … … 576 591 577 592 // initialize classes for validated data 578 foreach( $this->_field_data as $group_id => $group_data ) {579 580 foreach( $group_data['fields'] as $field_id => $field ) {593 foreach( (array) $this->_field_data as $group_id => $group_data ) { 594 595 foreach( (array) $group_data['fields'] as $field_id => $field ) { 581 596 $field_class_name = 'Easy_CF_Field_' . ucfirst( $field['type'] ); 582 597 if ( !class_exists( $field_class_name ) ) -
easy-custom-fields/trunk/readme.txt
r418693 r527123 3 3 Tags: custom fields, post meta, post_meta, custom post fields 4 4 Requires at least: 2.9.2 5 Tested up to: 3. 25 Tested up to: 3.3 6 6 Stable tag: trunk 7 7
Note: See TracChangeset
for help on using the changeset viewer.