Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Pre-post hook, modify before upload #26

Closed
maxmarkus opened this issue May 17, 2021 · 6 comments
Closed

Feature: Pre-post hook, modify before upload #26

maxmarkus opened this issue May 17, 2021 · 6 comments

Comments

@maxmarkus
Copy link

Hello,

I would like to see the possibility to modify the content before upload (and the other way around), since I would like to verify and change the payload before sending it to vimeo. Not talking about the video itself, but about the metadata.

My initial thought was about using a separate folder per user in vimeo, but that might be overkill.
Even if there are later maybe thousands of videos, at the end it should be enough to prefix the titles of a given user/entity with its id.

Therefore my wish would be two filters to modify the data before storing and after fetching it from vimeo.

Best, Markus

@gdarko
Copy link
Owner

gdarko commented May 27, 2021

Hi @maxmarkus ,

In the free version of the plugin, there is option to use dgv_backend_after_upload hook.

Something like this:

function my_dgv_backend_after_upload($params) {

      $vimeo_id = $params['vimeo_id'];
      // Do your logic...

}
add_action('dgv_backend_after_upload', 'my_dgv_backend_after_upload');

At this time the plugin API does not include utilities for folder management, but i will think for a way to include those methods in both free and premium versions.

Best Regards,
Darko

@maxmarkus
Copy link
Author

Hi @gdarko

Thank you for your response, I am not sure if this is what I was looking for.

I checked the code and I think it would be a dgv_backend_before_upload that I need in order to modify the $params, so those values are also persisted in vimeo.
Folder management is a bigger topic of its own, guess not ultimately necessary for my use case, just convenience.

Using the premium version btw.

So, would it be possible to add dgv_backend_before_upload to your feature requests, please?

Best regards,
Markus

@gdarko
Copy link
Owner

gdarko commented May 31, 2021

Hi @maxmarkus

Thanks for the information.

Just wanted to ask, which APIs you are using?

For example, I can add those hooks when the process is done through the backend (using PHP) e.g when using the frontend upload.

However, I can't add those hooks when using the Gutenberg/TinyMCE upload because those are handled entirely via JavaScript. If WordPress has some action/filter system for JavaScript I will add those for the Gutenberg/TinyMCE elements.

Best Regards,
Darko

@maxmarkus
Copy link
Author

maxmarkus commented May 31, 2021

Hi @gdarko

Using the Vimeo custom post type that is available in the backend. Not using any Gutenberg/TinyMCE, since my CPTs are built with standard ACF fields, where I can use a "relation" to get Vimeo entries.

I wonder what should be different for Gutenberg/TinyMCE, since you do do_action( 'dgv_backend_after_upload' in three places and those are right before the related video upload. So the hook could be in those places right before the Video upload to modify the title and description? Those are the only fields I see as relevant to be changed.

Edit: I see that

public function store_upload() {
is different, so you are right that Gutenberg/TinyMCE is out of the game, also couldn't find a filter/action/hook for that.

Then the hook would only be available for the other use cases, which can be documented.

Best, Markus

@gdarko
Copy link
Owner

gdarko commented Jun 1, 2021

@maxmarkus , I added the hook for the other use cases as of version 1.7.1

For example, different client requested to add a timestamp on the Video dates created from the front-end, This wasn't possible before 1.7.1 and you can see example here:

/**
 * Append date to the video title stored in Media > Library
 *
 * @param $args
 *
 * @return mixed
 */
function dgv_before_create_local_video_params_823842831( $args ) {
	$args['post_title'] = sprintf( '%s - %s', $args['post_title'], wp_date( get_option( 'date_format' ) ) );

	return $args;
}

add_filter( 'dgv_before_create_local_video_params', 'dgv_before_create_local_video_params_823842831', 20 );

/**
 * Append date to the video title stored in Vimeo.com
 * @param $args
 *
 * @return mixed
 */
function dgv_before_create_api_video_params_823842831( $args ) {
	$args['name'] = sprintf( '%s - %s', $args['name'], wp_date( get_option( 'date_format' ) ) );

	return $args;
}
add_filter( 'dgv_before_create_api_video_params', 'dgv_before_create_api_video_params_823842831', 20 );

Please note that you can still manipulate the Vimeo.com entries with the using dgv_backend_after_upload and dgv_frontend_after_upload. It just requires instance of WP_DGV_Api_Helper class. Something like this:

/**
 * Additional vimeo api manipulation after video upload.
 *
 * @param $args
 */
function dgv_backend_after_upload_823842831( $args ) {

	$uri    = wvv_id_to_uri( $args['vimeo_id'] );
	$source = isset( $args['software']['source'] ) ? $args['software']['source'] : ''; // Possible values: Editor, Media Table, API::upload, API::uplod_pull

	try {
		$vimeo = new WP_DGV_Api_Helper();
		$vimeo->set_video_folder( $uri, '/users/120624714/projects/2801250' ); // eg. /users/{user_id}/projects/{folder_id}
		// Other calls..
		// Eg. $vimeo->api->get()
		// Eg. $vimeo->api->request()

	} catch ( \Exception $e ) {
		error_log( 'WP Vimeo Videos error: ' . $e->getMessage() );
	}
}
add_action( 'dgv_backend_after_upload', 'dgv_backend_after_upload_823842831', 20 );

@maxmarkus
Copy link
Author

Thanks alot, I think that solves my requirements. Would close it for now and only reopen if I experience issues with the new feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants