Skip to content

Commit 12bbf1c

Browse files
committed
Initial commit
0 parents  commit 12bbf1c

File tree

4 files changed

+548
-0
lines changed

4 files changed

+548
-0
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# WP Custom Settings
2+
3+
Allows developers to create a custom admin menu page with settings using Settings API without registering callbacks to every settings section and field.
4+
5+
Please check example.php file to see how to create custom menu page and settings.
6+
7+
## Supported Input Fields
8+
9+
- Text
10+
- Textarea
11+
12+
**Note:** I'd suggest to add WP Custom Settings main file in your theme or plugin instead of adding as standalone plugin. This way you can modify it as per your need.

example.php

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Custom Settings example by using WP Settings API Wrapper.
4+
*
5+
* @package wp-settings-api-wrapper
6+
*/
7+
8+
/**
9+
* An example of adding a custom settings page.
10+
*
11+
* @return void
12+
*/
13+
function wp_register_custom_settings() {
14+
15+
$custom_settings = new WP_Custom_Settings(
16+
// Arguments to add menu page.
17+
[
18+
'page_title' => __( 'Custom Settings', 'wp-custom-settings' ),
19+
'menu_title' => __( 'Custom Settings', 'wp-custom-settings' ),
20+
'capability' => 'manage_options',
21+
'menu_slug' => 'wp-custom-settings-page',
22+
'icon_url' => '',
23+
'position' => null,
24+
],
25+
// Arguments to register setting.
26+
[
27+
'option_group' => 'wp_custom_settings_group',
28+
'option_name' => 'wp_custom_settings_options',
29+
'args' => array(
30+
'type' => 'array',
31+
'description' => 'Description of Custom Settings.',
32+
'show_in_rest' => true,
33+
'default' => array(),
34+
'sanitize_callback' => null,
35+
),
36+
],
37+
// Arguments to add sections and fields.
38+
[
39+
new WP_Custom_Settings_Section(
40+
'wp_custom_settings_section',
41+
__( 'Section Title.', 'wp-custom-settings' ),
42+
__( 'Section Description.', 'wp-custom-settings' ),
43+
[
44+
new WP_Custom_Settings_Field(
45+
'text',
46+
'wp_custom_settings_field',
47+
__( 'Field Title', 'wp-settings-api-wrapper' ),
48+
[
49+
'description' => 'Description of Custom Settings.',
50+
'label_for' => 'wp_custom_settings_field',
51+
'class' => 'regular-text',
52+
]
53+
),
54+
]
55+
),
56+
new WP_Custom_Settings_Section(
57+
'wp_custom_settings_section_1',
58+
__( 'Section Title 1.', 'wp-custom-settings' ),
59+
__( 'Section Description 1.', 'wp-custom-settings' ),
60+
[
61+
new WP_Custom_Settings_Field(
62+
'textarea',
63+
'wp_custom_settings_field_1',
64+
__( 'Field Title 1', 'wp-custom-settings' ),
65+
[
66+
'description' => 'Description of Custom Settings Field 1.',
67+
'label_for' => 'wp_custom_settings_field_2',
68+
'class' => 'large-text',
69+
]
70+
),
71+
]
72+
),
73+
]
74+
);
75+
76+
}
77+
add_action( 'init', 'wp_register_custom_settings' );

phpcs.xml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="WordPress-Coding-Standards">
3+
<description>WordPress Coding Standards</description>
4+
5+
<rule ref="WordPress">
6+
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
7+
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
8+
</rule>
9+
10+
<rule ref="PHPCompatibility">
11+
<exclude name="Generic.Arrays.DisallowShortArraySyntax.Found"/>
12+
</rule>
13+
14+
<config name="testVersion" value="7.0-"/>
15+
16+
<arg name="extensions" value="php,js"/>
17+
<arg value="s"/>
18+
19+
</ruleset>

0 commit comments

Comments
 (0)