Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

CF7 Settings Options

class DD_UPS_Chooser_Settings {

	public function __construct() {

		add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
		add_action( 'admin_init', array( $this, 'init_settings'  ) );

	}

	public function add_admin_menu() {

		add_options_page(
			esc_html__( 'UPS Choose Settings', 'duckdiver' ),
			esc_html__( 'UPS Chooser Settings', 'duckdiver' ),
			'manage_options',
			'ups-chooser-settings-page',
			array( $this, 'page_layout' )
		);

	}

	public function init_settings() {

		register_setting(
			'ups_chooser_settings_group',
			'ups_chooser_options'
		);

		add_settings_section(
			'ups_chooser_options_section',
			'',
			false,
			'ups_chooser_options'
		);

		add_settings_field(
			'cf7_step_one',
			__( 'Form ID of Step One', 'duckdiver' ),
			array( $this, 'render_cf7_step_one_field' ),
			'ups_chooser_options',
			'ups_chooser_options_section'
		);
		add_settings_field(
			'cf7_step_two',
			__( 'Form ID of Step 2', 'duckdiver' ),
			array( $this, 'render_cf7_step_two_field' ),
			'ups_chooser_options',
			'ups_chooser_options_section'
		);
		add_settings_field(
			'page_id_step_two',
			__( 'Page ID of Step 2', 'duckdiver' ),
			array( $this, 'render_page_id_step_two_field' ),
			'ups_chooser_options',
			'ups_chooser_options_section'
		);
		add_settings_field(
			'thank_you_page',
			__( 'Thank You Page ID', 'duckdiver' ),
			array( $this, 'render_thank_you_page_field' ),
			'ups_chooser_options',
			'ups_chooser_options_section'
		);

	}

	public function page_layout() {

		// Check required user capability
		if ( !current_user_can( 'manage_options' ) )  {
			wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'duckdiver' ) );
		}

		// Admin Page Layout
		echo '<div class="wrap">' . "n";
		echo '	<h1>' . get_admin_page_title() . '</h1>' . "n";
		echo '	<form action="options.php" method="post">' . "n";

		settings_fields( 'ups_chooser_settings_group' );
		do_settings_sections( 'ups_chooser_options' );
		submit_button();

		echo '	</form>' . "n";
		echo '</div>' . "n";

	}

	function render_cf7_step_one_field() {

		// Retrieve data from the database.
		$options = get_option( 'ups_chooser_options' );

		// Set default value.
		$value = isset( $options['cf7_step_one'] ) ? $options['cf7_step_one'] : '';

		// Field output.
		echo '<input type="number" name="ups_chooser_options[cf7_step_one]" class="regular-text cf7_step_one_field" placeholder="' . esc_attr__( '', 'duckdiver' ) . '" value="' . esc_attr( $value ) . '">';

	}

	function render_cf7_step_two_field() {

		// Retrieve data from the database.
		$options = get_option( 'ups_chooser_options' );

		// Set default value.
		$value = isset( $options['cf7_step_two'] ) ? $options['cf7_step_two'] : '';

		// Field output.
		echo '<input type="number" name="ups_chooser_options[cf7_step_two]" class="regular-text cf7_step_two_field" placeholder="' . esc_attr__( '', 'duckdiver' ) . '" value="' . esc_attr( $value ) . '">';

	}

	function render_page_id_step_two_field() {

		// Retrieve data from the database.
		$options = get_option( 'ups_chooser_options' );

		// Set default value.
		$value = isset( $options['page_id_step_two'] ) ? $options['page_id_step_two'] : '';

		// Field output.
		echo '<input type="number" name="ups_chooser_options[page_id_step_two]" class="regular-text page_id_step_two_field" placeholder="' . esc_attr__( '', 'duckdiver' ) . '" value="' . esc_attr( $value ) . '">';
		echo '<p class="description">' . __( 'This is the page/post ID of the page where the step 2 form is', 'duckdiver' ) . '</p>';

	}

	function render_thank_you_page_field() {

		// Retrieve data from the database.
		$options = get_option( 'ups_chooser_options' );

		// Set default value.
		$value = isset( $options['thank_you_page'] ) ? $options['thank_you_page'] : '';

		// Field output.
		echo '<input type="number" name="ups_chooser_options[thank_you_page]" class="regular-text thank_you_page_field" placeholder="' . esc_attr__( '', 'duckdiver' ) . '" value="' . esc_attr( $value ) . '">';
		echo '<p class="description">' . __( 'The page ID of the thank you page.', 'duckdiver' ) . '</p>';

	}

}

new DD_UPS_Chooser_Settings;