| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | function bpfr_add_page_to_group() { |
|---|
| 4 | |
|---|
| 5 | if ( class_exists( 'BP_Group_Extension' ) ) : |
|---|
| 6 | |
|---|
| 7 | class BPFR_Custom_Group_Extension extends BP_Group_Extension { |
|---|
| 8 | |
|---|
| 9 | /** |
|---|
| 10 | * building the tab |
|---|
| 11 | */ |
|---|
| 12 | |
|---|
| 13 | function __construct() { |
|---|
| 14 | $args = array( |
|---|
| 15 | 'slug' => 'additionnal-page', // tab slug - mandatory |
|---|
| 16 | 'name' => 'Additionnal Page' // tab name - mandatory |
|---|
| 17 | ); |
|---|
| 18 | parent::init( $args ); |
|---|
| 19 | } // end construct() |
|---|
| 20 | |
|---|
| 21 | /** |
|---|
| 22 | * content display |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | function display() { |
|---|
| 26 | |
|---|
| 27 | // grab page or post ID |
|---|
| 28 | $id = 140; |
|---|
| 29 | $p = get_post($id); |
|---|
| 30 | |
|---|
| 31 | /** |
|---|
| 32 | * example 1 (post) |
|---|
| 33 | * images are visible, videos are not. |
|---|
| 34 | * autoembeding is not working here. |
|---|
| 35 | */ |
|---|
| 36 | |
|---|
| 37 | // output the title |
|---|
| 38 | echo '<h3>'.apply_filters('the_content', $p->post_title).'</h3>'; |
|---|
| 39 | // output the post |
|---|
| 40 | echo apply_filters('the_content', $p->post_content); |
|---|
| 41 | // end option 1 |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * example 2 (video) |
|---|
| 46 | * adding a video to the group |
|---|
| 47 | */ |
|---|
| 48 | |
|---|
| 49 | // output a Youtube video |
|---|
| 50 | echo '<p style="text-align:center">'.wp_oembed_get( 'http://www.youtube.com/watch?v=dQw4w9WgXcQ', array( |
|---|
| 51 | 'width' => 600, |
|---|
| 52 | 'height' => 400 |
|---|
| 53 | ) ).'</p>'; |
|---|
| 54 | // end option 2 |
|---|
| 55 | |
|---|
| 56 | } // end display() |
|---|
| 57 | } // end class |
|---|
| 58 | |
|---|
| 59 | //////////////////////////////////////////////////////////// |
|---|
| 60 | /* display content only in one group (ex. group_ID is 14) */ |
|---|
| 61 | //////////////////////////////////////////////////////////// |
|---|
| 62 | |
|---|
| 63 | // check for a group ID |
|---|
| 64 | if( bp_has_groups() ) { |
|---|
| 65 | // Grab current group ID |
|---|
| 66 | bp_the_group(); |
|---|
| 67 | $group_id = bp_get_group_ID(); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | ////////////////////////////////////////// |
|---|
| 71 | /* apply our changes only to this group */ |
|---|
| 72 | ////////////////////////////////////////// |
|---|
| 73 | |
|---|
| 74 | // conditionnal action |
|---|
| 75 | if ( $group_id == 14 ) { |
|---|
| 76 | bp_register_group_extension( 'BPFR_Custom_Group_Extension' ); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | endif; |
|---|
| 80 | } |
|---|
| 81 | add_filter('bp_groups_default_extension', 'bpfr_add_page_to_group' ); |
|---|
| 82 | |
|---|
| 83 | ?> |
|---|