| @@ -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,25 +130,19 @@ | ||
| 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 ); | |
| 146 | - $js_object = $template->as_js_object(); | |
| 147 | - | |
| 148 | - if ( $js_object ) { | |
| 149 | - $total[] = $js_object; | |
| 150 | - } | |
| 151 | - | |
| 143 | + $template = new FrmApplicationTemplate( $current ); | |
| 144 | + $total[] = $template->as_js_object(); | |
| 152 | 145 | return $total; |
| 153 | 146 | } |
| 154 | 147 | |
| 155 | 148 | /** |
| @@ -155,15 +148,14 @@ | ||
| 155 | 148 | /** |
| 156 | 149 | * Sort applications alphabetically. |
| 157 | 150 | * |
| 158 | 151 | * @param array<array> $applications |
| 159 | - * | |
| 160 | 152 | * @return array<array> |
| 161 | 153 | */ |
| 162 | 154 | private static function sort_templates( $applications ) { |
| 163 | 155 | usort( |
| 164 | 156 | $applications, |
| 165 | - function ( $a, $b ) { | |
| 157 | + function( $a, $b ) { | |
| 166 | 158 | return strcmp( $a['name'], $b['name'] ); |
| 167 | 159 | } |
| 168 | 160 | ); |
| 169 | 161 | return $applications; |
| @@ -169,21 +161,10 @@ | ||
| 169 | 161 | return $applications; |
| 170 | 162 | } |
| 171 | 163 | |
| 172 | 164 | /** |
| 173 | - * @usedby FrmAppController::admin_init(). | |
| 174 | - * | |
| 175 | - * @since 6.8 | |
| 176 | - * | |
| 177 | 165 | * @return void |
| 178 | 166 | */ |
| 179 | - public static function load_page() { | |
| 180 | - self::load_assets(); | |
| 181 | - } | |
| 182 | - | |
| 183 | - /** | |
| 184 | - * @return void | |
| 185 | - */ | |
| 186 | 167 | public static function load_assets() { |
| 187 | 168 | $plugin_url = FrmAppHelper::plugin_url(); |
| 188 | 169 | $version = FrmAppHelper::plugin_version(); |
| 189 | 170 | |
| @@ -191,10 +172,9 @@ | ||
| 191 | 172 | wp_enqueue_style( 'formidable-grids' ); |
| 192 | 173 | |
| 193 | 174 | $js_dependencies = array( |
| 194 | 175 | 'wp-i18n', |
| 195 | - // This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7. | |
| 196 | - 'wp-hooks', | |
| 176 | + 'wp-hooks', // This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7. | |
| 197 | 177 | 'formidable_dom', |
| 198 | 178 | ); |
| 199 | 179 | wp_register_script( 'formidable_applications', $plugin_url . '/js/admin/applications.js', $js_dependencies, $version, true ); |
| 200 | 180 | wp_register_style( 'formidable_applications', $plugin_url . '/css/admin/applications.css', array(), $version ); |
| @@ -204,9 +184,8 @@ | ||
| 204 | 184 | ); |
| 205 | 185 | wp_localize_script( 'formidable_applications', 'frmApplicationsVars', $js_vars ); |
| 206 | 186 | |
| 207 | 187 | wp_enqueue_script( 'formidable_applications' ); |
| 208 | - wp_set_script_translations( 'formidable_applications', 'formidable' ); | |
| 209 | 188 | wp_enqueue_style( 'formidable_applications' ); |
| 210 | 189 | |
| 211 | 190 | do_action( 'frm_applications_assets' ); |
| 212 | 191 | } |
| @@ -215,9 +194,11 @@ | ||
| 215 | 194 | * @return void |
| 216 | 195 | */ |
| 217 | 196 | public static function dequeue_scripts() { |
| 218 | 197 | if ( 'formidable-applications' === FrmAppHelper::simple_get( 'page', 'sanitize_title' ) ) { |
| 219 | - FrmAppHelper::dequeue_extra_global_scripts(); | |
| 198 | + // Avoid extra scripts loading on applications index that aren't needed. | |
| 199 | + wp_dequeue_script( 'frm-surveys-admin' ); | |
| 200 | + wp_dequeue_script( 'frm-quizzes-form-action' ); | |
| 220 | 201 | } |
| 221 | 202 | } |
| 222 | 203 | |
| 223 | 204 | /** |
| @@ -222,9 +203,8 @@ | ||
| 222 | 203 | |
| 223 | 204 | /** |
| 224 | 205 | * @param string $title |
| 225 | 206 | * @param string $context values include 'index', 'list', and 'edit'. |
| 226 | - * | |
| 227 | 207 | * @return void |
| 228 | 208 | */ |
| 229 | 209 | public static function render_applications_header( $title, $context ) { |
| 230 | 210 | FrmAppHelper::print_admin_banner( true ); |