Plugin Directory

Changeset 527123


Ignore:
Timestamp:
04/04/2012 07:16:49 AM (14 years ago)
Author:
tott
Message:
  • Allowing "context" changes
  • Overloading custom user parameters.

( Thanks for this to Austin Burns )

  • Adding examples file
Location:
easy-custom-fields/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • easy-custom-fields/trunk/easy-custom-fields.php

    r418693 r527123  
    33Plugin Name: Easy Custom Fields
    44Plugin Script: easy-custom-fields.php
    5 Plugin URI:
     5Plugin URI: http://wordpress.org/extend/plugins/easy-custom-fields/
    66Description: A set of extendable classes for easy Custom Field Handling
    7 Version: 0.1
     7Version: 0.2
    88Author: Thorsten Ott
    99Author URI: http://automattic.com
     
    170170                return $value;
    171171        }
     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        }
    172182
    173183        /*
     
    391401         */
    392402        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 ) {
    394404                $group_title = ( empty( $group_data['title'] ) ) ? $group_id : $group_data['title'];
    395405                $group_context = ( empty( $group_data['context'] ) ) ? 'advanced' : $group_data['context'];
    396406                $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 ) {
    398408                    add_meta_box( $group_id, $group_title, array( &$this, 'meta_box_cb' ), $page, $group_context );
    399409                }
     
    415425         */
    416426        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 ) {
    418428                if ( ! wp_verify_nonce( $_REQUEST[$this->_plugin_prefix . '_' . $box_id . '_nonce'], $this->_plugin_prefix . '_' . $box_id . '_nonce' ) ) {
    419429                    return $post->ID;
     
    430440               
    431441                // 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 ) )
    433443                    return $post->ID;
    434444               
    435445                // Add values of $my_data as custom fields
    436446                // Let's cycle through the $my_data array!
    437                 foreach ( $field_ids as $field_id ) {
     447                foreach ( (array) $field_ids as $field_id ) {
    438448                    $value = $_POST[$field_id];
    439449                    if ( !$this->{$field_id}->validate( $value, $post->ID ) ) {
     
    483493            // validate data, make sure to fill $this->_field_data only with validated fields
    484494
    485             foreach( $field_data as $group_id => $group_data ) {
     495            foreach( (array) $field_data as $group_id => $group_data ) {
    486496                // check group_id
    487497                if ( !preg_match( "#^[a-zA-Z0-9_-]+$#msiU", $group_id ) ) {
     
    511521
    512522                // check fields array
    513                 foreach( $group_data['fields'] as $field_id => $field ) {
     523                foreach( (array) $group_data['fields'] as $field_id => $field ) {
    514524
    515525                    // check field id
     
    522532                    }
    523533
    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;
    528579                    }
    529 
    530                     // check hint
    531                     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_msg
    537                     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 class
    543                     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_class
    549                     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 type
    555                     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 validate
    561                     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'] );
    567580                }
    568581
    569582                $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,                   
    573588                );
    574589            }
     
    576591
    577592            // 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 ) {
    581596                    $field_class_name = 'Easy_CF_Field_' . ucfirst( $field['type'] );
    582597                    if ( !class_exists( $field_class_name ) )
  • easy-custom-fields/trunk/readme.txt

    r418693 r527123  
    33Tags: custom fields, post meta, post_meta, custom post fields
    44Requires at least: 2.9.2
    5 Tested up to: 3.2
     5Tested up to: 3.3
    66Stable tag: trunk
    77
Note: See TracChangeset for help on using the changeset viewer.