From 6cff3d3609a1416cd8e07b41854f9e68cf7a5f47 Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Mon, 12 Feb 2024 14:12:16 +0530 Subject: [PATCH 01/13] Added media upload code for sideloading images --- includes/Services/SiteGenService.php | 148 +++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index fdc7f67..33e41a6 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -820,4 +820,152 @@ public static function publish_sitemap_pages( $site_description, $content_style, return true; } + + /** + * Uploads images to the WordPress media library from a given array of Unsplash image URLs. + * + * @param array $image_urls An array of Unsplash image URLs to upload. + * @return array An array containing the URLs of the uploaded images in the WordPress media library. + */ + + public static function upload_images_to_wp_media_library($image_urls) { + require_once(ABSPATH . 'wp-admin/includes/file.php'); + require_once(ABSPATH . 'wp-admin/includes/media.php'); + require_once(ABSPATH . 'wp-admin/includes/image.php'); + + $uploaded_image_urls = array(); + foreach ($image_urls as $image_url) { + if (!filter_var($image_url, FILTER_VALIDATE_URL)) { + continue; + } + + // Check for extensions in the image url + if (!preg_match('/[^\?]+\.(jpg|jpeg|jpe|png|gif|webp)\b/i', $image_url)) { + // If not, append customExtension=true and force .jpg extension + $image_url = add_query_arg('customExtension', 'true', $image_url) . '.jpg'; + } + + // Download file to temp location + $tmp = download_url($image_url); + if (is_wp_error($tmp)) { + // Handle error, skip to next URL + error_log("Error downloading image: " . $tmp->get_error_message()); + continue; + } + + $file_array = array( + 'name' => wp_basename($image_url), + 'tmp_name' => $tmp, + ); + + $id = media_handle_sideload($file_array, 0); + if (is_wp_error($id)) { + //deleting the file not sure how to check this ? + @unlink($file_array['tmp_name']); + error_log("Error sideloading image: " . $id->get_error_message()); + continue; + } + + // Get the URL of the uploaded image + $url = wp_get_attachment_url($id); + if ($url) { + $uploaded_image_urls[] = $url; + } else { + error_log("Error retrieving uploaded image URL for image ID: $id"); + } + } + + error_log("Uploaded attachment URLs: " . print_r($uploaded_image_urls, true)); + return $uploaded_image_urls; + } + +/* + public static function upload_images_to_wp_media_library($image_urls) { + require_once(ABSPATH . 'wp-admin/includes/file.php'); + require_once(ABSPATH . 'wp-admin/includes/media.php'); + require_once(ABSPATH . 'wp-admin/includes/image.php'); + + $uploaded_image_urls = array(); + + foreach ($image_urls as $image_url) { + // Check if the URL is valid + if (!filter_var($image_url, FILTER_VALIDATE_URL)) { + continue; + } + + // Fetch the image via remote get + $response = wp_remote_get($image_url); + error_log("Uploaded attachment urls".print_r($response, true)); + if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { + continue; // Skip if request failed + } + + $headers = wp_remote_retrieve_headers($response); + $contentType = $headers['content-type'] ?? ''; + $image_data = wp_remote_retrieve_body($response); + if (empty($contentType) || empty($image_data)) { + continue; // Skip if no content type or image data is present + } + + // Determine the file extension based on MIME type + $file_extension = ''; + switch ($contentType) { + case 'image/jpeg': + $file_extension = '.jpg'; + break; + case 'image/png': + $file_extension = '.png'; + break; + case 'image/gif': + $file_extension = '.gif'; + break; + case 'image/webp': + $file_extension = '.webp'; + break; + default: + // Log or handle unsupported MIME types as needed + error_log('Unsupported MIME type: ' . $contentType); + continue; // Skip files with unsupported MIME types + } + // create upload directory + $upload_dir = wp_upload_dir(); + + // xtract a filename from the URL + $parsed_url = parse_url($image_url); + $path_parts = pathinfo($parsed_url['path']); + //filename to be added in directory + $original_filename = $path_parts['filename'] . $file_extension; + + // Ensure the filename is unique within the upload directory + $filename = wp_unique_filename($upload_dir['path'], $original_filename); + $filepath = $upload_dir['path'] . '/' . $filename; + + // Save the image to the uploads directory + file_put_contents($filepath, $image_data); + + // Create an attachment post for the image + $attachment = array( + 'guid' => $upload_dir['url'] . '/' . $filename, + 'post_mime_type' => $contentType, + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), + 'post_content' => '', + 'post_status' => 'inherit' + ); + + $attach_id = wp_insert_attachment($attachment, $filepath); + + // Generate and assign metadata for the attachment + $attach_data = wp_generate_attachment_metadata($attach_id, $filepath); + wp_update_attachment_metadata($attach_id, $attach_data); + + // Add the WordPress attachment URL to the list + if ($attach_id) { + $uploaded_image_urls[] = wp_get_attachment_url($attach_id); + } + } + error_log("Uploaded attachment urls".print_r($uploaded_image_urls, true)); + return $uploaded_image_urls; + } + */ + } From 18bf5de8cee28fa143e0188e4482ad5bc974c137 Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Wed, 28 Feb 2024 12:03:22 +0530 Subject: [PATCH 02/13] sideload and replace image on active homepages --- includes/Services/SiteGenService.php | 216 ++++++++++----------------- 1 file changed, 78 insertions(+), 138 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index 3eb4157..cca80bf 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -480,6 +480,7 @@ public static function process_homepages_response( 'header' => $data['header'], 'footer' => $data['footer'], 'color' => $selected_palette, + 'generatedImages' => $data['generatedImages'], ); ++$version_number; } @@ -971,169 +972,108 @@ public static function get_dummy_navigation_menu_items() { return $dummy_items; } - /** - * Uploads images to the WordPress media library from a given array of Unsplash image URLs. - * - * @param array $image_urls An array of Unsplash image URLs to upload. - * @return array An array containing the URLs of the uploaded images in the WordPress media library. + /** + * Returns the wp:navigation-link grammar for a given post. + * + * @param integer $id The Post ID. + * @param string $name The name of the post to display on the menu. + * @param string $url The permalink of the post. + * @return string|false */ - - public static function upload_images_to_wp_media_library($image_urls) { - require_once(ABSPATH . 'wp-admin/includes/file.php'); + public static function get_nav_link_grammar_from_post_data( $id, $name, $url ) { + $prompt = self::get_prompt(); + $site_info = array( 'site_description' => $prompt ); + $sitemap = self::instantiate_site_meta( $site_info, 'sitemap', true ); + if ( is_wp_error( $sitemap ) ) { + return false; + } + + return ""; + } + + public static function upload_images_to_wp_media_library($image_urls) { require_once(ABSPATH . 'wp-admin/includes/media.php'); + require_once(ABSPATH . 'wp-admin/includes/file.php'); require_once(ABSPATH . 'wp-admin/includes/image.php'); $uploaded_image_urls = array(); + foreach ($image_urls as $image_url) { + // Check if the URL is valid if (!filter_var($image_url, FILTER_VALIDATE_URL)) { continue; } - // Check for extensions in the image url - if (!preg_match('/[^\?]+\.(jpg|jpeg|jpe|png|gif|webp)\b/i', $image_url)) { - // If not, append customExtension=true and force .jpg extension - $image_url = add_query_arg('customExtension', 'true', $image_url) . '.jpg'; - } + // Sideload image without attaching it to any post + // The $post_id parameter is set to 0, indicating no post attachment + $sideloaded_image_id = media_sideload_image($image_url, 0, null, 'id'); - // Download file to temp location - $tmp = download_url($image_url); - if (is_wp_error($tmp)) { - // Handle error, skip to next URL - error_log("Error downloading image: " . $tmp->get_error_message()); - continue; - } - - $file_array = array( - 'name' => wp_basename($image_url), - 'tmp_name' => $tmp, - ); - - $id = media_handle_sideload($file_array, 0); - if (is_wp_error($id)) { - //deleting the file not sure how to check this ? - @unlink($file_array['tmp_name']); - error_log("Error sideloading image: " . $id->get_error_message()); + // Check for errors + if (is_wp_error($sideloaded_image_id)) { + error_log("Error sideloading image: " . $sideloaded_image_id->get_error_message()); continue; } // Get the URL of the uploaded image - $url = wp_get_attachment_url($id); - if ($url) { - $uploaded_image_urls[] = $url; + $image_url = wp_get_attachment_url($sideloaded_image_id); + if ($image_url) { + $uploaded_image_urls[] = $image_url; } else { - error_log("Error retrieving uploaded image URL for image ID: $id"); + error_log("Error retrieving uploaded image URL for image ID: $sideloaded_image_id"); } } error_log("Uploaded attachment URLs: " . print_r($uploaded_image_urls, true)); return $uploaded_image_urls; } + - /** - * Returns the wp:navigation-link grammar for a given post. - * - * @param integer $id The Post ID. - * @param string $name The name of the post to display on the menu. - * @param string $url The permalink of the post. - * @return string|false - */ - public static function get_nav_link_grammar_from_post_data( $id, $name, $url ) { - $prompt = self::get_prompt(); - $site_info = array( 'site_description' => $prompt ); - $sitemap = self::instantiate_site_meta( $site_info, 'sitemap', true ); - if ( is_wp_error( $sitemap ) ) { + public static function sideload_and_replace($active_homepage){ + $generatedDalleImage = "https://dalleprodsec.blob.core.windows.net/private/images/2673265f-0883-4a17-a64a-13b93f2cda7f/generated_00.png?se=2024-02-29T03%3A58%3A38Z&sig=5HqW9fGGNf5w49XxK6BUM9AdHckJqY%2Bl5mcipFDQVPM%3D&ske=2024-03-06T00%3A37%3A15Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2024-02-28T00%3A37%3A15Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02&w=800&h=800&crop="; + + // Append the new image URL to the 'generatedImages' array + if (isset($active_homepage['generatedImages']) && is_array($active_homepage['generatedImages'])) { + $active_homepage['generatedImages'][] = $generatedDalleImage; + } else { + $active_homepage['generatedImages'] = array($generatedDalleImage); // In case 'generatedImages' is not set or not an array + } + /* + steps : 1) upload the images in wordpress media library + 2) make a mapping of generatedImages to the images in wordpress media library + 3) find the generatedImages urls in the block grammar + 4) replace them with the uploaded iamge urls + 5) update the contents in blockgrammar + 5) update the homepages in flow + */ + error_log("Sideload images called:".print_r($active_homepage,true)); + + $generatedImages = $active_homepage['generatedImages']; + // Now upload the images in the 'generatedImages' array to WordPress media library + $uploaded_image_urls = SiteGenService::upload_images_to_wp_media_library($generatedImages); + + $urlMapping = array_combine($generatedImages, $uploaded_image_urls); + + $content = $active_homepage['content']; + foreach ($urlMapping as $oldUrl => $newUrl) { + // escaping any special characters in the old URL to avoid breaking the regex + $escapedOldUrl = preg_quote($oldUrl, '/'); + $content = preg_replace("/src=\"$escapedOldUrl\"/", "src=\"$newUrl\"", $content); + } + + // Update the content with new image URLs + $active_homepage['content'] = $content; + + error_log("Content after image sideload:".print_r($active_homepage['content'], true)); + + $data = FlowService::read_data_from_wp_option( false ); + if ( ! isset( $data['sitegen']['homepages']['active'] ) ) { return false; } - return ""; - } + $data['sitegen']['homepages']['active'] = $active_homepage; + FlowService::update_data_in_wp_option( $data ); -/* - public static function upload_images_to_wp_media_library($image_urls) { - require_once(ABSPATH . 'wp-admin/includes/file.php'); - require_once(ABSPATH . 'wp-admin/includes/media.php'); - require_once(ABSPATH . 'wp-admin/includes/image.php'); - - $uploaded_image_urls = array(); - - foreach ($image_urls as $image_url) { - // Check if the URL is valid - if (!filter_var($image_url, FILTER_VALIDATE_URL)) { - continue; - } - - // Fetch the image via remote get - $response = wp_remote_get($image_url); - error_log("Uploaded attachment urls".print_r($response, true)); - if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { - continue; // Skip if request failed - } - - $headers = wp_remote_retrieve_headers($response); - $contentType = $headers['content-type'] ?? ''; - $image_data = wp_remote_retrieve_body($response); - if (empty($contentType) || empty($image_data)) { - continue; // Skip if no content type or image data is present - } - - // Determine the file extension based on MIME type - $file_extension = ''; - switch ($contentType) { - case 'image/jpeg': - $file_extension = '.jpg'; - break; - case 'image/png': - $file_extension = '.png'; - break; - case 'image/gif': - $file_extension = '.gif'; - break; - case 'image/webp': - $file_extension = '.webp'; - break; - default: - // Log or handle unsupported MIME types as needed - error_log('Unsupported MIME type: ' . $contentType); - continue; // Skip files with unsupported MIME types - } - // create upload directory - $upload_dir = wp_upload_dir(); - - // xtract a filename from the URL - $parsed_url = parse_url($image_url); - $path_parts = pathinfo($parsed_url['path']); - //filename to be added in directory - $original_filename = $path_parts['filename'] . $file_extension; - - // Ensure the filename is unique within the upload directory - $filename = wp_unique_filename($upload_dir['path'], $original_filename); - $filepath = $upload_dir['path'] . '/' . $filename; - - // Save the image to the uploads directory - file_put_contents($filepath, $image_data); - - // Create an attachment post for the image - $attachment = array( - 'guid' => $upload_dir['url'] . '/' . $filename, - 'post_mime_type' => $contentType, - 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), - 'post_content' => '', - 'post_status' => 'inherit' - ); - - $attach_id = wp_insert_attachment($attachment, $filepath); - - // Generate and assign metadata for the attachment - $attach_data = wp_generate_attachment_metadata($attach_id, $filepath); - wp_update_attachment_metadata($attach_id, $attach_data); - - // Add the WordPress attachment URL to the list - if ($attach_id) { - $uploaded_image_urls[] = wp_get_attachment_url($attach_id); - } - } - error_log("Uploaded attachment urls".print_r($uploaded_image_urls, true)); - return $uploaded_image_urls; - } - */ + + // return $active_homepage; + } } From 885ba93b0259d50a6816e4d60cfe047b5ee400c9 Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Thu, 29 Feb 2024 02:39:52 +0530 Subject: [PATCH 03/13] updated acrive and home page data --- includes/Services/SiteGenService.php | 118 +++++++++++++++++++++++++-- 1 file changed, 109 insertions(+), 9 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index cca80bf..7167efc 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -133,7 +133,8 @@ public static function instantiate_site_meta( $site_info, $identifier, $skip_cac * @return boolean */ public static function complete( $active_homepage, $homepage_data ) { - $show_pages_on_front = \get_option( Options::get_option_name( 'show_on_front', false ) ); + self::sideload_and_replace( $active_homepage ); + /* $show_pages_on_front = \get_option( Options::get_option_name( 'show_on_front', false ) ); // Check if default homepage is posts. if ( 'posts' === $show_pages_on_front ) { @@ -199,7 +200,7 @@ public static function complete( $active_homepage, $homepage_data ) { ThemeGeneratorService::activate_theme( $active_homepage['slug'] ); self::trash_sample_page(); - container()->get( 'cachePurger' )->purgeAll(); + container()->get( 'cachePurger' )->purgeAll(); */ return true; } @@ -990,12 +991,12 @@ public static function get_nav_link_grammar_from_post_data( $id, $name, $url ) { return ""; } - +/* public static function upload_images_to_wp_media_library($image_urls) { require_once(ABSPATH . 'wp-admin/includes/media.php'); require_once(ABSPATH . 'wp-admin/includes/file.php'); require_once(ABSPATH . 'wp-admin/includes/image.php'); - + error_log("wp media lib image_urls: " . print_r($image_urls, true)); $uploaded_image_urls = array(); foreach ($image_urls as $image_url) { @@ -1007,7 +1008,7 @@ public static function upload_images_to_wp_media_library($image_urls) { // Sideload image without attaching it to any post // The $post_id parameter is set to 0, indicating no post attachment $sideloaded_image_id = media_sideload_image($image_url, 0, null, 'id'); - + error_log("wp media lib image_urls: " . print_r($sideloaded_image_id, true)); // Check for errors if (is_wp_error($sideloaded_image_id)) { error_log("Error sideloading image: " . $sideloaded_image_id->get_error_message()); @@ -1025,15 +1026,104 @@ public static function upload_images_to_wp_media_library($image_urls) { error_log("Uploaded attachment URLs: " . print_r($uploaded_image_urls, true)); return $uploaded_image_urls; - } + } */ + + + public static function upload_images_to_wp_media_library($image_urls) { + require_once(ABSPATH . 'wp-admin/includes/file.php'); + require_once(ABSPATH . 'wp-admin/includes/media.php'); + require_once(ABSPATH . 'wp-admin/includes/image.php'); + + $uploaded_image_urls = array(); + + foreach ($image_urls as $image_url) { + // Check if the URL is valid + if (!filter_var($image_url, FILTER_VALIDATE_URL)) { + continue; + } + + // Fetch the image via remote get + $response = wp_remote_get($image_url); + error_log("Uploaded response urls".print_r($response, true)); + if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { + continue; // Skip if request failed + } + + $headers = wp_remote_retrieve_headers($response); + $contentType = $headers['content-type'] ?? ''; + $image_data = wp_remote_retrieve_body($response); + if (empty($contentType) || empty($image_data)) { + continue; // Skip if no content type or image data is present + } + + // Determine the file extension based on MIME type + $file_extension = ''; + switch ($contentType) { + case 'image/jpeg': + $file_extension = '.jpg'; + break; + case 'image/png': + $file_extension = '.png'; + break; + case 'image/gif': + $file_extension = '.gif'; + break; + case 'image/webp': + $file_extension = '.webp'; + break; + default: + // Log or handle unsupported MIME types as needed + error_log('Unsupported MIME type: ' . $contentType); + continue; // Skip files with unsupported MIME types + } + // create upload directory + $upload_dir = wp_upload_dir(); + + // xtract a filename from the URL + $parsed_url = parse_url($image_url); + $path_parts = pathinfo($parsed_url['path']); + //filename to be added in directory + $original_filename = $path_parts['filename'] . $file_extension; + + // Ensure the filename is unique within the upload directory + $filename = wp_unique_filename($upload_dir['path'], $original_filename); + $filepath = $upload_dir['path'] . '/' . $filename; + + // Save the image to the uploads directory + file_put_contents($filepath, $image_data); + + // Create an attachment post for the image + $attachment = array( + 'guid' => $upload_dir['url'] . '/' . $filename, + 'post_mime_type' => $contentType, + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), + 'post_content' => '', + 'post_status' => 'inherit' + ); + + $attach_id = wp_insert_attachment($attachment, $filepath); + + // Generate and assign metadata for the attachment + $attach_data = wp_generate_attachment_metadata($attach_id, $filepath); + wp_update_attachment_metadata($attach_id, $attach_data); + + // Add the WordPress attachment URL to the list + if ($attach_id) { + $uploaded_image_urls[] = wp_get_attachment_url($attach_id); + } + } + error_log("Uploaded attachment urls".print_r($uploaded_image_urls, true)); + return $uploaded_image_urls; + } + public static function sideload_and_replace($active_homepage){ - $generatedDalleImage = "https://dalleprodsec.blob.core.windows.net/private/images/2673265f-0883-4a17-a64a-13b93f2cda7f/generated_00.png?se=2024-02-29T03%3A58%3A38Z&sig=5HqW9fGGNf5w49XxK6BUM9AdHckJqY%2Bl5mcipFDQVPM%3D&ske=2024-03-06T00%3A37%3A15Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2024-02-28T00%3A37%3A15Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02&w=800&h=800&crop="; + $generatedDalleImage = ["https://dalleprodsec.blob.core.windows.net/private/images/9837a6ea-ec66-470e-b527-762ee62bef2e/generated_00.png?se=2024-02-29T13%3A18%3A38Z&sig=pwmLmfLDGlcyPa9EGaCB%2FaMZGH1JFC2W59BKybaG3LQ%3D&ske=2024-03-06T05%3A49%3A17Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2024-02-28T05%3A49%3A17Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02&w=1000&h=&crop=",]; // Append the new image URL to the 'generatedImages' array if (isset($active_homepage['generatedImages']) && is_array($active_homepage['generatedImages'])) { - $active_homepage['generatedImages'][] = $generatedDalleImage; + $active_homepage['generatedImages'] = $generatedDalleImage; } else { $active_homepage['generatedImages'] = array($generatedDalleImage); // In case 'generatedImages' is not set or not an array } @@ -1045,11 +1135,12 @@ public static function sideload_and_replace($active_homepage){ 5) update the contents in blockgrammar 5) update the homepages in flow */ - error_log("Sideload images called:".print_r($active_homepage,true)); $generatedImages = $active_homepage['generatedImages']; + error_log("Sideload images called:".print_r($generatedImages,true)); // Now upload the images in the 'generatedImages' array to WordPress media library $uploaded_image_urls = SiteGenService::upload_images_to_wp_media_library($generatedImages); + error_log("uploaded image urls:".print_r($uploaded_image_urls, true)); $urlMapping = array_combine($generatedImages, $uploaded_image_urls); @@ -1071,6 +1162,15 @@ public static function sideload_and_replace($active_homepage){ } $data['sitegen']['homepages']['active'] = $active_homepage; + + foreach ($data['sitegen']['homepages']['data'] as $homepagesData => &$homepageData) { + error_log("homepageData['slug'] slug:".print_r($homepageData['slug'], true)); + error_log("active_homepage['slug']:".print_r($active_homepage['slug'], true)); + if ($homepageData['slug'] === $active_homepage['slug']) { + $homepageData = $active_homepage; // Update the version with the changes + break; // Stop the loop after updating the matching version + } + } FlowService::update_data_in_wp_option( $data ); From adfcdf2a2992948ed23ebbe4bd6c50b1f29b149b Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Thu, 29 Feb 2024 02:41:43 +0530 Subject: [PATCH 04/13] removed comment --- includes/Services/SiteGenService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index 7167efc..ee51475 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -134,7 +134,7 @@ public static function instantiate_site_meta( $site_info, $identifier, $skip_cac */ public static function complete( $active_homepage, $homepage_data ) { self::sideload_and_replace( $active_homepage ); - /* $show_pages_on_front = \get_option( Options::get_option_name( 'show_on_front', false ) ); + $show_pages_on_front = \get_option( Options::get_option_name( 'show_on_front', false ) ); // Check if default homepage is posts. if ( 'posts' === $show_pages_on_front ) { @@ -200,7 +200,7 @@ public static function complete( $active_homepage, $homepage_data ) { ThemeGeneratorService::activate_theme( $active_homepage['slug'] ); self::trash_sample_page(); - container()->get( 'cachePurger' )->purgeAll(); */ + container()->get( 'cachePurger' )->purgeAll(); return true; } From 0e87e65d62974f4c9dfb455151b90f67cd5f4dc1 Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Thu, 29 Feb 2024 22:39:50 +0530 Subject: [PATCH 05/13] added regex check --- includes/Services/SiteGenService.php | 53 ++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index ee51475..5a2be6a 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -1044,16 +1044,15 @@ public static function upload_images_to_wp_media_library($image_urls) { // Fetch the image via remote get $response = wp_remote_get($image_url); - error_log("Uploaded response urls".print_r($response, true)); if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { - continue; // Skip if request failed + continue; } $headers = wp_remote_retrieve_headers($response); $contentType = $headers['content-type'] ?? ''; $image_data = wp_remote_retrieve_body($response); if (empty($contentType) || empty($image_data)) { - continue; // Skip if no content type or image data is present + continue; } // Determine the file extension based on MIME type @@ -1072,9 +1071,8 @@ public static function upload_images_to_wp_media_library($image_urls) { $file_extension = '.webp'; break; default: - // Log or handle unsupported MIME types as needed error_log('Unsupported MIME type: ' . $contentType); - continue; // Skip files with unsupported MIME types + continue; } // create upload directory $upload_dir = wp_upload_dir(); @@ -1113,20 +1111,34 @@ public static function upload_images_to_wp_media_library($image_urls) { } } error_log("Uploaded attachment urls".print_r($uploaded_image_urls, true)); - return $uploaded_image_urls; + return $uploaded_image_urls; + + /* $home_url = home_url(); + + $relative_image_urls = array(); + + foreach ($uploaded_image_urls as $full_url) { + // Remove the domain part from the full URL + $relative_url = str_replace($home_url, '', $full_url); + $relative_image_urls[] = $relative_url; + } + + error_log("Uploaded relative attachment urls".print_r($relative_image_urls, true)); + return $relative_image_urls; */ } public static function sideload_and_replace($active_homepage){ - $generatedDalleImage = ["https://dalleprodsec.blob.core.windows.net/private/images/9837a6ea-ec66-470e-b527-762ee62bef2e/generated_00.png?se=2024-02-29T13%3A18%3A38Z&sig=pwmLmfLDGlcyPa9EGaCB%2FaMZGH1JFC2W59BKybaG3LQ%3D&ske=2024-03-06T05%3A49%3A17Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2024-02-28T05%3A49%3A17Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02&w=1000&h=&crop=",]; + /* // $generatedDalleImage = ["https://dalleprodsec.blob.core.windows.net/private/images/9837a6ea-ec66-470e-b527-762ee62bef2e/generated_00.png?se=2024-02-29T13%3A18%3A38Z&sig=pwmLmfLDGlcyPa9EGaCB%2FaMZGH1JFC2W59BKybaG3LQ%3D&ske=2024-03-06T05%3A49%3A17Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2024-02-28T05%3A49%3A17Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02&w=1000&h=&crop=",]; + $generatedDalleImage = ["https://dalleprodsec.blob.core.windows.net/private/images/0ace3576-cf7e-48f4-b069-33437e2874d2/generated_00.png?se=2024-03-01T08%3A57%3A08Z&sig=LHvXV%2Fp1QGzn0lxtUks0Q%2BcwAovZrOSOIA2rJZrfUjA%3D&ske=2024-03-07T07%3A58%3A28Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2024-02-29T07%3A58%3A28Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02&w=300&h=300&crop="]; // Append the new image URL to the 'generatedImages' array if (isset($active_homepage['generatedImages']) && is_array($active_homepage['generatedImages'])) { $active_homepage['generatedImages'] = $generatedDalleImage; } else { $active_homepage['generatedImages'] = array($generatedDalleImage); // In case 'generatedImages' is not set or not an array - } + } */ /* steps : 1) upload the images in wordpress media library 2) make a mapping of generatedImages to the images in wordpress media library @@ -1136,8 +1148,14 @@ public static function sideload_and_replace($active_homepage){ 5) update the homepages in flow */ + if (isset($active_homepage['generatedImages']) && is_array($active_homepage['generatedImages'])) { + $generatedImages = $active_homepage['generatedImages']; + } else { + return; + } + $generatedImages = $active_homepage['generatedImages']; - error_log("Sideload images called:".print_r($generatedImages,true)); + error_log("IMAGE FROM ACTIVE HOMEPAGE:".print_r($generatedImages,true)); // Now upload the images in the 'generatedImages' array to WordPress media library $uploaded_image_urls = SiteGenService::upload_images_to_wp_media_library($generatedImages); error_log("uploaded image urls:".print_r($uploaded_image_urls, true)); @@ -1148,13 +1166,22 @@ public static function sideload_and_replace($active_homepage){ foreach ($urlMapping as $oldUrl => $newUrl) { // escaping any special characters in the old URL to avoid breaking the regex $escapedOldUrl = preg_quote($oldUrl, '/'); - $content = preg_replace("/src=\"$escapedOldUrl\"/", "src=\"$newUrl\"", $content); + error_log("escaped old url:".print_r($escapedOldUrl, true)); +/* $escapedOldUrlregex = '/'.$escapedOldUrl.'.*?"/m'; + $content = preg_replace($escapedOldUrlregex, $newUrl.'"', $content); */ + + $escapedOldUrlRegexDoubleQuote = '/"' . $escapedOldUrl . '.*?"/m'; + $content = preg_replace($escapedOldUrlRegexDoubleQuote, '"'. $newUrl . '"', $content); + + $escapedOldUrlRegexParenthesis = '/\(' . $escapedOldUrl . '.*?\)/m'; + $content = preg_replace($escapedOldUrlRegexParenthesis, '('. $newUrl . ')', $content); + + // $content = preg_replace("/src=\"$escapedOldUrl\"/", "src=\"$newUrl\"", $content); + // $content = str_replace($oldUrl, $newUrl, $content); } // Update the content with new image URLs $active_homepage['content'] = $content; - - error_log("Content after image sideload:".print_r($active_homepage['content'], true)); $data = FlowService::read_data_from_wp_option( false ); if ( ! isset( $data['sitegen']['homepages']['active'] ) ) { @@ -1164,8 +1191,6 @@ public static function sideload_and_replace($active_homepage){ $data['sitegen']['homepages']['active'] = $active_homepage; foreach ($data['sitegen']['homepages']['data'] as $homepagesData => &$homepageData) { - error_log("homepageData['slug'] slug:".print_r($homepageData['slug'], true)); - error_log("active_homepage['slug']:".print_r($active_homepage['slug'], true)); if ($homepageData['slug'] === $active_homepage['slug']) { $homepageData = $active_homepage; // Update the version with the changes break; // Stop the loop after updating the matching version From 069450b830f0a9709060aeb5617b21abeaa8c290 Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Fri, 1 Mar 2024 15:04:25 +0530 Subject: [PATCH 06/13] added formatting and comments --- includes/Services/SiteGenService.php | 349 ++++++++++++--------------- 1 file changed, 150 insertions(+), 199 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index 5a2be6a..4b9a3b9 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -133,7 +133,9 @@ public static function instantiate_site_meta( $site_info, $identifier, $skip_cac * @return boolean */ public static function complete( $active_homepage, $homepage_data ) { + /* Replace dalle images */ self::sideload_and_replace( $active_homepage ); + $show_pages_on_front = \get_option( Options::get_option_name( 'show_on_front', false ) ); // Check if default homepage is posts. @@ -141,7 +143,7 @@ public static function complete( $active_homepage, $homepage_data ) { \update_option( Options::get_option_name( 'show_on_front', false ), 'page' ); } - // Setting page title from sitemap option + // Setting page title from sitemap option. $title = $active_homepage['title']; $prompt = self::get_prompt(); $site_info = array( 'site_description' => $prompt ); @@ -474,13 +476,13 @@ public static function process_homepages_response( $homepage_slug = 'version-' . $version_number; $processed_homepages[ $homepage_slug ] = array( - 'slug' => $homepage_slug, - 'title' => __( 'Version ', 'wp-module-onboarding' ) . $version_number, - 'isFavorite' => false, - 'content' => $data['content'], - 'header' => $data['header'], - 'footer' => $data['footer'], - 'color' => $selected_palette, + 'slug' => $homepage_slug, + 'title' => __( 'Version ', 'wp-module-onboarding' ) . $version_number, + 'isFavorite' => false, + 'content' => $data['content'], + 'header' => $data['header'], + 'footer' => $data['footer'], + 'color' => $selected_palette, 'generatedImages' => $data['generatedImages'], ); ++$version_number; @@ -887,7 +889,7 @@ public static function publish_sitemap_pages( $site_description, $content_style, return true; } - + /** * Trash the "Sample Page" generated for all new sites. * @@ -917,12 +919,12 @@ public static function instantiate_sitegen_hooks() { */ public static function set_site_title_and_tagline( $site_details ) { - // Updates the Site Title + // Updates the Site Title. if ( ( ! empty( $site_details['site_title'] ) ) ) { \update_option( Options::get_option_name( 'blog_name', false ), $site_details['site_title'] ); } - // Updates the Site Desc (Tagline) + // Updates the Site Desc (Tagline). if ( ( ! empty( $site_details['tagline'] ) ) ) { \update_option( Options::get_option_name( 'blog_description', false ), $site_details['tagline'] ); } @@ -991,214 +993,163 @@ public static function get_nav_link_grammar_from_post_data( $id, $name, $url ) { return ""; } -/* - public static function upload_images_to_wp_media_library($image_urls) { - require_once(ABSPATH . 'wp-admin/includes/media.php'); - require_once(ABSPATH . 'wp-admin/includes/file.php'); - require_once(ABSPATH . 'wp-admin/includes/image.php'); - error_log("wp media lib image_urls: " . print_r($image_urls, true)); + + /** + * Uploads images to the WordPress media library as attachments. + * + * This function takes an array of image URLs, downloads them, and + * uploads them to the WordPress media library, returning the URLs + * of the newly uploaded images. + * + * @param array $image_urls An array of image URLs to upload. + * @return array|false An array of WordPress attachment URLs on success, false on failure. + * @throws Exception If there is an error during the upload process. + */ + public static function upload_images_to_wp_media_library( $image_urls ) { + require_once ABSPATH . 'wp-admin/includes/file.php'; + require_once ABSPATH . 'wp-admin/includes/media.php'; + require_once ABSPATH . 'wp-admin/includes/image.php'; + $uploaded_image_urls = array(); - - foreach ($image_urls as $image_url) { - // Check if the URL is valid - if (!filter_var($image_url, FILTER_VALIDATE_URL)) { - continue; - } - - // Sideload image without attaching it to any post - // The $post_id parameter is set to 0, indicating no post attachment - $sideloaded_image_id = media_sideload_image($image_url, 0, null, 'id'); - error_log("wp media lib image_urls: " . print_r($sideloaded_image_id, true)); - // Check for errors - if (is_wp_error($sideloaded_image_id)) { - error_log("Error sideloading image: " . $sideloaded_image_id->get_error_message()); - continue; - } - - // Get the URL of the uploaded image - $image_url = wp_get_attachment_url($sideloaded_image_id); - if ($image_url) { - $uploaded_image_urls[] = $image_url; - } else { - error_log("Error retrieving uploaded image URL for image ID: $sideloaded_image_id"); - } - } - - error_log("Uploaded attachment URLs: " . print_r($uploaded_image_urls, true)); - return $uploaded_image_urls; - } */ - - - public static function upload_images_to_wp_media_library($image_urls) { - require_once(ABSPATH . 'wp-admin/includes/file.php'); - require_once(ABSPATH . 'wp-admin/includes/media.php'); - require_once(ABSPATH . 'wp-admin/includes/image.php'); - - $uploaded_image_urls = array(); - - foreach ($image_urls as $image_url) { - // Check if the URL is valid - if (!filter_var($image_url, FILTER_VALIDATE_URL)) { - continue; - } - - // Fetch the image via remote get - $response = wp_remote_get($image_url); - if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { - continue; - } - - $headers = wp_remote_retrieve_headers($response); - $contentType = $headers['content-type'] ?? ''; - $image_data = wp_remote_retrieve_body($response); - if (empty($contentType) || empty($image_data)) { - continue; - } - - // Determine the file extension based on MIME type - $file_extension = ''; - switch ($contentType) { - case 'image/jpeg': - $file_extension = '.jpg'; - break; - case 'image/png': - $file_extension = '.png'; - break; - case 'image/gif': - $file_extension = '.gif'; - break; - case 'image/webp': - $file_extension = '.webp'; - break; - default: - error_log('Unsupported MIME type: ' . $contentType); - continue; - } - // create upload directory - $upload_dir = wp_upload_dir(); - - // xtract a filename from the URL - $parsed_url = parse_url($image_url); - $path_parts = pathinfo($parsed_url['path']); - //filename to be added in directory - $original_filename = $path_parts['filename'] . $file_extension; - - // Ensure the filename is unique within the upload directory - $filename = wp_unique_filename($upload_dir['path'], $original_filename); - $filepath = $upload_dir['path'] . '/' . $filename; - - // Save the image to the uploads directory - file_put_contents($filepath, $image_data); - - // Create an attachment post for the image - $attachment = array( - 'guid' => $upload_dir['url'] . '/' . $filename, - 'post_mime_type' => $contentType, - 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), - 'post_content' => '', - 'post_status' => 'inherit' - ); - - $attach_id = wp_insert_attachment($attachment, $filepath); - - // Generate and assign metadata for the attachment - $attach_data = wp_generate_attachment_metadata($attach_id, $filepath); - wp_update_attachment_metadata($attach_id, $attach_data); - - // Add the WordPress attachment URL to the list - if ($attach_id) { - $uploaded_image_urls[] = wp_get_attachment_url($attach_id); - } - } - error_log("Uploaded attachment urls".print_r($uploaded_image_urls, true)); - return $uploaded_image_urls; + try { + foreach ( $image_urls as $image_url ) { + // Check if the URL is valid. + if ( ! filter_var( $image_url, FILTER_VALIDATE_URL ) ) { + continue; + } - /* $home_url = home_url(); + // Fetch the image via remote get. + $response = wp_remote_get( $image_url ); + if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { + continue; + } + + // Reading the headers from the image url to determine. + $headers = wp_remote_retrieve_headers( $response ); + $content_type = $headers['content-type'] ?? ''; + $image_data = wp_remote_retrieve_body( $response ); + if ( empty( $content_type ) || empty( $image_data ) ) { + continue; + } - $relative_image_urls = array(); + // Determine the file extension based on MIME type. + $file_extension = ''; + switch ( $content_type ) { + case 'image/jpeg': + $file_extension = '.jpg'; + break; + case 'image/png': + $file_extension = '.png'; + break; + case 'image/gif': + $file_extension = '.gif'; + break; + case 'image/webp': + $file_extension = '.webp'; + break; + default: + error_log( 'Unsupported MIME type: ' . $content_type ); + continue; + } + // create upload directory. + $upload_dir = wp_upload_dir(); + + // xtract a filename from the URL. + $parsed_url = parse_url( $image_url ); + $path_parts = pathinfo( $parsed_url['path'] ); + // filename to be added in directory. + $original_filename = $path_parts['filename'] . $file_extension; + + // to ensure the filename is unique within the upload directory. + $filename = wp_unique_filename( $upload_dir['path'], $original_filename ); + $filepath = $upload_dir['path'] . '/' . $filename; + + // Saving the image to the uploads directory. + file_put_contents( $filepath, $image_data ); + + // Create an attachment post for the image, metadata needed for WordPress media library. + // guid -for url, post_title for cleaned up name, post content is empty as this is an attachment. + // post_status inherit is for visibility. + $attachment = array( + 'guid' => $upload_dir['url'] . '/' . $filename, + 'post_mime_type' => $content_type, + 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), + 'post_content' => '', + 'post_status' => 'inherit', + ); - foreach ($uploaded_image_urls as $full_url) { - // Remove the domain part from the full URL - $relative_url = str_replace($home_url, '', $full_url); - $relative_image_urls[] = $relative_url; + $attach_id = wp_insert_attachment( $attachment, $filepath ); + + // Generate and assign metadata for the attachment.. + $attach_data = wp_generate_attachment_metadata( $attach_id, $filepath ); + wp_update_attachment_metadata( $attach_id, $attach_data ); + + // Add the WordPress attachment URL to the list.. + if ( $attach_id ) { + $attachment_url = wp_get_attachment_url( $attach_id ); + if ( ! $attachment_url ) { + throw new Exception( 'Failed to retrieve attachment URL for attachment ID: ' . $attach_id ); + } + $uploaded_image_urls[] = $attachment_url; + } + } + } catch ( Exception $e ) { + error_log( $e->getMessage() ); } - error_log("Uploaded relative attachment urls".print_r($relative_image_urls, true)); - return $relative_image_urls; */ - } + return $uploaded_image_urls; + } - + /** + * Replace the uploaded images in the block grammar. + * + * This function takes the active homepage array, processes it to + * replace old image URLs with new ones based on some criteria or + * operations performed within the function. + * + * @param array $active_homepage The active homepage data, including block grammar and image URLs. + */ + public static function sideload_and_replace( $active_homepage ) { - public static function sideload_and_replace($active_homepage){ - /* // $generatedDalleImage = ["https://dalleprodsec.blob.core.windows.net/private/images/9837a6ea-ec66-470e-b527-762ee62bef2e/generated_00.png?se=2024-02-29T13%3A18%3A38Z&sig=pwmLmfLDGlcyPa9EGaCB%2FaMZGH1JFC2W59BKybaG3LQ%3D&ske=2024-03-06T05%3A49%3A17Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2024-02-28T05%3A49%3A17Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02&w=1000&h=&crop=",]; - $generatedDalleImage = ["https://dalleprodsec.blob.core.windows.net/private/images/0ace3576-cf7e-48f4-b069-33437e2874d2/generated_00.png?se=2024-03-01T08%3A57%3A08Z&sig=LHvXV%2Fp1QGzn0lxtUks0Q%2BcwAovZrOSOIA2rJZrfUjA%3D&ske=2024-03-07T07%3A58%3A28Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2024-02-29T07%3A58%3A28Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02&w=300&h=300&crop="]; - - // Append the new image URL to the 'generatedImages' array - if (isset($active_homepage['generatedImages']) && is_array($active_homepage['generatedImages'])) { - $active_homepage['generatedImages'] = $generatedDalleImage; - } else { - $active_homepage['generatedImages'] = array($generatedDalleImage); // In case 'generatedImages' is not set or not an array - } */ - /* - steps : 1) upload the images in wordpress media library - 2) make a mapping of generatedImages to the images in wordpress media library - 3) find the generatedImages urls in the block grammar - 4) replace them with the uploaded iamge urls - 5) update the contents in blockgrammar - 5) update the homepages in flow - */ - - if (isset($active_homepage['generatedImages']) && is_array($active_homepage['generatedImages'])) { - $generatedImages = $active_homepage['generatedImages']; + if ( isset( $active_homepage['generatedImages'] ) && is_array( $active_homepage['generatedImages'] ) ) { + $generated_images = $active_homepage['generatedImages']; } else { return; } - $generatedImages = $active_homepage['generatedImages']; - error_log("IMAGE FROM ACTIVE HOMEPAGE:".print_r($generatedImages,true)); - // Now upload the images in the 'generatedImages' array to WordPress media library - $uploaded_image_urls = SiteGenService::upload_images_to_wp_media_library($generatedImages); - error_log("uploaded image urls:".print_r($uploaded_image_urls, true)); - - $urlMapping = array_combine($generatedImages, $uploaded_image_urls); - - $content = $active_homepage['content']; - foreach ($urlMapping as $oldUrl => $newUrl) { - // escaping any special characters in the old URL to avoid breaking the regex - $escapedOldUrl = preg_quote($oldUrl, '/'); - error_log("escaped old url:".print_r($escapedOldUrl, true)); -/* $escapedOldUrlregex = '/'.$escapedOldUrl.'.*?"/m'; - $content = preg_replace($escapedOldUrlregex, $newUrl.'"', $content); */ - - $escapedOldUrlRegexDoubleQuote = '/"' . $escapedOldUrl . '.*?"/m'; - $content = preg_replace($escapedOldUrlRegexDoubleQuote, '"'. $newUrl . '"', $content); - - $escapedOldUrlRegexParenthesis = '/\(' . $escapedOldUrl . '.*?\)/m'; - $content = preg_replace($escapedOldUrlRegexParenthesis, '('. $newUrl . ')', $content); - - // $content = preg_replace("/src=\"$escapedOldUrl\"/", "src=\"$newUrl\"", $content); - // $content = str_replace($oldUrl, $newUrl, $content); - } - - // Update the content with new image URLs - $active_homepage['content'] = $content; - + // Upload the images in the 'generatedImages' array to WordPress media library. + $uploaded_image_urls = self::upload_images_to_wp_media_library( $generated_images ); + + $url_mapping = array_combine( $generated_images, $uploaded_image_urls ); + + $content = $active_homepage['content']; + foreach ( $url_mapping as $old_url => $new_url ) { + // escaping any special characters in the old URL to avoid breaking the regex. + $escaped_old_url = preg_quote( $old_url, '/' ); + + $escaped_old_url_regex_double_quote = '/"' . $escaped_old_url . '.*?"/m'; + $content = preg_replace( $escaped_old_url_regex_double_quote, '"' . $new_url . '"', $content ); + + $escaped_old_url_regex_parenthesis = '/\(' . $escaped_old_url . '.*?\)/m'; + $content = preg_replace( $escaped_old_url_regex_parenthesis, '(' . $new_url . ')', $content ); + } + + // Update the content with new image URLs. + $active_homepage['content'] = $content; + $data = FlowService::read_data_from_wp_option( false ); if ( ! isset( $data['sitegen']['homepages']['active'] ) ) { return false; } $data['sitegen']['homepages']['active'] = $active_homepage; - - foreach ($data['sitegen']['homepages']['data'] as $homepagesData => &$homepageData) { - if ($homepageData['slug'] === $active_homepage['slug']) { - $homepageData = $active_homepage; // Update the version with the changes - break; // Stop the loop after updating the matching version + + foreach ( $data['sitegen']['homepages']['data'] as $homepages_data => &$homepage_data ) { + if ( $homepage_data['slug'] === $active_homepage['slug'] ) { + $homepage_data = $active_homepage; + break; } } FlowService::update_data_in_wp_option( $data ); - - - // return $active_homepage; } } From f6340b2088fc2f27cd6ece15777bf83082202ad2 Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Sun, 3 Mar 2024 20:46:09 +0530 Subject: [PATCH 07/13] Update includes/Services/SiteGenService.php refactored Co-authored-by: Allen Benny <48691514+officiallygod@users.noreply.github.com> --- includes/Services/SiteGenService.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index 4b9a3b9..0b8aebd 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -1111,14 +1111,12 @@ public static function upload_images_to_wp_media_library( $image_urls ) { */ public static function sideload_and_replace( $active_homepage ) { - if ( isset( $active_homepage['generatedImages'] ) && is_array( $active_homepage['generatedImages'] ) ) { - $generated_images = $active_homepage['generatedImages']; - } else { + if ( !isset( $active_homepage['generatedImages'] ) || !is_array( $active_homepage['generatedImages'] ) ) { return; - } + } // Upload the images in the 'generatedImages' array to WordPress media library. - $uploaded_image_urls = self::upload_images_to_wp_media_library( $generated_images ); + $uploaded_image_urls = self::upload_images_to_wp_media_library( $active_homepage['generatedImages'] ); $url_mapping = array_combine( $generated_images, $uploaded_image_urls ); From 365aba64f993e09fa6d0e19ee77ce13cf8f852f5 Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Mon, 4 Mar 2024 11:55:40 +0530 Subject: [PATCH 08/13] added null for corrupt uploads and null check --- includes/Services/SiteGenService.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index 0b8aebd..d4c6c1d 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -134,7 +134,7 @@ public static function instantiate_site_meta( $site_info, $identifier, $skip_cac */ public static function complete( $active_homepage, $homepage_data ) { /* Replace dalle images */ - self::sideload_and_replace( $active_homepage ); + self::sideload_images_and_replace_grammar( $active_homepage ); $show_pages_on_front = \get_option( Options::get_option_name( 'show_on_front', false ) ); @@ -1010,7 +1010,7 @@ public static function upload_images_to_wp_media_library( $image_urls ) { require_once ABSPATH . 'wp-admin/includes/media.php'; require_once ABSPATH . 'wp-admin/includes/image.php'; - $uploaded_image_urls = array(); + $uploaded_image_urls = array_fill_keys( $image_urls, null ); try { foreach ( $image_urls as $image_url ) { // Check if the URL is valid. @@ -1109,11 +1109,11 @@ public static function upload_images_to_wp_media_library( $image_urls ) { * * @param array $active_homepage The active homepage data, including block grammar and image URLs. */ - public static function sideload_and_replace( $active_homepage ) { + public static function sideload_images_and_replace_grammar( $active_homepage ) { - if ( !isset( $active_homepage['generatedImages'] ) || !is_array( $active_homepage['generatedImages'] ) ) { + if ( ! isset( $active_homepage['generatedImages'] ) || ! is_array( $active_homepage['generatedImages'] ) ) { return; - } + } // Upload the images in the 'generatedImages' array to WordPress media library. $uploaded_image_urls = self::upload_images_to_wp_media_library( $active_homepage['generatedImages'] ); @@ -1122,6 +1122,9 @@ public static function sideload_and_replace( $active_homepage ) { $content = $active_homepage['content']; foreach ( $url_mapping as $old_url => $new_url ) { + if ( null === $new_url ) { + continue; + } // escaping any special characters in the old URL to avoid breaking the regex. $escaped_old_url = preg_quote( $old_url, '/' ); From a7d8212e44cc2cab1c256e2d4a89196f91df85ea Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Mon, 4 Mar 2024 12:48:03 +0530 Subject: [PATCH 09/13] removed array_fill --- includes/Services/SiteGenService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index d4c6c1d..f1f8216 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -1010,7 +1010,7 @@ public static function upload_images_to_wp_media_library( $image_urls ) { require_once ABSPATH . 'wp-admin/includes/media.php'; require_once ABSPATH . 'wp-admin/includes/image.php'; - $uploaded_image_urls = array_fill_keys( $image_urls, null ); + $uploaded_image_urls = array(); try { foreach ( $image_urls as $image_url ) { // Check if the URL is valid. @@ -1088,7 +1088,8 @@ public static function upload_images_to_wp_media_library( $image_urls ) { if ( $attach_id ) { $attachment_url = wp_get_attachment_url( $attach_id ); if ( ! $attachment_url ) { - throw new Exception( 'Failed to retrieve attachment URL for attachment ID: ' . $attach_id ); + error_log('Failed to retrieve attachment URL for attachment ID: ' . $attach_id); + $attachment_url = null; } $uploaded_image_urls[] = $attachment_url; } @@ -1117,8 +1118,7 @@ public static function sideload_images_and_replace_grammar( $active_homepage ) { // Upload the images in the 'generatedImages' array to WordPress media library. $uploaded_image_urls = self::upload_images_to_wp_media_library( $active_homepage['generatedImages'] ); - - $url_mapping = array_combine( $generated_images, $uploaded_image_urls ); + $url_mapping = array_combine( $active_homepage['generatedImages'], $uploaded_image_urls ); $content = $active_homepage['content']; foreach ( $url_mapping as $old_url => $new_url ) { From 479a8e7ffcbcd367ec06fa661de5b71b3b8043a8 Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Mon, 4 Mar 2024 12:49:25 +0530 Subject: [PATCH 10/13] lint fix --- includes/Services/SiteGenService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index f1f8216..9a41851 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -1088,7 +1088,7 @@ public static function upload_images_to_wp_media_library( $image_urls ) { if ( $attach_id ) { $attachment_url = wp_get_attachment_url( $attach_id ); if ( ! $attachment_url ) { - error_log('Failed to retrieve attachment URL for attachment ID: ' . $attach_id); + error_log( 'Failed to retrieve attachment URL for attachment ID: ' . $attach_id ); $attachment_url = null; } $uploaded_image_urls[] = $attachment_url; @@ -1118,7 +1118,7 @@ public static function sideload_images_and_replace_grammar( $active_homepage ) { // Upload the images in the 'generatedImages' array to WordPress media library. $uploaded_image_urls = self::upload_images_to_wp_media_library( $active_homepage['generatedImages'] ); - $url_mapping = array_combine( $active_homepage['generatedImages'], $uploaded_image_urls ); + $url_mapping = array_combine( $active_homepage['generatedImages'], $uploaded_image_urls ); $content = $active_homepage['content']; foreach ( $url_mapping as $old_url => $new_url ) { From 6ba639151a0bf93d027077a923df8308e22e3fa0 Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Mon, 4 Mar 2024 15:50:00 +0530 Subject: [PATCH 11/13] refactored code --- includes/Services/SiteGenService.php | 52 +++++++++++++++------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index 9a41851..5ea4366 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -134,7 +134,8 @@ public static function instantiate_site_meta( $site_info, $identifier, $skip_cac */ public static function complete( $active_homepage, $homepage_data ) { /* Replace dalle images */ - self::sideload_images_and_replace_grammar( $active_homepage ); + + $active_homepage['content'] = self::sideload_images_and_replace_grammar( $active_homepage['content'], $active_homepage['generatedImages'] ); $show_pages_on_front = \get_option( Options::get_option_name( 'show_on_front', false ) ); @@ -197,7 +198,11 @@ public static function complete( $active_homepage, $homepage_data ) { if ( $data['isFavorite'] && $data['slug'] !== $active_homepage['slug'] ) { self::generate_child_theme( $data ); } + if ( $data['slug'] === $active_homepage['slug'] ) { + $homepage_data[ $active_homepage['slug'] ] = $active_homepage; + } } + self::sync_flow_data( $homepage_data ); ThemeGeneratorService::activate_theme( $active_homepage['slug'] ); @@ -1104,23 +1109,22 @@ public static function upload_images_to_wp_media_library( $image_urls ) { /** * Replace the uploaded images in the block grammar. * - * This function takes the active homepage array, processes it to - * replace old image URLs with new ones based on some criteria or - * operations performed within the function. + * This function takes a block of content and an array of new image URLs, uploads the images + * to the WordPress media library, and then replaces the old image URLs in the content + * with the new ones. * - * @param array $active_homepage The active homepage data, including block grammar and image URLs. + * @param array $content The block grammar containing the old image URLs. + * @param array $generated_image_urls An array of new image URLs to replace the old ones in the content. */ - public static function sideload_images_and_replace_grammar( $active_homepage ) { + public static function sideload_images_and_replace_grammar( $content, $generated_image_urls ) { - if ( ! isset( $active_homepage['generatedImages'] ) || ! is_array( $active_homepage['generatedImages'] ) ) { + if ( ! isset( $generated_image_urls ) || ! is_array( $generated_image_urls ) ) { return; } - // Upload the images in the 'generatedImages' array to WordPress media library. - $uploaded_image_urls = self::upload_images_to_wp_media_library( $active_homepage['generatedImages'] ); - $url_mapping = array_combine( $active_homepage['generatedImages'], $uploaded_image_urls ); + $uploaded_image_urls = self::upload_images_to_wp_media_library( $generated_image_urls ); + $url_mapping = array_combine( $generated_image_urls, $uploaded_image_urls ); - $content = $active_homepage['content']; foreach ( $url_mapping as $old_url => $new_url ) { if ( null === $new_url ) { continue; @@ -1136,21 +1140,19 @@ public static function sideload_images_and_replace_grammar( $active_homepage ) { } // Update the content with new image URLs. - $active_homepage['content'] = $content; - - $data = FlowService::read_data_from_wp_option( false ); - if ( ! isset( $data['sitegen']['homepages']['active'] ) ) { - return false; - } - - $data['sitegen']['homepages']['active'] = $active_homepage; + return $content; + } - foreach ( $data['sitegen']['homepages']['data'] as $homepages_data => &$homepage_data ) { - if ( $homepage_data['slug'] === $active_homepage['slug'] ) { - $homepage_data = $active_homepage; - break; - } - } + /** + * Syncs flow data with new updates. + * + * This function is responsible for updating the flow data with new home page data changes. + * + * @param array $updated_data The new data to be integrated into the existing flow data. + */ + public static function sync_flow_data( $updated_data ) { + $data = FlowService::read_data_from_wp_option( false ); + $data['sitegen']['homepages']['data'] = $updated_data; FlowService::update_data_in_wp_option( $data ); } } From c680fa915dbd5e636f7fcd50aa7458a262203165 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 4 Mar 2024 19:08:46 +0530 Subject: [PATCH 12/13] Remove array_combine() --- includes/Services/SiteGenService.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index 5ea4366..809cd5b 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -1096,7 +1096,7 @@ public static function upload_images_to_wp_media_library( $image_urls ) { error_log( 'Failed to retrieve attachment URL for attachment ID: ' . $attach_id ); $attachment_url = null; } - $uploaded_image_urls[] = $attachment_url; + $uploaded_image_urls[ $image_url ] = $attachment_url; } } } catch ( Exception $e ) { @@ -1122,8 +1122,7 @@ public static function sideload_images_and_replace_grammar( $content, $generated return; } // Upload the images in the 'generatedImages' array to WordPress media library. - $uploaded_image_urls = self::upload_images_to_wp_media_library( $generated_image_urls ); - $url_mapping = array_combine( $generated_image_urls, $uploaded_image_urls ); + $url_mapping = self::upload_images_to_wp_media_library( $generated_image_urls ); foreach ( $url_mapping as $old_url => $new_url ) { if ( null === $new_url ) { From 41edfdf77751eadf8f3513f4dbbf41ac51d8c3ef Mon Sep 17 00:00:00 2001 From: diDroid Date: Mon, 4 Mar 2024 19:26:24 +0530 Subject: [PATCH 13/13] bump dependency versions --- composer.json | 6 +- composer.lock | 233 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 217 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index e10f0b9..83789f9 100644 --- a/composer.json +++ b/composer.json @@ -24,12 +24,12 @@ "require": { "newfold-labs/wp-module-installer": "^1.1", "newfold-labs/wp-module-patterns": "^0.1.14", - "newfold-labs/wp-module-ai": "^1.1.5", + "newfold-labs/wp-module-ai": "^1.1.6", "wp-forge/wp-upgrade-handler": "^1.0", "mustache/mustache": "^2.14", "newfold-labs/wp-module-data": "^2.4.18", - "newfold-labs/wp-module-coming-soon": "^1.2.0", - "newfold-labs/wp-module-performance": "^1.3.0" + "newfold-labs/wp-module-coming-soon": "^1.2.3", + "newfold-labs/wp-module-performance": "^1.4.0" }, "require-dev": { "newfold-labs/wp-php-standards": "^1.2" diff --git a/composer.lock b/composer.lock index d59b924..d7053c4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,104 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "778e891a53d3c414fe0ca1d505c0d973", + "content-hash": "998138ef441dc42e81a583d7175c7251", "packages": [ + { + "name": "doctrine/inflector", + "version": "1.4.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/inflector.git", + "reference": "4bd5c1cdfcd00e9e2d8c484f79150f67e5d355d9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/4bd5c1cdfcd00e9e2d8c484f79150f67e5d355d9", + "reference": "4bd5c1cdfcd00e9e2d8c484f79150f67e5d355d9", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^8.0", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpstan/phpstan-strict-rules": "^0.12", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Inflector\\": "lib/Doctrine/Inflector", + "Doctrine\\Common\\Inflector\\": "lib/Doctrine/Common/Inflector" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.", + "homepage": "https://www.doctrine-project.org/projects/inflector.html", + "keywords": [ + "inflection", + "inflector", + "lowercase", + "manipulation", + "php", + "plural", + "singular", + "strings", + "uppercase", + "words" + ], + "support": { + "issues": "https://github.com/doctrine/inflector/issues", + "source": "https://github.com/doctrine/inflector/tree/1.4.4" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finflector", + "type": "tidelift" + } + ], + "time": "2021-04-16T17:34:40+00:00" + }, { "name": "mustache/mustache", "version": "v2.14.2", @@ -58,16 +154,16 @@ }, { "name": "newfold-labs/wp-module-ai", - "version": "1.1.5", + "version": "1.1.6", "source": { "type": "git", "url": "https://github.com/newfold-labs/wp-module-ai.git", - "reference": "c8b776496904213476a7b79f0b431aac5837e1b3" + "reference": "de39aa47b11d68c763087ac26cca674068d47161" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/newfold-labs/wp-module-ai/zipball/c8b776496904213476a7b79f0b431aac5837e1b3", - "reference": "c8b776496904213476a7b79f0b431aac5837e1b3", + "url": "https://api.github.com/repos/newfold-labs/wp-module-ai/zipball/de39aa47b11d68c763087ac26cca674068d47161", + "reference": "de39aa47b11d68c763087ac26cca674068d47161", "shasum": "" }, "require": { @@ -96,23 +192,23 @@ ], "description": "A module for providing artificial intelligence capabilities.", "support": { - "source": "https://github.com/newfold-labs/wp-module-ai/tree/1.1.5", + "source": "https://github.com/newfold-labs/wp-module-ai/tree/1.1.6", "issues": "https://github.com/newfold-labs/wp-module-ai/issues" }, - "time": "2024-02-27T15:16:54+00:00" + "time": "2024-02-29T10:39:41+00:00" }, { "name": "newfold-labs/wp-module-coming-soon", - "version": "1.2.0", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/newfold-labs/wp-module-coming-soon.git", - "reference": "74a6eab836e1d339f3650c68e89fd51b574e46bb" + "reference": "335bfe833ebdc072de55ed54cd6eebe0a210e43f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/newfold-labs/wp-module-coming-soon/zipball/74a6eab836e1d339f3650c68e89fd51b574e46bb", - "reference": "74a6eab836e1d339f3650c68e89fd51b574e46bb", + "url": "https://api.github.com/repos/newfold-labs/wp-module-coming-soon/zipball/335bfe833ebdc072de55ed54cd6eebe0a210e43f", + "reference": "335bfe833ebdc072de55ed54cd6eebe0a210e43f", "shasum": "" }, "require": { @@ -150,10 +246,64 @@ ], "description": "Coming Soon module for WordPress sites.", "support": { - "source": "https://github.com/newfold-labs/wp-module-coming-soon/tree/1.2.0", + "source": "https://github.com/newfold-labs/wp-module-coming-soon/tree/1.2.3", "issues": "https://github.com/newfold-labs/wp-module-coming-soon/issues" }, - "time": "2024-01-31T17:46:37+00:00" + "time": "2024-02-29T19:54:02+00:00" + }, + { + "name": "newfold-labs/wp-module-context", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/newfold-labs/wp-module-context.git", + "reference": "0d852f83f353f1631309e5ae7da9cb1e046bc984" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/newfold-labs/wp-module-context/zipball/0d852f83f353f1631309e5ae7da9cb1e046bc984", + "reference": "0d852f83f353f1631309e5ae7da9cb1e046bc984", + "shasum": "" + }, + "require": { + "wp-forge/helpers": "^2.0" + }, + "require-dev": { + "newfold-labs/wp-php-standards": "^1.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "NewfoldLabs\\WP\\Context\\": "includes" + }, + "files": [ + "includes/functions.php", + "bootstrap.php" + ] + }, + "scripts": { + "fix": [ + "vendor/bin/phpcbf . --standard=phpcs.xml" + ], + "lint": [ + "vendor/bin/phpcs . --standard=phpcs.xml -s" + ] + }, + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "Evan Mullins", + "homepage": "https://evanmullins.com" + } + ], + "description": "Newfold module to determine context for various brands and platforms.", + "support": { + "source": "https://github.com/newfold-labs/wp-module-context/tree/1.0.0", + "issues": "https://github.com/newfold-labs/wp-module-context/issues" + }, + "time": "2024-02-22T18:22:13+00:00" }, { "name": "newfold-labs/wp-module-data", @@ -298,19 +448,20 @@ }, { "name": "newfold-labs/wp-module-performance", - "version": "1.3.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/newfold-labs/wp-module-performance.git", - "reference": "4ac17a7ad77bb39cd90ebbb5cb207ede5336dbac" + "reference": "3d11c8da5928cc29899876bf9b1ea41b76cfc8cd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/newfold-labs/wp-module-performance/zipball/4ac17a7ad77bb39cd90ebbb5cb207ede5336dbac", - "reference": "4ac17a7ad77bb39cd90ebbb5cb207ede5336dbac", + "url": "https://api.github.com/repos/newfold-labs/wp-module-performance/zipball/3d11c8da5928cc29899876bf9b1ea41b76cfc8cd", + "reference": "3d11c8da5928cc29899876bf9b1ea41b76cfc8cd", "shasum": "" }, "require": { + "newfold-labs/wp-module-context": "^1.0", "wp-forge/collection": "^1.0", "wp-forge/wp-htaccess-manager": "^1.0", "wpscholar/url": "^1.2" @@ -336,10 +487,10 @@ ], "description": "A module for managing caching functionality.", "support": { - "source": "https://github.com/newfold-labs/wp-module-performance/tree/1.3.0", + "source": "https://github.com/newfold-labs/wp-module-performance/tree/1.4.0", "issues": "https://github.com/newfold-labs/wp-module-performance/issues" }, - "time": "2023-12-04T23:27:28+00:00" + "time": "2024-02-27T20:09:07+00:00" }, { "name": "wp-forge/collection", @@ -378,6 +529,50 @@ }, "time": "2022-08-26T17:42:31+00:00" }, + { + "name": "wp-forge/helpers", + "version": "2.0", + "source": { + "type": "git", + "url": "https://github.com/wp-forge/helpers.git", + "reference": "28ebc09a3390dbff427270a4ed2b93395e8b9b78" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-forge/helpers/zipball/28ebc09a3390dbff427270a4ed2b93395e8b9b78", + "reference": "28ebc09a3390dbff427270a4ed2b93395e8b9b78", + "shasum": "" + }, + "require": { + "doctrine/inflector": "^1.3", + "ext-mbstring": "*" + }, + "type": "library", + "autoload": { + "files": [ + "includes/functions.php" + ], + "psr-4": { + "WP_Forge\\Helpers\\": "includes" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "Micah Wood", + "email": "micah@wpscholar.com" + } + ], + "description": "A collection of helpers for WordPress and PHP development.", + "support": { + "issues": "https://github.com/wp-forge/helpers/issues", + "source": "https://github.com/wp-forge/helpers/tree/2.0" + }, + "time": "2022-01-06T13:10:47+00:00" + }, { "name": "wp-forge/wp-htaccess-manager", "version": "1.0",