Completed
Push — develop ( 32f12c...df82b0 )
by Zack
53:29 queued 33:28
created

GravityView_Lightbox_Provider::get_settings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Registers a lightbox provider.
5
 *
6
 * @internal Currently internal; not ready for public usage.
7
 */
8
abstract class GravityView_Lightbox_Provider {
9
10
	public static $slug;
11
12
	public static $script_slug;
13
14
	public static $style_slug;
15
16
	/**
17
	 * Adds actions and that modify GravityView to use this lightbox provider
18
	 */
19
	public function add_hooks() {
20
		add_filter( 'gravityview_lightbox_script', array( $this, 'filter_lightbox_script' ), 1000 );
21
		add_filter( 'gravityview_lightbox_style', array( $this, 'filter_lightbox_style' ), 1000 );
22
23
		add_filter( 'gravityview/fields/fileupload/link_atts', array( $this, 'fileupload_link_atts' ), 10, 3 );
24
		add_filter( 'gravityview/get_link/allowed_atts', array( $this, 'allowed_atts' ) );
25
26
		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts') );
27
		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles') );
28
29
		add_action( 'wp_footer', array( $this, 'output_footer' ) );
30
	}
31
32
	/**
33
	 * Removes actions that were added by {@see GravityView_Lightbox_Provider::add_hooks}
34
	 * @internal Do not call directly. Instead, use:
35
	 *
36
	 * <code>
37
	 * do_action( 'gravityview/lightbox/provider', 'slug' );
38
	 * </code>
39
	 */
40
	public function remove_hooks() {
41
		remove_filter( 'gravityview_lightbox_script', array( $this, 'filter_lightbox_script' ), 1000 );
42
		remove_filter( 'gravityview_lightbox_style', array( $this, 'filter_lightbox_style' ), 1000 );
43
44
		remove_filter( 'gravityview/fields/fileupload/link_atts', array( $this, 'fileupload_link_atts' ), 10 );
45
		remove_filter( 'gravityview/get_link/allowed_atts', array( $this, 'allowed_atts' ) );
46
47
		remove_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts') );
48
		remove_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles') );
49
50
		remove_action( 'wp_footer', array( $this, 'output_footer' ) );
51
	}
52
53
	/**
54
	 * Modifies the name of the stylesheet to be enqueued when loading thickbox
55
	 *
56
	 * @param string $script
57
	 *
58
	 * @return string
59
	 */
60
	public function filter_lightbox_script( $script = 'thickbox' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $script is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
		return static::$script_slug;
62
	}
63
64
	/**
65
	 * Modifies the name of the stylesheet to be enqueued when loading thickbox
66
	 *
67
	 * @param string $style
68
	 *
69
	 * @return string
70
	 */
71
	public function filter_lightbox_style( $style = 'thickbox' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $style is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
		return static::$style_slug;
73
	}
74
75
	/**
76
	 * Get default settings for the script
77
	 *
78
	 * @return array
79
	 */
80
	protected function default_settings() {
81
		return array();
82
	}
83
84
	/**
85
	 * Get the settings for the JavaScript, with filter applied
86
	 *
87
	 * @internal
88
	 *
89
	 * @return mixed|void
90
	 */
91
	protected function get_settings() {
92
93
		$settings = static::default_settings();
94
95
		return apply_filters( 'gravityview/lightbox/provider/' . self::$slug . '/settings', $settings );
96
	}
97
98
	/**
99
	 * Output raw HTML in the wp_footer()
100
	 *
101
	 * @internal
102
	 */
103
	public function output_footer() {}
104
105
	/**
106
	 * Enqueue scripts for the lightbox
107
	 *
108
	 * @internal
109
	 */
110
	public function enqueue_scripts() {}
111
112
	/**
113
	 * Enqueue styles for the lightbox
114
	 *
115
	 * @internal
116
	 */
117
	public function enqueue_styles() {}
118
119
	/**
120
	 * Modify the attributes allowed in an anchor tag generated by GravityView
121
	 *
122
	 * @internal
123
	 *
124
	 * @param array $atts Attributes allowed in an anchor <a> tag.
125
	 *
126
	 * @return array
127
	 */
128
	public function allowed_atts( $atts = array() ) {
129
		return $atts;
130
	}
131
132
	/**
133
	 * Modified File Upload field links to use lightbox
134
	 *
135
	 * @internal
136
	 *
137
	 * @param array|string $link_atts Array or attributes string.
138
	 * @param array $field_compat Current GravityView field.
139
	 * @param \GV\Template_Context|null $context The context.
140
	 *
141
	 * @return mixed
142
	 */
143
	public function fileupload_link_atts( $link_atts, $field_compat = array(), $context = null ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field_compat is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
144
		return $link_atts;
145
	}
146
147
}
148