<?php
/**
 * Provides an example of the filters provided by the "Media Manager Enhancements" feature
 *
 * In this example the initial value for the MIME Type dropdown control is changed.
 *
 * @package MLA Media Modal Hooks Example
 * @version 1.00
 */

/*
Plugin Name: MLA Media Modal Hooks Example
Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
Description: Provides an example of the filters provided by the "Media Manager Enhancements" feature
Author: David Lingren
Version: 1.00
Author URI: http://fairtradejudaica.org/our-story/staff/

Copyright 2014 David Lingren

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You can get a copy of the GNU General Public License by writing to the
	Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*/

/**
 * Class MLA Media Modal Hooks Example hooks all of the filters provided by the "Media Manager Enhancements" feature
 *
 * Call it anything you want, but give it an unlikely and hopefully unique name. Hiding everything
 * else inside a class means this is the only name you have to worry about.
 *
 * @package MLA Media Modal Hooks Example
 * @since 1.00
 */
class MLAMediaModalExample {
	/**
	 * Initialization function, similar to __construct()
	 *
	 * Installs filters and actions that handle the MLA hooks for uploading and mapping.
	 *
	 * @since 1.00
	 *
	 * @return	void
	 */
	public static function initialize() {
		/*
		 * The filters are only useful in the admin section; exit if in the "front-end" posts/pages. 
		 */
		if ( ! is_admin() )
			return;

		/*
		 * add_filter parameters:
		 * $tag - name of the hook you're filtering; defined by [mla_gallery]
		 * $function_to_add - function to be called when [mla_gallery] applies the filter
		 * $priority - default 10; lower runs earlier, higher runs later
		 * $accepted_args - number of arguments your function accepts
		 *
		 * Comment out the filters you don't need; save them for future use
		 */
		add_filter( 'mla_media_modal_initial_filters', 'MLAMediaModalExample::mla_media_modal_initial_filters_filter', 10, 1 );
	}

	/**
	 * MLA Edit Media Initial Filters Filter
	 *
	 * This filter gives you an opportunity to change the initial values of the
	 * Media Manager Modal Window toolbar controls.
	 *
	 * @since 1.00
	 *
	 * @param	array	toolbar control initial values
	 *
	 * @return	array	updated toolbar control initial values
	 */
	public static function mla_media_modal_initial_filters_filter( $initial_values ) {
		/*
		 * Uncomment the error_log statements in any of the filters to see what's passed in
		 */
		//error_log( 'MLAMediaModalExample::mla_media_modal_initial_filters_filter $initial_values = ' . var_export( $initial_values, true ), 0 );

		/*
		 * The default initial values are:
		 *
		 * $initial_values = array(
		 * 	'filterMime' => 'all',
		 * 	'filterMonth' => 0,
		 * 	'filterTerm' => 0,
		 * 	'searchConnector' => 'AND',
		 * 	'searchFields' => array( 'title', 'content' ),
		 * 	'searchValue' => '',
		 * );
		 *
		 * Other values include:
		 * 	filterMime: uploaded, image, audio, video, text, application, detached
		 * 	filterMonth: year and month, e.g., '201407'
		 * 	filterTerm: term ID in the selected taxonomy (NOT term-taxonomy ID)
		 * 	searchConnector: 'OR'
		 * 	searchFields: name (slug), alt-text, excerpt (caption), terms
		 */

		// uncomment next lines to set initial values
		//$initial_values['filterMime'] = 'image';
		//$initial_values['filterMonth'] = '201404';
		//$initial_values['filterTerm'] = 175; // term ID in attachment_tags
		//$initial_values['searchConnector'] = 'OR';
		//$initial_values['searchValue'] = 'de la';
		
		return $initial_values;
	} // mla_media_modal_initial_filters_filter
} //MLAMediaModalExample

/*
 * Install the filters at an early opportunity
 */
add_action('init', 'MLAMediaModalExample::initialize');
?>