| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Custom ACF field for creating paged forms. Altered copy of the default tab field. |
| 5 |
* |
| 6 |
* @since 1.5.0 |
| 7 |
* |
| 8 |
*/ |
| 9 |
class AF_Page_Field extends acf_field { |
| 10 |
|
| 11 |
function initialize() { |
| 12 |
|
| 13 |
// vars |
| 14 |
$this->name = 'page'; |
| 15 |
$this->label = __( 'Page','advanced-forms' ); |
| 16 |
$this->category = 'Forms'; |
| 17 |
$this->defaults = array(); |
| 18 |
|
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
/* |
| 23 |
* render_field() |
| 24 |
* |
| 25 |
* Create the HTML interface for your field |
| 26 |
* |
| 27 |
* @param $field - an array holding all the field's data |
| 28 |
* |
| 29 |
* @type action |
| 30 |
* @since 3.6 |
| 31 |
* @date 23/01/13 |
| 32 |
*/ |
| 33 |
|
| 34 |
function render_field( $field ) { |
| 35 |
|
| 36 |
// vars |
| 37 |
$atts = array( |
| 38 |
'href' => '', |
| 39 |
'class' => 'af-page-button', |
| 40 |
'data-key' => $field['key'] |
| 41 |
); |
| 42 |
|
| 43 |
$atts['data-show-numbering'] = ! empty ( $field['show_numbering'] ) ? 'true' : 'false'; |
| 44 |
|
| 45 |
$previous_atts = array( 'class' => 'af-previous-button' ); |
| 46 |
$previous_atts = apply_filters( 'af/form/previous_button_atts', $previous_atts, $field ); |
| 47 |
if ( empty( $field['previous_text'] ) ) { |
| 48 |
$field['previous_text'] = __( 'Previous', 'advanced-forms' ); |
| 49 |
} |
| 50 |
|
| 51 |
$next_atts = array( 'class' => 'af-next-button' ); |
| 52 |
$next_atts = apply_filters( 'af/form/next_button_atts', $next_atts, $field ); |
| 53 |
if ( empty ( $field['next_text'] ) ) { |
| 54 |
$field['next_text'] = __( 'Next', 'advanced-forms' ); |
| 55 |
} |
| 56 |
|
| 57 |
?> |
| 58 |
<a <?php acf_esc_attr_e( $atts ); ?>> |
| 59 |
<span class="title"><?php echo acf_esc_html($field['label']); ?></span> |
| 60 |
</a> |
| 61 |
|
| 62 |
<button <?php acf_esc_attr_e( $previous_atts ); ?>><?php echo $field['previous_text']; ?></button> |
| 63 |
<button <?php acf_esc_attr_e( $next_atts ); ?>><?php echo $field['next_text']; ?></button> |
| 64 |
<?php |
| 65 |
|
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
/* |
| 72 |
* render_field_settings() |
| 73 |
* |
| 74 |
* Create extra options for your field. This is rendered when editing a field. |
| 75 |
* The value of $field['name'] can be used (like bellow) to save extra data to the $field |
| 76 |
* |
| 77 |
* @param $field - an array holding all the field's data |
| 78 |
* |
| 79 |
* @type action |
| 80 |
* @since 3.6 |
| 81 |
* @date 23/01/13 |
| 82 |
*/ |
| 83 |
|
| 84 |
function render_field_settings( $field ) { |
| 85 |
|
| 86 |
// back_text |
| 87 |
acf_render_field_setting( $field, array( |
| 88 |
'label' => __( 'Show numbering', 'advanced-forms' ), |
| 89 |
'type' => 'true_false', |
| 90 |
'name' => 'show_numbering', |
| 91 |
'ui' => true, |
| 92 |
'default_value' => true, |
| 93 |
)); |
| 94 |
|
| 95 |
// back_text |
| 96 |
acf_render_field_setting( $field, array( |
| 97 |
'label' => __( 'Previous text', 'advanced-forms' ), |
| 98 |
'instructions' => __( 'Text for the "Previous" button', 'advanced-forms' ), |
| 99 |
'type' => 'text', |
| 100 |
'name' => 'previous_text', |
| 101 |
'placeholder' => __( 'Previous', 'advanced-forms' ), |
| 102 |
)); |
| 103 |
|
| 104 |
// next_text |
| 105 |
acf_render_field_setting( $field, array( |
| 106 |
'label' => __( 'Next text', 'advanced-forms' ), |
| 107 |
'instructions' => __( 'Text for the "Next" button', 'advanced-forms' ), |
| 108 |
'type' => 'text', |
| 109 |
'name' => 'next_text', |
| 110 |
'placeholder' => __( 'Next', 'advanced-forms' ), |
| 111 |
)); |
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
/* |
| 117 |
* load_field() |
| 118 |
*/ |
| 119 |
|
| 120 |
function load_field( $field ) { |
| 121 |
|
| 122 |
// Remove name to avoid caching issue |
| 123 |
$field['name'] = ''; |
| 124 |
|
| 125 |
// Remove required to avoid JS issues |
| 126 |
$field['required'] = 0; |
| 127 |
|
| 128 |
// Set value other than 'null' to avoid ACF loading / caching issue |
| 129 |
$field['value'] = false; |
| 130 |
|
| 131 |
// Hide field from admin |
| 132 |
$field['hide_admin'] = true; |
| 133 |
|
| 134 |
// return |
| 135 |
return $field; |
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
// initialize |
| 143 |
acf_register_field_type( 'AF_Page_Field' ); |
| 144 |
|
| 145 |
?> |