1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* FooGallery Pro Gallery Shortcode Override Class |
4
|
|
|
*/ |
5
|
|
|
if ( ! class_exists( 'FooGallery_Pro_Gallery_Shortcode_Override' ) ) { |
6
|
|
|
|
7
|
|
|
class FooGallery_Pro_Gallery_Shortcode_Override { |
|
|
|
|
8
|
|
|
|
9
|
|
|
function __construct() { |
|
|
|
|
10
|
|
|
add_filter( 'foogallery_admin_settings_override', array( $this, 'gallery_shortcode_override_settings' ) ); |
11
|
|
|
add_filter( 'post_gallery', array( $this, 'override_gallery_output' ), 10, 3 ); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Create the override |
16
|
|
|
* @return array |
17
|
|
|
*/ |
18
|
|
|
function gallery_shortcode_override_settings($settings) { |
|
|
|
|
19
|
|
|
$settings['settings'][] = array( |
20
|
|
|
'id' => 'override_gallery_shortcode', |
21
|
|
|
'title' => __('Override Gallery Shortcode', 'foogallery'), |
22
|
|
|
'desc' => sprintf(__('This will allow you to override all default gallery shortcodes to rather use a %s template. The defaults above will be used when displaying the gallery.', 'foogallery'), foogallery_plugin_name()), |
23
|
|
|
'type' => 'checkbox', |
24
|
|
|
'tab' => 'general', |
25
|
|
|
'section' => __('Shortcodes', 'foogallery') |
26
|
|
|
); |
27
|
|
|
|
28
|
|
|
return $settings; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/* |
32
|
|
|
* Override the gallery shortcode output if enabled |
33
|
|
|
* @param $output |
34
|
|
|
* @param $attr |
35
|
|
|
* @param $instance |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
function override_gallery_output( $output, $attr, $instance) { |
|
|
|
|
39
|
|
|
$override_enabled = foogallery_get_setting( 'override_gallery_shortcode'); |
40
|
|
|
|
41
|
|
|
if ($override_enabled === 'on') { |
42
|
|
|
$attr['attachment_ids'] = $attr['ids']; |
43
|
|
|
|
44
|
|
|
//create new instance of template engine |
45
|
|
|
$engine = new FooGallery_Template_Loader(); |
46
|
|
|
|
47
|
|
|
ob_start(); |
48
|
|
|
|
49
|
|
|
$engine->render_template( $attr ); |
50
|
|
|
|
51
|
|
|
$output_string = ob_get_contents(); |
52
|
|
|
ob_end_clean(); |
53
|
|
|
return $output_string; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return ''; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.