PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 5.8.6
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v5.8.6
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
automatorwp / includes / admin.php

admin.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 5.8.6, at includes/admin.php

444 lines 12.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin
4 *
5 * @package AutomatorWP\Admin
6 * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]>
7 * @since 1.0.0
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 // Admin includes
13 require_once AUTOMATORWP_DIR . 'includes/admin/notices.php';
14 require_once AUTOMATORWP_DIR . 'includes/admin/upgrades.php';
15 // Admin pages
16 require_once AUTOMATORWP_DIR . 'includes/admin/pages/dashboard.php';
17 require_once AUTOMATORWP_DIR . 'includes/admin/pages/add-ons.php';
18 require_once AUTOMATORWP_DIR . 'includes/admin/pages/import-automation.php';
19 require_once AUTOMATORWP_DIR . 'includes/admin/pages/licenses.php';
20 require_once AUTOMATORWP_DIR . 'includes/admin/pages/settings.php';
21
22 /**
23 * Helper function to get an option value.
24 *
25 * @since 1.0.0
26 *
27 * @param string $option_name
28 * @param bool $default
29 *
30 * @return mixed Option value or default parameter value if not exists.
31 */
32 function automatorwp_get_option( $option_name, $default = false ) {
33
34 if( AutomatorWP()->settings === null ) {
35 AutomatorWP()->settings = get_option( 'automatorwp_settings' );
36 }
37
38 return isset( AutomatorWP()->settings[ $option_name ] ) ? AutomatorWP()->settings[ $option_name ] : $default;
39
40 }
41
42 /**
43 * Admin menus
44 *
45 * @since 1.0.0
46 */
47 function automatorwp_admin_menu() {
48
49 $minimum_role = automatorwp_get_manager_capability();
50
51 // AutomatorWP menu
52 add_menu_page( 'AutomatorWP', 'AutomatorWP', $minimum_role, 'automatorwp', '', 'dashicons-automatorwp', 50 );
53
54 // Dashboard submenu
55 add_submenu_page( 'automatorwp', __( 'Dashboard', 'automatorwp' ), __( 'Dashboard', 'automatorwp' ), $minimum_role, 'automatorwp', 'automatorwp_dashboard_page' );
56
57 }
58 add_action( 'admin_menu', 'automatorwp_admin_menu' );
59
60 /**
61 * Admin submenus
62 *
63 * @since 1.0.0
64 */
65 function automatorwp_admin_submenu() {
66
67 $minimum_role = automatorwp_get_manager_capability();
68
69 // Add-ons submenu
70 add_submenu_page( 'automatorwp', __( 'Add-ons', 'automatorwp' ), __( 'Add-ons', 'automatorwp' ), $minimum_role, 'automatorwp_add_ons', 'automatorwp_add_ons_page' );
71
72 // Import Automation submenu (hidden)
73 add_submenu_page( 'automatorwp', __( 'Import Automation', 'automatorwp' ), __( 'Import Automation', 'automatorwp' ), $minimum_role, 'automatorwp_import_automation', 'automatorwp_import_automation_page' );
74
75 }
76 add_action( 'admin_menu', 'automatorwp_admin_submenu', 15 );
77
78 /**
79 * Helper function to get the try of the day
80 *
81 * @since 1.0.0
82 *
83 * @return array|false
84 */
85 function automatorwp_get_try_option() {
86
87 $options = array();
88
89 if( ! class_exists( 'GamiPress' ) ) {
90 $options[] = array(
91 'label' => __( 'Try GamiPress!', 'automatorwp' ),
92 'slug' => 'gamipress'
93 );
94 }
95
96 if( ! class_exists( 'ShortLinksPro' ) ) {
97 $options[] = array(
98 'label' => __( 'Try ShortLinks Pro!', 'automatorwp' ),
99 'slug' => 'shortlinkspro'
100 );
101 }
102
103 if( ! class_exists( 'BBForms' ) ) {
104 $options[] = array(
105 'label' => __( 'Try BBForms!', 'automatorwp' ),
106 'slug' => 'bbforms'
107 );
108 }
109
110 $count = count( $options );
111
112 // Bail if no options found
113 if( $count === 0 ) return false;
114
115 $day = absint( gmdate( 'd' ) );
116 $index = $day % $count;
117
118 if( ! isset( $options[ $index ] ) ) {
119 $index = 0;
120 }
121
122 return $options[ $index ];
123
124 }
125
126 /**
127 * Add Try submenu
128 *
129 * @since 1.0.0
130 */
131 function automatorwp_try_admin_submenu() {
132
133 $option = automatorwp_get_try_option();
134
135 if( ! $option ) return;
136
137 // Set minimum role for menu
138 $minimum_role = automatorwp_get_manager_capability();
139
140 $badge = '<span class="automatorwp-admin-menu-badge">' . __( 'New', 'automatorwp' ) . '</span>';
141
142 add_submenu_page( 'automatorwp', $option['label'], $option['label'] . $badge, $minimum_role, 'https://wordpress.org/plugins/' . $option['slug'] . '/', null );
143 }
144 add_action( 'admin_menu', 'automatorwp_try_admin_submenu', 9999 );
145
146 /**
147 * Add AutomatorWP admin bar menu
148 *
149 * @since 1.3.2
150 *
151 * @param WP_Admin_Bar $wp_admin_bar
152 */
153 function automatorwp_admin_bar_menu( $wp_admin_bar ) {
154
155 // Bail if current user can't manage AutomatorWP
156 if ( ! current_user_can( automatorwp_get_manager_capability() ) ) {
157 return;
158 }
159
160 // Bail if admin bar menu disabled
161 if( (bool) automatorwp_get_option( 'disable_admin_bar_menu', false ) ) {
162 return;
163 }
164
165 // AutomatorWP
166 $wp_admin_bar->add_node( array(
167 'id' => 'automatorwp',
168 'title' => '<span class="ab-icon"></span>' . 'AutomatorWP',
169 'meta' => array( 'class' => 'automatorwp' ),
170 ) );
171
172 // Dashboard
173 $wp_admin_bar->add_node( array(
174 'id' => 'automatorwp-dashboard',
175 'title' => __( 'Dashboard', 'automatorwp' ),
176 'parent' => 'automatorwp',
177 'href' => admin_url( 'admin.php?page=automatorwp' )
178 ) );
179
180 // Automations
181 $wp_admin_bar->add_node( array(
182 'id' => 'automatorwp-automations',
183 'title' => __( 'Automations', 'automatorwp' ),
184 'parent' => 'automatorwp',
185 'href' => admin_url( 'admin.php?page=automatorwp_automations' )
186 ) );
187
188 // Logs
189 $wp_admin_bar->add_node( array(
190 'id' => 'automatorwp-logs',
191 'title' => __( 'Logs', 'automatorwp' ),
192 'parent' => 'automatorwp',
193 'href' => admin_url( 'admin.php?page=automatorwp_logs' )
194 ) );
195
196 }
197 add_action( 'admin_bar_menu', 'automatorwp_admin_bar_menu', 100 );
198
199 /**
200 * Add GamiPress admin bar menu
201 *
202 * @since 1.3.2
203 */
204 function automatorwp_admin_bar_menu_bottom( $wp_admin_bar ) {
205
206 // Bail if current user can't manage AutomatorWP
207 if ( ! current_user_can( automatorwp_get_manager_capability() ) ) {
208 return;
209 }
210
211 // Bail if admin bar menu disabled
212 if( (bool) automatorwp_get_option( 'disable_admin_bar_menu', false ) ) {
213 return;
214 }
215
216 // Licenses
217 $wp_admin_bar->add_node( array(
218 'id' => 'automatorwp-licenses',
219 'title' => __( 'Licenses', 'automatorwp' ),
220 'parent' => 'automatorwp',
221 'href' => admin_url( 'admin.php?page=automatorwp_licenses' )
222 ) );
223
224 // Settings
225 $wp_admin_bar->add_node( array(
226 'id' => 'automatorwp-settings',
227 'title' => __( 'Settings', 'automatorwp' ),
228 'parent' => 'automatorwp',
229 'href' => admin_url( 'admin.php?page=automatorwp_settings' )
230 ) );
231
232 // Add-ons
233 $wp_admin_bar->add_node( array(
234 'id' => 'automatorwp-add-ons',
235 'title' => __( 'Add-ons', 'automatorwp' ),
236 'parent' => 'automatorwp',
237 'href' => admin_url( 'admin.php?page=automatorwp_add_ons' )
238 ) );
239
240 }
241 add_action( 'admin_bar_menu', 'automatorwp_admin_bar_menu_bottom', 999 );
242
243 /**
244 * Add Try admin bar submenu
245 *
246 * @since 1.0.0
247 *
248 * @param object $wp_admin_bar The WordPress toolbar object
249 */
250 function automatorwp_try_admin_bar_submenu( $wp_admin_bar ) {
251
252 // Bail if current user can't manage
253 if ( ! current_user_can( automatorwp_get_manager_capability() ) ) {
254 return;
255 }
256
257 // Bail if admin bar menu disabled
258 if( (bool) automatorwp_get_option( 'disable_admin_bar_menu', false ) ) {
259 return;
260 }
261
262 $option = automatorwp_get_try_option();
263
264 if( ! $option ) return;
265
266 $badge = '<span class="automatorwp-admin-menu-badge">' . __( 'New', 'automatorwp' ) . '</span>';
267
268 // Try AutomatorWP
269 $wp_admin_bar->add_node( array(
270 'id' => 'automatorwp-try',
271 'title' => $option['label'] . $badge,
272 'parent' => 'automatorwp',
273 'href' => 'https://wordpress.org/plugins/' . $option['slug'] . '/'
274 ) );
275
276 }
277 add_action( 'admin_bar_menu', 'automatorwp_try_admin_bar_submenu', 9999 );
278
279 /**
280 * Processes all GamiPress actions sent via POST and GET by looking for the 'automatorwp-action' request and running do_action() to call the function
281 *
282 * @since 1.4.8
283 */
284 function automatorwp_process_actions() {
285 if ( isset( $_POST['automatorwp-action'] ) ) {
286 do_action( 'automatorwp_action_' . $_POST['automatorwp-action'], $_POST );
287 }
288
289 if ( isset( $_GET['automatorwp-action'] ) ) {
290 do_action( 'automatorwp_action_' . $_GET['automatorwp-action'], $_GET );
291 }
292 }
293 add_action( 'admin_init', 'automatorwp_process_actions' );
294
295 /**
296 * Helper function to register custom meta boxes
297 *
298 * @since 1.0.8
299 *
300 * @param string $id
301 * @param string $title
302 * @param string|array $object_types
303 * @param array $fields
304 * @param array $args
305 */
306 function automatorwp_add_meta_box( $id, $title, $object_types, $fields, $args = array() ) {
307
308 // ID for hooks
309 $hook_id = str_replace( '-', '_', $id );
310
311 /**
312 * Filter box fields to allow to extend it
313 *
314 * @since 1.0.8
315 *
316 * @param array $fields Box fields
317 * @param array $args Box args
318 *
319 * @return array
320 */
321 $fields = apply_filters( "automatorwp_{$hook_id}_fields", $fields, $args );
322
323 foreach( $fields as $field_id => $field ) {
324
325 $fields[$field_id]['id'] = $field_id;
326
327 // Support for group fields
328 if( isset( $field['fields'] ) && is_array( $field['fields'] ) ) {
329
330 foreach( $field['fields'] as $group_field_id => $group_field ) {
331
332 $fields[$field_id]['fields'][$group_field_id]['id'] = $group_field_id;
333
334 }
335
336 }
337
338 }
339
340 $args = wp_parse_args( $args, array(
341 'vertical_tabs' => false,
342 'tabs' => array(),
343 'context' => 'normal',
344 'priority' => 'default',
345 'show_on_cb' => '',
346 ) );
347
348 /**
349 * Filter box tabs to allow extend it
350 *
351 * @since 1.0.8
352 *
353 * @param array $tabs Box tabs
354 * @param array $fields Box fields
355 * @param array $args Box args
356 *
357 * @return array
358 */
359 $tabs = apply_filters( "automatorwp_{$hook_id}_tabs", $args['tabs'], $fields, $args );
360
361 // Parse tabs
362 foreach( $tabs as $tab_id => $tab ) {
363
364 $tabs[$tab_id]['id'] = $tab_id;
365
366 }
367
368 // Setup the final box arguments
369 $box = array(
370 'id' => $id,
371 'title' => $title,
372 'object_types' => ! is_array( $object_types) ? array( $object_types ) : $object_types,
373 'tabs' => $tabs,
374 'vertical_tabs' => $args['vertical_tabs'],
375 'context' => $args['context'],
376 'priority' => $args['priority'],
377 'show_on_cb' => $args['show_on_cb'],
378 'classes' => 'automatorwp-form automatorwp-box-form',
379 'fields' => $fields
380 );
381
382 /**
383 * Filter the final box args that will be passed to CMB2
384 *
385 * @since 1.0.0
386 *
387 * @param array $box Final box args
388 * @param string $id Box id
389 * @param string $title Box title
390 * @param string|array $object_types Object types where box will appear
391 * @param array $fields Box fields
392 * @param array $tabs Box tabs
393 * @param array $args Box args
394 */
395 apply_filters( "automatorwp_{$hook_id}_box", $box, $id, $title, $object_types, $fields, $tabs, $args );
396
397 // Instance the CMB2 box
398 new_cmb2_box( $box );
399
400 }
401
402 /**
403 * Add custom footer text to the admin dashboard
404 *
405 * @since 2.0.0
406 *
407 * @param string $footer_text The existing footer text
408 *
409 * @return string
410 */
411 function automatorwp_admin_footer_text( $footer_text ) {
412
413 global $typenow;
414
415 if (( isset( $_GET['page'] ) && (
416 $_GET['page'] === 'automatorwp_settings'
417 || $_GET['page'] === 'automatorwp_automations'
418 || $_GET['page'] === 'edit_automatorwp_automations'
419 || $_GET['page'] === 'automatorwp_logs'
420 || $_GET['page'] === 'edit_automatorwp_logs'
421 || $_GET['page'] === 'automatorwp_add_ons'
422 || $_GET['page'] === 'automatorwp_tools'
423 || $_GET['page'] === 'automatorwp'
424 )
425 )
426 ) {
427
428 $automatorwp_footer_text = sprintf( __( 'Thank you for using <a href="%1$s" target="_blank">AutomatorWP</a>! Please leave us a <a href="%2$s" target="_blank">%3$s</a> rating on WordPress.org', 'automatorwp' ),
429 'https://automatorwp.com',
430 'https://wordpress.org/support/plugin/automatorwp/reviews/?rate=5#new-post',
431 '&#9733;&#9733;&#9733;&#9733;&#9733;'
432 );
433
434 return str_replace( '</span>', '', $footer_text ) . ' | ' . $automatorwp_footer_text . '</span>';
435
436 } else {
437
438 return $footer_text;
439
440 }
441
442 }
443 add_filter( 'admin_footer_text', 'automatorwp_admin_footer_text' );
444