| @@ -78,16 +78,16 @@ | ||
| 78 | 78 | |
| 79 | 79 | $view = FrmAppHelper::get_param( 'view', '', 'get', 'sanitize_text_field' ); |
| 80 | 80 | $data = array(); |
| 81 | 81 | |
| 82 | - if ( 'applications' !== $view ) { | |
| 82 | + if ( 'applications' === $view ) { | |
| 83 | + FrmAppHelper::permission_check( 'frm_edit_applications' ); | |
| 84 | + } else { | |
| 83 | 85 | FrmAppHelper::permission_check( self::get_required_capability() ); |
| 84 | 86 | |
| 85 | - // view may be 'applications', 'templates', or empty. | |
| 87 | + // View may be 'applications', 'templates', or empty. | |
| 86 | 88 | $data['templates'] = self::get_prepared_template_data(); |
| 87 | 89 | $data['categories'] = FrmApplicationTemplate::get_categories(); |
| 88 | - } else { | |
| 89 | - FrmAppHelper::permission_check( 'frm_edit_applications' ); | |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
| 93 | 93 | * @param array $data |
| @@ -102,12 +102,11 @@ | ||
| 102 | 102 | * |
| 103 | 103 | * @return array<array> |
| 104 | 104 | */ |
| 105 | 105 | private static function get_prepared_template_data() { |
| 106 | - $api = new FrmApplicationApi(); | |
| 107 | - $applications = $api->get_api_info(); | |
| 108 | - $applications = array_filter( $applications, 'is_array' ); | |
| 109 | - | |
| 106 | + $api = new FrmApplicationApi(); | |
| 107 | + $applications = $api->get_api_info(); | |
| 108 | + $applications = array_filter( $applications, 'is_array' ); | |
| 110 | 109 | $unlocked_templates = array(); |
| 111 | 110 | $locked_templates = array(); |
| 112 | 111 | |
| 113 | 112 | foreach ( $applications as $key => $application ) { |
| @@ -123,11 +122,10 @@ | ||
| 123 | 122 | } |
| 124 | 123 | } |
| 125 | 124 | |
| 126 | 125 | $unlocked_templates = self::sort_templates( $unlocked_templates ); |
| 126 | + $applications = $unlocked_templates; | |
| 127 | 127 | |
| 128 | - $applications = $unlocked_templates; | |
| 129 | - | |
| 130 | 128 | if ( current_user_can( 'administrator' ) || current_user_can( 'frm_change_settings' ) ) { |
| 131 | 129 | $locked_templates = self::sort_templates( $locked_templates ); |
| 132 | 130 | $applications = array_merge( $applications, $locked_templates ); |
| 133 | 131 | } |
| @@ -143,10 +141,9 @@ | ||
| 143 | 141 | * |
| 144 | 142 | * @return array<array> |
| 145 | 143 | */ |
| 146 | 144 | private static function reduce_template( $total, $current ) { |
| 147 | - $template = new FrmApplicationTemplate( $current ); | |
| 148 | - | |
| 145 | + $template = new FrmApplicationTemplate( $current ); | |
| 149 | 146 | $js_object = $template->as_js_object(); |
| 150 | 147 | |
| 151 | 148 | if ( $js_object ) { |
| 152 | 149 | $total[] = $js_object; |