*/ private static function get_prepared_template_data() { $api = new FrmApplicationApi(); $applications = $api->get_api_info(); $applications = array_filter( $applications, 'is_array' ); $unlocked_templates = array(); $locked_templates = array(); foreach ( $applications as $key => $application ) { if ( ! is_numeric( $key ) ) { // Skip "error" or any other non-numeric key. continue; } if ( ! empty( $application['url'] ) ) { $unlocked_templates[] = $application; } else { $locked_templates[] = $application; } } $unlocked_templates = self::sort_templates( $unlocked_templates ); $applications = $unlocked_templates; if ( current_user_can( 'administrator' ) || current_user_can( 'frm_change_settings' ) ) { $locked_templates = self::sort_templates( $locked_templates ); $applications = array_merge( $applications, $locked_templates ); } FrmApplicationTemplate::init(); return array_reduce( $applications, array( __CLASS__, 'reduce_template' ), array() ); } /** * @param array $total the accumulated array of reduced application data. * @param array $current data for the current template from the API. * @return array */ private static function reduce_template( $total, $current ) { $template = new FrmApplicationTemplate( $current ); $total[] = $template->as_js_object(); return $total; } /** * Sort applications alphabetically. * * @param array $applications * @return array */ private static function sort_templates( $applications ) { usort( $applications, function( $a, $b ) { return strcmp( $a['name'], $b['name'] ); } ); return $applications; } /** * @usedby FrmAppController::admin_init(). * * @since 6.8 * * @return void */ public static function load_page() { self::load_assets(); } /** * @return void */ public static function load_assets() { $plugin_url = FrmAppHelper::plugin_url(); $version = FrmAppHelper::plugin_version(); wp_enqueue_style( 'formidable-admin' ); wp_enqueue_style( 'formidable-grids' ); $js_dependencies = array( 'wp-i18n', // This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7. 'wp-hooks', 'formidable_dom', ); wp_register_script( 'formidable_applications', $plugin_url . '/js/admin/applications.js', $js_dependencies, $version, true ); wp_register_style( 'formidable_applications', $plugin_url . '/css/admin/applications.css', array(), $version ); $js_vars = array( 'proUpgradeUrl' => FrmAppHelper::admin_upgrade_link( 'applications' ), ); wp_localize_script( 'formidable_applications', 'frmApplicationsVars', $js_vars ); wp_enqueue_script( 'formidable_applications' ); wp_enqueue_style( 'formidable_applications' ); do_action( 'frm_applications_assets' ); } /** * @return void */ public static function dequeue_scripts() { if ( 'formidable-applications' === FrmAppHelper::simple_get( 'page', 'sanitize_title' ) ) { // Avoid extra scripts loading on applications index that aren't needed. wp_dequeue_script( 'frm-surveys-admin' ); wp_dequeue_script( 'frm-quizzes-form-action' ); } } /** * @param string $title * @param string $context values include 'index', 'list', and 'edit'. * @return void */ public static function render_applications_header( $title, $context ) { FrmAppHelper::print_admin_banner( true ); require self::get_view_path() . 'header.php'; } }