GithubHelp home page GithubHelp logo

isabella232 / cf-settings-api-wrapper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from crowdfavorite/cf-settings-api-wrapper

0.0 0.0 0.0 29 KB

Wraps the Settings API into a single hook for simple Settings page construction with extendible template architecture.

License: GNU General Public License v2.0

JavaScript 13.70% PHP 84.60% CSS 1.70%

cf-settings-api-wrapper's Introduction

cf-settings-api-wrapper

Wraps the Settings API into a single hook for simple Settings page construction with extendible template architecture.

Quick usage example with [ ] tags for optional parameters and a very brief description for some special cases

add_filter( 'cf_settings__plugin_settings__eg_name', function( $a ) {
	return array(
		// Will be auto-generated based on "eg_name"
		[ 'id' => 'my-plugin-settings-id', ]
		// Will be auto-generated based on "eg_name"
		[ 'group' => 'my-plugin-group', ]
		// Will be auto-generated based on "eg_name"
		[ 'option_name' => 'my-plugin-db-name', ]

		// Will default inside the Settings menu with label based on "eg_name"
		[ 'menu' => array(
			[ 'label' => 'My Plugin Settings', ]
			[ 'parent' => '', ]
		), ]

		// Optional template settings
		[ 'page' => array(
			[ 'heading' => 'My Plugin Settings', ]
		), ]

		/**
		*  The 'settings' key is optional if none of the above are provided.
		*  Specifically, an array of arrays with no keys will be presumed to be
		*  the settings array. Invalid section structure will error gracefully
		*  if the assumption is in error.
		*/
		'settings' => array(
			array(
				'id' => 'my-first-section',
				[ 'label' => 'My First Section', ]
				'fields' => array(
					// Names of fields are technically optional, but are preferred
					'my-setting-1a' => array(
						'label' => 'Setting 1a',
						[ 'description' => '1a -- text', ]
						'type' => 'text',
						'default' => 'Setting 1a Default Value',
					),
					'my-setting-1b' => array(
						'label' => 'Setting 1b',
						'description' => '1b -- rel_link',
						'type' => 'rel_link',
					),
					'my-setting-1c' => array(
						'label' => 'Setting 1c',
						'description' => '1c -- select',
						'type' => 'select',
						// If the field type is one with multiple options, provide them.
						'options' => array(
							'1c-a' => '1c A',
							'1c-b' => '1c B',
							'1c-c' => '1c C',
							'1c-d' => '1c D',
						),
					),
					'my-setting-1d' => array(
						'label' => 'Setting 1d',
						'description' => '1d -- true_false',
						'type' => 'true_false',
						'default' => 0,
					),
				),
			),
			array(
				'id' => 'my-second-section',
				'label' => 'My Second Section',
				'fields' => array(
					// We can also handle grouped fields within a section
					'my-setting-group' => array(
						'label' => 'Settings Group',
						// Provide the "group" type and "multi" array of sub-fields
						'type' => 'group',
						'multi' => array(
							// These are constructed exactly as the standard fields
							'my-setting-2a-a' => array(
								'label' => 'Setting 2a-a',
								'description' => 'Text Field',
								'type' => 'text',
								'default' => "Some Text Value",
							),
							'my-setting-2a-b' => array(
								'label' => 'Setting 2a-b',
								'description' => 'Relative Link',
								'type' => 'rel_link',
								// Support exists for placeholders and is filterable.
								'default' => '::site_url::/home/',
							),
						),
					),
				),
			),
		),
	);
});

cf-settings-api-wrapper's People

Contributors

stephenmurphy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.