Variables exposed to the template. */ protected function data(): array { $tab = $this->current_tab(); return array( 'page_title' => $this->page_title(), 'tabs' => SettingsRegistry::tabs(), 'current_tab' => $tab, 'option_group' => self::OPTION_GROUP, 'option_name' => Settings::OPTION, 'tab_marker' => SettingsRegistry::TAB_MARKER, 'section_page' => SettingsRegistry::page( $tab ), 'tab_base_url' => $this->url(), 'transfer' => $this->transfer(), 'notice' => $this->notice(), ); } /** * Returns what the import and export controls need. * * @return array Endpoint, actions and their nonces. */ private function transfer(): array { return array( 'url' => admin_url( 'admin-post.php' ), 'export_action' => SettingsTransfer::EXPORT_ACTION, 'import_action' => SettingsTransfer::IMPORT_ACTION, 'export_nonce' => wp_create_nonce( SettingsTransfer::EXPORT_ACTION ), 'import_nonce' => wp_create_nonce( SettingsTransfer::IMPORT_ACTION ), ); } /** * Builds the notice shown after an import. * * @return array{type: string, text: string}|null The notice, or null when there is nothing to report. */ private function notice(): ?array { $message = Request::key( 'formpilot_message' ); if ( '' === $message ) { return null; } $count = max( 0, Request::int( 'formpilot_count' ) ); return match ( $message ) { 'imported' => array( 'type' => 'success', 'text' => 0 === $count ? __( 'The file was read and every setting already matched it.', 'devplugins-custom-form-builder' ) : sprintf( /* translators: %s: Number of settings. */ _n( '%s setting was imported.', '%s settings were imported.', $count, 'devplugins-custom-form-builder' ), number_format_i18n( $count ) ), ), 'import_missing' => array( 'type' => 'error', 'text' => __( 'Choose a file to import.', 'devplugins-custom-form-builder' ), ), 'import_large' => array( 'type' => 'error', 'text' => __( 'That file is too large to be a settings export.', 'devplugins-custom-form-builder' ), ), 'import_unreadable' => array( 'type' => 'error', 'text' => __( 'That file could not be read as JSON.', 'devplugins-custom-form-builder' ), ), 'import_foreign' => array( 'type' => 'error', 'text' => __( 'That file is not a FormPilot — Smart Form Builder settings export.', 'devplugins-custom-form-builder' ), ), default => null, }; } /** * Returns the tab being displayed. */ private function current_tab(): string { $tab = Request::key( 'tab' ); $tabs = SettingsRegistry::tabs(); if ( '' !== $tab && array_key_exists( $tab, $tabs ) ) { return $tab; } // A tab that has since been folded into another one. $moved = SettingsRegistry::moved_tabs(); if ( isset( $moved[ $tab ] ) && array_key_exists( $moved[ $tab ], $tabs ) ) { return $moved[ $tab ]; } return (string) array_key_first( $tabs ); } }