| @@ -7,8 +7,10 @@ | ||
| 7 | 7 | use Templately\Core\Importer\Runners\BaseRunner; |
| 8 | 8 | |
| 9 | 9 | class ExtraContent extends BaseRunner { |
| 10 | 10 | |
| 11 | + protected static $imported_form = []; | |
| 12 | + | |
| 11 | 13 | public function get_name(): string { |
| 12 | 14 | return 'extra-content'; |
| 13 | 15 | } |
| 14 | 16 | |
| @@ -32,27 +34,22 @@ | ||
| 32 | 34 | return ! empty( $this->manifest['extra-content'] ) && !empty($data['import_demo_content']); |
| 33 | 35 | } |
| 34 | 36 | |
| 35 | 37 | public function import( $data, $imported_data ): array { |
| 36 | - $extra_content = []; | |
| 37 | - $contents = $this->manifest['extra-content']; | |
| 38 | + $contents = $this->manifest['extra-content'] ?? []; | |
| 38 | 39 | |
| 39 | - if( ! empty( $contents ) ) { | |
| 40 | - foreach( $contents as $type => $content ) { | |
| 41 | - switch ( $type ) { | |
| 42 | - case 'form': | |
| 43 | - $import = $this->import_form( $content ); | |
| 44 | - $extra_content['form'] = $import; | |
| 45 | - break; | |
| 46 | - case 'data': | |
| 47 | - break; | |
| 48 | - } | |
| 40 | + $extra_content = $this->loop( $contents, function($type, $content, $extra_content ) { | |
| 41 | + switch ( $type ) { | |
| 42 | + case 'form': | |
| 43 | + $import = $this->import_form( $content ); | |
| 44 | + $extra_content['form'] = $import; | |
| 45 | + break; | |
| 46 | + case 'data': | |
| 47 | + break; | |
| 49 | 48 | } |
| 49 | + return $extra_content; | |
| 50 | + }); | |
| 50 | 51 | |
| 51 | - // $imported_data = array_merge( $imported_data, [ 'extra-content' => $this->extra_content ] ); | |
| 52 | - } | |
| 53 | - | |
| 54 | - | |
| 55 | 52 | return [ 'extra-content' => $extra_content ]; |
| 56 | 53 | } |
| 57 | 54 | |
| 58 | 55 | private function import_form( $contents ): array { |
| @@ -75,13 +72,20 @@ | ||
| 75 | 72 | } |
| 76 | 73 | |
| 77 | 74 | foreach ( $form_list as $form ) { |
| 78 | 75 | try { |
| 76 | + $form_id = isset( $form['identifier'] ) ? $form['settings'][$form['identifier']] : $form['settings']['form_list']; | |
| 77 | + if(isset(self::$imported_form[ $plugin_name ][ $form_id ])){ | |
| 78 | + $result[$json_id][ $plugin_name ][ $form['id'] ] = self::$imported_form[ $plugin_name ][ $form_id ]; | |
| 79 | + continue; | |
| 80 | + } | |
| 81 | + | |
| 79 | 82 | $file_path = $root_path . wp_unslash( $form['file_path'] ); |
| 80 | 83 | $import = new Form( $plugin_name, $file_path, $form ); |
| 81 | 84 | $data = $import->run(); |
| 82 | 85 | |
| 83 | - $result[$json_id][ $plugin_name ][ $form['id'] ] = $data; | |
| 86 | + self::$imported_form[ $plugin_name ][ $form_id ] = (string) $data; | |
| 87 | + $result[$json_id][ $plugin_name ][ $form['id'] ] = (string) $data; | |
| 84 | 88 | } catch ( Exception $e ) { |
| 85 | 89 | continue; |
| 86 | 90 | } |
| 87 | 91 | } |