|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Abstract class that makes it easy for plugins and themes to register no-conflict scripts and styles, as well as |
|
4
|
|
|
* add post meta keys for GravityView to parse when checking for the existence of shortcodes in content. |
|
5
|
|
|
* |
|
6
|
|
|
* @file abstract-gravityview-plugin-and-theme-hooks.php |
|
7
|
|
|
* @package GravityView |
|
8
|
|
|
* @license GPL2+ |
|
9
|
|
|
* @author Katz Web Services, Inc. |
|
10
|
|
|
* @link http://gravityview.co |
|
11
|
|
|
* @copyright Copyright 2015, Katz Web Services, Inc. |
|
12
|
|
|
* |
|
13
|
|
|
* @since 1.15.2 |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Abstract class that makes it easy for plugins and themes to register no-conflict scripts and styles, as well as |
|
18
|
|
|
* add post meta keys for GravityView to parse when checking for the existence of shortcodes in content. |
|
19
|
|
|
* |
|
20
|
|
|
* @since 1.15.2 |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class GravityView_Plugin_and_Theme_Hooks { |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @type string Optional. Class that should be exist in a plugin or theme. Used to check whether plugin is active. |
|
26
|
|
|
* @since 1.15.2 |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $class_name = false; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @type string Optional. Function that should be exist in a plugin or theme. Used to check whether plugin is active. |
|
32
|
|
|
* @since 1.15.2 |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $function_name = false; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @type string Optional. Constant that should be defined by plugin or theme. Used to check whether plugin is active. |
|
38
|
|
|
* @since 1.15.2 |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $constant_name = false; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Define the keys to be parsed by the `gravityview/data/parse/meta_keys` hook |
|
44
|
|
|
* @see GravityView_View_Data::parse_post_meta |
|
45
|
|
|
* @since 1.15.2 |
|
46
|
|
|
* @type array |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $content_meta_keys = array(); |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Define script handles used by the theme or plugin to be parsed by the `gravityview/data/parse/meta_keys` hook |
|
52
|
|
|
* @see GravityView_Admin::remove_conflicts |
|
53
|
|
|
* @since 1.15.2 |
|
54
|
|
|
* @type array |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $script_handles = array(); |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Define style handles used by the theme or plugin to be parsed by the `gravityview/data/parse/meta_keys` hook |
|
60
|
|
|
* @see GravityView_Admin::remove_conflicts |
|
61
|
|
|
* @since 1.15.2 |
|
62
|
|
|
* @type array |
|
63
|
|
|
*/ |
|
64
|
|
|
protected $style_handles = array(); |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Define features in the admin editor used by the theme or plugin to be used when registering the GravityView post type |
|
68
|
|
|
* @see \GV\Entry::get_endpoint_name |
|
69
|
|
|
* @since 1.15.2 |
|
70
|
|
|
* @type array |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $post_type_support = array(); |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* GravityView_Theme_Support constructor. |
|
76
|
|
|
* @return void |
|
|
|
|
|
|
77
|
|
|
*/ |
|
78
|
|
|
public function __construct() { |
|
79
|
|
|
add_action( 'wp_loaded', array( $this, '_wp_loaded' ) ); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Fired when all themes and plugins have been loaded. |
|
84
|
|
|
* This makes sure we can reliably detect functions and classes. |
|
85
|
|
|
* @internal |
|
86
|
|
|
* @return void |
|
87
|
|
|
*/ |
|
88
|
|
|
public function _wp_loaded() { |
|
89
|
|
|
$this->maybe_add_hooks(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Check whether plugin or theme exists. If so, add hooks. |
|
94
|
|
|
* This is to reduce load time, since `apply_filters()` isn't free. |
|
95
|
|
|
* If the class name or function name or constant exists for a plugin or theme, add hooks |
|
96
|
|
|
* If the class/function/definition aren't speicifed add the hooks |
|
97
|
|
|
* |
|
98
|
|
|
* @since 1.15.2 |
|
99
|
|
|
* @return void |
|
100
|
|
|
*/ |
|
101
|
|
|
private function maybe_add_hooks() { |
|
102
|
|
|
$class_exists = $this->class_name && class_exists( $this->class_name ); |
|
103
|
|
|
$function_exists = $this->function_name && function_exists( $this->function_name ); |
|
104
|
|
|
$constant_defined = $this->constant_name && defined("{$this->constant_name}"); |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
if( $class_exists || $function_exists || $constant_defined ) { |
|
107
|
|
|
$this->add_hooks(); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Add filters for meta key and script/style handles, if defined. |
|
113
|
|
|
* @since 1.15.2 |
|
114
|
|
|
* @return void |
|
115
|
|
|
*/ |
|
116
|
|
|
protected function add_hooks() { |
|
117
|
|
|
if( $this->content_meta_keys ) { |
|
|
|
|
|
|
118
|
|
|
add_filter( 'gravityview/data/parse/meta_keys', array( $this, 'merge_content_meta_keys' ), 10, 2 ); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
if( $this->script_handles ) { |
|
|
|
|
|
|
122
|
|
|
add_filter( 'gravityview_noconflict_scripts', array( $this, 'merge_noconflict_scripts' ) ); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
if( $this->style_handles ) { |
|
|
|
|
|
|
126
|
|
|
add_filter( 'gravityview_noconflict_styles', array( $this, 'merge_noconflict_styles' ) ); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
if( $this->post_type_support ) { |
|
|
|
|
|
|
130
|
|
|
add_filter( 'gravityview_post_type_support', array( $this, 'merge_post_type_support' ), 10, 2 ); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Merge plugin or theme post type support definitions with existing support values |
|
136
|
|
|
* |
|
137
|
|
|
* @since 1.15.2 |
|
138
|
|
|
* |
|
139
|
|
|
* @param array $supports Array of features associated with a functional area of the edit screen. |
|
140
|
|
|
* @param boolean $is_hierarchical Do Views support parent/child relationships? See `gravityview_is_hierarchical` filter. |
|
141
|
|
|
* |
|
142
|
|
|
* @return array Array of features associated with a functional area of the edit screen, merged with existing values |
|
143
|
|
|
*/ |
|
144
|
|
|
public function merge_post_type_support( $supports = array(), $is_hierarchical = false ) { |
|
|
|
|
|
|
145
|
|
|
$supports = array_merge( $this->post_type_support, $supports ); |
|
146
|
|
|
return $supports; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Merge plugin or theme styles with existing no-conflict styles |
|
151
|
|
|
* |
|
152
|
|
|
* @since 1.15.2 |
|
153
|
|
|
* |
|
154
|
|
|
* @param array $handles Array of style handles, as registered with WordPress |
|
155
|
|
|
* |
|
156
|
|
|
* @return array Handles, merged with existing styles |
|
157
|
|
|
*/ |
|
158
|
|
|
public function merge_noconflict_styles( $handles ) { |
|
159
|
|
|
$handles = array_merge( $this->style_handles, $handles ); |
|
160
|
|
|
return $handles; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Merge plugin or theme scripts with existing no-conflict scripts |
|
165
|
|
|
* |
|
166
|
|
|
* @since 1.15.2 |
|
167
|
|
|
* |
|
168
|
|
|
* @param array $handles Array of script handles, as registered with WordPress |
|
169
|
|
|
* |
|
170
|
|
|
* @return array Handles, merged with existing scripts |
|
171
|
|
|
*/ |
|
172
|
|
|
public function merge_noconflict_scripts( $handles ) { |
|
173
|
|
|
$handles = array_merge( $this->script_handles, $handles ); |
|
174
|
|
|
return $handles; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Merge plugin or theme meta keys that store shortcode data with existing keys to check |
|
179
|
|
|
* |
|
180
|
|
|
* @since 1.15.2 |
|
181
|
|
|
* |
|
182
|
|
|
* @param array $handles Array of meta keys to check for existence of shortcodes |
|
|
|
|
|
|
183
|
|
|
* @param int $post_id The ID being checked by GravityView |
|
184
|
|
|
* |
|
185
|
|
|
* @return array Meta key array, merged with existing meta keys |
|
186
|
|
|
*/ |
|
187
|
|
|
public function merge_content_meta_keys( $meta_keys = array(), $post_id = 0 ) { |
|
|
|
|
|
|
188
|
|
|
return array_merge( $this->content_meta_keys, $meta_keys ); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
} |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.