| @@ -18,8 +18,9 @@ | ||
| 18 | 18 | $cap = self::get_required_capability(); |
| 19 | 19 | |
| 20 | 20 | if ( ! current_user_can( $cap ) && is_callable( 'FrmProApplicationsHelper::get_custom_applications_capability' ) ) { |
| 21 | 21 | $custom_applications_cap = FrmProApplicationsHelper::get_custom_applications_capability(); |
| 22 | + | |
| 22 | 23 | if ( current_user_can( $custom_applications_cap ) ) { |
| 23 | 24 | $cap = $custom_applications_cap; |
| 24 | 25 | $slug = 'edit-tags.php?taxonomy=frm_application'; |
| 25 | 26 | $callback = ''; |
| @@ -77,16 +78,16 @@ | ||
| 77 | 78 | |
| 78 | 79 | $view = FrmAppHelper::get_param( 'view', '', 'get', 'sanitize_text_field' ); |
| 79 | 80 | $data = array(); |
| 80 | 81 | |
| 81 | - if ( 'applications' !== $view ) { | |
| 82 | + if ( 'applications' === $view ) { | |
| 83 | + FrmAppHelper::permission_check( 'frm_edit_applications' ); | |
| 84 | + } else { | |
| 82 | 85 | FrmAppHelper::permission_check( self::get_required_capability() ); |
| 83 | 86 | |
| 84 | - // view may be 'applications', 'templates', or empty. | |
| 87 | + // View may be 'applications', 'templates', or empty. | |
| 85 | 88 | $data['templates'] = self::get_prepared_template_data(); |
| 86 | 89 | $data['categories'] = FrmApplicationTemplate::get_categories(); |
| 87 | - } else { | |
| 88 | - FrmAppHelper::permission_check( 'frm_edit_applications' ); | |
| 89 | 90 | } |
| 90 | 91 | |
| 91 | 92 | /** |
| 92 | 93 | * @param array $data |
| @@ -101,14 +102,14 @@ | ||
| 101 | 102 | * |
| 102 | 103 | * @return array<array> |
| 103 | 104 | */ |
| 104 | 105 | private static function get_prepared_template_data() { |
| 105 | - $api = new FrmApplicationApi(); | |
| 106 | - $applications = $api->get_api_info(); | |
| 107 | - $applications = array_filter( $applications, 'is_array' ); | |
| 108 | - | |
| 106 | + $api = new FrmApplicationApi(); | |
| 107 | + $applications = $api->get_api_info(); | |
| 108 | + $applications = array_filter( $applications, 'is_array' ); | |
| 109 | 109 | $unlocked_templates = array(); |
| 110 | 110 | $locked_templates = array(); |
| 111 | + | |
| 111 | 112 | foreach ( $applications as $key => $application ) { |
| 112 | 113 | if ( ! is_numeric( $key ) ) { |
| 113 | 114 | // Skip "error" or any other non-numeric key. |
| 114 | 115 | continue; |
| @@ -121,10 +122,10 @@ | ||
| 121 | 122 | } |
| 122 | 123 | } |
| 123 | 124 | |
| 124 | 125 | $unlocked_templates = self::sort_templates( $unlocked_templates ); |
| 126 | + $applications = $unlocked_templates; | |
| 125 | 127 | |
| 126 | - $applications = $unlocked_templates; | |
| 127 | 128 | if ( current_user_can( 'administrator' ) || current_user_can( 'frm_change_settings' ) ) { |
| 128 | 129 | $locked_templates = self::sort_templates( $locked_templates ); |
| 129 | 130 | $applications = array_merge( $applications, $locked_templates ); |
| 130 | 131 | } |
| @@ -136,14 +137,15 @@ | ||
| 136 | 137 | |
| 137 | 138 | /** |
| 138 | 139 | * @param array $total the accumulated array of reduced application data. |
| 139 | 140 | * @param array $current data for the current template from the API. |
| 141 | + * | |
| 140 | 142 | * @return array<array> |
| 141 | 143 | */ |
| 142 | 144 | private static function reduce_template( $total, $current ) { |
| 143 | - $template = new FrmApplicationTemplate( $current ); | |
| 145 | + $template = new FrmApplicationTemplate( $current ); | |
| 146 | + $js_object = $template->as_js_object(); | |
| 144 | 147 | |
| 145 | - $js_object = $template->as_js_object(); | |
| 146 | 148 | if ( $js_object ) { |
| 147 | 149 | $total[] = $js_object; |
| 148 | 150 | } |
| 149 | 151 | |
| @@ -153,8 +155,9 @@ | ||
| 153 | 155 | /** |
| 154 | 156 | * Sort applications alphabetically. |
| 155 | 157 | * |
| 156 | 158 | * @param array<array> $applications |
| 159 | + * | |
| 157 | 160 | * @return array<array> |
| 158 | 161 | */ |
| 159 | 162 | private static function sort_templates( $applications ) { |
| 160 | 163 | usort( |
| @@ -219,8 +222,9 @@ | ||
| 219 | 222 | |
| 220 | 223 | /** |
| 221 | 224 | * @param string $title |
| 222 | 225 | * @param string $context values include 'index', 'list', and 'edit'. |
| 226 | + * | |
| 223 | 227 | * @return void |
| 224 | 228 | */ |
| 225 | 229 | public static function render_applications_header( $title, $context ) { |
| 226 | 230 | FrmAppHelper::print_admin_banner( true ); |