Skip to content

Commit

Permalink
fix: vip function
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasio committed Nov 4, 2024
1 parent b21cd13 commit e8a28a5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions wp/headless-wp/includes/classes/Integrations/Gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function register() {
* @return int
*/
protected function get_image_by_url( $url ) {
if ( function_exists( '\wpcom_vip_url_to_postid' ) ) {
return \wpcom_vip_url_to_postid( $url );
if ( function_exists( '\wpcom_vip_attachment_url_to_postid' ) ) {
return \wpcom_vip_attachment_url_to_postid( $url );
}

$cache_key = sprintf( 'get_image_by_%s', md5( $url ) );
Expand Down Expand Up @@ -74,8 +74,12 @@ public function ensure_image_has_dimensions( $block_content, $block ) {

if ( $doc->next_tag( 'img' ) ) {
$src = $doc->get_attribute( 'src' );
// check if $src is a image hosted in the current wp install
if ( strpos( $src, get_site_url() ) !== false && empty( $block['attrs']['id'] ) ) {

$src_check = str_replace( 'http://', 'https://', $src );
$site_url = str_replace( 'http://', 'https://', get_site_url() );

// check if $src is a image hosted in the current wp install and block has no ID
if ( str_contains( $src_check, $site_url ) && empty( $block['attrs']['id'] ) ) {
$image_id = $this->get_image_by_url( $src );

if ( $image_id ) {
Expand Down

0 comments on commit e8a28a5

Please sign in to comment.