1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* FooGallery Shortcodes |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
if ( ! class_exists( 'FooGallery_Shortcodes' ) ) { |
7
|
|
|
|
8
|
|
|
class FooGallery_Shortcodes { |
9
|
|
|
|
10
|
|
|
function __construct() { |
|
|
|
|
11
|
|
|
add_action( 'foogallery_load_template', array( $this, 'handle_lightbox_field' ) ); |
12
|
|
|
add_action( 'foogallery_loaded_template', array( $this, 'render_custom_css' ) ); |
13
|
|
|
|
14
|
|
|
add_shortcode( foogallery_gallery_shortcode_tag(), array( $this, 'render_foogallery_shortcode' ) ); |
15
|
|
|
|
16
|
|
|
add_shortcode( 'foogallery-enqueue', array( $this, 'render_foogallery_enqueue' ) ); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
function render_foogallery_shortcode( $atts ) { |
20
|
|
|
|
21
|
|
|
$args = wp_parse_args( $atts, array( |
22
|
|
|
'id' => 0, |
23
|
|
|
'gallery' => '', |
24
|
|
|
) ); |
25
|
|
|
|
26
|
|
|
$args = apply_filters( 'foogallery_shortcode_atts', $args ); |
27
|
|
|
|
28
|
|
|
//create new instance of template engine |
29
|
|
|
$engine = new FooGallery_Template_Loader(); |
30
|
|
|
|
31
|
|
|
ob_start(); |
32
|
|
|
|
33
|
|
|
$engine->render_template( $args ); |
34
|
|
|
|
35
|
|
|
$output_string = ob_get_contents(); |
36
|
|
|
ob_end_clean(); |
37
|
|
|
return $output_string; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function render_foogallery_enqueue() { |
|
|
|
|
41
|
|
|
foogallery_enqueue_core_gallery_template_script(); |
42
|
|
|
foogallery_enqueue_core_gallery_template_style(); |
43
|
|
|
wp_enqueue_script( 'masonry' ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Handle a gallery that has a lightbox. This allows us to include any scripts or CSS that is needed for the lightbox |
48
|
|
|
* |
49
|
|
|
* @param $gallery FooGallery |
50
|
|
|
*/ |
51
|
|
|
function handle_lightbox_field( $gallery ) { |
52
|
|
|
if ( $gallery->gallery_template_has_field_of_type( 'lightbox' ) ) { |
53
|
|
|
$lightbox = foogallery_gallery_template_setting( 'lightbox' ); |
54
|
|
|
|
55
|
|
|
if ( false != $lightbox ) { |
56
|
|
|
do_action( "foogallery_template_lightbox-{$lightbox}", $gallery ); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
function render_custom_css( $foogallery ) { |
62
|
|
|
if ( !empty( $foogallery->custom_css ) ) { |
63
|
|
|
echo '<style type="text/css">'; |
64
|
|
|
echo $foogallery->custom_css; |
65
|
|
|
echo '</style>'; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.