Getting Started

Code

Field
Features
Example 1
Example 2
Example 3
1
$this_field = $this_field_instance->this_field('my_field_id');
Copied!
1
// CREATE: $this_field to our desired field type via our $this_field_instance variable
2
$this_field = $this_field_instance->this_field('my_field_id');
3
4
// ASSIGN: our global field features
5
// NOTE: these features are available to all field types but are considered unique,
6
// like layout, style, dependency values and validation methods, etc...
7
$this_field->horizontal(true); // DEFAULT: false
8
$this_field->style('width: 100%;'); // DEFAULT: false
9
10
// ASSIGN: our unique field features
11
// NOTE: these features are only available to this field type
12
// CONTROLS: this_feature_method | DEFAULT: value
13
$this_field->this_feature_method();
Copied!
Function Method
1
// CALL: wponion/loaded action to load our my_function function
2
add_action('wponion/loaded', 'my_function');
3
4
// CREATE: my_function to load our field and module routine
5
function my_function() {
6
7
// CREATE: our wponion_builder variable instance
8
// NOTE: we always create a wponion_builder variable instance to boot any wponion feature,
9
// then we determine what to do with that instance and its stored arguments
10
$this_field_instance = wponion_builder();
11
12
// CREATE: $this_field to our desired field type via our $this_field_instance variable
13
$this_field = $this_field_instance->this_field('my_field_id');
14
15
// ASSIGN: our general field features
16
// NOTE: these features are available to ALL field types but are considered general,
17
// like title, text descriptions, debug, etc...
18
$this_field->title(__('My Field Label')); // DEFAULT: false
19
$this_field->desc(__('My field description...')); // DEFAULT: false
20
$this_field->desc_field(__('My field description...')); // DEFAULT: false
21
// $this_field->debug(true); // DEFAULT: false
22
23
// ASSIGN: our unique field features
24
// NOTE: these features are ONLY available to this field type
25
// CONTROLS: this_feature_method | DEFAULT: value
26
$this_field->this_feature_method();
27
28
// ASSIGN: our global field features
29
// NOTE: these features are available to ALL field types but are considered unique in their usage,
30
// like layout, custom css, dependency values and validation methods, etc...
31
$this_field->horizontal(true); // DEFAULT: false
32
$this_field->style('width: 100%;'); // DEFAULT: false
33
$this_field->help(array('content' => __('This field tooltip...'))); // DEFAULT: false
34
35
// CREATE: $this_module_instance options array
36
// NOTE: these options vary depending on the module output you choose
37
// like wponion_admin_page, wponion_metabox, wponion_taxonomy, etc...
38
$this_module_instance = array(
39
'metabox_title' => __('My Metabox Title'),
40
'metabox_id' => 'my-metabox-id',
41
'option_name' => 'my_metabox_name',
42
'screens' => array('post', 'page', 'product',),
43
'context' => 'normal',
44
'theme' => 'wp',
45
'ajax' => true,
46
);
47
48
// CALL: our wponion_metabox module
49
// NOTE: Here you can call your desired module method
50
// like wponion_admin_page, wponion_metabox, wponion_taxonomy, etc...
51
// We are passing our module settings and our various field settings into our desired module output
52
// NOTE: in a more real world use, $this_field_instance would contain multiple fields and their settings
53
// instead of the one field shown in our documentation demo
54
wponion_metabox($this_module_instance, $this_field_instance);
55
56
}
Copied!
Class Method
1
// IF: My_Class doesn't exist
2
if (!class_exists('My_Class')) {
3
4
// CALL: wponion/loaded action to load our My_Class class
5
add_action('wponion/loaded', function() {
6
7
// INSTANTIATE: My_Class
8
new My_Class();
9
10
});
11
12
// CREATE: My_Class class
13
final class My_Class {
14
15
// CREATE: our class constructor method
16
public function __construct() {
17
18
// CALL: my_function to load our field and module routine
19
$this->my_function();
20
21
}
22
23
// CREATE: my_function function to load our field and module routine
24
private function my_function() {
25
26
// CREATE: our wponion_builder variable instance
27
// NOTE: we always create a wponion_builder variable instance to boot any wponion feature,
28
// then we determine what to do with that instance and its stored arguments
29
$this_field_instance = wponion_builder();
30
31
// CREATE: $this_field to our desired field type via our $this_field_instance variable
32
$this_field = $this_field_instance->this_field('my_field_id');
33
34
// ASSIGN: our general field features
35
// NOTE: these features are available to ALL field types but are considered general,
36
// like title, text descriptions, debug, etc...
37
$this_field->title(__('My Field Label')); // DEFAULT: false
38
$this_field->desc(__('My field description...')); // DEFAULT: false
39
$this_field->desc_field(__('My field description...')); // DEFAULT: false
40
// $this_field->debug(true); // DEFAULT: false
41
42
// ASSIGN: our unique field features
43
// NOTE: these features are ONLY available to this field type
44
// CONTROLS: this_feature_method | DEFAULT: value
45
$this_field->this_feature_method();
46
47
// ASSIGN: our global field features
48
// NOTE: these features are available to ALL field types but are considered unique in their usage,
49
// like layout, custom css, dependency values and validation methods, etc...
50
$this_field->horizontal(true); // DEFAULT: false
51
$this_field->style('width: 100%;'); // DEFAULT: false
52
$this_field->help(array('content' => __('This field tooltip...'))); // DEFAULT: false
53
54
// CREATE: $this_module_instance options array
55
// NOTE: these options vary depending on the module output you choose
56
// like wponion_admin_page, wponion_metabox, wponion_taxonomy, etc...
57
$this_module_instance = array(
58
'metabox_title' => __('My Metabox Title'),
59
'metabox_id' => 'my-metabox-id',
60
'option_name' => 'my_metabox_name',
61
'screens' => array('post', 'page', 'product',),
62
'context' => 'normal',
63
'theme' => 'wp',
64
'ajax' => true,
65
);
66
67
// CALL: our wponion_metabox module
68
// NOTE: Here you can call your desired module method
69
// like wponion_admin_page, wponion_metabox, wponion_taxonomy, etc...
70
// We are passing our module settings and our various field settings into our desired module output
71
// NOTE: in a more real world use, $this_field_instance would contain multiple fields and their settings
72
// instead of the one field shown in our documentation demo
73
wponion_metabox($this_module_instance, $this_field_instance);
74
75
}
76
77
}
78
79
}
Copied!
External Method
1
// CALL: post_submitbox_misc_actions action to load our render_this_field_externally function
2
// NOTE: you can render a single wponion field into any custom wp do_action location
3
// NOTE: you must write your own saving methods when rendering a wponion field externally
4
add_action('post_submitbox_misc_actions', 'render_this_field_externally');
5
6
// CREATE: render_this_field_externally to load our field and module routine
7
// NOTE: our wpo_field function can only echo a single field at a time
8
// you cannot pass multiple field types into the final echo ..->render()
9
function render_this_field_externally() {
10
11
// CREATE: our wponion_builder variable instance
12
// NOTE: we always create a wponion_builder variable instance to boot any wponion feature,
13
// then we determine what to do with that instance and its stored arguments
14
$this_field_instance = wponion_builder();
15
16
// CREATE: $this_field to our desired field type via our $this_field_instance variable
17
$this_field = $this_field_instance->this_field('my_field_id');
18
19
// ASSIGN: our general field features
20
// NOTE: these features are available to ALL field types but are considered general,
21
// like title, text descriptions, debug, etc...
22
$this_field->title(__('My Field Label')); // DEFAULT: false
23
$this_field->desc(__('My field description...')); // DEFAULT: false
24
$this_field->desc_field(__('My field description...')); // DEFAULT: false
25
// $this_field->debug(true); // DEFAULT: false
26
27
// ASSIGN: our unique field features
28
// NOTE: these features are ONLY available to this field type
29
// CONTROLS: this_feature_method | DEFAULT: value
30
$this_field->this_feature_method();
31
32
// ASSIGN: our global field features
33
// NOTE: these features are available to ALL field types but are considered unique in their usage,
34
// like layout, custom css, dependency values and validation methods, etc...
35
$this_field->horizontal(true); // DEFAULT: false
36
$this_field->style('width: 100%;'); // DEFAULT: false
37
$this_field->help(array('content' => __('This field tooltip...'))); // DEFAULT: false
38
39
// CALL: our single field render method
40
// NOTE: we can only echo a single field at a time
41
// you cannot pass multiple field types into echo ->render()
42
echo $this_field->render('my-custom-name-value', 'my_option_name');
43
44
}
Copied!

Output

$this_field->multiple(false);

Notes

There are currently no extra notes for this operation.
Last modified 1yr ago
Export as PDF
Copy link