'radio',
'name' => 'fields['.$key.'][return_format]',
'value' => $field['return_format'],
'choices' => array(
'table_id' => __("Table ID - Output only the Table ID Number",'advanced-custom-fields-tablepress'),
'rendered_html' => __("HTML - Output the rendered HTML of the table itself. Equivalent to do_shortcode(), but does not use that function.",'advanced-custom-fields-tablepress'),
),
'layout' => 'vertical',
));
?>
defaults, $field);
$choices = array();
/* Exits function if TablePress not active */
if ( !defined( 'TABLEPRESS_ABSPATH' ) ) {
echo __('TablePress must be activated for this ACF field to work', 'advanced-custom-fields-tablepress');
return;
}
/* get list of table ID and post ID pairs */
$table_json = get_option( 'tablepress_tables' );
$json_dec = json_decode( $table_json, true );
$tables = $json_dec['table_post'];
/* Get table titles for list of choices */
if ( !is_array( $tables ) || empty( $tables ) ) {
echo sprintf( __('No TablePress tables found, once you add some tables they\'ll show up here.', 'advanced-custom-fields-tablepress' ), admin_url( 'admin.php?page=tablepress' ) );
return;
}
foreach ($tables as $table_id => $post_id) {
$post = get_post( $post_id );
$choices[ $table_id ] = $post->post_title;
}
$field['choices'] = $choices;
$field['type'] = 'select';
do_action('acf/create_field', $field);
}
function format_value_for_api( $value, $post_id, $field ) {
$field = array_merge($this->defaults, $field);
if ( $field['return_format'] == 'table_id' ) return $value;
if ( $field['return_format'] == 'rendered_html' ) {
if ( !function_exists( 'tablepress_get_table' ) ) {
return 'TablePress must be enabled';
}
$value = tablepress_get_table( array(
'id' => $value,
'use_datatables' => true,
'print_name' => false
) );
return $value;
}
}
}
new acf_field_tablepress();