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