{"id":427,"date":"2012-07-14T09:17:02","date_gmt":"2012-07-14T09:17:02","guid":{"rendered":"https:\/\/www.frozenlogistic.com\/?p=427"},"modified":"2013-05-09T13:07:26","modified_gmt":"2013-05-09T13:07:26","slug":"option-files","status":"publish","type":"post","link":"https:\/\/www.frozenlogistic.com\/?p=427","title":{"rendered":"Option files"},"content":{"rendered":"<p>Modification of administration panel content\u00a0 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>\n<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>\n<ul>\n<li><strong>tabs.json<\/strong> file &#8211; it includes a list of sections visible on the right side of an administration panel: <a href=\"https:\/\/www.frozenlogistic.com\/wp-content\/uploads\/2012\/07\/meetgavern_wp-sidebar.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"size-full wp-image-962 aligncenter\" alt=\"meetgavern_wp-sidebar\" src=\"https:\/\/www.frozenlogistic.com\/wp-content\/uploads\/2012\/07\/meetgavern_wp-sidebar.png\" width=\"224\" height=\"513\" \/><\/a>\u00a0each section is described with a table in the form [code][\u00abBasic\u00bb, \u00aboptions.basic\u00bb, \u00abenabled\u00bb][\/code] the first element of a table is a section name displayed in a panel, the second element is a file name without \u00ab<strong>.json<\/strong>\u00bb 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\u00a0<strong>options.basic.json<\/strong> file.<\/li>\n<li><strong>options.*.json\u00a0<\/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>\n<\/ul>\n<p>Each options.*.json file includes three main fields in an object stored:<\/p>\n<ul>\n<li><strong>groupname<\/strong> &#8211; it is a section title<\/li>\n<li><strong>groupdesc<\/strong> &#8211; it specifies a section description displayed directly under a\u00a0 section title<\/li>\n<li><strong>fields<\/strong> &#8211; it includes a table of objects of fields displayed under the title and a section description<\/li>\n<\/ul>\n<p>Each field defined by an object including the following fields:<\/p>\n<ul>\n<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>\n<li><strong>type<\/strong>&#8211; it specifies a field type. Standard fields are:\n<ul>\n<li><strong>TextBlock<\/strong> &#8211; a field including a description text &#8211; it is not used for storing any option value<\/li>\n<li><strong>Text<\/strong> &#8211; the easiest text field allowing to insert short text values<\/li>\n<li><strong>RawText <\/strong>&#8211; pure, simple text without any formatting<\/li>\n<li><strong>Textarea<\/strong> &#8211; a text field used for inserting a greater number of text values<\/li>\n<li><strong>Select<\/strong> &#8211; a select field<\/li>\n<li><strong>Switcher<\/strong> &#8211; a checkbox restricted to two options: \u00abEnabled\u00bb and \u00abDisabled\u00bb<\/li>\n<li><strong>Media<\/strong> &#8211; a field allowing to choose images<\/li>\n<li><strong>WidthHeight<\/strong> &#8211; a field allowing to specify two values defining width and height (mostly used with a Media field)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<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 \/>\n<strong><\/strong><\/p>\n<ul>\n<li><strong>Menu<\/strong> &#8211; a field allowing to generate options connected with page&#8217;s menu &#8211; used in a Navigation section<\/li>\n<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>\n<\/ul>\n<p>The description of creating your own fields types we will describe in the further part of this article.<\/p>\n<ul>\n<li><strong>label<\/strong> &#8211; it specifies a label text visible next to a field<\/li>\n<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>\n<li><strong>default<\/strong> &#8211; default value of a field given<\/li>\n<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>\n<li><strong>format<\/strong> &#8211; (optional) a field specifying a desired field content in the form of a regular expression. e.g. value:\u00a0[code][a-zA-Z]{2,5}[\/code] 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>\n<li><strong>required<\/strong> &#8211; (optional) allows to specify whether filling in a particular field was required<\/li>\n<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\u00a0 <strong>FIELD_NAME<\/strong> is a name without a prefix with a theme name. e.g. [code]option1=10,option2=20[\/code] will cause that a field given will be visible when an option with\u00a0<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>\n<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>\n<\/ul>\n<p>After adding a new option, you have to remember about its support in the theme. Option value is loaded by using a\u00a0get_option function of a schemata given:<\/p>\n<p>[code]get_option($tpl-&gt;name . &#8216;_OPTION_NAME&#8217;, &#8216;DEFAULT_VALUE&#8217;);[\/code]<\/p>\n<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 \u00ab<strong>_<\/strong>\u00bb symbol which you cannot omit. A prefix with a theme name is added in order differentiate values of options of different themes.<\/p>\n<h3>Creating your own field types options<\/h3>\n<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>\n<p>[code]{<\/p>\n<p>\u00abname\u00bb: \u00abCustomField\u00bb,<\/p>\n<p>\u00abdescription\u00bb: \u00abExample Custom Field\u00bb,<\/p>\n<p>\u00abjs\u00bb: false,<\/p>\n<p>\u00abcss\u00bb: false,<\/p>\n<p>\u00abphp\u00bb: \u00abcustomfield.php\u00bb,<\/p>\n<p>\u00abclass\u00bb: \u00abGKFormInputCustomField\u00bb<\/p>\n<p>}[\/code]<\/p>\n<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>\n<p>Also, a <strong>customfield.css<\/strong> file must include a safety code at the beginning:<\/p>\n<p>[code]\/\/ disable direct access to the file<\/p>\n<p>defined(&#8216;GAVERN_WP&#8217;) or die(&#8216;Access denied&#8217;);[\/code]<\/p>\n<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>\n<p>[code]$this-&gt;required[\/code]<\/p>\n<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>\n<p>The remaining class methods have to be created according to the needs of the author of a form\u00a0 field given.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Modification of administration panel content\u00a0 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 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57],"tags":[56,28,71,50],"class_list":["post-427","post","type-post","status-publish","format-standard","hentry","category-theme-back-end","tag-back-end","tag-json","tag-option-files","tag-theme"],"_links":{"self":[{"href":"https:\/\/www.frozenlogistic.com\/index.php?rest_route=\/wp\/v2\/posts\/427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.frozenlogistic.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.frozenlogistic.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.frozenlogistic.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.frozenlogistic.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=427"}],"version-history":[{"count":3,"href":"https:\/\/www.frozenlogistic.com\/index.php?rest_route=\/wp\/v2\/posts\/427\/revisions"}],"predecessor-version":[{"id":429,"href":"https:\/\/www.frozenlogistic.com\/index.php?rest_route=\/wp\/v2\/posts\/427\/revisions\/429"}],"wp:attachment":[{"href":"https:\/\/www.frozenlogistic.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.frozenlogistic.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.frozenlogistic.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}