-
Notifications
You must be signed in to change notification settings - Fork 5
/
simple-google-photos-grid-shortcode.php
36 lines (26 loc) · 1.13 KB
/
simple-google-photos-grid-shortcode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
include_once 'Simple_Google_Photos_Grid.php';
/**
* Widget to display Google Photos from a public album.
*/
class Simple_Google_Photos_Grid_Shortcode
{
public static function shortcode($attributes = [], $content = null, $tag = '') {
$attributes = array_change_key_case((array)$attributes, CASE_LOWER);
if(!isset($attributes['album-url']) || substr($attributes['album-url'], 0, 8) != 'https://') {
return '';
}
$cache_interval = isset($attributes['cache-interval'])
? intval($attributes['cache-interval'])
: Simple_Google_Photos_Grid::CACHE_INTERVAL;
$num_photos = isset($attributes['number-photos'])
? intval($attributes['number-photos'])
: Simple_Google_Photos_Grid::NUMBER_PHOTOS;
$num_photos_per_row = isset($attributes['number-photos-per-row'])
? intval($attributes['number-photos-per-row'])
: Simple_Google_Photos_Grid::NUMBER_PHOTOS_PER_ROW;
$grid = new Simple_Google_Photos_Grid();
$photos = $grid->get_photos($attributes['album-url'], $cache_interval);
return $grid->html($photos, $num_photos, $num_photos_per_row, $attributes['album-url']);
}
}