定制 luizbills/wp-options-page 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

luizbills/wp-options-page

Composer 安装命令:

composer require luizbills/wp-options-page

包简介

Easy way to build options/settings pages in your WordPress plugins and themes.

README 文档

README

A class to build options pages for your WordPress plugins and themes.

Install

Install using composer:

composer require luizbills/wp-options-page

Getting Started

Just create an WP_Options_Page class instance on init action hook:

function yourprefix_create_settings_page () {
	$page = new WP_Options_Page();

	// give your page a ID
	$page->id = 'my_settings_page';

	// set the menu name
	$page->menu_title = 'My Settings';

	// register your options fields
	$page->fields = [
		// a simple text input field
		[
			'id' => 'api_key',
			'title' => 'API Key',
			'type' => 'text',
		]
	];

	// register the page
	$page->init();

	// access the stored options
	$api_key = $page->get_option( 'api_key' );

	// store this page in a global object or variable
	// So you can easily your instance class later
	// example: My_Plugin->settings = $page;
}
add_action( 'init', 'yourprefix_create_settings_page' );

Or create your own derived class:

class My_Settings_Page extends WP_Options_Page {
	// I recommend using Singleton pattern
	// So you can easily retrieve the class later
	// example: My_Settings_Page::instance()->get_option( 'api_key' );
	private static $instance = null;
	public static function instance () {
		if ( ! self::$instance ) self::$instance = new self();
		return self::$instance;
	}

	private function __construct () {
		add_action( 'init', [ $this, 'init' ] );
	}

	// overrides the `init` method to setup your page
	public function init () {
		// give your page a ID
		$this->id = 'my_settings_page';

		// set the menu name
		$this->menu_title = 'My Settings';

		// register the page
		parent::init();
	}

	// overrides the `get_fields` method to register your fields
	public function get_fields () {
		return [
			[
				'id' => 'api_key',
				'title' => 'API Key',
				'type' => 'text',
			]
		];
	}
}

// start your class
My_Settings_Page::instance();

Preview:

Learn More

Visit our wiki or study (and install) our Demo Plugin.

LICENSE

GPLv2 or later

统计信息

  • 总下载量: 758
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 26
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 26
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2023-01-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固