PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.2
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.2
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 5.6.2 All 33 releases
automatorwp / includes / admin.php

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

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