GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 3bd383...ce1d31 )
by Brad
02:29
created

functions.php ➔ foogallery_album_uninstall()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 5
nop 0
dl 0
loc 18
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Builds up a FooGallery album shortcode
5
 *
6
 * @param $album_id
7
 *
8
 * @return string
9
 */
10
function foogallery_build_album_shortcode( $album_id ) {
11
	return '[' . foogallery_album_shortcode_tag() . ' id="' . $album_id . '"]';
12
}
13
14
/**
15
 * Returns the album shortcode tag
16
 *
17
 * @return string
18
 */
19
function foogallery_album_shortcode_tag() {
20
	return apply_filters( 'foogallery_album_shortcode_tag', FOOGALLERY_CPT_ALBUM );
21
}
22
23
/**
24
 * Return all the album templates used within FooGallery
25
 *
26
 * @return array
27
 */
28
function foogallery_album_templates() {
29
	$album_templates[] = array(
30
		'slug'        => 'default',
31
		'name'        => __( 'Responsive Album Layout', 'foogallery' ),
32
		'fields'	  => array(
33
			array(
34
				'id'      => 'thumbnail_dimensions',
35
				'title'   => __( 'Thumbnail Size', 'foogallery' ),
36
				'desc'    => __( 'Choose the size of your gallery thumbnails.', 'foogallery' ),
37
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
38
				'type'    => 'thumb_size',
39
				'default' => array(
40
					'width' => get_option( 'thumbnail_size_w' ),
41
					'height' => get_option( 'thumbnail_size_h' ),
42
					'crop' => true,
43
				),
44
			),
45
			array(
46
				'id'      => 'title_bg',
47
				'title'   => __( 'Title Background Color', 'foogallery' ),
48
				'desc'    => __( 'The color of the title that overlays the album thumbnails', 'foogallery' ),
49
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
50
				'type'    => 'colorpicker',
51
				'default' => '#fff'
52
			),
53
			array(
54
				'id'      => 'title_font_color',
55
				'title'   => __( 'Title Text Color', 'foogallery' ),
56
				'desc'    => __( 'The color of the title text that overlays the album thumbnails', 'foogallery' ),
57
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
58
				'type'    => 'colorpicker',
59
				'default' => '#000000'
60
			),
61
			array(
62
				'id'      => 'alignment',
63
				'title'   => __( 'Alignment', 'foogallery' ),
64
				'desc'    => __( 'The horizontal alignment of the gallery thumbnails inside the album.', 'foogallery' ),
65
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
66
				'default' => 'alignment-left',
67
				'type'    => 'select',
68
				'choices' => array(
69
					'alignment-left' => __( 'Left', 'foogallery' ),
70
					'alignment-center' => __( 'Center', 'foogallery' ),
71
					'alignment-right' => __( 'Right', 'foogallery' ),
72
				)
73
			),
74
			array(
75
				'id'      => 'gallery_link',
76
				'title'   => __( 'Gallery Link', 'foogallery' ),
77
				'section' => __( 'URL Settings', 'foogallery' ),
78
				'default' => '',
79
				'type'    => 'radio',
80
				'spacer'  => '<span class="spacer"></span>',
81
				'choices' =>  array(
82
						'' =>  __('Default', 'foogallery'),
83
						'custom_url' => __('Custom URL', 'foogallery')
84
				),
85
				'desc'	  => __( 'You can choose to link each gallery to the default embedded gallery, or you can choose to link to the gallery custom URL (if set).', 'foogallery' ),
86
			),
87
			array(
88
				'id'      => 'gallery_link_format',
89
				'title'   => __( 'Gallery Link Format', 'foogallery' ),
90
				'desc'    => __( 'The format of the URL for each individual gallery in the album.', 'foogallery' ),
91
				'section' => __( 'URL Settings', 'foogallery' ),
92
				'type'    => 'radio',
93
				'choices' =>  array(
94
					'default' =>  __('Pretty, e.g. ', 'foogallery') . '<code>/page-with-album/' . foogallery_album_gallery_url_slug() . '/some-gallery</code>',
95
					'querystring' => __('Querystring e.g. ', 'foogallery') . '<code>/page-with-album?' . foogallery_album_gallery_url_slug() . '=some-gallery</code>'
96
				),
97
				'default' => foogallery_determine_best_link_format_default()
98
			),
99
			array(
100
				'id'	  => 'url_help',
101
				'title'	  => __( 'Please Note', 'foogallery' ),
102
				'section' => __( 'URL Settings', 'foogallery' ),
103
				'type'	  => 'help',
104
				'help'	  => true,
105
				'desc'	  => __( 'If you are getting 404\'s when clicking on the album galleries, then change to the querystring format. To force your rewrite rules to flush, simply deactivate and activate the albums extension again.', 'foogallery' ),
106
			),
107
			array(
108
				'id'      => 'album_hash',
109
				'title'   => __( 'Remember Scroll Position', 'foogallery' ),
110
				'desc'    => __( 'When a gallery is loaded in your album, the page is refreshed which means the scroll position will be lost .', 'foogallery' ),
111
				'section' => __( 'URL Settings', 'foogallery' ),
112
				'type'    => 'radio',
113
				'choices' =>  array(
114
					'none' =>  __('Don\'t Remember', 'foogallery'),
115
					'remember' => __('Remember Scroll Position', 'foogallery')
116
				),
117
				'default' => 'none'
118
			)
119
		)
120
	);
121
122
	$album_templates[] = array(
123
		'slug'        => 'stack',
124
		'name'        => __( 'All-In-One Stack Album', 'foogallery' ),
125
		'fields'	  => array(
126
			array(
127
				'id'      => 'lightbox',
128
				'title'   => __( 'Lightbox', 'foogallery' ),
129
				'desc'    => __( 'Choose which lightbox you want to use to display images.', 'foogallery' ),
130
				'type'    => 'lightbox',
131
			),
132
133
			array(
134
				'id'      => 'thumbnail_dimensions',
135
				'title'   => __( 'Thumbnail Size', 'foogallery' ),
136
				'desc'    => __( 'Choose the size of your image stack thumbnails.', 'foogallery' ),
137
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
138
				'type'    => 'thumb_size',
139
				'default' => array(
140
					'width' => get_option( 'thumbnail_size_w' ),
141
					'height' => get_option( 'thumbnail_size_h' ),
142
					'crop' => true,
143
				),
144
			),
145
146
			array(
147
				'id'      => 'random_angle',
148
				'title'   => __( 'Thumbnail Rotation', 'foogallery' ),
149
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
150
				'desc'    => __( 'Choose how thumbnails in each gallery are shown when clicking an image stack.', 'foogallery' ),
151
				'type'    => 'radio',
152
				'default' => 'false',
153
				'choices' =>  array(
154
					'false' => __( 'Normal', 'foogallery' ),
155
					'true' => __( 'Random Angles', 'foogallery' )
156
				)
157
			),
158
159
			array(
160
				'id'      => 'gutter',
161
				'title'   => __( 'Thumbnail Gutter', 'foogallery' ),
162
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
163
				'desc'    => __( 'The spacing between each image stack.', 'foogallery' ),
164
				'type'    => 'number',
165
				'default' => 50
166
			),
167
168
			array(
169
				'id'      => 'delay',
170
				'title'   => __( 'Expand Delay', 'foogallery' ),
171
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
172
				'desc'    => __( 'The delay between expanding each image on a image stack.', 'foogallery' ),
173
				'type'    => 'number',
174
				'default' => 0
175
			),
176
177
			array(
178
				'id'      => 'pile_angles',
179
				'title'   => __( 'Image Stack Angles', 'foogallery' ),
180
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
181
				'desc'    => __( 'The angle of the images behind the thumbnail in each image stack.', 'foogallery' ),
182
				'type'    => 'radio',
183
				'default' => '1',
184
				'choices' =>  array(
185
					'1' => __( 'Low', 'foogallery' ),
186
					'2' => __( 'Normal', 'foogallery' ),
187
					'3' => __( 'More Than Normal', 'foogallery' ),
188
					'5' => __( 'High', 'foogallery' ),
189
				)
190
			)
191
		)
192
	);
193
194
	return apply_filters( 'foogallery_album_templates', $album_templates );
195
}
196
197
function foogallery_determine_best_link_format_default() {
198
	global $wp_rewrite;
199
	if ( '' === $wp_rewrite->permalink_structure ) {
200
		//we are using ?page_id
201
		return 'querystring';
202
	}
203
204
	//we are using permalinks
205
	return 'default';
206
}
207
208
/**
209
 * Returns the default album template
210
 *
211
 * @return string
212
 */
