statuses = new StatusesTab(); } public function register(): void { add_action( 'admin_menu', array( $this, 'menu' ), 20 ); add_action( 'admin_init', array( $this, 'register_setting' ) ); add_filter( 'option_page_capability_' . self::GROUP, array( $this, 'capability' ) ); $this->statuses->register(); } /** * Current tab: '' (general and forms) or StatusesTab::TAB. */ private function current_tab(): string { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only tab switch. $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : ''; return StatusesTab::TAB === $tab ? $tab : ''; } private function render_tabs( string $current ): void { $tabs = array( '' => __( 'General and forms', 'action-receipts' ), StatusesTab::TAB => __( 'Statuses', 'action-receipts' ), ); echo ''; } public function capability(): string { return Installer::CAP; } public function menu(): void { add_submenu_page( Admin::PAGE, __( 'Receipt settings', 'action-receipts' ), __( 'Settings', 'action-receipts' ), Installer::CAP, self::PAGE, array( $this, 'render' ) ); } public function register_setting(): void { register_setting( self::GROUP, Settings::OPTION, array( 'type' => 'array', 'sanitize_callback' => array( $this, 'sanitize' ), 'show_in_rest' => false, ) ); } /** * @param mixed $input Raw posted settings. */ public function sanitize( $input ): array { $input = is_array( $input ) ? $input : array(); $current = Settings::get(); $out = Settings::defaults(); $out['status_page_id'] = absint( $input['status_page_id'] ?? 0 ); $out['retention_days'] = min( 3650, absint( $input['retention_days'] ?? 0 ) ); $out['delete_on_uninstall'] = ! empty( $input['delete_on_uninstall'] ); // Keep settings of forms not on screen (e.g. their form plugin is deactivated). $out['forms'] = is_array( $current['forms'] ) ? $current['forms'] : array(); $forms = isset( $input['forms'] ) && is_array( $input['forms'] ) ? $input['forms'] : array(); foreach ( $forms as $key => $form ) { $key = (string) $key; if ( ! Settings::is_valid_form_key( $key ) || ! is_array( $form ) ) { continue; } if ( isset( $form['fields_shown'] ) ) { // The field list was on screen: store exactly what was ticked. $fields = isset( $form['fields'] ) && is_array( $form['fields'] ) ? $form['fields'] : array(); } elseif ( array_key_exists( 'fields', $form ) ) { // Already-sanitised settings passed through again (e.g. by add_option). $fields = $form['fields']; } else { $fields = $current['forms'][ $key ]['fields'] ?? null; } if ( is_array( $fields ) ) { $fields = array_values( array_map( 'sanitize_text_field', $fields ) ); } else { $fields = null; } $pattern = sanitize_text_field( $form['pattern'] ?? '' ); if ( '' === $pattern || ( false === strpos( $pattern, '{SEQ' ) && false === strpos( $pattern, '{RAND' ) ) ) { $pattern = ReferenceGenerator::DEFAULT_PATTERN; } $out['forms'][ $key ] = array( 'enabled' => ! empty( $form['enabled'] ), 'prefix' => ReferenceGenerator::clean_prefix( (string) ( $form['prefix'] ?? '' ) ), 'pattern' => substr( $pattern, 0, 64 ), 'fields' => $fields, 'email_field' => sanitize_text_field( $form['email_field'] ?? '' ), 'show_in_message' => ! empty( $form['show_in_message'] ), 'send_confirmation' => ! empty( $form['send_confirmation'] ), ); } return $out; } public function render(): void { if ( ! current_user_can( Installer::CAP ) ) { wp_die( esc_html__( 'You do not have permission to change these settings.', 'action-receipts' ) ); } $tab = $this->current_tab(); ?>
|
' . esc_html( self::example_reference( $cfg ) ) . '' ); ?> |
|
| key(), $form_id ) ) : ?> | |
| $info ) : ?> 1; ?> |
|
tag_help() as $tag => $help ) : ?>
|