Media Modal Gutenberg 缺失样式

发布于 2025-01-09 17:12:36 字数 1318 浏览 0 评论 0原文

所以今天,我的所有网站都更新到了新版本的 WordPress 5.9.1。很好很好。但是,我在古腾堡中包含图像元素的自定义块破坏了媒体模式的样式(您可以直接在帖子中添加图像)。

输入图片这里的描述

我开始了一个新项目,只是为了测试它是否是我的主题或插件,但即使没有任何插件(ACF Pro 除外)并且在二十二十二主题上,如果我添加我的2022主题的functions.php文件中的注册代码,我遇到了同样的问题。

这是寄存器块代码:

add_action('acf/init', 'my_acf_init_block_types');
function my_acf_init_block_types() {
  if( function_exists('acf_register_block_type') ) {


    acf_register_block_type(array(
      'name'              => 'carousel',
      'title'             => __('Carrousel'),
      'description'       => __(''),
      'render_template'   => 'web/blocks/carousel.php',
      'category'          => 'custom-blocks',
      'icon'              => 'images-alt',
      'keywords'          => array( 'carousel', 'carrousel'),
      'supports'          => array( 'anchor' => true),
    ));
  }

}

我创建了一个字段组,尝试使用数组和仅使用 URL 的图像。

输入图片这里的描述

我尝试过的:

  • 没有插件(ACF除外)
  • WP主题(2022)
  • 自定义主题,没有功能
  • 将注册码添加到2022主题(同样的错误)

请帮助我们这里的姐妹。

So today, all my websites were updated to the new release of WordPress 5.9.1. Good good. However, my custom blocks in Gutenberg that are containing an image element are breaking the style of the media modal (where you can add an image directly in the post).

enter image description here

I started a new project, just to test if it was my theme, or the plugins, but even without any plugin (except ACF Pro) and on the Twenty Twenty-Two theme, if I add my registration code in the functions.php file of 2022 theme, I get the same problem.

Here's the register-block code:

add_action('acf/init', 'my_acf_init_block_types');
function my_acf_init_block_types() {
  if( function_exists('acf_register_block_type') ) {


    acf_register_block_type(array(
      'name'              => 'carousel',
      'title'             => __('Carrousel'),
      'description'       => __(''),
      'render_template'   => 'web/blocks/carousel.php',
      'category'          => 'custom-blocks',
      'icon'              => 'images-alt',
      'keywords'          => array( 'carousel', 'carrousel'),
      'supports'          => array( 'anchor' => true),
    ));
  }

}

And I've created a Field group trying the image with the array annnnnd the one using only the URL.

enter image description here

What I tried:

  • no plugins (except ACF)
  • WP theme (2022)
  • custom theme with no functions
  • adding the registration code to 2022 theme (same error)

Please, help a sister our here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

饮惑 2025-01-16 17:12:36

我认为这是由 5.9.1 更新引起的

您可以在functions.php中使用它作为临时修复

function fix_media_views_css() {
    echo '<link rel="stylesheet" id="fix-media-views-css" href="'.get_bloginfo('url').'/wp-includes/css/media-views.min.css?ver=5.9.1" media="all">';
}
add_action('admin_footer', 'fix_media_views_css');

I think it was cause by the 5.9.1 update

You can use this in functions.php as temporary fix

function fix_media_views_css() {
    echo '<link rel="stylesheet" id="fix-media-views-css" href="'.get_bloginfo('url').'/wp-includes/css/media-views.min.css?ver=5.9.1" media="all">';
}
add_action('admin_footer', 'fix_media_views_css');
初雪 2025-01-16 17:12:36

我已将这段代码添加到我的functions.php 文件中(最后,没什么大不了的)。

function acf_filter_rest_api_preload_paths( $preload_paths ) {
  if ( ! get_the_ID() ) {
    return $preload_paths;
  }
  $remove_path = '/wp/v2/' . get_post_type() . 's/' . get_the_ID() . '?context=edit';
  $v1 =  array_filter(
    $preload_paths,
    function( $url ) use ( $remove_path ) {
      return $url !== $remove_path;
    }
  );
  $remove_path = '/wp/v2/' . get_post_type() . 's/' . get_the_ID() . '/autosaves?context=edit';
  return array_filter(
    $v1,
    function( $url ) use ( $remove_path ) {
      return $url !== $remove_path;
    }
  );
}
add_filter( 'block_editor_rest_api_preload_paths', 'acf_filter_rest_api_preload_paths', 10, 1 );

它像以前一样完美地工作。我尝试将其降级到 5.9,它也有效,但需要更多的时间/精力,并且可能会发生很多错误。

希望它能帮助不止一个。

I've added that piece of code to my functions.php file (at the end, no biggy).

function acf_filter_rest_api_preload_paths( $preload_paths ) {
  if ( ! get_the_ID() ) {
    return $preload_paths;
  }
  $remove_path = '/wp/v2/' . get_post_type() . 's/' . get_the_ID() . '?context=edit';
  $v1 =  array_filter(
    $preload_paths,
    function( $url ) use ( $remove_path ) {
      return $url !== $remove_path;
    }
  );
  $remove_path = '/wp/v2/' . get_post_type() . 's/' . get_the_ID() . '/autosaves?context=edit';
  return array_filter(
    $v1,
    function( $url ) use ( $remove_path ) {
      return $url !== $remove_path;
    }
  );
}
add_filter( 'block_editor_rest_api_preload_paths', 'acf_filter_rest_api_preload_paths', 10, 1 );

It works perfectly like before. I've tried to downversion it to 5.9 and it worked as well, but it takes more time/effort and many mistakes can happen.

Hope it helps more than one.

柳絮泡泡 2025-01-16 17:12:36

ACF 已意识到该问题:https://github.com/AdvancedCustomFields/acf/issues/612

这是临时修复,粘贴到你的functions.php中:

function acf_filter_rest_api_preload_paths( $preload_paths ) {
    global $post;
    $rest_path    = rest_get_route_for_post( $post );
    $remove_paths = array(
        add_query_arg( 'context', 'edit', $rest_path ),
        sprintf( '%s/autosaves?context=edit', $rest_path ),
    );

    return array_filter(
        $preload_paths,
        function( $url ) use ( $remove_paths ) {
            return ! in_array( $url, $remove_paths, true );
        }
    );
}
add_filter( 'block_editor_rest_api_preload_paths', 'acf_filter_rest_api_preload_paths', 10, 1 );

ACF is aware of the issue: https://github.com/AdvancedCustomFields/acf/issues/612

Here is the temp fix, paste in your functions.php:

function acf_filter_rest_api_preload_paths( $preload_paths ) {
    global $post;
    $rest_path    = rest_get_route_for_post( $post );
    $remove_paths = array(
        add_query_arg( 'context', 'edit', $rest_path ),
        sprintf( '%s/autosaves?context=edit', $rest_path ),
    );

    return array_filter(
        $preload_paths,
        function( $url ) use ( $remove_paths ) {
            return ! in_array( $url, $remove_paths, true );
        }
    );
}
add_filter( 'block_editor_rest_api_preload_paths', 'acf_filter_rest_api_preload_paths', 10, 1 );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文