| @@ -13,14 +13,14 @@ | ||
| 13 | 13 | * |
| 14 | 14 | * @return void |
| 15 | 15 | */ |
| 16 | 16 | public static function menu() { |
| 17 | - $label = __( 'Applications', 'formidable' ); | |
| 18 | - $cap = self::get_required_capability(); | |
| 17 | + $label = __( 'Applications', 'formidable' ); | |
| 18 | + $new_pill = '<span class="frm-new-pill">NEW</span>'; | |
| 19 | + $cap = self::get_required_capability(); | |
| 19 | 20 | |
| 20 | 21 | if ( ! current_user_can( $cap ) && is_callable( 'FrmProApplicationsHelper::get_custom_applications_capability' ) ) { |
| 21 | 22 | $custom_applications_cap = FrmProApplicationsHelper::get_custom_applications_capability(); |
| 22 | - | |
| 23 | 23 | if ( current_user_can( $custom_applications_cap ) ) { |
| 24 | 24 | $cap = $custom_applications_cap; |
| 25 | 25 | $slug = 'edit-tags.php?taxonomy=frm_application'; |
| 26 | 26 | $callback = ''; |
| @@ -28,12 +28,12 @@ | ||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | if ( ! isset( $slug ) ) { |
| 31 | 31 | $slug = 'formidable-applications'; |
| 32 | - $callback = array( self::class, 'landing_page' ); | |
| 32 | + $callback = array( __CLASS__, 'landing_page' ); | |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - add_submenu_page( 'formidable', 'Formidable | ' . $label, $label, $cap, $slug, $callback ); | |
| 35 | + add_submenu_page( 'formidable', 'Formidable | ' . $label, $label . $new_pill, $cap, $slug, $callback ); | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Get the required capability for accessing the Applications dashboard. |
| @@ -72,11 +72,8 @@ | ||
| 72 | 72 | * |
| 73 | 73 | * @return void |
| 74 | 74 | */ |
| 75 | 75 | public static function get_applications_data() { |
| 76 | - FrmAppHelper::permission_check( 'frm_view_forms' ); | |
| 77 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 78 | - | |
| 79 | 76 | $view = FrmAppHelper::get_param( 'view', '', 'get', 'sanitize_text_field' ); |
| 80 | 77 | $data = array(); |
| 81 | 78 | |
| 82 | 79 | if ( 'applications' !== $view ) { |
| @@ -108,9 +105,8 @@ | ||
| 108 | 105 | $applications = array_filter( $applications, 'is_array' ); |
| 109 | 106 | |
| 110 | 107 | $unlocked_templates = array(); |
| 111 | 108 | $locked_templates = array(); |
| 112 | - | |
| 113 | 109 | foreach ( $applications as $key => $application ) { |
| 114 | 110 | if ( ! is_numeric( $key ) ) { |
| 115 | 111 | // Skip "error" or any other non-numeric key. |
| 116 | 112 | continue; |
| @@ -125,9 +121,8 @@ | ||
| 125 | 121 | |
| 126 | 122 | $unlocked_templates = self::sort_templates( $unlocked_templates ); |
| 127 | 123 | |
| 128 | 124 | $applications = $unlocked_templates; |
| 129 | - | |
| 130 | 125 | if ( current_user_can( 'administrator' ) || current_user_can( 'frm_change_settings' ) ) { |
| 131 | 126 | $locked_templates = self::sort_templates( $locked_templates ); |
| 132 | 127 | $applications = array_merge( $applications, $locked_templates ); |
| 133 | 128 | } |
| @@ -133,26 +128,19 @@ | ||
| 133 | 128 | } |
| 134 | 129 | |
| 135 | 130 | FrmApplicationTemplate::init(); |
| 136 | 131 | |
| 137 | - return array_reduce( $applications, array( self::class, 'reduce_template' ), array() ); | |
| 132 | + return array_reduce( $applications, array( __CLASS__, 'reduce_template' ), array() ); | |
| 138 | 133 | } |
| 139 | 134 | |
| 140 | 135 | /** |
| 141 | 136 | * @param array $total the accumulated array of reduced application data. |
| 142 | 137 | * @param array $current data for the current template from the API. |
| 143 | - * | |
| 144 | 138 | * @return array<array> |
| 145 | 139 | */ |
| 146 | 140 | private static function reduce_template( $total, $current ) { |
| 147 | 141 | $template = new FrmApplicationTemplate( $current ); |
| 148 | - | |
| 149 | - $js_object = $template->as_js_object(); | |
| 150 | - | |
| 151 | - if ( $js_object ) { | |
| 152 | - $total[] = $js_object; | |
| 153 | - } | |
| 154 | - | |
| 142 | + $total[] = $template->as_js_object(); | |
| 155 | 143 | return $total; |
| 156 | 144 | } |
| 157 | 145 | |
| 158 | 146 | /** |
| @@ -158,15 +146,14 @@ | ||
| 158 | 146 | /** |
| 159 | 147 | * Sort applications alphabetically. |
| 160 | 148 | * |
| 161 | 149 | * @param array<array> $applications |
| 162 | - * | |
| 163 | 150 | * @return array<array> |
| 164 | 151 | */ |
| 165 | 152 | private static function sort_templates( $applications ) { |
| 166 | 153 | usort( |
| 167 | 154 | $applications, |
| 168 | - function ( $a, $b ) { | |
| 155 | + function( $a, $b ) { | |
| 169 | 156 | return strcmp( $a['name'], $b['name'] ); |
| 170 | 157 | } |
| 171 | 158 | ); |
| 172 | 159 | return $applications; |
| @@ -172,21 +159,10 @@ | ||
| 172 | 159 | return $applications; |
| 173 | 160 | } |
| 174 | 161 | |
| 175 | 162 | /** |
| 176 | - * @usedby FrmAppController::admin_init(). | |
| 177 | - * | |
| 178 | - * @since 6.8 | |
| 179 | - * | |
| 180 | 163 | * @return void |
| 181 | 164 | */ |
| 182 | - public static function load_page() { | |
| 183 | - self::load_assets(); | |
| 184 | - } | |
| 185 | - | |
| 186 | - /** | |
| 187 | - * @return void | |
| 188 | - */ | |
| 189 | 165 | public static function load_assets() { |
| 190 | 166 | $plugin_url = FrmAppHelper::plugin_url(); |
| 191 | 167 | $version = FrmAppHelper::plugin_version(); |
| 192 | 168 | |
| @@ -194,10 +170,9 @@ | ||
| 194 | 170 | wp_enqueue_style( 'formidable-grids' ); |
| 195 | 171 | |
| 196 | 172 | $js_dependencies = array( |
| 197 | 173 | 'wp-i18n', |
| 198 | - // This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7. | |
| 199 | - 'wp-hooks', | |
| 174 | + 'wp-hooks', // This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7. | |
| 200 | 175 | 'formidable_dom', |
| 201 | 176 | ); |
| 202 | 177 | wp_register_script( 'formidable_applications', $plugin_url . '/js/admin/applications.js', $js_dependencies, $version, true ); |
| 203 | 178 | wp_register_style( 'formidable_applications', $plugin_url . '/css/admin/applications.css', array(), $version ); |
| @@ -207,9 +182,8 @@ | ||
| 207 | 182 | ); |
| 208 | 183 | wp_localize_script( 'formidable_applications', 'frmApplicationsVars', $js_vars ); |
| 209 | 184 | |
| 210 | 185 | wp_enqueue_script( 'formidable_applications' ); |
| 211 | - wp_set_script_translations( 'formidable_applications', 'formidable' ); | |
| 212 | 186 | wp_enqueue_style( 'formidable_applications' ); |
| 213 | 187 | |
| 214 | 188 | do_action( 'frm_applications_assets' ); |
| 215 | 189 | } |
| @@ -218,9 +192,11 @@ | ||
| 218 | 192 | * @return void |
| 219 | 193 | */ |
| 220 | 194 | public static function dequeue_scripts() { |
| 221 | 195 | if ( 'formidable-applications' === FrmAppHelper::simple_get( 'page', 'sanitize_title' ) ) { |
| 222 | - FrmAppHelper::dequeue_extra_global_scripts(); | |
| 196 | + // Avoid extra scripts loading on applications index that aren't needed. | |
| 197 | + wp_dequeue_script( 'frm-surveys-admin' ); | |
| 198 | + wp_dequeue_script( 'frm-quizzes-form-action' ); | |
| 223 | 199 | } |
| 224 | 200 | } |
| 225 | 201 | |
| 226 | 202 | /** |
| @@ -225,9 +201,8 @@ | ||
| 225 | 201 | |
| 226 | 202 | /** |
| 227 | 203 | * @param string $title |
| 228 | 204 | * @param string $context values include 'index', 'list', and 'edit'. |
| 229 | - * | |
| 230 | 205 | * @return void |
| 231 | 206 | */ |
| 232 | 207 | public static function render_applications_header( $title, $context ) { |
| 233 | 208 | FrmAppHelper::print_admin_banner( true ); |