I am Boone

  • Lead Developer, BuddyPress
  • Queens, NY
  • Freelance developer and consultant
  • Clients mostly universities and schools
  • Love fade-in bullet lists

These slides:

http://blo.so/bpmia

BuddyPressification

BuddyPressification

and its many guises

  • BP-specific theme templates
  • Extending Members with BP_Component
  • Miscellaneous add_action() and add_filter() hooks
  • Extending Groups with BP_Group_Extension

BuddyPressification

your mom is in a BuddyPress group

BuddyPress Group

BuddyPressification

suckazzz

contact form 7

BuddyPressification

follow along

Getting Started

bootstrap with care

/*
Plugin Name: Bp-cf7
*/
function bpcf7_init() {
        // Make sure that CF7 exists
        if ( ! function_exists( 'wpcf7' ) )
                return;

        include( dirname(__FILE__) . '/includes/class-bpcf7.php' );
}
add_action( 'bp_include', 'bpcf7_init' );

wp-content/plugins/bp-cf7/bp-cf7.php (main plugin file)

Getting Started

bootstrap with care


if ( class_exists( 'BP_Group_Extension' ) ) :
        class BPCF7 extends BP_Group_Extension { // ...
        }
endif;

Check first, to avoid errors during updates and deactivations

Using BP_Group_Extension

1) a simple example

Example 1

Using BP_Group_Extension

1) a simple example

class BPCF7 extends BP_Group_Extension {
        public function __construct() {
                $this->name = __( 'Contact Forms', 'bp-cf7' );
                $this->slug = 'contact-forms';
        }

        public function display() {
                echo '<h2>' . __( 'Contact', 'bp-cf7' ) . '</h2>';
                echo do_shortcode( '[contact-form-7 id="318" title="My Group Form"]' );
        }
}
bp_register_group_extension( 'BPCF7' );

Using BP_Group_Extension

2) group-specific settings

Example 2

Using BP_Group_Extension

2) group-specific settings

protected function get_form_id() {
        $group_id = bp_get_current_group_id();
        $form_id = groups_get_groupmeta( $group_id, 'cf7_form_id' );

        if ( ! $form_id )
                $form_id = 318;

        return $form_id;
}

public function edit_screen() {
        $form_id = $this->get_form_id(); ?>

        <h2><?php echo esc_html( $this->name ) ?></h2>

        <label for="cf7_form_id"><?php _e( 'Form ID', 'bp-cf7' ) ?></label>
        <input id="cf7_form_id" name="cf7_form_id" value="<?php echo esc_attr( $form_id ) ?>" />
        <input type="submit" value="<?php _e( 'Submit', 'bp-cf7' ) ?>" />

        <?php wp_nonce_field( 'groups_edit_save_' . $this->slug );
}

Using BP_Group_Extension

2) group-specific settings

public function edit_screen_save() {
        if ( ! isset( $_POST['cf7_form_id'] ) )
                return;

        check_admin_referer( 'groups_edit_save_' . $this->slug );

        $form_id = intval( $_POST['cf7_form_id'] );

        if ( groups_update_groupmeta( bp_get_current_group_id(), 'cf7_form_id', $form_id ) )
                bp_core_add_message( __( 'Yes!', 'bp-cf7' ) );
        else
                bp_core_add_message( __( 'Sadface.', 'bp-cf7' ), 'error' );

        bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 
                          '/admin/' . $this->slug . '/' );
}

public function display() {
        echo '<h2>' . __( 'Contact', 'bp-cf7' ) . '</h2>';
        $form_id = $this->get_form_id();
        $shortcode = '[contact-form-7 id="' . intval( $form_id ) . '" title="My Group Form"]';
        echo do_shortcode( $shortcode );
}

Using BP_Group_Extension

2) group-specific settings

See also:

  • create_screen()
  • create_screen_save()
  • admin_screen()
  • admin_screen_save()

Using BP_Group_Extension

3) more advanced configuration

public function __construct() {
        // ...

        // Don't need a Create step?
        $this->enable_create_item = false;

        // Move your Dashboard metabox around
        $this->admin_metabox_context = 'side';

        // Custom access
        $this->enable_nav_item = $this->enable_nav_item();

        // Load template files from a different theme location
        $this->template_file = '/bp-cf7/foo';

        // ...
}			

THANKS D00DS