213
function foogallery_default_album_template() {
214
	return foogallery_get_setting( 'album_template' );
215
}
216
217
/**
218
 * Returns the gallery link url for an album
219
 *
220
 * @param $album FooGalleryAlbum
221
 * @param $gallery FooGallery
222
 *
223
 * @return string
224
 */
225
function foogallery_album_build_gallery_link( $album, $gallery ) {
226
	//first check if we want to use custom URL's
227
	$gallery_link = $album->get_meta( 'default_gallery_link', '' );
228
229
	if ( 'custom_url' === $gallery_link ) {
230
		//check if the gallery has a custom url, and if so, then use it
231
		$url = get_post_meta( $gallery->ID, 'custom_url', true );
232
	}
233
234
	if ( empty( $url ) ) {
235
		$slug   = foogallery_album_gallery_url_slug();
236
		$format = $album->get_meta( 'default_gallery_link_format', 'default' );
237
238
		if ( 'default' === $format && 'default' === foogallery_determine_best_link_format_default() ) {
239
			$url = untrailingslashit( trailingslashit( get_permalink() ) . $slug . '/' . $gallery->slug );
240
		} else {
241
			$url = add_query_arg( $slug, $gallery->slug );
242
		}
243
244
		$use_hash = $album->get_meta( 'default_album_hash', 'remember' );
245
246
		if ( 'remember' === $use_hash ) {
247
			//add the album hash if required
248
			$url .= '#' . $album->slug;
249
		}
250
	}
251
252
	return apply_filters( 'foogallery_album_build_gallery_link', $url );
253
}
254
255
/**
256
 * Returns the gallery slug used when generating gallery URL's
257
 *
258
 * @return string
259
 */
