PluginProbe
Gravity Forms Eway / 2.4.1
Gravity Forms Eway v2.4.1
2.7.0 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.8.0 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 All 56 releases
gravityforms-eway / includes / class.Requires.php

class.Requires.php in Gravity Forms Eway 2.4.1, at includes/class.Requires.php

85 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * collect and display admin notices for failed prerequisites
9 */
10 class GfEwayRequires {
11
12 private $notices;
13
14 /**
15 * set up the notices container, and hook actions for displaying notices
16 * only called when a notice is being added
17 */
18 protected function init() {
19 if (!is_array($this->notices)) {
20 $this->notices = array();
21
22 // hook admin_notices, again! so need to hook later than 10
23 add_action('admin_notices', array($this, 'maybeShowAdminNotices'), 20);
24
25 // show Requires notices before update information, so hook earlier than 10
26 add_action('after_plugin_row_' . GFEWAY_PLUGIN_NAME, array($this, 'showPluginRowNotices'), 9, 2);
27 }
28 }
29
30 /**
31 * add a Requires notices
32 * @param string $notice
33 */
34 public function addNotice($notice) {
35 $this->init();
36 $this->notices[] = $notice;
37 }
38
39 /**
40 * maybe show admin notices, if on an appropriate admin page with admin or similar logged in
41 */
42 public function maybeShowAdminNotices() {
43 if ($this->canShowAdminNotices()) {
44 $notices = $this->notices;
45 require GFEWAY_PLUGIN_ROOT . 'views/requires-admin-notice.php';
46 }
47 }
48
49 /**
50 * show plugin page row with requires notices
51 */
52 public function showPluginRowNotices() {
53 global $wp_list_table;
54
55 if (empty($wp_list_table)) {
56 return;
57 }
58
59 $notices = $this->notices;
60 require GFEWAY_PLUGIN_ROOT . 'views/requires-plugin-notice.php';
61 }
62
63 /**
64 * test whether we can show admin-related notices
65 * @return bool
66 */
67 protected function canShowAdminNotices() {
68 global $hook_suffix;
69
70 // only on specific pages
71 $subview = empty($_GET['subview']) ? 'settings' : $_GET['subview'];
72 if ($hook_suffix !== 'forms_page_gf_settings' || $subview !== 'settings') {
73 return false;
74 }
75
76 // only bother admins / plugin installers / option setters with this stuff
77 if (!current_user_can('activate_plugins') && !current_user_can('manage_options')) {
78 return false;
79 }
80
81 return true;
82 }
83
84 }
85