BuddyDev

Search

Replies

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #7030

    I think I got it! Just tested it and it is working.

    ——————————–

    function mpp_custom_upload_permission( $can_do, $component, $component_id, $gallery ) {

    $total_uploaded_audio = mpp_get_media_count(array( ‘component_id’ => bp_loggedin_user_id(), ‘component’=> ‘members’, ‘type’ => ‘audio’ ) );

    $total_uploaded_photo = mpp_get_media_count(array( ‘component_id’ => bp_loggedin_user_id(), ‘component’=> ‘members’, ‘type’ => ‘photo’ ) );

    if ( empty( $gallery ) ) {
    return $can_do;
    }

    $type = $gallery->type;

    if ( $type == ‘photo’ && $total_uploaded_photo >= ‘8’ ) {
    $can_do = false;
    }

    if ( $type == ‘audio’ && $total_uploaded_audio >= ’10’ ) {
    $can_do = false;
    }

    return $can_do;

    }

    add_filter( ‘mpp_user_can_upload’, ‘mpp_custom_upload_permission’, 10, 4 );

    ——————————–

    Let me know if I should be aware of anything else with this, otherwise I will mark as resolved.
    Thanks again

    • This reply was modified 7 years, 10 months ago by Brian.
  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #7027

    Thank you Brajesh.
    So is there no way to disallow audio uploads while allowing image uploads in MediaPress?

    Meaning, separate the two?

    I am not looking for ‘$total_uploaded’ (combination of both audio and image), but rather restrict audio uploads to 10 and restricting image uploads to 8.

    I’ve created the following hook and it works

    ————————————-

    function mpp_custom_upload_permission( $can_do, $component, $component_id, $gallery ) {

    $audiogalleryid2 = mpp_get_gallery_ids( array( ‘component’=> ‘members’, ‘component_id’=> bp_loggedin_user_id(), ‘type’=> ‘audio’ ) );
    list($audiogalleryid) = $audiogalleryid2;

    $photogalleryid2 = mpp_get_gallery_ids( array( ‘component’=> ‘members’, ‘component_id’=> bp_loggedin_user_id(), ‘type’=> ‘photo’ ) );
    list($photogalleryid) = $photogalleryid2;

    $audioattach = get_children( array( ‘post_parent’ => $audiogalleryid ) );
    $audiocount = count( $audioattach );

    $photoattach = get_children( array( ‘post_parent’ => $photogalleryid ) );
    $photocount = count( $photoattach );

    if ($photocount < ‘8’) {
    return $can_do;
    }

    else {
    $can_do = false;
    }

    if ($audiocount < ’10’) {
    return $can_do;
    }

    else {
    $can_do = false;
    }

    }

    add_filter( ‘mpp_user_can_upload’, ‘mpp_custom_upload_permission’, 10, 4 );

    ————————————-

    But as I was saying, if a user has, for example, 8 photo uploads.. and only 2 audio uploads, it still restricts users from uploading across the board (rather than restricting photo uploads and allowing 8 more audio uploads).

    Hope that makes sense

    • This reply was modified 7 years, 10 months ago by Brian.
    • This reply was modified 7 years, 10 months ago by Brian.
  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #7014

    Looked into this a little bit more. Seems this is the proper hook that I’m going to be wanting to latch onto:

    ——————–
    mpp_user_can_upload:
    ——————–

    function mpp_user_can_upload( $component, $component_id, $gallery = null ) {
    if ( ! is_user_logged_in() ) {
    return false;
    }
    $can_do = false;
    $user_id = get_current_user_id();
    if ( is_super_admin() ) {
    $can_do = true;
    } elseif ( mediapress()->is_bp_active() && $component == ‘members’ && $component_id == $user_id ) {
    $can_do = true;
    } elseif ( mpp_is_active_component( ‘groups’ ) && $component == ‘groups’ && function_exists( ‘groups_is_user_member’ ) && groups_is_user_member( $user_id, $component_id ) ) {
    $can_do = true;
    } elseif ( mpp_is_active_component( ‘sitewide’ ) && $component == ‘sitewide’ && $component_id == $user_id ) {
    $can_do = true;
    }
    $can_do = apply_filters( ‘mpp_user_can_upload’, $can_do, $component, $component_id, $gallery );
    return apply_filters( “mpp_can_user_upload_to_{$component}”, $can_do, $gallery );
    }

    ——————–
    ——————–

    Also I’m getting a current count of the number of media items in the gallery on one of my pages by using:

    $audioattach = get_children( array( ‘post_parent’ => $audiogalleryid ) );
    $audiocount = count( $audioattach );

    &

    $photoattach = get_children( array( ‘post_parent’ => $photogalleryid ) );
    $photocount = count( $photoattach );

    So I’m thinking it is possible to simply use PHP to remove the upload link once a user gets over their limit.
    But this may be a band-aid solution.

    And I’m not familiar with properly using hooks quite well, but I can try and mess around with this.

    If you have any thoughts Brajesh, I’d love to hear it. Also an FYI be having my boss buy a related plugin soon when this is getting ready to launch.

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #5927

    Thanks for the tidbit on the orphan attribute, wasn’t sure what that was about.
    I am passing $user_id in my array, but I think because I am logged in as admin while on localhost/development it’s for whatever reason overriding it. Anyways, this won’t be an issue when I move out of development testing, so I’m not worried about it.

    Everything else is working great. Was able to make my own custom front-end form like

    [Song Title] (text field)
    [Audio File Upload] (audio file input)
    [Album Cover] (image file input)

    And just tested and they immediately go into the MediaPress gallery and shortcode listing with the three inputs. Still have to optimize it, but i’m happy it’s what I wanted 🙂

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #5911

    Nevermind, turns out this wasn’t a MediaPress issue at all.
    I used mpp_media_to_json and compared the two uploads styles.
    Noticed the ‘author’ wasn’t setting in correct for my ajax uploads.
    So just simply added

    $setpostauthor = array(
    ‘ID’ => $id,
    ‘post_author’ => 470
    );
    wp_update_post( $setpostauthor );

    to my function and now they show up in the playlist query.

    • This reply was modified 8 years, 1 month ago by Brian.
  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #5909

    Okay so looking at mpp-media-functions.php
    https://github.com/buddydev/mediapress/blob/master/core/media/mpp-media-functions.php

    Maybe I should update metadata

    mpp_update_media_meta( $id, ‘_mpp_is_mpp_media’, 1 );
    wp_update_attachment_metadata( $id, mpp_generate_media_metadata( $id, $src ) );

    as well? But it still is not showing up on my query/shortcode playlist

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #5908

    To clarify, if not clear, these custom uploaded files are showing up just fine in my admin backend and buddypress profiles in appropriate gallery with all the others, but not showing up when using mpp-list-media, or more specifically [mpp-list-media type=audio view=playlist user_id=’.$userid.’]

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #5793

    Okay. Maybe I’ll see about loading the uploader in an iframe or other such method (currently uploader is embedded in bootstrap modal, not directly on page). Thanks for the support.

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #5741

    Brajesh,

    Good news.
    I searched previous support threads and found these two:

    https://buddydev.com/support/forums/topic/limit-number-of-galleries-per-user/
    https://buddydev.com/support/forums/topic/mediapress-predefined-user-galleries/

    With some slight modifications, I was able to get the result I wanted.

    My solution in this was to auto-create the two galleries (audio and photo), and then three other functions to disable gallery creation, editing and deletion.

    This is basically the same effect I was looking for (better, even, as if a user is restricted from creating more than 1 gallery per media type, why not create it for them automatically).

    I will mark this as resolved, thank you again.

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #5731

    Okay no worries Brajesh, I understand.