WC_REST_Products_Catalog_Controller::generate_catalog_file
Generate catalog file and save it to the specified file path.
Метод класса: WC_REST_Products_Catalog_Controller{}
Хуков нет.
Возвращает
true|WP_Error. True on success, WP_Error on failure.
Использование
// private - только в коде основоного (родительского) класса $result = $this->generate_catalog_file( $file_info );
- $file_info(массив) (обязательный)
- File information with
'filepath','url', and'directory'keys.
Код WC_REST_Products_Catalog_Controller::generate_catalog_file() WC REST Products Catalog Controller::generate catalog file WC 10.5.2
private function generate_catalog_file( $file_info ) {
// Ensure directory exists and is not indexable.
try {
FilesystemUtil::mkdir_p_not_indexable( $file_info['directory'], true );
} catch ( \Exception $exception ) {
return new WP_Error( 'catalog_dir_creation_failed', $exception->getMessage(), array( 'status' => 500 ) );
}
// Generate empty catalog file.
$catalog_data = array();
// Write to file.
$json = wp_json_encode( $catalog_data );
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
$result = file_put_contents( $file_info['filepath'], $json, LOCK_EX );
if ( false === $result ) {
return new WP_Error( 'catalog_generation_failed', __( 'Failed to generate catalog file.', 'woocommerce' ), array( 'status' => 500 ) );
}
return true;
}