-
Notifications
You must be signed in to change notification settings - Fork 2
/
class-astra-theme-visual-hooks.php
321 lines (289 loc) · 11.5 KB
/
class-astra-theme-visual-hooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<?php
defined( 'ABSPATH' ) or exit;
class Astra_Theme_Visual_Hooks {
private static $_instance = null;
/**
* All the Astra Hooks
*
* @since 1.0.0
* @var array
*/
private $astra_hooks = array();
public static function instance() {
if ( ! isset( self::$_instance ) ) {
self::$_instance = new self;
}
return self::$_instance;
}
public function set_hooks() {
$this->astra_hooks = array(
'head' => array(
'title' => __( 'Head', 'astra-addon' ),
'hooks' => array(
'astra_html_before' => array(
'title' => 'html_before',
'description' => __( 'Action to add your content or snippet just before the opening of <html> tag.', 'astra-addon' ),
),
'astra_head_top' => array(
'title' => 'head_top',
'description' => __( 'Action to add your content or snippet at top of the <head> tag.', 'astra-addon' ),
),
'astra_head_bottom' => array(
'title' => 'head_bottom',
'description' => __( 'Action to add your content or snippet at bottom of the <head> tag.', 'astra-addon' ),
),
'wp_head' => array(
'title' => 'wp_head',
'description' => __( 'Action to add custom style, script and meta at the bottom of <head> tag.', 'astra-addon' ),
),
),
),
'header' => array(
'title' => __( 'Header', 'astra-addon' ),
'hooks' => array(
'astra_body_top' => array(
'title' => 'body_top',
'description' => __( 'Action to add your content or snippet at top of the <body> tag.', 'astra-addon' ),
),
'astra_header_before' => array(
'title' => 'header_before',
'description' => __( 'Action to add your content or snippet just before the opening <header> tag.', 'astra-addon' ),
),
'astra_masthead_top' => array(
'title' => 'masthead_top',
'description' => __( 'Action to add your content or snippet at top of the <header> tag.', 'astra-addon' ),
),
'astra_main_header_bar_top' => array(
'title' => 'main_header_bar_top',
'description' => __( 'Action to add your content or snippet at top of the Main header.', 'astra-addon' ),
),
'astra_masthead_content' => array(
'title' => 'masthead_content',
'description' => __( 'Action to add your content or snippet in <header> tag.', 'astra-addon' ),
),
'astra_masthead_toggle_buttons_before' => array(
'title' => 'masthead_toggle_buttons_before',
'description' => __( 'Action to add your content or snippet before responsive menu toggle button.', 'astra-addon' ),
),
'astra_masthead_toggle_buttons_after' => array(
'title' => 'masthead_toggle_buttons_after',
'description' => __( 'Action to add your content or snippet after responsive menu toggle button.', 'astra-addon' ),
),
'astra_main_header_bar_bottom' => array(
'title' => 'main_header_bar_bottom',
'description' => __( 'Action to add your content or snippet after at bottom of the Main header.', 'astra-addon' ),
),
'astra_masthead_bottom' => array(
'title' => 'masthead_bottom',
'description' => __( 'Action to add your content or snippet at bottom of the <header> tag.', 'astra-addon' ),
),
'astra_header_after' => array(
'title' => 'header_after',
'description' => __( 'Action to add your content or snippet after the closing <header> tag.', 'astra-addon' ),
),
),
),
'content' => array(
'title' => __( 'Content', 'astra-addon' ),
'hooks' => array(
'astra_content_before' => array(
'title' => 'content_before',
'description' => __( 'Action to add your content or snippet before main content.', 'astra-addon' ),
),
'astra_content_top' => array(
'title' => 'content_top',
'description' => __( 'Action to add your content or snippet at top of main content.', 'astra-addon' ),
),
'astra_primary_content_top' => array(
'title' => 'primary_content_top',
'description' => __( 'Action to add your content or snippet at top of the primary content.', 'astra-addon' ),
),
'astra_content_while_before' => array(
'title' => 'content_while_before',
'description' => __( 'Action to add your content or snippet before loop start.', 'astra-addon' ),
),
'astra_entry_before' => array(
'title' => 'entry_before',
'description' => __( 'Action to add your content or snippet before <artical> tag.', 'astra-addon' ),
),
'astra_entry_top' => array(
'title' => 'entry_top',
'description' => __( 'Action to add your content or snippet at top of the <artical> tag.', 'astra-addon' ),
),
'astra_single_header_before' => array(
'title' => 'single_header_before',
'description' => __( 'Action to add your content or snippet before single post header.', 'astra-addon' ),
),
'astra_single_header_top' => array(
'title' => 'single_header_top',
'description' => __( 'Action to add your content or snippet at top of the single post header.', 'astra-addon' ),
),
'astra_single_header_bottom' => array(
'title' => 'single_header_bottom',
'description' => __( 'Action to add your content or snippet at bottom of the single post header.', 'astra-addon' ),
),
'astra_single_header_after' => array(
'title' => 'single_header_after',
'description' => __( 'Action to add your content or snippet after single post header.', 'astra-addon' ),
),
'astra_entry_content_before' => array(
'title' => 'entry_content_before',
'description' => __( 'Action to add your content or snippet before post content.', 'astra-addon' ),
),
'astra_entry_content_after' => array(
'title' => 'entry_content_after',
'description' => __( 'Action to add your content or snippet after post content', 'astra-addon' ),
),
'astra_entry_bottom' => array(
'title' => 'entry_bottom',
'description' => __( 'Action to add your content or snippet at bottom of the <artical> tag.', 'astra-addon' ),
),
'astra_entry_after' => array(
'title' => 'entry_after',
'description' => __( 'Action to add your content or snippet after closing <artical> tag.', 'astra-addon' ),
),
'astra_primary_content_bottom' => array(
'title' => 'primary_content_bottom',
'description' => __( 'Action to add your content or snippet at bottom of the primary content.', 'astra-addon' ),
),
'astra_content_while_after' => array(
'title' => 'content_while_after',
'description' => __( 'Action to add your content or snippet after loop end.', 'astra-addon' ),
),
'astra_content_bottom' => array(
'title' => 'content_bottom',
'description' => __( 'Action to add your content or snippet at bottom of the main content.', 'astra-addon' ),
),
'astra_content_after' => array(
'title' => 'content_after',
'description' => __( 'Action to add your content or snippet after main content.', 'astra-addon' ),
),
),
),
'comment' => array(
'title' => __( 'Comment', 'astra-addon' ),
'hooks' => array(
'astra_comments_before' => array(
'title' => 'comments_before',
'description' => __( 'Action to add your content or snippet before opening of comment start.', 'astra-addon' ),
),
'astra_comments_after' => array(
'title' => 'comments_after',
'description' => __( 'Action to add your content or snippet after closing of comment wrapper.', 'astra-addon' ),
),
),
),
'sidebar' => array(
'title' => __( 'Sidebar', 'astra-addon' ),
'hooks' => array(
'astra_sidebars_before' => array(
'title' => 'sidebars_before',
'description' => __( 'Action to add your content or snippet before opening of sidebar wrapper.', 'astra-addon' ),
),
'astra_sidebars_after' => array(
'title' => 'sidebars_after',
'description' => __( 'Action to add your content or snippet after closing of sidebar wrapper.', 'astra-addon' ),
),
),
),
'footer' => array(
'title' => __( 'Footer', 'astra-addon' ),
'hooks' => array(
'astra_footer_before' => array(
'title' => 'footer_before',
'description' => __( 'Action to add your content or snippet before the opening <footer> tag.', 'astra-addon' ),
),
'astra_footer_content_top' => array(
'title' => 'footer_content_top',
'description' => __( 'Action to add your content or snippet at top of the <footer> tag.', 'astra-addon' ),
),
'astra_footer_content_bottom' => array(
'title' => 'footer_content_bottom',
'description' => __( 'Action to add your content or snippet at bottom of the <footer> tag.', 'astra-addon' ),
),
'astra_footer_after' => array(
'title' => 'footer_after',
'description' => __( 'Action to add your content or snippet after the closing <footer> tag.', 'astra-addon' ),
),
'astra_body_bottom' => array(
'title' => 'body_bottom',
'description' => __( 'Action to add your content or snippet at bottom of the <body> tag.', 'astra-addon' ),
),
'wp_footer' => array(
'title' => 'wp_footer',
'description' => __( 'Action to add your content or snippet at end of the document.', 'astra-addon' ),
),
),
),
);
}
private function get_hooks() {
return $this->astra_hooks;
}
private function __construct() {
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu'), 90 );
if( ( isset( $_GET['astra-hooks' ] ) && 'show' === $_GET['astra-hooks' ] ) || apply_filters( 'astra_hooks_enable_for_non_admin_user', false ) ) {
$this->set_hooks();
add_action( 'wp', array( $this, 'display_hooks' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'add_css' ) );
}
}
/**
* Admin Bar Menu
*
* @since 1.1.0
*
* @param array $wp_admin_bar Admin bar menus.
* @return array Admin bar menus.
*/
function admin_bar_menu( $wp_admin_bar = array() )
{
$title = __( 'Show Astra Hooks' , 'astra-hooks' );
$href = add_query_arg( 'astra-hooks', 'show' );
if( isset( $_GET['astra-hooks' ] ) && 'show' === $_GET['astra-hooks' ] ) {
$title = __( 'Hide Astra Hooks' , 'astra-hooks' );
$href = remove_query_arg( 'astra-hooks' );
}
$wp_admin_bar->add_menu( array(
'title' => $title,
'id' => 'astra-hooks-menu',
'parent' => false,
'href' => $href,
) );
}
public function add_css() {
$css = '
.astra-hook{
text-align: left;
margin: 10px;
padding: 5px 5px 5px 10px;
border: 0px;
outline: 0px;
font-size: 14px;
overflow: auto;
color: #333333;
direction: ltr;
word-spacing: normal;
line-height: 1.5;
word-wrap: normal;
border: 1px solid #b1b1b1;
}
.astra-hook-astra_footer_content_top,
.astra-hook-astra_footer_content_bottom {
color: #b1b1b1;
}
';
wp_add_inline_style( 'astra-theme-css', $css );
}
public function display_hooks() {
foreach ( $this->get_hooks() as $section => $hooks_info ) {
$hooks = isset( $hooks_info[ 'hooks' ] ) ? $hooks_info[ 'hooks' ] : array();
foreach ( $hooks as $hook => $hook_details ) {
add_action( $hook, function() use ( $hook, $hook_details ) {
echo "<div class='astra-hook astra-hook-$hook'>". esc_attr( $hook ) ."</div>";
} );
}
}
}
}
add_action( 'plugins_loaded', 'Astra_Theme_Visual_Hooks::instance' );