Skip to content

Commit

Permalink
New filters for adding a classes to each image, list item or image. C…
Browse files Browse the repository at this point in the history
…loses scottsweb#10.
  • Loading branch information
scottsweb committed May 7, 2015
1 parent 181680f commit 9140ea6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
17 changes: 15 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Visit [WordPress.org for a comprehensive guide](http://codex.wordpress.org/Manag

## Hooks & Filters

The plugin has two filters. The first allows you adjust that cache time for retrieving the images from Instagram:
The plugin has five filters. The first allows you adjust that cache time for retrieving the images from Instagram:

```
add_filter('null_instagram_cache_time', 'my_cache_time');
Expand All @@ -49,6 +49,19 @@ The second allows you to filter video results from the widget:
add_filter('wpiw_images_only', '__return_true');
```

The rest allow you to add custom classes to each list item, link or image:

```
add_filter( 'wpiw_item_class', 'my_instagram_class' );
add_filter( 'wpiw_a_class', 'my_instagram_class' );
add_filter( 'wpiw_img_class', 'my_instagram_class' );
function my_instagram_class( $classes ) {
$classes = "instagram-image";
return $classes;
}
```

In version 1.3 you also have two new hooks for adding custom output before and after the widget:

```
Expand All @@ -64,7 +77,7 @@ wpiw_after_widget

####1.4 (in progress)
* Remove null framework support
* Introduce class filter `wpiw_item_class`
* Introduce class filters

####1.3.1
* Force lowercase usernames
Expand Down
16 changes: 14 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ To use within the [null theme framework](https://github.com/scottsweb/null) or [

= Hooks & Filters =

The plugin has two filters. The first allows you adjust that cache time for retrieving the images from Instagram:
The plugin has five filters. The first allows you adjust that cache time for retrieving the images from Instagram:

`add_filter('null_instagram_cache_time', 'my_cache_time');

Expand All @@ -52,6 +52,18 @@ The second allows you to filter video results from the widget:

`add_filter('wpiw_images_only', '__return_true');`

The rest allow you to add custom classes to each list item, link or image:

`add_filter( 'wpiw_item_class', 'my_instagram_class' );
add_filter( 'wpiw_a_class', 'my_instagram_class' );
add_filter( 'wpiw_img_class', 'my_instagram_class' );

function my_instagram_class( $classes ) {
$classes = "instagram-image";
return $classes;
}
`

In version 1.3 you also have two new hooks for adding custom output before and after the widget:

`wpiw_before_widget`
Expand All @@ -66,7 +78,7 @@ In version 1.3 you also have two new hooks for adding custom output before and a

= 1.4 (in progress) =
* Remove null framework support
* Introduce class filter `wpiw_item_class`
* Introduce class filters

= 1.3.1 =
* Force lowercase usernames
Expand Down
7 changes: 6 additions & 1 deletion wp-instagram-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ function widget($args, $instance) {
if ( $images_only = apply_filters( 'wpiw_images_only', FALSE ) )
$media_array = array_filter( $media_array, array( $this, 'images_only' ) );

// filters for custom classes
$liclass = esc_attr( apply_filters( 'wpiw_item_class', '' ) );
$aclass = esc_attr( apply_filters( 'wpiw_a_class', '' ) );
$imgclass = esc_attr( apply_filters( 'wpiw_img_class', '' ) );

?><ul class="instagram-pics instagram-size-<?php echo esc_attr( $instance['size'] ); ?>"><?php
foreach ($media_array as $item) {
echo '<li><a href="'. esc_url( $item['link'] ) .'" target="'. esc_attr( $target ) .'"><img src="'. esc_url($item[$size]['url']) .'" alt="'. esc_attr( $item['description'] ) .'" title="'. esc_attr( $item['description'] ).'"/></a></li>';
echo '<li class="'. $liclass .'"><a href="'. esc_url( $item['link'] ) .'" target="'. esc_attr( $target ) .'" class="'. $aclass .'"><img src="'. esc_url($item[$size]['url']) .'" alt="'. esc_attr( $item['description'] ) .'" title="'. esc_attr( $item['description'] ).'" class="'. $imgclass .'"/></a></li>';
}
?></ul><?php
}
Expand Down

0 comments on commit 9140ea6

Please sign in to comment.