Skip to content
This repository was archived by the owner on Nov 17, 2024. It is now read-only.

Using MediaThèque from your plugin

imath edited this page Oct 8, 2018 · 1 revision

What about relying on MediaThéque to handle your plugin's Media uploads needs ?

If you are using the WP_Editor within your plugin to allow front-end post type submissions for example, MediaThèque will automagically add an "Add User Media" button above your instance of the WP_Editor. You have nothing to do. Here's a screenshot about what happens with the bbPress topic form:

bbPress gif

NB: as, by default, bbPress is using the Quicktags mode, to make the animation more visual, I've used a specific filter to use the visual editor instead.

You can also use the mediatheque_button() function with other regular text fields. Once the user will click on the Insert Media button, this text field will contain the User Media permalink. Here's an example that adds an "Add User Media" button to the BuddyPress activity post form:

BuddyPress Activity gif

The code used to achieve this is:

<?php

function mediatheque_button_activity_post_form() {
	if ( ! function_exists( 'mediatheque_button' ) ) {
		return;
	}
	
	mediatheque_button( array(
		'editor_id' => 'whats-new',
	) );
}
add_action( 'bp_activity_post_form_options', 'mediatheque_button_activity_post_form' );

The editor_id argument is the ID of the regular text field you wish to use.

Clone this wiki locally