Skip to:
Content
Pages
Categories
Search
Top
Bottom

adding new field to group


  • isuru
    Participant

    @isuru

    I was trying to add a new field called ‘author’ to group. It was just a text field. I changed the source of

    bp-group.php,

    bp-group-classes.php,

    bp-group-filters.php,

    bp-group-templatetags.php

    After uploading, the field appears as normal

    But it gives error as “There was an error saving the field. Please try again buddypress”

    Hope someone will help me

Viewing 2 replies - 1 through 2 (of 2 total)
  • You did not need to post two threads for this. That will not make anyone help you quicker.

    Plus, how/why are we expected to be able to debug your custom code without even seeing the source?


    isuru
    Participant

    @isuru

    sry, this is the source code. i have mentioned the functions which i modified only.

    the screen “create new group” appears with added field, the error is given when saving.

    what are the other files to be modified????????

    <?php

    /**********************

    bp-group.php

    **********************/

    function groups_install() {

    /*some code goes here*/

    $sql[] = “CREATE TABLE {$bp->groups->table_name} (

    …………..

    author varchar(50) NOY NULL,

    ………….

    ) {$charset_collate};”;

    /*some code goes here*/

    }

    function groups_check_installed() {

    if(is_site_admin()){

    if ( !$wpdb->get_var(“SHOW TABLES LIKE ‘%” . $bp->groups->table_name . “%'”) || ( get_site_option(‘bp-groups-db-version’) < BP_GROUPS_DB_VERSION ) )

    groups_install();

    }

    /*some code goes here*/

    }

    function groups_screen_group_admin_edit_details() {

    /*some code goes here*/

    if ( $bp->current_component == $bp->groups->slug && ‘edit-details’ == $bp->action_variables[0] ) {

    if ( $bp->is_item_admin || $bp->is_item_mod ) {

    if ( isset( $_POST[‘save’] ) ) {

    if ( !groups_edit_base_group_details( $_POST[‘group-id’], $_POST[‘group-name’], $_POST[‘group-desc’], $_POST[‘group-news’], $_POST[‘author’], (int)$_POST[‘group-notify-members’] ) ) {

    bp_core_add_message( __( ‘There was an error updating group details, please try again.’, ‘buddypress’ ), ‘error’ );

    } else {

    /*some code goes here*/

    }

    /*some code goes here*/

    }

    do_action( ‘groups_screen_group_admin_edit_details’, $group_obj->id );

    bp_core_load_template( ‘groups/admin/edit-details’ );

    }

    }

    }

    add_action( ‘wp’, ‘groups_screen_group_admin_edit_details’, 4 );

    function groups_create_group( $step, $group_id ) {

    /*some code goes here*/

    if ( is_numeric( $step ) && ( 1 == (int)$step || 2 == (int)$step || 3 == (int)$step || 4 == (int)$step ) ) {

    if ( !$group_obj )

    $group_obj = new BP_Groups_Group( $group_id );

    switch ( $step ) {

    case ‘1’:

    if ( !check_admin_referer( ‘groups_step1_save’ ) )

    return false;

    if ( $_POST[‘group-name’] != ” && $_POST[‘group-desc’] != ” ) {

    /*some code goes here*/

    $group_obj->author = stripslashes($_POST[‘author’]);

    /*some code goes here*/

    if ( !$group_obj->save() )

    return false;

    /*some code goes here*/

    }

    break;

    /*some code goes here*/

    }

    }

    function groups_screen_create_group() {

    /*some code goes here*/

    if ( isset( $_POST[‘save’] ) || isset( $_POST[‘skip’] ) ) {

    /*some code goes here*/

    if ( !$group_id = groups_create_group( $create_group_step, $_SESSION[‘group_obj_id’] ) ) {

    /* error message*/

    } else {

    /*some code goes here*/

    }

    /*some code goes here*/

    }

    /*some code goes here*/

    bp_core_load_template( ‘groups/create’ );

    }

    function groups_edit_base_group_details( $group_id, $group_name, $group_desc, $group_news, $group_author, $notify_members ) {

    /*some code goes here*/

    if ( !check_admin_referer( ‘groups_edit_group_details’ ) )

    return false;

    if ( empty( $group_name ) || empty( $group_desc ) )

    return false;

    /*some code goes here*/

    $group->news = $group_news;

    /*some code goes here*/

    if ( !$group->save() )

    return false;

    if ( $notify_members )

    groups_notification_group_updated( $group->id );

    /*some code goes here*/

    }

    function groups_screen_group_admin_edit_details() {

    /*some code goes here*/

    if ( $bp->current_component == $bp->groups->slug && ‘edit-details’ == $bp->action_variables[0] ) {

    if ( $bp->is_item_admin || $bp->is_item_mod ) {

    if ( isset( $_POST[‘save’] ) ) {

    if ( !groups_edit_base_group_details( $_POST[‘group-id’], $_POST[‘group-name’], $_POST[‘group-desc’], $_POST[‘group-news’], $_POST[‘author’], (int)$_POST[‘group-notify-members’] ) ) {

    /*error message*/

    } else {

    /*some code goes here*/

    }

    /*some code goes here*/

    }

    /*some code goes here*/

    }

    }

    }

    //add_action();

    /**********************

    bp-groups-classes.php

    **********************/

    class BP_Groups_Group {

    /*some code goes here*/

    var $news;

    function populate( $get_user_dataset ) {

    /*some code goes here*/

    if ( $group ) {

    /*some code goes here*/

    $this->author = stripslashes($group->author);

    /*some code goes here*/

    }

    }

    function save() {

    /*some code goes here*/

    if ( $this->id ) {

    $sql = $wpdb->prepare(

    “UPDATE {$bp->groups->table_name} SET

    author = %s,

    WHERE

    id = %d

    “,

    /*some code goes here*/

    $this->author,

    /*some code goes here*/

    );

    } else {

    $sql = $wpdb->prepare(

    “INSERT INTO {$bp->groups->table_name} (

    news,

    ) VALUES (

    %s

    )”,

    /*some code goes here*/

    $this->author,

    /*some code goes here*/

    );

    }

    /*some code goes here*/

    }

    }

    /**********************

    bp-groups-filters.php

    **********************/

    add_filter( ‘bp_group_author’, ‘wptexturize’ );

    add_filter( ‘bp_group_author’, ‘convert_smilies’ );

    add_filter( ‘bp_group_author’, ‘convert_chars’ );

    add_filter( ‘bp_group_author’, ‘wpautop’ );

    add_filter( ‘bp_group_author’, ‘make_clickable’ );

    /**********************

    bp-groups-templatetags.php

    **********************/

    /*some code goes here*/

    function bp_group_author() {

    global $groups_template;

    echo apply_filters( ‘bp_group_author’, stripslashes($groups_template->group->author) );

    }

    function bp_group_author_editable() {

    global $groups_template;

    echo apply_filters( ‘bp_group_author_editable’, $groups_template->group->author );

    }

    /*some code goes here*/

    function bp_group_create_form() {

    /*some code goes here*/

    ?>

    <form action=”<?php echo $bp->displayed_user->domain . $bp->groups->slug ?>/create/step/<?php echo $create_group_step ?>” method=”post” id=”create-group-form” class=”standard-form” enctype=”multipart/form-data”>

    <?php switch( $create_group_step ) {

    case ‘1’: ?>

    <label for=”author”>* <?php _e(‘Author’, ‘buddypress’) ?></label>

    <textarea name=”author” id=”author”><?php echo ( $group_obj ) ? $group_obj->author : $_POST[‘author’]; ?>

    </textarea>

    <?php do_action( ‘groups_custom_group_fields_editable’ ) ?>

    <p><input type=”submit” value=”<?php _e(‘Create Group and Continue’, ‘buddypress’) ?> »” id=”save” name=”save”/></p>

    <?php wp_nonce_field( ‘groups_step1_save’ ) ?>

    <?php break;

    /*some code goes here*/

    }

    }

    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘adding new field to group’ is closed to new replies.
Skip to toolbar