<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Longhouses &#187; Option files</title>
	<atom:link href="http://www.longhouses.nl/tag/option-files/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.longhouses.nl</link>
	<description>creëert business</description>
	<lastBuildDate>Mon, 10 Feb 2014 12:13:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>Option files</title>
		<link>http://www.longhouses.nl/option-files/</link>
		<comments>http://www.longhouses.nl/option-files/#comments</comments>
		<pubDate>Sat, 14 Jul 2012 09:17:02 +0000</pubDate>
		<dc:creator><![CDATA[webmaster]]></dc:creator>
				<category><![CDATA[Theme back-end]]></category>
		<category><![CDATA[back-end]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Option files]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://www.longhouses.nl/?p=427</guid>
		<description><![CDATA[Modification of administration panel content  in GavernWP is very easy &#8211; it is based on JSON files which include a list of options. Thanks to it, creating new options available in an administration panel is very easy. Options files are in gavern/options catalog in a folder connected with a currently used language. In the catalog, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Modification of administration panel content  in GavernWP is very easy &#8211; it is based on JSON files which include a list of options. Thanks to it, creating new options available in an administration panel is very easy.</p>
<p>Options files are in gavern/options catalog in a folder connected with a currently used language. In the catalog, you will find two main files groups:</p>
<ul>
<li><strong>tabs.json</strong> file &#8211; it includes a list of sections visible on the right side of an administration panel: <a href="http://www.longhouses.nl/wp-content/uploads/2012/07/MeetGavernWP-‹-Meet-Gavern-WP-—-WordPress-1.jpg"><img class="aligncenter size-full wp-image-654" title="Sidebar" src="http://www.longhouses.nl/wp-content/uploads/2012/07/MeetGavernWP-‹-Meet-Gavern-WP-—-WordPress-1.jpg" alt="" width="231" height="485" /></a> each section is described with a table in the form <pre class="gk-code" data-style="style1"><code>["Basic", "options.basic", "enabled"]</code></pre> the first element of a table is a section name displayed in a panel, the second element is a file name without &#8220;<strong>.json</strong>&#8221; extension which stores a list of options available in a section given and the third value refers to whether a section given is visible in a panel. In this case, there will be a <strong>Basic</strong> tab displayed in a panel based on content of <strong>options.basic.json</strong> file.</li>
<li><strong>options.*.json </strong>files &#8211; they include a list of options available in a section given &#8211; their names are strictly connected with the content of <strong>tabs.json</strong> file.</li>
</ul>
<p>Each options.*.json file includes three main fields in an object stored:</p>
<ul>
<li><strong>groupname</strong> &#8211; it is a section title</li>
<li><strong>groupdesc</strong> &#8211; it specifies a section description displayed directly under a  section title</li>
<li><strong>fields</strong> &#8211; it includes a table of objects of fields displayed under the title and a section description</li>
</ul>
<p>Each field defined by an object including the following fields:</p>
<ul>
<li><strong>name</strong> &#8211; it specifies an option name which will be connected with a particular field. There is a prefix added automatically to an option name which is a theme name (it is stored in a global variable &#8211; <strong>$tpl-&gt;name</strong>).</li>
<li><strong>type</strong>&#8211; it specifies a field type. Standard fields are:
<ul>
<li><strong>TextBlock</strong> &#8211; a field including a description text &#8211; it is not used for storing any option value</li>
<li><strong>Text</strong> &#8211; the easiest text field allowing to insert short text values</li>
<li><strong>Textarea</strong> &#8211; a text field used for inserting a greater number of text values</li>
<li><strong>Select</strong> &#8211; a select field</li>
<li><strong>Switcher</strong> &#8211; a checkbox restricted to two options: &#8220;Enabled&#8221; and &#8220;Disabled&#8221;</li>
<li><strong>Media</strong> &#8211; a field allowing to choose images</li>
<li><strong>WidthHeight</strong> &#8211; a field allowing to specify two values defining width and height (mostly used with a Media field)</li>
</ul>
</li>
</ul>
<p>These fields are defined in a <strong>gavern/form_elements/standard.php</strong> file and their code was derived from a <strong>GKFormInput</strong> field. It is worth remembering that files connected with options are parsed by a <strong>gavern/form.parser.php</strong> file. Additionally, you may create your own fields types in a <strong>gavern/form_elements</strong> catalog. In GavernWP, we have included the following fields types:<br />
<strong></strong></p>
<ul>
<li><strong>Menu</strong> &#8211; a field allowing to generate options connected with page&#8217;s menu &#8211; used in a Navigation section</li>
<li><strong>ThemeStyle</strong> &#8211; a field allowing to choose page&#8217;s style &#8211; used at the beginning of a <strong>Basic</strong> section.</li>
</ul>
<p>The description of creating your own fields types we will describe in the further part of this article.</p>
<ul>
<li><strong>label</strong> &#8211; it specifies a label text visible next to a field</li>
<li><strong>tooltip</strong> &#8211; (optional) it allows to specify tooltip content which will appear after mousing over a label of a field given</li>
<li><strong>default</strong> &#8211; default value of a field given</li>
<li><strong>class</strong> &#8211; (optional) this field allows to specify CSS classes added to an element while generating it (if a field code supported such a functionality)</li>
<li><strong>format</strong> &#8211; (optional) a field specifying a desired field content in the form of a regular expression. e.g. value: <pre class="gk-code" data-style="style1"><code>[a-zA-Z]{2,5}</code></pre> specifies that a field given will be filled in correctly only when a user set as its value a sequence of capital or small letters from 2 to 5 symbols.</li>
<li><strong>required</strong> &#8211; (optional) allows to specify whether filling in a particular field was required</li>
<li><strong>visibility</strong> &#8211; (optional) specifies when a particular field is visible. Visibility rules are separated with commas and are created in <strong>FIELD_NAME=VALUE</strong> format &#8211; in the case of a few visibility rules, they are linked with <strong>AND</strong> operator. The value of  <strong>FIELD_NAME</strong> is a name without a prefix with a theme name. e.g. <pre class="gk-code" data-style="style1"><code>option1=10,option2=20</code></pre> will cause that a field given will be visible when an option with <strong>option1</strong> name will be set to <strong>10</strong> and, at the same time, an <strong>option2</strong> option will have have value equals <strong>20</strong>.</li>
<li><strong>other</strong> &#8211; (optional) this field is used for storing additional values, e.g. in the case of a <strong>Select</strong> field, it is used for storing names and options values. This field is very useful when creating more advanced fields which may require additional configuration options.</li>
</ul>
<p>After adding a new option, you have to remember about its support in the theme. Option value is loaded by using a get_option function of a schemata given:</p>
<pre class="gk-code" data-style="style1"><code>get_option($tpl-&gt;name . '_OPTION_NAME', 'DEFAULT_VALUE');</code></pre>
<p>when <strong>OPTION_NAME</strong> is an option name from a JSON file and <strong>DEFAULT_VALUE</strong> is default value of an option which will be used when a user does not specify a value of an option given. What is important, there is a &#8220;<strong>_</strong>&#8221; symbol which you cannot omit. A prefix with a theme name is added in order differentiate values of options of different themes.</p>
<h3>Creating your own field types options</h3>
<p>While creating a new field type, you have to start from creating a catalog compliant with a field name, e.g. <strong>CustomField</strong> in a <strong>gavern/form_elements</strong> catalog. Then, you have to create a config.json file in this catalog and fill it in according to the schemata below:</p>
<pre class="gk-code" data-style="style1"><code>{
"name": "CustomField",
"description": "Example Custom Field",
"js": false,
"css": false,
"php": "customfield.php",
"class": "GKFormInputCustomField"
}</code></pre>
<p><strong>name</strong>, <strong>description</strong>, <strong>php</strong> i <strong>class</strong> fields have to include particular values; js and css fields are optional &#8211; they allow to specify whether a field given has to use additional CSS and JavaScript code (then, a name of files from a field catalog has to be set as a value). Also, you have to create a <strong>customfield.php</strong> file including a <strong>GKFormInputCustomField</strong> class derived after a <strong>GKFormInput</strong> class.</p>
<p>Also, a <strong>customfield.css</strong> file must include a safety code at the beginning:</p>
<pre class="gk-code" data-style="style1"><code>// disable direct access to the file
defined('GAVERN_WP') or die('Access denied');</code></pre>
<p>Each field class has to include at least one public method &#8211; <strong>output</strong> not loading any additional arguments. This method must return HTML code of a field given. Field properties froma JSON file are available as class fields, e.g. <strong>required</strong> is available as:</p>
<pre class="gk-code" data-style="style1"><code>$this-&gt;required</code></pre>
<p>The second important public methid of each class of a form field is a <strong>getValue</strong> method which loads one argument &#8211; <strong>$default</strong>. Its use is optional and useful only when a value of a field given uses more than one field in the data base. Then, it is useful to overwrite this method &#8211; as an example we recommend a standard code of a <strong>WidthHeight</strong> field where overwritting a getValue method was used for storing values of two form fields in one main field created by a <strong>GKInputFormWidthHeight</strong> class.</p>
<p>The remaining class methods have to be created according to the needs of the author of a form  field given.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.longhouses.nl/option-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
