name = 'export'; $this->title = __("Export Field Groups", 'acf'); // active if( $this->is_active() ) { $this->title .= ' - ' . __('Generate PHP', 'acf'); } } /** * 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 field groups selected", 'acf') , 'error'); } // headers $file_name = 'acf-export-' . date('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 acf_json_encode( $json ); 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 field groups selected", 'acf') , 'error'); } // 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); $message = sprintf( _n( 'Exported 1 field group.', 'Exported %s field groups.', $count, 'acf' ), $count ); acf_add_admin_notice( $message ); } } } /** * html * * This function will output the metabox HTML * * @date 10/10/17 * @since 5.6.3 * * @param n/a * @return n/a */ function html() { // single (generate PHP) if( $this->is_active() ) { $this->html_single(); // archive } else { $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(); $field_groups = acf_get_field_groups(); // loop if( $field_groups ) { foreach( $field_groups as $field_group ) { $choices[ $field_group['key'] ] = esc_html( $field_group['title'] ); } } // render acf_render_field_wrap(array( 'label' => __('Select Field Groups', 'acf'), '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() { ?>

html_field_selection(); ?>

__('Empty settings', 'acf'), 'type' => 'select', 'name' => 'minimal', 'prefix' => false, 'value' => '', 'choices' => array( 'all' => 'Include all settings', 'minimal' => 'Ignore empty settings' ) )); */ ?>

html_field_selection(); ?>

html_generate(); ?>
html_panel_selection(); ?>

get_selected(); $str_replace = array( " " => "\t", "'!!__(!!\'" => "__('", "!!\', !!\'" => "', '", "!!\')!!'" => "')", "array (" => "array(" ); $preg_replace = array( '/([\t\r\n]+?)array/' => 'array', '/[0-9]+ => array/' => 'array' ); ?>

get_selected_keys(); $json = array(); // bail early if no keys if( !$selected ) return false; // construct JSON foreach( $selected as $key ) { // load field group $field_group = acf_get_field_group( $key ); // validate field group if( empty($field_group) ) continue; // load fields $field_group['fields'] = acf_get_fields( $field_group ); // prepare for export $field_group = acf_prepare_field_group_for_export( $field_group ); // add to json array $json[] = $field_group; } // return return $json; } } // initialize acf_register_admin_tool( 'ACF_Admin_Tool_Export' ); endif; // class_exists check ?>