Completed
Branch dev (d064b2)
by
unknown
24:08 queued 04:45
created

addSettingSections()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4286
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
/**
3
 * Admin Page Framework
4
 * 
5
 * http://en.michaeluno.jp/admin-page-framework/
6
 * Copyright (c) 2013-2015 Michael Uno; Licensed MIT
7
 * 
8
 */
9
10
/**
11
 * Provides methods for models.
12
 * 
13
 * @abstract
14
 * @since       3.0.4
15
 * @package     AdminPageFramework
16
 * @subpackage  Factory
17
 */
18
abstract class AdminPageFramework_Factory_Controller extends AdminPageFramework_Factory_View {
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
19
            
20
    /**
21
     * Should be extended
22
     * 
23
     * @internal
24
     */
25
    public function start() {}
26
    public function setUp() {}
27
            
28
    /**
29
     * Sets a system message.
30
     * 
31
     * This can be used to replace the framework system messages such as "Allowed maximum number of fields is ...".
32
     * 
33
     * @return      void
34
     * @since       DEVVER
35
     */
36
    public function setMessage( $sKey, $sMessage ) {
37
        $this->oMsg->set( $sKey, $sMessage );
38
    }
39
    
40
    /**
41
     * Returns the registered system message item(s).
42
     * 
43
     * @return      array|string
44
     * @since       DEVVER
45
     */
46
    public function getMessage( $sKey='' ) {
47
        return $this->oMsg->get( $sKey );
48
    }
49
       
50
    /**
51
     * Head Tag Methods - should be extended.
52
     * 
53
     * @remark      the number of arguments depend on the extended class.
54
     * @internal
55
     */
56
    
57
    /**
58
     * Enqueues styles of the given sources.
59
     * 
60
     * @since       3.0.4       The method itself has existed since v3.0.0 but moved to this factory class.
61
     * @param       array       The sources of the stylesheet to enqueue: the url, the absolute file path, or the relative path to the root directory of WordPress. Example: `array( '/css/mystyle.css', '/css/mystyle2.css' )`
62
     * @param       array       (optional) The another source argument array.
63
     * @return      array       The array holing the queued items.
64
     * @internal
65
     */
66
    public function enqueueStyles( $aSRCs, $_vArg2=null ) {} 
67
    
68
    /**
69
     * Enqueues a style of the given source.
70
     * 
71
     * @since       3.0.4       The method itself has existed since v3.0.0 but moved to this factory class.
72
     * @see         http://codex.wordpress.org/Function_Reference/wp_enqueue_style
73
     * @param       string      The source of the stylesheet to enqueue: the url, the absolute file path, or the relative path to the root directory of WordPress. Example: '/css/mystyle.css'.
74
     * @param       array       (optional) The argument array for more advanced parameters.
75
     * <h4>Argument Array</h4>
76
     * <ul>
77
     *     <li>**handle_id** - (optional, string) The handle ID of the stylesheet.</li>
78
     *     <li>**dependencies** - (optional, array) The dependency array. For more information, see <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_style">codex</a>.</li>
79
     *     <li>**version** - (optional, string) The stylesheet version number.</li>
80
     *     <li>**media** - (optional, string) the description of the field which is inserted into the after the input field tag.</li>
81
     *     <li>**attributes** - (optional, array) [3.3.0+] attributes array. `array( 'data-id' => '...' )`</li>
82
     * </ul>
83
     * @return      string      The style handle ID. If the passed url is not a valid url string, an empty string will be returned.
84
     * @internal
85
     */
86
    public function enqueueStyle( $sSRC, $_vArg2=null ) {}
87
    
88
    /**
89
     * Enqueues scripts by the given sources.
90
     * 
91
     * <h4>Example</h4>
92
     * <code>
93
     * $this->enqueueScripts(  
94
     *     array( 
95
     *          plugins_url( 'asset/js/test.js' , __FILE__ ), // source url or path
96
     *          plugins_url( 'asset/js/test2.js' , __FILE__ ),    
97
     *     )
98
     * );
99
     * </code>
100
     *
101
     * @since       3.0.4       The method itself has existed since v3.0.0 but moved to this factory class.
102
     * @param       array       The sources of the stylesheets to enqueue: the URL, the absolute file path, or the relative path to the root directory of WordPress. Example: '/js/myscript.js'.
103
     * @param       array       (optional) Ad additional source list array.
104
     * @return      array        The array holding the queued items.
105
     * @internal
106
     */    
107
    public function enqueueScripts( $aSRCs, $_vArg2=null ) {}
108
    /**
109
     * Enqueues a script by the given source.
110
     *  
111
     * <h4>Example</h4>
112
     * <code>$this->enqueueScript(  
113
     *      plugins_url( 'asset/js/test.js' , __FILE__ ), // source url or path
114
     *      array(
115
     *          'handle_id'     => 'my_script', // this handle ID also is used as the object name for the translation array below.
116
     *          'translation'   => array( 
117
     *              'a'                 => 'hello world!',
118
     *              'style_handle_id'   => $sStyleHandle, // check the enqueued style handle ID here.
119
     *          ),
120
     *      )
121
     * );</code>
122
     * 
123
     * @since       3.0.4       The method itself has existed since v3.0.0 but moved to this factory class.
124
     * @see         http://codex.wordpress.org/Function_Reference/wp_enqueue_script
125
     * @param       string      The URL of the stylesheet to enqueue, the absolute file path, or the relative path to the root directory of WordPress. Example: '/js/myscript.js'.
126
     * @param       array       (optional) The argument array for more advanced parameters.
127
     * <h4>Argument Array</h4>
128
     * <ul>
129
     *     <li>**handle_id** - (optional, string) The handle ID of the script.</li>
130
     *     <li>**dependencies** - (optional, array) The dependency array. For more information, see <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script">codex</a>.</li>
131
     *     <li>**version** - (optional, string) The stylesheet version number.</li>
132
     *     <li>**translation** - (optional, array) The translation array. The handle ID will be used for the object name.</li>
133
     *     <li>**in_footer** - (optional, boolean) Whether to enqueue the script before `</head>` or before`</body>` Default: `false`.</li>
134
     *     <li>**attributes** - (optional, array) [3.3.0+] attributes array. `array( 'data-id' => '...' )`</li>
135
     * </ul>
136
     * @return      string      The script handle ID. If the passed url is not a valid url string, an empty string will be returned.
137
     * @internal
138
     */    
139
    public function enqueueScript( $sSRC, $_vArg2=null ) {}    
140
    
141
    /*
142
     * Help Pane
143
     */
144
    /**
145
     * Adds the given HTML text to the contextual help pane.
146
     * 
147
     * The help tab will be the meta box title and all the added text will be inserted into the content area within the tab.
148
     * 
149
     * @example
150
     * <pre><code>$this->addHelpText( 
151
     *      __( 'This text will appear in the contextual help pane.', 'your-text-domain' ), 
152
     *      __( 'This description goes to the sidebar of the help pane.', 'your-text-domain' )
153
     * );</code></pre>
154
     * @since       2.1.0
155
     * @remark      This method just adds the given text into the class property. The actual registration will be performed with the `replyToRegisterHelpTabTextForMetaBox()` method.
156
     */ 
157
    public function addHelpText( $sHTMLContent, $sHTMLSidebarContent="" ) {
158
        if ( method_exists( $this->oHelpPane, '_addHelpText' ) ) {
159
            $this->oHelpPane->_addHelpText( $sHTMLContent, $sHTMLSidebarContent );
160
        }
161
    }
162
163
    /**
164
     * Adds sections.
165
     * 
166
     * It inserts the given section definition arrays into the class property and later they are parsed when sections are registered. The section definition array have required keys. Refer to the parameter section of this method.
167
     * 
168
     * <h3>Example</h3>
169
     * <code>$this->addSettingSections(
170
     *       array(
171
     *            'section_id'    => 'text_fields',
172
     *            'title'         => __( 'Text Fields', 'your-text-domain' ),
173
     *            'description'   => __( 'These are text type fields.', 'your-text-domain' ),
174
     *       ),    
175
     *       array(
176
     *            'section_id'    => 'selectors',
177
     *            'title'         => __( 'Selectors', 'your-text-domain' ),
178
     *            'description'   => __( 'These are selector type options such as dropdown lists, radio buttons, and checkboxes', 'your-text-domain' ),
179
     *       )
180
     * );</code>
181
     * @since       3.0.0     
182
     * @since       3.5.3       Removed the parameter declarations as they are caught with func_get_args().
183
     * @access      public
184
     * @remark      Accepts variadic parameters; the number of accepted parameters are not limited to three.
185
     * @remark      The target section tab slug will be reset once the method returns.
186
     * @param       array     a section definition array.
187
     * @param       array     (optional) another section array.
188
     * @param       array     (optional)  add more section array to the next parameters as many as necessary.
189
     * @return      void
190
     */    
191
    public function addSettingSections( /* $aSection1, $aSection2=null, $_and_more=null */ ) {
1 ignored issue
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
192
        
193
        foreach( func_get_args() as $_asSectionset ) { 
194
            $this->addSettingSection( $_asSectionset ); 
195
        }
196
        
197
        // Reset the stored target tab slug and the target section tab slug.
198
        $this->_sTargetSectionTabSlug = null;
0 ignored issues
show
Bug introduced by
The property _sTargetSectionTabSlug does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
199
        
200
    }
201
    
202
    /**
203
     * A singular form of the `adSettingSections()` method which takes only a single parameter.
204
     * 
205
     * This is useful when adding section arrays in loops.
206
     * 
207
     * @since       3.0.0               Changed the scope to public from protected.
208
     * @access      public
209
     * @remark      The actual registration will be performed in the `_replyToRegisterSettings()` method with the `admin_menu` hook.
210
     * @remark      The `$oForm` property should be created in each extended class.
211
     * @param       array|string        $aSection       the section array. If a string is passed, it is considered as a target page slug that will be used as a page slug element from the next call so that the element can be omitted.
0 ignored issues
show
Documentation introduced by
There is no parameter named $aSection. Did you maybe mean $aSectionset?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
212
     * <h4>Section Definition Array</h4>
213
     * <ul>
214
     *      <li>**section_id** - (string) the section ID. Avoid using non-alphabetic characters except underscore and numbers.</li>
215
     *      <li>**title** - (optional, string) the title of the section.</li>
216
     *      <li>**capability** - (optional, string) the <a href="http://codex.wordpress.org/Roles_and_Capabilities">access level</a> of the section. If the page visitor does not have sufficient capability, the section will be invisible to them.</li>
217
     *      <li>**if** - (optional, boolean) if the passed value is false, the section will not be registered.</li>
218
     *      <li>**order** - (optional, integer) the order number of the section. The higher the number is, the lower the position it gets.</li>
219
     *      <li>**help** - (optional, string) the help description added to the contextual help tab.</li>
220
     *      <li>**help_aside** - (optional, string) the additional help description for the side bar of the contextual help tab.</li>
221
     *      <li>**section_tab_slug** - (optional, string) the unique section tab slug to display the section in a tabbed container with other sections that have the same section tab slug.</li>
222
     *      <li>**hidden** - (optional, boolean) [3.3.1+] whether or not the section should be hidden. Default: <code>false</code>.</li>
223
     *      <li>**attributes** - (optional, string) [3.3.1+] An attribute array that applies to the section container element. e.g. `array( 'data-custom_data' => 'my_custom_data' )` The following sub-elements are supported.
224
     *          <ul>
225
     *              <li>**tab** - (optional, array) An sub-attribute array that applies to the section tab `<li>` tag element.</li>
226
     *          </ul>
227
     *      </li>
228
     *      <li>**class** - (optional, array) [3.3.1+] class selector(s) appended to the section container element. The following sub-elements are supported.
229
     *          <ul>
230
     *              <li>**tab** - (optional, array) An sub-class array that applies to the section tab `<li>` tag element.</li>
231
     *          </ul>
232
     *      </li>
233
     *      <li>**collapsible** - (optional, array) [3.4.0+] class selector(s) appended to the section container element. The following sub-elements are supported.
234
     *          <ul>
235
     *              <li>**title** - (optional, string) the section title will be assigned by default in the section formatting method.</li>
236
     *              <li>**is_collapsed** - (optional, boolean) whether it is already collapsed or expanded.</li>
237
     *              <li>**toggle_all_button** - (optional, boolean|string|array) the position of where to display the toggle-all button that toggles the folding state of all collapsible sections. Accepts the following values. 'top-right', 'top-left', 'bottom-right', 'bottom-left'. If true is passed, the default 'top-right' will be used. To not to display, do not set any or pass `false` or `null`.</li>
238
     *              <li>**collapse_others_on_expand** - (optional, boolean) whether the other collapsible sections should be folded when the section is unfolded. If the below `container` argument is set to `section`, this argument value does not take effect.</li>
239
     *              <li>**container** - (optional, string) the container element that collapsible styling gets applied to. Either 'sections' or 'section' is accepted. Use 'section' for repeatable sections.</li>
240
     *              <li>**type** - [DEVVER+] (optional, string) either `box` or `button`. Default: `box`. The `button` type only is supported when the `container` argument is set to `section`.</li>
241
     *          </ul>
242
     * `
243
     * $this->addSettingSections(
244
     *      array(
245
     *          'section_id'        => 'collapsible_repeatable_section',
246
     *          'title'             => __( 'Collapsible Repeatable Section', 'admin-page-framework-demo' ),
247
     *          'collapsible'       => array(
248
     *              'toggle_all_button' => array( 'top-left', 'bottom-left' ),
249
     *              'container'         => 'section',
250
     *          ),
251
     *          'repeatable'        => true,
252
     *      )
253
     *  );
254
     * `
255
     *      </li>
256
     *      <li>**sortable** - (optional, boolean) [3.6.0+] whether the section is sortable or not. In order for this option to be effective, the `repeatable` argument must be enabled.</li>
257
     *      <li>**content** - (optional, string) [3.6.1+] a custom section output.</li>
258
     *      <li>**tip** - (optional, string) [DEVVER+] a tool tip which pops up when the user hovers their mouse over the ? mark icon beside the title..</li>
259
     * </ul>
260
     * @return      void
261
     */
262
    public function addSettingSection( $aSectionset ) {
263
        
264
        if ( ! is_array( $aSectionset ) ) { 
265
            return; 
266
        }
267
        
268
        $this->_sTargetSectionTabSlug = $this->oUtil->getElement(
269
            $aSectionset,
270
            'section_tab_slug',
271
            $this->_sTargetSectionTabSlug
272
        );
273
        $aSectionset[ 'section_tab_slug' ] = $this->oUtil->getAOrB(
274
            $this->_sTargetSectionTabSlug,
275
            $this->_sTargetSectionTabSlug,
276
            null
277
        );
278
                
279
        $this->oForm->addSection( $aSectionset );
280
            
281
    }     
282
        
283
    /**
284
    * Adds form fields.
285
    * 
286
    * It inserts the given field definition arrays into the class property and later they are parsed when fields are registered. The field definition array requires specific keys. Refer to the parameter section of this method.
287
    * 
288
    * @since        2.0.0
289
    * @since        3.5.3       Removed the parameter declarations as they are caught with the func_get_args().
290
    * @remark       Accepts variadic parameters; the number of accepted parameters are not limited to three.
291
    * @param        array       the field definition array.
292
    * @param        array       (optional) another field array.
293
    * @param        array       (optional) add more field arrays to the next parameters as many as necessary.
294
    * @return       void
295
    */ 
296
    public function addSettingFields( /* $aField1, $aField2=null, $_and_more=null */ ) {
1 ignored issue
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
297
        foreach( func_get_args() as $_aFieldset ) { 
298
            $this->addSettingField( $_aFieldset ); 
299
        }
300
    }    
301
        
302
    /**
303
     * Adds the given field array items into the field array property.
304
     * 
305
     * Identical to the addSettingFields() method except that this method does not accept enumerated parameters. 
306
     * 
307
     * <h4>Examples</h4>
308
     * <code>
309
     *         $this->addSettingField(
310
     *             array(
311
     *                 'field_id'    => 'metabox_text_field',
312
     *                 'type'        => 'text',
313
     *                 'title'       => __( 'Text Input', 'admin-page-framework-demo' ),
314
     *                 'description' => __( 'The description for the field.', 'admin-page-framework-demo' ),
315
     *                 'help'        => 'This is help text.',
316
     *                 'help_aside'  => 'This is additional help text which goes to the side bar of the help pane.',
317
     *             )
318
     *         );    
319
     * </code>
320
     * 
321
     * @since        2.1.2
322
     * @since        3.0.0   The scope changed to public to indicate the users will use.
323
     * @return       void
324
     * @remark       The $oForm property should be created in each extended class.
325
     * @param        array|string       $asField        A field definition array or a string of the target section id.
0 ignored issues
show
Documentation introduced by
There is no parameter named $asField. Did you maybe mean $asFieldset?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
326
    * <h4>Built-in Field Types</h4>
327
    * <ul>
328
    *       <li>**text** - a normal field to enter text input.</li>
329
    *       <li>**password** - a masked text input field.</li>
330
    *       <li>**textarea** - a text input field with multiple lines. It supports rich text editor.</li>
331
    *       <li>**radio** - a set of radio buttons that lets the user pick an option.</li>
332
    *       <li>**checkbox** - a check box that lets the user enable/disable an item.</li>
333
    *       <li>**select** - a drop-down list that lest the user pick one or more item(s) from a list.</li>
334
    *       <li>**hidden** - a hidden field that will be useful to insert invisible values.</li>
335
    *       <li>**file** - a file uploader that lets the user upload files.</li>
336
    *       <li>**image** - a custom text field with the image uploader script that lets the user set the image URL.</li>
337
    *       <li>**media** - a custom text field with the media uploader script that lets the user set the file URL.</li>
338
    *       <li>**color** - a custom text field with the color picker script.</li>
339
    *       <li>**submit** - a submit button that lets the user send the form.</li>
340
    *       <li>**export** - a custom submit field that lets the user export the stored data.</li>
341
    *       <li>**import** - a custom combination field of the file and the submit fields that let the user import data.</li>
342
    *       <li>**posttype** - a check-list of post types enabled on the site.</li>
343
    *       <li>**taxonomy** - a set of check-lists of taxonomies enabled on the site in a tabbed box.</li>
344
    *       <li>**size** - a combination field of the text and the select fields that let the user set sizes with a selectable unit.</li>
345
    *       <li>**section_title** - [3.0.0+] a text field type that will be placed in the section title so that it lets the user set the section title. Note that only one field with this field type is allowed per a section.</li>
346
    *       <li>**system** - [3.3.0+] a custom textara field that displays the system information including the PHP settings, the framework version, MySQL version etc.</li>
347
    * </ul>
348
    * <h4>Field Definition Array</h4>
349
    * <ul>
350
    *       <li>**field_id** - ( required, string) the field ID. Avoid using non-alphabetic characters except underscore and numbers.</li>
351
    *       <li>**type** - ( required, string) the type of the field. The supported types are listed below.</li>
352
    *       <li>**section_id** - (optional, string) the section ID that the field belongs to. If not set, the internal `_default` section ID will be assigned.</li>
353
    *       <li>**title** - (optional, string) the title of the section.</li>
354
    *       <li>**description** - (optional, string) the description of the field which is inserted into the after the input field tag.</li>
355
    *       <li>**tip** - (optional, string) the tip for the field which is displayed when the mouse is hovered over the field title.</li>
356
    *       <li>**capability** - (optional, string) the <a href="http://codex.wordpress.org/Roles_and_Capabilities">access level</a> of the section. If the page visitor does not have sufficient capability, the section will be invisible to them.</li>
357
    *       <li>**error_message** - (optional, string) the error message to display above the input field.</li>
358
    *       <li>**before_field** - (optional, string) the HTML string to insert before the input field output.</li>
359
    *       <li>**after_field** - (optional, string) the HTML string to insert after the input field output.</li>
360
    *       <li>**if** - (optional, boolean) if the passed value is false, the section will not be registered.</li>
361
    *       <li>**order** - (optional, integer) the order number of the section. The higher the number is, the lower the position it gets.</li>
362
    *       <li>**label** - (optional, string) the text label(s) associated with and displayed along with the input field. Some input types can ignore this key.</li>
363
    *       <li>**default** - (optional, string|array) the default value(s) assigned to the input tag's value attribute.</li>
364
    *       <li>**value** - (optional, string|array) the value(s) assigned to the input tag's `value` attribute to override the default and the stored value.</li>
365
    *       <li>**delimiter** - (optional, string) the HTML string that delimits multiple elements. This is available if the <var>label</var> key is passed as array. It will be enclosed in inline-block elements so the passed HTML string should not contain block elements.</li>
366
    *       <li>**before_input** - (optional, string) the HTML string inserted right before the input tag. It will be enclosed in the <code>label</code> tag so the passed HTML string should not contain block elements.</li>
367
    *       <li>**after_input** - (optional, string) the HTML string inserted right after the input tag. It will be enclosed in the <code>label</code> tag so the passed HTML string should not contain block elements.</li>
368
    *       <li>**label_min_width** - (optional, string) the inline style property of the `min-width` of the label tag for the field. If the unit is not specified, 'px' is applied. Default: `120`. e.g. `100%`</li> 
369
    *       <li>**help** - (optional, string) the help description added to the contextual help tab.</li>
370
    *       <li>**help_aside** - (optional, string) the additional help description for the side bar of the contextual help tab.</li>
371
    *       <li>**repeatable** - [3.0.0+] (optional, array|boolean) whether the fields should be repeatable. If it yields true, the plus and the minus buttons appear next to each field that lets the user add/remove the fields. Optionally an setting array can be passed.
372
    *           <h5>Repeatable Fields Setting Array</h5>
373
    *           <ul>
374
    *                 <li>**max** - the allowed maximum number of fields to be repeated.</li>
375
    *                 <li>**min** - the allowed minimum number of fields to be repeated.</li>
376
    *           </ul>
377
    *       </li>
378
    *       <li>**sortable** - [3.0.0+] (optional, boolean) whether the fields should be sortable. If it yields true, the fields will be enclosed in a draggable box.
379
    *       <li>**attributes** - [3.0.0+] (optional, array) holds key-value pairs representing the attribute and its property. Note that some field types have specific keys in the first dimensions. e.g. `array( 'class' => 'my_custom_class_selector', 'style' => 'background-color:#777', 'size' => 20, )` Every field holds the following nested attribute definition arrays.
380
    *           <ul>
381
    *               <li>**fieldrow** - the `td` tag element containing the field output.</li>
382
    *               <li>**fieldset** - the `fieldset` tag element containing the field output.</li>
383
    *               <li>**fields** - the `div` tag element containing the sub-fields and the main field.</li>
384
    *               <li>**field** - the `div` tag element containing each field.</li>
385
    *           </ul>
386
    *       </li>
387
    *       <li>**show_title_column** - [3.0.0+] (optional, boolean) If true, the field title column will be omitted from the output.</li>
388
    *       <li>**hidden** - [3.0.0+] (optional, boolean) If true, the entire field row output will be invisible with the inline style attribute of `style="display:none"`.</li>
389
    *       <li>**save** - [3.6.0+] (optional, boolean) If `false`, the field value will not be saved. Default: `true`</li>
390
    *       <li>**content** - (optional, string) [3.6.1+] a custom section output.</li>
391
    * </ul>
392
    * 
393
    * <h4>Field Type Specific Arguments</h4>
394
    * <p>Each field type uses specific array arguments.</p>
395
    * <ul>
396
    *       <li>**text** - a text input field which allows the user to type text.</li>
397
    *       <li>**password** - a password input field which allows the user to type text.</li>
398
    *       <li>**number, range** - HTML5 input field types. Some browsers do not support these.</li>
399
    *       <li>**textarea** - a textarea input field. The following array keys are supported.
400
    *           <ul>
401
    *               <li>**rich** - [2.1.2+] (optional, array) to make it a rich text editor pass a non-empty value. It accept a setting array of the <code>_WP_Editors</code> class defined in the core.
402
    * For more information, see the argument section of <a href="http://codex.wordpress.org/Function_Reference/wp_editor" target="_blank">this page</a>.
403
    *               </li>
404
    *           </ul>
405
    *       </li>
406
    *       <li>**radio** - a radio button input field.</li>
407
    *       <li>**checkbox** - a check box input field.</li>
408
    *           <ul>
409
    *               <li>**select_all_button** - [3.3.0+] (optional, array) pass `true` to enable the `Select All` button. To set a custom label, set the text such as `__( 'Check All', 'test-domain' )`. Default: `true`.</li>
410
    *               <li>**select_none_button** - [3.3.0+] (optional, array) pass `true` to enable the `Select None` button. To set a custom label, set the text such as `__( 'Check All', 'test-domain' )`. Default: `true`.</li>
411
    *           </ul>
412
    *       <li>**select** - a drop-down input field.
413
    *           <ul>
414
    *               <li>**is_multiple** - (optional, boolean) if this is set to true, the `multiple` attribute will be inserted into the field input tag, which enables the multiple selections for the user.</li>
415
    *           </ul>
416
    *       </li>
417
    *       <li>**size** - a size input field. This is a combination of number and select fields.
418
    *           <ul>
419
    *               <li>
420
    *                   **units** - (optional, array) defines the units to show. e.g. `array( 'px' => 'px', '%' => '%', 'em' => 'em'  )` 
421
    *                   Default: `array( 'px' => 'px', '%' => '%', 'em' => 'em', 'ex' => 'ex', 'in' => 'in', 'cm' => 'cm', 'mm' => 'mm', 'pt' => 'pt', 'pc' => 'pc' )`
422
    *               </li>
423
    *               <li>**is_multiple** - (optional, boolean) if this is set to true, the `multiple` attribute will be inserted into the field input tag, which enables the multiple selections for the user.</li>
424
    *               <li>**attributes** - [3.0.0+] (optional, array) The attributes array of this field type has four initial keys: size, unit, optgroup, and option and they have a regular attribute array in each.</li>
425
    *           </ul>
426
    *       </li>
427
    *       <li>**hidden** - a hidden input field.</li>
428
    *       <li>**file** - a file upload input field.</li>
429
    *       <li>**submit** - a submit button input field.
430
    *           <ul>
431
    *               <li>**href** - (optional, string) the url(s) linked to the submit button.</li>
432
    *               <li>**redirect_url** - (optional, string) the url(s) redirected to after submitting the input form.</li>
433
    *               <li>**reset** - [2.1.2+] (optional, boolean|string|array) the option key to delete. Set 1 for the entire option. [3.5.3+] In order to reset a particular field that belongs to a section, set an array representing the dimensional keys such as `array( 'my_sectio_id', 'my_field_id' )`.</li>
434
    *               <li>**email** - [3.3.0+] (optional, array) Coming soon...
435
    *                   <ul>
436
    *                       <li>**to** - (string|array) the email address to send the email to. For multiple email addressed, set comma delimited items.</li>
437
    *                       <li>**subject** - (string|array) the email title.</li>
438
    *                       <li>**message** - (string|array) the email body text.</li>
439
    *                       <li>**attachments** - (string|array) the file path.</li>
440
    *                       <li>**name** - (string|array) the sender name.</li>
441
    *                       <li>**from** - (string|array) the sender email.</li>
442
    *                       <li>**is_html** - (boolean|array) indicates whether the message should be sent as an html or plain text.</li>
443
    *                   </ul>
444
    *               </li>
445
    *           </ul>
446
    *       </li>
447
    *       <li>**import** - an import input field. This is a custom file and submit field.
448
    *           <ul>
449
    *               <li>**option_key** - (optional, string) the option table key to save the importing data.</li>
450
    *               <li>**format** - (optional, string) the import format. json, or array is supported. Default: array</li>
451
    *               <li>**is_merge** - (optional, boolean) [2.0.5+] determines whether the imported data should be merged with the existing options.</li>
452
    *           </ul>
453
    *       </li>
454
    *       <li>**export** - an export input field. This is a custom submit field.
455
    *           <ul>
456
    *               <li>**file_name** - (optional, string) the file name to download.</li>
457
    *               <li>**format** - (optional, string) the format type. array, json, or text is supported. Default: array.</li>
458
    *               <li>**data** - (optional, string|array|object ) the data to export.</li>
459
    *           </ul>
460
    *       </li>
461
    *       <li>**image** - an image input field. This is a custom text field with an attached JavaScript script.
462
    *           <ul>
463
    *               <li>**show_preview** - (optional, boolean) if this is set to false, the image preview will be disabled.</li>
464
    *               <li>**attributes_to_store** - [2.1.3+] (optional, array) the array of the attribute names of the image to save. If this is set, the field will be an array with the specified attributes. The supported attributes are, 'title', 'alt', 'width', 'height', 'caption', 'id', 'align', and 'link'. Note that for external URLs, ID will not be captured. e.g. `'attributes_to_store' => array( 'id', 'caption', 'description' )`</li>
465
    *               <li>**allow_external_source** - [2.1.3+] (optional, boolean) whether external URL can be set via the uploader.</li>
466
    *               <li>**attributes** - [3.0.0+] (optional, array) The attributes array of this field type has three keys: input, button, and preview and they have a regular attribute array in each.</li>
467
    *           </ul>
468
    *       </li>
469
    *       <li>**media** - [2.1.3+] a media input field. This is a custom text field with an attached JavaScript script.
470
    *           <ul>
471
    *               <li>**attributes_to_store** - [2.1.3+] (optional, array) the array of the attribute names of the image to save. If this is set, the field will be an array with the specified attributes. The supported attributes are, 'id', 'caption', and 'description'. Note that for external URLs, ID will not be captured. e.g. `'attributes_to_store' => array( 'id', 'caption', 'description' )`</li>
472
    *               <li>**allow_external_source** - [2.1.3+] (optional, boolean) whether external URL can be set via the uploader.</li>
473
    *           </ul>
474
    *       </li>
475
    *       <li>**color** - a color picker input field. This is a custom text field with a JavaScript script.</li>
476
    *       <li>**taxonomy** - a taxonomy check list. This is a set of check boxes listing a specified taxonomy. This does not accept to create multiple fields by passing an array of labels.
477
    *           <ul>
478
    *               <li>**taxonomy_slugs** - (optional, array) the taxonomy slug to list.</li>
479
    *               <li>**max_width** - (optional, string) the inline style property value of `max-width` of this element. Include the unit such as px, %. Default: 100%</li>
480
    *               <li>**height** - (optional, string) the inline style property value of `height` of this element. Include the unit such as px, %. Default: 250px</li>
481
    *               <li>**select_all_button** - [3.3.0+] (optional, array) pass `true` to enable the `Select All` button. To set a custom label, set the text such as `__( 'Check All', 'test-domain' )`. Default: `true`.</li>
482
    *               <li>**select_none_button** - [3.3.0+] (optional, array) pass `true` to enable the `Select None` button. To set a custom label, set the text such as `__( 'Check All', 'test-domain' )`. Default: `true`.</li>
483
    *               <li>**label_no_term_found** - [3.3.2+] (optional, string) The label to display when no term is found. Default: `No Term Found`.</li>
484
    *               <li>**label_list_title** - [3.3.2+] (optional, string) The heading title string for a term list. Default: `''`. Insert an HTML custom string right before the list starts.</li>
485
    *               <li>**query** - [3.3.2+] (optional, array) the query array to search terms. For more details, see the argument of the [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms#Parameters) function.
486
    *                   <ul>
487
    *                       <li>child_of - (integer) The parent term ID. All the descendant terms such as child's child term will be listed. default: `0`</li>
488
    *                       <li>parent   - (integer) The direct parent term ID. Only the first level children will be listed. default: ``</li>
489
    *                       <li>orderby - (string) The type of how the term list should be ordered by. Either `ID`, `term_id`, or `name` can be accepted. Default: `name`.</li>
490
    *                       <li>order - (string) The order of the list. `ASC` or `DESC`. Default: `ASC`.</li>
491
    *                       <li>hide_empty - (boolean) whether to show the terms with no post associated. Default: `false`.</li>
492
    *                       <li>hierarchical - (boolean) whether to show the terms as a hierarchical tree. Default: `true`</li>
493
    *                       <li>number - (integer) The maximum number of the terms to show. 0 for no limit. Default: `0`.</li>
494
    *                       <li>pad_counts - (boolean) whether to sum up the post counts with the child post counts. Default: `false`</li>
495
    *                       <li>exclude - (string|array) Comma separated term IDs or an array to exclude from the list. for example `1` will remove the 'Uncategorized' category from the list. </li>
496
    *                       <li>exclude_tree - (integer) For more details see [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms#Parameters)..</li>
497
    *                       <li>include - (string|array) Comma separated term IDs to include in the list.</li>
498
    *                       <li>fields - (string) Default: `all`. For more details see [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms#Parameters).</li>
499
    *                       <li>slug - (string) Default: ``. For more details see [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms#Parameters).</li>
500
    *                       <li>get - (string) Default ``. For more details see [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms#Parameters).</li>
501
    *                       <li>name__like - (string) Default ``. For more details see [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms#Parameters).</li>
502
    *                       <li>description__like - (string) Default ``. For more details see [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms#Parameters).</li>
503
    *                       <li>offset - (integer) Default ``. For more details see [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms#Parameters).</li>
504
    *                       <li>search - (string) The search keyword to get the term with. Default ``.</li>
505
    *                       <li>cache_domain - (string) Default:`core`. For more details see [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms#Parameters).</li>
506
    *                   </ul>
507
    *               </li>
508
    *               <li>**queries** - [3.3.2+] (optional, array) Allows to set a query argument for each taxonomy. The array key must be the taxonomy slug and the value is the query argument array.</li>
509
    *           </ul>
510
    *           <h4>Example</h4>
511
    * <pre><code>array(  
512
    *     'field_id'              => 'taxonomy_custom_queries',
513
    *     'title'                 => __( 'Custom Taxonomy Queries', 'admin-page-framework-demo' ),
514
    *     'type'                  => 'taxonomy',
515
    *     'description'           => 
516
    *         array(
517
    *             __( 'With the <code>query</code> argument array, you can customize how the terms should be retrieved.', 'admin-page-framework-demo' ),
518
    *             sprintf( __( 'For the structure and the array key specifications, refer to the parameter section of the <a href="%1$s" target="_blank">get_term()</a> function.', 'admin-page-framework-demo' ), 'http://codex.wordpress.org/Function_Reference/get_terms#Parameters' ),
519
    *         ),
520
    *     
521
    *     // (required)   Determines which taxonomies should be listed
522
    *     'taxonomy_slugs'        => $aTaxnomies = get_taxonomies( '', 'names' ),    
523
    *         
524
    *     // (optional) This defines the default query argument. For the structure and supported arguments, see http://codex.wordpress.org/Function_Reference/get_terms#Parameters
525
    *     'query'                 => array(
526
    *         'depth'     => 2,
527
    *         'orderby'   => 'term_id',       // accepts 'ID', 'term_id', or 'name'
528
    *         'order'     => 'DESC',
529
    *         // 'exclude'   => '1', // removes the 'Uncategorized' category.
530
    *         // 'search' => 'PHP',   // the search keyward
531
    *         // 'parent'    => 9,    // only show terms whose direct parent ID is 9.
532
    *         // 'child_of'  => 8,    // only show child terms of the term ID of 8.
533
    *     ),
534
    *     // (optional) This allows to set a query argument for each taxonomy. 
535
    *     // Note that each element will be merged with the above default 'query' argument array. 
536
    *     // So unset keys here will be overridden by the default argument array above. 
537
    *     'queries'               => array(
538
    *         // taxonomy slug => query argument array
539
    *         'category'  =>  array(
540
    *             'depth'     => 2,
541
    *             'orderby'   => 'term_id',  
542
    *             'order'     => 'DESC',
543
    *             'exclude'   => array( 1 ), 
544
    *         ),
545
    *         'post_tag'  => array(
546
    *             'orderby'   => 'name',
547
    *             'order'     => 'ASC',
548
    *             // 'include'   => array( 4, ), // term ids
549
    *         ),
550
    *     ), 
551
    * ),
552
    * </code></pre>
553
    *       </li>
554
    *       <li>**posttype** - a post-type check list. This is a set of check boxes listing post type slugs.
555
    *           <ul>
556
    *               <li>**slugs_to_remove** - (optional, array) the post type slugs not to be listed. e.g.`array( 'revision', 'attachment', 'nav_menu_item' )`</li>
557
    *               <li>**select_all_button** - [3.3.0+] (optional, array) pass `true` to enable the `Select All` button. To set a custom label, set the text such as `__( 'Check All', 'test-domain' )`. Default: `true`.</li>
558
    *               <li>**select_none_button** - [3.3.0+] (optional, array) pass `true` to enable the `Select None` button. To set a custom label, set the text such as `__( 'Check All', 'test-domain' )`. Default: `true`.</li>
559
    *           </ul>
560
    *       </li>
561
    *       <li>**system** - [3.3.0+] a custom textara field that displays system information.
562
    *           <ul>
563
    *               <li>**data** - (optional, array) an associative array ta that holds the data to display.</li>
564
    *               <li>**print_type** - [3.3.6+] (optional, integer) Indicates how the data array should be displayed. 1: readable array representation. 2. the output of the print_r() function. Default: `1`.</li>
565
    *           </ul>
566
    *       </li>
567
    * </ul>    
568
     */     
569
    public function addSettingField( $asFieldset ) {
570
        if ( method_exists( $this->oForm, 'addField' ) ) {
571
            $this->oForm->addField( $asFieldset );     
572
        }
573
    }
574
    
575
    /**
576
     * Sets the field error array. 
577
     * 
578
     * This is normally used in validation callback methods when the submitted user's input data have an issue.
579
     * This method saves the given array in a temporary area (transient) of the options database table.
580
     * 
581
     * <h4>Example</h4>
582
     * <code>
583
     * public function validation_APF_Demo_verify_text_field_submit( $aNewInput, $aOldOptions ) {
584
     *
585
     *      // 1. Set a flag.
586
     *      $bVerified = true;
587
     *          
588
     *      // 2. Prepare an error array. 
589
     *      $aErrors = array();
590
     *      
591
     *      // 3. Check if the submitted value meets your criteria.
592
     *      if ( ! is_numeric( $aNewInput[ 'verify_text_field' ] ) ) {
593
     *          $aErrors[ 'verify_text_field' ] = __( 'The value must be numeric:', 'admin-page-framework-demo' ) 
594
     *              . $aNewInput[ 'verify_text_field' ];
595
     *          $bVerified = false;
596
     *      }
597
     *    
598
     *      // 4. An invalid value is found.
599
     *      if ( ! $bVerified ) {
600
     *  
601
     *          // 4-1. Set the error array for the input fields.
602
     *          $this->setFieldErrors( $aErrors );     
603
     *          $this->setSettingNotice( 'There was an error in your input.' );
604
     *          return $aOldOptions;
605
     * 
606
     *      }
607
     *     
608
     *      return $aNewInput;     
609
     *
610
     * }
611
     * </code>
612
     * 
613
     * @since   3.0.4     
614
     * @param   array   $aErrors     the field error array. The structure should follow the one contained in the submitted `$_POST` array.
615
     */    
616
    public function setFieldErrors( $aErrors ) {
617
        $this->oForm->setFieldErrors( $aErrors );      
618
/*         // The field-errors array will be stored in this global array element.
1 ignored issue
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
619
        $GLOBALS[ 'aAdminPageFramework' ][ 'aFieldErrors' ] = $this->oUtil->getElement( 
620
            $GLOBALS,  // subject array
621
            array( 'aAdminPageFramework', 'aFieldErrors' ), // key
622
            array()      // default
623
        );                    
624
625
        if ( empty( $GLOBALS[ 'aAdminPageFramework' ][ 'aFieldErrors' ] ) ) {
626
            add_action( 'shutdown', array( $this, '_replyToSaveFieldErrors' ) ); // the method is defined in the controller class.
627
        }
628
        
629
        $_sID = md5( $this->oProp->sClassName );
630
        $GLOBALS[ 'aAdminPageFramework' ][ 'aFieldErrors' ][ $_sID ] = isset( $GLOBALS[ 'aAdminPageFramework' ][ 'aFieldErrors' ][ $_sID ] )
631
            ? $this->oUtil->uniteArrays( 
632
                $GLOBALS[ 'aAdminPageFramework' ][ 'aFieldErrors' ][ $_sID ], 
633
                $aErrors 
634
            )
635
            : $aErrors;                   
636
     */
637
    }   
638
    
639
    /**
640
     * Check whether a user has set a field error(s) or not.
641
     * 
642
     * @since       3.3.0
643
     * @return      boolean     Whether or not a field error exists.
644
     */
645
    public function hasFieldError() {
646
        return $this->oForm->hasFieldError();
647
        // @deprecated  DEVVER
648
        // return isset( $GLOBALS[ 'aAdminPageFramework' ][ 'aFieldErrors' ][ md5( $this->oProp->sClassName ) ] );
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
649
    }
650
    
651
    /**
652
    * Sets the given message to be displayed in the next page load. 
653
    * 
654
    * This is used to inform users about the submitted input data, such as "Updated successfully." or "Problem occurred." etc. 
655
    * and normally used in validation callback methods.
656
    * 
657
    * <h4>Example</h4>
658
    * `
659
    * if ( ! $bVerified ) {
660
    *       $this->setFieldErrors( $aErrors );     
661
    *       $this->setSettingNotice( 'There was an error in your input.' );
662
    *       return $aOldPageOptions;
663
    * }
664
    * `
665
    *
666
    * @since        3.0.4     
667
    * @access       public
668
    * @param        string      $sMessage       the text message to be displayed.
669
    * @param        string      $sType          (optional) the type of the message, either "error" or "updated"  is used.
670
    * @param        array       $asAttributes   (optional) the tag attribute array applied to the message container HTML element. If a string is given, it is used as the ID attribute value.
671
    * @param        boolean     $bOverride      (optional) If true, only one message will be shown in the next page load. false: do not override when there is a message of the same id. true: override the previous one.
672
    * @return       void
673
    */      
674
    public function setSettingNotice( $sMessage, $sType='error', $asAttributes=array(), $bOverride=true ) {
675
        $this->oForm->setSubmitNotice(
676
            $sMessage,
677
            $sType,
678
            $asAttributes,
679
            $bOverride
680
        );        
681
    }
682
    
683
    /**
684
     * Checks if an error settings notice has been set.
685
     * 
686
     * This is used in the internal validation callback method to decide whether the system error or update notice should be added or not.
687
     * If this method yields true, the framework discards the system message and displays the user set notification message.
688
     * 
689
     * @since       3.1.0
690
     * @param       string      $sType If empty, the method will check if a message exists in all types. Otherwise, it checks the existence of a message of the specified type.
691
     * @return      boolean     True if a setting notice is set; otherwise, false.
692
     */
693
    public function hasSettingNotice( $sType='' ) {
694
        return $this->oForm->hasSubmitNotice( $sType );
695
    }
696
697
}