Skip to:
Content
Pages
Categories
Search
Top
Bottom

how to create a list of groups from a plugin


  • Samuel Aguilera
    Participant

    @samuelaguilera

    Hi!

    I’m trying to create a list of predefined groups with all the required info, just like If I make them from the create group form, but from a little plugin instead.

    I’m trying to create ONE group with this code based in the bp-groups.php and bp-groups-classes.php code that I can see for this:

    global $bp;

    $bp->groups->new_group_id = false;

    $bp->groups->current_group = new BP_Groups_Group( $bp->groups->new_group_id, false, false );

    // manual set some details

    $my_group_name = ‘TEST GROUP, S.L.’;

    $my_group_description = ‘TEST GROUP DESCRIPTION’;

    $my_group_creator = ‘1’;

    $group_status = ‘hidden’;

    $group_enable_wire = ‘0’;

    $group_enable_forum = ‘1’;

    $bp->groups->new_group_id = groups_create_group( array( ‘group_id’ => $bp->groups->new_group_id, ‘creator_id’ => $my_group_creator, ‘name’ => $my_group_name, ‘description’ => $my_group_description, ‘news’ => ”, ‘slug’ => groups_check_slug( sanitize_title($my_group_name) ), ‘status’ => $group_status, ‘enable_wire’ => $group_enable_wire, ‘enable_forum’ => $group_enable_forum, ‘date_created’ => time() ) );

    // uptade group meta

    groups_update_groupmeta( $bp->groups->new_group_id, ‘total_member_count’, 1 );

    groups_update_groupmeta( $bp->groups->new_group_id, ‘last_activity’, time() );

    groups_update_groupmeta( $bp->groups->new_group_id, ‘theme’, ‘buddypress’ );

    groups_update_groupmeta( $bp->groups->new_group_id, ‘stylesheet’, ‘buddypress’ );

    Using this the group array is created without problems in the wp_bp_groups table.

    But no group meta is created in the wp_bp_groups_groupmeta table :(

    And I get a lot of mysql errors in my apache error.log like these:

    WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE slug = ‘test-group-s-l” at line 1 for query SELECT slug FROM WHERE slug = ‘test-group-s-l’ made by require_once, require_once, require_once, require_once, include_once, groups_check_slug, BP_Groups_Group->check_slug, referer: http://localhost/wp-admin/plugins.php

    WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE slug = ‘test-group-s-l” at line 1 for query SELECT slug FROM WHERE slug = ‘test-group-s-l’ made by require_once, require_once, require_once, require_once, include_once, groups_create_group, groups_check_slug, BP_Groups_Group->check_slug, referer: http://localhost/wp-admin/plugins.php

    WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘( \n\t\t\t\t\tcreator_id,\n\t\t\t\t\tname,\n\t\t\t\t\tslug,\n\t\t\t\t\tdescription,\n\t\t\t\t\tnews,\n\t\t\t\t\tstat’ at line 1 for query INSERT INTO ( \n\t\t\t\t\tcreator_id,\n\t\t\t\t\tname,\n\t\t\t\t\tslug,\n\t\t\t\t\tdescription,\n\t\t\t\t\tnews,\n\t\t\t\t\tstatus,\n\t\t\t\t\tenable_wire,\n\t\t\t\t\tenable_forum,\n\t\t\t\t\tdate_created\n\t\t\t\t) VALUES (\n\t\t\t\t\t1, ‘TEST GROUP, S.L.’, ‘test-group-s-l’, ‘TEST GROUP DESCRIPTION’, ”, ”, 0, 1, FROM_UNIXTIME(1257869606)\n\t\t\t\t) made by require_once, require_once, require_once, require_once, include_once, groups_create_group, BP_Groups_Group->save, referer: http://localhost/wp-admin/plugins.php

    It seems to have a problem with the MYSQL syntax used by groups_check_slug function, but the slug is created…

    Somebody can help me to find out why the meta info is not added?

    Any help would be very appreciated.

  • The topic ‘how to create a list of groups from a plugin’ is closed to new replies.
Skip to toolbar