• Resolved hnb

    (@hnb)


    Hi there,

    i have to implement a gallery system where authors can create galleries and manage them (i modified a bit the code to display only theirs in the manage menu). So far so good, but i have to create a page for each authors and display their galleries, which is apparently not possible using shortcodes. So, before starting to develop anything i wanted to know if anyone found a solution and was willing to share it 😉

    Thanks a lot,

    HnB.

    http://wordpress.org/extend/plugins/nextgen-gallery/

Viewing 1 replies (of 1 total)
  • Thread Starter hnb

    (@hnb)

    Hi, it’s me again i found a solution for my problem and i wanted to share it :

    I decided to assign an album to a user using a new table :

    CREATE TABLE wp_user_album(
    	id INT PRIMARY KEY,
    	user_id INT NOT NULL,
    	album_id INT NOT NULL,
    	FOREIGN KEY (user_id) REFERENCES WP_USERS(ID)ON DELETE CASCADE,
    	FOREIGN KEY (album_id) REFERENCES wp_ngg_album(id)ON DELETE CASCADE
    );

    The assignation will be done manually on phpmyadmin for instance.

    Then i created a function which i hooked on the action ‘ngg_created_new_gallery’ which is right after the creation of a new gallery. You can drop this at the bottom of the admin/functions.php :

    /**
    * Add a gallery automatically in the user's album (set manually in the table wp_user_album)
    * @param: $galleryid Id of the gallery created
    * Hooked to the action 'ngg_created_new_gallery', return nothing
    */
    add_action('ngg_created_new_gallery', 'add_gallery_to_user_album', $galleryid);
    function add_gallery_to_user_album($galleryid){
    
    	global $wpdb;
    
    	//Get the gallery
    	$gallery = nggdb::find_gallery($galleryid);
    
    	//Get the user id
    	$user_id = $gallery->author;
    
    	//Get the album of the user
    	$user_album = $wpdb->get_row($wpdb->prepare("SELECT * from {$wpdb->prefix}user_album where user_id = %d", $user_id), ARRAY_A);
    	$album = nggdb::find_album($user_album['album_id']);
    
    	//If the user has an album
    	if($album != null){
    
    		//Create an array with the new gallery id
    		$new = array($gallery->gid);
    
    		//Merge it with the array of existing galeries id
    		if(count($album->gallery_ids) > 0)
    			$sort = array_merge((array)$album->gallery_ids, $new);
    		else
    			$sort = $new;
    
    		//serialize it
    		$serialized = serialize($sort);
    
    		//Update the album
    		$wpdb->query("UPDATE $wpdb->nggalbum SET sortorder = '$serialized' WHERE id = $album->id ");
    	}
    
    	//BEGIN DEBUG
    	$debug = '[author : '.$gallery->author.'] [album id : '.$album->id.'] [serialized : '.$serialized.']';
    	nggGallery::show_message($debug);
    	//END DEBUG
    
    }

    Therefore, every time a user with an assigned album will create a gallery it will be automatically added to its album and displayed on the page with the album shortcode (eg : [album id=1 template=compact]).

    Hope it will help,

    HnB

Viewing 1 replies (of 1 total)

The topic ‘Display a user's gallery’ is closed to new replies.