PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / 0.8
Advanced Custom Fields: Extended v0.8
0.9.2.6 0.9.2.5 0.8.6 0.8.6.1 0.8.6.3 0.8.6.5 0.8.6.6 0.8.6.7 0.8.6.8 0.8.6.9 0.8.7 0.8.7.1 0.8.7.2 0.8.7.3 0.8.7.4 0.8.7.5 0.8.7.6 0.8.8 0.8.8.1 0.8.8.10 0.8.8.11 0.8.8.2 0.8.8.3 0.8.8.4 0.8.8.5 0.8.8.6 0.8.8.7 0.8.8.8 0.8.8.9 0.8.9 0.8.9.1 0.8.9.2 0.8.9.3 0.8.9.4 0.8.9.5 0.9 0.9.0.1 0.9.0.2 0.9.0.3 0.9.0.4 0.9.0.5 0.9.0.6 0.9.0.7 0.9.0.8 0.9.0.9 0.9.1 0.9.1.1 0.9.2 0.9.2.1 0.9.2.2 0.9.2.3 0.9.2.4 trunk 0.5 0.5.1 0.5.2 0.5.2.1 0.5.2.3 0.5.5 0.5.5.1 0.5.8 0.5.8.1 0.6 0.6.0.1 0.6.0.2 0.6.1 0.6.3 0.6.5 0.6.7 0.6.7.2 0.7 0.7.0.3 0.7.5 0.7.5.5 0.7.8 0.7.9 0.7.9.3 0.7.9.4 0.7.9.9.8 0.7.9.9.9 0.8 0.8.1 0.8.2 0.8.3 0.8.3.1 0.8.4 0.8.4.1 0.8.4.5 0.8.4.6 0.8.5 0.8.5.5
acf-extended / includes / fields / field-button.php
acf-extended / includes / fields Last commit date
field-advanced-link.php 6 years ago field-button.php 6 years ago field-clone.php 6 years ago field-column.php 6 years ago field-dynamic-message.php 6 years ago field-file.php 6 years ago field-flexible-content.php 6 years ago field-forms.php 6 years ago field-group.php 6 years ago field-hidden.php 6 years ago field-image.php 6 years ago field-post-statuses.php 6 years ago field-post-types.php 6 years ago field-recaptcha.php 6 years ago field-repeater.php 6 years ago field-select.php 6 years ago field-slug.php 6 years ago field-taxonomies.php 6 years ago field-taxonomy-terms.php 6 years ago field-textarea.php 6 years ago field-user-roles.php 6 years ago
field-button.php
201 lines
1 <?php
2
3 if(!defined('ABSPATH'))
4 exit;
5
6 class acfe_field_button extends acf_field{
7
8 function __construct(){
9
10 $this->name = 'acfe_button';
11 $this->label = __('Button', 'acfe');
12 $this->category = 'basic';
13 $this->defaults = array(
14 'button_value' => __('Submit', 'acfe'),
15 'button_type' => 'button',
16 'button_before' => '',
17 'button_after' => '',
18 'button_class' => '',
19 'button_id' => '',
20 );
21
22 parent::__construct();
23
24 }
25
26 function render_field_settings($field){
27
28 // Value
29 acf_render_field_setting($field, array(
30 'label' => __('Button value', 'acfe'),
31 'instructions' => __('Set a default button value', 'acfe'),
32 'type' => 'text',
33 'name' => 'button_value',
34 'default_value' => __('Submit', 'acfe')
35 ));
36
37 // Type
38 acf_render_field_setting($field, array(
39 'label' => __('Button value', 'acfe'),
40 'instructions' => __('Choose the button type', 'acfe'),
41 'type' => 'radio',
42 'name' => 'button_type',
43 'default_value' => 'button',
44 'layout' => 'horizontal',
45 'choices' => array(
46 'button' => __('Button', 'acfe'),
47 'submit' => __('Submit', 'acfe'),
48 ),
49 ));
50
51 // class
52 acf_render_field_setting($field, array(
53 'label' => __('Button attributes','acf'),
54 'instructions' => '',
55 'type' => 'text',
56 'name' => 'button_class',
57 'prepend' => __('class', 'acf'),
58 ));
59
60 // id
61 acf_render_field_setting($field, array(
62 'label' => '',
63 'instructions' => '',
64 'type' => 'text',
65 'name' => 'button_id',
66 'prepend' => __('id', 'acf'),
67 '_append' => 'button_class'
68 ));
69
70 // Before HTML
71 acf_render_field_setting($field, array(
72 'label' => __('Before HTML', 'acfe'),
73 'instructions' => __('Custom HTML before the button', 'acfe'),
74 'type' => 'textarea',
75 'name' => 'button_before',
76 'rows' => 4,
77 ));
78
79 // After HTML
80 acf_render_field_setting($field, array(
81 'label' => __('After HTML', 'acfe'),
82 'instructions' => __('Custom HTML after the button', 'acfe'),
83 'type' => 'textarea',
84 'name' => 'button_after',
85 'rows' => 4,
86 ));
87
88 // Ajax
89 acf_render_field_setting($field, array(
90 'label' => __('Ajax call', 'acfe'),
91 'instructions' => __('Trigger ajax event on click', 'acfe'),
92 'name' => 'button_ajax',
93 'type' => 'true_false',
94 'ui' => 1,
95 ));
96
97 ob_start();
98 ?>
99 Write your own Ajax code using the following hook:<br /><br />
100 <pre>
101 add_action('wp_ajax_acfe/fields/button', 'my_acf_button_ajax');
102 add_action('wp_ajax_nopriv_acfe/fields/button', 'my_acf_button_ajax');
103 function my_acf_button_ajax(){
104
105 /**
106 * @bool/string $_POST['post_id'] Current post ID
107 * @string $_POST['field_key'] Button's field key
108 * @string $_POST['field_name'] Button's field name
109 */
110
111 echo 'Hello World';
112 die;
113
114 }
115 </pre>
116 <br />
117 You can get access to Javascript ajax call using the following JS hooks:<br /><br />
118 <pre>
119 acf.addAction('acfe/fields/button/before_ajax', function($el){
120 // $el
121 });
122
123 acf.addAction('acfe/fields/button/ajax_success', function(response, $el){
124 // response
125 // $el
126 });
127 </pre>
128 <?php
129
130 $message = ob_get_clean();
131
132 // ajax instructions
133 acf_render_field_setting($field, array(
134 'label' => __('Ajax instructions','acf'),
135 'instructions' => '',
136 'type' => 'message',
137 'name' => 'instructions',
138 'message' => $message,
139 'new_lines' => false,
140 'conditional_logic' => array(
141 array(
142 array(
143 'field' => 'button_ajax',
144 'operator' => '==',
145 'value' => '1',
146 )
147 )
148 )
149 ));
150
151 }
152
153 function render_field($field){
154
155 // Before
156 if(isset($field['button_before']) && !empty($field['button_before'])){
157
158 echo $field['button_before'];
159
160 }
161
162 $ajax = false;
163 $button_ajax = $field['button_ajax'];
164
165 if($button_ajax)
166 $ajax = 'data-ajax="1"';
167
168 // Button
169 if($field['button_type'] === 'button'){
170
171 echo '<button
172 id="' . esc_attr($field['button_id']) . '"
173 class="' . esc_attr($field['button_class']) . '"
174 ' . $ajax . '
175 >' . esc_attr($field['button_value']) . '</button>';
176
177 // Submit
178 }elseif($field['button_type'] === 'submit'){
179
180 echo '<input
181 type="submit"
182 id="' . esc_attr($field['button_id']) . '"
183 class="' . esc_attr($field['button_class']) . '"
184 value="' . esc_attr($field['button_value']) . '"
185 ' . $ajax . '
186 />';
187
188 }
189
190 // After
191 if(isset($field['button_after']) && !empty($field['button_after'])){
192
193 echo $field['button_after'];
194
195 }
196
197 }
198
199 }
200
201 new acfe_field_button();