260
function foogallery_album_gallery_url_slug() {
261
	$slug = foogallery_get_setting( 'album_gallery_slug', 'gallery' );
0 ignored issues
show
Documentation introduced by
'gallery' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
262
	return apply_filters( 'foogallery_album_gallery_url_slug', $slug );
263
}
264
265
/**
266
 * Returns the gallery link target for an album
267
 *
268
 * @param $album FooGalleryAlbum
269
 * @param $gallery FooGallery
270
 *
271
 * @return string
272
 */
273
function foogallery_album_build_gallery_link_target( $album, $gallery ) {
274
	//first check if we want to use custom URL's
275
	$gallery_link = $album->get_meta( 'default_gallery_link', '' );
276
277
	if ( 'custom_url' === $gallery_link ) {
278
		//check if the gallery has a custom target, and if so, then use it
279
		$target = get_post_meta( $gallery->ID, 'custom_target', true );
280
	}
281
282
	if ( empty( $target ) ) {
283
		$target = '_self';
284
	}
285
286
	return apply_filters( 'foogallery_album_build_gallery_link_target', $target );
287
}
288
289
function foogallery_album_get_current_gallery() {
290
	$slug = foogallery_album_gallery_url_slug();
291
292
	$gallery = get_query_var( $slug );
293
294
	if ( empty( $gallery ) ) {
295
		$gallery = safe_get_from_request( $slug );
296
	}
297
298
	return apply_filters( 'foogallery_album_get_current_gallery', $gallery );
299
}
300
301
function foogallery_album_remove_gallery_from_link() {
302
	$gallery = foogallery_album_get_current_gallery();
303
	$slug = foogallery_album_gallery_url_slug();
304
305
	$url = untrailingslashit( remove_query_arg( $slug ) );
306
307
	return str_replace( $slug . '/' . $gallery, '', $url);
308
}
309
310
/**
311
 * Get a foogallery album template setting for the current foogallery that is being output to the frontend
312
 * @param string	$key
313
 * @param string	$default
314
 *
315
 * @return bool
316
 */
317
function foogallery_album_template_setting( $key, $default = '' ) {
318
	global $current_foogallery_album;
319
	global $current_foogallery_album_arguments;
320
	global $current_foogallery_album_template;
321
322
	$settings_key = "{$current_foogallery_album_template}_{$key}";
323
324
	if ( $current_foogallery_album_arguments && array_key_exists( $key, $current_foogallery_album_arguments ) ) {
325
		//try to get the value from the arguments
326
		$value = $current_foogallery_album_arguments[ $key ];
327
328
	} else if ( $current_foogallery_album->settings && array_key_exists( $settings_key, $current_foogallery_album->settings ) ) {
329
		//then get the value out of the saved gallery settings
330
		$value = $current_foogallery_album->settings[ $settings_key ];
331
	} else {
332
		//otherwise set it to the default
333
		$value = $default;
334
	}
335
336
	$value = apply_filters( 'foogallery_album_template_setting-' . $key, $value );
337
338
	return $value;
339
}
340
341
/**
342
 * uninstall all albums and setting for albums
343
 */
344
function foogallery_album_uninstall() {
345
	if ( !current_user_can( 'install_plugins' ) ) exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The function foogallery_album_uninstall() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
346
347
	//delete all albums posts
348
	global $wpdb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
349
	$query = "SELECT p.ID FROM {$wpdb->posts} AS p WHERE p.post_type IN (%s)";
350
	$gallery_post_ids = $wpdb->get_col( $wpdb->prepare( $query, FOOGALLERY_CPT_ALBUM ) );
351
352
	if ( !empty( $gallery_post_ids ) ) {
353
		$deleted = 0;
354
		foreach ( $gallery_post_ids as $post_id ) {
355
			$del = wp_delete_post( $post_id );
356
			if ( false !== $del ) {
357
				++$deleted;
358
			}
359
		}
360
	}
361
}