name = 'acf_cf7';
$this->title = __( 'Contact Form 7','acf-field-for-contact-form-7' );
}
/**
* Creates options.
*
* @param string $key The key
* @param string $field The field
*/
function create_options( $key, $field ) {
// defaults
$field['multiple'] = isset( $field['multiple'] ) ? $field['multiple'] : 0;
$field['allow_null'] = isset( $field['allow_null'] ) ? $field['allow_null'] : 0;
$field['disable'] = isset( $field['disable'] ) ? $field['disable'] : '0';
$field['hide_disabled'] = isset( $field['hide_disabled'] ) ? $field['hide_disabled'] : 0; ?>
|
|
'wpcf7_contact_form', 'orderby' => 'id', 'order' => 'ASC', 'posts_per_page' => 999, 'numberposts' => 999 ) );
$choices = array();
$choices[0] = '---';
$k = 1;
foreach ( $forms as $f ) {
$choices[$k] = $f->post_title;
$k++;
}
$this->parent->create_field( array(
'type' => 'select',
'name' => 'fields['.$key.'][disable]',
'value' => $field['disable'],
'multiple' => '1',
'allow_null' => '0',
'choices' => $choices,
'layout' => 'horizontal',
) );
?>
|
|
|
parent->create_field( array(
'type' => 'radio',
'name' => 'fields['.$key.'][allow_null]',
'value' => $field['allow_null'],
'choices' => array(
'1' => 'Yes',
'0' => 'No',
),
'layout' => 'horizontal',
) );
?>
|
|
|
parent->create_field( array(
'type' => 'radio',
'name' => 'fields['.$key.'][multiple]',
'value' => $field['multiple'],
'choices' => array(
'1' => 'Yes',
'0' => 'No',
),
'layout' => 'horizontal',
) );
?>
|
|
|
parent->create_field( array(
'type' => 'radio',
'name' => 'fields['.$key.'][hide_disabled]',
'value' => $field['hide_disabled'],
'choices' => array(
'1' => 'Yes',
'0' => 'No',
),
'layout' => 'horizontal',
) );
?>
|
$field The field
*
* @return ( description_of_the_return_value )
*/
function pre_save_field( $field ) {
// do stuff with field (mostly format options data)
return parent::pre_save_field( $field );
}
/**
* Creates a field.
*
* @param string $field The field
*/
function create_field( $field ) {
$field['multiple'] = isset( $field['multiple'] ) ? $field['multiple'] : false;
$field['disable'] = isset( $field['disable'] ) ? $field['disable'] : false;
$field['hide_disabled'] = isset( $field['hide_disabled'] ) ? $field['hide_disabled'] : false;
// Add multiple select functionality as required
$multiple = '';
if ( $field['multiple'] == '1' ) {
$multiple = ' multiple="multiple" size="5" ';
$field['name'] .= '[]';
}
// Begin HTML select field
echo '';
}
/**
* Admin head.
*/
function admin_head() {
}
/**
* Admin script.
*/
function admin_print_scripts() {
}
/**
* Admin styles.
*/
function admin_print_styles() {
}
/**
* Update value
*
* @param int $post_id The post identifier
* @param string $field The field
* @param string $value The value
*/
function update_value( $post_id, $field, $value ) {
// do stuff with value
// save value
parent::update_value( $post_id, $field, $value );
}
/**
* Gets the value.
*
* @param int $post_id The post identifier
* @param string $field The field
*
* @return string The value.
*/
function get_value( $post_id, $field ) {
// get value
$value = parent::get_value( $post_id, $field );
// return value
return $value;
}
/**
* Gets the value for api.
*
* @param int $post_id The post identifier
* @param string $field The field
*
* @return boolean|string The value for api.
*/
function get_value_for_api( $post_id, $field ) {
// get value
$value = $this->get_value( $post_id, $field );
if ( ! $value || $value == 'null' ) {
return false;
}
// apply filter
$contact_obj = apply_filters( 'acf_cf7_object', false );
//If there are multiple forms, construct and return an array of form markup
if ( is_array( $value ) ) {
foreach ( $value as $k => $v ) {
$form = get_post($v);
if ( $contact_obj ) {
$value = $form;
} else {
$f = do_shortcode( '[contact-form-7 id="'.$form->ID.'" title="'.$form->post_title.'"]' );
$value[$k] = array();
$value[$k] = $f;
}
}
} else {
$form = get_post( $value );
if ( $contact_obj ) {
$value = $form;
} else {
$value = do_shortcode( '[contact-form-7 id="'.$form->ID.'" title="'.$form->post_title.'"]' );
}
}
return $value;
}
}
new ACF_Field_For_Contact_form_7_V3;
}