• Resolved supernova42

    (@supernova42)


    Now that I’ve purchased the multi image upload my media library is starting to get very full and needs to be organised. I have a few plugins which allows me to organise the folder but it is very time consuming.

    Is it possible to create a category for each user and when that user uploads a photo or file etc it is assigned to that category.

    Many Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter supernova42

    (@supernova42)

    I’ve finally managed to work out what I need to do to create a category for each user as shown below.

    function insert_category($category,$description,$parent) {
    wp_insert_term(
    $category,
    ‘media_category’,
    array(
    ‘description’ => $description,
    ‘media_parent’ => $parent,
    ‘slug’ => $category //convert to lower case with hyphen
    ));}
    add_action(‘after_setup_theme’,’insert_category’);

    I can create this category when the user first joins the site. $category will be the users wordpress username. I might have to use something like cat_username to differentiate it from the actual username.

    The only thing that remains is – How do I assign a category name (i.e. UserName) to each photo as it is uploaded. Once I’ve done that my media library is totally organised. Do you think you could help me out?

    Thanks

    ps
    This would be a great feature to add to the multi image add-on.

    Thread Starter supernova42

    (@supernova42)

    This is an improvement on my last attempt.
    I use the plugin ‘Enhanced Media Library’ as I can view each of the categories individually.

    This routine creates a separate category for each user, or it could be product or item etc. This routine just needs to be run once for each user, probably at joining.

    The next stage is to allocate each image to the defined category for that user which will give a totally organised media library (sort of…).

    I’m hoping Roland will give me a few pointers for this next stage.

    Thanks

    $current_user    = wp_get_current_user();
    $wp_username     = $current_user->user_login;
    $user_id         = Participants_Db::get_record_id_by_term('username', $wp_username);
    $data            = Participants_Db::get_participant($user_id);
    $first_name      = $data['first_name'];
    $last_name       = $data['last_name'];
    $boat_name       = $data['boat_name'];
    $boat_model      = $data['boat_model'];
    $parent_name     = 'Members Boats';
    $my_category     = $boat_name.' ['.$user_id.']';
    $my_description  = $first_name.' '.$last_name.' ['.$boat_model.']';
    
    function insert_category ($category,$description,$parent) {
    $parent_term = term_exists($parent,'media_category');
    $parent_term_id = $parent_term['term_id'];
    wp_insert_term(
        $category,
        'media_category',
        array(
            'description' => $description,
            'slug'        => $category,
            'parent'      => $parent_term_id,
        )
    );
    }
    
    insert_category($my_category,$my_description,$parent_name);
    Plugin Author xnau webdesign

    (@xnau)

    There is a filter in the Image Expansion Kit add-on that sets the target directory for the upload:

    pdbiex-uploads_dir

    Your filter handler can change that according to who is logged in at the time the upload takes place and also when they are logged in to view the images.

    However: these images won’t be visible to others because if you set the directory based on the currently logged-in user, the image will only be found when that user is logged in. So, if the images are meant to be private, then no problem.

    Thread Starter supernova42

    (@supernova42)

    I need all images to be seen by all users.

    My enquiry is about the files in the Media Library. I’m able to create Categories in the Media Library based on each users name etc.

    What I need to do now is assign that users Category name to each of the images he uploads. By doing that I can look at just the images for each user by selecting their category name.

    Thanks

    Plugin Author xnau webdesign

    (@xnau)

    OK, that is a general WordPress thing, I don’t know the code to use for that, but I think it’s possible to set up a filter so that when an image is added to the Media Library, you can assign a category for it.

    Thread Starter supernova42

    (@supernova42)

    Okay thank you

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Image Categories based on Users Name’ is closed to new replies.