1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if ( !class_exists( 'FooGallery_Thumbnail_Gallery_Template' ) ) { |
4
|
|
|
|
5
|
|
|
define('FOOGALLERY_THUMBNAIL_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ )); |
6
|
|
|
|
7
|
|
|
class FooGallery_Thumbnail_Gallery_Template { |
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Wire up everything we need to run the extension |
10
|
|
|
*/ |
11
|
|
|
function __construct() { |
|
|
|
|
12
|
|
|
add_filter( 'foogallery_gallery_templates', array( $this, 'add_template' ) ); |
13
|
|
|
add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) ); |
14
|
|
|
|
15
|
|
|
add_filter( 'foogallery_located_template-thumbnail', array( $this, 'enqueue_dependencies' ) ); |
16
|
|
|
|
17
|
|
|
//add extra fields to the templates |
18
|
|
|
add_filter( 'foogallery_override_gallery_template_fields-thumbnail', array( $this, 'add_common_thumbnail_fields' ), 10, 2 ); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Register myself so that all associated JS and CSS files can be found and automatically included |
23
|
|
|
* @param $extensions |
24
|
|
|
* |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
|
|
function register_myself( $extensions ) { |
|
|
|
|
28
|
|
|
$extensions[] = __FILE__; |
29
|
|
|
return $extensions; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Add our gallery template to the list of templates available for every gallery |
34
|
|
|
* @param $gallery_templates |
35
|
|
|
* |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
function add_template( $gallery_templates ) { |
|
|
|
|
39
|
|
|
$gallery_templates[] = array( |
40
|
|
|
'slug' => 'thumbnail', |
41
|
|
|
'name' => __( 'Single Thumbnail Gallery', 'foogallery' ), |
42
|
|
|
'lazyload_support' => true, |
43
|
|
|
'preview_css' => FOOGALLERY_THUMBNAIL_GALLERY_TEMPLATE_URL . 'css/gallery-thumbnail.css', |
44
|
|
|
'admin_js' => FOOGALLERY_THUMBNAIL_GALLERY_TEMPLATE_URL . 'js/admin-gallery-thumbnail.js', |
45
|
|
|
'fields' => array( |
46
|
|
|
array( |
47
|
|
|
'id' => 'help', |
48
|
|
|
'type' => 'html', |
49
|
|
|
'help' => true, |
50
|
|
|
'desc' => __( 'This gallery template only shows a single thumbnail, but the true power shines through when the thumbnail is clicked, because then the lightbox takes over and the user can view all the images in the gallery.', 'foogallery' ), |
51
|
|
|
), |
52
|
|
|
array( |
53
|
|
|
'id' => 'thumbnail_dimensions', |
54
|
|
|
'title' => __( 'Size', 'foogallery' ), |
55
|
|
|
'desc' => __( 'Choose the size of your thumbnail.', 'foogallery' ), |
56
|
|
|
'section' => __( 'Thumbnail Settings', 'foogallery' ), |
57
|
|
|
'type' => 'thumb_size', |
58
|
|
|
'default' => array( |
59
|
|
|
'width' => 250, |
60
|
|
|
'height' => 200, |
61
|
|
|
'crop' => true, |
62
|
|
|
), |
63
|
|
|
), |
64
|
|
|
array( |
65
|
|
|
'id' => 'position', |
66
|
|
|
'title' => __( 'Position', 'foogallery' ), |
67
|
|
|
'desc' => __( 'The position of the thumbnail related to the content around it.', 'foogallery' ), |
68
|
|
|
'section' => __( 'Thumbnail Settings', 'foogallery' ), |
69
|
|
|
'default' => 'position-block', |
70
|
|
|
'type' => 'select', |
71
|
|
|
'choices' => array( |
72
|
|
|
'position-block' => __( 'Full Width (block)', 'foogallery' ), |
73
|
|
|
'position-float-left' => __( 'Float Left', 'foogallery' ), |
74
|
|
|
'position-float-right' => __( 'Float Right', 'foogallery' ), |
75
|
|
|
) |
76
|
|
|
), |
77
|
|
|
array( |
78
|
|
|
'id' => 'link_custom_url', |
79
|
|
|
'title' => __( 'Link To Custom URL', 'foogallery' ), |
80
|
|
|
'section' => __( 'Thumbnail Settings', 'foogallery' ), |
81
|
|
|
'default' => '', |
82
|
|
|
'type' => 'checkbox', |
83
|
|
|
'desc' => __( 'You can link your thumbnails to Custom URL\'s (if they are set on your attachments). Fallback will be to the full size image.', 'foogallery' ) |
84
|
|
|
), |
85
|
|
|
array( |
86
|
|
|
'id' => 'caption_style', |
87
|
|
|
'title' => __( 'Caption Style', 'foogallery' ), |
88
|
|
|
'section' => __( 'Caption Settings', 'foogallery' ), |
89
|
|
|
'desc' => __( 'Choose which caption style you want to use.', 'foogallery' ), |
90
|
|
|
'type' => 'select', |
91
|
|
|
'default' => 'simple', |
92
|
|
|
'choices' => array( |
93
|
|
|
'caption-simple' => __( 'Simple' , 'foogallery' ), |
94
|
|
|
'caption-slideup' => __( 'Slide Up' , 'foogallery' ), |
95
|
|
|
'caption-fall' => __( 'Fall Down' , 'foogallery' ), |
96
|
|
|
'caption-fade' => __( 'Fade' , 'foogallery' ), |
97
|
|
|
'caption-push' => __( 'Push From Left' , 'foogallery' ), |
98
|
|
|
'caption-scale' => __( 'Scale' , 'foogallery' ), |
99
|
|
|
'caption-none' => __( 'None' , 'foogallery' ) |
100
|
|
|
), |
101
|
|
|
), |
102
|
|
|
array( |
103
|
|
|
'id' => 'caption_bgcolor', |
104
|
|
|
'title' => __('Caption Background Color', 'foogallery'), |
105
|
|
|
'section' => __( 'Caption Settings', 'foogallery' ), |
106
|
|
|
'desc' => __('The color of the caption background.', 'foogallery'), |
107
|
|
|
'type' => 'colorpicker', |
108
|
|
|
'default' => 'rgba(0, 0, 0, 0.8)', |
109
|
|
|
'opacity' => true |
110
|
|
|
), |
111
|
|
|
array( |
112
|
|
|
'id' => 'caption_color', |
113
|
|
|
'title' => __('Caption Text Color', 'foogallery'), |
114
|
|
|
'section' => __( 'Caption Settings', 'foogallery' ), |
115
|
|
|
'desc' => __('The color of the caption text.', 'foogallery'), |
116
|
|
|
'type' => 'colorpicker', |
117
|
|
|
'default' => 'rgb(255, 255, 255)' |
118
|
|
|
), |
119
|
|
|
array( |
120
|
|
|
'id' => 'caption_title', |
121
|
|
|
'title' => __('Caption Title', 'foogallery'), |
122
|
|
|
'section' => __( 'Caption Settings', 'foogallery' ), |
123
|
|
|
'desc' => __('Leave blank if you do not want a caption title.', 'foogallery'), |
124
|
|
|
'type' => 'text' |
125
|
|
|
), |
126
|
|
|
array( |
127
|
|
|
'id' => 'caption_description', |
128
|
|
|
'title' => __('Caption Description', 'foogallery'), |
129
|
|
|
'section' => __( 'Caption Settings', 'foogallery' ), |
130
|
|
|
'desc' => __('Leave blank if you do not want a caption description.', 'foogallery'), |
131
|
|
|
'type' => 'textarea' |
132
|
|
|
), |
133
|
|
|
array( |
134
|
|
|
'id' => 'lightbox', |
135
|
|
|
'title' => __( 'Lightbox', 'foogallery' ), |
136
|
|
|
'section' => __( 'Gallery Settings', 'foogallery' ), |
137
|
|
|
'desc' => __( 'Choose which lightbox you want to use.', 'foogallery' ), |
138
|
|
|
'type' => 'lightbox', |
139
|
|
|
) |
140
|
|
|
) |
141
|
|
|
); |
142
|
|
|
|
143
|
|
|
return $gallery_templates; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Enqueue scripts that the masonry gallery template relies on |
148
|
|
|
*/ |
149
|
|
|
function enqueue_dependencies() { |
|
|
|
|
150
|
|
|
wp_enqueue_script( 'jquery' ); |
151
|
|
|
|
152
|
|
|
//enqueue core files |
153
|
|
|
foogallery_enqueue_core_gallery_template_style(); |
154
|
|
|
foogallery_enqueue_core_gallery_template_script(); |
155
|
|
|
|
156
|
|
|
$css = FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_URL . 'thumbnail/css/foogallery.single-thumbnail.min.css'; |
157
|
|
|
wp_enqueue_style( 'foogallery-thumbnail', $css, array(), FOOGALLERY_VERSION ); |
158
|
|
|
|
159
|
|
|
$js = FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_URL . 'thumbnail/js/foogallery.single-thumbnail.min.js'; |
160
|
|
|
wp_enqueue_script( 'foogallery-thumbnail', $js, array(), FOOGALLERY_VERSION ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Add thumbnail fields to the gallery template |
165
|
|
|
* |
166
|
|
|
* @uses "foogallery_override_gallery_template_fields" |
167
|
|
|
* @param $fields |
168
|
|
|
* @param $template |
169
|
|
|
* |
170
|
|
|
* @return array |
171
|
|
|
*/ |
172
|
|
|
function add_common_thumbnail_fields( $fields, $template ) { |
|
|
|
|
173
|
|
|
$fields = array_merge( $fields, foogallery_get_gallery_template_common_thumbnail_fields($template) ); |
174
|
|
|
|
175
|
|
|
return $fields; |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
} |
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.