BuddyDev

Search

[Resolved] How to Hook into Mediapress Upload via PHP? (custom IPTC, EXIF & XMP data)


  • Participant
    Level: Initiated
    Posts: 9
    Christian W Zagarskas on #25245

    Summary: We are processing IPTC, EXIF and XMP metta data for every image that is uploaded and added them into custom editable fields.

    At this time we have figured out how to process all of the data, extract it from images, create custom fields, allow users to edit/save the data, update it into the images XML layer, in the WordPress and Mediapress layer ect… However, the following areas elude us:
    1- Where is the initial upload process started in PHP?
    2- what functions can we call on upload/save to update the mediapress cache?

    I have carefully examined the JS API documentation for the media up-loader
    https://buddydev.com/mediapress/api-guides/mediapress-uploader-events-lifecycle/
    However – we do not want to use “mpp:uploader:upload.success” as our entry point to this feature because it is in Javascript. We want to know where we can hook in using PHP.

    Few questions:
    Without using “mpp:uploader” JS events is there a way to hook into the mediapress upload actions in PHP?
    IE: What Medapress PHP functions/hooks/line numbers are related to the upload function?

    What we want: when a user uploads an image we want to take the IPTC data and use that for the title and description. We want this to happen “on first upload” and without using the JS API.

    If anyone can point us in the right direction, a function name or hook that would be great!
    Thank you for your consideration.


  • Keymaster
    (BuddyDev Team)
    Posts: 12238
    Brajesh Singh on #25246

    Hi Christian,
    Thank you for the question.

    We use the ajax action ‘wp_ajax_mpp_add_media’ to start upload. you can find this code in mediapress/core/ajax/mpp-ajax.php

    https://github.com/buddydev/mediapress/blob/master/core/ajax/mpp-ajax.php#L66

    It uses local storage helper for upload

    https://github.com/buddydev/mediapress/blob/master/core/storage/class-mpp-local-storage.php

    Hope that helps.

    Regards
    Brajesh


  • Participant
    Level: Initiated
    Posts: 9
    Christian W Zagarskas on #25247

    Thank you! I will look closer at those.

    Is there any way to hook into the following?
    mpp_add_media()
    add_media()
    mpp_get_title_desc_from_meta()
    get_meta()

    we need some way to update the initial $media_data on/around “first upload”


  • Keymaster
    (BuddyDev Team)
    Posts: 12238
    Brajesh Singh on #25248

    Hi Almost, all of them provide you some opportunity to hook(action or filter) except the mpp_get_title_desc_from_meta.

    I am hoping that you can hook into ‘mpp_media_added’ and update the settings/content for media as you please.

    regards
    Brajesh


  • Participant
    Level: Initiated
    Posts: 9
    Christian W Zagarskas on #25249

    ok.

    so… looking into add_action( ‘wp_ajax_mpp_add_media’, ‘my_custom_function’ );
    but since that action does not exist till private function setup() in MPP_Ajax_Helper
    because its a private function of the class it therefore seems to me that I am prevented from extending any functionality there… or am I wrong about this?

    mpp_media_added – I see the same problem there as well.
    add_action( ‘mpp_media_added’, ‘my_custom_function’, 9, 9 );
    will that really work? Its not available till after MPP_Gallery_Categories_Helper-> setup()
    but in that case I see its a public function… so, will that work?


  • Keymaster
    (BuddyDev Team)
    Posts: 12238
    Brajesh Singh on #25250

    Hi Christian,
    1. You can completely rewrite the upload by attaching to ‘wp_ajax_mpp_add_media’ on a high priority(say 9).
    If you do that, you will need to emulate the whole upload process as you see in the add_media.

    It does not matter if the method is private as you are not using that method. You are simply getting called before that and return the response, so that method never gets called(since it is ajax request).

    You can add to the action from anywhere, please make sure the file/code gets run before the action fires(it fires at very low priority, so even if you load on plugins_loaded, it will be fine).

    Regards
    Brajesh


  • Participant
    Level: Initiated
    Posts: 9
    Christian W Zagarskas on #25251

    ah, yes. I see. thank you very much.

    I have carefully re-read your posts here and examined each function mentioned a second time.
    I am now able to edit/save the media IPTC, XMP and EXIF on upload.

    I want to make sure I am handling this clearly.
    consider the following situation:

    In my own class MPP_IPTC_data_Helper
    add_action( ‘mpp_media_added’, array( $this, ‘my_add_media_IPTC’ ) );

    — and that works great, I am able to edit the meta values I seek based on your suggestions.

    however, should I also do this as well?
    add_action( ‘wp_ajax_mpp_add_media’, array( $this, ‘my_add_media_IPTC’ ) );
    when would I need/want to use wp_ajax_mpp_add_media, if at all?


  • Keymaster
    (BuddyDev Team)
    Posts: 12238
    Brajesh Singh on #25262

    Hi ,
    ‘mpp_media_added’ is more than efficient.

    The other action ‘wp_ajax_mpp_add_media’ is not advised. It was a way in case you want to handle the things completely differently.

    I am glad it is working now.

    marking ti resolved.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: resolved
Subscribe