| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Modules\Registerer; |
| 4 |
|
| 5 |
defined('ABSPATH') or die; |
| 6 |
|
| 7 |
use FluentForm\App\Modules\Acl\Acl; |
| 8 |
use FluentForm\App\Services\Manager\FormManagerService; |
| 9 |
use FluentForm\Framework\Helpers\ArrayHelper; |
| 10 |
|
| 11 |
class AdminBar |
| 12 |
{ |
| 13 |
|
| 14 |
public function register() |
| 15 |
{ |
| 16 |
if (!self::isDisabled()) { |
| 17 |
add_action('admin_bar_menu', [$this, 'addMenuBar'], 99); |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
public static function isDisabled() |
| 22 |
{ |
| 23 |
$settings = get_option('_fluentform_global_form_settings'); |
| 24 |
|
| 25 |
if(!$settings || is_multisite()) { |
| 26 |
return true; |
| 27 |
} |
| 28 |
|
| 29 |
return 'no' == ArrayHelper::get($settings, 'misc.admin_top_nav_status'); |
| 30 |
} |
| 31 |
|
| 32 |
public function addMenuBar($wpAdminBar) |
| 33 |
{ |
| 34 |
$items = $this->getMenuItems(); |
| 35 |
if(empty($items)){ |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
foreach ($items as $itemKey => $item) { |
| 40 |
$arr = [ |
| 41 |
'id' => $itemKey == 'fluent_form' ? $itemKey : sanitize_title($itemKey), |
| 42 |
'parent' => $itemKey != 'fluent_form' ? 'fluent_form' : '', |
| 43 |
'title' => ArrayHelper::get($item, 'title'), |
| 44 |
'href' => ArrayHelper::get($item, 'url'), |
| 45 |
]; |
| 46 |
if(ArrayHelper::get($item,'meta')){ |
| 47 |
$arr['meta'] = [ |
| 48 |
'target' => '_blank', |
| 49 |
'rel' => 'noopener noreferrer', |
| 50 |
]; |
| 51 |
} |
| 52 |
$wpAdminBar->add_menu( |
| 53 |
$arr |
| 54 |
); |
| 55 |
do_action("fluentform/admin_nav_menu_{$itemKey}"); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
private function getMenuItems() |
| 61 |
{ |
| 62 |
$dashBoardCapability = 'fluentform_dashboard_access'; |
| 63 |
$dashBoardCapability = apply_filters_deprecated( |
| 64 |
'fluentform_dashboard_capability', |
| 65 |
[ |
| 66 |
$dashBoardCapability |
| 67 |
], |
| 68 |
FLUENTFORM_FRAMEWORK_UPGRADE, |
| 69 |
'fluentform/dashboard_capability', |
| 70 |
'Use fluentform/dashboard_capability instead of fluentform_dashboard_capability.' |
| 71 |
); |
| 72 |
|
| 73 |
$dashBoardCapability = apply_filters( |
| 74 |
'fluentform/dashboard_capability', |
| 75 |
$dashBoardCapability |
| 76 |
); |
| 77 |
|
| 78 |
$settingManager = 'fluentform_settings_manager'; |
| 79 |
$settingManager = apply_filters_deprecated( |
| 80 |
'fluentform_settings_capability', |
| 81 |
[ |
| 82 |
$settingManager |
| 83 |
], |
| 84 |
FLUENTFORM_FRAMEWORK_UPGRADE, |
| 85 |
'fluentform/settings_capability', |
| 86 |
'Use fluentform/settings_capability instead of fluentform_settings_capability.' |
| 87 |
); |
| 88 |
|
| 89 |
$settingsCapability = apply_filters( |
| 90 |
'fluentform/settings_capability', |
| 91 |
$settingManager |
| 92 |
); |
| 93 |
|
| 94 |
$fromRole = $currentUserCapability = false; |
| 95 |
if (!current_user_can($dashBoardCapability) && !current_user_can($settingsCapability)) { |
| 96 |
$currentUserCapability = Acl::getCurrentUserCapability(); |
| 97 |
if (!$currentUserCapability) { |
| 98 |
return; |
| 99 |
} else { |
| 100 |
$fromRole = true; |
| 101 |
$dashBoardCapability = $settingsCapability = $currentUserCapability; |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
if (Acl::isSuperMan()) { |
| 106 |
$fromRole = true; |
| 107 |
} |
| 108 |
|
| 109 |
if (defined('FLUENTFORMPRO')) { |
| 110 |
$title = __('Fluent Forms Pro', 'fluentform'); |
| 111 |
} else { |
| 112 |
$title = __('Fluent Forms', 'fluentform'); |
| 113 |
} |
| 114 |
|
| 115 |
$allowForms = FormManagerService::getUserAllowedFormsScope(); |
| 116 |
$hasUnreadSubmissions = wpFluent()->table('fluentform_submissions') |
| 117 |
->where('status', 'unread') |
| 118 |
->when(false !== $allowForms, function ($q) use ($allowForms){ |
| 119 |
return $q->whereIn('form_id', $allowForms ?: [0]); |
| 120 |
}) |
| 121 |
->count(); |
| 122 |
|
| 123 |
$entriesDropdownTitle = __('Entries', 'fluentform'); |
| 124 |
if ($hasUnreadSubmissions > 0) { |
| 125 |
$style = "background: #1A7EFB;color: white;border-radius: 8px;padding: 1px 7px; height: 16px; display: inline-flex; align-items: center;"; |
| 126 |
$title .= ' <span class="ff_unread_count" style="' . $style . '">' . $hasUnreadSubmissions . '</span>'; |
| 127 |
// for dropdown title |
| 128 |
$style .= 'float:right; margin-top:4px'; |
| 129 |
$entriesDropdownTitle .= ' <span class="ff_unread_count" style="' . $style . '">' . $hasUnreadSubmissions . '</span>'; |
| 130 |
} |
| 131 |
|
| 132 |
$items = [ |
| 133 |
'fluent_form' => [ |
| 134 |
'title' => $title, |
| 135 |
'capability' => $currentUserCapability, |
| 136 |
'url' => admin_url('admin.php?page=fluent_forms') |
| 137 |
], |
| 138 |
'all_forms' => [ |
| 139 |
'title' => __('Forms', 'fluentform'), |
| 140 |
'capability' => $currentUserCapability, |
| 141 |
'url' => admin_url('admin.php?page=fluent_forms') |
| 142 |
], |
| 143 |
]; |
| 144 |
|
| 145 |
if ($settingsCapability) { |
| 146 |
$items['new_form'] = [ |
| 147 |
'title' => __('New Form', 'fluentform'), |
| 148 |
'capability' => $fromRole ? $settingsCapability : 'fluentform_forms_manager', |
| 149 |
'url' => admin_url('admin.php?page=fluent_forms#add=1'), |
| 150 |
]; |
| 151 |
|
| 152 |
$items['fluent_forms_all_entries'] = [ |
| 153 |
'title' => $entriesDropdownTitle, |
| 154 |
'capability' => $fromRole ? $settingsCapability : 'fluentform_entries_viewer', |
| 155 |
'url' => admin_url('admin.php?page=fluent_forms_all_entries'), |
| 156 |
]; |
| 157 |
$showPaymentEntries = false; |
| 158 |
$showPaymentEntries = apply_filters_deprecated( |
| 159 |
'fluentform_show_payment_entries', |
| 160 |
[ |
| 161 |
$showPaymentEntries |
| 162 |
], |
| 163 |
FLUENTFORM_FRAMEWORK_UPGRADE, |
| 164 |
'fluentform/show_payment_entries', |
| 165 |
'Use fluentform/show_payment_entries instead of fluentform_show_payment_entries.' |
| 166 |
); |
| 167 |
|
| 168 |
if (apply_filters('fluentform/show_payment_entries', $showPaymentEntries)) { |
| 169 |
$items ['fluent_forms_payment_entries'] = [ |
| 170 |
'title' => __('Payments', 'fluentform'), |
| 171 |
'capability' => $fromRole ? $settingsCapability : 'fluentform_view_payments', |
| 172 |
'url' => admin_url('admin.php?page=fluent_forms_payment_entries') |
| 173 |
]; |
| 174 |
} |
| 175 |
|
| 176 |
} |
| 177 |
$items['fluent_forms_community'] = [ |
| 178 |
'title' => esc_html__( 'Community', 'fluentform' ), |
| 179 |
'url' => 'https://community.wpmanageninja.com/portal/space/fluent-forms/home', |
| 180 |
'meta' => true |
| 181 |
]; |
| 182 |
$items['fluent_forms_doc'] = [ |
| 183 |
'title' => __('Docs','fluentform'), |
| 184 |
'url' => 'https://wpmanageninja.com/docs/fluent-form/', |
| 185 |
'meta' => true |
| 186 |
]; |
| 187 |
$items['fluent_forms_doc'] = [ |
| 188 |
'title' => __('Docs','fluentform'), |
| 189 |
'url' => 'https://wpmanageninja.com/docs/fluent-form/', |
| 190 |
]; |
| 191 |
$items['fluent_forms_dev_doc'] = [ |
| 192 |
'title' => __('Developer Docs','fluentform'), |
| 193 |
'url' => 'https://developers.fluentforms.com/', |
| 194 |
'meta' => true |
| 195 |
]; |
| 196 |
return apply_filters('fluentform/admin_menu_bar_items', $items); |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
} |
| 201 |
|