[section => string, label => string, type => string, ...]` * * @return array */ abstract protected function define_options(): array; /** * Title and id of the settings tab. * * @return string[] section_id => title */ abstract public function get_sections(): array; /** * Whether the tab has a submitable form. * * @return bool */ public function has_form(): bool { return true; } /** * Get all options for this tab. * * @return array */ public function get_options(): array { $options = $this->define_options(); /** * Filters the options for a specific settings tab. * The dynamic portion of the hook name, `$this->get_id()`, refers to the tab's ID (e.g., 'general'). * * @param array $options The array of option definitions for the tab. * @param self $this The instance of the current tab class. */ return apply_filters( "adpresso_settings_tab_{$this->get_id()}_options", $options, $this ); } /** * Renders the settings tab. * * @param bool $needs_submit * * @return void */ public function render( bool $needs_submit = true ): void { do_action( 'adpresso/settings/page/' . $this->get_id() . '/before', $this ); echo '
'; do_action( 'adpresso/settings/form/before', $this ); echo '
'; settings_fields( 'adpresso_settings_' . $this->get_id() ); do_action( 'adpresso/settings/section/' . $this->get_id() . '/before', $this ); do_settings_sections( 'adpresso_settings_' . $this->get_id() ); do_action( 'adpresso/settings/section/' . $this->get_id() . '/after', $this ); if ( $needs_submit ) { submit_button( __( 'Save Changes', 'adpresso' ), 'adpresso-btn adpresso-btn-action adpresso-color-accent' ); } do_action( 'adpresso/settings/form/' . $this->get_id() . '/end', $this ); echo '
'; do_action( 'adpresso/settings/form/' . $this->get_id() . '/after', $this ); echo '
'; do_action( 'adpresso/settings/page/' . $this->get_id() . '/after', $this ); } /** * Sanitize settings for each tab. * * @param $options * * @return array * @internal Is used as a callback for 'register_setting' on the settings page. */ public function sanitize_settings( $options ): array { if ( ! is_array( $options ) ) { return []; } $sanitized_options = []; $fields = $this->get_options(); $handler = new ParamsHandler( $options ); foreach ( $options as $id => $value ) { if ( ! isset( $fields[ $id ] ) ) { continue; } $field = $fields[ $id ]; $field['id'] = $id; $sanitized_value = ParamsHelper::sanitize_type_field( $field, $handler ); $sanitized_options[ $id ] = $sanitized_value; } return $sanitized_options; } /** * Returns the order. The highest order will be rendered first. * * @return int */ public function get_order(): int { return 20; } }