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