| @@ -13,43 +13,14 @@ | ||
| 13 | 13 | * |
| 14 | 14 | * @return void |
| 15 | 15 | */ |
| 16 | 16 | public static function menu() { |
| 17 | - $label = __( 'Applications', 'formidable' ); | |
| 18 | - $cap = self::get_required_capability(); | |
| 19 | - | |
| 20 | - if ( ! current_user_can( $cap ) && is_callable( 'FrmProApplicationsHelper::get_custom_applications_capability' ) ) { | |
| 21 | - $custom_applications_cap = FrmProApplicationsHelper::get_custom_applications_capability(); | |
| 22 | - if ( current_user_can( $custom_applications_cap ) ) { | |
| 23 | - $cap = $custom_applications_cap; | |
| 24 | - $slug = 'edit-tags.php?taxonomy=frm_application'; | |
| 25 | - $callback = ''; | |
| 26 | - } | |
| 27 | - } | |
| 28 | - | |
| 29 | - if ( ! isset( $slug ) ) { | |
| 30 | - $slug = 'formidable-applications'; | |
| 31 | - $callback = array( __CLASS__, 'landing_page' ); | |
| 32 | - } | |
| 33 | - | |
| 34 | - add_submenu_page( 'formidable', 'Formidable | ' . $label, $label, $cap, $slug, $callback ); | |
| 17 | + $label = __( 'Applications', 'formidable' ); | |
| 18 | + $new_pill = '<span class="frm-new-pill">NEW</span>'; | |
| 19 | + add_submenu_page( 'formidable', 'Formidable | ' . $label, $label . $new_pill, 'frm_edit_forms', 'formidable-applications', array( __CLASS__, 'landing_page' ) ); | |
| 35 | 20 | } |
| 36 | 21 | |
| 37 | 22 | /** |
| 38 | - * Get the required capability for accessing the Applications dashboard. | |
| 39 | - * | |
| 40 | - * @since 5.3.1 | |
| 41 | - * | |
| 42 | - * @return string | |
| 43 | - */ | |
| 44 | - private static function get_required_capability() { | |
| 45 | - if ( is_callable( 'FrmProApplicationsHelper::get_required_templates_capability' ) ) { | |
| 46 | - return FrmProApplicationsHelper::get_required_templates_capability(); | |
| 47 | - } | |
| 48 | - return 'frm_edit_forms'; | |
| 49 | - } | |
| 50 | - | |
| 51 | - /** | |
| 52 | 23 | * Render Applications index page. |
| 53 | 24 | * |
| 54 | 25 | * @return void |
| 55 | 26 | */ |
| @@ -71,22 +42,16 @@ | ||
| 71 | 42 | * |
| 72 | 43 | * @return void |
| 73 | 44 | */ |
| 74 | 45 | public static function get_applications_data() { |
| 75 | - FrmAppHelper::permission_check( 'frm_view_forms' ); | |
| 76 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 46 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 77 | 47 | |
| 78 | 48 | $view = FrmAppHelper::get_param( 'view', '', 'get', 'sanitize_text_field' ); |
| 79 | 49 | $data = array(); |
| 80 | - | |
| 81 | 50 | if ( 'applications' !== $view ) { |
| 82 | - FrmAppHelper::permission_check( self::get_required_capability() ); | |
| 83 | - | |
| 84 | 51 | // view may be 'applications', 'templates', or empty. |
| 85 | 52 | $data['templates'] = self::get_prepared_template_data(); |
| 86 | 53 | $data['categories'] = FrmApplicationTemplate::get_categories(); |
| 87 | - } else { | |
| 88 | - FrmAppHelper::permission_check( 'frm_edit_applications' ); | |
| 89 | 54 | } |
| 90 | 55 | |
| 91 | 56 | /** |
| 92 | 57 | * @param array $data |
| @@ -104,32 +69,10 @@ | ||
| 104 | 69 | private static function get_prepared_template_data() { |
| 105 | 70 | $api = new FrmApplicationApi(); |
| 106 | 71 | $applications = $api->get_api_info(); |
| 107 | 72 | $applications = array_filter( $applications, 'is_array' ); |
| 73 | + $applications = self::sort_templates( $applications ); | |
| 108 | 74 | |
| 109 | - $unlocked_templates = array(); | |
| 110 | - $locked_templates = array(); | |
| 111 | - foreach ( $applications as $key => $application ) { | |
| 112 | - if ( ! is_numeric( $key ) ) { | |
| 113 | - // Skip "error" or any other non-numeric key. | |
| 114 | - continue; | |
| 115 | - } | |
| 116 | - | |
| 117 | - if ( ! empty( $application['url'] ) ) { | |
| 118 | - $unlocked_templates[] = $application; | |
| 119 | - } else { | |
| 120 | - $locked_templates[] = $application; | |
| 121 | - } | |
| 122 | - } | |
| 123 | - | |
| 124 | - $unlocked_templates = self::sort_templates( $unlocked_templates ); | |
| 125 | - | |
| 126 | - $applications = $unlocked_templates; | |
| 127 | - if ( current_user_can( 'administrator' ) || current_user_can( 'frm_change_settings' ) ) { | |
| 128 | - $locked_templates = self::sort_templates( $locked_templates ); | |
| 129 | - $applications = array_merge( $applications, $locked_templates ); | |
| 130 | - } | |
| 131 | - | |
| 132 | 75 | FrmApplicationTemplate::init(); |
| 133 | 76 | |
| 134 | 77 | return array_reduce( $applications, array( __CLASS__, 'reduce_template' ), array() ); |
| 135 | 78 | } |
| @@ -172,9 +115,8 @@ | ||
| 172 | 115 | wp_enqueue_style( 'formidable-grids' ); |
| 173 | 116 | |
| 174 | 117 | $js_dependencies = array( |
| 175 | 118 | 'wp-i18n', |
| 176 | - 'wp-hooks', // This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7. | |
| 177 | 119 | 'formidable_dom', |
| 178 | 120 | ); |
| 179 | 121 | wp_register_script( 'formidable_applications', $plugin_url . '/js/admin/applications.js', $js_dependencies, $version, true ); |
| 180 | 122 | wp_register_style( 'formidable_applications', $plugin_url . '/css/admin/applications.css', array(), $version ); |
| @@ -206,8 +148,7 @@ | ||
| 206 | 148 | * @param string $context values include 'index', 'list', and 'edit'. |
| 207 | 149 | * @return void |
| 208 | 150 | */ |
| 209 | 151 | public static function render_applications_header( $title, $context ) { |
| 210 | - FrmAppHelper::print_admin_banner( true ); | |
| 211 | 152 | require self::get_view_path() . 'header.php'; |
| 212 | 153 | } |
| 213 | 154 | } |