| @@ -34,27 +34,23 @@ | ||
| 34 | 34 | return ! empty( $this->manifest['extra-content'] ) && !empty($data['import_demo_content']); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public function import( $data, $imported_data ): array { |
| 38 | - $extra_content = []; | |
| 39 | - $contents = $this->manifest['extra-content']; | |
| 38 | + $contents = $this->manifest['extra-content'] ?? []; | |
| 40 | 39 | |
| 41 | - if( ! empty( $contents ) ) { | |
| 42 | - foreach( $contents as $type => $content ) { | |
| 43 | - switch ( $type ) { | |
| 44 | - case 'form': | |
| 45 | - $import = $this->import_form( $content ); | |
| 46 | - $extra_content['form'] = $import; | |
| 47 | - break; | |
| 48 | - case 'data': | |
| 49 | - break; | |
| 50 | - } | |
| 40 | + $extra_content = $this->loop( $contents, function($type, $content ) { | |
| 41 | + $extra_content = []; | |
| 42 | + switch ( $type ) { | |
| 43 | + case 'form': | |
| 44 | + $import = $this->import_form( $content ); | |
| 45 | + $extra_content['form'] = $import; | |
| 46 | + break; | |
| 47 | + case 'data': | |
| 48 | + break; | |
| 51 | 49 | } |
| 50 | + return $extra_content; | |
| 51 | + }); | |
| 52 | 52 | |
| 53 | - // $imported_data = array_merge( $imported_data, [ 'extra-content' => $this->extra_content ] ); | |
| 54 | - } | |
| 55 | - | |
| 56 | - | |
| 57 | 53 | return [ 'extra-content' => $extra_content ]; |
| 58 | 54 | } |
| 59 | 55 | |
| 60 | 56 | private function import_form( $contents ): array { |
| @@ -77,10 +73,11 @@ | ||
| 77 | 73 | } |
| 78 | 74 | |
| 79 | 75 | foreach ( $form_list as $form ) { |
| 80 | 76 | try { |
| 81 | - if(isset(self::$imported_form[ $plugin_name ][ $form['form_id'] ])){ | |
| 82 | - $result[$json_id][ $plugin_name ][ $form['id'] ] = self::$imported_form[ $plugin_name ][ $form['form_id'] ]; | |
| 77 | + $form_id = isset( $form['identifier'] ) ? $form['settings'][$form['identifier']] : $form['settings']['form_list']; | |
| 78 | + if(isset(self::$imported_form[ $plugin_name ][ $form_id ])){ | |
| 79 | + $result[$json_id][ $plugin_name ][ $form['id'] ] = self::$imported_form[ $plugin_name ][ $form_id ]; | |
| 83 | 80 | continue; |
| 84 | 81 | } |
| 85 | 82 | |
| 86 | 83 | $file_path = $root_path . wp_unslash( $form['file_path'] ); |
| @@ -86,10 +83,10 @@ | ||
| 86 | 83 | $file_path = $root_path . wp_unslash( $form['file_path'] ); |
| 87 | 84 | $import = new Form( $plugin_name, $file_path, $form ); |
| 88 | 85 | $data = $import->run(); |
| 89 | 86 | |
| 90 | - self::$imported_form[ $plugin_name ][ $form['form_id'] ] = $data; | |
| 91 | - $result[$json_id][ $plugin_name ][ $form['id'] ] = $data; | |
| 87 | + self::$imported_form[ $plugin_name ][ $form_id ] = (string) $data; | |
| 88 | + $result[$json_id][ $plugin_name ][ $form['id'] ] = (string) $data; | |
| 92 | 89 | } catch ( Exception $e ) { |
| 93 | 90 | continue; |
| 94 | 91 | } |
| 95 | 92 | } |