8889841crevert/site-settings.php000064400000001226150522022220011357 0ustar00kits_manager->revert( $data['runners'][ static::get_name() ]['imported_kit_id'], $data['runners'][ static::get_name() ]['active_kit_id'], $data['runners'][ static::get_name() ]['previous_kit_id'] ); } } revert/wp-content.php000064400000003415150522022220010655 0ustar00 $post_types, 'post_status' => 'any', 'posts_per_page' => -1, 'meta_query' => [ [ 'key' => static::META_KEY_ELEMENTOR_EDIT_MODE, 'compare' => 'NOT EXISTS', ], [ 'key' => static::META_KEY_ELEMENTOR_IMPORT_SESSION_ID, 'value' => $data['session_id'], ], ], ]; $query = new \WP_Query( $query_args ); foreach ( $query->posts as $post ) { wp_delete_post( $post->ID, true ); } /** * Revert the nav menu terms. * BC: The nav menu in new kits will be imported as part of the taxonomies, but old kits * importing the nav menu terms as part from the wp-content import. */ $this->revert_nav_menus( $data ); } private function revert_nav_menus( array $data ) { $terms = get_terms( [ 'taxonomy' => 'nav_menu', 'hide_empty' => false, 'get' => 'all', 'meta_query' => [ [ 'key' => static::META_KEY_ELEMENTOR_IMPORT_SESSION_ID, 'value' => $data['session_id'], ], ], ] ); foreach ( $terms as $term ) { wp_delete_term( $term->term_id, $term->taxonomy ); } } } revert/taxonomies.php000064400000001415150522022220010743 0ustar00 $taxonomies, 'hide_empty' => false, 'get' => 'all', 'meta_query' => [ [ 'key' => static::META_KEY_ELEMENTOR_IMPORT_SESSION_ID, 'value' => $data['session_id'], ], ], ] ); foreach ( $terms as $term ) { wp_delete_term( $term->term_id, $term->taxonomy ); } } } revert/revert-runner-base.php000064400000001125150522022220012301 0ustar00init_page_on_front_data(); } public static function get_name() : string { return 'elementor-content'; } public function should_revert( array $data ) : bool { return ( isset( $data['runners'] ) && array_key_exists( static::get_name(), $data['runners'] ) ); } public function revert( array $data ) { $elementor_post_types = ImportExportUtils::get_elementor_post_types(); $query_args = [ 'post_type' => $elementor_post_types, 'post_status' => 'any', 'posts_per_page' => -1, 'meta_query' => [ [ 'key' => static::META_KEY_ELEMENTOR_EDIT_MODE, 'compare' => 'EXISTS', ], [ 'key' => static::META_KEY_ELEMENTOR_IMPORT_SESSION_ID, 'value' => $data['session_id'], ], ], ]; $query = new \WP_Query( $query_args ); foreach ( $query->posts as $post ) { $post_type_document = Plugin::$instance->documents->get( $post->ID ); $post_type_document->delete(); // Deleting the post will reset the show_on_front option. We need to set it to false, // so we can set it back to what it was. if ( $post->ID === $this->page_on_front_id ) { $this->show_page_on_front = false; } } $this->restore_page_on_front( $data ); } private function init_page_on_front_data() { $this->show_page_on_front = 'page' === get_option( 'show_on_front' ); if ( $this->show_page_on_front ) { $this->page_on_front_id = (int) get_option( 'page_on_front' ); } } private function restore_page_on_front( $data ) { if ( empty( $data['runners'][ static::get_name() ]['page_on_front'] ) ) { return; } $page_on_front = $data['runners'][ static::get_name() ]['page_on_front']; $document = Plugin::$instance->documents->get( $page_on_front ); if ( ! $document ) { return; } $this->set_page_on_front( $document->get_main_id() ); } private function set_page_on_front( $page_id ) { update_option( 'page_on_front', $page_id ); if ( ! $this->show_page_on_front ) { update_option( 'show_on_front', 'page' ); } } } revert/templates.php000064400000000570150522022220010554 0ustar00kits_manager->get_active_kit(); $kit_data = $kit->get_export_data(); $kit_tabs = $kit->get_tabs(); $excluded_kit_settings_keys = [ 'site_name', 'site_description', 'site_logo', 'site_favicon', ]; foreach ( $excluded_kit_settings_keys as $setting_key ) { unset( $kit_data['settings'][ $setting_key ] ); } unset( $kit_tabs['settings-site-identity'] ); $kit_tabs = array_keys( $kit_tabs ); $manifest_data['site-settings'] = $kit_tabs; return [ 'files' => [ 'path' => 'site-settings', 'data' => $kit_data, ], 'manifest' => [ $manifest_data, ], ]; } } export/wp-content.php000064400000003740150522022220010670 0ustar00export_wp_post_type( $post_type ); $files[] = $export['file']; $manifest_data['wp-content'][ $post_type ] = $export['manifest_data']; } foreach ( $custom_post_types as $post_type ) { $export = $this->export_wp_post_type( $post_type ); $files[] = $export['file']; $manifest_data['wp-content'][ $post_type ] = $export['manifest_data']; $post_type_object = get_post_type_object( $post_type ); $manifest_data['custom-post-type-title'][ $post_type ] = [ 'name' => $post_type_object->name, 'label' => $post_type_object->label, ]; } return [ 'files' => $files, 'manifest' => [ $manifest_data, ], ]; } private function export_wp_post_type( $post_type ) { $wp_exporter = new WP_Exporter( [ 'content' => $post_type, 'status' => 'publish', 'limit' => 20, 'meta_query' => [ [ 'key' => static::META_KEY_ELEMENTOR_EDIT_MODE, 'compare' => 'NOT EXISTS', ], ], 'include_post_featured_image_as_attachment' => true, ] ); $export_result = $wp_exporter->run(); return [ 'file' => [ 'path' => 'wp-content/' . $post_type . '/' . $post_type . '.xml', 'data' => $export_result['xml'], ], 'manifest_data' => $export_result['ids'], ]; } } export/taxonomies.php000064400000005167150522022220010765 0ustar00export_taxonomies( $post_types ); $manifest_data['taxonomies'] = $export['manifest']; return [ 'files' => $export['files'], 'manifest' => [ $manifest_data, ], ]; } private function export_taxonomies( array $post_types ) { $files = []; $manifest = []; $taxonomies = get_taxonomies(); foreach ( $taxonomies as $taxonomy ) { $taxonomy_post_types = get_taxonomy( $taxonomy )->object_type; $intersected_post_types = array_intersect( $taxonomy_post_types, $post_types ); if ( empty( $intersected_post_types ) ) { continue; } $data = $this->export_terms( $taxonomy ); if ( empty( $data ) ) { continue; } foreach ( $intersected_post_types as $post_type ) { $manifest[ $post_type ][] = $taxonomy; } $files[] = [ 'path' => 'taxonomies/' . $taxonomy, 'data' => $data, ]; } return [ 'files' => $files, 'manifest' => $manifest, ]; } private function export_terms( $taxonomy ) { $terms = get_terms( [ 'taxonomy' => (array) $taxonomy, 'hide_empty' => true, 'get' => 'all', ] ); $ordered_terms = $this->order_terms( $terms ); if ( empty( $ordered_terms ) ) { return []; } $data = []; foreach ( $ordered_terms as $term ) { $data[] = [ 'term_id' => $term->term_id, 'name' => $term->name, 'slug' => $term->slug, 'taxonomy' => $term->taxonomy, 'description' => $term->description, 'parent' => $term->parent, ]; } return $data; } // Put terms in order with no child going before its parent. private function order_terms( array $terms ) { $ordered_terms = []; while ( $term = array_shift( $terms ) ) { $is_top_level = 0 === $term->parent; $is_parent_exits = isset( $ordered_terms[ $term->parent ] ); if ( $is_top_level || $is_parent_exits ) { $ordered_terms[ $term->term_id ] = $term; } else { $terms[] = $term; } } return $ordered_terms; } } export/elementor-content.php000064400000006263150522022220012237 0ustar00init_page_on_front_data(); } public static function get_name() : string { return 'elementor-content'; } public function should_export( array $data ) { return ( isset( $data['include'] ) && in_array( 'content', $data['include'], true ) ); } public function export( array $data ) { $elementor_post_types = ImportExportUtils::get_elementor_post_types(); $files = []; $manifest = []; foreach ( $elementor_post_types as $post_type ) { $export = $this->export_elementor_post_type( $post_type ); $files = array_merge( $files, $export['files'] ); $manifest[ $post_type ] = $export['manifest_data']; } $manifest_data['content'] = $manifest; return [ 'files' => $files, 'manifest' => [ $manifest_data, ], ]; } private function export_elementor_post_type( $post_type ) { $query_args = [ 'post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => [ [ 'key' => static::META_KEY_ELEMENTOR_EDIT_MODE, 'compare' => 'EXISTS', ], [ 'key' => '_elementor_data', 'compare' => 'EXISTS', ], [ 'key' => '_elementor_data', 'compare' => '!=', 'value' => '[]', ], ], ]; $query = new \WP_Query( $query_args ); if ( empty( $query ) ) { return [ 'files' => [], 'manifest_data' => [], ]; } $post_type_taxonomies = $this->get_post_type_taxonomies( $post_type ); $manifest_data = []; $files = []; foreach ( $query->posts as $post ) { $document = Plugin::$instance->documents->get( $post->ID ); $terms = ! empty( $post_type_taxonomies ) ? $this->get_post_terms( $post->ID, $post_type_taxonomies ) : []; $post_manifest_data = [ 'title' => $post->post_title, 'excerpt' => $post->post_excerpt, 'doc_type' => $document->get_name(), 'thumbnail' => get_the_post_thumbnail_url( $post ), 'url' => get_permalink( $post ), 'terms' => $terms, ]; if ( $post->ID === $this->page_on_front_id ) { $post_manifest_data['show_on_front'] = true; } $manifest_data[ $post->ID ] = $post_manifest_data; $files[] = [ 'path' => 'content/' . $post_type . '/' . $post->ID, 'data' => $document->get_export_data(), ]; } return [ 'files' => $files, 'manifest_data' => $manifest_data, ]; } private function get_post_type_taxonomies( $post_type ) { return get_object_taxonomies( $post_type ); } private function get_post_terms( $post_id, array $taxonomies ) { $terms = wp_get_object_terms( $post_id, $taxonomies ); $result = []; foreach ( $terms as $term ) { $result[] = [ 'term_id' => $term->term_id, 'taxonomy' => $term->taxonomy, 'slug' => $term->slug, ]; } return $result; } private function init_page_on_front_data() { $show_page_on_front = 'page' === get_option( 'show_on_front' ); if ( $show_page_on_front ) { $this->page_on_front_id = (int) get_option( 'page_on_front' ); } } } export/templates.php000064400000002665150522022220010575 0ustar00 Source_Local::CPT, 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => [ [ 'key' => Document::TYPE_META_KEY, 'value' => $template_types, ], ], ]; $templates_query = new \WP_Query( $query_args ); $templates_manifest_data = []; $files = []; foreach ( $templates_query->posts as $template_post ) { $template_id = $template_post->ID; $template_document = Plugin::$instance->documents->get( $template_id ); $templates_manifest_data[ $template_id ] = $template_document->get_export_summary(); $files[] = [ 'path' => 'templates/' . $template_id, 'data' => $template_document->get_export_data(), ]; } $manifest_data['templates'] = $templates_manifest_data; return [ 'files' => $files, 'manifest' => [ $manifest_data, ], ]; } } export/plugins.php000064400000001057150522022220010252 0ustar00 [ $manifest_data, ], 'files' => [], ]; } } export/export-runner-base.php000064400000001320150522022220012322 0ustar00kits_manager->get_active_kit(); $this->active_kit_id = (int) $active_kit->get_id(); $this->previous_kit_id = (int) Plugin::$instance->kits_manager->get_previous_id(); $result = []; $old_settings = $active_kit->get_meta( PageManager::META_KEY ); if ( ! $old_settings ) { $old_settings = []; } if ( ! empty( $old_settings['custom_colors'] ) ) { $new_site_settings['custom_colors'] = array_merge( $old_settings['custom_colors'], $new_site_settings['custom_colors'] ); } if ( ! empty( $old_settings['custom_typography'] ) ) { $new_site_settings['custom_typography'] = array_merge( $old_settings['custom_typography'], $new_site_settings['custom_typography'] ); } if ( ! empty( $new_site_settings['space_between_widgets'] ) ) { $new_site_settings['space_between_widgets'] = Utils::update_space_between_widgets_values( $new_site_settings['space_between_widgets'] ); } $new_site_settings = array_replace_recursive( $old_settings, $new_site_settings ); $new_kit = Plugin::$instance->kits_manager->create_new_kit( $title, $new_site_settings ); $this->imported_kit_id = (int) $new_kit; $result['site-settings'] = (bool) $new_kit; return $result; } public function get_import_session_metadata() : array { return [ 'previous_kit_id' => $this->previous_kit_id, 'active_kit_id' => $this->active_kit_id, 'imported_kit_id' => $this->imported_kit_id, ]; } } import/wp-content.php000064400000006451150522022220010663 0ustar00import_session_id = $data['session_id']; $path = $data['extracted_directory_path'] . 'wp-content/'; $post_types = $this->filter_post_types( $data['selected_custom_post_types'] ); $taxonomies = $imported_data['taxonomies'] ?? []; $imported_terms = ImportExportUtils::map_old_new_term_ids( $imported_data ); $result['wp-content'] = []; foreach ( $post_types as $post_type ) { $import = $this->import_wp_post_type( $path, $post_type, $imported_data, $taxonomies, $imported_terms ); if ( empty( $import ) ) { continue; } $result['wp-content'][ $post_type ] = $import; $imported_data = array_merge( $imported_data, $result ); } return $result; } private function import_wp_post_type( $path, $post_type, array $imported_data, array $taxonomies, array $imported_terms ) { $args = [ 'fetch_attachments' => true, 'posts' => ImportExportUtils::map_old_new_post_ids( $imported_data ), 'terms' => $imported_terms, 'taxonomies' => ! empty( $taxonomies[ $post_type ] ) ? $taxonomies[ $post_type ] : [], 'posts_meta' => [ static::META_KEY_ELEMENTOR_IMPORT_SESSION_ID => $this->import_session_id, ], 'terms_meta' => [ static::META_KEY_ELEMENTOR_IMPORT_SESSION_ID => $this->import_session_id, ], ]; $file = $path . $post_type . '/' . $post_type . '.xml'; if ( ! file_exists( $file ) ) { return []; } $wp_importer = new WP_Import( $file, $args ); $result = $wp_importer->run(); return $result['summary']['posts']; } private function filter_post_types( $selected_custom_post_types = [] ) { $wp_builtin_post_types = ImportExportUtils::get_builtin_wp_post_types(); foreach ( $selected_custom_post_types as $custom_post_type ) { if ( post_type_exists( $custom_post_type ) ) { $this->selected_custom_post_types[] = $custom_post_type; } } $post_types = array_merge( $wp_builtin_post_types, $this->selected_custom_post_types ); $post_types = $this->force_element_to_be_last_by_value( $post_types, 'nav_menu_item' ); return $post_types; } public function get_import_session_metadata() : array { return [ 'custom_post_types' => $this->selected_custom_post_types, ]; } /** * @param $array array The array we want to relocate his element. * @param $element mixed The value of the element in the array we want to shift to end of the array. * @return mixed */ private function force_element_to_be_last_by_value( array $array, $element ) { $index = array_search( $element, $array, true ); if ( false !== $index ) { unset( $array[ $index ] ); $array[] = $element; } return $array; } } import/taxonomies.php000064400000007365150522022220010760 0ustar00import_session_id = $data['session_id']; $wp_builtin_post_types = ImportExportUtils::get_builtin_wp_post_types(); $selected_custom_post_types = isset( $data['selected_custom_post_types'] ) ? $data['selected_custom_post_types'] : []; $post_types = array_merge( $wp_builtin_post_types, $selected_custom_post_types ); $result = []; foreach ( $post_types as $post_type ) { if ( empty( $data['manifest']['taxonomies'][ $post_type ] ) ) { continue; } $result['taxonomies'][ $post_type ] = $this->import_taxonomies( $data['manifest']['taxonomies'][ $post_type ], $path ); } return $result; } private function import_taxonomies( array $taxonomies, $path ) { $result = []; $imported_taxonomies = []; foreach ( $taxonomies as $taxonomy ) { if ( ! taxonomy_exists( $taxonomy ) ) { continue; } if ( ! empty( $imported_taxonomies[ $taxonomy ] ) ) { $result[ $taxonomy ] = $imported_taxonomies[ $taxonomy ]; continue; } $taxonomy_data = ImportExportUtils::read_json_file( $path . $taxonomy ); if ( empty( $taxonomy_data ) ) { continue; } $import = $this->import_taxonomy( $taxonomy_data ); $result[ $taxonomy ] = $import; $imported_taxonomies[ $taxonomy ] = $import; } return $result; } private function import_taxonomy( array $taxonomy_data ) { $terms = []; foreach ( $taxonomy_data as $term ) { $old_slug = $term['slug']; $existing_term = term_exists( $term['slug'], $term['taxonomy'] ); if ( $existing_term ) { if ( 'nav_menu' === $term['taxonomy'] ) { $term = $this->handle_duplicated_nav_menu_term( $term ); } else { $terms[] = [ 'old_id' => (int) $term['term_id'], 'new_id' => (int) $existing_term['term_id'], 'old_slug' => $old_slug, 'new_slug' => $term['slug'], ]; continue; } } $parent = $this->get_term_parent( $term, $terms ); $args = [ 'slug' => $term['slug'], 'description' => wp_slash( $term['description'] ), 'parent' => (int) $parent, ]; $new_term = wp_insert_term( wp_slash( $term['name'] ), $term['taxonomy'], $args ); if ( ! is_wp_error( $new_term ) ) { $this->set_session_term_meta( (int) $new_term['term_id'], $this->import_session_id ); $terms[] = [ 'old_id' => $term['term_id'], 'new_id' => (int) $new_term['term_id'], 'old_slug' => $old_slug, 'new_slug' => $term['slug'], ]; } } return $terms; } private function handle_duplicated_nav_menu_term( $term ) { do { $term['slug'] = $term['slug'] . '-duplicate'; $term['name'] = $term['name'] . ' duplicate'; } while ( term_exists( $term['slug'], 'nav_menu' ) ); return $term; } private function get_term_parent( $term, array $imported_terms ) { $parent = $term['parent']; if ( 0 !== $parent && ! empty( $imported_terms ) ) { foreach ( $imported_terms as $imported_term ) { if ( $parent === $imported_term['old_id'] ) { $parent_term = term_exists( $imported_term['new_id'], $term['taxonomy'] ); break; } } if ( isset( $parent_term['term_id'] ) ) { return $parent_term['term_id']; } } return 0; } } import/elementor-content.php000064400000010517150522022220012225 0ustar00init_page_on_front_data(); } public static function get_name() : string { return 'elementor-content'; } public function should_import( array $data ) { return ( isset( $data['include'] ) && in_array( 'content', $data['include'], true ) && ! empty( $data['manifest']['content'] ) && ! empty( $data['extracted_directory_path'] ) ); } public function import( array $data, array $imported_data ) { $result['content'] = []; $this->import_session_id = $data['session_id']; $elementor_post_types = ImportExportUtils::get_elementor_post_types(); foreach ( $elementor_post_types as $post_type ) { if ( empty( $data['manifest']['content'][ $post_type ] ) ) { continue; } $posts_settings = $data['manifest']['content'][ $post_type ]; $path = $data['extracted_directory_path'] . 'content/' . $post_type . '/'; $imported_terms = ! empty( $imported_data['taxonomies'] ) ? ImportExportUtils::map_old_new_term_ids( $imported_data ) : []; $result['content'][ $post_type ] = $this->import_elementor_post_type( $posts_settings, $path, $post_type, $imported_terms ); } return $result; } private function import_elementor_post_type( array $posts_settings, $path, $post_type, array $imported_terms ) { $result = [ 'succeed' => [], 'failed' => [], ]; foreach ( $posts_settings as $id => $post_settings ) { try { $post_data = ImportExportUtils::read_json_file( $path . $id ); $import = $this->import_post( $post_settings, $post_data, $post_type, $imported_terms ); if ( is_wp_error( $import ) ) { $result['failed'][ $id ] = $import->get_error_message(); continue; } $result['succeed'][ $id ] = $import; } catch ( \Exception $error ) { $result['failed'][ $id ] = $error->getMessage(); } } return $result; } private function import_post( array $post_settings, array $post_data, $post_type, array $imported_terms ) { $post_attributes = [ 'post_title' => $post_settings['title'], 'post_type' => $post_type, 'post_status' => 'publish', ]; if ( ! empty( $post_settings['excerpt'] ) ) { $post_attributes['post_excerpt'] = $post_settings['excerpt']; } $new_document = Plugin::$instance->documents->create( $post_settings['doc_type'], $post_attributes ); if ( is_wp_error( $new_document ) ) { throw new \Exception( $new_document->get_error_message() ); } $post_data['import_settings'] = $post_settings; $new_attachment_callback = function( $attachment_id ) { $this->set_session_post_meta( $attachment_id, $this->import_session_id ); }; add_filter( 'elementor/template_library/import_images/new_attachment', $new_attachment_callback ); $new_document->import( $post_data ); remove_filter( 'elementor/template_library/import_images/new_attachment', $new_attachment_callback ); $new_post_id = $new_document->get_main_id(); if ( ! empty( $post_settings['terms'] ) ) { $this->set_post_terms( $new_post_id, $post_settings['terms'], $imported_terms ); } if ( ! empty( $post_settings['show_on_front'] ) ) { $this->set_page_on_front( $new_post_id ); } $this->set_session_post_meta( $new_post_id, $this->import_session_id ); return $new_post_id; } private function set_post_terms( $post_id, array $terms, array $imported_terms ) { foreach ( $terms as $term ) { if ( ! isset( $imported_terms[ $term['term_id'] ] ) ) { continue; } wp_set_post_terms( $post_id, [ $imported_terms[ $term['term_id'] ] ], $term['taxonomy'], false ); } } private function init_page_on_front_data() { $this->show_page_on_front = 'page' === get_option( 'show_on_front' ); if ( $this->show_page_on_front ) { $this->page_on_front_id = (int) get_option( 'page_on_front' ); } } private function set_page_on_front( $page_id ) { update_option( 'page_on_front', $page_id ); if ( ! $this->show_page_on_front ) { update_option( 'show_on_front', 'page' ); } } public function get_import_session_metadata() : array { return [ 'page_on_front' => $this->page_on_front_id ?? 0, ]; } } import/import-runner-base.php000064400000002171150522022220012311 0ustar00import_session_id = $data['session_id']; $path = $data['extracted_directory_path'] . 'templates/'; $templates = $data['manifest']['templates']; $result['templates'] = [ 'succeed' => [], 'failed' => [], ]; foreach ( $templates as $id => $template_settings ) { try { $template_data = ImportExportUtils::read_json_file( $path . $id ); $import = $this->import_template( $id, $template_settings, $template_data ); $result['templates']['succeed'][ $id ] = $import; } catch ( \Exception $error ) { $result['templates']['failed'][ $id ] = $error->getMessage(); } } return $result; } private function import_template( $id, array $template_settings, array $template_data ) { $doc_type = $template_settings['doc_type']; $new_document = Plugin::$instance->documents->create( $doc_type, [ 'post_title' => $template_settings['title'], 'post_type' => Source_Local::CPT, 'post_status' => 'publish', ] ); if ( is_wp_error( $new_document ) ) { throw new \Exception( $new_document->get_error_message() ); } $template_data['import_settings'] = $template_settings; $template_data['id'] = $id; $new_attachment_callback = function( $attachment_id ) { $this->set_session_post_meta( $attachment_id, $this->import_session_id ); }; add_filter( 'elementor/template_library/import_images/new_attachment', $new_attachment_callback ); $new_document->import( $template_data ); remove_filter( 'elementor/template_library/import_images/new_attachment', $new_attachment_callback ); $document_id = $new_document->get_main_id(); $this->set_session_post_meta( $document_id, $this->import_session_id ); return $document_id; } } import/plugins.php000064400000003227150522022220010244 0ustar00plugins_manager = $plugins_manager; } else { $this->plugins_manager = new Plugins_Manager(); } } public static function get_name() : string { return 'plugins'; } public function should_import( array $data ) { return ( isset( $data['include'] ) && in_array( 'plugins', $data['include'], true ) && ! empty( $data['manifest']['plugins'] ) && ! empty( $data['selected_plugins'] ) ); } public function import( array $data, array $imported_data ) { $plugins = $data['selected_plugins']; $plugins_collection = ( new Collection( $plugins ) ) ->map( function ( $item ) { if ( ! Str::ends_with( $item['plugin'], '.php' ) ) { $item['plugin'] .= '.php'; } return $item; } ); $slugs = $plugins_collection ->map( function ( $item ) { return $item['plugin']; } ) ->all(); $installed = $this->plugins_manager->install( $slugs ); $activated = $this->plugins_manager->activate( $installed['succeeded'] ); $ordered_activated_plugins = $plugins_collection ->filter( function ( $item ) use ( $activated ) { return in_array( $item['plugin'], $activated['succeeded'], true ); } ) ->map( function ( $item ) { return $item['name']; } ) ->all(); $result['plugins'] = $ordered_activated_plugins; return $result; } }