post_type && ! get_post_meta( $post->ID, 'form_key', true ) ) { $form_key = 'form_' . uniqid(); update_post_meta( $post->ID, 'form_key', $form_key ); } } /** * Displays the form key after the title * * @since 1.0.0 * */ function display_form_key() { global $post; if ( 'af_form' == $post->post_type && $form_key = get_post_meta( $post->ID, 'form_key', true ) ) { echo '
'; echo sprintf( '%s %s', __( 'Form key:', 'advanced-forms' ), $form_key ); echo '
'; } } /** * Adds a meta box to the form edit page used to display the form fields * * @since 1.0.0 * */ function add_fields_meta_box() { add_meta_box( 'af_form_fields', __( 'Fields', 'advanced-forms' ), array( $this, 'fields_meta_box_callback' ), 'af_form', 'normal', 'default', null ); } /** * Callback for the fields meta box * Displays all fields registered to the current form * * @since 1.0.0 * */ function fields_meta_box_callback() { global $post; $form = af_get_form( $post->ID ); // Get field groups for the current form $field_groups = af_get_form_field_groups( $form['key'] ); ?>

__( 'Key', 'advanced-forms' ), 'fields' => __( 'Fields', 'advanced-forms' ), 'entries' => __( 'Entries', 'advanced-forms' ), ); // Remove date column unset( $columns['date'] ); return array_merge( array_splice( $columns, 0, 2 ), $new_columns, $columns ); } /** * Outputs the content for the custom columns * * @since 1.0.0 * */ function custom_columns_content( $column, $post_id ) { $form = af_get_form( $post_id ); if ( 'key' == $column ) { echo get_post_meta( $post_id, 'form_key', true ); } if ( 'fields' == $column ) { $count = 0; $field_groups = af_get_form_field_groups( $form['key'] ); // Count the number of fields in all field groups foreach ( $field_groups as $field_group ) { $fields = acf_get_fields( $field_group ); $count += count( $fields ); } echo $count; } elseif ( 'entries' == $column ) { $entries = af_get_entries( $form['key'] ); echo sprintf( '%s', admin_url() . '/edit.php?post_type=af_entry&entry_form=' . $form['key'], count( $entries ) ); } } /** * Add an "Insert field" button to WYSIWYG fields * * @since 1.0.0 * */ function add_wysiwyg_content_field_inserter( $id ) { global $post; if ( ! $post ) { return; } $form = af_form_from_post( $post ); if ( ! $form ) { return; } if ( 'acf-editor' == substr($id, 0, 10) ) { _af_field_inserter_button( $form, 'all', false ); } } /** * Outputs the sidebar on the forms list page * Moved up by Javascript * * @since 1.5.0 * */ function add_forms_sidebar() { $title = AF()->pro ? 'Advanced Forms Pro' : 'Advanced Forms'; $doc_url = 'https://advancedforms.github.io'; $pro_url = 'https://hookturn.io/downloads/advanced-forms'; $icon = ''; ?> post_type ) { return; } echo '
'; do_action( 'af/admin/form/actions', $post->ID ); echo '
'; } /** * Registers the form settings fields * * @since 1.0.0 * */ function register_fields() { $settings_field_group = array ( 'key' => 'group_form_settings', 'title' => __( 'Form settings', 'advanced-forms' ), 'fields' => array ( array ( 'key' => 'field_form_display_tab', 'label' => '' . __( 'Display', 'advanced-forms' ), 'name' => '', 'type' => 'tab', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array ( 'width' => '', 'class' => '', 'id' => '', ), 'placement' => 'left', 'endpoint' => 0, ), array ( 'key' => 'field_form_description', 'label' => __( 'Description', 'advanced-forms' ), 'name' => 'form_description', 'type' => 'textarea', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array ( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'tabs' => 'all', 'toolbar' => 'full', 'media_upload' => 1, ), array ( 'key' => 'field_form_success_message', 'label' => __( 'Success message', 'advanced-forms' ), 'name' => 'form_success_message', 'type' => 'wysiwyg', 'instructions' => __( 'The message displayed after a successful submission.', 'advanced-forms' ), 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array ( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'tabs' => 'all', 'toolbar' => 'full', 'media_upload' => 1, ), array ( 'key' => 'field_form_statistics_tab', 'label' => '' . __( 'Statistics', 'advanced-forms' ), 'name' => '', 'type' => 'tab', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array ( 'width' => '', 'class' => '', 'id' => '', ), 'placement' => 'left', 'endpoint' => 0, ), array ( 'key' => 'field_form_num_of_submissions', 'label' => __( 'Number of submissions', 'advanced-forms' ), 'name' => 'form_num_of_submissions', 'type' => 'number', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array ( 'width' => '50', 'class' => '', 'id' => '', ), 'default_value' => 0, 'placeholder' => '', 'prepend' => '', 'append' => '', 'min' => '', 'max' => '', 'step' => '', 'readonly' => true, ), array ( 'key' => 'field_form_num_of_views', 'label' => __( 'Number of times viewed', 'advanced-forms' ), 'name' => 'form_num_of_views', 'type' => 'number', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array ( 'width' => '50', 'class' => '', 'id' => '', ), 'default_value' => 0, 'placeholder' => '', 'prepend' => '', 'append' => '', 'min' => '', 'max' => '', 'step' => '', 'readonly' => true, ), ), 'location' => array ( array ( array ( 'param' => 'post_type', 'operator' => '==', 'value' => 'af_form', ), ), ), 'menu_order' => 0, 'position' => 'normal', 'style' => 'default', 'label_placement' => 'top', 'instruction_placement' => 'label', 'hide_on_screen' => '', 'active' => 1, 'description' => '', ); $settings_field_group = apply_filters( 'af/form/settings_fields', $settings_field_group ); acf_add_local_field_group( $settings_field_group ); } } return new AF_Admin_Forms();