PHP code example of chandrapatel / wp-custom-settings

1. Go to this page and download the library: Download chandrapatel/wp-custom-settings library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chandrapatel / wp-custom-settings example snippets


$custom_settings = new WP_Custom_Settings(
	// Arguments to add menu page. Following arguments are same as add_menu_page() function arguments.
	// Callback argument does not needed.
	[
		'page_title' => __( 'Custom Settings', 'wp-custom-settings' ),
		'menu_title' => __( 'Custom Settings', 'wp-custom-settings' ),
		'capability' => 'manage_options',
		'menu_slug'  => 'wp-custom-settings-page',
		'icon_url'   => '',
		'position'   => null,
	],
	// Arguments to register setting. Following arguments are same as register_setting() function arguments.
	[
		'option_group' => 'wp_custom_settings_group',
		'option_name'  => 'wp_custom_settings_options',
		'args'         => array(
			'type'              => 'array',
			'description'       => 'Description of Custom Settings.',
			'show_in_rest'      => true,
			'default'           => array(),
			'sanitize_callback' => null,
		),
	],
	// Arguments to add sections and fields.
	[
		new WP_Custom_Settings_Section(
			'wp_custom_settings_section', // ID.
			__( 'Section Title.', 'wp-custom-settings' ), // Title.
			__( 'Section Description.', 'wp-custom-settings' ), // Description.
			[
				new WP_Custom_Settings_Field(
					'text', // Field type.
					'wp_custom_settings_field', // ID. Also, it will used for "name" attribute.
					__( 'Field Title', 'wp-settings-api-wrapper' ), // Title.
					[ // Pass additional arguments.
						'description' => 'Description of Custom Settings.',
						'label_for'   => 'wp_custom_settings_field',
						'class'       => 'regular-text',
					]
				),
			]
		),
	]
);