query
*
* @return void actions never return anything
*/
public static function mla_gallery_wp_query_object_action( $query_arguments ) {
//error_log( 'MLAGalleryHooksExample::mla_gallery_wp_query_object_action $query_arguments = ' . var_export( $query_arguments, true ), 0 );
self::$wp_query_properties = array();
self::$wp_query_properties ['request'] = MLAShortcodes::$mla_gallery_wp_query_object->request;
self::$wp_query_properties ['query_vars'] = MLAShortcodes::$mla_gallery_wp_query_object->query_vars;
self::$wp_query_properties ['post_count'] = MLAShortcodes::$mla_gallery_wp_query_object->post_count;
//error_log( 'MLAGalleryHooksExample::mla_gallery_wp_query_object_action self::$wp_query_properties = ' . var_export( self::$wp_query_properties, true ), 0 );
/*
* Unlike Filters, Actions never return anything
*/
return;
} // mla_gallery_wp_query_object_action
/**
* MLA Gallery Enclosed Content, final filter
*
* This filter gives you an opportunity to record or modify the content enclosed by the shortcode
* when the [mla_gallery]content[/mla_gallery] form is used.
* This final filter is called just after the WP_query and before control is passed
* to the alternate gallery shortcode.
*
* @since 1.02
*
* @param NULL|string content enclosed by the shortcode, if any
*
* @return array updated shortcode content
*/
public static function mla_gallery_final_content_filter( $shortcode_content ) {
//error_log( 'MLAGalleryHooksExample::mla_gallery_final_content_filter $shortcode_content = ' . var_export( $shortcode_content, true ), 0 );
return $shortcode_content;
} // mla_gallery_final_content_filter
/**
* Use MLA Gallery Style
*
* You can use this filter to allow or suppress the inclusion of CSS styles in the
* gallery output. Return 'true' to allow the styles, false to suppress them. You can also
* suppress styles by returning an empty string from the mla_gallery_style_parse_filter below.
*
* @since 1.00
*
* @param boolean true unless the mla_style parameter is "none"
* @param string value of the mla_style parameter
*
* @return boolean true to fetch and parse the style template, false to leave it empty
*/
public static function use_mla_gallery_style_filter( $use_style_template, $style_template_name ) {
//error_log( 'MLAGalleryHooksExample::use_mla_gallery_style_filter $use_style_template = ' . var_export( $use_style_template, true ), 0 );
//error_log( 'MLAGalleryHooksExample::use_mla_gallery_style_filter $style_template_name = ' . var_export( $style_template_name, true ), 0 );
/*
* Filters must return the first argument passed in, unchanged or updated
*/
return $use_style_template;
} // use_mla_gallery_style_filter
/**
* MLA Gallery Style Values
*
* The "Values" series of filters gives you a chance to modify the substitution parameter values
* before they are used to complete the associated template (in the corresponding "Parse" filter).
* It is called just before the values are used to parse the associated template.
* You can add, change or delete parameters as needed.
*
* @since 1.00
*
* @param array parameter_name => parameter_value pairs
*
* @return array updated substitution parameter name => value pairs
*/
public static function mla_gallery_style_values_filter( $style_values ) {
//error_log( 'MLAGalleryHooksExample::mla_gallery_style_values_filter $style_values = ' . var_export( $style_values, true ), 0 );
/*
* You also have access to the PHP Super Globals, e.g., $_REQUEST, $_SERVER
*/
//error_log( 'MLAGalleryHooksExample::mla_gallery_style_values_filter $_REQUEST = ' . var_export( $_REQUEST, true ), 0 );
//error_log( 'MLAGalleryHooksExample::mla_gallery_style_values_filter $_SERVER[ REQUEST_URI ] = ' . var_export( $_SERVER['REQUEST_URI'], true ), 0 );
/*
* You can use the WordPress globals like $wp_query, $wpdb and $table_prefix as well.
* Note that $wp_query contains values for the post/page query, NOT the [mla_gallery] query.
*/
global $wp_query;
//error_log( 'MLAGalleryHooksExample::mla_gallery_style_values_filter $wp_query->query = ' . var_export( $wp_query->query, true ), 0 );
return $style_values;
} // mla_gallery_style_values_filter
/**
* MLA Gallery Style Template
*
* The "Template" series of filters gives you a chance to modify the template value before
* it is used to generate the HTML markup (in the corresponding "Parse" filter).
* It is called just before the template is used to generate the markup.
* You can modify the template as needed.
*
* @since 1.00
*
* @param string template used to generate the HTML markup
*
* @return string updated template
*/
public static function mla_gallery_style_template_filter( $style_template ) {
//error_log( 'MLAGalleryHooksExample::mla_gallery_style_template_filter $style_template = ' . var_export( $style_template, true ), 0 );
return $style_template;
} // mla_gallery_style_template_filter
/**
* MLA Gallery Style Parse
*
* The "Parse" series of filters gives you a chance to modify or replace the HTML markup
* that will be added to the [mla_gallery] output. It is called just after the values array
* (updated in the corresponding "Values" filter) is combined (parsed) with the template.
* You can modify the HTML markup already prepared or start over with the template and the
* substitution values.
*
* @since 1.00
*
* @param string HTML markup returned by the template parser
* @param string template used to generate the HTML markup
* @param array parameter_name => parameter_value pairs
*
* @return array updated HTML markup for gallery output
*/
public static function mla_gallery_style_parse_filter( $html_markup, $style_template, $style_values ) {
//error_log( 'MLAGalleryHooksExample::mla_gallery_style_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
//error_log( 'MLAGalleryHooksExample::mla_gallery_style_parse_filter $style_template = ' . var_export( $style_template, true ), 0 );
//error_log( 'MLAGalleryHooksExample::mla_gallery_style_parse_filter $style_values = ' . var_export( $style_values, true ), 0 );
return $html_markup;
} // mla_gallery_style_parse_filter
/**
* MLA Gallery Open Values
*
* Note: The $markup_values array is shared among the open, row open, row close and close functions.
* It is also used to initialize the $item_values array.
*
* @since 1.00
*
* @param array parameter_name => parameter_value pairs
*
* @return array updated substitution parameter name => value pairs
*/
public static function mla_gallery_open_values_filter( $markup_values ) {
//error_log( 'MLAGalleryHooksExample::mla_gallery_open_values_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
return $markup_values;
} // mla_gallery_open_values_filter
/**
* MLA Gallery Open Template
*
* @since 1.00
*
* @param string template used to generate the HTML markup
*
* @return string updated template
*/
public static function mla_gallery_open_template_filter( $open_template ) {
//error_log( 'MLAGalleryHooksExample::mla_gallery_open_template_filter $open_template = ' . var_export( $open_template, true ), 0 );
return $open_template;
} // mla_gallery_open_template_filter
/**
* MLA Gallery Open Parse
*
* @since 1.00
*
* @param string HTML markup returned by the template parser
* @param string template used to generate the HTML markup
* @param array parameter_name => parameter_value pairs
*
* @return array updated HTML markup for gallery output
*/
public static function mla_gallery_open_parse_filter( $html_markup, $open_template, $markup_values ) {
//error_log( 'MLAGalleryHooksExample::mla_gallery_open_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
//error_log( 'MLAGalleryHooksExample::mla_gallery_open_parse_filter $open_template = ' . var_export( $open_template, true ), 0 );
//error_log( 'MLAGalleryHooksExample::mla_gallery_open_parse_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
return $html_markup;
} // mla_gallery_open_parse_filter
/**
* MLA Gallery Style
*
* This is an old filter retained for compatibility with earlier MLA versions.
* You will probably find the "Values" and "Parse" filters more useful.
*
* @since 1.00
*
* @param string HTML markup for "gallery style" and "gallery open", combined
* @param array parameter_name => parameter_value pairs for gallery style
* @param array parameter_name => parameter_value pairs for gallery open
* @param string template used to generate the HTML markup for gallery style
* @param string template used to generate the HTML markup for gallery open
*
* @return array updated HTML markup for "gallery style" and "gallery open" output
*/
public static function mla_gallery_style_filter( $html_markup, $style_values, $open_values, $style_template, $open_template ) {
//error_log( 'MLAGalleryHooksExample::mla_gallery_style_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
//error_log( 'MLAGalleryHooksExample::mla_gallery_style_filter $style_values = ' . var_export( $style_values, true ), 0 );
//error_log( 'MLAGalleryHooksExample::mla_gallery_style_filter $open_values = ' . var_export( $open_values, true ), 0 );
//error_log( 'MLAGalleryHooksExample::mla_gallery_style_filter $style_template = ' . var_export( $style_template, true ), 0 );
//error_log( 'MLAGalleryHooksExample::mla_gallery_style_filter $open_template = ' . var_export( $open_template, true ), 0 );
return $html_markup;
} // mla_gallery_style_filter
/**
* MLA Gallery Row Open Values
*
* @since 1.00
*
* @param array parameter_name => parameter_value pairs
*
* @return array updated substitution parameter name => value pairs
*/
public static function mla_gallery_row_open_values_filter( $markup_values ) {
//error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_values_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
return $markup_values;
} // mla_gallery_row_open_values_filter
/**
* MLA Gallery Row Open Template
*
* @since 1.00
*
* @param string template used to generate the HTML markup
*
* @return string updated template
*/
public static function mla_gallery_row_open_template_filter( $row_open_template ) {
//error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_template_filter $row_open_template = ' . var_export( $row_open_template, true ), 0 );
return $row_open_template;
} // mla_gallery_row_open_template_filter
/**
* MLA Gallery Row Open Parse
*
* @since 1.00
*
* @param string HTML markup returned by the template parser
* @param string template used to generate the HTML markup
* @param array parameter_name => parameter_value pairs
*
* @return array updated HTML markup for gallery output
*/
public static function mla_gallery_row_open_parse_filter( $html_markup, $row_open_template, $markup_values ) {
//error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
//error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_parse_filter $row_open_template = ' . var_export( $row_open_template, true ), 0 );
//error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_parse_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
return $html_markup;
} // mla_gallery_row_open_parse_filter
/**
* MLA Gallery Item Values
*
* @since 1.00
*
* @param array parameter_name => parameter_value pairs
*
* @return array updated substitution parameter name => value pairs
*/
public static function mla_gallery_item_values_filter( $item_values ) {
//error_log( 'MLAGalleryHooksExample::mla_gallery_item_values_filter $item_values = ' . var_export( $item_values, true ), 0 );
/*
* For this first example, we will reformat the 'date' value as d/m/Y. We use a shortcode parameter of our
* own to do this on a gallery-by-gallery basis, leaving other [mla_gallery] instances untouched.
*/
if ( isset( self::$shortcode_attributes['my_filter'] ) && 'format date' == self::$shortcode_attributes['my_filter'] ) {
/*
* Default format is YYYY-MM-DD HH:MM:SS (HH = 00 - 23), or 'Y-m-d H:i:s'
* Convert to UNIX timestamp so any reformat is possible
*/
$old_date = $item_values['date'];
$timestamp = mktime( substr( $old_date, 11, 2 ), substr( $old_date, 14, 2 ), substr( $old_date, 17, 2 ), substr( $old_date, 5, 2 ), substr( $old_date, 8, 2 ), substr( $old_date, 0, 4 ) );
/*
* Update the $item_values and pass them back from the filter.
* We must also update the caption because it was composed before this filter is called.
*/
$item_values['date'] = date( 'd/m/Y', $timestamp );
$item_values['caption'] = $item_values['description'] . $item_values['date'];
return $item_values;
}
/*
* For our example, we will add to the $item_values['caption'] value an unordered list
* of the custom fields populated for each gallery item. We use a shortcode parameter of our
* own to do this on a gallery-by-gallery basis, leaving other [mla_gallery] instances untouched.
*/
if ( ! isset( self::$shortcode_attributes['my_filter'] ) || 'all custom' != self::$shortcode_attributes['my_filter'] )
return $item_values; // leave them unchanged
/*
* Preserve the existing caption, if present
*/
$my_caption = '';
if ( ! empty( $item_values['caption'] ) )
$my_caption .= $item_values['caption'] . "
\r\n";
/*
* Retrieve the custom fields for this item, if any,
* and extract the values we are interested in.
*/
$custom_fields = array();
$post_meta = get_metadata( 'post', $item_values['attachment_ID'] );
//error_log( 'MLAGalleryHooksExample::mla_gallery_item_values_filter $post_meta = ' . var_export( $post_meta, true ), 0 );
if ( is_array( $post_meta ) ) {
foreach ( $post_meta as $post_meta_key => $post_meta_value ) {
if ( empty( $post_meta_key ) )
continue;
/*
* WordPress stores several of its own values as custom fields, which we will skip.
* Some of the values you might find useful are:
* _wp_attached_file, _wp_attachment_metadata, and _wp_attachment_image_alt
*/
if ( '_' == $post_meta_key{0} )
continue;
/*
* At this point, every value is an array; one element per instance of the key.
* We'll test anyway, just to be sure, then convert single-instance values to a scalar.
* Metadata array values are serialized for storage in the database, so we might have to
* unserialize them before processing them as an array.
*/
if ( is_array( $post_meta_value ) ) {
if ( count( $post_meta_value ) == 1 )
$post_meta_value = maybe_unserialize( $post_meta_value[0] );
else
foreach ( $post_meta_value as $single_key => $single_value )
$post_meta_value[ $single_key ] = maybe_unserialize( $single_value );
}
$custom_fields[ $post_meta_key ] = $post_meta_value;
} // foreach $post_meta
}
//error_log( 'MLAGalleryHooksExample::mla_gallery_item_values_filter $custom_fields = ' . var_export( $custom_fields, true ), 0 );
/*
* Don't alter the caption if there are no custom fields to display
*/
if ( empty( $custom_fields ) )
return $item_values;
/*
* Add the definition list to the caption
*/
$my_caption .= "