PHPackages                             lurenjiasworld/wp-settings-api-class - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lurenjiasworld/wp-settings-api-class

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lurenjiasworld/wp-settings-api-class
====================================

WordPress settings API Abstraction Class

0891PHP

Since Mar 20Pushed 6y agoCompare

[ Source](https://github.com/LuRenJiasWorld/wp-settings-api-class)[ Packagist](https://packagist.org/packages/lurenjiasworld/wp-settings-api-class)[ RSS](/packages/lurenjiasworld-wp-settings-api-class/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (1)

### Package Installation (via Composer)

[](#package-installation-via-composer)

To install this package, edit your `composer.json` file:

```
{
    "require": {
        "lurenjiasworld/wp-settings-api-class": "dev-master"
    }
}
```

Now run:

`$ composer install`

Usage Example
-------------

[](#usage-example)

Checkout the [examples](https://github.com/tareq1988/wordpress-settings-api-class/tree/master/example) folder for OOP and procedural example. They were called in [plugin.php](https://github.com/tareq1988/wordpress-settings-api-class/blob/master/plugin.php) file.

A detailed tutorial can be found [here](https://tareq.co/2012/06/wordpress-settings-api-php-class/).

### 重构获取选项

[](#重构获取选项)

```
/**
 * Get the value of a settings field
 *
 * @param string $option settings field name
 * @param string $section the section name this field belongs to
 * @param string $default default text if it's not found
 *
 * @return mixed
 */
function prefix_get_option( $option, $section, $default = '' ) {

    $options = get_option( $section );

    if ( isset( $options[$option] ) ) {
        return $options[$option];
    }

    return $default;
}
```

### 选项实例

[](#选项实例)

```
private $settings_api;

	function __construct() {
		$this->settings_api = new Settings();

		add_action( 'admin_init', array($this, 'admin_init') );
		add_action( 'admin_menu', array($this, 'admin_menu') );
	}

	function admin_init() {

		//set the settings
		$this->settings_api->set_sections( $this->get_settings_sections() );
		$this->settings_api->set_fields( $this->get_settings_fields() );

		//initialize settings
		$this->settings_api->admin_init();
	}

	function admin_menu() {
		add_options_page( 'Settings API', 'Settings API', 'delete_posts', 'settings_api_test', array($this, 'plugin_page') );
	}

	function get_settings_sections() {
		$sections = array(
			array(
				'id'    => 'wedevs_basics',
				'title' => __( 'Basic Settings', 'wedevs' )
			),
			array(
				'id'    => 'wedevs_advanced',
				'title' => __( 'Advanced Settings', 'wedevs' )
			)
		);
		return $sections;
	}

	/**
	 * Returns all the settings fields
	 *
	 * @return array settings fields
	 */
	function get_settings_fields() {
		$settings_fields = array(
			'wedevs_basics' => array(
				array(
					'name'              => 'text_val',
					'label'             => __( 'Text Input', 'wedevs' ),
					'desc'              => __( 'Text input description', 'wedevs' ),
					'placeholder'       => __( 'Text Input placeholder', 'wedevs' ),
					'type'              => 'text',
					'default'           => 'Title',
					'sanitize_callback' => 'sanitize_text_field'
				),
				array(
					'name'              => 'number_input',
					'label'             => __( 'Number Input', 'wedevs' ),
					'desc'              => __( 'Number field with validation callback `floatval`', 'wedevs' ),
					'placeholder'       => __( '1.99', 'wedevs' ),
					'min'               => 0,
					'max'               => 100,
					'step'              => '0.01',
					'type'              => 'number',
					'default'           => 'Title',
					'sanitize_callback' => 'floatval'
				),
				array(
					'name'        => 'textarea',
					'label'       => __( 'Textarea Input', 'wedevs' ),
					'desc'        => __( 'Textarea description', 'wedevs' ),
					'placeholder' => __( 'Textarea placeholder', 'wedevs' ),
					'type'        => 'textarea'
				),
				array(
					'name'        => 'html',
					'desc'        => __( 'HTML area description. You can use any bold or other HTML elements.', 'wedevs' ),
					'type'        => 'html'
				),
				array(
					'name'  => 'checkbox',
					'label' => __( 'Checkbox', 'wedevs' ),
					'desc'  => __( 'Checkbox Label', 'wedevs' ),
					'type'  => 'checkbox'
				),
				array(
					'name'    => 'radio',
					'label'   => __( 'Radio Button', 'wedevs' ),
					'desc'    => __( 'A radio button', 'wedevs' ),
					'type'    => 'radio',
					'options' => array(
						'yes' => 'Yes',
						'no'  => 'No'
					)
				),
				array(
					'name'    => 'selectbox',
					'label'   => __( 'A Dropdown', 'wedevs' ),
					'desc'    => __( 'Dropdown description', 'wedevs' ),
					'type'    => 'select',
					'default' => 'no',
					'options' => array(
						'yes' => 'Yes',
						'no'  => 'No'
					)
				),
				array(
					'name'    => 'password',
					'label'   => __( 'Password', 'wedevs' ),
					'desc'    => __( 'Password description', 'wedevs' ),
					'type'    => 'password',
					'default' => ''
				),
				array(
					'name'    => 'file',
					'label'   => __( 'File', 'wedevs' ),
					'desc'    => __( 'File description', 'wedevs' ),
					'type'    => 'file',
					'default' => '',
					'options' => array(
						'button_label' => 'Choose Image'
					)
				)
			),
			'wedevs_advanced' => array(
				array(
					'name'    => 'color',
					'label'   => __( 'Color', 'wedevs' ),
					'desc'    => __( 'Color description', 'wedevs' ),
					'type'    => 'color',
					'default' => ''
				),
				array(
					'name'    => 'password',
					'label'   => __( 'Password', 'wedevs' ),
					'desc'    => __( 'Password description', 'wedevs' ),
					'type'    => 'password',
					'default' => ''
				),
				array(
					'name'    => 'wysiwyg',
					'label'   => __( 'Advanced Editor', 'wedevs' ),
					'desc'    => __( 'WP_Editor description', 'wedevs' ),
					'type'    => 'wysiwyg',
					'default' => ''
				),
				array(
					'name'    => 'multicheck',
					'label'   => __( 'Multile checkbox', 'wedevs' ),
					'desc'    => __( 'Multi checkbox description', 'wedevs' ),
					'type'    => 'multicheck',
					'default' => array('one' => 'one', 'four' => 'four'),
					'options' => array(
						'one'   => 'One',
						'two'   => 'Two',
						'three' => 'Three',
						'four'  => 'Four'
					)
				),
			)
		);

		return $settings_fields;
	}

	function plugin_page() {
		echo '';

		$this->settings_api->show_navigation();
		$this->settings_api->show_forms();

		echo '';
	}

	/**
	 * Get all the pages
	 *
	 * @return array page names with key value pairs
	 */
	function get_pages() {
		$pages = get_pages();
		$pages_options = array();
		if ( $pages ) {
			foreach ($pages as $page) {
				$pages_options[$page->ID] = $page->post_title;
			}
		}

		return $pages_options;
	}
```

主方法实例对象即可

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e7987025013fd0eda9b9cecfc9c708835e8a32aa27fac0274e96e003d5a24d9?d=identicon)[LuRenJiasWorld](/maintainers/LuRenJiasWorld)

---

Top Contributors

[![LuRenJiasWorld](https://avatars.githubusercontent.com/u/29622423?v=4)](https://github.com/LuRenJiasWorld "LuRenJiasWorld (3 commits)")

### Embed Badge

![Health badge](/badges/lurenjiasworld-wp-settings-api-class/health.svg)

```
[![Health](https://phpackages.com/badges/lurenjiasworld-wp-settings-api-class/health.svg)](https://phpackages.com/packages/lurenjiasworld-wp-settings-api-class)
```

###  Alternatives

[qinchen/web-utils

A web application common utils

111.4k](/packages/qinchen-web-utils)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
