- Lead Developer, BuddyPress
- Queens, NY
- Freelance developer and consultant
- Clients mostly universities and schools
- Love fade-in bullet lists
BP_Component
add_action()
and add_filter()
hooksBP_Group_Extension
/* 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)
if ( class_exists( 'BP_Group_Extension' ) ) : class BPCF7 extends BP_Group_Extension { // ... } endif;
Check first, to avoid errors during updates and deactivations
BP_Group_Extension
BP_Group_Extension
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' );
BP_Group_Extension
BP_Group_Extension
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 ); }
BP_Group_Extension
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 ); }
BP_Group_Extension
See also:
create_screen()
create_screen_save()
admin_screen()
admin_screen_save()
BP_Group_Extension
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'; // ... }