diff --git a/includes/class-kadence-blocks-prebuilt-library-rest-api.php b/includes/class-kadence-blocks-prebuilt-library-rest-api.php index 522ddaf21..61d4ba1db 100644 --- a/includes/class-kadence-blocks-prebuilt-library-rest-api.php +++ b/includes/class-kadence-blocks-prebuilt-library-rest-api.php @@ -2392,19 +2392,31 @@ public function get_image_info( $images, $target_src ) { */ public function check_for_local_image( $image_data ) { global $wpdb; - - // Thanks BrainstormForce for this idea. - // Check if image is already local based on meta key and custom hex value. - $image_id = $wpdb->get_var( - $wpdb->prepare( - 'SELECT `post_id` FROM `' . $wpdb->postmeta . '` - WHERE `meta_key` = \'_kadence_blocks_image_hash\' - AND `meta_value` = %s - ;', - sha1( $image_data['url'] ) - ) - ); - if ( $image_id ) { + $image_id = ''; + if ( ! empty( $image_data['url'] ) && strpos( $image_data['url'], get_site_url() ) !== false ) { + $image_id = attachment_url_to_postid( $image_data['url'] ); + if ( empty( $image_id ) ) { + // Get unsized version use Regular expression to find the pattern -numberxnumber + $pattern = "/-\d+x\d+/"; + // Replace the pattern with an empty string. + $cleaned_url = preg_replace( $pattern, '', $image_data['url'] ); + $image_id = attachment_url_to_postid( $cleaned_url ); + } + } + if ( empty( $image_id ) ) { + // Thanks BrainstormForce for this idea. + // Check if image is already local based on meta key and custom hex value. + $image_id = $wpdb->get_var( + $wpdb->prepare( + 'SELECT `post_id` FROM `' . $wpdb->postmeta . '` + WHERE `meta_key` = \'_kadence_blocks_image_hash\' + AND `meta_value` = %s + ;', + sha1( $image_data['url'] ) + ) + ); + } + if ( ! empty( $image_id ) ) { $local_image = array( 'id' => $image_id, 'url' => wp_get_attachment_url( $image_id ), @@ -2428,10 +2440,7 @@ public function check_for_image( $link = '' ) { if ( empty( $link ) ) { return false; } - if ( strpos( $link, 'prophecyimg.fly.dev' ) !== false ) { - return true; - } - if ( strpos( $link, 'images.pexels.com' ) !== false ) { + if ( strpos( $link, 'https://images.pexels.com' ) !== false ) { return true; } return preg_match( '/^((https?:\/\/)|(www\.))([a-z0-9-].?)+(:[0-9]+)?\/[\w\-]+\.(jpg|png|gif|webp|jpeg)\/?$/i', $link ); diff --git a/src/plugins/prebuilt-library/pattern-library.js b/src/plugins/prebuilt-library/pattern-library.js index 50747b741..44c590e37 100644 --- a/src/plugins/prebuilt-library/pattern-library.js +++ b/src/plugins/prebuilt-library/pattern-library.js @@ -639,13 +639,6 @@ function PatternLibrary( { }, [aIUserData]); async function onInsertContent( pattern ) { setIsImporting( true ); - // const response = await getPattern( ( pattern?.type === 'page' ? 'pages' : 'section' ), ( pattern?.type ? pattern.type : 'pattern' ), ( pattern?.id ? pattern.id : '' ), ( pattern?.style ? pattern.style : 'light' ) ); - // let patternBlocks = pattern?.content ? pattern.content : ''; - // if ( response && ! patternBlocks ) { - // patternBlocks = parse( response, { - // __unstableSkipMigrationLogs: true - // }); - // } let patternBlocks = pattern?.content ? pattern.content : ''; processImportContent( patternBlocks ); }