Skip to content

palasthotel/wp-media-license

Repository files navigation

Media License

Allows you to add media license info to your media files. Plugin is available at WordPress.org

Captions are automatically added to images in post content. Elsewhere you can use media_license_get_caption function.

Templates

You can copy the default templates from plugins "templates" folder to "%theme%/plugin-parts/*".

media-license-caption.tpl.php

Available variables in template:

$this ===> MediaLicense object context.

$caption ===> Image caption text.

$original_caption ===> Unmanipulated caption text. (No manipulations from other plugins)

$license ===> MediaLicense\CreativeCommon object

$info ===> Array of meta information. (author, info, url, all additional from add_fields filter)

$media_license_author ===> Author field text.

$media_license_info ===> License info text.

$media_license_url ===> License url.


Filters

Available filters for media license plugin.

Provide custom template path

Add the following filter in your custom plugins code and provide a path that exists in your plugin.

if(class_exists("\Palasthotel\MediaLicense\Plugin")){
	add_filter(\Palasthotel\MediaLicense\Plugin::FILTER_TEMPLATE_PATHS, function($paths){
		$paths[] = dirname(__FILE__)."/templates";
		return $paths;
	});
}

Manipulate caption text

add_filter( 'media_license_edit_caption', 'myplugin_media_license_edit_caption', 10, 3);
function myplugin_media_license_edit_caption($caption, $original_caption, $info){
	// manipulate $caption
	return $caption;
}

Parameters:

$caption ==> The manipulated caption.

$caption_original ==> The unmanipulated caption.

$info ==> Array of info field values.

Return

manipulated_caption ===> Manipulate the $caption and return the result

Add even more info fields

add_filter( 'media_license_add_fields', 'myplugin_media_license_add_fields');
function myplugin_media_license_add_fields($fields){
	// manipulate $fields
	return $fields;
}

Parameters:

$fields ==> Array of field definitions.

Available Types:

$fields['my_text_field'] = array(
	'label' => 'Field label',
	'input' => 'text',
	'value' => 'default value',
	'helps' => 'Descriptive text',
);

$fields['my_select_field'] = array(
    'label' => 'Field label',
    'input' => 'select',
    'value' => '',
    'helps' => 'Descriptive text',
    'selections' => array(
        array(
            "value" => 'slug1',
            "label" => 'Label 1',
        ),
        ...
    ),
);

Autoload captions

add_filter( 'media_license_autoload_async_image_license', 'myplugin_media_license_autoload_async_image_license', 10, 3);
function myplugin_media_license_autoload_async_image_license($autoload){
	// disable autoload 
	return false;
}

Parameters:

$autoload ==> boolean.

Return

autoload ===> if captions should be autoloaded in post content

Functions

Public plugin function. Always use php function_exists(...) before using an function.

Get license caption by attachment ID

$caption = media_license_get_caption($attachment_id)

Parameters:

$attachment_id ==> ID of the attachment.

Return

caption ===> rendered caption.