Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/19/2009 12:21:53 PM (17 years ago)
Author:
apeatling
Message:

Added value filters and before and after actions to all save() methods.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r1311 r1351  
    4646        global $wpdb, $bp;
    4747       
    48         $this->name = wp_filter_kses( $this->name );
    49         $this->description = wp_filter_kses( $this->description );
    50 
    51         if ( $this->id != null ) {
    52             $sql = $wpdb->prepare("UPDATE {$bp->profile->table_name_groups} SET name = %s, description = %s WHERE id = %d", $this->name, $this->description, $this->id);
    53         } else {
    54             $sql = $wpdb->prepare("INSERT INTO {$bp->profile->table_name_groups} (name, description, can_delete) VALUES (%s, %s, 1)", $this->name, $this->description);     
     48        $this->name = apply_filters( 'xprofile_group_name_before_save', $this->name, $this->id );
     49        $this->description = apply_filters( 'xprofile_group_description_before_save', $this->description, $this->id );
     50
     51        do_action( 'xprofile_group_before_save', $this );
     52
     53        if ( $this->id ) {
     54            $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s, description = %s WHERE id = %d", $this->name, $this->description, $this->id );
     55        } else {
     56            $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_groups} (name, description, can_delete) VALUES (%s, %s, 1)", $this->name, $this->description );       
    5557        }
    5658       
    5759        if ( !$wpdb->query($sql) )
    5860            return false;
     61
     62        do_action( 'xprofile_group_after_save', $this );
    5963       
    6064        return true;
     
    246250        global $wpdb, $bp;
    247251       
    248         $this->name = wp_filter_kses( $this->name );
    249         $this->desc = wp_filter_kses( $this->desc );       
     252        $error = false;
     253       
     254        $this->group_id = apply_filters( 'xprofile_field_group_id_before_save', $this->group_id, $this->id );
     255        $this->parent_id = apply_filters( 'xprofile_field_parent_id_before_save', $this->parent_id, $this->id );
     256        $this->type = apply_filters( 'xprofile_field_type_before_save', $this->type, $this->id );
     257        $this->name = apply_filters( 'xprofile_field_name_before_save', $this->name, $this->id );
     258        $this->desc = apply_filters( 'xprofile_field_description_before_save', $this->desc, $this->id );
     259        $this->is_required = apply_filters( 'xprofile_field_is_required_before_save', $this->is_required, $this->id );
     260        $this->is_public = apply_filters( 'xprofile_field_is_public_before_save', $this->is_public, $this->id );
     261        $this->order_by = apply_filters( 'xprofile_field_order_by_before_save', $this->order_by, $this->id );
     262
     263        do_action( 'xprofile_field_before_save', $this );
    250264       
    251265        if ( $this->id != null ) {
     
    354368                    }
    355369                }
    356 
    357                 return true;
    358            
    359             } else {
    360                 return true;
    361370            }
    362         }
    363         else
    364         {
     371        } else {
     372            $error = true;
     373        }
     374       
     375        if ( !$error ) {
     376            do_action( 'xprofile_field_after_save', $this );
     377            return true;
     378        } else {
    365379            return false;
    366380        }
     
    10391053    function save() {
    10401054        global $wpdb, $bp;
    1041        
    1042         $this->last_updated = date( 'Y-m-d H:i:s' );
    1043         $this->value = wp_filter_kses( $this->value );
    1044 
     1055
     1056        $this->user_id = apply_filters( 'xprofile_data_user_id_before_save', $this->user_id, $this->id );
     1057        $this->field_id = apply_filters( 'xprofile_data_field_id_before_save', $this->field_id, $this->id );
     1058        $this->value = apply_filters( 'xprofile_data_value_before_save', $this->value, $this->id );
     1059        $this->last_updated = apply_filters( 'xprofile_data_last_updated_before_save', date( 'Y-m-d H:i:s' ), $this->id );
     1060       
     1061        do_action( 'xprofile_data_before_save', $this );
     1062       
    10451063        if ( $this->is_valid_field() ) {
    10461064            if ( $this->exists() && $this->value != '' ) {
     
    10561074                return false;
    10571075
     1076            do_action( 'xprofile_data_after_save', $this );
     1077           
    10581078            return true;
    10591079        }
Note: See TracChangeset for help on using the changeset viewer.