name = 'export'; $this->title = __( 'Export Admin Forms', 'frontend-admin' ); // active if ( $this->is_active() ) { $this->title .= ' - ' . __( 'Generate PHP', 'frontend-admin' ); } } /** * submit * * This function will run when the tool's form has been submit * * @date 10/10/17 * @since 5.6.3 * * @param n/a * @return n/a */ function submit() { // vars $action = acf_maybe_get_POST( 'action' ); // download if ( $action === 'download' ) { $this->submit_download(); // generate } elseif ( $action === 'generate' ) { $this->submit_generate(); } } /** * submit_download * * description * * @date 17/10/17 * @since 5.6.3 * * @param n/a * @return n/a */ function submit_download() { // vars $json = $this->get_selected(); // validate if ( $json === false ) { return acf_add_admin_notice( __( 'No forms selected', 'frontend-admin' ), 'warning' ); } // headers $file_name = 'fea-export-' . gmdate( 'Y-m-d' ) . '.json'; header( 'Content-Description: File Transfer' ); header( "Content-Disposition: attachment; filename={$file_name}" ); header( 'Content-Type: application/json; charset=utf-8' ); // return echo json_encode( $json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE ); die; } /** * submit_generate * * description * * @date 17/10/17 * @since 5.6.3 * * @param n/a * @return n/a */ function submit_generate() { // vars $keys = $this->get_selected_keys(); // validate if ( ! $keys ) { return acf_add_admin_notice( __( 'No forms selected', 'frontend-admin' ), 'warning' ); } // url $url = add_query_arg( 'keys', implode( '+', $keys ), $this->get_url() ); // redirect wp_redirect( $url ); exit; } /** * load * * description * * @date 21/10/17 * @since 5.6.3 * * @param n/a * @return n/a */ function load() { // active if ( $this->is_active() ) { // get selected keys $selected = $this->get_selected_keys(); // add notice if ( $selected ) { $count = count( $selected ); $text = sprintf( /* translators: %s: number of forms */ _n( 'Exported %s form.', 'Exported %s forms.', $count, 'frontend-admin' ), $count ); acf_add_admin_notice( $text, 'success' ); } } } /** * html * * This function will output the metabox HTML * * @date 10/10/17 * @since 5.6.3 * * @param n/a * @return n/a */ function html() { $this->html_archive(); } /** * html_field_selection * * description * * @date 24/10/17 * @since 5.6.3 * * @param n/a * @return n/a */ function html_field_selection() { // vars $choices = array(); $selected = $this->get_selected_keys(); $forms = feadmin_form_choices(); // loop if ( $forms ) { foreach ( $forms as $id => $form ) { $form_key = get_post_meta( $id, 'form_key', 1 ); if ( ! $form_key ) { $form_key = uniqid( 'form_' ); update_post_meta( $id, 'form_key', $form_key ); } $choices[ $form_key ] = $form; } } // render acf_render_field_wrap( array( 'label' => __( 'Select Forms', 'frontend-admin' ), 'type' => 'checkbox', 'name' => 'keys', 'prefix' => false, 'value' => $selected, 'toggle' => true, 'choices' => $choices, ) ); } /** * html_panel_selection * * description * * @date 21/10/17 * @since 5.6.3 * * @param n/a * @return n/a */ function html_panel_selection() { ?>
get_selected_keys(); $json = array(); // bail early if no keys if ( ! $selected ) { return false; } // construct JSON foreach ( $selected as $key ) { // load field group $form = fea_instance()->form_display->get_form( $key, true ); // validate field group if ( empty( $form ) ) { continue; } // prepare for export $form = acf_prepare_field_group_for_export( $form ); // add to json array $json[] = $form; } // return return $json; } } // initialize fea_instance()->admin_tools->register_tool( 'FEA_Form_Export' ); endif; // class_exists check ?>