Advertisement
scaylos

BP-NGG-Integrate

Apr 29th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: BP + NEXTGEN Gallery Integrate
  4. Description: Integrate NEXTGEN Gallery with Buddypress profiles
  5. Version: 1.0
  6. Author: Nickolas Klue aka 'Scaylos'
  7. License: GPL2
  8. */
  9.  
  10. // Setup the navigation
  11. // From here... ->
  12. function my_setup_nav() {
  13.     global $bp;
  14.  
  15.     bp_core_new_nav_item( array(
  16.         'name' => __( 'My Gallery', 'buddypress' ),
  17.         'slug' => 'my-gallery',
  18.         'position' => 75,
  19.         'screen_function' => 'my_gallery_link',
  20.         'show_for_displayed_user' => true,
  21.         'default_subnav_slug' => 'my-gallery',
  22.         'item_css_id' => 'my-gallery'
  23.     ) );
  24. }
  25.  
  26. add_action( 'bp_setup_nav', 'my_setup_nav', 1000 );
  27.  
  28. // Print gallery title
  29. function my_gallery_title() {
  30.     echo 'My Gallery';
  31. }
  32. // <- ...to here not mine
  33. // Print NEXTGEN gallery content
  34. function my_gallery_content() {
  35.     global $bp;
  36.     global $wpdb;
  37. // Grab the id for the currently displayed user and turn it into a string            
  38.     $dispvar = strval($bp->displayed_user->id);
  39. // Query NEXTGEN Gallery table for all galleries where displayed user is author
  40.     $gallery_array = $wpdb->get_results(
  41.         "SELECT * FROM ".$wpdb->prefix."ngg_gallery WHERE author = $dispvar");
  42.  
  43. // Get ready for while loop!
  44.     $gallery_id = 0;
  45.     $i = 0;
  46.     $max = count($gallery_array);
  47. // And go! - Print each gallery's slug and feed gallery id into shortcode magic
  48.     while ($i < $max) {
  49.         $gallery_id = $gallery_array[$i]->gid;
  50.         echo '<h4>' . $gallery_array[$i]->slug . '</h4>';
  51.         echo do_shortcode( "[nggallery id=" . $gallery_id . "]" );
  52.         $i++;
  53.     };
  54. }
  55.  
  56. // Setup gallery link
  57. function my_gallery_link () {
  58.     add_action( 'bp_template_title', 'my_gallery_title' );
  59.     add_action( 'bp_template_content', 'my_gallery_content' );
  60.     bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
  61. }
  62.  
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement