WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Платформа для конвертации и монетизации трафика
функция не описана

ACF_Admin_Tool_Import::submit() public ACF 5.6.3

This function will run when the tool's form has been submit

{} Это метод класса: ACF_Admin_Tool_Import{}

Хуков нет.

Возвращает

n/a.

Использование

$ACF_Admin_Tool_Import = new ACF_Admin_Tool_Import();
$ACF_Admin_Tool_Import->submit();

Список изменений

С версии 5.6.3 Введена.

Код ACF_Admin_Tool_Import::submit() ACF 5.9.1

<?php
function submit() {
	
	// Check file size.
	if( empty($_FILES['acf_import_file']['size']) ) {
		return acf_add_admin_notice( __("No file selected", 'acf'), 'warning' );
	}
	
	// Get file data.
	$file = $_FILES['acf_import_file'];
	
	// Check errors.
	if( $file['error'] ) {
		return acf_add_admin_notice( __("Error uploading file. Please try again", 'acf'), 'warning' );
	}
	
	// Check file type.
	if( pathinfo($file['name'], PATHINFO_EXTENSION) !== 'json' ) {
		return acf_add_admin_notice( __("Incorrect file type", 'acf'), 'warning' );
	}
	
	// Read JSON.
	$json = file_get_contents( $file['tmp_name'] );
	$json = json_decode($json, true);
	
	// Check if empty.
    	if( !$json || !is_array($json) ) {
    		return acf_add_admin_notice( __("Import file empty", 'acf'), 'warning' );
    	}
    	
    	// Ensure $json is an array of groups.
    	if( isset($json['key']) ) {
    	$json = array( $json );	    	
    	}
    	
    	// Remeber imported field group ids.
    	$ids = array();
    	
    	// Loop over json
    	foreach( $json as $field_group ) {
    	
    	// Search database for existing field group.
    	$post = acf_get_field_group_post( $field_group['key'] );
    	if( $post ) {
	    	$field_group['ID'] = $post->ID;
    	}
    	
    	// Import field group.
    	$field_group = acf_import_field_group( $field_group );
    	
    	// append message
    	$ids[] = $field_group['ID'];
    	}
    	
    	// Count number of imported field groups.
	$total = count($ids);
	
	// Generate text.
	$text = sprintf( _n( 'Imported 1 field group', 'Imported %s field groups', $total, 'acf' ), $total );		
	
	// Add links to text.
	$links = array();
	foreach( $ids as $id ) {
		$links[] = '<a href="' . get_edit_post_link( $id ) . '">' . get_the_title( $id ) . '</a>';
	}
	$text .= ' ' . implode( ', ', $links );
	
	// Add notice
	acf_add_admin_notice( $text, 'success' );
}