Skip to content

Commit

Permalink
tweak image check
Browse files Browse the repository at this point in the history
  • Loading branch information
kadencewp committed Feb 16, 2024
1 parent 5a32db3 commit 7ee69df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions includes/class-kadence-blocks-prebuilt-library-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,7 @@ public function process_pattern( WP_REST_Request $request ) {
// Avoid srcset images.
if (
false === strpos( $link, '-150x' ) &&
false === strpos( $link, '-300x' ) &&
false === strpos( $link, '-1024x' )
false === strpos( $link, '-300x' )
) {
$image_urls[] = $link;
}
Expand Down Expand Up @@ -910,7 +909,6 @@ public function process_pattern( WP_REST_Request $request ) {
}
// Regex to find wp:kadence/image blocks with id and src.
$pattern = '/<!-- wp:kadence\/image .*?"id":(\d+),.*?"uniqueID":"[^"]+".*?-->(.*?)<img src="([^"]+)".*?<!-- \/wp:kadence\/image -->/s';

// Use preg_match_all to find all matches
if ( preg_match_all( $pattern, $content, $block_matches, PREG_SET_ORDER ) ) {
foreach ( $block_matches as $block_match ) {
Expand Down Expand Up @@ -2402,7 +2400,13 @@ public function check_for_local_image( $image_data ) {
$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 ( $cleaned_url !== $image_data['url'] ) {
$image_id = attachment_url_to_postid( $cleaned_url );
if ( empty( $image_id ) ) {
$scaled_url = preg_replace( $pattern, '-scaled', $image_data['url'] );
$image_id = attachment_url_to_postid( $scaled_url );
}
}
}
}
if ( empty( $image_id ) ) {
Expand All @@ -2421,7 +2425,7 @@ public function check_for_local_image( $image_data ) {
if ( ! empty( $image_id ) ) {
$local_image = array(
'id' => $image_id,
'url' => wp_get_attachment_url( $image_id ),
'url' => ( ! empty( $image_data['url'] ) && strpos( $image_data['url'], get_site_url() ) !== false ) ? $image_data['url'] : wp_get_attachment_url( $image_id ),
);
return array(
'status' => true,
Expand Down
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ developers of this plugin.
== Changelog ==

= 3.2.23 =
Release Date: February TBD, 2024
Release Date: February 16th 2024
* Add: "only text" responsive option when using an icon in Advanced button.
* Add: New language selection for AI wizard.
* Update: Pattern import to handle advanced forms.
* Fix: Responsive font sizes on text in infobox.
* Fix: Ability to set icon size to 0 on tablet and mobile in icon block.
Expand Down

0 comments on commit 7ee69df

Please sign in to comment.