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.

alter_class_attributes()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 3
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
/**
3
 * Class used to add custom classes to gallery links
4
 * Date: 04/06/2017
5
 */
6
if ( ! class_exists( 'FooGallery_Attachment_Custom_Class' ) ) {
7
8
	class FooGallery_Attachment_Custom_Class {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
10
		function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
11
			add_filter( 'foogallery_attachment_custom_fields', array( $this, 'add_custom_class_field' ) );
12
			add_filter( 'foogallery_attachment_html_link_attributes', array( $this, 'alter_class_attributes' ), 99, 3 );
13
		}
14
15
		/**
16
		 * Adds a custom class field to the attachments
17
		 *
18
		 * @param $fields array
19
		 *
20
		 * @return array
21
		 */
22
		function add_custom_class_field( $fields ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
23
			$fields['foogallery_custom_class'] = array(
24
				'label'       =>  __( 'Custom Class', 'foogallery' ),
25
				'input'       => 'text',
26
				'helps'       => __( 'Add extra classes to the attachment', 'foogallery' ),
27
				'exclusions'  => array( 'audio', 'video' ),
28
			);
29
30
			return $fields;
31
		}
32
33
		/**
34
		 * Alters the actual link output to include the custom class added
35
		 *
36
		 * @uses "foogallery_attachment_html_link_attributes" filter
37
		 *
38
		 * @param                             $attr
39
		 * @param                             $args
40
		 * @param object|FooGalleryAttachment $object
41
		 *
42
		 * @return array
43
		 */
44
		function alter_class_attributes( $attr, $args, $object ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
45
			$custom_class = get_post_meta( $object->ID, '_foogallery_custom_class', true );
46
47
			if ( ! isset( $attr[ 'class' ] ) ) {
48
				$attr[ 'class' ] = $custom_class;
49
			}else{
50
				$attr[ 'class' ] .= ' ' . $custom_class;
51
			}
52
53
			//check for any special class names and do some magic!
54
			if ( 'nolink' === $custom_class ) {
55
				unset( $attr['href'] );
56
			}
57
58
			return $attr;
59
		}
60
	}
61
}