| @@ -10,8 +10,9 @@ | ||
| 10 | 10 | use BitCode\BitForm\Core\Integration\IntegrationHandler; |
| 11 | 11 | use BitCode\BitForm\Core\Util\DateTimeHelper; |
| 12 | 12 | use BitCode\BitForm\Core\Util\FileDownloadProvider; |
| 13 | 13 | use BitCode\BitForm\Core\Util\IpTool; |
| 14 | +use WP_Admin_Bar; | |
| 14 | 15 | |
| 15 | 16 | class Admin_Bar |
| 16 | 17 | { |
| 17 | 18 | private static $fonts_url = [ |
| @@ -25,8 +26,10 @@ | ||
| 25 | 26 | add_action('admin_menu', [$this, 'AdminMenu']); |
| 26 | 27 | add_action('admin_enqueue_scripts', [$this, 'AdminAssets']); |
| 27 | 28 | add_filter('style_loader_tag', [$this, 'linkTagFilter'], 0, 3); |
| 28 | 29 | add_filter('script_loader_tag', [$this, 'scriptTagFilter'], 0, 3); |
| 30 | + add_action('admin_bar_menu', [$this, 'AdminTopMenu'], 999); | |
| 31 | + add_action('admin_enqueue_scripts', [$this, 'bitforms_enqueue_admin_styles']); | |
| 29 | 32 | } |
| 30 | 33 | |
| 31 | 34 | /** |
| 32 | 35 | * Register the admin menu |
| @@ -37,8 +40,9 @@ | ||
| 37 | 40 | { |
| 38 | 41 | global $submenu; |
| 39 | 42 | |
| 40 | 43 | $capability = apply_filters('bitforms_form_access_capability', 'manage_options'); |
| 44 | + | |
| 41 | 45 | add_menu_page( |
| 42 | 46 | __('Bit Form - Most advanced form builder and database management system', 'bit-form'), |
| 43 | 47 | 'Bit Form', |
| 44 | 48 | $capability, |
| @@ -47,16 +51,90 @@ | ||
| 47 | 51 | 'data:image/svg+xml;base64,' . base64_encode('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 163 163"><path fill="#fff" d="M106 0H57A57 57 0 000 57v49a57 57 0 0057 57h49a57 57 0 0057-57V57a57 57 0 00-57-57zM51 60v3l-1 59v12c0 5-3 8-8 6-2-1-3-4-3-6v-21-55a29 29 0 011-4 5 5 0 015-4h33a4 4 0 004-2c2-3 8-2 10-1a9 9 0 015 9 9 9 0 01-7 8c-3 1-6 0-9-3a3 3 0 00-1-1H51zm73 74c-6 5-12 6-20 6H72a8 8 0 01-4-1 5 5 0 01-2-6 5 5 0 015-3h35c11-1 20-10 21-20 0-11-8-20-18-23a6 6 0 00-1 0H78h-1v14l1 2h18a4 4 0 003-1c4-4 8-3 11-1 4 2 5 7 3 12-2 4-9 6-13 2a6 6 0 00-5-1H71c-3 0-5-2-5-6V82c0-4 1-5 5-6h17a21 21 0 0021-24c-1-9-8-16-16-18a25 25 0 00-6 0H46c-4 0-7-3-7-6s3-5 7-5h42a33 33 0 0132 23c2 11 0 20-6 29l-1 2 5 2c11 4 17 12 19 23 3 12-2 24-13 32z"/></svg>'), |
| 48 | 52 | 56 |
| 49 | 53 | ); |
| 50 | 54 | if (current_user_can($capability)) { |
| 51 | - $submenu['bitform'][] = [__('All Forms', 'bit-form'), $capability, 'admin.php?page=bitform#/']; | |
| 55 | + $entriesCount = ''; | |
| 56 | + if (self::countUnreadEntries()) { | |
| 57 | + $entriesCount = ' <span class="update-plugins">' . self::countUnreadEntries() . '</span>'; | |
| 58 | + } | |
| 59 | + | |
| 60 | + $submenu['bitform'][] = [__('All Forms' . $entriesCount, 'bit-form'), $capability, 'admin.php?page=bitform#/']; | |
| 61 | + $submenu['bitform'][] = [__('Form Templates <span class="bf-template-new-badge">New</span>', 'bit-form'), $capability, 'admin.php?page=bitform#/form-templates']; | |
| 52 | 62 | $submenu['bitform'][] = [__('App Settings', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/recaptcha']; |
| 53 | 63 | $submenu['bitform'][] = [__('SMTP', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/smtp']; |
| 64 | + $submenu['bitform'][] = [__('PDF Setting', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/pdf']; | |
| 65 | + $submenu['bitform'][] = [__('CPT', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/cpt']; | |
| 66 | + $submenu['bitform'][] = [__('Bit Form API', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/api']; | |
| 54 | 67 | $submenu['bitform'][] = [__('Payments', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/payments']; |
| 55 | 68 | $submenu['bitform'][] = [__('Doc & Support', 'bit-form'), $capability, 'admin.php?page=bitform#/doc-support']; |
| 56 | 69 | } |
| 57 | 70 | } |
| 58 | 71 | |
| 72 | + public function AdminTopMenu(WP_Admin_Bar $wp_admin_bar) | |
| 73 | + { | |
| 74 | + $indicator = ''; | |
| 75 | + if (self::countUnreadEntries()) { | |
| 76 | + $indicator = ' <div class="wp-core-ui wp-ui-notification bf-indicator-badge">' . self::countUnreadEntries() . '</div>'; | |
| 77 | + } | |
| 78 | + | |
| 79 | + $wp_admin_bar->add_node([ | |
| 80 | + 'id' => 'bitform', | |
| 81 | + 'title' => 'Bit Form' . $indicator, | |
| 82 | + 'href' => admin_url('admin.php?page=bitform'), | |
| 83 | + 'meta' => [ | |
| 84 | + 'class' => 'bitform-admin-bar', | |
| 85 | + ], | |
| 86 | + ]); | |
| 87 | + $wp_admin_bar->add_node([ | |
| 88 | + 'id' => 'bitform-all-forms', | |
| 89 | + 'parent' => 'bitform', | |
| 90 | + 'title' => 'All Forms' . $indicator, | |
| 91 | + 'href' => admin_url('admin.php?page=bitform#/'), | |
| 92 | + ]); | |
| 93 | + $wp_admin_bar->add_node([ | |
| 94 | + 'id' => 'bitform-form-templates', | |
| 95 | + 'parent' => 'bitform', | |
| 96 | + 'title' => 'Form Templates', | |
| 97 | + 'href' => admin_url('admin.php?page=bitform#/form-templates'), | |
| 98 | + ]); | |
| 99 | + $wp_admin_bar->add_node([ | |
| 100 | + 'id' => 'bitform-app-settings', | |
| 101 | + 'parent' => 'bitform', | |
| 102 | + 'title' => 'App Settings', | |
| 103 | + 'href' => admin_url('admin.php?page=bitform#/app-settings/recaptcha'), | |
| 104 | + ]); | |
| 105 | + $wp_admin_bar->add_node([ | |
| 106 | + 'id' => 'bitform-smtp', | |
| 107 | + 'parent' => 'bitform', | |
| 108 | + 'title' => 'SMTP', | |
| 109 | + 'href' => admin_url('admin.php?page=bitform#/app-settings/smtp'), | |
| 110 | + ]); | |
| 111 | + $wp_admin_bar->add_node([ | |
| 112 | + 'id' => 'bitform-pdf-setting', | |
| 113 | + 'parent' => 'bitform', | |
| 114 | + 'title' => 'PDF Setting', | |
| 115 | + 'href' => admin_url('admin.php?page=bitform#/app-settings/pdf'), | |
| 116 | + ]); | |
| 117 | + $wp_admin_bar->add_node([ | |
| 118 | + 'id' => 'bitform-cpt', | |
| 119 | + 'parent' => 'bitform', | |
| 120 | + 'title' => 'CPT', | |
| 121 | + 'href' => admin_url('admin.php?page=bitform#/app-settings/cpt'), | |
| 122 | + ]); | |
| 123 | + $wp_admin_bar->add_node([ | |
| 124 | + 'id' => 'bitform-api', | |
| 125 | + 'parent' => 'bitform', | |
| 126 | + 'title' => 'Bit Form API', | |
| 127 | + 'href' => admin_url('admin.php?page=bitform#/app-settings/api'), | |
| 128 | + ]); | |
| 129 | + $wp_admin_bar->add_node([ | |
| 130 | + 'id' => 'bitform-payments', | |
| 131 | + 'parent' => 'bitform', | |
| 132 | + 'title' => 'Payments', | |
| 133 | + 'href' => admin_url('admin.php?page=bitform#/app-settings/payments'), | |
| 134 | + ]); | |
| 135 | + } | |
| 136 | + | |
| 59 | 137 | public function getAllPages() |
| 60 | 138 | { |
| 61 | 139 | $pages = get_pages(['post_status' => 'publish', 'sort_column' => 'post_date', 'sort_order' => 'desc']); |
| 62 | 140 | $allPages = []; |
| @@ -234,8 +312,12 @@ | ||
| 234 | 312 | 'timeZone' => DateTimeHelper::wp_timezone_string(), |
| 235 | 313 | 'googleRedirectURL' => get_rest_url() . 'bitform/v1/google', |
| 236 | 314 | 'oneDriveRedirectURL' => get_rest_url() . 'bitform/v1/oneDrive', |
| 237 | 315 | 'zohoRedirectURL' => get_rest_url() . 'bitform/v1/zoho', |
| 316 | + 'userRoles' => get_editable_roles(), | |
| 317 | + 'downloadedPdfFonts' => is_array(get_option('bitforms_pdf_fonts')) ? get_option('bitforms_pdf_fonts') : [], | |
| 318 | + 'permission' => empty(get_option('bitforms_allow_tracking')) ? false : true, | |
| 319 | + 'templatePath' => BITFORMS_ROOT_URI . '/static/templates', | |
| 238 | 320 | ]; |
| 239 | 321 | |
| 240 | 322 | $isMigratingToV2 = get_option('bitforms_migrating_to_v2', false); |
| 241 | 323 | if ($isMigratingToV2) { |
| @@ -269,8 +351,19 @@ | ||
| 269 | 351 | // if (\function_exists('wp_set_script_translations')) |
| 270 | 352 | // wp_set_script_translations('bitforms-admin-script', 'bitform', BITFORMS_PLUGIN_DIR_PATH . 'languages'); |
| 271 | 353 | } |
| 272 | 354 | |
| 355 | + public function bitforms_enqueue_admin_styles() | |
| 356 | + { | |
| 357 | + wp_enqueue_style( | |
| 358 | + 'bitforms-admin-styles', | |
| 359 | + BITFORMS_ROOT_URI . '/resources/admin.css', | |
| 360 | + [], | |
| 361 | + BITFORMS_VERSION, | |
| 362 | + 'all' | |
| 363 | + ); | |
| 364 | + } | |
| 365 | + | |
| 273 | 366 | /** |
| 274 | 367 | * Bitforms apps-root id provider |
| 275 | 368 | * @return void |
| 276 | 369 | */ |
| @@ -328,6 +421,13 @@ | ||
| 328 | 421 | if (preg_match('/BITFORM-MODULE/', $handle)) { |
| 329 | 422 | $newTag = preg_replace('/<script /', '<script type="module" ', $newTag); |
| 330 | 423 | } |
| 331 | 424 | return $newTag; |
| 425 | + } | |
| 426 | + | |
| 427 | + private static function countUnreadEntries() | |
| 428 | + { | |
| 429 | + global $wpdb; | |
| 430 | + $unreadEntries = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}bitforms_form_entries WHERE status = 1"); | |
| 431 | + return $unreadEntries; | |
| 332 | 432 | } |
| 333 | 433 | } |